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

Commit 3ab32218 authored by timhypeng's avatar timhypeng Committed by tim peng
Browse files

Two "Active" subtext in media transfer slice when switching HearingAid

- replace MediaDevice ID from MAC address to HiSyncId for hearingAid
device
- update test case

Bug: 138974478
Test: make -j42 RunSettingsRoboTests
Change-Id: I478652766160e896399f5760b5dde831fc5477a0
parent 914dacb3
Loading
Loading
Loading
Loading
+18 −17
Original line number Diff line number Diff line
@@ -126,10 +126,13 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall
            return;
        }

        final List<Long> devicesHiSyncIds = new ArrayList<>();
        final List<BluetoothDevice> devices = hapProfile.getConnectableDevices();

        for (BluetoothDevice device : devices) {
            // Only add master HearingAid device, ignore sub
            if (mCachedBluetoothDeviceManager.isSubDevice(device)) {
                Log.w(TAG, "Sub hearingAid device: " + device.getName());
                continue;
            }
            final CachedBluetoothDevice cachedDevice =
                    mCachedBluetoothDeviceManager.findDevice(device);

@@ -142,13 +145,8 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall
                    + ", is connected : " + cachedDevice.isConnected()
                    + ", is preferred : " + hapProfile.isPreferred(device));

            final long hiSyncId = hapProfile.getHiSyncId(device);

            // device with same hiSyncId should not be shown in the UI.
            // So do not add it into connectedDevices.
            if (!devicesHiSyncIds.contains(hiSyncId) && hapProfile.isPreferred(device)
            if (hapProfile.isPreferred(device)
                    && BluetoothDevice.BOND_BONDED == cachedDevice.getBondState()) {
                devicesHiSyncIds.add(hiSyncId);
                addMediaDevice(cachedDevice);
            }
        }
@@ -284,9 +282,8 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall
                + activeDevice + ", profile : " + bluetoothProfile);

        if (BluetoothProfile.HEARING_AID == bluetoothProfile) {
            if (activeDevice != null) {
                dispatchConnectedDeviceChanged(MediaDeviceUtils.getId(activeDevice));
            }
            dispatchConnectedDeviceChanged(activeDevice == null
                    ? PhoneMediaDevice.ID : MediaDeviceUtils.getId(activeDevice));
        } else if (BluetoothProfile.A2DP == bluetoothProfile) {
            // When active device change to Hearing Aid,
            // BluetoothEventManager also send onActiveDeviceChanged() to notify that active device
@@ -304,12 +301,16 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall
    private MediaDevice findActiveHearingAidDevice() {
        final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile();

        if (hearingAidProfile != null) {
        if (hearingAidProfile == null) {
            Log.e(TAG, "findActiveHearingAidDevice: hearingAidProfile == null");
            return null;
        }
        final List<BluetoothDevice> activeDevices = hearingAidProfile.getActiveDevices();
        for (BluetoothDevice btDevice : activeDevices) {
                if (btDevice != null) {
                    return findMediaDevice(MediaDeviceUtils.getId(btDevice));
                }
            final MediaDevice mediaDevice =
                    findMediaDevice(Long.toString(hearingAidProfile.getHiSyncId(btDevice)));
            if (mediaDevice != null) {
                return mediaDevice;
            }
        }
        return null;
+3 −0
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ public class MediaDeviceUtils {
     * @return CachedBluetoothDevice address
     */
    public static String getId(CachedBluetoothDevice cachedDevice) {
        if (cachedDevice.isHearingAidDevice()) {
            return Long.toString(cachedDevice.getHiSyncId());
        }
        return cachedDevice.getAddress();
    }

+4 −3
Original line number Diff line number Diff line
@@ -428,20 +428,21 @@ public class BluetoothMediaManagerTest {

    @Test
    public void onActiveDeviceChanged_hearingAidDeviceIsActive_returnHearingAidDeviceId() {
        final Long hiSyncId = Integer.toUnsignedLong(12345);
        final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class);
        final List<BluetoothDevice> devices = new ArrayList<>();
        devices.add(bluetoothDevice);
        final BluetoothMediaDevice bluetoothMediaDevice = mock(BluetoothMediaDevice.class);
        mMediaManager.mMediaDevices.add(bluetoothMediaDevice);

        when(bluetoothDevice.getAddress()).thenReturn(TEST_ADDRESS);
        when(mHapProfile.getHiSyncId(bluetoothDevice)).thenReturn(hiSyncId);
        when(mHapProfile.getActiveDevices()).thenReturn(devices);
        when(bluetoothMediaDevice.getId()).thenReturn(TEST_ADDRESS);
        when(bluetoothMediaDevice.getId()).thenReturn(Long.toString(hiSyncId));

        mMediaManager.registerCallback(mCallback);
        mMediaManager.onActiveDeviceChanged(null, BluetoothProfile.A2DP);

        verify(mCallback).onConnectedDeviceChanged(TEST_ADDRESS);
        verify(mCallback).onConnectedDeviceChanged(Long.toString(hiSyncId));
    }

    @Test