Don't initialize ActionBar with invalid tab index
If an invalid tab index is persisted to SharedPreferences then every time you
open the People app, the app will crash. This CL fixes this crash. It doesn't
prevent the tab index from getting in an invalid state in the first place.
I don't understand how this invalid tab index gets set. The
ActionBarImpl and TabPagerAdapter would both have to believe that a tab
at position 3 exists, otherwise a crash would occur before an invalid
tab index could be persisted.
TESTING
-verified that I could close and open the app from every tab position
-pushed an invalid shared_preferences.xml to a phone. This causes crashes
without this CL. This CL fixes the crashes.
Bug: 12938207
Change-Id: I6eb9a9043dcc76ce94a1cc280c7441e57a4abfd1
diff --git a/src/com/android/contacts/activities/ActionBarAdapter.java b/src/com/android/contacts/activities/ActionBarAdapter.java
index c707b62..f184d12 100644
--- a/src/com/android/contacts/activities/ActionBarAdapter.java
+++ b/src/com/android/contacts/activities/ActionBarAdapter.java
@@ -239,6 +239,10 @@
// Just set to the field here. The listener will be notified by update().
mCurrentTab = savedState.getInt(EXTRA_KEY_SELECTED_TAB);
}
+ if (mCurrentTab >= TabState.COUNT || mCurrentTab < 0) {
+ // Invalid tab index was saved (b/12938207). Restore the default.
+ mCurrentTab = TabState.DEFAULT;
+ }
// Show tabs or the expanded {@link SearchView}, depending on whether or not we are in
// search mode.
update();