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

Commit 94e54d2e authored by jasonwshsu's avatar jasonwshsu
Browse files

Fix input sound does not switch to another Bluetooth device when the active device changes.

Root Cause: Did not check profile active status

Solution: Add active status check for HEARING_AID and LE_AUDIO profile

Bug: 387938333
Test: atest HearingAidDeviceManagerTest
Flag: com.android.settingslib.flags.hearing_devices_input_routing_control
Change-Id: Id6b9fac0f14c5cfc7397ea6c60c4de17b7fba0c3
parent 834f96f5
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -483,14 +483,18 @@ public class HearingAidDeviceManager {

    void onActiveDeviceChanged(CachedBluetoothDevice device) {
        if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_AUDIO_ROUTING)) {
            if (device.isConnectedHearingAidDevice()) {
            if (device.isConnectedHearingAidDevice()
                    && (device.isActiveDevice(BluetoothProfile.HEARING_AID)
                    || device.isActiveDevice(BluetoothProfile.LE_AUDIO))) {
                setAudioRoutingConfig(device);
            } else {
                clearAudioRoutingConfig();
            }
        }
        if (com.android.settingslib.flags.Flags.hearingDevicesInputRoutingControl()) {
            if (device.isConnectedHearingAidDevice()) {
            if (device.isConnectedHearingAidDevice()
                    && (device.isActiveDevice(BluetoothProfile.HEARING_AID)
                    || device.isActiveDevice(BluetoothProfile.LE_AUDIO))) {
                setMicrophoneForCalls(device);
            } else {
                clearMicrophoneForCalls();
+39 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.audiopolicy.AudioProductStrategy;
import android.os.Parcel;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.util.FeatureFlagUtils;

import androidx.test.core.app.ApplicationProvider;
@@ -72,6 +75,8 @@ import java.util.List;
public class HearingAidDeviceManagerTest {
    @Rule
    public MockitoRule mMockitoRule = MockitoJUnit.rule();
    @Rule
    public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();

    private static final long HISYNCID1 = 10;
    private static final long HISYNCID2 = 11;
@@ -736,6 +741,7 @@ public class HearingAidDeviceManagerTest {

    @Test
    public void onActiveDeviceChanged_connected_callSetStrategies() {
        when(mCachedDevice1.isConnectedHearingAidDevice()).thenReturn(true);
        when(mHelper.getMatchedHearingDeviceAttributesForOutput(mCachedDevice1)).thenReturn(
                mHearingDeviceAttribute);
        when(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).thenReturn(true);
@@ -750,6 +756,7 @@ public class HearingAidDeviceManagerTest {

    @Test
    public void onActiveDeviceChanged_disconnected_callSetStrategiesWithAutoValue() {
        when(mCachedDevice1.isConnectedHearingAidDevice()).thenReturn(false);
        when(mHelper.getMatchedHearingDeviceAttributesForOutput(mCachedDevice1)).thenReturn(
                mHearingDeviceAttribute);
        when(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).thenReturn(false);
@@ -952,6 +959,38 @@ public class HearingAidDeviceManagerTest {
                ConnectionStatus.CONNECTED);
    }

    @Test
    @RequiresFlagsEnabled(
            com.android.settingslib.flags.Flags.FLAG_HEARING_DEVICES_INPUT_ROUTING_CONTROL)
    public void onActiveDeviceChanged_activeHearingAidProfile_callSetInputDeviceForCalls() {
        when(mCachedDevice1.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).thenReturn(true);
        when(mDevice1.isMicrophonePreferredForCalls()).thenReturn(true);
        doReturn(true).when(mHelper).setPreferredDeviceRoutingStrategies(anyList(), any(),
                anyInt());

        mHearingAidDeviceManager.onActiveDeviceChanged(mCachedDevice1);

        verify(mHelper).setPreferredInputDeviceForCalls(
                eq(mCachedDevice1), eq(HearingAidAudioRoutingConstants.RoutingValue.AUTO));

    }

    @Test
    @RequiresFlagsEnabled(
            com.android.settingslib.flags.Flags.FLAG_HEARING_DEVICES_INPUT_ROUTING_CONTROL)
    public void onActiveDeviceChanged_notActiveHearingAidProfile_callClearInputDeviceForCalls() {
        when(mCachedDevice1.isConnectedHearingAidDevice()).thenReturn(true);
        when(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).thenReturn(false);
        when(mDevice1.isMicrophonePreferredForCalls()).thenReturn(true);
        doReturn(true).when(mHelper).setPreferredDeviceRoutingStrategies(anyList(), any(),
                anyInt());

        mHearingAidDeviceManager.onActiveDeviceChanged(mCachedDevice1);

        verify(mHelper).clearPreferredInputDeviceForCalls();
    }

    private HearingAidInfo getLeftAshaHearingAidInfo(long hiSyncId) {
        return new HearingAidInfo.Builder()
                .setAshaDeviceSide(HearingAidInfo.DeviceSide.SIDE_LEFT)