@@ -67,7 +67,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
6767 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
6868 // is properly propagated through your change. Not doing so will result in a loss of user
6969 // settings.
70- private static final int DATABASE_VERSION = 85 ;
70+ private static final int DATABASE_VERSION = 86 ;
7171
7272 private Context mContext ;
7373 private int mUserHandle ;
@@ -308,7 +308,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
308308 Settings .Secure .WIFI_WATCHDOG_PING_DELAY_MS ,
309309 Settings .Secure .WIFI_WATCHDOG_PING_TIMEOUT_MS ,
310310 };
311- moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_SECURE , settingsToMove );
311+ moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_SECURE , settingsToMove , false );
312312 upgradeVersion = 28 ;
313313 }
314314
@@ -674,7 +674,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
674674 "lockscreen.lockedoutpermanently" ,
675675 "lockscreen.password_salt"
676676 };
677- moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_SECURE , settingsToMove );
677+ moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_SECURE , settingsToMove , false );
678678 upgradeVersion = 52 ;
679679 }
680680
@@ -724,7 +724,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
724724 Secure .SET_INSTALL_LOCATION ,
725725 Secure .DEFAULT_INSTALL_LOCATION
726726 };
727- moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_SECURE , settingsToMove );
727+ moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_SECURE , settingsToMove , false );
728728 db .beginTransaction ();
729729 SQLiteStatement stmt = null ;
730730 try {
@@ -1209,9 +1209,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
12091209 // new users can be created.
12101210 createGlobalTable (db );
12111211 String [] settingsToMove = hashsetToStringArray (SettingsProvider .sSystemGlobalKeys );
1212- moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_GLOBAL , settingsToMove );
1212+ moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_GLOBAL , settingsToMove , false );
12131213 settingsToMove = hashsetToStringArray (SettingsProvider .sSecureGlobalKeys );
1214- moveSettingsToNewTable (db , TABLE_SECURE , TABLE_GLOBAL , settingsToMove );
1214+ moveSettingsToNewTable (db , TABLE_SECURE , TABLE_GLOBAL , settingsToMove , false );
12151215
12161216 db .setTransactionSuccessful ();
12171217 } finally {
@@ -1254,7 +1254,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
12541254 db .beginTransaction ();
12551255 SQLiteStatement stmt = null ;
12561256 try {
1257- // Patch up the slightly-wrong key migration from 82 -> 83
1257+ // Patch up the slightly-wrong key migration from 82 -> 83 for those
1258+ // devices that missed it, ignoring if the move is redundant
12581259 String [] settingsToMove = {
12591260 Settings .Secure .ADB_ENABLED ,
12601261 Settings .Secure .BLUETOOTH_ON ,
@@ -1263,7 +1264,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
12631264 Settings .Secure .INSTALL_NON_MARKET_APPS ,
12641265 Settings .Secure .USB_MASS_STORAGE_ENABLED
12651266 };
1266- moveSettingsToNewTable (db , TABLE_SECURE , TABLE_GLOBAL , settingsToMove );
1267+ moveSettingsToNewTable (db , TABLE_SECURE , TABLE_GLOBAL , settingsToMove , true );
12671268 db .setTransactionSuccessful ();
12681269 } finally {
12691270 db .endTransaction ();
@@ -1272,6 +1273,21 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
12721273 upgradeVersion = 85 ;
12731274 }
12741275
1276+ if (upgradeVersion == 85 ) {
1277+ db .beginTransaction ();
1278+ try {
1279+ // Fix up the migration, ignoring already-migrated elements, to snap up to
1280+ // date with new changes to the set of global versus system/secure settings
1281+ String [] settingsToMove = { Settings .System .STAY_ON_WHILE_PLUGGED_IN };
1282+ moveSettingsToNewTable (db , TABLE_SYSTEM , TABLE_GLOBAL , settingsToMove , true );
1283+
1284+ db .setTransactionSuccessful ();
1285+ } finally {
1286+ db .endTransaction ();
1287+ }
1288+ upgradeVersion = 86 ;
1289+ }
1290+
12751291 // *** Remember to update DATABASE_VERSION above!
12761292
12771293 if (upgradeVersion != currentVersion ) {
@@ -1306,15 +1322,16 @@ private String[] hashsetToStringArray(HashSet<String> set) {
13061322
13071323 private void moveSettingsToNewTable (SQLiteDatabase db ,
13081324 String sourceTable , String destTable ,
1309- String [] settingsToMove ) {
1325+ String [] settingsToMove , boolean doIgnore ) {
13101326 // Copy settings values from the source table to the dest, and remove from the source
13111327 SQLiteStatement insertStmt = null ;
13121328 SQLiteStatement deleteStmt = null ;
13131329
13141330 db .beginTransaction ();
13151331 try {
1316- insertStmt = db .compileStatement ("INSERT INTO "
1317- + destTable + " (name,value) SELECT name,value FROM "
1332+ insertStmt = db .compileStatement ("INSERT "
1333+ + (doIgnore ? " OR IGNORE " : "" )
1334+ + " INTO " + destTable + " (name,value) SELECT name,value FROM "
13181335 + sourceTable + " WHERE name=?" );
13191336 deleteStmt = db .compileStatement ("DELETE FROM " + sourceTable + " WHERE name=?" );
13201337
0 commit comments