BLE hearing aid information in Bluetooth device preference

Update the bluetooth icon and summary text for BLE hearing aid shown in
Bluetooth device preference.

BLE hearing aid will connect to both LE audio and HAP client profile.
These two profiles which connect first will be displayed as the device
bluetooth icon, but is should be hearing aid icon for BLE hearing aid.

The solution is to check if the device connected to any of the hearing
aid related profiles first. If hearing aid related profiles found, it
should use hearing aid icon. Otherwise, it should check if any other
profile has specific icon to show.

Bug: 259904131
Test: make RunSettingsLibRoboTests ROBOTEST_FILTER=CachedBluetoothDeviceTest
Change-Id: I5dbe90814ce1199fae704833935dd897a36128f2
This commit is contained in:
Angela Wang
2022-11-21 03:35:30 +00:00
parent d39c54a1bd
commit 0f0862124c
3 changed files with 54 additions and 6 deletions

View File

@@ -115,12 +115,24 @@ public class BluetoothUtils {
}
List<LocalBluetoothProfile> profiles = cachedDevice.getProfiles();
int resId = 0;
for (LocalBluetoothProfile profile : profiles) {
int resId = profile.getDrawableResource(btClass);
if (resId != 0) {
return new Pair<>(getBluetoothDrawable(context, resId), null);
int profileResId = profile.getDrawableResource(btClass);
if (profileResId != 0) {
// The device should show hearing aid icon if it contains any hearing aid related
// profiles
if (profile instanceof HearingAidProfile || profile instanceof HapClientProfile) {
return new Pair<>(getBluetoothDrawable(context, profileResId), null);
}
if (resId == 0) {
resId = profileResId;
}
}
}
if (resId != 0) {
return new Pair<>(getBluetoothDrawable(context, resId), null);
}
if (btClass != null) {
if (doesClassMatch(btClass, BluetoothClass.PROFILE_HEADSET)) {
return new Pair<>(

View File

@@ -1164,14 +1164,22 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
// Try to show left/right information if can not get it from battery for hearing
// aids specifically.
if (mIsActiveDeviceHearingAid
boolean isActiveAshaHearingAid = mIsActiveDeviceHearingAid;
boolean isActiveLeAudioHearingAid = mIsActiveDeviceLeAudio
&& isConnectedHapClientDevice();
if ((isActiveAshaHearingAid || isActiveLeAudioHearingAid)
&& stringRes == R.string.bluetooth_active_no_battery_level) {
final Set<CachedBluetoothDevice> memberDevices = getMemberDevice();
final CachedBluetoothDevice subDevice = getSubDevice();
if (subDevice != null && subDevice.isConnected()) {
if (memberDevices.stream().anyMatch(m -> m.isConnected())) {
stringRes = R.string.bluetooth_hearing_aid_left_and_right_active;
} else if (subDevice != null && subDevice.isConnected()) {
stringRes = R.string.bluetooth_hearing_aid_left_and_right_active;
} else {
int deviceSide = getDeviceSide();
if (deviceSide == HearingAidInfo.DeviceSide.SIDE_LEFT) {
if (deviceSide == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) {
stringRes = R.string.bluetooth_hearing_aid_left_and_right_active;
} else if (deviceSide == HearingAidInfo.DeviceSide.SIDE_LEFT) {
stringRes = R.string.bluetooth_hearing_aid_left_active;
} else if (deviceSide == HearingAidInfo.DeviceSide.SIDE_RIGHT) {
stringRes = R.string.bluetooth_hearing_aid_right_active;

View File

@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.content.Context;
@@ -446,6 +447,26 @@ public class CachedBluetoothDeviceTest {
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, 10% battery");
}
@Test
public void getConnectionSummary_testActiveDeviceLeAudioHearingAid() {
// Test without battery level
// Set HAP Client and LE Audio profile to be connected and test connection state summary
when(mProfileManager.getHapClientProfile()).thenReturn(mHapClientProfile);
updateProfileStatus(mHapClientProfile, BluetoothProfile.STATE_CONNECTED);
updateProfileStatus(mLeAudioProfile, BluetoothProfile.STATE_CONNECTED);
assertThat(mCachedDevice.getConnectionSummary()).isNull();
// Set device as Active for LE Audio and test connection state summary
mCachedDevice.setHearingAidInfo(getLeftLeAudioHearingAidInfo());
mCachedDevice.onActiveDeviceChanged(true, BluetoothProfile.LE_AUDIO);
assertThat(mCachedDevice.getConnectionSummary()).isEqualTo("Active, left only");
// Set LE Audio profile to be disconnected and test connection state summary
mCachedDevice.onActiveDeviceChanged(false, BluetoothProfile.LE_AUDIO);
mCachedDevice.onProfileStateChanged(mLeAudioProfile, BluetoothProfile.STATE_DISCONNECTED);
assertThat(mCachedDevice.getConnectionSummary()).isNull();
}
@Test
public void getConnectionSummary_testMultipleProfilesActiveDevice() {
// Test without battery level
@@ -1110,9 +1131,16 @@ public class CachedBluetoothDeviceTest {
.setAshaDeviceSide(HearingAidProfile.DeviceSide.SIDE_LEFT)
.build();
}
private HearingAidInfo getRightAshaHearingAidInfo() {
return new HearingAidInfo.Builder()
.setAshaDeviceSide(HearingAidProfile.DeviceSide.SIDE_RIGHT)
.build();
}
private HearingAidInfo getLeftLeAudioHearingAidInfo() {
return new HearingAidInfo.Builder()
.setLeAudioLocation(BluetoothLeAudio.AUDIO_LOCATION_SIDE_LEFT)
.build();
}
}