Bug 1373174 - Change Leanplum user identification method. r?maliu draft
authorNevin Chen <cnevinchen@gmail.com>
Thu, 15 Jun 2017 16:56:52 +0800
changeset 601427 d02bb6348c0b8cf498e104df3c76ec6621ec8adc
parent 600616 f4e52135d9bdc6ce98bb37b450021445aed894ce
child 601428 3d5a3cb073875bef3279d0dc285111ea1d1d4f5b
push id66049
push userbmo:cnevinchen@gmail.com
push dateWed, 28 Jun 2017 18:59:59 +0000
reviewersmaliu
bugs1373174
milestone56.0a1
Bug 1373174 - 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,34 @@
  * 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.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());
@@ -35,18 +40,28 @@ public class MmaLeanplumImp implements M
         } else {
             Leanplum.setAppIdForDevelopmentMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
         }
 
         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");
+            attributes.put("focus", true);
+        } else {
+            attributes.put("focus", false);
         }
+
+        final SharedPreferences sharedPreferences = activity.getPreferences(0);
+        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