Bug 1291385 - 1. Remove geckoview dependency on certain GeckoApp constants; r=sebastian
authorJim Chen <nchen@mozilla.com>
Wed, 14 Sep 2016 12:43:36 -0400
changeset 313942 403103b3b8650b27f945c97ec41ec2d46036aeba
parent 313941 74422ceb5af227175a0c42d91c33b936d1568811
child 313943 88e521197760c92f2f688d4223915844a0a66c69
push id81749
push usernchen@mozilla.com
push dateWed, 14 Sep 2016 16:44:09 +0000
treeherdermozilla-inbound@7fe478cdf45a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1291385
milestone51.0a1
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
Bug 1291385 - 1. Remove geckoview dependency on certain GeckoApp constants; r=sebastian Code in geckoview depends on several string constants in GeckoApp. This patch moves PREFS_OOM_EXCEPTION and ACTION_ALERT_CALLBACK from GeckoApp to GeckoAppShell, to reverse the dependency. Ideally, we'd want those constants to not be used or used differently in geckoview code, but this is a quick workaround for now. GeckoThread uses GeckoApp.ACTION_HOMESCREEN_SHORTCUT, but that block of code is actually obsolete, so this patch removes the code block and the dependency.
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/health/SessionInformation.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -132,30 +132,28 @@ public abstract class GeckoApp
     GeckoMenu.MenuPresenter,
     NativeEventListener,
     Tabs.OnTabsChangedListener,
     ViewTreeObserver.OnGlobalLayoutListener {
 
     private static final String LOGTAG = "GeckoApp";
     private static final long ONE_DAY_MS = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
 
-    public static final String ACTION_ALERT_CALLBACK       = "org.mozilla.gecko.ACTION_ALERT_CALLBACK";
     public static final String ACTION_HOMESCREEN_SHORTCUT  = "org.mozilla.gecko.BOOKMARK";
     public static final String ACTION_DEBUG                = "org.mozilla.gecko.DEBUG";
     public static final String ACTION_LAUNCH_SETTINGS      = "org.mozilla.gecko.SETTINGS";
     public static final String ACTION_LOAD                 = "org.mozilla.gecko.LOAD";
     public static final String ACTION_INIT_PW              = "org.mozilla.gecko.INIT_PW";
     public static final String ACTION_SWITCH_TAB           = "org.mozilla.gecko.SWITCH_TAB";
 
     public static final String INTENT_REGISTER_STUMBLER_LISTENER = "org.mozilla.gecko.STUMBLER_REGISTER_LOCAL_LISTENER";
 
     public static final String EXTRA_STATE_BUNDLE          = "stateBundle";
 
     public static final String PREFS_ALLOW_STATE_BUNDLE    = "allowStateBundle";
-    public static final String PREFS_OOM_EXCEPTION         = "OOMException";
     public static final String PREFS_VERSION_CODE          = "versionCode";
     public static final String PREFS_WAS_STOPPED           = "wasStopped";
     public static final String PREFS_CRASHED_COUNT         = "crashedCount";
     public static final String PREFS_CLEANUP_TEMP_FILES    = "cleanupTempFiles";
 
     public static final String SAVED_STATE_IN_BACKGROUND   = "inBackground";
     public static final String SAVED_STATE_PRIVATE_SESSION = "privateSession";
 
@@ -1369,17 +1367,17 @@ public abstract class GeckoApp
                 localeManager.initialize(getApplicationContext());
 
                 SessionInformation previousSession = SessionInformation.fromSharedPrefs(prefs);
                 if (previousSession.wasKilled()) {
                     Telemetry.addToHistogram("FENNEC_WAS_KILLED", 1);
                 }
 
                 SharedPreferences.Editor editor = prefs.edit();
-                editor.putBoolean(GeckoApp.PREFS_OOM_EXCEPTION, false);
+                editor.putBoolean(GeckoAppShell.PREFS_OOM_EXCEPTION, false);
 
                 // Put a flag to check if we got a normal `onSaveInstanceState`
                 // on exit, or if we were suddenly killed (crash or native OOM).
                 editor.putBoolean(GeckoApp.PREFS_WAS_STOPPED, false);
 
                 editor.apply();
 
                 // The lifecycle of mHealthRecorder is "shortly after onCreate"
@@ -1663,17 +1661,17 @@ public abstract class GeckoApp
             }
 
             if (GeckoThread.isRunning()) {
                 geckoConnected();
                 GeckoAppShell.notifyObservers("Viewport:Flush", null);
             }
         }
 
