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

Commit 09544613 authored by Lei Yu's avatar Lei Yu
Browse files

Revert "remove getName() from CachedBluetoothDeviceManager"

This reverts commit c386c87b.

Reason for revert:
To fix null pointer crash in Pairing dialog. Dialog maybe triggered by intent, in which LocalBluetoothManager couldn't have instance for BluetoothDevice and will return null. As a result, we need to depend on method in CachedBluetoothManager to handle it.

Bug: 115754654
Bug: 112735753
Change-Id: I727089cfd23819f292f96f0d0232f35bc6ebac64
parent c386c87b
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -211,6 +211,26 @@ public class CachedBluetoothDeviceManager {
        }
    }

    /**
     * Attempts to get the name of a remote device, otherwise returns the address.
     *
     * @param device The remote device.
     * @return The name, or if unavailable, the address.
     */
    public String getName(BluetoothDevice device) {
        CachedBluetoothDevice cachedDevice = findDevice(device);
        if (cachedDevice != null && cachedDevice.getName() != null) {
            return cachedDevice.getName();
        }

        String name = device.getAliasName();
        if (name != null) {
            return name;
        }

        return device.getAddress();
    }

    public synchronized void clearNonBondedDevices() {

        mCachedDevicesMapForHearingAids.entrySet().removeIf(entries
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ public class CachedBluetoothDeviceManagerTest {
    public void testGetName_validCachedDevice_nameFound() {
        CachedBluetoothDevice cachedDevice1 = mCachedDeviceManager.addDevice(mDevice1);
        assertThat(cachedDevice1).isNotNull();
        assertThat(mCachedDeviceManager.findDevice(mDevice1).getName()).isEqualTo(DEVICE_ALIAS_1);
        assertThat(mCachedDeviceManager.getName(mDevice1)).isEqualTo(DEVICE_ALIAS_1);
    }

    /**