From b0ec51f09b5466b63da10e307eaa176a8d9943c1 Mon Sep 17 00:00:00 2001 From: Igor Oliveira Date: Mon, 19 Nov 2018 14:25:27 -0200 Subject: [PATCH 1/3] Bug 28507: Parse a set of strings in Android Set Preferences Android allows a set of String values in the preferences editor. However, the TBA distribution just supported simple scalar types. This patch implements the code to parse complex prefs from the distribution preference file. --- .../gecko/preferences/DistroSharedPrefsImport.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/java/org/mozilla/gecko/preferences/DistroSharedPrefsImport.java b/mobile/android/base/java/org/mozilla/gecko/preferences/DistroSharedPrefsImport.java index 13047c6f2ff4..7969aca3d2ac 100644 --- a/mobile/android/base/java/org/mozilla/gecko/preferences/DistroSharedPrefsImport.java +++ b/mobile/android/base/java/org/mozilla/gecko/preferences/DistroSharedPrefsImport.java @@ -11,10 +11,13 @@ import org.mozilla.gecko.distribution.Distribution; import android.content.Context; import android.content.SharedPreferences; import android.util.Log; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.util.HashSet; import java.util.Iterator; +import java.util.Set; public class DistroSharedPrefsImport { @@ -58,7 +61,21 @@ public class DistroSharedPrefsImport { } else if (value instanceof Long) { sharedPreferences.putLong(GeckoPreferences.NON_PREF_PREFIX + key, (long) value); } else { - Log.d(LOGTAG, "Unknown preference value type whilst importing android preferences from distro file."); + JSONArray jsonArray = preferences.optJSONArray(key); + if (jsonArray != null) { + Set prefValues = new HashSet(); + for (int i = 0; i < jsonArray.length(); i++) { + try { + prefValues.add(jsonArray.getString(i)); + } catch (JSONException e) { + Log.e(LOGTAG, "Unable to parse Android Preferences.", e); + continue; + } + } + sharedPreferences.putStringSet(GeckoPreferences.NON_PREF_PREFIX + key, prefValues); + } else { + Log.d(LOGTAG, "Unknown preference value type whilst importing android preferences from distro file."); + } } } sharedPreferences.apply(); -- 2.14.1