Skip to content

Commit 0ac1028

Browse files
committed
Move bluetooth priorities from Secure to Global.
Bug: 7231171 Change-Id: I836fdc2cfb8d67f984b4715559b9e92d0dc41c95
1 parent 32ee831 commit 0ac1028

File tree

2 files changed

+93
-25
lines changed

2 files changed

+93
-25
lines changed

core/java/android/provider/Settings.java

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3077,30 +3077,6 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val
30773077
@Deprecated
30783078
public static final String BLUETOOTH_ON = Global.BLUETOOTH_ON;
30793079

3080-
/**
3081-
* Get the key that retrieves a bluetooth headset's priority.
3082-
* @hide
3083-
*/
3084-
public static final String getBluetoothHeadsetPriorityKey(String address) {
3085-
return ("bluetooth_headset_priority_" + address.toUpperCase());
3086-
}
3087-
3088-
/**
3089-
* Get the key that retrieves a bluetooth a2dp sink's priority.
3090-
* @hide
3091-
*/
3092-
public static final String getBluetoothA2dpSinkPriorityKey(String address) {
3093-
return ("bluetooth_a2dp_sink_priority_" + address.toUpperCase());
3094-
}
3095-
3096-
/**
3097-
* Get the key that retrieves a bluetooth Input Device's priority.
3098-
* @hide
3099-
*/
3100-
public static final String getBluetoothInputDevicePriorityKey(String address) {
3101-
return ("bluetooth_input_device_priority_" + address.toUpperCase());
3102-
}
3103-
31043080
/**
31053081
* @deprecated Use {@link android.provider.Settings.Global#DATA_ROAMING} instead
31063082
*/
@@ -5160,6 +5136,40 @@ public static final class Global extends NameValueTable {
51605136
*/
51615137
public static final String DEFAULT_DNS_SERVER = "default_dns_server";
51625138

5139+
/** {@hide} */
5140+
public static final String
5141+
BLUETOOTH_HEADSET_PRIORITY_PREFIX = "bluetooth_headset_priority_";
5142+
/** {@hide} */
5143+
public static final String
5144+
BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX = "bluetooth_a2dp_sink_priority_";
5145+
/** {@hide} */
5146+
public static final String
5147+
BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX = "bluetooth_input_device_priority_";
5148+
5149+
/**
5150+
* Get the key that retrieves a bluetooth headset's priority.
5151+
* @hide
5152+
*/
5153+
public static final String getBluetoothHeadsetPriorityKey(String address) {
5154+
return BLUETOOTH_HEADSET_PRIORITY_PREFIX + address.toUpperCase();
5155+
}
5156+
5157+
/**
5158+
* Get the key that retrieves a bluetooth a2dp sink's priority.
5159+
* @hide
5160+
*/
5161+
public static final String getBluetoothA2dpSinkPriorityKey(String address) {
5162+
return BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX + address.toUpperCase();
5163+
}
5164+
5165+
/**
5166+
* Get the key that retrieves a bluetooth Input Device's priority.
5167+
* @hide
5168+
*/
5169+
public static final String getBluetoothInputDevicePriorityKey(String address) {
5170+
return BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX + address.toUpperCase();
5171+
}
5172+
51635173
// Populated lazily, guarded by class object:
51645174
private static NameValueCache sNameValueCache = new NameValueCache(
51655175
SYS_PROP_SETTING_VERSION,

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)