Bug 1519418 - Retrieve LP debug id for local uid on debug builds. r=petru
authorVlad Baicu <vlad.baicu@softvision.ro>
Wed, 16 Jan 2019 16:24:40 +0000
changeset 511603 259e581af979d775e91f6ce2b15bb6e29fdc996d
parent 511602 7b123a6c5f5a6b680da3a9c387a0508f1819baf7
child 511604 e29be447ca751eb0fd8b854631c3eee176dba32e
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1519418
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1519418 - Retrieve LP debug id for local uid on debug builds. r=petru On debug builds whenever we would attempt to retrieve the value of localUid it would be null because the LP debug id is never persisted. Differential Revision: https://phabricator.services.mozilla.com/D16319
mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
--- a/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
@@ -11,18 +11,16 @@ import android.content.Intent;
 import android.net.Uri;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.customtabs.CustomTabsIntent;
 import android.util.Log;
 
 import org.mozilla.gecko.home.HomeConfig;
 import org.mozilla.gecko.mma.MmaDelegate;
-import org.mozilla.gecko.switchboard.SwitchBoard;
-import org.mozilla.gecko.util.FileUtils;
 import org.mozilla.gecko.webapps.WebAppActivity;
 import org.mozilla.gecko.webapps.WebAppIndexer;
 import org.mozilla.gecko.customtabs.CustomTabsActivity;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.mozglue.SafeIntent;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.tabqueue.TabQueueHelper;
 import org.mozilla.gecko.tabqueue.TabQueueService;
@@ -193,17 +191,17 @@ public class LauncherActivity extends Ac
     }
 
     private void dispatchDeepLink(SafeIntent intent) {
         if (intent == null || intent.getData() == null || intent.getData().getHost() == null) {
             return;
         }
         final String deepLink = intent.getData().getHost();
         final String uid = intent.getData().getQueryParameter("uid");
-        final String localUid = getSharedPreferences(BrowserApp.class.getName(), MODE_PRIVATE).getString(MmaDelegate.KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, null);
+        final String localUid = MmaDelegate.getDeviceId(LauncherActivity.this);
         final boolean isMmaDeepLink = uid != null && localUid != null && uid.equals(localUid);
 
         if (!validateMmaDeepLink(deepLink, isMmaDeepLink)) {
             return;
         }
 
         switch (deepLink) {
             case LINK_OPEN:
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -7,17 +7,16 @@
 package org.mozilla.gecko.mma;
 
 import android.app.Activity;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.text.TextUtils;
-import android.util.Log;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.Experiments;
 import org.mozilla.gecko.MmaConstants;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
@@ -89,36 +88,35 @@ public class MmaDelegate {
                 registerInstalledPackagesReceiver(activity);
             }
         });
         applicationContext = activity.getApplicationContext();
         // Since user attributes are gathered in Fennec, not in MMA implementation,
         // we gather the information here then pass to mmaHelper.init()
         // Note that generateUserAttribute always return a non null HashMap.
         final Map<String, Object> attributes = gatherUserAttributes(activity);
-        final String deviceId = getDeviceId(activity);
+        String deviceId = getDeviceId(activity);
+        if (deviceId == null) {
+            deviceId = UUID.randomUUID().toString();
+            setDeviceId(activity, deviceId);
+        }
         mmaHelper.setDeviceId(deviceId);
         PrefsHelper.setPref(GeckoPreferences.PREFS_MMA_DEVICE_ID, deviceId);
         // above two config setup required to be invoked before mmaHelper.init.
         mmaHelper.init(activity, attributes);
 
         if (!isDefaultBrowser(activity)) {
             mmaHelper.event(MmaDelegate.LAUNCH_BUT_NOT_DEFAULT_BROWSER);
         }
         mmaHelper.event(MmaDelegate.LAUNCH_BROWSER);
 
         activityName = activity.getLocalClassName();
         notifyAboutPreviouslyInstalledPackages(activity);
 
-        ThreadUtils.postToUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mmaHelper.listenOnceForVariableChanges(remoteVariablesListener);
-            }
-        });
+        ThreadUtils.postToUiThread(() -> mmaHelper.listenOnceForVariableChanges(remoteVariablesListener));
     }
 
     /**
      * Stop LeanPlum functionality.
      */
     public static void stop() {
         mmaHelper.stop();
     }
@@ -278,28 +276,28 @@ public class MmaDelegate {
             return false;
         }
     }
 
     public static PanelConfig getPanelConfig(@NonNull Context context, PanelConfig.TYPE panelConfigType, final boolean useLocalValues) {
         return mmaHelper.getPanelConfig(context, panelConfigType, useLocalValues);
     }
 
-    private static String getDeviceId(Activity activity) {
+    public static String getDeviceId(Activity activity) {
         if (SwitchBoard.isInExperiment(activity, Experiments.LEANPLUM_DEBUG)) {
             return DEBUG_LEANPLUM_DEVICE_ID;
         }
 
         final SharedPreferences prefs = activity.getPreferences(Context.MODE_PRIVATE);
-        String deviceId = prefs.getString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, null);
-        if (deviceId == null) {
-            deviceId = UUID.randomUUID().toString();
-            prefs.edit().putString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, deviceId).apply();
-        }
-        return deviceId;
+        return prefs.getString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, null);
+    }
+
+    private static void setDeviceId(Activity activity, String deviceId) {
+        final SharedPreferences prefs = activity.getPreferences(Context.MODE_PRIVATE);
+        prefs.edit().putString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, deviceId).apply();
     }
 
     private static void registerInstalledPackagesReceiver(@NonNull final Activity activity) {
         packageAddedReceiver = new PackageAddedReceiver();
         activity.registerReceiver(packageAddedReceiver, PackageAddedReceiver.getIntentFilter());
     }
 
     private static void unregisterInstalledPackagesReceiver(@NonNull final Activity activity) {