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

Commit 54e5a759 authored by Angela Wang's avatar Angela Wang
Browse files

Fix showing hearing device icon for headphone device issue

When turn off and on Bluetooth or reboot the device, the hearing aid
info will accidentally set on any LE audio device. This cause the icon
display wrongly for these device.

HapClientProfile.getHearingAidType() will return 0 (valid value for
binaural hearing aid) even if the device doesn't support HAP. Need to
check if the device supports HAP before generating the hearing aid info.

Bug: 327680602
Test: atest CachedBluetoothDeviceManagerTest
Change-Id: If2ccd5c4551510051a1a3ee1181623f11da10ada
parent c7d04194
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -346,11 +346,15 @@ public class HearingAidDeviceManager {
        } else {
            long hiSyncId = asha.getHiSyncId(cachedDevice.getDevice());
            if (isValidHiSyncId(hiSyncId)) {
                final HearingAidInfo.Builder infoBuilder = new HearingAidInfo.Builder()
                final HearingAidInfo info = new HearingAidInfo.Builder()
                        .setAshaDeviceSide(asha.getDeviceSide(cachedDevice.getDevice()))
                        .setAshaDeviceMode(asha.getDeviceMode(cachedDevice.getDevice()))
                        .setHiSyncId(hiSyncId);
                return infoBuilder.build();
                        .setHiSyncId(hiSyncId)
                        .build();
                if (DEBUG) {
                    Log.d(TAG, "generateHearingAidInfo, " + cachedDevice + ", info=" + info);
                }
                return info;
            }
        }

@@ -358,15 +362,20 @@ public class HearingAidDeviceManager {
        final LeAudioProfile leAudioProfile = profileManager.getLeAudioProfile();
        if (hapClientProfile == null || leAudioProfile == null) {
            Log.w(TAG, "HapClientProfile or LeAudioProfile is not supported on this device");
        } else {
        } else if (cachedDevice.getProfiles().stream().anyMatch(
                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) {
                final HearingAidInfo.Builder infoBuilder = new HearingAidInfo.Builder()
                final HearingAidInfo info = new HearingAidInfo.Builder()
                        .setLeAudioLocation(audioLocation)
                        .setHapDeviceType(hearingAidType);
                return infoBuilder.build();
                        .setHapDeviceType(hearingAidType)
                        .build();
                if (DEBUG) {
                    Log.d(TAG, "generateHearingAidInfo, " + cachedDevice + ", info=" + info);
                }
                return info;
            }
        }