Fix default microphone for calls sometimes not work and not show UI

Root Cause: Only setMicrophonePreferredForCalls and show UI to current device, but audioManager
might hold other device in the same set

Solution: setMicrophonePreferredForCalls to whole device set and also check if any address in device
set contain in audioManager GET_DEVICES_INPUTS list

Bug: 392902067
Test: atest BluetoothDetailsHearingDeviceInputRoutingControllerTest
Flag: EXEMPT bugfix
Change-Id: Ic5846de26df4a8db67fa8efcf474fa4509f7918a
This commit is contained in:
jasonwshsu
2025-02-19 18:59:56 +08:00
parent 010869fc7e
commit 691a3fd641
2 changed files with 49 additions and 7 deletions

View File

@@ -36,6 +36,7 @@ import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import com.android.settings.bluetooth.HearingDeviceInputRoutingPreference.InputRoutingValue;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HapClientProfile;
import org.junit.Rule;
@@ -49,6 +50,7 @@ import org.robolectric.RobolectricTestRunner;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/** Tests for {@link BluetoothDetailsHearingDeviceInputRoutingController}. */
@@ -59,11 +61,14 @@ public class BluetoothDetailsHearingDeviceInputRoutingControllerTest extends
public final MockitoRule mockito = MockitoJUnit.rule();
private static final String TEST_ADDRESS = "55:66:77:88:99:AA";
private static final String TEST_ADDRESS_2 = "55:66:77:88:99:BB";
@Mock
private BluetoothDevice mBluetoothDevice;
@Mock
private HapClientProfile mHapClientProfile;
@Mock
private CachedBluetoothDevice mMemberCachedDevice;
@Spy
private AudioManager mAudioManager;
@@ -162,6 +167,18 @@ public class BluetoothDetailsHearingDeviceInputRoutingControllerTest extends
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_validInputMember_supportHapProfile_returnTrue() {
when(mCachedDevice.getMemberDevice()).thenReturn(Set.of(mMemberCachedDevice));
when(mCachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
when(mMemberCachedDevice.getAddress()).thenReturn(TEST_ADDRESS_2);
AudioDeviceInfo[] mockInfo = new AudioDeviceInfo[] {mockTestAddressInfo(TEST_ADDRESS_2)};
when(mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS)).thenReturn(mockInfo);
when(mCachedDevice.getProfiles()).thenReturn(List.of(mHapClientProfile));
assertThat(mController.isAvailable()).isTrue();
}
private AudioDeviceInfo mockTestAddressInfo(String address) {
final AudioDeviceInfo info = mock(AudioDeviceInfo.class);
when(info.getType()).thenReturn(AudioDeviceInfo.TYPE_BLE_HEADSET);