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

Commit cb3895d5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Fix hearing aid device audio route switch issue." into tm-qpr-dev

parents 09511838 8e031921
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ public class BluetoothDeviceManager {
    private BluetoothLeAudio mBluetoothLeAudioService;
    private boolean mLeAudioSetAsCommunicationDevice = false;
    private String mLeAudioDevice;
    private String mHearingAidDevice;
    private boolean mHearingAidSetAsCommunicationDevice = false;
    private BluetoothDevice mBluetoothHearingAidActiveDeviceCache;
    private BluetoothAdapter mBluetoothAdapter;
@@ -443,10 +444,17 @@ public class BluetoothDeviceManager {
    }

    public void clearHearingAidCommunicationDevice() {
        Log.i(this, "clearHearingAidCommunicationDevice: mHearingAidSetAsCommunicationDevice = "
                + mHearingAidSetAsCommunicationDevice);
        if (!mHearingAidSetAsCommunicationDevice) {
            return;
        }
        mHearingAidSetAsCommunicationDevice = false;
        if (mHearingAidDevice != null) {
            mBluetoothRouteManager.onAudioLost(mHearingAidDevice);
            mHearingAidDevice = null;
        }

        if (mAudioManager == null) {
            Log.i(this, "clearHearingAidCommunicationDevice: mAudioManager is null");
            return;
@@ -552,6 +560,7 @@ public class BluetoothDeviceManager {
            Log.w(this, " Could not set hearingAid device");
        } else {
            Log.i(this, " hearingAid device set");
            mHearingAidDevice = hearingAid.getAddress();
            mHearingAidSetAsCommunicationDevice = true;
        }
        return result;
+2 −1
Original line number Diff line number Diff line
@@ -491,7 +491,8 @@ public class BluetoothRouteManager extends StateMachine {
            SomeArgs args = (SomeArgs) msg.obj;

            Log.continueSession(((Session) args.arg1), "BRM.pM_" + msg.what);
            Log.i(LOG_TAG, "Message received: %s.", MESSAGE_CODE_TO_NAME.get(msg.what));
            Log.i(LOG_TAG, "%s received message: %s.", this,
                    MESSAGE_CODE_TO_NAME.get(msg.what));
        } else if (msg.what == RUN_RUNNABLE && msg.obj instanceof Runnable) {
            Log.i(LOG_TAG, "Running runnable for testing");
        } else {
+7 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import java.util.List;

@RunWith(JUnit4.class)
public class BluetoothDeviceManagerTest extends TelecomTestCase {
    private static final String DEVICE_ADDRESS_1 = "00:00:00:00:00:01";

    @Mock BluetoothRouteManager mRouteManager;
    @Mock BluetoothHeadset mBluetoothHeadset;
    @Mock BluetoothAdapter mAdapter;
@@ -484,7 +486,11 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
    @SmallTest
    @Test
    public void testClearHearingAidCommunicationDevice() {
        AudioDeviceInfo mockAudioDeviceInfo = mock(AudioDeviceInfo.class);
        when(mockAudioDeviceInfo.getAddress()).thenReturn(DEVICE_ADDRESS_1);
        when(mockAudioDeviceInfo.getType()).thenReturn(AudioDeviceInfo.TYPE_HEARING_AID);
        List<AudioDeviceInfo> devices = new ArrayList<>();
        devices.add(mockAudioDeviceInfo);

        when(mockAudioManager.getAvailableCommunicationDevices())
                .thenReturn(devices);
@@ -492,6 +498,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        mBluetoothDeviceManager.setHearingAidCommunicationDevice();
        when(mockAudioManager.getCommunicationDevice()).thenReturn(null);
        mBluetoothDeviceManager.clearHearingAidCommunicationDevice();
        verify(mRouteManager).onAudioLost(eq(DEVICE_ADDRESS_1));
        assertFalse(mBluetoothDeviceManager.isHearingAidSetAsCommunicationDevice());
    }