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

Commit 448c2830 authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Fixes a bug in the BluetoothDevice#getIdentityAddress API where it

returns the mAddress field of the device instead of null when the
identity address is not known.

Tag: #feature
Bug: 238353063
Test: atest AdapterServiceTest#testAddressConsolidate
Ignore-AOSP-First: Change needs to land in TM release
Change-Id: I577843c9e2cc279915d0632ff25bde66aa949e94
parent 97908968
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -3881,7 +3881,7 @@ public class AdapterService extends Service {
        if (deviceProp != null && deviceProp.isConsolidated()) {
        if (deviceProp != null && deviceProp.isConsolidated()) {
            return deviceProp.getIdentityAddress();
            return deviceProp.getIdentityAddress();
        } else {
        } else {
            return address;
            return null;
        }
        }
    }
    }


+8 −5
Original line number Original line Diff line number Diff line
@@ -853,19 +853,22 @@ public class AdapterServiceTest {


    @Test
    @Test
    public void testAddressConsolidation() {
    public void testAddressConsolidation() {
        // Create device properties
        // Verify that we return null when the device property for this address does not exist
        Assert.assertNull(mAdapterService.getIdentityAddress(TEST_BT_ADDR_1));

        // Create device property
        RemoteDevices remoteDevices = mAdapterService.getRemoteDevices();
        RemoteDevices remoteDevices = mAdapterService.getRemoteDevices();
        remoteDevices.addDeviceProperties(Utils.getBytesFromAddress((TEST_BT_ADDR_1)));
        remoteDevices.addDeviceProperties(Utils.getBytesFromAddress((TEST_BT_ADDR_1)));
        String identityAddress = mAdapterService.getIdentityAddress(TEST_BT_ADDR_1);

        Assert.assertEquals(identityAddress, TEST_BT_ADDR_1);
        // Verify that we return null when the identity address is not known
        Assert.assertNull(mAdapterService.getIdentityAddress(TEST_BT_ADDR_1));


        // Trigger address consolidate callback
        // Trigger address consolidate callback
        remoteDevices.addressConsolidateCallback(Utils.getBytesFromAddress(TEST_BT_ADDR_1),
        remoteDevices.addressConsolidateCallback(Utils.getBytesFromAddress(TEST_BT_ADDR_1),
                Utils.getBytesFromAddress(TEST_BT_ADDR_2));
                Utils.getBytesFromAddress(TEST_BT_ADDR_2));


        // Verify we can get correct identity address
        // Verify we can get correct identity address
        identityAddress = mAdapterService.getIdentityAddress(TEST_BT_ADDR_1);
        Assert.assertEquals(TEST_BT_ADDR_2, mAdapterService.getIdentityAddress(TEST_BT_ADDR_1));
        Assert.assertEquals(identityAddress, TEST_BT_ADDR_2);
    }
    }


    private static byte[] getMetricsSalt(HashMap<String, HashMap<String, String>> adapterConfig) {
    private static byte[] getMetricsSalt(HashMap<String, HashMap<String, String>> adapterConfig) {
+2 −1
Original line number Original line Diff line number Diff line
@@ -1477,7 +1477,8 @@ public final class BluetoothDevice implements Parcelable, Attributable {
     * Returns the identity address of this BluetoothDevice.
     * Returns the identity address of this BluetoothDevice.
     * <p> For example, "00:11:22:AA:BB:CC".
     * <p> For example, "00:11:22:AA:BB:CC".
     *
     *
     * @return Bluetooth identity address as a string
     * @return this device's identity address as a string or {@code null} if the identity
     *         address is either not known or is unable to be retrieved
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi