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

Commit 4ca9c339 authored by Jason Hsu's avatar Jason Hsu
Browse files

Fix wrong history data when connected to LEA hearig aids

Root Cause: Triggered by profile state changed, when HapProfile get connected, it will change history TYPE_HEARING_DEVICES_CONNECTED. Then when its LeAudioProfile get connected, it will also change TYPE_LE_HEARING_CONNECTED. So a LEA hearing aids  will alter 2 times history data.

Solution: HapProfile should be treated independently, and LeAudioProfile should consider does it belong hearing aids or not.

Bug: 441228401
Test: atest HearingDeviceStatsLogUtilsTest
Flag: EXEMPT bugfix
Change-Id: I6e97332f9fd388b4cf0e9a0a21ef7d7456608ba2
parent 9ee322dc
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -177,15 +177,13 @@ public final class HearingDeviceStatsLogUtils {

        if (profileState == BluetoothProfile.STATE_CONNECTED) {
            // Saves connected timestamp as the source for judging whether to display the survey
            if (profile instanceof LeAudioProfile) {
                if (isHearingDevice(cachedDevice)) {
                    addCurrentTimeToHistory(context, HistoryType.TYPE_LE_HEARING_CONNECTED);
                } else {
            if (profile instanceof LeAudioProfile && !isHearingDevice(cachedDevice)) {
                addCurrentTimeToHistory(context, HistoryType.TYPE_LE_HEARABLE_CONNECTED);
                }
            } else if (isHearingProfile(profile)) {
            } else if (profile instanceof HapClientProfile) {
                addCurrentTimeToHistory(context, HistoryType.TYPE_LE_HEARING_CONNECTED);
            } else if (profile instanceof HearingAidProfile) {
                addCurrentTimeToHistory(context, HistoryType.TYPE_HEARING_DEVICES_CONNECTED);
            } else if (isHearableProfile(profile)) {
            } else if (profile instanceof A2dpProfile || profile instanceof HeadsetProfile) {
                addCurrentTimeToHistory(context, HistoryType.TYPE_HEARABLE_DEVICES_CONNECTED);
            }
        }
+19 −2
Original line number Diff line number Diff line
@@ -227,17 +227,34 @@ public class HearingDeviceStatsLogUtilsTest {
        HearingDeviceStatsLogUtils.updateHistoryIfNeeded(mContext, mCachedBluetoothDevice,
                hapClientProfile, BluetoothProfile.STATE_CONNECTED);

        assertHistorySize(TYPE_HEARING_DEVICES_CONNECTED, 1);
        assertHistorySize(TYPE_LE_HEARING_CONNECTED, 1);
    }

    @Test
    public void updateHistoryIfNeeded_leAudioHearingDevice_leAudioConnected_historyCorrect() {
    public void updateHistoryIfNeeded_leAudioHearingDevice_onlyLeAudioConnected_notBelongAnyYet() {
        prepareLeAudioHearingDevice();

        LeAudioProfile leAudioProfile = mock(LeAudioProfile.class);
        HearingDeviceStatsLogUtils.updateHistoryIfNeeded(mContext, mCachedBluetoothDevice,
                leAudioProfile, BluetoothProfile.STATE_CONNECTED);

        assertHistorySize(TYPE_HEARING_DEVICES_CONNECTED, 0);
        assertHistorySize(TYPE_LE_HEARING_CONNECTED, 0);

    }

    @Test
    public void updateHistoryIfNeeded_leAudioHearingDevice_hapAndLeAudioConnected_historyCorrect() {
        prepareLeAudioHearingDevice();

        HapClientProfile hapClientProfile = mock(HapClientProfile.class);
        LeAudioProfile leAudioProfile = mock(LeAudioProfile.class);
        HearingDeviceStatsLogUtils.updateHistoryIfNeeded(mContext, mCachedBluetoothDevice,
                leAudioProfile, BluetoothProfile.STATE_CONNECTED);
        HearingDeviceStatsLogUtils.updateHistoryIfNeeded(mContext, mCachedBluetoothDevice,
                hapClientProfile, BluetoothProfile.STATE_CONNECTED);

        assertHistorySize(TYPE_HEARING_DEVICES_CONNECTED, 0);
        assertHistorySize(TYPE_LE_HEARING_CONNECTED, 1);
    }