Bug 1373174 Change Change Leanplum user identification method. r?maliu
MozReview-Commit-ID: LEgFJPaNBpe
--- 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