Bug 1351585 - Part 2. Add build flag and change our existing build system to inject leanplum implementation r?nalexander,maliu,sebastian draft
authorcnevinc <cnevinc@livemail.tw>
Sat, 13 May 2017 14:08:57 -0700
changeset 581066 4f635ad9e0d6c411f32b6ea347f51c523fdf1141
parent 581065 5e91a5caae740604a86f79582c619d83a0b77828
child 581067 ee13192ee7bdeef9016fb623a5320d1c1a76a9d3
push id59758
push userbmo:cnevinchen@gmail.com
push dateFri, 19 May 2017 07:56:51 +0000
reviewersnalexander, maliu, sebastian
bugs1351585
milestone55.0a1
Bug 1351585 - Part 2. Add build flag and change our existing build system to inject leanplum implementation r?nalexander,maliu,sebastian MozReview-Commit-ID: uN7imeGYcj
mobile/android/app/build.gradle
mobile/android/base/AndroidManifest.xml.in
mobile/android/base/Makefile.in
mobile/android/base/MmaAndroidManifest_services.xml.in
mobile/android/base/MmaConstants.java.in
mobile/android/base/generate_build_config.py
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/Experiments.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/base/java/org/mozilla/gecko/switchboard/SwitchBoard.java
mobile/android/base/moz.build
mobile/android/geckoview/build.gradle
--- a/mobile/android/app/build.gradle
+++ b/mobile/android/app/build.gradle
@@ -159,16 +159,22 @@ android {
                 }
 
                 if (mozconfig.substs.MOZ_INSTALL_TRACKING) {
                     exclude 'org/mozilla/gecko/adjust/StubAdjustHelper.java'
                 } else {
                     exclude 'org/mozilla/gecko/adjust/AdjustHelper.java'
                 }
 
+                if (mozconfig.substs.MOZ_ANDROID_MMA) {
+                    exclude 'org/mozilla/gecko/mma/MmaStubImp.java'
+                } else {
+                    exclude 'org/mozilla/gecko/mma/MmaLeanplumImp.java'
+                }
+
                 if (!mozconfig.substs.MOZ_ANDROID_GCM) {
                     exclude 'org/mozilla/gecko/gcm/**/*.java'
                     exclude 'org/mozilla/gecko/push/**/*.java'
                 }
 
                 srcDir "${project.buildDir}/generated/source/preprocessed_code" // See syncPreprocessedCode.
             }
 
@@ -296,16 +302,17 @@ task checkstyle(type: Checkstyle) {
     classpath = files()
 }
 
 task syncPreprocessedCode(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
     into("${project.buildDir}/generated/source/preprocessed_code")
     from("${topobjdir}/mobile/android/base/generated/preprocessed") {
         // All other preprocessed code is included in the geckoview project.
         include '**/AdjustConstants.java'
+        include '**/MmaConstants.java'
     }
 }
 
 // The localization system uses the moz.build preprocessor to interpolate a .dtd
 // file of XML entity definitions into an XML file of elements referencing those
 // entities.  (Each locale produces its own .dtd file, backstopped by the en-US
 // .dtd file in tree.)  Android Studio (and IntelliJ) don't handle these inline
 // entities smoothly.  This filter merely expands the entities in place, making
--- a/mobile/android/base/AndroidManifest.xml.in
+++ b/mobile/android/base/AndroidManifest.xml.in
@@ -475,10 +475,14 @@
 
         <service
             android:name="org.mozilla.gecko.gfx.SurfaceAllocatorService"
             android:enabled="true"
             android:exported="false"
             android:isolatedProcess="false">
         </service>
 
