[tor-commits] [tor-browser/tor-browser-60.3.0esr-8.5-1] Bug 28507: Parse a set of strings in Android Set Preferences

gk at torproject.org gk at torproject.org
Thu Nov 22 21:16:52 UTC 2018


commit b03bfc5100f3d255ae0116ab18653759f87fe241
Author: Igor Oliveira <igt0 at torproject.org>
Date:   Mon Nov 19 14:25:27 2018 -0200

    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<String> prefValues = new HashSet<String>();
+                    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();





More information about the tor-commits mailing list