Bug 1029046/1030141 - Conditionally enable new recent tabs panel in config migration (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Thu, 03 Jul 2014 16:40:40 +0100
changeset 192159 34e8a8a7603b21098625690ecfaabe264cec33bb
parent 192158 f93d3036c5a4d2465ee7c1297aeaf9c2eaf72ff8
child 192160 543c2448130b259de22e14e504aaba9257199dd2
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmfinkle
bugs1029046, 1030141
milestone33.0a1
Bug 1029046/1030141 - Conditionally enable new recent tabs panel in config migration (r=mfinkle)
mobile/android/base/home/HomeConfigPrefsBackend.java
--- 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();