Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +15 −3 Original line number Diff line number Diff line Loading @@ -115,12 +115,24 @@ public class BluetoothUtils { } List<LocalBluetoothProfile> profiles = cachedDevice.getProfiles(); int resId = 0; for (LocalBluetoothProfile profile : profiles) { int resId = profile.getDrawableResource(btClass); 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<>( Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +11 −3 Original line number Diff line number Diff line Loading @@ -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; Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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(); } } Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +15 −3 Original line number Diff line number Diff line Loading @@ -115,12 +115,24 @@ public class BluetoothUtils { } List<LocalBluetoothProfile> profiles = cachedDevice.getProfiles(); int resId = 0; for (LocalBluetoothProfile profile : profiles) { int resId = profile.getDrawableResource(btClass); 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<>( Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +11 −3 Original line number Diff line number Diff line Loading @@ -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; Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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(); } }