Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Retain preload channel ID
We now keep the same package ID for OEM installs as the Play Store. This
is good for users and developers because everyone gets the same apk when
updates are made. This is bad for trackers because the preload channel
ID, a property of the original preloaded apk and different for upgraded
apks, was lost as soon as the phone was connected to the internet and
upgrades are downloaded. We now record the channel ID on first boot.

Bug: T115396
Change-Id: Iec363ee4b011dd70e457dcea733fc21551244def
  • Loading branch information
niedzielski committed Jan 18, 2016
1 parent 55014be commit 026b8ed
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
16 changes: 5 additions & 11 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -15,6 +15,9 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- For recording OEM preload channel ID prior to app upgrades. -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<!-- For Nearby feature -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location" android:required="false" />
Expand Down Expand Up @@ -201,19 +204,10 @@
after the app is installed, if the original link that led the user to the Play Store
for installing the app contained a "referrer" query parameter. This is why the receiver
needs to be exported.
Because the receiver is exported, it usually requires a permission associated with it,
to filter out the kinds of apps that can send us this intent. Otherwise, a Lint warning
shows up, notifying that a receiver is exported without a permission. However, since the
Play Store app is literally the only app that is expected to send this intent, we can
safely ignore this warning. Technically we could specify a permission such as
permission.INTERNET (which we assume the Play Store app has), but then we wouldn't be able
to test this intent using adb (am broadcast).
-->
<receiver
android:name="org.wikipedia.analytics.InstallReferrerReceiver"
android:exported="true"
tools:ignore="ExportedReceiver">
<receiver android:name=".analytics.InstallReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
Expand Down
Expand Up @@ -2,18 +2,42 @@

import org.wikipedia.WikipediaApp;
import org.wikipedia.page.PageActivity;
import org.wikipedia.util.ReleaseUtil;
import org.wikipedia.util.ShareUtil;
import org.wikipedia.util.log.L;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.text.TextUtils;

public final class InstallReferrerReceiver extends BroadcastReceiver {
public final class InstallReceiver extends BroadcastReceiver {
private static final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
private static final String INSTALL_ACTION = "com.android.vending.INSTALL_REFERRER";
private static final String REFERRER_KEY = "referrer";

public void onReceive(Context ctx, Intent intent) {
String action = intent.getAction();
switch (action) {
case INSTALL_ACTION:
// for play store devices only:
// * invoke the receiver and open the page:
// `adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n org.wikipedia.dev/org.wikipedia.analytics.InstallReceiver --es "referrer" "referrer_url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FWombat&campaign_id=foo&install_id=bar"`
// * invoke the receiver but don't open the app (bad url):
// `adb shell am broadcast -a com.android.vending.INSTALL_REFERRER -n org.wikipedia.dev/org.wikipedia.analytics.InstallReceiver --es "referrer" "referrer_url=gibberish&campaign_id=foo&install_id=bar"`
installReferrer(ctx, intent);
break;
case BOOT_ACTION:
// `adb shell am broadcast -a android.intent.action.BOOT_COMPLETED`
recordChannelId(ctx);
break;
default:
L.d("action=" + action);
break;
}
}

/**
* Receives an Intent from the Play Store app upon first launch after the app has been
* installed. If the original link that led the user to the Play Store for installing
Expand All @@ -26,10 +50,10 @@ public final class InstallReferrerReceiver extends BroadcastReceiver {
* @param ctx Context in which this intent is received.
* @param intent Intent that contains referrer data from the Play Store.
*/
public void onReceive(Context ctx, Intent intent) {
private void installReferrer(@NonNull Context ctx, @NonNull Intent intent) {
String referrerStr = intent.getStringExtra(REFERRER_KEY);
L.d("Received install referrer: " + referrerStr);
if (!INSTALL_ACTION.equals(intent.getAction()) || TextUtils.isEmpty(referrerStr)) {
if (TextUtils.isEmpty(referrerStr)) {
return;
}

Expand Down Expand Up @@ -57,6 +81,11 @@ public void onReceive(Context ctx, Intent intent) {
}
}

private void recordChannelId(@NonNull Context ctx) {
String channel = ReleaseUtil.getChannel(ctx);
L.v("channel=" + channel);
}

private void openPageFromUrl(Context context, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/developer_preferences.xml
Expand Up @@ -83,6 +83,12 @@
android:title="@string/preferences_developer_remote_log_title"
android:dialogMessage="@string/preferences_developer_remote_log_summary" />

<!--suppress AndroidUnknownAttribute -->
<org.wikipedia.settings.EditTextAutoSummarizePreference
style="@style/EditTextAutoSummarizePreference"
android:key="@string/preference_key_app_channel"
android:title="@string/preference_key_app_channel" />

</PreferenceCategory>

<PreferenceCategory android:title="@string/preferences_developer_misc_heading">
Expand Down

0 comments on commit 026b8ed

Please sign in to comment.