Loading android/app/src/com/android/bluetooth/btservice/storage/DatabaseManager.java +4 −2 Original line number Diff line number Diff line Loading @@ -293,7 +293,8 @@ public class DatabaseManager { * {@link BluetoothProfile#PAN}, {@link BluetoothProfile#PBAP}, * {@link BluetoothProfile#PBAP_CLIENT}, {@link BluetoothProfile#MAP}, * {@link BluetoothProfile#MAP_CLIENT}, {@link BluetoothProfile#SAP}, * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO} * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO}, * {@link BluetoothProfile#VOLUME_CONTROL} * @param newConnectionPolicy the connectionPolicy to set; one of * {@link BluetoothProfile.CONNECTION_POLICY_UNKNOWN}, * {@link BluetoothProfile.CONNECTION_POLICY_FORBIDDEN}, Loading Loading @@ -349,7 +350,8 @@ public class DatabaseManager { * {@link BluetoothProfile#PAN}, {@link BluetoothProfile#PBAP}, * {@link BluetoothProfile#PBAP_CLIENT}, {@link BluetoothProfile#MAP}, * {@link BluetoothProfile#MAP_CLIENT}, {@link BluetoothProfile#SAP}, * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO} * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO}, * {@link BluetoothProfile#VOLUME_CONTROL} * @return the profile connection policy of the device; one of * {@link BluetoothProfile.CONNECTION_POLICY_UNKNOWN}, * {@link BluetoothProfile.CONNECTION_POLICY_FORBIDDEN}, Loading android/app/src/com/android/bluetooth/btservice/storage/Metadata.java +5 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,9 @@ class Metadata { case BluetoothProfile.LE_AUDIO: profileConnectionPolicies.le_audio_connection_policy = connectionPolicy; break; case BluetoothProfile.VOLUME_CONTROL: profileConnectionPolicies.volume_control_connection_policy = connectionPolicy; break; default: throw new IllegalArgumentException("invalid profile " + profile); } Loading Loading @@ -146,6 +149,8 @@ class Metadata { return profileConnectionPolicies.hearing_aid_connection_policy; case BluetoothProfile.LE_AUDIO: return profileConnectionPolicies.le_audio_connection_policy; case BluetoothProfile.VOLUME_CONTROL: return profileConnectionPolicies.volume_control_connection_policy; } return BluetoothProfile.CONNECTION_POLICY_UNKNOWN; } Loading android/app/src/com/android/bluetooth/btservice/storage/MetadataDatabase.java +21 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import java.util.List; /** * MetadataDatabase is a Room database stores Bluetooth persistence data */ @Database(entities = {Metadata.class}, version = 106) @Database(entities = {Metadata.class}, version = 107) public abstract class MetadataDatabase extends RoomDatabase { /** * The metadata database file name Loading @@ -59,6 +59,7 @@ public abstract class MetadataDatabase extends RoomDatabase { .addMigrations(MIGRATION_103_104) .addMigrations(MIGRATION_104_105) .addMigrations(MIGRATION_105_106) .addMigrations(MIGRATION_106_107) .allowMainThreadQueries() .build(); } Loading Loading @@ -348,4 +349,23 @@ public abstract class MetadataDatabase extends RoomDatabase { } } }; @VisibleForTesting static final Migration MIGRATION_106_107 = new Migration(106, 107) { @Override public void migrate(SupportSQLiteDatabase database) { try { database.execSQL("ALTER TABLE metadata ADD COLUMN " + "`volume_control_connection_policy` INTEGER DEFAULT 100"); } catch (SQLException ex) { // Check if user has new schema, but is just missing the version update Cursor cursor = database.query("SELECT * FROM metadata"); if (cursor == null || cursor.getColumnIndex("volume_control_connection_policy") == -1) { throw ex; } } } }; } android/app/src/com/android/bluetooth/btservice/storage/ProfilePrioritiesEntity.java +4 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ class ProfilePrioritiesEntity { public int hearing_aid_connection_policy; public int map_client_connection_policy; public int le_audio_connection_policy; public int volume_control_connection_policy; ProfilePrioritiesEntity() { a2dp_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; Loading @@ -51,6 +52,7 @@ class ProfilePrioritiesEntity { hearing_aid_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; map_client_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; le_audio_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; volume_control_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; } public String toString() { Loading @@ -67,7 +69,8 @@ class ProfilePrioritiesEntity { .append("|MAP_CLIENT=").append(map_client_connection_policy) .append("|SAP=").append(sap_connection_policy) .append("|HEARING_AID=").append(hearing_aid_connection_policy) .append("|LE_AUDIO=").append(le_audio_connection_policy); .append("|LE_AUDIO=").append(le_audio_connection_policy) .append("|VOLUME_CONTROL=").append(volume_control_connection_policy); return builder.toString(); } Loading android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -1022,6 +1022,34 @@ public final class DatabaseManagerTest { } } @Test public void testDatabaseMigration_106_107() throws IOException { String testString = "TEST STRING"; // Create a database with version 106 SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 106); // insert a device to the database ContentValues device = new ContentValues(); device.put("address", TEST_BT_ADDR); device.put("migrated", false); assertThat(db.insert("metadata", SQLiteDatabase.CONFLICT_IGNORE, device), CoreMatchers.not(-1)); // Migrate database from 106 to 107 db.close(); db = testHelper.runMigrationsAndValidate(DB_NAME, 107, true, MetadataDatabase.MIGRATION_106_107); Cursor cursor = db.query("SELECT * FROM metadata"); assertHasColumn(cursor, "volume_control_connection_policy", true); while (cursor.moveToNext()) { // Check the new columns was added with default value assertColumnIntData(cursor, "volume_control_connection_policy", 100); } } /** * Helper function to check whether the database has the expected column */ Loading Loading
android/app/src/com/android/bluetooth/btservice/storage/DatabaseManager.java +4 −2 Original line number Diff line number Diff line Loading @@ -293,7 +293,8 @@ public class DatabaseManager { * {@link BluetoothProfile#PAN}, {@link BluetoothProfile#PBAP}, * {@link BluetoothProfile#PBAP_CLIENT}, {@link BluetoothProfile#MAP}, * {@link BluetoothProfile#MAP_CLIENT}, {@link BluetoothProfile#SAP}, * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO} * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO}, * {@link BluetoothProfile#VOLUME_CONTROL} * @param newConnectionPolicy the connectionPolicy to set; one of * {@link BluetoothProfile.CONNECTION_POLICY_UNKNOWN}, * {@link BluetoothProfile.CONNECTION_POLICY_FORBIDDEN}, Loading Loading @@ -349,7 +350,8 @@ public class DatabaseManager { * {@link BluetoothProfile#PAN}, {@link BluetoothProfile#PBAP}, * {@link BluetoothProfile#PBAP_CLIENT}, {@link BluetoothProfile#MAP}, * {@link BluetoothProfile#MAP_CLIENT}, {@link BluetoothProfile#SAP}, * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO} * {@link BluetoothProfile#HEARING_AID}, {@link BluetoothProfile#LE_AUDIO}, * {@link BluetoothProfile#VOLUME_CONTROL} * @return the profile connection policy of the device; one of * {@link BluetoothProfile.CONNECTION_POLICY_UNKNOWN}, * {@link BluetoothProfile.CONNECTION_POLICY_FORBIDDEN}, Loading
android/app/src/com/android/bluetooth/btservice/storage/Metadata.java +5 −0 Original line number Diff line number Diff line Loading @@ -113,6 +113,9 @@ class Metadata { case BluetoothProfile.LE_AUDIO: profileConnectionPolicies.le_audio_connection_policy = connectionPolicy; break; case BluetoothProfile.VOLUME_CONTROL: profileConnectionPolicies.volume_control_connection_policy = connectionPolicy; break; default: throw new IllegalArgumentException("invalid profile " + profile); } Loading Loading @@ -146,6 +149,8 @@ class Metadata { return profileConnectionPolicies.hearing_aid_connection_policy; case BluetoothProfile.LE_AUDIO: return profileConnectionPolicies.le_audio_connection_policy; case BluetoothProfile.VOLUME_CONTROL: return profileConnectionPolicies.volume_control_connection_policy; } return BluetoothProfile.CONNECTION_POLICY_UNKNOWN; } Loading
android/app/src/com/android/bluetooth/btservice/storage/MetadataDatabase.java +21 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import java.util.List; /** * MetadataDatabase is a Room database stores Bluetooth persistence data */ @Database(entities = {Metadata.class}, version = 106) @Database(entities = {Metadata.class}, version = 107) public abstract class MetadataDatabase extends RoomDatabase { /** * The metadata database file name Loading @@ -59,6 +59,7 @@ public abstract class MetadataDatabase extends RoomDatabase { .addMigrations(MIGRATION_103_104) .addMigrations(MIGRATION_104_105) .addMigrations(MIGRATION_105_106) .addMigrations(MIGRATION_106_107) .allowMainThreadQueries() .build(); } Loading Loading @@ -348,4 +349,23 @@ public abstract class MetadataDatabase extends RoomDatabase { } } }; @VisibleForTesting static final Migration MIGRATION_106_107 = new Migration(106, 107) { @Override public void migrate(SupportSQLiteDatabase database) { try { database.execSQL("ALTER TABLE metadata ADD COLUMN " + "`volume_control_connection_policy` INTEGER DEFAULT 100"); } catch (SQLException ex) { // Check if user has new schema, but is just missing the version update Cursor cursor = database.query("SELECT * FROM metadata"); if (cursor == null || cursor.getColumnIndex("volume_control_connection_policy") == -1) { throw ex; } } } }; }
android/app/src/com/android/bluetooth/btservice/storage/ProfilePrioritiesEntity.java +4 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ class ProfilePrioritiesEntity { public int hearing_aid_connection_policy; public int map_client_connection_policy; public int le_audio_connection_policy; public int volume_control_connection_policy; ProfilePrioritiesEntity() { a2dp_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; Loading @@ -51,6 +52,7 @@ class ProfilePrioritiesEntity { hearing_aid_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; map_client_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; le_audio_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; volume_control_connection_policy = BluetoothProfile.CONNECTION_POLICY_UNKNOWN; } public String toString() { Loading @@ -67,7 +69,8 @@ class ProfilePrioritiesEntity { .append("|MAP_CLIENT=").append(map_client_connection_policy) .append("|SAP=").append(sap_connection_policy) .append("|HEARING_AID=").append(hearing_aid_connection_policy) .append("|LE_AUDIO=").append(le_audio_connection_policy); .append("|LE_AUDIO=").append(le_audio_connection_policy) .append("|VOLUME_CONTROL=").append(volume_control_connection_policy); return builder.toString(); } Loading
android/app/tests/unit/src/com/android/bluetooth/btservice/storage/DatabaseManagerTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -1022,6 +1022,34 @@ public final class DatabaseManagerTest { } } @Test public void testDatabaseMigration_106_107() throws IOException { String testString = "TEST STRING"; // Create a database with version 106 SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 106); // insert a device to the database ContentValues device = new ContentValues(); device.put("address", TEST_BT_ADDR); device.put("migrated", false); assertThat(db.insert("metadata", SQLiteDatabase.CONFLICT_IGNORE, device), CoreMatchers.not(-1)); // Migrate database from 106 to 107 db.close(); db = testHelper.runMigrationsAndValidate(DB_NAME, 107, true, MetadataDatabase.MIGRATION_106_107); Cursor cursor = db.query("SELECT * FROM metadata"); assertHasColumn(cursor, "volume_control_connection_policy", true); while (cursor.moveToNext()) { // Check the new columns was added with default value assertColumnIntData(cursor, "volume_control_connection_policy", 100); } } /** * Helper function to check whether the database has the expected column */ Loading