OSDN Git Service

Remove white balance and non-HDR scene mode settings
[android-x86/packages-apps-Camera2.git] / src / com / android / camera / settings / SettingsManager.java
index 5fa25b8..187bfd8 100644 (file)
@@ -20,12 +20,13 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
 import android.preference.PreferenceManager;
-import android.util.Log;
 import android.util.SparseArray;
 
 import com.android.camera.ListPreference;
 import com.android.camera.app.AppController;
 import com.android.camera.app.LocationManager;
+import com.android.camera.debug.Log;
+import com.android.camera.util.CameraUtil;
 import com.android.camera.util.SettingsHelper;
 import com.android.camera2.R;
 
@@ -37,7 +38,7 @@ import java.util.List;
  * local SharedPreferences.
  */
 public class SettingsManager {
-    private static final String TAG = "SettingsManager";
+    private static final Log.Tag TAG = new Log.Tag("SettingsManager");
 
     private final Context mContext;
     private final SharedPreferences mDefaultSettings;
@@ -51,6 +52,51 @@ public class SettingsManager {
     private final AppController mAppController;
 
     /**
+     * General settings upgrade model:
+     *
+     *  On app upgrade, there are three main ways Settings can be stale/incorrect:
+     *  (1) if the type of a setting has changed.
+     *  (2) if a set value is no longer a member of the set of possible values.
+     *  (3) if the SharedPreferences backing file has changed for a setting.
+     *
+     *  Recovery strategies:
+     *  (1) catch the ClassCastException or NumberFormatException and try to do a
+     *      type conversion, or reset the setting to whatever default is valid.
+     *  (2) sanitize sets, and reset to default if set value is no longer valid.
+     *  (3) use the default value by virtue of the setting not yet being in the
+     *      new file.
+     *
+     * Special cases:
+     *
+     *  There are some settings which shouldn't be reset to default on upgrade if
+     *  possible.  We provide a callback which is executed only on strict upgrade.
+     *  This callback does special case upgrades to a subset of the settings.  This
+     *  contrasts  with the general upgrade strategies, which happen lazily, once a
+     *  setting is used.
+     *
+     * Removing obsolete key/value pairs:
+     *
+     *  This can be done in the strict upgrade callback.  The strict upgrade callback
+     *  should be idempotent, so it is important to leave removal code in the upgrade
+     *  callback so the key/value pairs are removed even if a user skips a version.
+     */
+    public interface StrictUpgradeCallback {
+        /**
+         * Will be executed in the SettingsManager constructor if the strict
+         * upgrade version counter has changed.
+         */
+        public void upgrade(SettingsManager settingsManager, int version);
+    }
+
+    /**
+     * Increment this value whenever a new StrictUpgradeCallback needs to
+     * be executed.  This defines upgrade behavior that should be executed
+     * strictly on app upgrades, when the upgrade behavior differs from the general,
+     * lazy upgrade strategies.
+     */
+    private static final int STRICT_UPGRADE_VERSION = 2;
+
+    /**
      * A List of OnSettingChangedListener's, maintained to compare to new
      * listeners and prevent duplicate registering.
      */
@@ -62,7 +108,8 @@ public class SettingsManager {
      */
     private final List<OnSharedPreferenceChangeListener> mSharedPreferenceListeners = new ArrayList<OnSharedPreferenceChangeListener>();
 
-    public SettingsManager(Context context, AppController app, int nCameras) {
+    public SettingsManager(Context context, AppController app, int nCameras,
+                           StrictUpgradeCallback upgradeCallback) {
         mContext = context;
         mAppController = app;
 
@@ -71,6 +118,15 @@ public class SettingsManager {
 
         mDefaultSettings = PreferenceManager.getDefaultSharedPreferences(context);
         initGlobal();
+
+        if (upgradeCallback != null) {
+            // Check for a strict version upgrade.
+            int version = getInt(SETTING_STRICT_UPGRADE_VERSION);
+            if (STRICT_UPGRADE_VERSION != version) {
+                upgradeCallback.upgrade(this, STRICT_UPGRADE_VERSION);
+            }
+            setInt(SETTING_STRICT_UPGRADE_VERSION, STRICT_UPGRADE_VERSION);
+        }
     }
 
     /**
@@ -285,46 +341,49 @@ public class SettingsManager {
 
     // For quick lookup from id to Setting.
     public static final int SETTING_RECORD_LOCATION = 0;
-    public static final int SETTING_VIDEO_QUALITY = 1;
-    public static final int SETTING_VIDEO_TIME_LAPSE_FRAME_INTERVAL = 2;
-    public static final int SETTING_PICTURE_SIZE = 3;
-    public static final int SETTING_JPEG_QUALITY = 4;
-    public static final int SETTING_FOCUS_MODE = 5;
-    public static final int SETTING_FLASH_MODE = 6;
-    public static final int SETTING_VIDEOCAMERA_FLASH_MODE = 7;
-    public static final int SETTING_WHITE_BALANCE = 8;
-    public static final int SETTING_SCENE_MODE = 9;
-    public static final int SETTING_EXPOSURE = 10;
-    public static final int SETTING_TIMER = 11;
-    public static final int SETTING_TIMER_SOUND_EFFECTS = 12;
-    public static final int SETTING_VIDEO_EFFECT = 13;
-    public static final int SETTING_CAMERA_ID = 14;
-    public static final int SETTING_CAMERA_HDR = 15;
-    public static final int SETTING_CAMERA_HDR_PLUS = 16;
-    public static final int SETTING_CAMERA_FIRST_USE_HINT_SHOWN = 17;
-    public static final int SETTING_VIDEO_FIRST_USE_HINT_SHOWN = 18;
-    public static final int SETTING_STARTUP_MODULE_INDEX = 19;
-    public static final int SETTING_SHIMMY_REMAINING_PLAY_TIMES_INDEX = 20;
-    public static final int SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX = 21;
-    public static final int SETTING_CAMERA_PANO_ORIENTATION = 22;
-    public static final int SETTING_CAMERA_GRID_LINES = 23;
-    public static final int SETTING_RELEASE_DIALOG_LAST_SHOWN_VERSION = 24;
+    public static final int SETTING_VIDEO_QUALITY_BACK = 1;
+    public static final int SETTING_VIDEO_QUALITY_FRONT = 2;
+    public static final int SETTING_VIDEO_TIME_LAPSE_FRAME_INTERVAL = 3;
+    public static final int SETTING_PICTURE_SIZE_BACK = 4;
+    public static final int SETTING_PICTURE_SIZE_FRONT = 5;
+    public static final int SETTING_JPEG_QUALITY = 6;
+    public static final int SETTING_FOCUS_MODE = 7;
+    public static final int SETTING_FLASH_MODE = 8;
+    public static final int SETTING_VIDEOCAMERA_FLASH_MODE = 9;
+    public static final int SETTING_SCENE_MODE = 11;
+    public static final int SETTING_EXPOSURE = 12;
+    public static final int SETTING_VIDEO_EFFECT = 15;
+    public static final int SETTING_CAMERA_ID = 16;
+    public static final int SETTING_CAMERA_HDR = 17;
+    public static final int SETTING_CAMERA_HDR_PLUS = 18;
+    public static final int SETTING_CAMERA_FIRST_USE_HINT_SHOWN = 19;
+    public static final int SETTING_VIDEO_FIRST_USE_HINT_SHOWN = 20;
+    public static final int SETTING_STARTUP_MODULE_INDEX = 21;
+    public static final int SETTING_KEY_CAMERA_MODULE_LAST_USED_INDEX = 23;
+    public static final int SETTING_CAMERA_PANO_ORIENTATION = 24;
+    public static final int SETTING_CAMERA_GRID_LINES = 25;
+    public static final int SETTING_RELEASE_DIALOG_LAST_SHOWN_VERSION = 26;
+    public static final int SETTING_FLASH_SUPPORTED_BACK_CAMERA = 27;
+    public static final int SETTING_STRICT_UPGRADE_VERSION = 28;
+    // A boolean for requesting to return to HDR plus
+    // as soon as possible, if a user requests a setting/mode option
+    // that forces them to leave HDR plus.
+    public static final int SETTING_REQUEST_RETURN_HDR_PLUS = 30;
 
     // Shared preference keys.
     public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key";
-    public static final String KEY_VIDEO_QUALITY = "pref_video_quality_key";
+    public static final String KEY_VIDEO_QUALITY_BACK = "pref_video_quality_back_key";
+    public static final String KEY_VIDEO_QUALITY_FRONT = "pref_video_quality_front_key";
     public static final String KEY_VIDEO_TIME_LAPSE_FRAME_INTERVAL =
             "pref_video_time_lapse_frame_interval_key";
-    public static final String KEY_PICTURE_SIZE = "pref_camera_picturesize_key";
+    public static final String KEY_PICTURE_SIZE_BACK = "pref_camera_picturesize_back_key";
+    public static final String KEY_PICTURE_SIZE_FRONT = "pref_camera_picturesize_front_key";
     public static final String KEY_JPEG_QUALITY = "pref_camera_jpegquality_key";
     public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key";
     public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key";
     public static final String KEY_VIDEOCAMERA_FLASH_MODE = "pref_camera_video_flashmode_key";
-    public static final String KEY_WHITE_BALANCE = "pref_camera_whitebalance_key";
     public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key";
     public static final String KEY_EXPOSURE = "pref_camera_exposure_key";
-    public static final String KEY_TIMER = "pref_camera_timer_key";
-    public static final String KEY_TIMER_SOUND_EFFECTS = "pref_camera_timer_sound_key";
     public static final String KEY_VIDEO_EFFECT = "pref_video_effect_key";
     public static final String KEY_CAMERA_ID = "pref_camera_id_key";
     public static final String KEY_CAMERA_HDR = "pref_camera_hdr_key";
@@ -334,14 +393,16 @@ public class SettingsManager {
     public static final String KEY_VIDEO_FIRST_USE_HINT_SHOWN =
             "pref_video_first_use_hint_shown_key";
     public static final String KEY_STARTUP_MODULE_INDEX = "camera.startup_module";
-    public static final String KEY_SHIMMY_REMAINING_PLAY_TIMES =
-            "pref_shimmy_remaining_play_times";
     public static final String KEY_CAMERA_MODULE_LAST_USED =
             "pref_camera_module_last_used_index";
     public static final String KEY_CAMERA_PANO_ORIENTATION = "pref_camera_pano_orientation";
     public static final String KEY_CAMERA_GRID_LINES = "pref_camera_grid_lines";
     public static final String KEY_RELEASE_DIALOG_LAST_SHOWN_VERSION =
             "pref_release_dialog_last_shown_version";
+    public static final String KEY_FLASH_SUPPORTED_BACK_CAMERA =
+            "pref_flash_supported_back_camera";
+    public static final String KEY_STRICT_UPGRADE_VERSION = "pref_strict_upgrade_version";
+    public static final String KEY_REQUEST_RETURN_HDR_PLUS = "pref_request_return_hdr_plus";
 
     public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
 
@@ -360,7 +421,7 @@ public class SettingsManager {
         /**
          * A constructor used to store a setting's profile.
          */
-        Setting(String source, String type, String defaultValue, String key,
+        public Setting(String source, String type, String defaultValue, String key,
                 String[] values, boolean flushOnCameraChange) {
             mSource = source;
             mType = type;
@@ -424,7 +485,10 @@ public class SettingsManager {
      * Get the SharedPreferences needed to query/update the setting.
      */
     public SharedPreferences getSettingSource(Setting setting) {
-        String source = setting.getSource();
+        return getSettingSource(setting.getSource());
+    }
+
+    private SharedPreferences getSettingSource(String source) {
         if (source.equals(SOURCE_DEFAULT)) {
             return mDefaultSettings;
         }
@@ -435,7 +499,8 @@ public class SettingsManager {
             return mCameraSettings;
         }
         if (source.equals(SOURCE_MODULE)) {
-            int modeIndex = mAppController.getCurrentModuleIndex();
+            int modeIndex = CameraUtil.getCameraModeParentModeId(
+                mAppController.getCurrentModuleIndex(), mAppController.getAndroidContext());
             return getModulePreferences(modeIndex);
         }
         return null;
@@ -454,10 +519,11 @@ public class SettingsManager {
         if (setting == null || !TYPE_STRING.equals(setting.getType())) {
             return -1;
         }
+        return getStringValueIndex(setting.getStringValues(), get(id));
+    }
 
-        String value = get(id);
+    private int getStringValueIndex(String[] possibleValues, String value) {
         if (value != null) {
-            String[] possibleValues = setting.getStringValues();
             if (possibleValues != null) {
                 for (int i = 0; i < possibleValues.length; i++) {
                     if (value.equals(possibleValues[i])) {
@@ -493,16 +559,156 @@ public class SettingsManager {
     }
 
     /**
+     * Returns whether this Setting was last set as a String.
+     */
+    private boolean isString(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
+        try {
+            preferences.getString(setting.getKey(), null);
+            return true;
+        } catch (ClassCastException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Returns whether this Setting was last set as a boolean.
+     */
+    private boolean isBoolean(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
+        try {
+            preferences.getBoolean(setting.getKey(), false);
+            return true;
+        } catch (ClassCastException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Returns whether this Setting was last set as an Integer.
+     */
+    private boolean isInteger(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
+        try {
+            preferences.getInt(setting.getKey(), 0);
+            return true;
+        } catch (NumberFormatException e) {
+            return false;
+        }
+    }
+
+    /**
+     * Recover a Setting by converting it to a String if the type
+     * is known and the type conversion is successful, otherwise
+     * reset to the default.
+     */
+    private String recoverToString(int id, String source) {
+        String value;
+        try {
+            if (isBoolean(id, source)) {
+                value = (getBoolean(id, source) ? VALUE_ON : VALUE_OFF);
+            } else if (isInteger(id, source)) {
+                value = Integer.toString(getInt(id, source));
+            } else {
+                throw new Exception();
+            }
+        } catch (Exception e) {
+            value = mSettingsCache.get(id).getDefault();
+        }
+        set(id, source, value);
+        return value;
+    }
+
+    /**
+     * Recover a Setting by converting it to a boolean if the type
+     * is known and the type conversion is successful, otherwise
+     * reset to the default.
+     */
+    private boolean recoverToBoolean(int id, String source) {
+        boolean value;
+        try {
+            if (isString(id, source)) {
+                value = VALUE_ON.equals(get(id, source));
+            } else if (isInteger(id, source)) {
+                value = getInt(id, source) != 0;
+            } else {
+                throw new Exception();
+            }
+        } catch (Exception e) {
+            value = VALUE_ON.equals(mSettingsCache.get(id).getDefault());
+        }
+        setBoolean(id, source, value);
+        return value;
+    }
+
+    /**
+     * Recover a Setting by converting it to an Integer if the type
+     * is known and the type conversion is successful, otherwise
+     * reset to the default.
+     */
+    private int recoverToInteger(int id, String source) {
+        int value;
+        try {
+            if (isString(id, source)) {
+                value = Integer.parseInt(get(id, source));
+            } else if (isBoolean(id, source)) {
+                value = getBoolean(id, source) ? 1 : 0;
+            } else {
+                throw new Exception();
+            }
+        } catch (Exception e) {
+            value = Integer.parseInt(mSettingsCache.get(id).getDefault());
+        }
+        setInt(id, value);
+        return value;
+    }
+
+    /**
+     * Check if a String value is in the set of possible values for a Setting.
+     * We only keep track of possible values for String types for now.
+     */
+    private String sanitize(Setting setting, String value) {
+        if (setting.getStringValues() != null &&
+                getStringValueIndex(setting.getStringValues(), value) < 0) {
+            // If the set of possible values is not empty, and the value
+            // is not in the set of possible values, use the default, because
+            // the set of possible values probably changed.
+            return setting.getDefault();
+        }
+        return value;
+    }
+
+    /**
      * Get a Setting's String value based on Setting id.
      */
-    // TODO: rename to something more descriptive.
+    // TODO: rename to something more descriptive like getString.
     public String get(int id) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        return get(id, setting.getSource());
+    }
+
+    /**
+     * Get a Setting's String value based on Setting id and a source file id.
+     */
+    public String get(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
-            return preferences.getString(setting.getKey(), setting.getDefault());
+            try {
+                String value = preferences.getString(setting.getKey(), setting.getDefault());
+                return sanitize(setting, value);
+            } catch (ClassCastException e) {
+                // If the api defines this Setting as a String, but the
+                // last set saved it as a different type, try to recover
+                // the value, but if impossible reset to default.
+                return recoverToString(id, source);
+            }
         } else {
-            return null;
+            throw new IllegalStateException(
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -511,12 +717,28 @@ public class SettingsManager {
      */
     public boolean getBoolean(int id) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
-        boolean defaultValue = setting.getDefault().equals(VALUE_ON);
+        return getBoolean(id, setting.getSource());
+    }
+
+    /**
+     * Get a Setting's boolean value based on a Setting id and a source file id.
+     */
+    public boolean getBoolean(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
+        boolean defaultValue = VALUE_ON.equals(setting.getDefault());
         if (preferences != null) {
-            return preferences.getBoolean(setting.getKey(), defaultValue);
+            try {
+                return preferences.getBoolean(setting.getKey(), defaultValue);
+            } catch (ClassCastException e) {
+                // If the api defines this Setting as a boolean, but the
+                // last set saved it as a different type, try to recover
+                // the value, but if impossible reset to default.
+                return recoverToBoolean(id, source);
+            }
         } else {
-            return defaultValue;
+            throw new IllegalStateException(
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -525,12 +747,28 @@ public class SettingsManager {
      */
     public int getInt(int id) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        return getInt(id, setting.getSource());
+    }
+
+    /**
+     * Get a Setting's int value based on Setting id and a source file id.
+     */
+    public int getInt(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         int defaultValue = Integer.parseInt(setting.getDefault());
         if (preferences != null) {
-            return preferences.getInt(setting.getKey(), defaultValue);
+            try {
+                return preferences.getInt(setting.getKey(), defaultValue);
+            } catch (NumberFormatException e) {
+                // If the api defines this Setting as an Integer, but the
+                // last set saved it as a different type, try to recover
+                // the value, but if impossible reset to default.
+                return recoverToInteger(id, source);
+            }
         } else {
-            return defaultValue;
+            throw new IllegalStateException(
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -540,9 +778,21 @@ public class SettingsManager {
     // TODO: rename to something more descriptive.
     public void set(int id, String value) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        set(id, setting.getSource(), value);
+    }
+
+    /**
+     * Set a Setting with a String value based on Setting id and a source file id.
+     */
+    public void set(int id, String source, String value) {
+        Setting setting = mSettingsCache.get(id);
+        value = sanitize(setting, value);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             preferences.edit().putString(setting.getKey(), value).apply();
+        } else {
+            throw new IllegalStateException(
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -551,9 +801,19 @@ public class SettingsManager {
      */
     public void setBoolean(int id, boolean value) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        setBoolean(id, setting.getSource(), value);
+    }
+    /**
+     * Set a Setting with a boolean value based on Setting id and a source file id.
+     */
+    public void setBoolean(int id, String source, boolean value) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             preferences.edit().putBoolean(setting.getKey(), value).apply();
+        } else {
+            throw new IllegalStateException(
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -562,9 +822,20 @@ public class SettingsManager {
      */
     public void setInt(int id, int value) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
+        setInt(id, setting.getSource(), value);
+    }
+
+    /**
+     * Set a Setting with an int value based on Setting id and a source file id.
+     */
+    public void setInt(int id, String source, int value) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
         if (preferences != null) {
             preferences.edit().putInt(setting.getKey(), value).apply();
+        } else {
+            throw new IllegalStateException(
+                "Setting source=" + source + " is unitialized.");
         }
     }
 
@@ -573,11 +844,21 @@ public class SettingsManager {
      */
     public boolean isSet(int id) {
         Setting setting = mSettingsCache.get(id);
-        SharedPreferences preferences = getSettingSource(setting);
-        if (preferences == null) {
-            return false;
+        return isSet(id, setting.getSource());
+    }
+
+    /**
+     * Check if a Setting has ever been set based on Setting id and a source file id.
+     */
+    public boolean isSet(int id, String source) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(source);
+        if (preferences != null) {
+            return preferences.contains(setting.getKey());
+        } else {
+            throw new IllegalStateException(
+                "Setting source=" + setting.getSource() + " is unitialized.");
         }
-        return preferences.contains(setting.getKey());
     }
 
     /**
@@ -588,6 +869,9 @@ public class SettingsManager {
         SharedPreferences preferences = getSettingSource(setting);
         if (preferences != null) {
             preferences.edit().putString(setting.getKey(), setting.getDefault());
+        } else {
+            throw new IllegalStateException(
+                "Setting source=" + setting.getSource() + " is unitialized.");
         }
     }
 
@@ -614,7 +898,22 @@ public class SettingsManager {
                 throw new IllegalArgumentException("Type " + type + " is not known.");
             }
         } else {
-            return false;
+            throw new IllegalStateException(
+                "Setting source=" + setting.getSource() + " is unitialized.");
+        }
+    }
+
+    /**
+     * Remove a Setting from SharedPreferences.
+     */
+    public void remove(int id) {
+        Setting setting = mSettingsCache.get(id);
+        SharedPreferences preferences = getSettingSource(setting);
+        if (preferences != null) {
+            preferences.edit().remove(setting.getKey()).apply();
+        } else {
+            throw new IllegalStateException(
+                "Setting source=" + setting.getSource() + " is unitialized.");
         }
     }
 
@@ -625,11 +924,19 @@ public class SettingsManager {
                 values, FLUSH_OFF);
     }
 
-    public static Setting getPictureSizeSetting(Context context) {
+    public static Setting getPictureSizeBackSetting(Context context) {
+        String defaultValue = null;
+        String[] values = context.getResources().getStringArray(
+                R.array.pref_camera_picturesize_entryvalues);
+        return new Setting(SOURCE_DEFAULT, TYPE_STRING, defaultValue, KEY_PICTURE_SIZE_BACK,
+                values, FLUSH_OFF);
+    }
+
+    public static Setting getPictureSizeFrontSetting(Context context) {
         String defaultValue = null;
         String[] values = context.getResources().getStringArray(
                 R.array.pref_camera_picturesize_entryvalues);
-        return new Setting(SOURCE_DEFAULT, TYPE_STRING, defaultValue, KEY_PICTURE_SIZE,
+        return new Setting(SOURCE_DEFAULT, TYPE_STRING, defaultValue, KEY_PICTURE_SIZE_FRONT,
                 values, FLUSH_OFF);
     }
 
@@ -644,14 +951,6 @@ public class SettingsManager {
                 values, FLUSH_ON);
     }
 
-    public static Setting getWhiteBalanceSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_camera_whitebalance_default);
-        String[] values = context.getResources().getStringArray(
-                R.array.pref_camera_whitebalance_entryvalues);
-        return new Setting(SOURCE_CAMERA, TYPE_STRING, defaultValue, KEY_WHITE_BALANCE,
-                values, FLUSH_OFF);
-    }
-
     public static Setting getHdrSetting(Context context) {
         String defaultValue = context.getString(R.string.pref_camera_hdr_default);
         String[] values = context.getResources().getStringArray(
@@ -710,26 +1009,19 @@ public class SettingsManager {
                 values, FLUSH_OFF);
     }
 
-    public static Setting getTimerSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_camera_timer_default);
-        String[] values = null; // TODO: get the values dynamically.
-        return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER,
-                values, FLUSH_OFF);
-    }
-
-    public static Setting getTimerSoundSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_camera_timer_sound_default);
+    public static Setting getVideoQualityBackSetting(Context context) {
+        String defaultValue = context.getString(R.string.pref_video_quality_default);
         String[] values = context.getResources().getStringArray(
-                R.array.pref_camera_timer_sound_entryvalues);
-        return new Setting(SOURCE_GLOBAL, TYPE_STRING, defaultValue, KEY_TIMER_SOUND_EFFECTS,
+                R.array.pref_video_quality_entryvalues);
+        return new Setting(SOURCE_DEFAULT, TYPE_STRING, defaultValue, KEY_VIDEO_QUALITY_BACK,
                 values, FLUSH_OFF);
     }
 
-    public static Setting getVideoQualitySetting(Context context) {
+    public static Setting getVideoQualityFrontSetting(Context context) {
         String defaultValue = context.getString(R.string.pref_video_quality_default);
         String[] values = context.getResources().getStringArray(
                 R.array.pref_video_quality_entryvalues);
-        return new Setting(SOURCE_DEFAULT, TYPE_STRING, defaultValue, KEY_VIDEO_QUALITY,
+        return new Setting(SOURCE_DEFAULT, TYPE_STRING, defaultValue, KEY_VIDEO_QUALITY_FRONT,
                 values, FLUSH_OFF);
     }
 
@@ -781,12 +1073,6 @@ public class SettingsManager {
                 KEY_STARTUP_MODULE_INDEX, values, FLUSH_OFF);
     }
 
-    public static Setting getShimmyRemainingTimesSetting(Context context) {
-        String defaultValue = context.getString(R.string.pref_shimmy_play_times);
-        return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
-                KEY_SHIMMY_REMAINING_PLAY_TIMES, null, FLUSH_OFF);
-    }
-
     public static Setting getLastUsedCameraModule(Context context) {
         String defaultValue = Integer.toString(context.getResources()
                 .getInteger(R.integer.camera_mode_photo));
@@ -815,6 +1101,24 @@ public class SettingsManager {
                 KEY_RELEASE_DIALOG_LAST_SHOWN_VERSION, null, FLUSH_OFF);
     }
 
+    public static Setting getFlashSupportedBackCameraSetting(Context context) {
+        String defaultValue = context.getString(R.string.setting_none_value);
+        return new Setting(SOURCE_GLOBAL, TYPE_BOOLEAN, defaultValue,
+                KEY_FLASH_SUPPORTED_BACK_CAMERA, null, FLUSH_OFF);
+    }
+
+    public static Setting getStrictUpgradeVersionSetting(Context context) {
+        String defaultValue = "0";
+        return new Setting(SOURCE_DEFAULT, TYPE_INTEGER, defaultValue,
+                KEY_STRICT_UPGRADE_VERSION, null, FLUSH_OFF);
+    }
+
+    public static Setting getRequestReturnHdrPlusSetting(Context context) {
+        String defaultValue = context.getString(R.string.setting_none_value);
+        return new Setting(SOURCE_MODULE, TYPE_BOOLEAN, VALUE_OFF,
+                KEY_REQUEST_RETURN_HDR_PLUS, null, FLUSH_OFF);
+    }
+
     // Utilities.
 
     /**
@@ -830,11 +1134,26 @@ public class SettingsManager {
      * Returns whether hdr plus mode is set on.
      */
     public boolean isHdrPlusOn() {
+        String hdrOn = get(SettingsManager.SETTING_CAMERA_HDR_PLUS);
+        return hdrOn.equals(SettingsManager.VALUE_ON);
+    }
+
+    /**
+     * Returns whether hdr mode is set on.
+     */
+    public boolean isHdrOn() {
         String hdrOn = get(SettingsManager.SETTING_CAMERA_HDR);
         return hdrOn.equals(SettingsManager.VALUE_ON);
     }
 
     /**
+     * Returns whether the app should return to hdr plus mode if possible.
+     */
+    public boolean requestsReturnToHdrPlus() {
+        return getBoolean(SettingsManager.SETTING_REQUEST_RETURN_HDR_PLUS);
+    }
+
+    /**
      * Returns whether grid lines are set on.
      */
     public boolean areGridLinesOn() {
@@ -916,13 +1235,7 @@ public class SettingsManager {
      * given location manager.
      */
     public void syncLocationManager(LocationManager locationManager) {
-        boolean value = false;
-        try {
-            value = this.getBoolean(SettingsManager.SETTING_RECORD_LOCATION);
-        } catch (Exception ex) {
-            // Keep disabled, if we cannot parse the preference.
-            Log.w(TAG, "Could not parse location value. Defaulting to 'false'.");
-        }
+        boolean value = getBoolean(SettingsManager.SETTING_RECORD_LOCATION);
         locationManager.recordLocation(value);
     }
 }