summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/settings/AppUpgrader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/camera/settings/AppUpgrader.java')
-rw-r--r--src/com/android/camera/settings/AppUpgrader.java69
1 files changed, 45 insertions, 24 deletions
diff --git a/src/com/android/camera/settings/AppUpgrader.java b/src/com/android/camera/settings/AppUpgrader.java
index 2e60e70be..e94c2d100 100644
--- a/src/com/android/camera/settings/AppUpgrader.java
+++ b/src/com/android/camera/settings/AppUpgrader.java
@@ -43,6 +43,7 @@ public class AppUpgrader extends SettingsUpgrader {
private static final String OLD_CAMERA_PREFERENCES_PREFIX = "_preferences_";
private static final String OLD_MODULE_PREFERENCES_PREFIX = "_preferences_module_";
private static final String OLD_GLOBAL_PREFERENCES_FILENAME = "_preferences_camera";
+ private static final String OLD_KEY_UPGRADE_VERSION = "pref_strict_upgrade_version";
/**
* With this version everyone was forced to choose their location settings
@@ -60,8 +61,13 @@ public class AppUpgrader extends SettingsUpgrader {
/**
* With this version, the names of the files storing camera specific and
* module specific settings changed.
+ * <p>
+ * NOTE: changed this from 4 to 6 to re-run on latest Glacier upgrade.
+ * Initial upgraders to Glacier will run conversion once as of the change.
+ * When re-run for early dogfooders, values will get overwritten but will
+ * all work.
*/
- private static final int CAMERA_MODULE_SETTINGS_FILES_RENAMED_VERSION = 4;
+ private static final int CAMERA_MODULE_SETTINGS_FILES_RENAMED_VERSION = 6;
/**
* With this version, timelapse mode was removed and mode indices need to be
@@ -80,6 +86,12 @@ public class AppUpgrader extends SettingsUpgrader {
private static final int CAMERA_SETTINGS_MAX_BRIGHTNESS = 7;
/**
+ * With this version internal storage is changed to use only Strings, and
+ * a type conversion process should execute.
+ */
+ private static final int CAMERA_SETTINGS_STRINGS_UPGRADE = 5;
+
+ /**
* Increment this value whenever new AOSP UpgradeSteps need to be executed.
*/
public static final int APP_UPGRADE_VERSION = 7;
@@ -93,28 +105,35 @@ public class AppUpgrader extends SettingsUpgrader {
@Override
protected int getLastVersion(SettingsManager settingsManager) {
- // Prior appwide versions were stored in the default preferences. If
- // current
- // state indicates this is still the case, port the version and then
- // process
- // all other known app settings to the new SettingsManager string
- // scheme.
- try {
- return super.getLastVersion(settingsManager);
- } catch (ClassCastException e) {
- // We infer that a ClassCastException here means we have pre-String
- // settings that need to be upgraded, so we hack in a full upgrade
- // here.
- upgradeTypesToStrings(settingsManager);
- // Retrieve version as default now that we're sure it is converted
- return super.getLastVersion(settingsManager);
+ // Prior upgrade versions were stored in the default preferences as int
+ // and String. We create a new version location for migration to String.
+ // If we don't have a version persisted in the new location, check for
+ // the prior value from the old location. We expect the old value to be
+ // processed during {@link #upgradeTypesToStrings}.
+ SharedPreferences defaultPreferences = settingsManager.getDefaultPreferences();
+ if (defaultPreferences.contains(OLD_KEY_UPGRADE_VERSION)) {
+ Map<String, ?> allPrefs = defaultPreferences.getAll();
+ Object oldVersion = allPrefs.get(OLD_KEY_UPGRADE_VERSION);
+ defaultPreferences.edit().remove(OLD_KEY_UPGRADE_VERSION).apply();
+ if (oldVersion instanceof Integer) {
+ return (Integer) oldVersion;
+ } else if (oldVersion instanceof String) {
+ return SettingsManager.convertToInt((String) oldVersion);
+ }
}
+ return super.getLastVersion(settingsManager);
}
@Override
public void upgrade(SettingsManager settingsManager, int lastVersion, int currentVersion) {
Context context = mAppController.getAndroidContext();
+ // Do strings upgrade first before 'earlier' upgrades, since they assume
+ // valid storage of values.
+ if (lastVersion < CAMERA_SETTINGS_STRINGS_UPGRADE) {
+ upgradeTypesToStrings(settingsManager);
+ }
+
if (lastVersion < FORCE_LOCATION_CHOICE_VERSION) {
forceLocationChoice(settingsManager);
}
@@ -166,11 +185,6 @@ public class AppUpgrader extends SettingsUpgrader {
SharedPreferences oldGlobalPreferences =
settingsManager.openPreferences(OLD_GLOBAL_PREFERENCES_FILENAME);
- // Strict upgrade version: Integer -> String, from default.
- int strictUpgradeVersion = removeInteger(defaultPreferences, Keys.KEY_UPGRADE_VERSION);
- settingsManager.set(SettingsManager.SCOPE_GLOBAL, Keys.KEY_UPGRADE_VERSION,
- strictUpgradeVersion);
-
// Location: boolean -> String, from default.
if (defaultPreferences.contains(Keys.KEY_RECORD_LOCATION)) {
boolean location = removeBoolean(defaultPreferences, Keys.KEY_RECORD_LOCATION);
@@ -340,6 +354,11 @@ public class AppUpgrader extends SettingsUpgrader {
* SharedPreferences file to another SharedPreferences file, as Strings.
* Settings that are not a known supported format (int/boolean/String)
* are dropped with warning.
+ *
+ * This will normally be run only once but was used both for upgrade version
+ * 4 and 6 -- in 6 we repair issues with previous runs of the upgrader. So
+ * we make sure to remove entries from destination if the source isn't valid
+ * like a null or unsupported type.
*/
private void copyPreferences(SharedPreferences oldPrefs,
SharedPreferences newPrefs) {
@@ -348,7 +367,8 @@ public class AppUpgrader extends SettingsUpgrader {
String key = entry.getKey();
Object value = entry.getValue();
if (value == null) {
- Log.w(TAG, "skipped upgrade for null key " + key);
+ Log.w(TAG, "skipped upgrade and removing entry for null key " + key);
+ newPrefs.edit().remove(key).apply();
} else if (value instanceof Boolean) {
String boolValue = SettingsManager.convert((Boolean) value);
newPrefs.edit().putString(key, boolValue).apply();
@@ -370,8 +390,9 @@ public class AppUpgrader extends SettingsUpgrader {
} else if (value instanceof String){
newPrefs.edit().putString(key, (String) value).apply();
} else {
- Log.w(TAG,"skipped upgrade for unrecognized key type " +
- key + " : " + value.getClass());
+ Log.w(TAG,"skipped upgrade and removing entry for unrecognized "
+ + "key type " + key + " : " + value.getClass());
+ newPrefs.edit().remove(key).apply();
}
}
}