Bug 1519418 - Replace MMA preferences with sharedPreferences.r=petru
authorVlad Baicu <vlad.baicu@softvision.ro>
Tue, 05 Mar 2019 17:33:57 +0000
changeset 521008 3c21d47f9ddf9853519f2f7c49a1fe1ca5aa6463
parent 521007 ef2b461b0a90a509075824a47115a7c94a3eb25b
child 521009 e1459b0afa258f53b7799447c063654e994e4d7f
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspetru
bugs1519418
milestone67.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 - Replace MMA preferences with sharedPreferences.r=petru Patch D16319 attempted to clean the MMA code and allow for easier debugging of LP deeplinks on dev builds. However it introduced a regression because the MMA preferences were being accessed by the initializing activity. By making getDeviceId public and static, calling it from another activity would result in a null value returned. I have refactored the code to use shared preferences and remove the dependency on other activities. Differential Revision: https://phabricator.services.mozilla.com/D21984
mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -9,16 +9,17 @@ 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 org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.BrowserApp;
 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;
 import org.mozilla.gecko.activitystream.homepanel.ActivityStreamConfiguration;
 import org.mozilla.gecko.firstrun.PanelConfig;
@@ -28,16 +29,18 @@ import org.mozilla.gecko.switchboard.Swi
 import org.mozilla.gecko.util.ContextUtils;
 import org.mozilla.gecko.util.PackageUtil;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
+import static android.content.Context.MODE_PRIVATE;
+
 
 public class MmaDelegate {
 
     public static final String READER_AVAILABLE = "E_Reader_Available";
     public static final String DOWNLOAD_MEDIA_SAVED_IMAGE = "E_Download_Media_Saved_Image";
     public static final String CLEARED_PRIVATE_DATA = "E_Cleared_Private_Data";
     public static final String SAVED_BOOKMARK = "E_Saved_Bookmark";
     public static final String OPENED_BOOKMARK = "E_Opened_Bookmark";
@@ -276,25 +279,34 @@ public class MmaDelegate {
             return false;
         }
     }
 
     public static PanelConfig getPanelConfig(@NonNull Context context, PanelConfig.TYPE panelConfigType, final boolean useLocalValues) {
         return mmaHelper.getPanelConfig(context, panelConfigType, useLocalValues);
     }
 
-    public static String getDeviceId(Activity activity) {
+    private 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);
         return prefs.getString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, null);
     }
 
+    public static String getDeviceId(Context context) {
+        if (SwitchBoard.isInExperiment(context, Experiments.LEANPLUM_DEBUG)) {
+            return DEBUG_LEANPLUM_DEVICE_ID;
+        }
+
+        //MMA preferences are stored in the initialising activity's preferences, which in our case is BrowserApp.
+        return context.getSharedPreferences(BrowserApp.class.getName(), MODE_PRIVATE).getString(MmaDelegate.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());