Skip to content

Commit 970683c

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Further fixup of migration to global settings" into jb-mr1-dev
2 parents 4db5d23 + 9219874 commit 970683c

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

core/java/android/provider/Settings.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,13 +878,16 @@ public static final class System extends NameValueTable {
878878
private static final HashSet<String> MOVED_TO_GLOBAL;
879879
static {
880880
MOVED_TO_GLOBAL = new HashSet<String>();
881+
// these were originally in system but migrated to secure in the past,
882+
// so are duplicated in the Secure.* namespace
881883
MOVED_TO_GLOBAL.add(Global.ADB_ENABLED);
882884
MOVED_TO_GLOBAL.add(Global.BLUETOOTH_ON);
883885
MOVED_TO_GLOBAL.add(Global.DATA_ROAMING);
884886
MOVED_TO_GLOBAL.add(Global.DEVICE_PROVISIONED);
885887
MOVED_TO_GLOBAL.add(Global.INSTALL_NON_MARKET_APPS);
886888
MOVED_TO_GLOBAL.add(Global.USB_MASS_STORAGE_ENABLED);
887889

890+
// these are moving directly from system to global
888891
MOVED_TO_GLOBAL.add(Settings.Global.AIRPLANE_MODE_ON);
889892
MOVED_TO_GLOBAL.add(Settings.Global.AIRPLANE_MODE_RADIOS);
890893
MOVED_TO_GLOBAL.add(Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);

packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,22 @@ public class SettingsProvider extends ContentProvider {
113113
// table, shared across all users
114114
// These must match Settings.Secure.MOVED_TO_GLOBAL
115115
sSecureGlobalKeys = new HashSet<String>();
116+
sSecureGlobalKeys.add(Settings.Secure.ADB_ENABLED);
116117
sSecureGlobalKeys.add(Settings.Secure.ASSISTED_GPS_ENABLED);
118+
sSecureGlobalKeys.add(Settings.Secure.BLUETOOTH_ON);
117119
sSecureGlobalKeys.add(Settings.Secure.CDMA_CELL_BROADCAST_SMS);
118120
sSecureGlobalKeys.add(Settings.Secure.CDMA_ROAMING_MODE);
119121
sSecureGlobalKeys.add(Settings.Secure.CDMA_SUBSCRIPTION_MODE);
120122
sSecureGlobalKeys.add(Settings.Secure.DATA_ACTIVITY_TIMEOUT_MOBILE);
121123
sSecureGlobalKeys.add(Settings.Secure.DATA_ACTIVITY_TIMEOUT_WIFI);
124+
sSecureGlobalKeys.add(Settings.Secure.DATA_ROAMING);
122125
sSecureGlobalKeys.add(Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED);
126+
sSecureGlobalKeys.add(Settings.Secure.DEVICE_PROVISIONED);
123127
sSecureGlobalKeys.add(Settings.Secure.DISPLAY_DENSITY_FORCED);
124128
sSecureGlobalKeys.add(Settings.Secure.DISPLAY_SIZE_FORCED);
125129
sSecureGlobalKeys.add(Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE);
126130
sSecureGlobalKeys.add(Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE);
131+
sSecureGlobalKeys.add(Settings.Secure.INSTALL_NON_MARKET_APPS);
127132
sSecureGlobalKeys.add(Settings.Secure.MOBILE_DATA);
128133
sSecureGlobalKeys.add(Settings.Secure.NETSTATS_DEV_BUCKET_DURATION);
129134
sSecureGlobalKeys.add(Settings.Secure.NETSTATS_DEV_DELETE_AGE);
@@ -167,6 +172,7 @@ public class SettingsProvider extends ContentProvider {
167172
sSecureGlobalKeys.add(Settings.Secure.THROTTLE_RESET_DAY);
168173
sSecureGlobalKeys.add(Settings.Secure.THROTTLE_THRESHOLD_BYTES);
169174
sSecureGlobalKeys.add(Settings.Secure.THROTTLE_VALUE_KBITSPS);
175+
sSecureGlobalKeys.add(Settings.Secure.USB_MASS_STORAGE_ENABLED);
170176
sSecureGlobalKeys.add(Settings.Secure.USE_GOOGLE_MAIL);
171177
sSecureGlobalKeys.add(Settings.Secure.WEB_AUTOFILL_QUERY_URL);
172178
sSecureGlobalKeys.add(Settings.Secure.WIFI_COUNTRY_CODE);
@@ -193,12 +199,6 @@ public class SettingsProvider extends ContentProvider {
193199
// Keys from the 'system' table now moved to 'global'
194200
// These must match Settings.System.MOVED_TO_GLOBAL
195201
sSystemGlobalKeys = new HashSet<String>();
196-
sSystemGlobalKeys.add(Settings.Secure.ADB_ENABLED);
197-
sSystemGlobalKeys.add(Settings.Secure.BLUETOOTH_ON);
198-
sSystemGlobalKeys.add(Settings.Secure.DATA_ROAMING);
199-
sSystemGlobalKeys.add(Settings.Secure.DEVICE_PROVISIONED);
200-
sSystemGlobalKeys.add(Settings.Secure.INSTALL_NON_MARKET_APPS);
201-
sSystemGlobalKeys.add(Settings.Secure.USB_MASS_STORAGE_ENABLED);
202202

203203
sSystemGlobalKeys.add(Settings.System.AIRPLANE_MODE_ON);
204204
sSystemGlobalKeys.add(Settings.System.AIRPLANE_MODE_RADIOS);
@@ -214,6 +214,7 @@ public class SettingsProvider extends ContentProvider {
214214
sSystemGlobalKeys.add(Settings.System.UNLOCK_SOUND);
215215
sSystemGlobalKeys.add(Settings.System.LOW_BATTERY_SOUND);
216216
sSystemGlobalKeys.add(Settings.System.POWER_SOUNDS_ENABLED);
217+
sSystemGlobalKeys.add(Settings.System.STAY_ON_WHILE_PLUGGED_IN);
217218
sSystemGlobalKeys.add(Settings.System.WIFI_SLEEP_POLICY);
218219
}
219220

0 commit comments

Comments
 (0)