Backed out changeset 645836bfad25 (bug 1361664) because bug 1365089 got backed out and this depends on it. r=backout
authorSebastian Hengst <archaeopteryx@coole-files.de>
Sun, 28 May 2017 18:45:28 +0200
changeset 409150 afde8a5603f84c4e3536f407b9715dcb32cbd04e
parent 409149 01476dee058410a5a14e4ff55d9959243782d869
child 409151 71a29c988fb5f151e49ca1a6ac30bf1831000cd0
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1361664, 1365089
milestone55.0a1
backs out645836bfad25435b49db0faf12d2febc63a605df
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
Backed out changeset 645836bfad25 (bug 1361664) because bug 1365089 got backed out and this depends on it. r=backout
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
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/thirdparty/com/leanplum/LeanplumActivityHelper.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -890,17 +890,17 @@ public class BrowserApp extends GeckoApp
         new AsyncConfigLoader(context, serverUrl) {
             @Override
             protected Void doInBackground(Void... params) {
                 super.doInBackground(params);
                 SwitchBoard.loadConfig(context, serverUrl);
                 if (SwitchBoard.isInExperiment(context, Experiments.LEANPLUM) &&
                         GeckoPreferences.getBooleanPref(context, GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true)) {
                     // Do LeanPlum start/init here
-                    MmaDelegate.init(BrowserApp.this);
+                    MmaDelegate.init(BrowserApp.this.getApplication());
                 }
                 return null;
             }
         }.execute();
     }
 
     private static void initTelemetryUploader(final boolean isInAutomation) {
         TelemetryUploadService.setDisabled(isInAutomation);
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -1,64 +1,49 @@
 //#filter substitution
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * 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.util.Log;
+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 TAG = "MmaDelegate";
-    private static final String KEY_PREF_BOOLEAN_MMA_ENABLED = "mma.enabled";
-    private static final String[] PREFS = { KEY_PREF_BOOLEAN_MMA_ENABLED };
+    private static final String ENABLE_PREF = "mma.enabled";
+
+    private static MmaInterface mmaHelper = MmaConstants.getMma();
+
+    private static final String[] prefs = { ENABLE_PREF };
 
 
-    private static boolean isGeckoPrefOn = false;
-    private static MmaInterface mmaHelper = MmaConstants.getMma();
-
-
-    public static void init(Activity activity) {
-        setupPrefHandler(activity);
+    public static void init(Application application) {
+        setupPrefHandler(application);
     }
 
     public static void stop() {
         mmaHelper.stop();
     }
 
-    private static void setupPrefHandler(final Activity activity) {
+    private static void setupPrefHandler(final Application application) {
         PrefsHelper.PrefHandler handler = new PrefsHelper.PrefHandlerBase() {
             @Override
             public void prefValue(String pref, boolean value) {
-                if (pref.equals(KEY_PREF_BOOLEAN_MMA_ENABLED)) {
-                    Log.d(TAG, "prefValue() called with: pref = [" + pref + "], value = [" + value + "]");
+                if (pref.equals(ENABLE_PREF)) {
                     if (value) {
-                        mmaHelper.init(activity);
-                        isGeckoPrefOn = true;
+                        mmaHelper.init(application);
                     } else {
-                        isGeckoPrefOn = false;
+                        mmaHelper.stop();
                     }
+
                 }
             }
         };
-        PrefsHelper.addObserver(PREFS, handler);
-    }
-
-    public static void track(String event) {
-        if (isGeckoPrefOn) {
-            mmaHelper.track(event);
-        }
-    }
-
-    public static void track(String event, long value) {
-        if (isGeckoPrefOn) {
-            mmaHelper.track(event, value);
-        }
+        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
@@ -1,24 +1,23 @@
 //#filter substitution
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * 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.app.Application;
 import android.content.Context;
 
 
 public interface MmaInterface {
-    void init(Activity Activity);
+    void init(Application application);
 
     void start(Context context);
 
-    void track(String mmaEvent);
+    void track(String leanplumEvent);
 
-    void track(String mmaEvent, double value);
+    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
@@ -1,58 +1,41 @@
 //#filter substitution
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * 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.app.Application;
 import android.content.Context;
 
 import com.leanplum.Leanplum;
 import com.leanplum.LeanplumActivityHelper;
 import com.leanplum.annotations.Parser;
 
-import org.mozilla.gecko.ActivityHandlerHelper;
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.MmaConstants;
-import org.mozilla.gecko.util.ContextUtils;
-
-import java.util.HashMap;
-import java.util.Map;
 
 
 public class MmaLeanplumImp implements MmaInterface {
     @Override
-    public void init(Activity activity) {
-        Leanplum.setApplicationContext(activity.getApplicationContext());
-
-        LeanplumActivityHelper.enableLifecycleCallbacks(activity.getApplication());
+    public void init(Application application) {
+        Leanplum.setApplicationContext(application);
+        Parser.parseVariables(application);
+        LeanplumActivityHelper.enableLifecycleCallbacks(application);
 
         if (AppConstants.MOZILLA_OFFICIAL) {
             Leanplum.setAppIdForProductionMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
         } else {
             Leanplum.setAppIdForDevelopmentMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
         }
 
-
-        Map<String, Object> attributes = new HashMap<>();
-        boolean installedFocus = ContextUtils.isPackageInstalled(activity, "org.mozilla.focus");
-        boolean installedKlar = ContextUtils.isPackageInstalled(activity, "org.mozilla.klar");
-        if (installedFocus || installedKlar) {
-            attributes.put("focus", "installed");
-        }
-        Leanplum.start(activity, attributes);
-        Leanplum.track("Launch");
-        // this is special to Leanplum. Since we defer LeanplumActivityHelper's onResume call till
-        // switchboard completes loading, we manually call it here.
-        LeanplumActivityHelper.onResume(activity);
+        Leanplum.start(application);
     }
 
     @Override
     public void start(Context context) {
 
     }
 
     @Override
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
@@ -1,24 +1,23 @@
 //#filter substitution
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * 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.app.Application;
 import android.content.Context;
 
 
 public class MmaStubImp implements MmaInterface {
     @Override
-    public void init(Activity activity) {
+    public void init(Application application) {
 
     }
 
     @Override
     public void start(Context context) {
 
     }
 
--- a/mobile/android/thirdparty/com/leanplum/LeanplumActivityHelper.java
+++ b/mobile/android/thirdparty/com/leanplum/LeanplumActivityHelper.java
@@ -204,17 +204,17 @@ public class LeanplumActivityHelper {
       if (!registeredCallbacks) {
         onPause(activity);
       }
     } catch (Throwable t) {
       Util.handleException(t);
     }
   }
 
-  public static void onResume(Activity activity) {
+  private static void onResume(Activity activity) {
     isActivityPaused = false;
     currentActivity = activity;
     if (LeanplumInternal.isPaused() || LeanplumInternal.hasStartedInBackground()) {
       Leanplum.resume();
       LocationManager locationManager = ActionManager.getLocationManager();
       if (locationManager != null) {
         locationManager.updateGeofencing();
         locationManager.updateUserLocation();