Bug 1269682 - Guard against onPause being called without onResume; r=ahunt a=gchang
☠☠ backed out by 9c28c3b843d9 ☠ ☠
authorJim Chen <nchen@mozilla.com>
Mon, 09 May 2016 22:31:18 -0400
changeset 332983 a2c46d6880e2ae4488c657c58c4bf71ece9d4433
parent 332982 c40d4d7f4bb2b10c82348b900978fd2c0c3576a7
child 332984 6dc895b3dea4e53ca1aaeaa2acb778512152588e
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahunt, gchang
bugs1269682
milestone48.0a2
Bug 1269682 - Guard against onPause being called without onResume; r=ahunt a=gchang When we try to restart Fennec immediately after launching Fennec, it's possible for onPause to be called without a corresponding onResume being called first. This patch guards against registering events twice due to this quirk. Bug 1269682 - Don't try to switch to guest profile; r=margaret a=gchang BrowserApp has a snippet that tries to restart in guest profile if we're supposed to be in it, but are currently not. This is vestigial code from lock screen widget support, and should not be needed anymore. Bug 1269682 - Always detect guest mode first; r=margaret a=gchang Always check for guest mode even if we don't have arguments, because we can still be in guest mode even if we don't have arguments.
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -304,16 +304,18 @@ public class BrowserApp extends GeckoApp
     private boolean mHideWebContentOnAnimationEnd;
 
     private final DynamicToolbar mDynamicToolbar = new DynamicToolbar();
     private final ScreenshotObserver mScreenshotObserver = new ScreenshotObserver();
 
     @NonNull
     private SearchEngineManager searchEngineManager; // Contains reference to Context - DO NOT LEAK!
 
+    private boolean mHasResumed;
+
     @Override
     public View onCreateView(final String name, final Context context, final AttributeSet attrs) {
         final View view;
         if (BrowserToolbar.class.getName().equals(name)) {
             view = BrowserToolbar.create(context, attrs);
         } else if (TabsPanel.TabsLayout.class.getName().equals(name)) {
             view = TabsPanel.createTabsLayout(context, attrs);
         } else {
@@ -1080,30 +1082,22 @@ public class BrowserApp extends GeckoApp
         super.onResume();
         if (mIsAbortingAppLaunch) {
             return;
         }
 
         // Needed for Adjust to get accurate session measurements
         AdjustConstants.getAdjustHelper().onResume();
 
-        final String args = ContextUtils.getStringExtra(getIntent(), "args");
-        // If an external intent tries to start Fennec in guest mode, and it's not already
-        // in guest mode, this will change modes before opening the url.
-        // NOTE: OnResume is called twice sometimes when showing on the lock screen.
-        final boolean enableGuestSession = GuestSession.shouldUse(this, args);
-        final boolean inGuestSession = GeckoProfile.get(this).inGuestMode();
-        if (enableGuestSession != inGuestSession) {
-            doRestart(getIntent());
-            return;
+        if (!mHasResumed) {
+            EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener) this,
+                    "Prompt:ShowTop");
+            mHasResumed = true;
         }
 
-        EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener) this,
-            "Prompt:ShowTop");
-
         processTabQueue();
 
         mScreenshotObserver.start();
 
         mAddToHomeScreenPromotion.resume();
     }
 
     @Override
@@ -1111,19 +1105,22 @@ public class BrowserApp extends GeckoApp
         super.onPause();
         if (mIsAbortingAppLaunch) {
             return;
         }
 
         // Needed for Adjust to get accurate session measurements
         AdjustConstants.getAdjustHelper().onPause();
 
-        // Register for Prompt:ShowTop so we can foreground this activity even if it's hidden.
-        EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this,
-                "Prompt:ShowTop");
+        if (mHasResumed) {
+            // Register for Prompt: so we can foreground this activity even if it's hidden.
+            EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this,
+                "Prompt:");
+            mHasResumed = false;
+        }
 
         mScreenshotObserver.stop();
 
         mAddToHomeScreenPromotion.pause();
     }
 
     @Override
     public void onRestart() {
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
@@ -110,24 +110,24 @@ public final class GeckoProfile {
         UNLOCKED,
         UNDEFINED
     };
 
     /**
      * Can return null.
      */
     public static GeckoProfile getFromArgs(final Context context, final String args) {
+        if (GuestSession.shouldUse(context, args)) {
+            return GeckoProfile.getOrCreateGuestProfile(context);
+        }
+
         if (args == null) {
             return null;
         }
 
-        if (GuestSession.shouldUse(context, args)) {
-            return GeckoProfile.getOrCreateGuestProfile(context);
-        }
-
         String profileName = null;
         String profilePath = null;
         if (args.contains("-P")) {
             final Pattern p = Pattern.compile("(?:-P\\s*)(\\w*)(\\s*)");
             final Matcher m = p.matcher(args);
             if (m.find()) {
                 profileName = m.group(1);
             }