OSDN Git Service

Avoid porting null keys when copying preferences into new system
authorAlan Newberger <alann@google.com>
Sat, 4 Oct 2014 00:34:09 +0000 (17:34 -0700)
committerAlan Newberger <alann@google.com>
Sat, 4 Oct 2014 01:02:39 +0000 (01:02 +0000)
Testing on Fishlake shows certain preferences are of 'null' type
in shared preferences. Avoid an NPE on porting a null. From testing,
this can happen with focus mode, best to just skip porting the key
and let the app use a default.

Bug: 17829562
Change-Id: I483cb5beb160d3fb7fc8a42aa5085531e3fccb63
(cherry picked from commit d560aabf7baef81a14e78341af81994efc1d4f17)

src/com/android/camera/settings/AppUpgrader.java

index 8e4d1db..bb15d38 100644 (file)
@@ -334,8 +334,12 @@ public class AppUpgrader extends SettingsUpgrader {
         Map<String, ?> entries = oldPrefs.getAll();
         for (Map.Entry<String, ?> entry : entries.entrySet()) {
             String key = entry.getKey();
-            String value = entry.getValue().toString();
-            newPrefs.edit().putString(key, value).apply();
+            Object value = entry.getValue();
+            if (value != null) {
+                newPrefs.edit().putString(key, String.valueOf(value)).apply();
+            } else {
+                Log.w(TAG, "skipped upgrade for null key " + key);
+            }
         }
     }