-        if (ACTION_ALERT_CALLBACK.equals(action)) {
+        if (GeckoAppShell.ACTION_ALERT_CALLBACK.equals(action)) {
             processAlertCallback(intent);
         }
     }
 
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
     @Override
     public void onGlobalLayout() {
         if (Versions.preJB) {
@@ -1960,17 +1958,17 @@ public abstract class GeckoApp
         if (data != null) {
             alertName = data.getQueryParameter("name");
             if (alertName == null)
                 alertName = "";
             alertCookie = data.getQueryParameter("cookie");
             if (alertCookie == null)
                 alertCookie = "";
         }
-        handleNotification(ACTION_ALERT_CALLBACK, alertName, alertCookie);
+        handleNotification(GeckoAppShell.ACTION_ALERT_CALLBACK, alertName, alertCookie);
     }
 
     @Override
     protected void onNewIntent(Intent externalIntent) {
         final SafeIntent intent = new SafeIntent(externalIntent);
 
         final boolean isFirstTab = !mWasFirstTabShownAfterActivityUnhidden;
         mWasFirstTabShownAfterActivityUnhidden = true; // Reset since we'll be loading a tab.
@@ -2005,17 +2003,17 @@ public abstract class GeckoApp
                     }
                     Tabs.getInstance().loadUrlWithIntentExtras(url, intent, flags);
                 }
             });
         } else if (ACTION_HOMESCREEN_SHORTCUT.equals(action)) {
             mLayerView.loadUri(uri, GeckoView.LOAD_SWITCH_TAB);
         } else if (Intent.ACTION_SEARCH.equals(action)) {
             mLayerView.loadUri(uri, GeckoView.LOAD_NEW_TAB);
-        } else if (ACTION_ALERT_CALLBACK.equals(action)) {
+        } else if (GeckoAppShell.ACTION_ALERT_CALLBACK.equals(action)) {
             processAlertCallback(intent);
         } else if (NotificationHelper.HELPER_BROADCAST_ACTION.equals(action)) {
             NotificationHelper.getInstance(getApplicationContext()).handleNotificationIntent(intent);
         } else if (ACTION_LAUNCH_SETTINGS.equals(action)) {
             // Check if launched from data reporting notification.
             Intent settingsIntent = new Intent(GeckoApp.this, GeckoPreferences.class);
             // Copy extras.
             settingsIntent.putExtras(intent.getUnsafe());
@@ -2029,17 +2027,18 @@ public abstract class GeckoApp
     }
 
     /**
      * Handles getting a URI from an intent in a way that is backwards-
      * compatible with our previous implementations.
      */
     protected String getURIFromIntent(SafeIntent intent) {
         final String action = intent.getAction();
-        if (ACTION_ALERT_CALLBACK.equals(action) || NotificationHelper.HELPER_BROADCAST_ACTION.equals(action)) {
+        if (GeckoAppShell.ACTION_ALERT_CALLBACK.equals(action) ||
+                NotificationHelper.HELPER_BROADCAST_ACTION.equals(action)) {
             return null;
         }
 
         return intent.getDataString();
     }
 
     protected int getOrientation() {
         return GeckoScreenOrientation.getInstance().getAndroidOrientation();
--- a/mobile/android/base/java/org/mozilla/gecko/health/SessionInformation.java
+++ b/mobile/android/base/java/org/mozilla/gecko/health/SessionInformation.java
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.health;
 
 import android.content.SharedPreferences;
 import android.util.Log;
 
 import org.mozilla.gecko.GeckoApp;
+import org.mozilla.gecko.GeckoAppShell;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
 public class SessionInformation {
     private static final String LOG_TAG = "GeckoSessInfo";
 
     public static final String PREFS_SESSION_START = "sessionStart";
@@ -46,17 +47,17 @@ public class SessionInformation {
      *
      * This includes retrieving OOM/crash data, as well as timings.
      *
      * If no wallStartTime was found, that implies that the previous
      * session was correctly recorded, and an object with a zero
      * wallStartTime is returned.
      */
     public static SessionInformation fromSharedPrefs(SharedPreferences prefs) {
-        boolean wasOOM = prefs.getBoolean(GeckoApp.PREFS_OOM_EXCEPTION, false);
+        boolean wasOOM = prefs.getBoolean(GeckoAppShell.PREFS_OOM_EXCEPTION, false);
         boolean wasStopped = prefs.getBoolean(GeckoApp.PREFS_WAS_STOPPED, true);
         long wallStartTime = prefs.getLong(PREFS_SESSION_START, 0L);
         long realStartTime = 0L;
         Log.d(LOG_TAG, "Building SessionInformation from prefs: " +
                        wallStartTime + ", " + realStartTime + ", " +
                        wasStopped + ", " + wasOOM);
         return new SessionInformation(wallStartTime, realStartTime, wasOOM, wasStopped);
     }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -148,17 +148,17 @@ public class GeckoAppShell
         }
 
         @Override
         public boolean reportException(final Thread thread, final Throwable exc) {
             try {
                 if (exc instanceof OutOfMemoryError) {
                     SharedPreferences prefs = getSharedPreferences();
                     SharedPreferences.Editor editor = prefs.edit();
-                    editor.putBoolean(GeckoApp.PREFS_OOM_EXCEPTION, true);
+                    editor.putBoolean(PREFS_OOM_EXCEPTION, true);
 
                     // Synchronously write to disk so we know it's done before we
                     // shutdown
                     editor.commit();
                 }
 
                 reportJavaCrash(exc, getExceptionStackTrace(exc));
 
@@ -231,16 +231,19 @@ public class GeckoAppShell
     static public final int LINK_TYPE_ETHERNET = 1;
     static public final int LINK_TYPE_USB = 2;
     static public final int LINK_TYPE_WIFI = 3;
     static public final int LINK_TYPE_WIMAX = 4;
     static public final int LINK_TYPE_2G = 5;
     static public final int LINK_TYPE_3G = 6;
     static public final int LINK_TYPE_4G = 7;
 
+    public static final String PREFS_OOM_EXCEPTION = "OOMException";
+    public static final String ACTION_ALERT_CALLBACK = "org.mozilla.gecko.ALERT_CALLBACK";
+
     /* The Android-side API: API methods that Android calls */
 
     // helper methods
     @WrapForJNI
     /* package */ static native void reportJavaCrash(Throwable exc, String stackTrace);
 
     @WrapForJNI(dispatchTo = "gecko")
     public static native void notifyUriVisited(String uri);
@@ -959,17 +962,17 @@ public class GeckoAppShell
                     notificationID, "persistent-notification-click", persistentData);
             closeIntent = makePersistentNotificationIntent(
                     notificationID, "persistent-notification-close", persistentData);
 
         } else {
             notifyAlertListener(alertName, "alertshow");
 
             // The intent to launch when the user clicks the expanded notification
-            final Intent notificationIntent = new Intent(GeckoApp.ACTION_ALERT_CALLBACK);
+            final Intent notificationIntent = new Intent(ACTION_ALERT_CALLBACK);
             notificationIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME,
                                             AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
             notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 
             // Put the strings into the intent as an URI
             // "alert:?name=<alertName>&app=<appName>&cookie=<cookie>"
             final Uri.Builder b = new Uri.Builder();
             final Uri dataUri = b.scheme("alert")
@@ -994,17 +997,17 @@ public class GeckoAppShell
 
         final int notificationID = alertName.hashCode();
         notificationClient.remove(notificationID);
     }
 
     public static void handleNotification(String action, String alertName, String alertCookie) {
         final int notificationID = alertName.hashCode();
 
-        if (GeckoApp.ACTION_ALERT_CALLBACK.equals(action)) {
+        if (ACTION_ALERT_CALLBACK.equals(action)) {
             notifyAlertListener(alertName, "alertclickcallback");
 
             if (notificationClient.isOngoing(notificationID)) {
                 // When clicked, keep the notification if it displays progress
                 return;
             }
         }
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
@@ -398,23 +398,16 @@ public class GeckoThread extends Thread 
         GeckoLoader.loadSQLiteLibs(context, resourcePath);
         GeckoLoader.loadNSSLibs(context, resourcePath);
         GeckoLoader.loadGeckoLibs(context, resourcePath);
         setState(State.LIBS_READY);
 
         return resourcePath;
     }
 
-    private static String getTypeFromAction(String action) {
-        if (GeckoApp.ACTION_HOMESCREEN_SHORTCUT.equals(action)) {
-            return "-bookmark";
-        }
-        return null;
-    }
-
     private String addCustomProfileArg(String args) {
         String profileArg = "";
 
         // Make sure a profile exists.
         final GeckoProfile profile = getProfile();
         profile.getDir(); // call the lazy initializer
 
         // If args don't include the profile, make sure it's included.
@@ -435,21 +428,16 @@ public class GeckoThread extends Thread 
         final StringBuilder args = new StringBuilder(context.getPackageName());
         args.append(" -greomni ").append(apkPath);
 
         final String userArgs = addCustomProfileArg(mArgs);
         if (userArgs != null) {
             args.append(' ').append(userArgs);
         }
 
-        final String type = getTypeFromAction(mAction);
-        if (type != null) {
-            args.append(" ").append(type);
-        }
-
         // In un-official builds, we want to load Javascript resources fresh
         // with each build.  In official builds, the startup cache is purged by
         // the buildid mechanism, but most un-official builds don't bump the
         // buildid, so we purge here instead.
         if (!AppConstants.MOZILLA_OFFICIAL) {
             Log.w(LOGTAG, "STARTUP PERFORMANCE WARNING: un-official build: purging the " +
                           "startup (JavaScript) caches.");
             args.append(" -purgecaches");