CMSettings : Move force_show_navbar to global
Keep feature inline with 12.1, only allow owner to control the feature and mirror across users. Also add additional checks for moved settings. Change-Id: Ida11b71bc5ce9463628f8c5d76e59902d47d59bb
This commit is contained in:
parent
6113701337
commit
68665286e8
@ -46,7 +46,7 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{
|
||||
private static final boolean LOCAL_LOGV = false;
|
||||
|
||||
private static final String DATABASE_NAME = "cmsettings.db";
|
||||
private static final int DATABASE_VERSION = 5;
|
||||
private static final int DATABASE_VERSION = 6;
|
||||
|
||||
public static class CMTableNames {
|
||||
public static final String TABLE_SYSTEM = "system";
|
||||
@ -219,6 +219,16 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{
|
||||
upgradeVersion = 5;
|
||||
}
|
||||
|
||||
if (upgradeVersion < 6) {
|
||||
// Move force_show_navbar to global
|
||||
if (mUserHandle == UserHandle.USER_OWNER) {
|
||||
moveSettingsToNewTable(db, CMTableNames.TABLE_SECURE,
|
||||
CMTableNames.TABLE_GLOBAL, new String[] {
|
||||
CMSettings.Secure.DEV_FORCE_SHOW_NAVBAR
|
||||
}, true);
|
||||
}
|
||||
upgradeVersion = 6;
|
||||
}
|
||||
// *** Remember to update DATABASE_VERSION above!
|
||||
|
||||
if (upgradeVersion < newVersion) {
|
||||
@ -237,6 +247,40 @@ public class CMDatabaseHelper extends SQLiteOpenHelper{
|
||||
}
|
||||
}
|
||||
|
||||
private void moveSettingsToNewTable(SQLiteDatabase db,
|
||||
String sourceTable, String destTable,
|
||||
String[] settingsToMove, boolean doIgnore) {
|
||||
// Copy settings values from the source table to the dest, and remove from the source
|
||||
SQLiteStatement insertStmt = null;
|
||||
SQLiteStatement deleteStmt = null;
|
||||
|
||||
db.beginTransaction();
|
||||
try {
|
||||
insertStmt = db.compileStatement("INSERT "
|
||||
+ (doIgnore ? " OR IGNORE " : "")
|
||||
+ " INTO " + destTable + " (name,value) SELECT name,value FROM "
|
||||
+ sourceTable + " WHERE name=?");
|
||||
deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE name=?");
|
||||
|
||||
for (String setting : settingsToMove) {
|
||||
insertStmt.bindString(1, setting);
|
||||
insertStmt.execute();
|
||||
|
||||
deleteStmt.bindString(1, setting);
|
||||
deleteStmt.execute();
|
||||
}
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
if (insertStmt != null) {
|
||||
insertStmt.close();
|
||||
}
|
||||
if (deleteStmt != null) {
|
||||
deleteStmt.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the table and index for the specified database and table name
|
||||
* @param db The {@link SQLiteDatabase} to drop the table and index in.
|
||||
|
@ -530,6 +530,11 @@ public final class CMSettings {
|
||||
/** @hide */
|
||||
public static boolean putStringForUser(ContentResolver resolver, String name, String value,
|
||||
int userId) {
|
||||
if (MOVED_TO_SECURE.contains(name)) {
|
||||
Log.w(TAG, "Setting " + name + " has moved from CMSettings.System"
|
||||
+ " to CMSettings.Secure, value is unchanged.");
|
||||
return false;
|
||||
}
|
||||
return sNameValueCache.putStringForUser(resolver, name, value, userId);
|
||||
}
|
||||
|
||||
@ -2093,6 +2098,13 @@ public final class CMSettings {
|
||||
CALL_METHOD_GET_SECURE,
|
||||
CALL_METHOD_PUT_SECURE);
|
||||
|
||||
/** @hide */
|
||||
protected static final ArraySet<String> MOVED_TO_GLOBAL;
|
||||
static {
|
||||
MOVED_TO_GLOBAL = new ArraySet<>(1);
|
||||
MOVED_TO_GLOBAL.add(Global.DEV_FORCE_SHOW_NAVBAR);
|
||||
}
|
||||
|
||||
// region Methods
|
||||
|
||||
/**
|
||||
@ -2156,6 +2168,11 @@ public final class CMSettings {
|
||||
/** @hide */
|
||||
public static String getStringForUser(ContentResolver resolver, String name,
|
||||
int userId) {
|
||||
if (MOVED_TO_GLOBAL.contains(name)) {
|
||||
Log.w(TAG, "Setting " + name + " has moved from CMSettings.Secure"
|
||||
+ " to CMSettings.Global, value is unchanged.");
|
||||
return CMSettings.Global.getStringForUser(resolver, name, userId);
|
||||
}
|
||||
return sNameValueCache.getStringForUser(resolver, name, userId);
|
||||
}
|
||||
|
||||
@ -2173,6 +2190,11 @@ public final class CMSettings {
|
||||
/** @hide */
|
||||
public static boolean putStringForUser(ContentResolver resolver, String name, String value,
|
||||
int userId) {
|
||||
if (MOVED_TO_GLOBAL.contains(name)) {
|
||||
Log.w(TAG, "Setting " + name + " has moved from CMSettings.Secure"
|
||||
+ " to CMSettings.Global, value is unchanged.");
|
||||
return false;
|
||||
}
|
||||
return sNameValueCache.putStringForUser(resolver, name, value, userId);
|
||||
}
|
||||
|
||||
@ -2483,6 +2505,7 @@ public final class CMSettings {
|
||||
|
||||
/**
|
||||
* Developer options - Navigation Bar show switch
|
||||
* @deprecated
|
||||
* @hide
|
||||
*/
|
||||
public static final String DEV_FORCE_SHOW_NAVBAR = "dev_force_show_navbar";
|
||||
@ -3298,6 +3321,12 @@ public final class CMSettings {
|
||||
* <p>{@link cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit#FAHRENHEIT}</p>
|
||||
*/
|
||||
public static final String WEATHER_TEMPERATURE_UNIT = "weather_temperature_unit";
|
||||
|
||||
/**
|
||||
* Developer options - Navigation Bar show switch
|
||||
* @hide
|
||||
*/
|
||||
public static final String DEV_FORCE_SHOW_NAVBAR = "dev_force_show_navbar";
|
||||
// endregion
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user