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

Commit 67c96a88 authored by David Duarte's avatar David Duarte Committed by Android (Google) Code Review
Browse files

Merge changes from topics "presubmit-am-1753742950de4d659d314f18c7ed4216",...

Merge changes from topics "presubmit-am-1753742950de4d659d314f18c7ed4216", "presubmit-am-db3e3b084ac942c8a8f08c01d6ac259c" into tm-mainline-prod

* changes:
  Add missing migration 115_116 to database builder
  Add APIs to set and get the preferred audio mode
parents 0466e11a d5efb612
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -61,6 +61,22 @@ public class Metadata {
    @Embedded
    public AudioPolicyEntity audioPolicyMetadata;

    /**
     * The preferred profile to be used for {@link BluetoothDevice#AUDIO_MODE_OUTPUT_ONLY}. This can
     * be either {@link BluetoothProfile#A2DP} or {@link BluetoothProfile#LE_AUDIO}. This value is
     * only used if the remote device supports both A2DP and LE Audio and both transports are
     * connected and active.
     */
    public int preferred_output_only_profile;

    /**
     * The preferred profile to be used for {@link BluetoothDevice#AUDIO_MODE_DUPLEX}. This can
     * be either {@link BluetoothProfile#HEADSET} or {@link BluetoothProfile#LE_AUDIO}. This value
     * is only used if the remote device supports both HFP and LE Audio and both transports are
     * connected and active.
     */
    public int preferred_duplex_profile;

    Metadata(String address) {
        this.address = address;
        migrated = false;
@@ -71,6 +87,8 @@ public class Metadata {
        last_active_time = MetadataDatabase.sCurrentConnectionNumber++;
        is_active_a2dp_device = true;
        audioPolicyMetadata = new AudioPolicyEntity();
        preferred_output_only_profile = 0;
        preferred_duplex_profile = 0;
    }

    /**
+23 −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 = 115)
@Database(entities = {Metadata.class}, version = 116)
public abstract class MetadataDatabase extends RoomDatabase {
    /**
     * The metadata database file name
@@ -68,6 +68,7 @@ public abstract class MetadataDatabase extends RoomDatabase {
                .addMigrations(MIGRATION_112_113)
                .addMigrations(MIGRATION_113_114)
                .addMigrations(MIGRATION_114_115)
                .addMigrations(MIGRATION_115_116)
                .allowMainThreadQueries()
                .build();
    }
@@ -526,4 +527,25 @@ public abstract class MetadataDatabase extends RoomDatabase {
            }
        }
    };

    @VisibleForTesting
    static final Migration MIGRATION_115_116 = new Migration(115, 116) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            try {
                database.execSQL("ALTER TABLE metadata ADD COLUMN `preferred_output_only_profile` "
                        + "INTEGER NOT NULL DEFAULT 0");
                database.execSQL("ALTER TABLE metadata ADD COLUMN `preferred_duplex_profile` "
                        + "INTEGER NOT NULL DEFAULT 0");
            } 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("preferred_output_only_profile") == -1
                        || cursor.getColumnIndex("preferred_duplex_profile") == -1) {
                    throw ex;
                }
            }
        }
    };
}
+31 −4
Original line number Diff line number Diff line
@@ -1158,7 +1158,7 @@ public final class DatabaseManagerTest {
    @Test
    public void testDatabaseMigration_111_112() throws IOException {
        String testString = "TEST STRING";
        // Create a database with version 109
        // Create a database with version 111
        SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 111);
        // insert a device to the database
        ContentValues device = new ContentValues();
@@ -1204,7 +1204,7 @@ public final class DatabaseManagerTest {

    @Test
    public void testDatabaseMigration_113_114() throws IOException {
        // Create a database with version 112
        // Create a database with version 113
        SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 113);
        // insert a device to the database
        ContentValues device = new ContentValues();
@@ -1226,7 +1226,7 @@ public final class DatabaseManagerTest {

    @Test
    public void testDatabaseMigration_114_115() throws IOException {
        // Create a database with version 112
        // Create a database with version 114
        SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 114);
        // insert a device to the database
        ContentValues device = new ContentValues();
@@ -1234,11 +1234,13 @@ public final class DatabaseManagerTest {
        device.put("migrated", false);
        assertThat(db.insert("metadata", SQLiteDatabase.CONFLICT_IGNORE, device),
                CoreMatchers.not(-1));
        // Migrate database from 112 to 113

        // Migrate database from 114 to 115
        db.close();
        db = testHelper.runMigrationsAndValidate(DB_NAME, 115, true,
                MetadataDatabase.MIGRATION_114_115);
        Cursor cursor = db.query("SELECT * FROM metadata");

        assertHasColumn(cursor, "call_establish_audio_policy", true);
        assertHasColumn(cursor, "connecting_time_audio_policy", true);
        assertHasColumn(cursor, "in_band_ringtone_audio_policy", true);
@@ -1250,6 +1252,31 @@ public final class DatabaseManagerTest {
        }
    }

    @Test
    public void testDatabaseMigration_115_116() throws IOException {
        // Create a database with version 115
        SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 115);
        // 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 115 to 116
        db.close();
        db = testHelper.runMigrationsAndValidate(DB_NAME, 116, true,
                MetadataDatabase.MIGRATION_115_116);
        Cursor cursor = db.query("SELECT * FROM metadata");
        assertHasColumn(cursor, "preferred_output_only_profile", true);
        assertHasColumn(cursor, "preferred_duplex_profile", true);
        while (cursor.moveToNext()) {
            // Check the new columns was added with default value
            assertColumnIntData(cursor, "preferred_output_only_profile", 0);
            assertColumnIntData(cursor, "preferred_duplex_profile", 0);
        }
    }

    /**
     * Helper function to check whether the database has the expected column
     */
+370 −0
Original line number Diff line number Diff line
{
  "formatVersion": 1,
  "database": {
    "version": 116,
    "identityHash": "0b8549de3acad8b14fe6f7198206ea02",
    "entities": [
      {
        "tableName": "metadata",
        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`address` TEXT NOT NULL, `migrated` INTEGER NOT NULL, `a2dpSupportsOptionalCodecs` INTEGER NOT NULL, `a2dpOptionalCodecsEnabled` INTEGER NOT NULL, `last_active_time` INTEGER NOT NULL, `is_active_a2dp_device` INTEGER NOT NULL, `preferred_output_only_profile` INTEGER NOT NULL, `preferred_duplex_profile` INTEGER NOT NULL, `a2dp_connection_policy` INTEGER, `a2dp_sink_connection_policy` INTEGER, `hfp_connection_policy` INTEGER, `hfp_client_connection_policy` INTEGER, `hid_host_connection_policy` INTEGER, `pan_connection_policy` INTEGER, `pbap_connection_policy` INTEGER, `pbap_client_connection_policy` INTEGER, `map_connection_policy` INTEGER, `sap_connection_policy` INTEGER, `hearing_aid_connection_policy` INTEGER, `hap_client_connection_policy` INTEGER, `map_client_connection_policy` INTEGER, `le_audio_connection_policy` INTEGER, `volume_control_connection_policy` INTEGER, `csip_set_coordinator_connection_policy` INTEGER, `le_call_control_connection_policy` INTEGER, `bass_client_connection_policy` INTEGER, `battery_connection_policy` INTEGER, `manufacturer_name` BLOB, `model_name` BLOB, `software_version` BLOB, `hardware_version` BLOB, `companion_app` BLOB, `main_icon` BLOB, `is_untethered_headset` BLOB, `untethered_left_icon` BLOB, `untethered_right_icon` BLOB, `untethered_case_icon` BLOB, `untethered_left_battery` BLOB, `untethered_right_battery` BLOB, `untethered_case_battery` BLOB, `untethered_left_charging` BLOB, `untethered_right_charging` BLOB, `untethered_case_charging` BLOB, `enhanced_settings_ui_uri` BLOB, `device_type` BLOB, `main_battery` BLOB, `main_charging` BLOB, `main_low_battery_threshold` BLOB, `untethered_left_low_battery_threshold` BLOB, `untethered_right_low_battery_threshold` BLOB, `untethered_case_low_battery_threshold` BLOB, `spatial_audio` BLOB, `fastpair_customized` BLOB, `le_audio` BLOB, `call_establish_audio_policy` INTEGER, `connecting_time_audio_policy` INTEGER, `in_band_ringtone_audio_policy` INTEGER, PRIMARY KEY(`address`))",
        "fields": [
          {
            "fieldPath": "address",
            "columnName": "address",
            "affinity": "TEXT",
            "notNull": true
          },
          {
            "fieldPath": "migrated",
            "columnName": "migrated",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "a2dpSupportsOptionalCodecs",
            "columnName": "a2dpSupportsOptionalCodecs",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "a2dpOptionalCodecsEnabled",
            "columnName": "a2dpOptionalCodecsEnabled",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "last_active_time",
            "columnName": "last_active_time",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "is_active_a2dp_device",
            "columnName": "is_active_a2dp_device",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "preferred_output_only_profile",
            "columnName": "preferred_output_only_profile",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "preferred_duplex_profile",
            "columnName": "preferred_duplex_profile",
            "affinity": "INTEGER",
            "notNull": true
          },
          {
            "fieldPath": "profileConnectionPolicies.a2dp_connection_policy",
            "columnName": "a2dp_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.a2dp_sink_connection_policy",
            "columnName": "a2dp_sink_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.hfp_connection_policy",
            "columnName": "hfp_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.hfp_client_connection_policy",
            "columnName": "hfp_client_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.hid_host_connection_policy",
            "columnName": "hid_host_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.pan_connection_policy",
            "columnName": "pan_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.pbap_connection_policy",
            "columnName": "pbap_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.pbap_client_connection_policy",
            "columnName": "pbap_client_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.map_connection_policy",
            "columnName": "map_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.sap_connection_policy",
            "columnName": "sap_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.hearing_aid_connection_policy",
            "columnName": "hearing_aid_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.hap_client_connection_policy",
            "columnName": "hap_client_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.map_client_connection_policy",
            "columnName": "map_client_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.le_audio_connection_policy",
            "columnName": "le_audio_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.volume_control_connection_policy",
            "columnName": "volume_control_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.csip_set_coordinator_connection_policy",
            "columnName": "csip_set_coordinator_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.le_call_control_connection_policy",
            "columnName": "le_call_control_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.bass_client_connection_policy",
            "columnName": "bass_client_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "profileConnectionPolicies.battery_connection_policy",
            "columnName": "battery_connection_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.manufacturer_name",
            "columnName": "manufacturer_name",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.model_name",
            "columnName": "model_name",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.software_version",
            "columnName": "software_version",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.hardware_version",
            "columnName": "hardware_version",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.companion_app",
            "columnName": "companion_app",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.main_icon",
            "columnName": "main_icon",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.is_untethered_headset",
            "columnName": "is_untethered_headset",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_left_icon",
            "columnName": "untethered_left_icon",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_right_icon",
            "columnName": "untethered_right_icon",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_case_icon",
            "columnName": "untethered_case_icon",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_left_battery",
            "columnName": "untethered_left_battery",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_right_battery",
            "columnName": "untethered_right_battery",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_case_battery",
            "columnName": "untethered_case_battery",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_left_charging",
            "columnName": "untethered_left_charging",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_right_charging",
            "columnName": "untethered_right_charging",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_case_charging",
            "columnName": "untethered_case_charging",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.enhanced_settings_ui_uri",
            "columnName": "enhanced_settings_ui_uri",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.device_type",
            "columnName": "device_type",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.main_battery",
            "columnName": "main_battery",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.main_charging",
            "columnName": "main_charging",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.main_low_battery_threshold",
            "columnName": "main_low_battery_threshold",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_left_low_battery_threshold",
            "columnName": "untethered_left_low_battery_threshold",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_right_low_battery_threshold",
            "columnName": "untethered_right_low_battery_threshold",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.untethered_case_low_battery_threshold",
            "columnName": "untethered_case_low_battery_threshold",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.spatial_audio",
            "columnName": "spatial_audio",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.fastpair_customized",
            "columnName": "fastpair_customized",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "publicMetadata.le_audio",
            "columnName": "le_audio",
            "affinity": "BLOB",
            "notNull": false
          },
          {
            "fieldPath": "audioPolicyMetadata.callEstablishAudioPolicy",
            "columnName": "call_establish_audio_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "audioPolicyMetadata.connectingTimeAudioPolicy",
            "columnName": "connecting_time_audio_policy",
            "affinity": "INTEGER",
            "notNull": false
          },
          {
            "fieldPath": "audioPolicyMetadata.inBandRingtoneAudioPolicy",
            "columnName": "in_band_ringtone_audio_policy",
            "affinity": "INTEGER",
            "notNull": false
          }
        ],
        "primaryKey": {
          "autoGenerate": false,
          "columnNames": [
            "address"
          ]
        },
        "indices": [],
        "foreignKeys": []
      }
    ],
    "views": [],
    "setupQueries": [
      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0b8549de3acad8b14fe6f7198206ea02')"
    ]
  }
}
 No newline at end of file