Bug 1269682 - Guard against onPause being called without onResume; r=ahunt a=gchang
authorJim Chen <nchen@mozilla.com>
Mon, 09 May 2016 22:31:18 -0400
changeset 333016 12f53b845cb9843dbcfa4431d3aa2d12a824c878
parent 333015 b01ee9309ba0d1d2ac65e4f2d8e25899ca817ec4
child 333017 f887875e60c8738740089de8e85d6b68475de96e
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,
+        if (mHasResumed) {
+            // Register for Prompt:ShowTop so we can foreground this activity even if it's hidden.
+            EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener) this,
                 "Prompt:ShowTop");
+            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);
             }