Bug 1358117 - Add pref to turn on/off leanplum. r?maliu,sebastian draft
authorNevin Chen <cnevinchen@gmail.com>
Thu, 18 May 2017 19:27:13 +0800
changeset 585255 eaa41063a8539f7051f07d2e4a7916257182f638
parent 584591 58a54427780db1f135174f9c7d94a913bc7f234b
child 585262 ef6c740158ac2e293b62a5729c19947992bccf82
push id61082
push userbmo:cnevinchen@gmail.com
push dateFri, 26 May 2017 19:13:22 +0000
reviewersmaliu, sebastian
bugs1358117
milestone55.0a1
Bug 1358117 - Add pref to turn on/off leanplum. r?maliu,sebastian MozReview-Commit-ID: 8LHvMPSxAdl
mobile/android/app/mobile.js
mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
mobile/android/base/java/org/mozilla/gecko/mma/MmaInterface.java
mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
mobile/android/thirdparty/com/leanplum/Leanplum.java
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -409,16 +409,25 @@ pref("browser.ui.zoom.force-user-scalabl
 // When removing this Nightly flag, also remember to remove the flags surrounding this feature
 // in GeckoPreferences and BrowserApp (see bug 1245930).
 #ifdef NIGHTLY_BUILD
 pref("ui.bookmark.mobilefolder.enabled", true);
 #else
 pref("ui.bookmark.mobilefolder.enabled", false);
 #endif
 
+#if MOZ_UPDATE_CHANNEL == nightly
+pref("mma.enabled", true);
+#elif MOZ_UPDATE_CHANNEL == beta
+pref("mma.enabled", true);
+#else
+pref("mma.enabled", true);
+#endif
+
+
 pref("ui.touch.radius.enabled", false);
 pref("ui.touch.radius.leftmm", 3);
 pref("ui.touch.radius.topmm", 5);
 pref("ui.touch.radius.rightmm", 3);
 pref("ui.touch.radius.bottommm", 2);
 pref("ui.touch.radius.visitedWeight", 120);
 
 pref("ui.mouse.radius.enabled", false);
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -5,23 +5,45 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.mma;
 
 import android.app.Application;
 import android.content.Context;
 
 import org.mozilla.gecko.MmaConstants;
+import org.mozilla.gecko.PrefsHelper;
 
 
 public class MmaDelegate {
 
+    private static final String ENABLE_PREF = "mma.enabled";
+
     private static MmaInterface mmaHelper = MmaConstants.getMma();
 
+    private static final String[] prefs = { ENABLE_PREF };
+
+
     public static void init(Application application) {
-        mmaHelper.init(application);
+        setupPrefHandler(application);
+    }
+
+    public static void stop() {
+        mmaHelper.stop();
     }
 
-    public void start(Context context) {
-        mmaHelper.start(context);
+    private static void setupPrefHandler(final Application application) {
+        PrefsHelper.PrefHandler handler = new PrefsHelper.PrefHandlerBase() {
+            @Override
+            public void prefValue(String pref, boolean value) {
+                if (pref.equals(ENABLE_PREF)) {
+                    if (value) {
+                        mmaHelper.init(application);
+                    } else {
+                        mmaHelper.stop();
+                    }
+
+                }
+            }
+        };
+        PrefsHelper.addObserver(prefs, handler);
     }
-
 }
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaInterface.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaInterface.java
@@ -14,9 +14,10 @@ public interface MmaInterface {
     void init(Application application);
 
     void start(Context context);
 
     void track(String leanplumEvent);
 
     void track(String leanplumEvent, double value);
 
+    void stop();
 }
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
@@ -44,9 +44,14 @@ public class MmaLeanplumImp implements M
 
     }
 
     @Override
     public void track(String leanplumEvent, double value) {
         Leanplum.track(leanplumEvent, value);
 
     }
+
+    @Override
+    public void stop() {
+        Leanplum.stop();
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
@@ -25,9 +25,14 @@ public class MmaStubImp implements MmaIn
     public void track(String leanplumEvent) {
 
     }
 
     @Override
     public void track(String leanplumEvent, double value) {
 
     }
+
+    @Override
+    public void stop() {
+
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -27,16 +27,17 @@ import org.mozilla.gecko.R;
 import org.mozilla.gecko.SnackbarBuilder;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.TelemetryContract.Method;
 import org.mozilla.gecko.activitystream.ActivityStream;
 import org.mozilla.gecko.db.BrowserContract.SuggestedSites;
 import org.mozilla.gecko.feeds.FeedService;
 import org.mozilla.gecko.feeds.action.CheckForUpdatesAction;
+import org.mozilla.gecko.mma.MmaDelegate;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.restrictions.Restrictable;
 import org.mozilla.gecko.restrictions.Restrictions;
 import org.mozilla.gecko.tabqueue.TabQueueHelper;
 import org.mozilla.gecko.tabqueue.TabQueuePrompt;
 import org.mozilla.gecko.updater.UpdateService;
 import org.mozilla.gecko.updater.UpdateServiceHelper;
 import org.mozilla.gecko.util.BundleEventListener;
@@ -1215,16 +1216,19 @@ public class GeckoPreferences
             setCharEncodingState(((String) newValue).equals("true"));
         } else if (PREFS_UPDATER_AUTODOWNLOAD.equals(prefName)) {
             UpdateServiceHelper.setAutoDownloadPolicy(this, UpdateService.AutoDownloadPolicy.get((String) newValue));
         } else if (PREFS_UPDATER_URL.equals(prefName)) {
             UpdateServiceHelper.setUpdateUrl(this, (String) newValue);
         } else if (PREFS_HEALTHREPORT_UPLOAD_ENABLED.equals(prefName)) {
             final Boolean newBooleanValue = (Boolean) newValue;
             AdjustConstants.getAdjustHelper().setEnabled(newBooleanValue);
+            if (!newBooleanValue) {
+                MmaDelegate.stop();
+            }
         } else if (PREFS_GEO_REPORTING.equals(prefName)) {
             if ((Boolean) newValue) {
                 enableStumbler((CheckBoxPreference) preference);
                 return false;
             } else {
                 broadcastStumblerPref(GeckoPreferences.this, false);
                 return true;
             }
--- a/mobile/android/thirdparty/com/leanplum/Leanplum.java
+++ b/mobile/android/thirdparty/com/leanplum/Leanplum.java
@@ -1016,17 +1016,17 @@ public class Leanplum {
   private static void resumeHeartbeat() {
     startHeartbeat();
   }
 
   /**
    * Call this to explicitly end the session. This should not be used in most cases, so we won't
    * make it public for now.
    */
-  static void stop() {
+  public static void stop() {
     if (Constants.isNoop()) {
       return;
     }
     if (!LeanplumInternal.hasCalledStart()) {
       Log.e("You cannot call stop before calling start");
       return;
     }