Fix incorrect summary for LE audio hearing aids

For LE audio lead device, the `CachedBluetoothDevice.isConnected()` will return true since `BluetoothLeAudio.getConnectionStatus(device)` will return STATE_CONNECTED even if the device is powered off. Changing to use `CachedBluetoothDevice.getDevice().isConnected()` can avoid the wrong value of the connection status of the device.

Bug: 325524694
Flag: EXEMPT bugfix
Test: atest AccessibilityHearingAidPreferenceControllerTest
Change-Id: If763c0861bb5796d9bc0511916b7077c784b49f5
This commit is contained in:
Angela Wang
2024-05-28 08:40:40 +00:00
parent 42b714f450
commit 5fef3c2bb0
2 changed files with 14 additions and 6 deletions

View File

@@ -134,7 +134,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
// Check if another side of LE audio hearing aid is connected as a pair // Check if another side of LE audio hearing aid is connected as a pair
final Set<CachedBluetoothDevice> memberDevices = device.getMemberDevice(); final Set<CachedBluetoothDevice> memberDevices = device.getMemberDevice();
if (memberDevices.stream().anyMatch(m -> m.isConnected())) { if (memberDevices.stream().anyMatch(m -> m.getDevice().isConnected())) {
return mContext.getString( return mContext.getString(
R.string.accessibility_hearingaid_left_and_right_side_device_summary, R.string.accessibility_hearingaid_left_and_right_side_device_summary,
name); name);
@@ -142,7 +142,7 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
// Check if another side of ASHA hearing aid is connected as a pair // Check if another side of ASHA hearing aid is connected as a pair
final CachedBluetoothDevice subDevice = device.getSubDevice(); final CachedBluetoothDevice subDevice = device.getSubDevice();
if (subDevice != null && subDevice.isConnected()) { if (subDevice != null && subDevice.getDevice().isConnected()) {
return mContext.getString( return mContext.getString(
R.string.accessibility_hearingaid_left_and_right_side_device_summary, name); R.string.accessibility_hearingaid_left_and_right_side_device_summary, name);
} }

View File

@@ -19,6 +19,7 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf; import static org.robolectric.Shadows.shadowOf;
@@ -81,6 +82,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
private BluetoothAdapter mBluetoothAdapter; private BluetoothAdapter mBluetoothAdapter;
private ShadowBluetoothAdapter mShadowBluetoothAdapter; private ShadowBluetoothAdapter mShadowBluetoothAdapter;
private BluetoothDevice mBluetoothDevice; private BluetoothDevice mBluetoothDevice;
private BluetoothDevice mSubBluetoothDevice;
private final Context mContext = ApplicationProvider.getApplicationContext(); private final Context mContext = ApplicationProvider.getApplicationContext();
private Preference mHearingAidPreference; private Preference mHearingAidPreference;
@@ -141,8 +144,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
public void getSummary_connectedAshaHearingAidBothSide_connectedBothSideSummary() { public void getSummary_connectedAshaHearingAidBothSide_connectedBothSideSummary() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidInfo.DeviceSide.SIDE_LEFT); HearingAidInfo.DeviceSide.SIDE_LEFT);
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice); when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
when(mSubBluetoothDevice.isConnected()).thenReturn(true);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList()); when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
mPreferenceController.onStart(); mPreferenceController.onStart();
@@ -205,8 +208,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
@Test @Test
public void getSummary_connectedLeAudioHearingAidBothSide_connectedBothSideSummary() { public void getSummary_connectedLeAudioHearingAidBothSide_connectedBothSideSummary() {
when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(generateMemberDevices()); when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(generateMemberDevices());
when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList()); when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
when(mSubBluetoothDevice.isConnected()).thenReturn(true);
mPreferenceController.onStart(); mPreferenceController.onStart();
Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED); Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
@@ -277,7 +280,8 @@ public class AccessibilityHearingAidPreferenceControllerTest {
mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter); mShadowBluetoothAdapter = Shadow.extract(mBluetoothAdapter);
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID); mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID);
mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT); mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT);
mBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS); mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS));
mSubBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
mBluetoothAdapter.enable(); mBluetoothAdapter.enable();
doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager(); doReturn(mEventManager).when(mLocalBluetoothManager).getEventManager();
@@ -288,8 +292,12 @@ public class AccessibilityHearingAidPreferenceControllerTest {
when(mHearingAidProfile.isProfileReady()).thenReturn(true); when(mHearingAidProfile.isProfileReady()).thenReturn(true);
when(mHapClientProfile.isProfileReady()).thenReturn(true); when(mHapClientProfile.isProfileReady()).thenReturn(true);
when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice); when(mCachedDeviceManager.findDevice(mBluetoothDevice)).thenReturn(mCachedBluetoothDevice);
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS); when(mCachedBluetoothDevice.getAddress()).thenReturn(TEST_DEVICE_ADDRESS);
when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME); when(mCachedBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME);
when(mCachedDeviceManager.findDevice(mSubBluetoothDevice)).thenReturn(
mCachedSubBluetoothDevice);
when(mCachedSubBluetoothDevice.getDevice()).thenReturn(mSubBluetoothDevice);
} }
private void sendIntent(Intent intent) { private void sendIntent(Intent intent) {
@@ -308,7 +316,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
// Generates different Bluetooth devices for testing multiple devices // Generates different Bluetooth devices for testing multiple devices
final List<BluetoothDevice> deviceList = new ArrayList<>(2); final List<BluetoothDevice> deviceList = new ArrayList<>(2);
deviceList.add(mBluetoothDevice); deviceList.add(mBluetoothDevice);
deviceList.add(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2)); deviceList.add(mSubBluetoothDevice);
return deviceList; return deviceList;
} }