Closed Bug 896170 Opened 11 years ago Closed 11 years ago

Tabs are duplicated after going back to Firefox, when "Don't keep activities" is enabled

Categories

(Firefox for Android Graveyard :: General, defect)

25 Branch
ARM
Android
defect
Not set
normal

Tracking

(fennec+)

RESOLVED FIXED
Firefox 26
Tracking Status
fennec + ---

People

(Reporter: u421692, Assigned: bnicholson)

References

Details

(Keywords: addon-compat)

Attachments

(3 files)

Attached file Logs
Environment:
Build: Firefox for Android 25.0a1 (2013-07-19)
Device: Samsung Galaxy Vibrant(AOKP Android 4.2.2) / LG Nexus 4 (Android 4.2.2)

Preconditions:
Enable "Don't keep activities" from Developer options

Steps to reproduce:
1. Open some webpages in different tabs.
2. Open ADD-ONS page and install an add-on that needs to restart the app.(e.g. SanRockstar).
3. When prompted restart the app.
4. Put Firefox to background then back to foreground.

Expected result:
The tabs are correctly restored.

Actual result:
Every time you perform the action from step 4, tabs are being duplicated.
tracking-fennec: --- → ?
Kevin, why should this track?
Assignee: nobody → bnicholson
tracking-fennec: ? → +
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
Fixing bug 899141 did not fix this issue. Reopening bug.
Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---
Session:Restore is sent every time we initialize, but we only want to send that message the first time the browser starts.
Attachment #796328 - Flags: review?(mark.finkle)
The first patch is enough to fix this bug, but looking through some of this old code, I think we can simplify things quite a bit. For all restart cases I can think of (crashes, guest mode, add-ons), we always want to do a restore. So rather than saving Java prefs to remember whether we want to restore, we can just attach an extra to the intent that indicates we just restarted.

This removes old code that prevents crash loops, but that code hasn't been working anyway as described by the comments. I'm not sure whether we even need this crash loop prevention code anymore: we only load one tab when we restore (since all others are in the background) and, thanks to tab stubs, the user can simply close any offending tab at startup before a crash if it repeats.

This patch also improves the UX for add-on restarts. We're currenly handling restart restores in Gecko (by checking resume_session_once), so about:home is shown for several seconds before tabs are actually restored. Add-ons restarts will be handled here as part of the always-restore-on-restart intents, so they'll now be able to take advantage of tab stubs.

I tested this change with the crash reporter, add-on restarts, guest mode, and session restore prefs.
Attachment #796350 - Flags: review?(mark.finkle)
Comment on attachment 796350 [details] [diff] [review]
Part 2: Use intent extra to trigger restore on restart

Review of attachment 796350 [details] [diff] [review]:
-----------------------------------------------------------------

::: mobile/android/base/BrowserApp.java
@@ +396,3 @@
>          }
>  
> +        GeckoProfile.maybeCleanupGuestProfile(this);

This should be in an else statement; I changed this locally.
Attachment #796328 - Flags: review?(mark.finkle) → review+
Comment on attachment 796350 [details] [diff] [review]
Part 2: Use intent extra to trigger restore on restart

>diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java

>+    protected boolean getSessionRestoreState(Bundle savedInstanceState) {

>+        } else if (savedInstanceState != null
>+                   || PreferenceManager.getDefaultSharedPreferences(this)
>+                                       .getString(GeckoPreferences.PREFS_RESTORE_SESSION, "quit")
>+                                       .equals("always")
>+                   || getIntent().getBooleanExtra("didRestart", false)) {

Good lord, my eyes are bleeding! I'm trying to think of how to make this more readable.

Would you mind something like this:

          } else {
              boolean didQuit = PreferenceManager.getDefaultSharedPreferences(this)
                                                 .getString(GeckoPreferences.PREFS_RESTORE_SESSION, "quit")
                                                 .equals("always");
              boolean didRestart = getIntent().getBooleanExtra("didRestart", false);
              if (savedInstanceState != null || didQuit || didRestart) {

>diff --git a/mobile/android/components/SessionStore.js b/mobile/android/components/SessionStore.js

>       case "quit-application":
>-        // If we are restarting, lets restore the tabs
>-        if (aData == "restart") {
>-          Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
>-
>-          // Ignore purges when restarting. The notification is fired after "quit-application".
>-          Services.obs.removeObserver(this, "browser:purge-session-history");
>-        }
>-

How are Gecko side restarts handled? Like this one:
http://mxr.mozilla.org/mozilla-central/source/mobile/android/chrome/content/browser.js#5587

Based on the Try results and the testing you've done, we can try this.
Attachment #796350 - Flags: review?(mark.finkle) → review+
Comment on attachment 796350 [details] [diff] [review]
Part 2: Use intent extra to trigger restore on restart

>diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java

>+    protected boolean getSessionRestoreState(Bundle savedInstanceState) {

>+        } else if (savedInstanceState != null
>+                   || PreferenceManager.getDefaultSharedPreferences(this)
>+                                       .getString(GeckoPreferences.PREFS_RESTORE_SESSION, "quit")
>+                                       .equals("always")
>+                   || getIntent().getBooleanExtra("didRestart", false)) {

Actually, how about refactoring this into two new methods:

getSessionRestorePreference()
getRestartFromIntent()

then

          } else if (savedInstanceState != null || getSessionRestorePreference().equals("always") || getRestartFromIntent()) {
(In reply to Mark Finkle (:mfinkle) from comment #10)
> Comment on attachment 796350 [details] [diff] [review]
> Part 2: Use intent extra to trigger restore on restart
> 
> >diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java
> 
> >+    protected boolean getSessionRestoreState(Bundle savedInstanceState) {
> 
> >+        } else if (savedInstanceState != null
> >+                   || PreferenceManager.getDefaultSharedPreferences(this)
> >+                                       .getString(GeckoPreferences.PREFS_RESTORE_SESSION, "quit")
> >+                                       .equals("always")
> >+                   || getIntent().getBooleanExtra("didRestart", false)) {
> 
> Actually, how about refactoring this into two new methods:
> 
> getSessionRestorePreference()
> getRestartFromIntent()
> 
> then
> 
>           } else if (savedInstanceState != null ||
> getSessionRestorePreference().equals("always") || getRestartFromIntent()) {

Yeah, I like that better than your first suggestion since we still get short-circuit evaluation that way.


> >diff --git a/mobile/android/components/SessionStore.js b/mobile/android/components/SessionStore.js
> 
> >       case "quit-application":
> >-        // If we are restarting, lets restore the tabs
> >-        if (aData == "restart") {
> >-          Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
> >-
> >-          // Ignore purges when restarting. The notification is fired after "quit-application".
> >-          Services.obs.removeObserver(this, "browser:purge-session-history");
> >-        }
> >-
> 
> How are Gecko side restarts handled? Like this one:
> http://mxr.mozilla.org/mozilla-central/source/mobile/android/chrome/content/
> browser.js#5587

I didn't trace the whole thing, but we eventually call onXreExit which calls doRestart here: http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/GeckoAppShell.java#652
https://hg.mozilla.org/mozilla-central/rev/cacfd928e6dc
https://hg.mozilla.org/mozilla-central/rev/7d0fc78efe59
Status: REOPENED → RESOLVED
Closed: 11 years ago11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 26
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: