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

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

Merge changes from topic "ha-preset-unavailable" into main

* changes:
  Remove unavailable preset info option
  Show message when no preset info is obtained from the remote device
parents 2d0638c7 2b78c17e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -156,6 +156,8 @@
    <string name="bluetooth_hearing_device_settings_summary">Shortcut, hearing aid compatibility</string>
    <!-- Connected devices settings. Title for hearing aids presets. A preset is a set of hearing aid settings. User can apply different settings in different environments (e.g. Outdoor, Restaurant, Home) [CHAR LIMIT=60] [BACKUP_MESSAGE_ID=5429761844739722885] -->
    <string name="bluetooth_hearing_aids_presets">Preset</string>
    <!-- Connected devices settings. Summary of the preference when no preset info is obtained from the remote device [CHAR LIMIT=60] -->
    <string name="bluetooth_hearing_aids_presets_empty_list_message">There are no presets programmed by your audiologist</string>
    <!-- Message when selecting hearing aids presets failed. [CHAR LIMIT=NONE] -->
    <string name="bluetooth_hearing_aids_presets_error">Couldn\u2019t update preset</string>
    <!-- Connected devices settings. Title of the preference to show the entrance of the audio output page. It can change different types of audio are played on phone or other bluetooth devices. [CHAR LIMIT=35] -->
+10 −6
Original line number Diff line number Diff line
@@ -159,19 +159,22 @@ public class BluetoothDetailsHearingAidsPresetsController extends
        mPreference.setEnabled(mCachedDevice.isConnectedHapClientDevice());

        loadAllPresetInfo();
        mPreference.setSummary(null);
        if (mPreference.getEntries().length == 0) {
            if (mPreference.isEnabled()) {
                if (DEBUG) {
                    Log.w(TAG, "Disable the preference since preset info size = 0");
                }
                mPreference.setEnabled(false);
                mPreference.setSummary(mContext.getString(
                        R.string.bluetooth_hearing_aids_presets_empty_list_message));
            }
        } else {
            int activePresetIndex = mHapClientProfile.getActivePresetIndex(
                    mCachedDevice.getDevice());
            if (activePresetIndex != BluetoothHapClient.PRESET_INDEX_UNAVAILABLE) {
                mPreference.setValue(Integer.toString(activePresetIndex));
                mPreference.setSummary(mPreference.getEntry());
            } else {
                mPreference.setSummary(null);
            }
        }
    }
@@ -273,7 +276,8 @@ public class BluetoothDetailsHearingAidsPresetsController extends
            return;
        }
        List<BluetoothHapPresetInfo> infoList = mHapClientProfile.getAllPresetInfo(
                mCachedDevice.getDevice());
                mCachedDevice.getDevice()).stream().filter(
                BluetoothHapPresetInfo::isAvailable).toList();
        CharSequence[] presetNames = new CharSequence[infoList.size()];
        CharSequence[] presetIndexes = new CharSequence[infoList.size()];
        for (int i = 0; i < infoList.size(); i++) {
+27 −4
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.bluetooth.BluetoothHapPresetInfo;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceCategory;

import com.android.settings.R;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
@@ -215,11 +216,13 @@ public class BluetoothDetailsHearingAidsPresetsControllerTest extends

        assertThat(mController.getPreference()).isNotNull();
        assertThat(mController.getPreference().isEnabled()).isFalse();
        assertThat(String.valueOf(mController.getPreference().getSummary())).isEqualTo(
                mContext.getString(R.string.bluetooth_hearing_aids_presets_empty_list_message));
    }

    @Test
    public void refresh_validPresetInfo_preferenceEnabled() {
        BluetoothHapPresetInfo info = getTestPresetInfo();
        BluetoothHapPresetInfo info = getTestPresetInfo(true);
        when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));

        mController.refresh();
@@ -230,7 +233,7 @@ public class BluetoothDetailsHearingAidsPresetsControllerTest extends

    @Test
    public void refresh_invalidActivePresetIndex_summaryIsNull() {
        BluetoothHapPresetInfo info = getTestPresetInfo();
        BluetoothHapPresetInfo info = getTestPresetInfo(true);
        when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));
        when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(PRESET_INDEX_UNAVAILABLE);

@@ -242,7 +245,7 @@ public class BluetoothDetailsHearingAidsPresetsControllerTest extends

    @Test
    public void refresh_validActivePresetIndex_summaryIsNotNull() {
        BluetoothHapPresetInfo info = getTestPresetInfo();
        BluetoothHapPresetInfo info = getTestPresetInfo(true);
        when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));
        when(mHapClientProfile.getActivePresetIndex(mDevice)).thenReturn(TEST_PRESET_INDEX);

@@ -262,10 +265,30 @@ public class BluetoothDetailsHearingAidsPresetsControllerTest extends
        verify(mHapClientProfile).selectPreset(mDevice, TEST_PRESET_INDEX);
    }

    private BluetoothHapPresetInfo getTestPresetInfo() {
    @Test
    public void loadAllPresetInfo_unavailablePreset_notAddedToEntries() {
        BluetoothHapPresetInfo info = getTestPresetInfo(false);
        when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));

        mController.refresh();

        assertThat(mController.getPreference().getEntries().length).isEqualTo(0);
    }

    @Test
    public void loadAllPresetInfo_availablePreset_addedToEntries() {
        BluetoothHapPresetInfo info = getTestPresetInfo(true);
        when(mHapClientProfile.getAllPresetInfo(mDevice)).thenReturn(List.of(info));

        mController.refresh();

        assertThat(mController.getPreference().getEntries().length).isEqualTo(1);
    }
    private BluetoothHapPresetInfo getTestPresetInfo(boolean available) {
        BluetoothHapPresetInfo info = mock(BluetoothHapPresetInfo.class);
        when(info.getName()).thenReturn(TEST_PRESET_NAME);
        when(info.getIndex()).thenReturn(TEST_PRESET_INDEX);
        when(info.isAvailable()).thenReturn(available);
        return info;
    }