Bug 1234629 - Create bouncer APK for OTA distribution installs. f?margaret draft
authorNick Alexander <nalexander@mozilla.com>
Tue, 22 Dec 2015 14:33:58 -0800
changeset 319108 a6572b6352d32f51eb6c67829b81f194297fc61f
parent 319077 892c469f9513cb053876991b2794feea21502601
child 319109 d3621b5921b367e414d62e251b3b763459b82486
push id8973
push usermleibovic@mozilla.com
push dateTue, 05 Jan 2016 20:54:12 +0000
bugs1234629
milestone46.0a1
Bug 1234629 - Create bouncer APK for OTA distribution installs. f?margaret margaret, over to you. You'll want to hack up the mobile/android/bouncer/AndroidManifest.xml.in to register the BouncerActivity, and add whatever intent handlers are appropriate for the distribution copying code. I'm hard-coding the APK version to 1, so you'll always be able to install any Fennec APK over top. Rebuild with |mach build mobile/android/bouncer|. Run |mach package| to get $OBJDIR/dist/bouncer.apk. Use |adb install| to install. We can add the support-v4 or appcompat-v7 libraries if we need, but it's not trivial.
configure.in
mobile/android/bouncer/AndroidManifest.xml.in
mobile/android/bouncer/Makefile.in
mobile/android/bouncer/java/org/mozilla/bouncer/BouncerActivity.java
mobile/android/bouncer/moz.build
mobile/android/bouncer/res/drawable-v21/logo.xml
mobile/android/bouncer/res/drawable/logo.xml
mobile/android/confvars.sh
mobile/android/moz.build
toolkit/mozapps/installer/upload-files.mk
--- a/configure.in
+++ b/configure.in
@@ -8501,16 +8501,17 @@ AC_SUBST(MOZ_ANDROID_HISTORY)
 AC_SUBST(MOZ_WEBSMS_BACKEND)
 AC_SUBST(MOZ_ANDROID_BEAM)
 AC_SUBST(MOZ_LOCALE_SWITCHER)
 AC_SUBST(MOZ_DISABLE_GECKOVIEW)
 AC_SUBST(MOZ_ANDROID_GCM)
 AC_SUBST(MOZ_ANDROID_GECKOLIBS_AAR)
 AC_SUBST(MOZ_ANDROID_READING_LIST_SERVICE)
 AC_SUBST(MOZ_ANDROID_SEARCH_ACTIVITY)
+AC_SUBST(MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER)
 AC_SUBST(MOZ_ANDROID_MLS_STUMBLER)
 AC_SUBST(MOZ_ANDROID_DOWNLOADS_INTEGRATION)
 AC_SUBST(MOZ_ANDROID_APPLICATION_CLASS)
 AC_SUBST(MOZ_ANDROID_BROWSER_INTENT_CLASS)
 AC_SUBST(MOZ_ANDROID_SEARCH_INTENT_CLASS)
 AC_SUBST(MOZ_ANDROID_DOWNLOAD_CONTENT_SERVICE)
 AC_SUBST(MOZ_EXCLUDE_HYPHENATION_DICTIONARIES)
 AC_SUBST(MOZ_INSTALL_TRACKING)
new file mode 100644
--- /dev/null
+++ b/mobile/android/bouncer/AndroidManifest.xml.in
@@ -0,0 +1,34 @@
+#filter substitution
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="@ANDROID_PACKAGE_NAME@"
+      android:installLocation="auto"
+      android:versionCode="@ANDROID_VERSION_CODE@"
+      android:versionName="@MOZ_APP_VERSION@"
+#ifdef MOZ_ANDROID_SHARED_ID
+      android:sharedUserId="@MOZ_ANDROID_SHARED_ID@"
+#endif
+      >
+    <uses-sdk android:minSdkVersion="@MOZ_ANDROID_MIN_SDK_VERSION@"
+#ifdef MOZ_ANDROID_MAX_SDK_VERSION
+              android:maxSdkVersion="@MOZ_ANDROID_MAX_SDK_VERSION@"
+#endif
+              android:targetSdkVersion="22"/>
+
+
+    <application android:label="@string/moz_app_displayname"
+                 android:icon="@drawable/icon"
+                 android:logo="@drawable/logo"
+                 android:hardwareAccelerated="true"
+                 android:allowBackup="false"
+# The preprocessor does not yet support arbitrary parentheses, so this cannot
+# be parenthesized thus to clarify that the logical AND operator has precedence:
+#   !defined(MOZILLA_OFFICIAL) || (defined(NIGHTLY_BUILD) && defined(MOZ_DEBUG))
+#if !defined(MOZILLA_OFFICIAL) || defined(NIGHTLY_BUILD) && defined(MOZ_DEBUG)
+                 android:debuggable="true">
+#else
+                 android:debuggable="false">
+#endif
+
+    </application>
+</manifest>
copy from mobile/android/javaaddons/Makefile.in
copy to mobile/android/bouncer/Makefile.in
--- a/mobile/android/javaaddons/Makefile.in
+++ b/mobile/android/bouncer/Makefile.in
@@ -1,9 +1,22 @@
 # 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/.
 
