diff --git a/android/app/src/main/java/org/mozilla/magnet/api/Utils.java b/android/app/src/main/java/org/mozilla/magnet/api/Utils.java index a89c6210..d2c201f4 100644 --- a/android/app/src/main/java/org/mozilla/magnet/api/Utils.java +++ b/android/app/src/main/java/org/mozilla/magnet/api/Utils.java @@ -83,10 +83,9 @@ public static WritableMap jsonToWritableMap(JSONObject jsonObject) { return null; } - Iterator iterator = jsonObject.keys(); if (!iterator.hasNext()) { - return null; + return writableMap; } while (iterator.hasNext()) { @@ -155,4 +154,4 @@ public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) { return writableArray; } -} \ No newline at end of file +} diff --git a/android/app/src/main/java/org/mozilla/magnet/magnetapi/ApiPreferences.java b/android/app/src/main/java/org/mozilla/magnet/magnetapi/ApiPreferences.java index ceac3015..0cffcdae 100644 --- a/android/app/src/main/java/org/mozilla/magnet/magnetapi/ApiPreferences.java +++ b/android/app/src/main/java/org/mozilla/magnet/magnetapi/ApiPreferences.java @@ -28,7 +28,13 @@ class ApiPreferences extends Api { */ @Override public void get(String aPath, Callback aCallback) { - aCallback.resolve(getCache().getJsonObject(PREFERENCES_STORE_KEY)); + JSONObject json = getCache().getJsonObject(PREFERENCES_STORE_KEY); + + if (json == null) { + json = new JSONObject(); + } + + aCallback.resolve(json); } /** diff --git a/lib/app.js b/lib/app.js index 5e0b54bc..8095d3af 100644 --- a/lib/app.js +++ b/lib/app.js @@ -199,7 +199,7 @@ class App extends React.Component { debug('inflate user flags'); return api.get('preferences') .then(prefs => { - Object.keys(prefs ).forEach(key => { + Object.keys(prefs).forEach(key => { debug('got user flag', key, prefs[key]); const value = parseBoolean(prefs[key]); if (value == null) return;