Bug 1351581 - Add build flag to inject mma implementation. r?maliu,sebastian,nalexander draft
authorcnevinc <cnevinc@livemail.tw>
Thu, 11 May 2017 23:48:53 -0700
changeset 576972 d73e8e44ff5788ebc20f7e3f3a0e9af8f027ddf3
parent 576736 5864d02edca03050038820b38657c85258d53d56
child 628377 2f02d2cbac5bad4fe000b806d7cc84f7ab6eb3a3
push id58553
push userbmo:cnevinchen@gmail.com
push dateFri, 12 May 2017 15:38:13 +0000
reviewersmaliu, sebastian, nalexander
bugs1351581
milestone55.0a1
Bug 1351581 - Add build flag to inject mma implementation. r?maliu,sebastian,nalexander MozReview-Commit-ID: HEUPLEaE7tN
mobile/android/app/build.gradle
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/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/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_INSTALL_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
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/MmaConstants.java.in
@@ -0,0 +1,31 @@
+//#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_INSTALL_MMA
+import org.mozilla.gecko.mma.MmaLeanplumImp;
+//#else
+import org.mozilla.gecko.mma.MmaStubImp;
+//#endif
+
+public class MmaConstants {
+    public static final String MOZ_INSTALL_MMA_SDK_APP_TOKEN =
+//#ifdef MOZ_INSTALL_MMA_SDK_APP_TOKEN
+    "@MOZ_INSTALL_MMA_SDK_APP_TOKEN@";
+//#else
+    null;
+//#endif
+
+    public static MmaInterface getMma() {
+//#ifdef MOZ_INSTALL_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
@@ -44,16 +44,17 @@ def _defines():
                 'MOZ_ANDROID_DOWNLOAD_CONTENT_SERVICE',
                 'MOZ_ANDROID_EXCLUDE_FONTS',
                 'MOZ_ANDROID_GCM',
                 'MOZ_ANDROID_MLS_STUMBLER',
                 'MOZ_ANDROID_SEARCH_ACTIVITY',
                 'MOZ_CRASHREPORTER',
                 'MOZ_DEBUG',
                 'MOZ_INSTALL_TRACKING',
+                'MOZ_INSTALL_MMA'
                 'MOZ_LOCALE_SWITCHER',
                 'MOZ_NATIVE_DEVICES',
                 'MOZ_SWITCHBOARD'):
         if CONFIG[var]:
             DEFINES[var] = 1
 
     for var in ('MOZ_ANDROID_GCM_SENDERID',
                 'MOZ_PKG_SPECIAL',
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -54,16 +54,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;
@@ -879,16 +880,17 @@ public class BrowserApp extends GeckoApp
         final String serverUrl = TextUtils.isEmpty(serverExtra) ? SWITCHBOARD_SERVER : serverExtra;
         new AsyncConfigLoader(context, serverUrl) {
             @Override
             protected Void doInBackground(Void... params) {
                 super.doInBackground(params);
                 if (SwitchBoard.isInExperiment(context, Experiments.LEANPLUM) &&
                         GeckoPreferences.getBooleanPref(context, GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true)) {
                     // Do LeanPlum start/init here
+                    MmaDelegate.init(context.getApplicationContext());
                 }
                 return null;
             }
         }.execute();
     }
 
     private static void initTelemetryUploader(final boolean isInAutomation) {
         TelemetryUploadService.setDisabled(isInAutomation);
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -0,0 +1,40 @@
+//#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.content.Context;
+
+import org.mozilla.gecko.MmaConstants;
+
+
+public class MmaDelegate {
+
+    private static MmaInterface mmaHelper = MmaConstants.getMma();
+
+    public static String FIRST_RUN = "First Run";
+    public static String SECOND_RUN = "Second Run";
+    public static String OPENED_APP = "Opened App";
+    public static String OPENED_LOGIN_MANAGER = "Opened Login Manager";
+    public static String OPENED_BOOKMARK = "Opened Bookmark";
+    public static String OPENED_NEW_TAB = "Opened New Tab";
+    public static String INTERACT_WITH_SEARCH_URL_AREA = "Interact With Search URL Area";
+    public static String SAVED_BOOKMARK = "saved bookmark";
+    public static String OPENED_TELEPHONE_LINK = "Opened Telephone Link";
+    public static String OPENED_MAILTO_LINK = "Opened Mailto Link";
+    public static String SAVED_IMAGE = "Download Media - Saved Image";
+    public static String CLEAR_PRIVATE_DATA = "Closed Private Tabs When Leaving Private Browsing";
+    public static String CLOSED_PRIVATE_TABS = "Closed Private Tabs";
+    public static String SAVED_LOGIN_AND_PASSWORD = "Saved Login and Password";
+
+    public static void init(Context context) {
+        mmaHelper.init(context);
+    }
+
+    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,16 @@
+//#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.content.Context;
+
+
+public interface MmaInterface {
+    void init(Context context);
+
+    void start(Context context);
+
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
@@ -0,0 +1,19 @@
+//#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.content.Context;
+
+
+public class MmaLeanplumImp implements MmaInterface {
+    @Override public void init(Context context) {
+
+    }
+
+    @Override public void start(Context context) {
+
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
@@ -0,0 +1,19 @@
+//#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.content.Context;
+
+
+public class MmaStubImp implements MmaInterface {
+    @Override public void init(Context context) {
+
+    }
+
+    @Override public void start(Context context) {
+
+    }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -114,26 +114,32 @@ 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']
+
+y1 = GENERATED_FILES['generated/preprocessed/org/mozilla/gecko/MmaConstants.java']
+y1.script = 'generate_build_config.py:generate_java'
+y1.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 +155,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 +182,25 @@ 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_INSTALL_MMA']:
+    constants_jar.sources += ['java/org/mozilla/gecko/' + x for x in [
+        'mma/MmaLeanplumImp.java',
+    ]]
+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']
@@ -740,16 +757,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',
--- a/mobile/android/geckoview/build.gradle
+++ b/mobile/android/geckoview/build.gradle
@@ -94,16 +94,17 @@ 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.
         exclude '**/AdjustConstants.java'
+        exclude '**/MmaConstants.java'
     }
 }
 
 apply from: "${topsrcdir}/mobile/android/gradle/with_gecko_binaries.gradle"
 
 android.libraryVariants.all { variant ->
     variant.preBuild.dependsOn syncPreprocessedCode