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

Commit 7d39416c authored by Jakub Pawłowski's avatar Jakub Pawłowski Committed by Android (Google) Code Review
Browse files

Merge "BluetoothDevice: add METADATA_LE_AUDIO" into tm-qpr-dev

parents c62e5252 9bc6cf09
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ class CustomizedMetadataEntity {
    public byte[] untethered_case_low_battery_threshold;
    public byte[] spatial_audio;
    public byte[] fastpair_customized;
    public byte[] le_audio;

    public String toString() {
        StringBuilder builder = new StringBuilder();
@@ -100,7 +101,10 @@ class CustomizedMetadataEntity {
                .append("|spatial_audio=")
                .append(metadataToString(spatial_audio))
                .append("|fastpair_customized=")
                .append(metadataToString(fastpair_customized));
                .append(metadataToString(fastpair_customized))
                .append("|le_audio=")
                .append(metadataToString(le_audio));


        return builder.toString();
    }
+6 −0
Original line number Diff line number Diff line
@@ -287,6 +287,9 @@ public class Metadata {
            case BluetoothDevice.METADATA_FAST_PAIR_CUSTOMIZED_FIELDS:
                publicMetadata.fastpair_customized = value;
                break;
            case BluetoothDevice.METADATA_LE_AUDIO:
                publicMetadata.le_audio = value;
                break;
        }
    }

@@ -375,6 +378,9 @@ public class Metadata {
            case BluetoothDevice.METADATA_FAST_PAIR_CUSTOMIZED_FIELDS:
                value = publicMetadata.fastpair_customized;
                break;
            case BluetoothDevice.METADATA_LE_AUDIO:
                value = publicMetadata.le_audio;
                break;
        }
        return value;
    }
+18 −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 = 113)
@Database(entities = {Metadata.class}, version = 114)
public abstract class MetadataDatabase extends RoomDatabase {
    /**
     * The metadata database file name
@@ -66,6 +66,7 @@ public abstract class MetadataDatabase extends RoomDatabase {
                .addMigrations(MIGRATION_110_111)
                .addMigrations(MIGRATION_111_112)
                .addMigrations(MIGRATION_112_113)
                .addMigrations(MIGRATION_113_114)
                .allowMainThreadQueries()
                .build();
    }
@@ -483,4 +484,20 @@ public abstract class MetadataDatabase extends RoomDatabase {
            }
        }
    };

    @VisibleForTesting
    static final Migration MIGRATION_113_114 = new Migration(113, 114) {
        @Override
        public void migrate(SupportSQLiteDatabase database) {
            try {
                database.execSQL("ALTER TABLE metadata ADD COLUMN `le_audio` BLOB");
            } 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("le_audio") == -1) {
                    throw ex;
                }
            }
        }
    };
}
+26 −0
Original line number Diff line number Diff line
@@ -385,6 +385,8 @@ public final class DatabaseManagerTest {
                value, true);
        testSetGetCustomMetaCase(false, BluetoothDevice.METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                value, true);
        testSetGetCustomMetaCase(false, BluetoothDevice.METADATA_LE_AUDIO,
                value, true);
        testSetGetCustomMetaCase(false, badKey, value, false);

        // Device is in database
@@ -443,6 +445,8 @@ public final class DatabaseManagerTest {
                value, true);
        testSetGetCustomMetaCase(true, BluetoothDevice.METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                value, true);
        testSetGetCustomMetaCase(true, BluetoothDevice.METADATA_LE_AUDIO,
                value, true);
    }

    @Test
@@ -1183,6 +1187,28 @@ public final class DatabaseManagerTest {
        }
    }

    @Test
    public void testDatabaseMigration_113_114() throws IOException {
        // Create a database with version 112
        SupportSQLiteDatabase db = testHelper.createDatabase(DB_NAME, 113);
        // 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 113 to 114
        db.close();
        db = testHelper.runMigrationsAndValidate(DB_NAME, 114, true,
                MetadataDatabase.MIGRATION_113_114);
        Cursor cursor = db.query("SELECT * FROM metadata");
        assertHasColumn(cursor, "le_audio", true);
        while (cursor.moveToNext()) {
            // Check the new columns was added with default value
            assertColumnBlobData(cursor, "le_audio", null);
        }
    }

    /**
     * Helper function to check whether the database has the expected column
     */
+340 −0
Original line number Diff line number Diff line
{
  "formatVersion": 1,
  "database": {
    "version": 114,
    "identityHash": "ba0a06f58eaae06198b90b4f6e5eb553",
    "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, `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, 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": "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
          }
        ],
        "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, 'ba0a06f58eaae06198b90b4f6e5eb553')"
    ]
  }
}
 No newline at end of file
Loading