@@ -68,7 +68,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
6868 // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
6969 // is properly propagated through your change. Not doing so will result in a loss of user
7070 // settings.
71- private static final int DATABASE_VERSION = 89 ;
71+ private static final int DATABASE_VERSION = 90 ;
7272
7373 private Context mContext ;
7474 private int mUserHandle ;
@@ -1380,6 +1380,26 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
13801380 upgradeVersion = 89 ;
13811381 }
13821382
1383+ if (upgradeVersion == 89 ) {
1384+ if (mUserHandle == UserHandle .USER_OWNER ) {
1385+ db .beginTransaction ();
1386+ try {
1387+ String [] prefixesToMove = {
1388+ Settings .Global .BLUETOOTH_HEADSET_PRIORITY_PREFIX ,
1389+ Settings .Global .BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX ,
1390+ Settings .Global .BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX ,
1391+ };
1392+
1393+ movePrefixedSettingsToNewTable (db , TABLE_SECURE , TABLE_GLOBAL , prefixesToMove );
1394+
1395+ db .setTransactionSuccessful ();
1396+ } finally {
1397+ db .endTransaction ();
1398+ }
1399+ }
1400+ upgradeVersion = 90 ;
1401+ }
1402+
13831403 // *** Remember to update DATABASE_VERSION above!
13841404
13851405 if (upgradeVersion != currentVersion ) {
@@ -1446,6 +1466,44 @@ private void moveSettingsToNewTable(SQLiteDatabase db,
14461466 }
14471467 }
14481468
1469+ /**
1470+ * Move any settings with the given prefixes from the source table to the
1471+ * destination table.
1472+ */
1473+ private void movePrefixedSettingsToNewTable (
1474+ SQLiteDatabase db , String sourceTable , String destTable , String [] prefixesToMove ) {
1475+ SQLiteStatement insertStmt = null ;
1476+ SQLiteStatement deleteStmt = null ;
1477+
1478+ db .beginTransaction ();
1479+ try {
1480+ insertStmt = db .compileStatement ("INSERT INTO " + destTable
1481+ + " (name,value) SELECT name,value FROM " + sourceTable
1482+ + " WHERE substr(name,0,?)=?" );
1483+ deleteStmt = db .compileStatement (
1484+ "DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?" );
1485+
1486+ for (String prefix : prefixesToMove ) {
1487+ insertStmt .bindLong (1 , prefix .length () + 1 );
1488+ insertStmt .bindString (2 , prefix );
1489+ insertStmt .execute ();
1490+
1491+ deleteStmt .bindLong (1 , prefix .length () + 1 );
1492+ deleteStmt .bindString (2 , prefix );
1493+ deleteStmt .execute ();
1494+ }
1495+ db .setTransactionSuccessful ();
1496+ } finally {
1497+ db .endTransaction ();
1498+ if (insertStmt != null ) {
1499+ insertStmt .close ();
1500+ }
1501+ if (deleteStmt != null ) {
1502+ deleteStmt .close ();
1503+ }
1504+ }
1505+ }
1506+
14491507 private void upgradeLockPatternLocation (SQLiteDatabase db ) {
14501508 Cursor c = db .query (TABLE_SYSTEM , new String [] {"_id" , "value" }, "name='lock_pattern'" ,
14511509 null , null , null , null );
0 commit comments