Bug 1331080 - Switch suggestedSites.hidden to be marked as Android pref. r=sebastian, a=jcristau
authorMichael Kaply <mozilla@kaply.com>
Wed, 18 Jan 2017 09:44:05 -0600
changeset 354201 f867ccafb47482578642cff261383e0d60cf4633
parent 354200 07fc9bc143f7bfa4a6be7ecb5c0d3c591211b3a7
child 354202 2e91c8334463411fe75e448a4b27c48ce37f21ad
push id6892
push userryanvm@gmail.com
push dateTue, 14 Feb 2017 16:13:02 +0000
treeherdermozilla-esr52@35e191e72900 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, jcristau
bugs1331080
milestone52.0
Bug 1331080 - Switch suggestedSites.hidden to be marked as Android pref. r=sebastian, a=jcristau
mobile/android/base/java/org/mozilla/gecko/db/SuggestedSites.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/SuggestedSites.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/SuggestedSites.java
@@ -38,16 +38,17 @@ import org.mozilla.gecko.annotation.Robo
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.Locales;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.distribution.Distribution;
 import org.mozilla.gecko.restrictions.Restrictions;
 import org.mozilla.gecko.util.RawResource;
 import org.mozilla.gecko.util.ThreadUtils;
+import org.mozilla.gecko.preferences.GeckoPreferences;
 
 /**
  * {@code SuggestedSites} provides API to get a list of locale-specific
  * suggested sites to be used in Fennec's top sites panel. It provides
  * only a single method to fetch the list as a {@code Cursor}. This cursor
  * will then be wrapped by {@code TopSitesCursorWrapper} to blend top,
  * pinned, and suggested sites in the UI. The returned {@code Cursor}
  * uses its own schema defined in {@code BrowserContract.SuggestedSites}
@@ -63,20 +64,22 @@ import org.mozilla.gecko.util.ThreadUtil
  *
  * Changes to the list of suggested sites are saved in SharedPreferences.
  */
 @RobocopTarget
 public class SuggestedSites {
     private static final String LOGTAG = "GeckoSuggestedSites";
 
     // SharedPreference key for suggested sites that should be hidden.
-    public static final String PREF_SUGGESTED_SITES_HIDDEN = "suggestedSites.hidden";
+    public static final String PREF_SUGGESTED_SITES_HIDDEN = GeckoPreferences.NON_PREF_PREFIX + "suggestedSites.hidden";
+    public static final String PREF_SUGGESTED_SITES_HIDDEN_OLD = "suggestedSites.hidden";
 
     // Locale used to generate the current suggested sites.
-    public static final String PREF_SUGGESTED_SITES_LOCALE = "suggestedSites.locale";
+    public static final String PREF_SUGGESTED_SITES_LOCALE = GeckoPreferences.NON_PREF_PREFIX + "suggestedSites.locale";
+    public static final String PREF_SUGGESTED_SITES_LOCALE_OLD = "suggestedSites.locale";
 
     // File in profile dir with the list of suggested sites.
     private static final String FILENAME = "suggestedsites.json";
 
     private static final String[] COLUMNS = new String[] {
         BrowserContract.SuggestedSites._ID,
         BrowserContract.SuggestedSites.URL,
         BrowserContract.SuggestedSites.TITLE,
@@ -177,17 +180,26 @@ public class SuggestedSites {
             cachedFile = GeckoProfile.get(context).getFile(FILENAME);
         }
         return cachedFile;
     }
 
     private static boolean isNewLocale(Context context, Locale requestedLocale) {
         final SharedPreferences prefs = GeckoSharedPrefs.forProfile(context);
 
-        String locale = prefs.getString(PREF_SUGGESTED_SITES_LOCALE, null);
+        String locale = prefs.getString(PREF_SUGGESTED_SITES_LOCALE_OLD, null);
+        if (locale != null) {
+          // Migrate the old pref and remove it
+          final Editor editor = prefs.edit();
+          editor.remove(PREF_SUGGESTED_SITES_LOCALE_OLD);
+          editor.putString(PREF_SUGGESTED_SITES_LOCALE, locale);
+          editor.apply();
+        } else {
+          locale = prefs.getString(PREF_SUGGESTED_SITES_LOCALE, null);
+        }
         if (locale == null) {
             // Initialize config with the current locale
             updateSuggestedSitesLocale(context);
             return true;
         }
 
         return !TextUtils.equals(requestedLocale.toString(), locale);
     }
@@ -526,18 +538,27 @@ public class SuggestedSites {
         final Site site = getSiteForUrl(url);
         return (site != null ? site.bgColor : null);
     }
 
     private Set<String> loadBlacklist() {
         Log.d(LOGTAG, "Loading blacklisted suggested sites from SharedPreferences.");
         final Set<String> blacklist = new HashSet<String>();
 
-        final SharedPreferences preferences = GeckoSharedPrefs.forProfile(context);
-        final String sitesString = preferences.getString(PREF_SUGGESTED_SITES_HIDDEN, null);
+        final SharedPreferences prefs = GeckoSharedPrefs.forProfile(context);
+        String sitesString = prefs.getString(PREF_SUGGESTED_SITES_HIDDEN_OLD, null);
+        if (sitesString != null) {
+          // Migrate the old pref and remove it
+          final Editor editor = prefs.edit();
+          editor.remove(PREF_SUGGESTED_SITES_HIDDEN_OLD);
+          editor.putString(PREF_SUGGESTED_SITES_HIDDEN, sitesString);
+          editor.apply();
+        } else {
+          sitesString = prefs.getString(PREF_SUGGESTED_SITES_HIDDEN, null);
+        }
 
         if (sitesString != null) {
             for (String site : sitesString.trim().split(" ")) {
                 blacklist.add(Uri.decode(site));
             }
         }
 
         return blacklist;