Bug 1029046/1030141 - Conditionally enable new recent tabs panel in config migration (r=mfinkle)
--- a/mobile/android/base/home/HomeConfigPrefsBackend.java
+++ b/mobile/android/base/home/HomeConfigPrefsBackend.java
@@ -93,16 +93,32 @@ class HomeConfigPrefsBackend implements
panelConfigs.add(0, historyEntry);
panelConfigs.add(0, recentTabsEntry);
}
return new State(panelConfigs, true);
}
/**
+ * Iterate through the panels to check if they are all disabled.
+ */
+ private static boolean allPanelsAreDisabled(JSONArray jsonPanels) throws JSONException {
+ final int count = jsonPanels.length();
+ for (int i = 0; i < count; i++) {
+ final JSONObject jsonPanelConfig = jsonPanels.getJSONObject(i);
+
+ if (!jsonPanelConfig.optBoolean(PanelConfig.JSON_KEY_DISABLED, false)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Migrates JSON config data storage.
*
* @param context Context used to get shared preferences and create built-in panel.
* @param jsonString String currently stored in preferences.
*
* @return JSONArray array representing new set of panel configs.
*/
private static synchronized JSONArray maybePerformMigration(Context context, String jsonString) throws JSONException {
@@ -139,18 +155,23 @@ class HomeConfigPrefsBackend implements
final SharedPreferences.Editor prefsEditor = prefs.edit();
for (int v = version + 1; v <= VERSION; v++) {
Log.d(LOGTAG, "Migrating to version = " + v);
switch (v) {
case 1:
// Add "Recent Tabs" panel
- final PanelConfig recentTabsConfig = createBuiltinPanelConfig(context, PanelType.RECENT_TABS);
- final JSONObject jsonRecentTabsConfig = recentTabsConfig.toJSON();
+ final JSONObject jsonRecentTabsConfig =
+ createBuiltinPanelConfig(context, PanelType.RECENT_TABS).toJSON();
+
+ // If any panel is enabled, then we should make the recent tabs
+ // panel enabled.
+ jsonRecentTabsConfig.put(PanelConfig.JSON_KEY_DISABLED,
+ allPanelsAreDisabled(originalJsonPanels));
// Add the new panel to the front of the array on phones.
if (!HardwareUtils.isTablet()) {
newJsonPanels.put(jsonRecentTabsConfig);
}
// Copy the original panel configs.
final int count = originalJsonPanels.length();