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

Commit ecb163aa authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Create metadata after the device is bonded

DatabaseManager creates a metadata entry for the devices when bonding. If the BT is restarted when bonding is going on, the BOND_NONE event is not generated and the residual metadata entry is not removed.

Change-Id: I96ac1e9b464ecc02aeef60f69d3a3a32fe643cc9
Test: atest CtsBluetoothTestCases:android.bluetooth.cts.BluetoothDeviceTest
Flag: com.android.bluetooth.flags.create_metadata_after_bonding
Bug: 387523986
Bug: 387523991
parent b266b856
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -201,6 +201,7 @@ public class DatabaseManager {
    void bondStateChanged(BluetoothDevice device, int state) {
        synchronized (mMetadataCache) {
            String address = device.getAddress();
            if (!Flags.createMetadataAfterBonding()) {
                if (state != BluetoothDevice.BOND_NONE) {
                    if (mMetadataCache.containsKey(address)) {
                        return;
@@ -213,6 +214,21 @@ public class DatabaseManager {
                        deleteDatabase(metadata);
                    }
                }
                return;
            }

            if (state == BluetoothDevice.BOND_BONDED) {
                if (mMetadataCache.containsKey(address)) {
                    return;
                }
                createMetadata(address, false);
            } else if (state == BluetoothDevice.BOND_NONE) {
                Metadata metadata = mMetadataCache.get(address);
                if (metadata != null) {
                    mMetadataCache.remove(address);
                    deleteDatabase(metadata);
                }
            }
        }
    }