+#ifdef MOZ_ANDROID_MMA
+#include MmaAndroidManifest_services.xml.in
+#endif
+
     </application>
 </manifest>
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -73,16 +73,21 @@ endif
 
 ifdef MOZ_INSTALL_TRACKING
     JAVA_CLASSPATH += \
         $(ANDROID_PLAY_SERVICES_ADS_AAR_LIB) \
         $(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
         $(NULL)
 endif
 
+
+# MOZ_ANDROID_MMA requires MOZ_ANDROID_GCM and MOZ_INSTALL_TRACKING,
+# so we don't need a separate clause adding to JAVA_CLASSPATH for
+# MMA (Leanplum) support.
+
 JAVA_CLASSPATH := $(subst $(NULL) ,:,$(strip $(JAVA_CLASSPATH)))
 
 # Library jars that we're bundling: these are subject to Proguard before inclusion
 # into classes.dex.
 java_bundled_libs := \
     $(ANDROID_SUPPORT_V4_AAR_LIB) \
     $(ANDROID_SUPPORT_V4_AAR_INTERNAL_LIB) \
     $(ANDROID_APPCOMPAT_V7_AAR_LIB) \
@@ -116,16 +121,20 @@ endif
 
 ifdef MOZ_INSTALL_TRACKING
     java_bundled_libs += \
         $(ANDROID_PLAY_SERVICES_ADS_AAR_LIB) \
         $(ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB) \
         $(NULL)
 endif
 
+# MOZ_ANDROID_MMA requires MOZ_ANDROID_GCM and MOZ_INSTALL_TRACKING,
+# so we don't need a separate clause adding to java_bundled_libs for
+# MMA (Leanplum) support.
+
 # uniq purloined from http://stackoverflow.com/a/16151140.
 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
 
 java_bundled_libs := $(call uniq,$(java_bundled_libs))
 java_bundled_libs := $(subst $(NULL) ,:,$(strip $(java_bundled_libs)))
 
 GECKOVIEW_JARS = \
   constants.jar \
@@ -135,16 +144,20 @@ GECKOVIEW_JARS = \
   gecko-view.jar \
   sync-thirdparty.jar \
   $(NULL)
 
 ifdef MOZ_INSTALL_TRACKING
 GECKOVIEW_JARS += gecko-thirdparty-adjust_sdk.jar
 endif
 
+ifdef MOZ_ANDROID_MMA
+GECKOVIEW_JARS += gecko-thirdparty-leanplum_sdk.jar
+endif
+
 geckoview_jars_classpath := $(subst $(NULL) ,:,$(strip $(GECKOVIEW_JARS)))
 
 FENNEC_JARS = \
   gecko-browser.jar \
   gecko-thirdparty.jar \
   services.jar \
   $(NULL)
 
@@ -155,16 +168,17 @@ endif
 ifdef MOZ_ANDROID_SEARCH_ACTIVITY
 FENNEC_JARS += search-activity.jar
 endif
 
 ifdef MOZ_ANDROID_MLS_STUMBLER
 FENNEC_JARS += ../stumbler/stumbler.jar
 endif
 
+
 # All the jars we're compiling from source. (not to be confused with
 # java_bundled_libs, which holds the jars which we're including as binaries).
 ALL_JARS = \
   $(GECKOVIEW_JARS) \
   $(FENNEC_JARS) \
   $(NULL)
 
 # The list of jars in Java classpath notation (colon-separated).
@@ -191,16 +205,19 @@ library_jars := \
 # code doesn't reference the package anymore.  However, we do need to Proguard
 # against the deprecated package.  If we don't, Proguard -- which is a global
 # optimization -- sees Google libraries referencing "non-existent" libraries and
 # complains.  The solution is to mimic the `useLibraries` directive by declaring
 # the legacy package as a provided library jar.
 #
 # See https://bugzilla.mozilla.org/show_bug.cgi?id=1233238#c19 for symptoms and
 # more discussion.
+#
+# MOZ_ANDROID_MMA requires MOZ_INSTALL_TRACKING, so we don't need a
+# separate clause for MMA (Leanplum) support.
 ifdef MOZ_INSTALL_TRACKING
 library_jars += $(ANDROID_SDK)/optional/org.apache.http.legacy.jar
 endif # MOZ_INSTALL_TRACKING
 
 library_jars := $(subst $(NULL) ,:,$(strip $(library_jars)))
 
 gradle_dir := $(topobjdir)/gradle/build/mobile/android
 
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/MmaAndroidManifest_services.xml.in
@@ -0,0 +1,22 @@
+        <receiver android:name="com.leanplum.LeanplumPushReceiver" android:exported="false"
+            android:enabled="true">
+            <intent-filter>
+                <action android:name="com.leanplum.LeanplumPushListenerService" />
+            </intent-filter>
+        </receiver>
+
+        <!-- Leanplum Local Push Notification Service-->
+        <service android:name="com.leanplum.LeanplumLocalPushListenerService" android:exported="false"
+            android:enabled="false" />
+
+        <!-- Leanplum GCM Instance ID Service -->
+        <service android:name="com.leanplum.LeanplumPushInstanceIDService" android:exported="false"
+            android:enabled="false">
+            <intent-filter>
+                <action android:name="com.google.android.gms.iid.InstanceID" />
+            </intent-filter>
+        </service>
+
+        <!-- Leanplum GCM/FCM Registration Service -->
+        <service android:name="com.leanplum.LeanplumPushRegistrationService" android:exported="false"
+            android:enabled="false" />
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/MmaConstants.java.in
@@ -0,0 +1,38 @@
+//#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;
+
+import org.mozilla.gecko.mma.MmaInterface;
+//#ifdef MOZ_ANDROID_MMA
+import org.mozilla.gecko.mma.MmaLeanplumImp;
+//#else
+import org.mozilla.gecko.mma.MmaStubImp;
+//#endif
+
+public class MmaConstants {
+    public static final String MOZ_LEANPLUM_SDK_KEY =
+//#ifdef MOZ_LEANPLUM_SDK_KEY
+    "@MOZ_LEANPLUM_SDK_KEY@";
+//#else
+    null;
+//#endif
+
+public static final String MOZ_LEANPLUM_SDK_CLIENTID =
+//#ifdef MOZ_LEANPLUM_SDK_CLIENTID
+    "@MOZ_LEANPLUM_SDK_CLIENTID@";
+//#else
+    null;
+//#endif
+
+    public static MmaInterface getMma() {
+//#ifdef MOZ_ANDROID_MMA
+        return new MmaLeanplumImp();
+//#else
+        return new MmaStubImp();
+//#endif
+    }
+}
--- a/mobile/android/base/generate_build_config.py
+++ b/mobile/android/base/generate_build_config.py
@@ -40,16 +40,19 @@ def _defines():
                 'MOZ_ANDROID_ANR_REPORTER',
                 'MOZ_ANDROID_BEAM',
                 'MOZ_ANDROID_CUSTOM_TABS',
                 'MOZ_ANDROID_DOWNLOADS_INTEGRATION',
                 'MOZ_ANDROID_DOWNLOAD_CONTENT_SERVICE',
                 'MOZ_ANDROID_EXCLUDE_FONTS',
                 'MOZ_ANDROID_GCM',
                 'MOZ_ANDROID_MLS_STUMBLER',
+                'MOZ_ANDROID_MMA',
+                'MOZ_LEANPLUM_SDK_KEY',
+                'MOZ_LEANPLUM_SDK_CLIENTID',
                 'MOZ_ANDROID_SEARCH_ACTIVITY',
                 'MOZ_CRASHREPORTER',
                 'MOZ_DEBUG',
                 'MOZ_INSTALL_TRACKING',
                 'MOZ_LOCALE_SWITCHER',
                 'MOZ_NATIVE_DEVICES',
                 'MOZ_SWITCHBOARD'):
         if CONFIG[var]:
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -53,16 +53,17 @@ import org.mozilla.gecko.home.HomePager.
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.home.HomePanelsManager;
 import org.mozilla.gecko.home.HomeScreen;
 import org.mozilla.gecko.home.SearchEngine;
 import org.mozilla.gecko.icons.Icons;
 import org.mozilla.gecko.media.VideoPlayer;
 import org.mozilla.gecko.menu.GeckoMenu;
 import org.mozilla.gecko.menu.GeckoMenuItem;
