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

Commit c5307d2d 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 d037c269
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -433,6 +433,7 @@ public class BluetoothDeviceManager {
            mAudioManager.clearCommunicationDevice();
            mLeAudioSetAsCommunicationDevice = false;
        }
        mLeAudioSetAsCommunicationDevice = false;
    }

    public void clearHearingAidCommunicationDevice() {
@@ -450,6 +451,7 @@ public class BluetoothDeviceManager {
            mAudioManager.clearCommunicationDevice();
            mHearingAidSetAsCommunicationDevice = false;
        }
        mHearingAidSetAsCommunicationDevice = false;
    }

    public boolean setLeAudioCommunicationDevice() {
+15 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
@@ -42,6 +41,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;
@@ -49,7 +49,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@@ -482,6 +481,20 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        verify(mAdapter).setActiveDevice(device6, BluetoothAdapter.ACTIVE_DEVICE_ALL);
    }

    @SmallTest
    @Test
    public void testClearHearingAidCommunicationDevice() {
        List<AudioDeviceInfo> devices = new ArrayList<>();

        when(mockAudioManager.getAvailableCommunicationDevices())
                .thenReturn(devices);

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

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