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

Commit 80a3a93e authored by Grace Jia's avatar Grace Jia
Browse files

Set communication audio flag for BT le device and hearing aid device off

if the communication device is already set to other devices.

Bug: 232360337
Test: BluetoothDeviceManagerTest
Change-Id: I3dac549c7fce8d7337ca0863819dcce04f46896b
Merged-In: I3dac549c7fce8d7337ca0863819dcce04f46896b
parent 3d7ee370
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -430,8 +430,8 @@ public class BluetoothDeviceManager {
                && mAudioManager.getCommunicationDevice().getType()
                == AudioDeviceInfo.TYPE_BLE_HEADSET) {
            mAudioManager.clearCommunicationDevice();
            mLeAudioSetAsCommunicationDevice = false;
        }
        mLeAudioSetAsCommunicationDevice = false;
    }

    public void clearHearingAidCommunicationDevice() {
@@ -447,8 +447,8 @@ public class BluetoothDeviceManager {
                && mAudioManager.getCommunicationDevice().getType()
                == AudioDeviceInfo.TYPE_HEARING_AID) {
            mAudioManager.clearCommunicationDevice();
            mHearingAidSetAsCommunicationDevice = false;
        }
        mHearingAidSetAsCommunicationDevice = false;
    }

    public boolean setLeAudioCommunicationDevice() {
+25 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.telecom.tests;

import static android.media.AudioDeviceInfo.TYPE_BUILTIN_SPEAKER;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
@@ -42,6 +44,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.nullable;
@@ -65,6 +68,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
    @Mock BluetoothHearingAid mBluetoothHearingAid;
    @Mock BluetoothLeAudio mBluetoothLeAudio;
    @Mock AudioManager mockAudioManager;
    @Mock AudioDeviceInfo mSpeakerInfo;

    BluetoothDeviceManager mBluetoothDeviceManager;
    BluetoothProfile.ServiceListener serviceListenerUnderTest;
@@ -116,6 +120,8 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
                         ArgumentCaptor.forClass(BluetoothLeAudio.Callback.class);
        mBluetoothDeviceManager.setLeAudioServiceForTesting(mBluetoothLeAudio);
        verify(mBluetoothLeAudio).registerCallback(any(), leAudioCallbacksTest.capture());

        when(mSpeakerInfo.getType()).thenReturn(TYPE_BUILTIN_SPEAKER);
    }

    @Override
@@ -451,6 +457,25 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        verify(mAdapter).setActiveDevice(device6, BluetoothAdapter.ACTIVE_DEVICE_ALL);
    }

    @SmallTest
    @Test
    public void testClearHearingAidCommunicationDevice() {
        AudioDeviceInfo mockAudioDeviceInfo = mock(AudioDeviceInfo.class);
        when(mockAudioDeviceInfo.getType()).thenReturn(AudioDeviceInfo.TYPE_HEARING_AID);
        List<AudioDeviceInfo> devices = new ArrayList<>();
        devices.add(mockAudioDeviceInfo);

        when(mockAudioManager.getAvailableCommunicationDevices())
                .thenReturn(devices);
        when(mockAudioManager.setCommunicationDevice(eq(mockAudioDeviceInfo)))
                .thenReturn(true);

        mBluetoothDeviceManager.setHearingAidCommunicationDevice();
        when(mockAudioManager.getCommunicationDevice()).thenReturn(mSpeakerInfo);
        mBluetoothDeviceManager.clearHearingAidCommunicationDevice();
        assertFalse(mBluetoothDeviceManager.isHearingAidSetAsCommunicationDevice());
    }

    private Intent buildConnectionActionIntent(int state, BluetoothDevice device, int deviceType) {
        String intentString;