Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +7 −2 Original line number Diff line number Diff line Loading @@ -1591,6 +1591,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> private int getHearingDeviceSummaryRes(int leftBattery, int rightBattery, boolean shortSummary) { if (getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_MONO || getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) { return !shortSummary && (getBatteryLevel() > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) ? R.string.bluetooth_active_battery_level : R.string.bluetooth_active_no_battery_level; } boolean isLeftDeviceConnected = getConnectedHearingAidSide( HearingAidInfo.DeviceSide.SIDE_LEFT).isPresent(); boolean isRightDeviceConnected = getConnectedHearingAidSide( Loading Loading @@ -1646,8 +1652,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> @HearingAidInfo.DeviceSide int side) { return Stream.concat(Stream.of(this, mSubDevice), mMemberDevices.stream()) .filter(Objects::nonNull) .filter(device -> device.getDeviceSide() == side || device.getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) .filter(device -> device.getDeviceSide() == side) .filter(device -> device.getDevice().isConnected()) // For hearing aids, we should expect only one device assign to one side, but if // it happens, we don't care which one. Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.settingslib.bluetooth; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothHapClient; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.le.ScanFilter; Loading Loading @@ -432,8 +431,7 @@ public class HearingAidDeviceManager { p -> p instanceof HapClientProfile)) { int audioLocation = leAudioProfile.getAudioLocation(cachedDevice.getDevice()); int hearingAidType = hapClientProfile.getHearingAidType(cachedDevice.getDevice()); if (audioLocation != BluetoothLeAudio.AUDIO_LOCATION_INVALID && hearingAidType != HapClientProfile.HearingAidType.TYPE_INVALID) { if (hearingAidType != HapClientProfile.HearingAidType.TYPE_INVALID) { final HearingAidInfo info = new HearingAidInfo.Builder() .setLeAudioLocation(audioLocation) .setHapDeviceType(hearingAidType) Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ public class HearingAidInfo { DeviceSide.SIDE_LEFT, DeviceSide.SIDE_RIGHT, DeviceSide.SIDE_LEFT_AND_RIGHT, DeviceSide.SIDE_MONO }) /** Side definition for hearing aids. */ Loading @@ -42,6 +43,7 @@ public class HearingAidInfo { int SIDE_LEFT = 0; int SIDE_RIGHT = 1; int SIDE_LEFT_AND_RIGHT = 2; int SIDE_MONO = 3; } @Retention(java.lang.annotation.RetentionPolicy.SOURCE) Loading Loading @@ -124,6 +126,9 @@ public class HearingAidInfo { @DeviceSide private static int convertLeAudioLocationToInternalSide(int leAudioLocation) { if (leAudioLocation == BluetoothLeAudio.AUDIO_LOCATION_MONO) { return DeviceSide.SIDE_MONO; } boolean isLeft = (leAudioLocation & LE_AUDIO_LOCATION_LEFT) != 0; boolean isRight = (leAudioLocation & LE_AUDIO_LOCATION_RIGHT) != 0; if (isLeft && isRight) { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/HearingAidDeviceManagerTest.java +4 −5 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package com.android.settingslib.bluetooth; import static android.bluetooth.BluetoothHearingAid.HI_SYNC_ID_INVALID; import static android.bluetooth.BluetoothLeAudio.AUDIO_LOCATION_FRONT_LEFT; import static android.bluetooth.BluetoothLeAudio.AUDIO_LOCATION_INVALID; import static com.android.settingslib.bluetooth.HapClientProfile.HearingAidType.TYPE_BINAURAL; import static com.android.settingslib.bluetooth.HapClientProfile.HearingAidType.TYPE_INVALID; Loading Loading @@ -272,14 +271,14 @@ public class HearingAidDeviceManagerTest { * * Conditions: * 1) LeAudio hearing aid * 2) Invalid audio location and device type * 2) Invalid device type * Result: * Do not set hearing aid info to the device. */ @Test public void initHearingAidDeviceIfNeeded_leAudio_invalidInfo_notToSetHearingAidInfo() { when(mCachedDevice1.getProfiles()).thenReturn(List.of(mLeAudioProfile, mHapClientProfile)); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_INVALID); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_FRONT_LEFT); when(mHapClientProfile.getHearingAidType(mDevice1)).thenReturn(TYPE_INVALID); mHearingAidDeviceManager.initHearingAidDeviceIfNeeded(mCachedDevice1, null); Loading Loading @@ -506,14 +505,14 @@ public class HearingAidDeviceManagerTest { * * Conditions: * 1) LeAudio hearing aid * 2) Invalid audio location and device type * 2) Invalid device type * Result: * Do not set hearing aid info to the device. */ @Test public void updateHearingAidsDevices_leAudio_invalidInfo_notToSetHearingAidInfo() { when(mCachedDevice1.getProfiles()).thenReturn(List.of(mLeAudioProfile, mHapClientProfile)); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_INVALID); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_FRONT_LEFT); when(mHapClientProfile.getHearingAidType(mDevice1)).thenReturn(TYPE_INVALID); mCachedDeviceManager.mCachedDevices.add(mCachedDevice1); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +7 −2 Original line number Diff line number Diff line Loading @@ -1591,6 +1591,12 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> private int getHearingDeviceSummaryRes(int leftBattery, int rightBattery, boolean shortSummary) { if (getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_MONO || getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) { return !shortSummary && (getBatteryLevel() > BluetoothDevice.BATTERY_LEVEL_UNKNOWN) ? R.string.bluetooth_active_battery_level : R.string.bluetooth_active_no_battery_level; } boolean isLeftDeviceConnected = getConnectedHearingAidSide( HearingAidInfo.DeviceSide.SIDE_LEFT).isPresent(); boolean isRightDeviceConnected = getConnectedHearingAidSide( Loading Loading @@ -1646,8 +1652,7 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> @HearingAidInfo.DeviceSide int side) { return Stream.concat(Stream.of(this, mSubDevice), mMemberDevices.stream()) .filter(Objects::nonNull) .filter(device -> device.getDeviceSide() == side || device.getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) .filter(device -> device.getDeviceSide() == side) .filter(device -> device.getDevice().isConnected()) // For hearing aids, we should expect only one device assign to one side, but if // it happens, we don't care which one. Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidDeviceManager.java +1 −3 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ package com.android.settingslib.bluetooth; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothHapClient; import android.bluetooth.BluetoothHearingAid; import android.bluetooth.BluetoothLeAudio; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.le.ScanFilter; Loading Loading @@ -432,8 +431,7 @@ public class HearingAidDeviceManager { p -> p instanceof HapClientProfile)) { int audioLocation = leAudioProfile.getAudioLocation(cachedDevice.getDevice()); int hearingAidType = hapClientProfile.getHearingAidType(cachedDevice.getDevice()); if (audioLocation != BluetoothLeAudio.AUDIO_LOCATION_INVALID && hearingAidType != HapClientProfile.HearingAidType.TYPE_INVALID) { if (hearingAidType != HapClientProfile.HearingAidType.TYPE_INVALID) { final HearingAidInfo info = new HearingAidInfo.Builder() .setLeAudioLocation(audioLocation) .setHapDeviceType(hearingAidType) Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/HearingAidInfo.java +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ public class HearingAidInfo { DeviceSide.SIDE_LEFT, DeviceSide.SIDE_RIGHT, DeviceSide.SIDE_LEFT_AND_RIGHT, DeviceSide.SIDE_MONO }) /** Side definition for hearing aids. */ Loading @@ -42,6 +43,7 @@ public class HearingAidInfo { int SIDE_LEFT = 0; int SIDE_RIGHT = 1; int SIDE_LEFT_AND_RIGHT = 2; int SIDE_MONO = 3; } @Retention(java.lang.annotation.RetentionPolicy.SOURCE) Loading Loading @@ -124,6 +126,9 @@ public class HearingAidInfo { @DeviceSide private static int convertLeAudioLocationToInternalSide(int leAudioLocation) { if (leAudioLocation == BluetoothLeAudio.AUDIO_LOCATION_MONO) { return DeviceSide.SIDE_MONO; } boolean isLeft = (leAudioLocation & LE_AUDIO_LOCATION_LEFT) != 0; boolean isRight = (leAudioLocation & LE_AUDIO_LOCATION_RIGHT) != 0; if (isLeft && isRight) { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/HearingAidDeviceManagerTest.java +4 −5 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ package com.android.settingslib.bluetooth; import static android.bluetooth.BluetoothHearingAid.HI_SYNC_ID_INVALID; import static android.bluetooth.BluetoothLeAudio.AUDIO_LOCATION_FRONT_LEFT; import static android.bluetooth.BluetoothLeAudio.AUDIO_LOCATION_INVALID; import static com.android.settingslib.bluetooth.HapClientProfile.HearingAidType.TYPE_BINAURAL; import static com.android.settingslib.bluetooth.HapClientProfile.HearingAidType.TYPE_INVALID; Loading Loading @@ -272,14 +271,14 @@ public class HearingAidDeviceManagerTest { * * Conditions: * 1) LeAudio hearing aid * 2) Invalid audio location and device type * 2) Invalid device type * Result: * Do not set hearing aid info to the device. */ @Test public void initHearingAidDeviceIfNeeded_leAudio_invalidInfo_notToSetHearingAidInfo() { when(mCachedDevice1.getProfiles()).thenReturn(List.of(mLeAudioProfile, mHapClientProfile)); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_INVALID); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_FRONT_LEFT); when(mHapClientProfile.getHearingAidType(mDevice1)).thenReturn(TYPE_INVALID); mHearingAidDeviceManager.initHearingAidDeviceIfNeeded(mCachedDevice1, null); Loading Loading @@ -506,14 +505,14 @@ public class HearingAidDeviceManagerTest { * * Conditions: * 1) LeAudio hearing aid * 2) Invalid audio location and device type * 2) Invalid device type * Result: * Do not set hearing aid info to the device. */ @Test public void updateHearingAidsDevices_leAudio_invalidInfo_notToSetHearingAidInfo() { when(mCachedDevice1.getProfiles()).thenReturn(List.of(mLeAudioProfile, mHapClientProfile)); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_INVALID); when(mLeAudioProfile.getAudioLocation(mDevice1)).thenReturn(AUDIO_LOCATION_FRONT_LEFT); when(mHapClientProfile.getHearingAidType(mDevice1)).thenReturn(TYPE_INVALID); mCachedDeviceManager.mCachedDevices.add(mCachedDevice1); Loading