+import org.mozilla.gecko.mma.MmaDelegate;
 import org.mozilla.gecko.mozglue.GeckoLoader;
 import org.mozilla.gecko.mozglue.SafeIntent;
 import org.mozilla.gecko.notifications.NotificationHelper;
 import org.mozilla.gecko.overlays.ui.ShareDialog;
 import org.mozilla.gecko.permissions.Permissions;
 import org.mozilla.gecko.preferences.ClearOnShutdownPref;
 import org.mozilla.gecko.preferences.GeckoPreferences;
 import org.mozilla.gecko.promotion.AddToHomeScreenPromotion;
@@ -868,28 +869,40 @@ public class BrowserApp extends GeckoApp
         final String installerPackageName = getPackageManager().getInstallerPackageName(getPackageName());
         Telemetry.sendUIEvent(TelemetryContract.Event.LAUNCH, TelemetryContract.Method.SYSTEM, "installer_" + installerPackageName);
     }
 
     /**
      * Initializes the default Switchboard URLs the first time.
      * @param intent
      */
-    private static void initSwitchboard(final Context context, final SafeIntent intent, final boolean isInAutomation) {
+    private void initSwitchboard(final Context context, final SafeIntent intent, final boolean isInAutomation) {
         if (isInAutomation) {
             Log.d(LOGTAG, "Switchboard disabled - in automation");
             return;
         } else if (!AppConstants.MOZ_SWITCHBOARD) {
             Log.d(LOGTAG, "Switchboard compile-time disabled");
             return;
         }
 
         final String serverExtra = intent.getStringExtra(INTENT_KEY_SWITCHBOARD_SERVER);
         final String serverUrl = TextUtils.isEmpty(serverExtra) ? SWITCHBOARD_SERVER : serverExtra;
-        new AsyncConfigLoader(context, serverUrl).execute();
+        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.getApplication());
+                }
+                return null;
+            }
+        }.execute();
     }
 
     private static void initTelemetryUploader(final boolean isInAutomation) {
         TelemetryUploadService.setDisabled(isInAutomation);
     }
 
     private void showUpdaterPermissionSnackbar() {
         SnackbarBuilder.SnackbarCallback allowCallback = new SnackbarBuilder.SnackbarCallback() {
--- a/mobile/android/base/java/org/mozilla/gecko/Experiments.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Experiments.java
@@ -66,16 +66,19 @@ public class Experiments {
     public static final String ACTIVITY_STREAM_OPT_OUT = "activity-stream-opt-out";
 
     // Tabs tray: Arrange tabs in two columns in portrait mode
     public static final String COMPACT_TABS = "compact-tabs";
 
     // Enable full bookmark management(full-page dialog, bookmark/folder modification, etc.)
     public static final String FULL_BOOKMARK_MANAGEMENT = "full-bookmark-management";
 
+    // Enable Leanplum SDK
+    public static final String LEANPLUM = "leanplum-start";
+
     /**
      * Returns if a user is in certain local experiment.
      * @param experiment Name of experiment to look up
      * @return returns value for experiment or false if experiment does not exist.
      */
     public static boolean isInExperimentLocal(Context context, String experiment) {
         if (SwitchBoard.isInBucket(context, 0, 20)) {
             return Experiments.ONBOARDING3_A.equals(experiment);
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -0,0 +1,27 @@
+//#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.Application;
+import android.content.Context;
+
+import org.mozilla.gecko.MmaConstants;
+
+
+public class MmaDelegate {
+
+    private static MmaInterface mmaHelper = MmaConstants.getMma();
+
+    public static void init(Application application) {
+        mmaHelper.init(application);
+    }
+
+    public void start(Context context) {
+        mmaHelper.start(context);
+    }
+
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaInterface.java
@@ -0,0 +1,22 @@
+//#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.Application;
+import android.content.Context;
+
+
+public interface MmaInterface {
+    void init(Application application);
+
+    void start(Context context);
+
+    void track(String leanplumEvent);
+
+    void track(String leanplumEvent, double value);
+
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
@@ -0,0 +1,52 @@
+//#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.Application;
+import android.content.Context;
+
+import com.leanplum.Leanplum;
+import com.leanplum.LeanplumActivityHelper;
+import com.leanplum.annotations.Parser;
+
+import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.MmaConstants;
+
+
+public class MmaLeanplumImp implements MmaInterface {
+    @Override
+    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);
+        }
+
+        Leanplum.start(application);
+    }
+
+    @Override
+    public void start(Context context) {
+
+    }
+
+    @Override
+    public void track(String leanplumEvent) {
+        Leanplum.track(leanplumEvent);
+
+    }
+
+    @Override
+    public void track(String leanplumEvent, double value) {
+        Leanplum.track(leanplumEvent, value);
+
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
@@ -0,0 +1,33 @@
+//#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.Application;
+import android.content.Context;
+
+
+public class MmaStubImp implements MmaInterface {
+    @Override
+    public void init(Application application) {
+
+    }
+
+    @Override
+    public void start(Context context) {
+
+    }
+
+    @Override
+    public void track(String leanplumEvent) {
+
+    }
+
+    @Override
+    public void track(String leanplumEvent, double value) {
+
+    }
+}
--- a/mobile/android/base/java/org/mozilla/gecko/switchboard/SwitchBoard.java
+++ b/mobile/android/base/java/org/mozilla/gecko/switchboard/SwitchBoard.java
@@ -91,17 +91,17 @@ public class SwitchBoard {
 
     /**
      * Loads a new config for a user. This method does network I/O, so it
      * should not be called on the main thread.
      *
      * @param c ApplicationContext
      * @param serverUrl Server URL endpoint.
      */
-    static void loadConfig(Context c, @NonNull String serverUrl) {
+    public static void loadConfig(Context c, @NonNull String serverUrl) {
         final URL url;
         try {
             url = new URL(serverUrl);
         } catch (MalformedURLException e) {
             Log.e(TAG, "Exception creating server URL", e);
             return;
         }
 
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -114,26 +114,30 @@ with Files('resources/menu/browsersearch
 
 DIRS += ['locales']
 
 GENERATED_FILES += [
     '../geckoview/generated/preprocessed/org/mozilla/geckoview/BuildConfig.java',
     'AndroidManifest.xml',
     'generated/preprocessed/org/mozilla/gecko/AdjustConstants.java',
     'generated/preprocessed/org/mozilla/gecko/AppConstants.java',
+    'generated/preprocessed/org/mozilla/gecko/MmaConstants.java',
 ]
 w = GENERATED_FILES['../geckoview/generated/preprocessed/org/mozilla/geckoview/BuildConfig.java']
 w.script = 'generate_build_config.py:generate_java'
 w.inputs += ['../geckoview/BuildConfig.java.in']
 x = GENERATED_FILES['generated/preprocessed/org/mozilla/gecko/AdjustConstants.java']
 x.script = 'generate_build_config.py:generate_java'
 x.inputs += ['AdjustConstants.java.in']
 y = GENERATED_FILES['generated/preprocessed/org/mozilla/gecko/AppConstants.java']
 y.script = 'generate_build_config.py:generate_java'
 y.inputs += ['AppConstants.java.in']
+y = GENERATED_FILES['generated/preprocessed/org/mozilla/gecko/MmaConstants.java']
+y.script = 'generate_build_config.py:generate_java'
+y.inputs += ['MmaConstants.java.in']
 z = GENERATED_FILES['AndroidManifest.xml']
 z.script = 'generate_build_config.py:generate_android_manifest'
 z.inputs += ['AndroidManifest.xml.in']
 
 include('android-services.mozbuild')
 
 geckoview_source_dir = TOPSRCDIR + '/mobile/android/geckoview/src/main/'
 geckoview_thirdparty_source_dir = TOPSRCDIR + '/mobile/android/geckoview/src/thirdparty/'
@@ -149,21 +153,23 @@ constants_jar.sources += [geckoview_sour
     'SysInfo.java',
 ]]
 constants_jar.sources += ['java/org/mozilla/gecko/' + x for x in [
     'adjust/AdjustHelperInterface.java',
     'adjust/AttributionHelperListener.java',
     'db/BrowserContract.java',
     'LocaleManager.java',
     'Locales.java',
+    'mma/MmaInterface.java',
 ]]
 constants_jar.generated_sources = [
     '../geckoview/generated/preprocessed/org/mozilla/geckoview/BuildConfig.java',
     'generated/preprocessed/org/mozilla/gecko/AdjustConstants.java',
     'generated/preprocessed/org/mozilla/gecko/AppConstants.java',
+    'generated/preprocessed/org/mozilla/gecko/MmaConstants.java',
 ]
 constants_jar.extra_jars = [
     CONFIG['ANDROID_SUPPORT_ANNOTATIONS_JAR_LIB'],
     CONFIG['ANDROID_SUPPORT_V4_AAR_LIB'],
     CONFIG['ANDROID_SUPPORT_V4_AAR_INTERNAL_LIB'],
     CONFIG['ANDROID_APPCOMPAT_V7_AAR_LIB'],
 ]
 
@@ -174,16 +180,28 @@ if CONFIG['MOZ_INSTALL_TRACKING']:
     constants_jar.extra_jars += [
         'gecko-thirdparty-adjust_sdk.jar',
     ]
 else:
     constants_jar.sources += ['java/org/mozilla/gecko/' + x for x in [
         'adjust/StubAdjustHelper.java',
     ]]
 
+if CONFIG['MOZ_ANDROID_MMA']:
+    constants_jar.sources += ['java/org/mozilla/gecko/' + x for x in [
+        'mma/MmaLeanplumImp.java',
+    ]]
+    constants_jar.extra_jars += [
+        'gecko-thirdparty-leanplum_sdk.jar'
+    ]
+else:
+    constants_jar.sources += ['java/org/mozilla/gecko/' + x for x in [
+        'mma/MmaStubImp.java',
+    ]]
+
 resjar = add_java_jar('gecko-R')
 resjar.sources = []
 resjar.generated_sources += [
     'generated/org/mozilla/gecko/R.java',
 ]
 
 if CONFIG['ANDROID_SUPPORT_V4_AAR']:
     ANDROID_EXTRA_PACKAGES += ['android.support.v4']
@@ -744,16 +762,17 @@ gbjar.sources += ['java/org/mozilla/geck
     'menu/GeckoMenuInflater.java',
     'menu/GeckoMenuItem.java',
     'menu/GeckoSubMenu.java',
     'menu/MenuItemActionBar.java',
     'menu/MenuItemDefault.java',
     'menu/MenuItemSwitcherLayout.java',
     'menu/MenuPanel.java',
     'menu/MenuPopup.java',
+    'mma/MmaDelegate.java',
     'MotionEventInterceptor.java',
     'notifications/NotificationClient.java',
     'notifications/NotificationHelper.java',
     'notifications/NotificationReceiver.java',
     'notifications/NotificationService.java',
     'notifications/WhatsNewReceiver.java',
     'overlays/OverlayConstants.java',
     'overlays/service/OverlayActionService.java',
@@ -972,17 +991,17 @@ gbjar.sources += ['java/org/mozilla/geck
     'widget/themed/ThemedView.java',
 ]]
 android_package_dir = CONFIG['ANDROID_PACKAGE_NAME'].replace('.', '/')
 gbjar.generated_sources = [] # Keep it this way.
 gbjar.extra_jars += [
     CONFIG['ANDROID_SUPPORT_ANNOTATIONS_JAR_LIB'],
     CONFIG['ANDROID_SUPPORT_V4_AAR_LIB'],
     CONFIG['ANDROID_SUPPORT_V4_AAR_INTERNAL_LIB'],
-    'constants.jar'
+    'constants.jar',
 ]
 if CONFIG['MOZ_CRASHREPORTER']:
     gbjar.sources += [ 'java/org/mozilla/gecko/CrashReporter.java' ]
     ANDROID_RES_DIRS += [ 'crashreporter/res' ]
 
 if CONFIG['MOZ_ANDROID_GCM']:
     gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
         'gcm/GcmInstanceIDListenerService.java',
@@ -1207,16 +1226,132 @@ if CONFIG['MOZ_INSTALL_TRACKING']:
         'com/adjust/sdk/RequestHandler.java',
         'com/adjust/sdk/UnitTestActivity.java',
         'com/adjust/sdk/Util.java'
     ] ]
     adjustjar.extra_jars += [
         'sync-thirdparty.jar',
     ]
 
+
+if CONFIG['MOZ_ANDROID_MMA']:
+    lpjar = add_java_jar('gecko-thirdparty-leanplum_sdk')
+    lpjar.sources += [ thirdparty_source_dir + f for f in [
+        'com/leanplum/ActionArgs.java',
+        'com/leanplum/ActionContext.java',
+        'com/leanplum/activities/LeanplumAccountAuthenticatorActivity.java',
+        'com/leanplum/activities/LeanplumActionBarActivity.java',
+        'com/leanplum/activities/LeanplumActivity.java',
+        'com/leanplum/activities/LeanplumActivityGroup.java',
+        'com/leanplum/activities/LeanplumAliasActivity.java',
+        'com/leanplum/activities/LeanplumAppCompatActivity.java',
+        'com/leanplum/activities/LeanplumExpandableListActivity.java',
+        'com/leanplum/activities/LeanplumFragmentActivity.java',
+        'com/leanplum/activities/LeanplumLauncherActivity.java',
+        'com/leanplum/activities/LeanplumListActivity.java',
+        'com/leanplum/activities/LeanplumNativeActivity.java',
+        'com/leanplum/activities/LeanplumPreferenceActivity.java',
+        'com/leanplum/activities/LeanplumTabActivity.java',
+        'com/leanplum/annotations/File.java',
+        'com/leanplum/annotations/Parser.java',
+        'com/leanplum/annotations/Variable.java',
+        'com/leanplum/CacheUpdateBlock.java',
+        'com/leanplum/callbacks/ActionCallback.java',
+        'com/leanplum/callbacks/InboxChangedCallback.java',
+        'com/leanplum/callbacks/NewsfeedChangedCallback.java',
+        'com/leanplum/callbacks/PostponableAction.java',
+        'com/leanplum/callbacks/RegisterDeviceCallback.java',
+        'com/leanplum/callbacks/RegisterDeviceFinishedCallback.java',
+        'com/leanplum/callbacks/StartCallback.java',
+        'com/leanplum/callbacks/VariableCallback.java',
+        'com/leanplum/callbacks/VariablesChangedCallback.java',
+        'com/leanplum/internal/ActionArg.java',
+        'com/leanplum/internal/ActionManager.java',
+        'com/leanplum/internal/AESCrypt.java',
+        'com/leanplum/internal/BaseActionContext.java',
+        'com/leanplum/internal/CollectionUtil.java',
+        'com/leanplum/internal/Constants.java',
+        'com/leanplum/internal/FileManager.java',
+        'com/leanplum/internal/HybiParser.java',
+        'com/leanplum/internal/JsonConverter.java',
+        'com/leanplum/internal/LeanplumInternal.java',
+        'com/leanplum/internal/LeanplumManifestHelper.java',
+        'com/leanplum/internal/LeanplumManifestParser.java',
+        'com/leanplum/internal/LeanplumMessageMatchFilter.java',
+        'com/leanplum/internal/LeanplumUIEditorWrapper.java',
+        'com/leanplum/internal/Log.java',
+        'com/leanplum/internal/OsHandler.java',
+        'com/leanplum/internal/Registration.java',
+        'com/leanplum/internal/Request.java',
+        'com/leanplum/internal/RequestFactory.java',
+        'com/leanplum/internal/ResourceQualifiers.java',
+        'com/leanplum/internal/Socket.java',
+        'com/leanplum/internal/SocketIOClient.java',
+        'com/leanplum/internal/Util.java',
+        'com/leanplum/internal/VarCache.java',
+        'com/leanplum/internal/WebSocketClient.java',
+        'com/leanplum/Leanplum.java',
+        'com/leanplum/LeanplumActivityHelper.java',
+        'com/leanplum/LeanplumApplication.java',
+        'com/leanplum/LeanplumCloudMessagingProvider.java',
+        'com/leanplum/LeanplumDeviceIdMode.java',
+        'com/leanplum/LeanplumEditorMode.java',
+        'com/leanplum/LeanplumException.java',
+        'com/leanplum/LeanplumGcmProvider.java',
+        'com/leanplum/LeanplumInbox.java',
+        'com/leanplum/LeanplumInboxMessage.java',
+        'com/leanplum/LeanplumInflater.java',
+        'com/leanplum/LeanplumLocalPushListenerService.java',
+        'com/leanplum/LeanplumLocationAccuracyType.java',
+        'com/leanplum/LeanplumManualProvider.java',
+        'com/leanplum/LeanplumPushInstanceIDService.java',
+        'com/leanplum/LeanplumPushListenerService.java',
+        'com/leanplum/LeanplumPushNotificationCustomizer.java',
+        'com/leanplum/LeanplumPushReceiver.java',
+        'com/leanplum/LeanplumPushRegistrationService.java',
+        'com/leanplum/LeanplumPushService.java',
+        'com/leanplum/LeanplumResources.java',
+        'com/leanplum/LeanplumUIEditor.java',
+        'com/leanplum/LocationManager.java',
+        'com/leanplum/messagetemplates/Alert.java',
+        'com/leanplum/messagetemplates/BaseMessageDialog.java',
+        'com/leanplum/messagetemplates/BaseMessageOptions.java',
+        'com/leanplum/messagetemplates/CenterPopup.java',
+        'com/leanplum/messagetemplates/CenterPopupOptions.java',
+        'com/leanplum/messagetemplates/Confirm.java',
+        'com/leanplum/messagetemplates/HTMLOptions.java',
+        'com/leanplum/messagetemplates/HTMLTemplate.java',
+        'com/leanplum/messagetemplates/Interstitial.java',
+        'com/leanplum/messagetemplates/InterstitialOptions.java',
+        'com/leanplum/messagetemplates/MessageTemplates.java',
+        'com/leanplum/messagetemplates/OpenURL.java',
+        'com/leanplum/messagetemplates/WebInterstitial.java',
+        'com/leanplum/messagetemplates/WebInterstitialOptions.java',
+        'com/leanplum/Newsfeed.java',
+        'com/leanplum/NewsfeedMessage.java',
+        'com/leanplum/UIEditorBridge.java',
+        'com/leanplum/utils/BitmapUtil.java',
+        'com/leanplum/utils/SharedPreferencesUtil.java',
+        'com/leanplum/utils/SizeUtil.java',
+        'com/leanplum/Var.java',
+        'com/leanplum/views/BackgroundImageView.java',
+        'com/leanplum/views/CloseButton.java',
+    ] ]
+    lpjar.extra_jars += [
+        CONFIG['ANDROID_APPCOMPAT_V7_AAR_LIB'],
+        CONFIG['ANDROID_PLAY_SERVICES_ADS_AAR_LIB'],
+        CONFIG['ANDROID_PLAY_SERVICES_BASEMENT_AAR_LIB'],
+        CONFIG['ANDROID_PLAY_SERVICES_BASE_AAR_LIB'],
+        CONFIG['ANDROID_PLAY_SERVICES_GCM_AAR_LIB'],
+        CONFIG['ANDROID_SUPPORT_ANNOTATIONS_JAR_LIB'],
+        CONFIG['ANDROID_SUPPORT_V4_AAR_INTERNAL_LIB'],
+        CONFIG['ANDROID_SUPPORT_V4_AAR_LIB'],
+        'sync-thirdparty.jar',
+    ]
+
 # Putting branding earlier allows branders to override default resources.
 ANDROID_RES_DIRS += [
     '/' + CONFIG['MOZ_BRANDING_DIRECTORY'] + '/res',
     'resources',
     '/mobile/android/services/src/main/res',
     '!res',
 ]
 
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -92,18 +92,19 @@ android {
 
 dependencies {
     compile "com.android.support:support-v4:${mozconfig.substs.ANDROID_SUPPORT_LIBRARY_VERSION}"
 }
 
 task syncPreprocessedCode(type: Sync, dependsOn: rootProject.generateCodeAndResources) {
     into("${project.buildDir}/generated/source/preprocessed_code")
     from("${topobjdir}/mobile/android/base/generated/preprocessed") {
-        // AdjustConstants is included in the main app project.
+        // These constants files are included in the main app project.
         exclude '**/AdjustConstants.java'
+        exclude '**/MmaConstants.java'
     }
 }
 
 apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
 
 android.libraryVariants.all { variant ->
     variant.preBuild.dependsOn syncPreprocessedCode