Bug 1373174 Change Change Leanplum user identification method. r?maliu draft
authorNevin Chen <cnevinchen@gmail.com>
Thu, 15 Jun 2017 16:56:52 +0800
changeset 594653 783abfda4e70f1500fe31e6103b7e87f72d20f56
parent 592464 27cad9749cddf68e11fdd4e5d73dad84a8f8cf23
child 594654 09f788bd5150377d479b407f7f91d0ee5cd66893
child 595505 3960de522624436bcfbf073177f617240a3056e8
push id64105
push userbmo:cnevinchen@gmail.com
push dateThu, 15 Jun 2017 08:58:09 +0000
reviewersmaliu
bugs1373174
milestone55.0a1
Bug 1373174 Change Change Leanplum user identification method. r?maliu MozReview-Commit-ID: LEgFJPaNBpe
mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
@@ -3,29 +3,35 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.mma;
 
 import android.app.Activity;
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 
 import com.leanplum.Leanplum;
 import com.leanplum.LeanplumActivityHelper;
 
 import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.MmaConstants;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 
 
 public class MmaLeanplumImp implements MmaInterface {
+
+    private static final String KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID = "android.not_a_preference.leanplum.device_id";
+
     @Override
     public void init(final Activity activity) {
         if (activity == null) {
             return;
         }
         Leanplum.setApplicationContext(activity.getApplicationContext());
 
         LeanplumActivityHelper.enableLifecycleCallbacks(activity.getApplication());
@@ -37,16 +43,23 @@ public class MmaLeanplumImp implements M
         }
 
         Map<String, Object> attributes = new HashMap<>();
         boolean installedFocus = isPackageInstalled(activity, "org.mozilla.focus");
         boolean installedKlar = isPackageInstalled(activity, "org.mozilla.klar");
         if (installedFocus || installedKlar) {
             attributes.put("focus", "installed");
         }
+        final SharedPreferences sharedPreferences = GeckoSharedPrefs.forApp(activity);
+        String deviceId = sharedPreferences.getString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, null);
+        if (deviceId == null) {
+            deviceId = UUID.randomUUID().toString();
+            sharedPreferences.edit().putString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, deviceId).apply();
+        }
+        Leanplum.setDeviceId(deviceId);
         Leanplum.start(activity, attributes);
 
         // this is special to Leanplum. Since we defer LeanplumActivityHelper's onResume call till
         // switchboard completes loading. We miss the call to LeanplumActivityHelper.onResume.
         // So I manually call it here.
         //
         // There's a risk that if this is called after activity's onPause(Although I've
         // tested it's seems okay). We  should require their SDK to separate activity call back with