Fix issue of losing tab state
Browser makes a backup of tab state when adding visited history and
page finished. When browser is being destroyed at times there could
be an instance where a background load triggers to write state while
the browser is already in cleanup state. This causes to write empty
state that looses the previous saved status .
Change-Id: I760c36e376c816302f8635c8e73d8b3871faf0b4
diff --git a/src/com/android/browser/Controller.java b/src/com/android/browser/Controller.java
index 457b1c4..454b25a 100644
--- a/src/com/android/browser/Controller.java
+++ b/src/com/android/browser/Controller.java
@@ -754,6 +754,12 @@
/* package */ Bundle createSaveState() {
Bundle saveState = new Bundle();
mTabControl.saveState(saveState);
+ // This method is called multiple times.Need to
+ // guard against TabControl not having any tabs
+ // during the destroy cycles which looses all the
+ // existing saved information.
+ if (saveState.isEmpty())
+ return null;
return saveState;
}
diff --git a/src/com/android/browser/CrashRecoveryHandler.java b/src/com/android/browser/CrashRecoveryHandler.java
index bcdf8b0..c02eb07 100644
--- a/src/com/android/browser/CrashRecoveryHandler.java
+++ b/src/com/android/browser/CrashRecoveryHandler.java
@@ -109,7 +109,9 @@
}
public void backupState() {
- mForegroundHandler.postDelayed(mCreateState, BACKUP_DELAY);
+ // Only write if we are not already destroyed
+ if (mController.getTabControl() != null)
+ mForegroundHandler.postDelayed(mCreateState, BACKUP_DELAY);
}
private Runnable mCreateState = new Runnable() {
@@ -118,8 +120,11 @@
public void run() {
try {
final Bundle state = mController.createSaveState();
- Message.obtain(mBackgroundHandler, MSG_WRITE_STATE, state)
- .sendToTarget();
+ // block write of null values
+ if (state != null && mController.getTabControl() != null) {
+ Message.obtain(mBackgroundHandler, MSG_WRITE_STATE, state)
+ .sendToTarget();
+ }
// Remove any queued up saves
mForegroundHandler.removeCallbacks(mCreateState);
} catch (Throwable t) {