-include $(topsrcdir)/config/rules.mk
+include $(topsrcdir)/config/config.mk
+
+JAVAFILES := \
+	java/org/mozilla/bouncer/BouncerActivity.java \
+  $(NULL)
+
+ANDROID_EXTRA_JARS := \
+  $(NULL)
 
-include $(topsrcdir)/config/android-common.mk
+PP_TARGETS += manifest
+manifest := $(srcdir)/AndroidManifest.xml.in
+manifest_TARGET := export
+# Special 'cuz it's set in mobile/android/defs.mk.
+manifest_FLAGS += \
+  -DMOZ_ANDROID_SHARED_ID='$(ANDROID_PACKAGE_NAME).sharedID' \
+  $(NULL)
 
-libs:: javaaddons-1.0.jar
+libs:: $(ANDROID_APK_NAME).apk
copy from mobile/android/javaaddons/java/org/mozilla/javaaddons/JavaAddonInterfaceV1.java
copy to mobile/android/bouncer/java/org/mozilla/bouncer/BouncerActivity.java
--- a/mobile/android/javaaddons/java/org/mozilla/javaaddons/JavaAddonInterfaceV1.java
+++ b/mobile/android/bouncer/java/org/mozilla/bouncer/BouncerActivity.java
@@ -1,51 +1,11 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; 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.javaaddons;
-
-import android.content.Context;
-import org.json.JSONObject;
-
-public interface JavaAddonInterfaceV1 {
-    /**
-     * Callback interface for Gecko requests.
-     * <p/>
-     * For each instance of EventCallback, exactly one of sendResponse, sendError, must be called to prevent observer leaks.
-     * If more than one send* method is called, or if a single send method is called multiple times, an
-     * {@link IllegalStateException} will be thrown.
-     */
-    interface EventCallback {
-        /**
-         * Sends a success response with the given data.
-         *
-         * @param response The response data to send to Gecko. Can be any of the types accepted by
-         *                 JSONObject#put(String, Object).
-         */
-        public void sendSuccess(Object response);
+package org.mozilla.bouncer;
 
-        /**
-         * Sends an error response with the given data.
-         *
-         * @param response The response data to send to Gecko. Can be any of the types accepted by
-         *                 JSONObject#put(String, Object).
-         */
-        public void sendError(Object response);
-    }
+import android.app.Activity;
 
-    interface EventDispatcher {
-        void registerEventListener(EventListener listener, String... events);
-        void unregisterEventListener(EventListener listener);
-
-        void sendRequestToGecko(String event, JSONObject message, RequestCallback callback);
-    }
-
-    interface EventListener {
-        public void handleMessage(final Context context, final String event, final JSONObject message, final EventCallback callback);
-    }
-
-    interface RequestCallback {
-        void onResponse(final Context context, JSONObject jsonObject);
-    }
+public class BouncerActivity extends Activity {
 }
copy from mobile/android/javaaddons/moz.build
copy to mobile/android/bouncer/moz.build
--- a/mobile/android/javaaddons/moz.build
+++ b/mobile/android/bouncer/moz.build
@@ -1,11 +1,21 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
-jar = add_java_jar('javaaddons-1.0')
-jar.sources = [
-    'java/org/mozilla/javaaddons/JavaAddonInterfaceV1.java',
+DEFINES['ANDROID_VERSION_CODE'] = '1'
+
+for var in ('ANDROID_PACKAGE_NAME',
+            'MOZ_APP_VERSION'):
+    DEFINES[var] = CONFIG[var]
+
+ANDROID_APK_NAME = 'bouncer'
+ANDROID_APK_PACKAGE = CONFIG['ANDROID_PACKAGE_NAME']
+
+# Putting branding earlier allows branders to override default resources.
+ANDROID_RES_DIRS += [
+    '/' + CONFIG['MOZ_BRANDING_DIRECTORY'] + '/res', # For the icon.
+    'res',
+    '!/mobile/android/base/res', # For strings.
 ]
-jar.javac_flags += ['-Xlint:all']
copy from mobile/android/base/resources/drawable-v21/logo.xml
copy to mobile/android/bouncer/res/drawable-v21/logo.xml
copy from mobile/android/base/resources/drawable/logo.xml
copy to mobile/android/bouncer/res/drawable/logo.xml
--- a/mobile/android/confvars.sh
+++ b/mobile/android/confvars.sh
@@ -88,16 +88,19 @@ MOZ_WEBGL_CONFORMANT=1
 MOZ_ANDROID_SEARCH_ACTIVITY=1
 
 # Enable the Mozilla Location Service stumbler.
 MOZ_ANDROID_MLS_STUMBLER=1
 
 # Enable adding to the system downloads list.
 MOZ_ANDROID_DOWNLOADS_INTEGRATION=1
 
+# Build and package the install bouncer APK by default.
+MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER=1
+
 # Use the low-memory GC tuning.
 export JS_GC_SMALL_CHUNK_SIZE=1
 
 # Enable GCM registration on Nightly builds only.
 if test "$NIGHTLY_BUILD"; then
   MOZ_ANDROID_GCM=1
 fi
 
--- a/mobile/android/moz.build
+++ b/mobile/android/moz.build
@@ -22,15 +22,18 @@ DIRS += [
     'modules',
     'themes/core',
     'app',
     'fonts',
     'geckoview_library',
     'extensions',
 ]
 
+if CONFIG['MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER']:
+    DIRS += ['bouncer'] # Must be built after base to consume generated resources.
+
 DIRS += ['../../xulrunner/tools/redit']
 
 TEST_DIRS += [
     'tests',
 ]
 
 SPHINX_TREES['fennec'] = 'docs'
--- a/toolkit/mozapps/installer/upload-files.mk
+++ b/toolkit/mozapps/installer/upload-files.mk
@@ -340,16 +340,26 @@ ROBOCOP_PATH = $(topobjdir)/mobile/andro
 INNER_ROBOCOP_PACKAGE= \
   cp $(GECKO_APP_AP_PATH)/fennec_ids.txt $(ABS_DIST) && \
   $(call RELEASE_SIGN_ANDROID_APK,$(ROBOCOP_PATH)/robocop-debug-unsigned-unaligned.apk,$(ABS_DIST)/robocop.apk)
 endif
 else
 INNER_ROBOCOP_PACKAGE=echo 'Testing is disabled - No Android Robocop for you'
 endif
 
+ifdef MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER
+UPLOAD_EXTRA_FILES += bouncer.apk
+
+# Package and release sign the install bouncer APK.
+INNER_INSTALL_BOUNCER_PACKAGE=\
+  $(call RELEASE_SIGN_ANDROID_APK,$(abspath $(DEPTH)/mobile/android/bouncer/bouncer-unsigned-unaligned.apk),$(_ABS_DIST)/bouncer.apk)
+else
+INNER_INSTALL_BOUNCER_PACKAGE=echo 'Install bouncer is disabled - No trampolines for you'
+endif # MOZ_ANDROID_PACKAGE_INSTALL_BOUNCER
+
 # Create geckoview_library/geckoview_{assets,library}.zip for third-party GeckoView consumers.
 ifdef NIGHTLY_BUILD
 ifndef MOZ_DISABLE_GECKOVIEW
 INNER_MAKE_GECKOVIEW_LIBRARY= \
   $(MAKE) -C ../mobile/android/geckoview_library package
 INNER_MAKE_GECKOVIEW_EXAMPLE= \
 	$(MAKE) -C ../embedding/android/geckoview_example package
 else
@@ -484,16 +494,17 @@ INNER_MAKE_PACKAGE	= \
   $(INNER_SZIP_LIBRARIES) && \
   make -C $(GECKO_APP_AP_PATH) gecko-nodeps.ap_ && \
   cp $(GECKO_APP_AP_PATH)/gecko-nodeps.ap_ $(ABS_DIST)/gecko.ap_ && \
   ( (test ! -f $(GECKO_APP_AP_PATH)/R.txt && echo "*** Warning: The R.txt that is being packaged might not agree with the R.txt that was built. This is normal during l10n repacks.") || \
     diff $(GECKO_APP_AP_PATH)/R.txt $(GECKO_APP_AP_PATH)/gecko-nodeps/R.txt >/dev/null || \
     (echo "*** Error: The R.txt that was built and the R.txt that is being packaged are not the same. Rebuild mobile/android/base and re-package." && exit 1)) && \
   $(INNER_MAKE_APK) && \
   $(INNER_ROBOCOP_PACKAGE) && \
+  $(INNER_INSTALL_BOUNCER_PACKAGE) && \
   $(INNER_MAKE_GECKOLIBS_AAR) && \
   $(INNER_MAKE_GECKOVIEW_LIBRARY) && \
   $(INNER_MAKE_GECKOVIEW_EXAMPLE)
 endif
 
 ifeq ($(MOZ_BUILD_APP),mobile/android/b2gdroid)
 INNER_MAKE_PACKAGE	= \
   $(INNER_SZIP_LIBRARIES) && \