From 4f91da8e6a350e71d457d3e867a875033d5fdac4 Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Wed, 9 May 2012 10:20:10 -0700 Subject: [PATCH] Bug 753175 - Race condition in Sync Migration / Preference:Get. r=gcp --- mobile/android/base/ProfileMigrator.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mobile/android/base/ProfileMigrator.java b/mobile/android/base/ProfileMigrator.java index 859ca6612c0..4f66635f010 100644 --- a/mobile/android/base/ProfileMigrator.java +++ b/mobile/android/base/ProfileMigrator.java @@ -518,7 +518,12 @@ public class ProfileMigrator { // This includes personal info, so don't log. // Log.d(LOGTAG, "Message: " + message.toString()); JSONArray jsonPrefs = message.getJSONArray("preferences"); - parsePrefs(jsonPrefs); + + // Check that the batch of preferences we got notified of are in + // the ones we requested and not those requested by other java code. + if (!parsePrefs(jsonPrefs)) + return; + GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", (GeckoEventListener)this); @@ -576,12 +581,18 @@ public class ProfileMigrator { return result; } - protected void parsePrefs(JSONArray jsonPrefs) { + // Returns true if we sucessfully got the preferences we requested. + protected boolean parsePrefs(JSONArray jsonPrefs) { try { final int length = jsonPrefs.length(); for (int i = 0; i < length; i++) { JSONObject jPref = jsonPrefs.getJSONObject(i); final String prefName = jPref.getString("name"); + + // Check to make sure we're working with preferences we requested. + if (!mSyncSettingsList.contains(prefName)) + return false; + final String prefType = jPref.getString("type"); if ("bool".equals(prefType)) { final boolean value = jPref.getBoolean("value"); @@ -599,7 +610,10 @@ public class ProfileMigrator { } catch (JSONException e) { Log.e(LOGTAG, "Exception handling preferences answer: " + e.getMessage()); + return false; } + + return true; } protected void configureSync() {