Bug 1304777 - Part 1: Perform homeconfig cleanup to ensure default still exists. r=sebastian, a=ritu
authorAndrzej Hunt <ahunt@mozilla.com>
Mon, 26 Sep 2016 13:12:16 -0700
changeset 358032 8de5082984bd186521fcd491b8f0ad273e8b2989
parent 358031 3a43ceb01d35621912efa7f99e79dce637ee5ddd
child 358033 d9015b8e5f6e819263991ef95c495d0787212407
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, ritu
bugs1304777, 1251362
milestone51.0a2
Bug 1304777 - Part 1: Perform homeconfig cleanup to ensure default still exists. r=sebastian, a=ritu Bug 1251362 can result in there no default panel being set (this happens if the history panel was the default panel before the panel migration). We can reuse the code from a previous bug which sets history as the default panel if no other panel is set as default. A second commit fixes the broken migration to ensure that history remains the default homepanel, however this cleanup migration will help ensure existing clients get fixed. MozReview-Commit-ID: EcUb2uUfOeJ
mobile/android/base/java/org/mozilla/gecko/home/HomeConfigPrefsBackend.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/HomeConfigPrefsBackend.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/HomeConfigPrefsBackend.java
@@ -30,17 +30,17 @@ import android.content.SharedPreferences
 import android.support.v4.content.LocalBroadcastManager;
 import android.text.TextUtils;
 import android.util.Log;
 
 public class HomeConfigPrefsBackend implements HomeConfigBackend {
     private static final String LOGTAG = "GeckoHomeConfigBackend";
 
     // Increment this to trigger a migration.
-    private static final int VERSION = 7;
+    private static final int VERSION = 8;
 
     // This key was originally used to store only an array of panel configs.
     public static final String PREFS_CONFIG_KEY_OLD = "home_panels";
 
     // This key is now used to store a version number with the array of panel configs.
     public static final String PREFS_CONFIG_KEY = "home_panels_with_version";
 
     // Keys used with JSON object stored in prefs.
@@ -206,17 +206,22 @@ public class HomeConfigPrefsBackend impl
             } else {
                 newArray.put(jsonPanels.get(i));
             }
         }
 
         return newArray;
     }
 
-    private static void ensureDefaultPanelForV5(Context context, JSONArray jsonPanels) throws JSONException {
+    /**
+     * Iterate over all homepanels to verify that there is at least one default panel. If there is
+     * no default panel, set History as the default panel. (This is only relevant for two botched
+     * migrations where the history panel should have been made the default panel, but wasn't.)
+     */
+    private static void ensureDefaultPanelForV5orV8(Context context, JSONArray jsonPanels) throws JSONException {
         int historyIndex = -1;
 
         for (int i = 0; i < jsonPanels.length(); i++) {
             final PanelConfig panelConfig = new PanelConfig(jsonPanels.getJSONObject(i));
             if (panelConfig.isDefault()) {
                 return;
             }
 
@@ -391,28 +396,34 @@ public class HomeConfigPrefsBackend impl
                     // Combine the History and Sync panels. In order to minimize an unexpected reordering
                     // of panels, we try to replace the History panel if it's visible, and fall back to
                     // the Sync panel if that's visible.
                     jsonPanels = combineHistoryAndSyncPanels(context, jsonPanels);
                     break;
 
                 case 5:
                     // This is the fix for bug 1264136 where we lost track of the default panel during some migrations.
-                    ensureDefaultPanelForV5(context, jsonPanels);
+                    ensureDefaultPanelForV5orV8(context, jsonPanels);
                     break;
 
                 case 6:
                     jsonPanels = removePanel(context, jsonPanels,
                             PanelType.DEPRECATED_READING_LIST, PanelType.BOOKMARKS, false);
                     break;
 
                 case 7:
                     jsonPanels = removePanel(context, jsonPanels,
                             PanelType.DEPRECATED_RECENT_TABS, PanelType.COMBINED_HISTORY, true);
                     break;
+
+                case 8:
+                    // Similar to "case 5" above, this time 1304777 - once again we lost track
+                    // of the history panel
+                    ensureDefaultPanelForV5orV8(context, jsonPanels);
+                    break;
             }
         }
 
         // Save the new panel config and the new version number.
         final JSONObject newJson = new JSONObject();
         newJson.put(JSON_KEY_PANELS, jsonPanels);
         newJson.put(JSON_KEY_VERSION, VERSION);