Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be71881e authored by Angela Wang's avatar Angela Wang Committed by Android (Google) Code Review
Browse files

Merge "New hearing aid info side "SIDE_MONO"" into main

parents e9890579 dcbb63f8
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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(
@@ -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.
+1 −3
Original line number Diff line number Diff line
@@ -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;
@@ -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)
+5 −0
Original line number Diff line number Diff line
@@ -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. */
@@ -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)
@@ -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) {
+4 −5
Original line number Diff line number Diff line
@@ -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;
@@ -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);
@@ -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);