Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf56433c authored by Alice Kuo's avatar Alice Kuo Committed by Automerger Merge Worker
Browse files

Merge "Add volume control profile metadata storage support" am: c5312141

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1811407

Change-Id: I693596d0f2de1fbf06af294c39ffed13a8aab8f1
parents 66e1eeda c5312141
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -294,7 +294,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},
@@ -350,7 +351,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},
+5 −0
Original line number Diff line number Diff line
@@ -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);
        }
@@ -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;
    }
+21 −1
Original line number Diff line number Diff line
@@ -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
@@ -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();
    }
@@ -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;
                }
            }
        }
    };
}
+4 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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() {
@@ -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();
    }
+28 −0
Original line number Diff line number Diff line
@@ -1031,6 +1031,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