From 3ae7f74a64fd1dc101910f1b14f315b34d1f1274 Mon Sep 17 00:00:00 2001 From: Michael Kolb Date: Wed, 13 Jul 2011 15:18:25 -0700 Subject: fix restore bug Bug: 5023284 only save tab id's if the tab state can be saved this prevents trying to restore tabs that didn't get saved Change-Id: I9ca8a3f71c4cb9029718492fbd5447e782524869 --- src/com/android/browser/TabControl.java | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/com/android/browser/TabControl.java') diff --git a/src/com/android/browser/TabControl.java b/src/com/android/browser/TabControl.java index 5f3995ff3..1be2016ac 100644 --- a/src/com/android/browser/TabControl.java +++ b/src/com/android/browser/TabControl.java @@ -297,10 +297,12 @@ class TabControl { long[] ids = new long[numTabs]; int i = 0; for (Tab tab : mTabs) { - ids[i++] = tab.getId(); if (tab.saveState()) { + ids[i++] = tab.getId(); outState.putBundle(Long.toString(tab.getId()), tab.getSavedState(saveImages)); + } else { + ids[i++] = -1; } } if (!outState.isEmpty()) { @@ -327,13 +329,12 @@ class TabControl { } final long oldcurrent = inState.getLong(CURRENT); long current = -1; - if (restoreIncognitoTabs || - !inState.getBundle(Long.toString(oldcurrent)).getBoolean(Tab.INCOGNITO)) { + if (restoreIncognitoTabs || (hasState(oldcurrent, inState) && !isIncognito(oldcurrent, inState))) { current = oldcurrent; } else { // pick first non incognito tab for (long id : ids) { - if (!inState.getBundle(Long.toString(id)).getBoolean(Tab.INCOGNITO)) { + if (hasState(id, inState) && !isIncognito(id, inState)) { current = id; break; } @@ -342,6 +343,20 @@ class TabControl { return current; } + private boolean hasState(long id, Bundle state) { + if (id == -1) return false; + Bundle tab = state.getBundle(Long.toString(id)); + return ((tab != null) && !tab.isEmpty()); + } + + private boolean isIncognito(long id, Bundle state) { + Bundle tabstate = state.getBundle(Long.toString(id)); + if ((tabstate != null) && !tabstate.isEmpty()) { + return tabstate.getBoolean(Tab.INCOGNITO); + } + return false; + } + /** * Restore the state of all the tabs. * @param currentId The tab id to restore. -- cgit v1.2.3