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

Commit 416b5bd6 authored by Angela Wang's avatar Angela Wang
Browse files

Unifies constants accross hearing aid related profiles (2/2)

Hearing aid constants defined differently across different hearing aid
related profiles. For hearing aid device mode, HearingAidProfile and
HapClientProfile have different values for mode definition and there is also
a new BANDED hearing aid type in HapClientProfile spec. For hearing aid
device side, HearingAidProfile has only 2 kinds of side which is left
and right whereas BLE hearing aid can retrieve 27 different kinds of
audio location.

We therefore introduce a new class HearingAidInfo for mapping these
different constants across these profiles into a single unified set of
constants.

Bug: 253192350
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AccessibilityHearingAidPreferenceControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=HearingAidPairingDialogFragmentTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=HearingAidUtilsTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=BluetoothDetailsPairOtherControllerTest
Test: make RunSettingsRoboTests ROBOTEST_FILTER=AvailableMediaDeviceGroupControllerTest
Change-Id: Id14928dbc051fcf76fe0d66b43aefefb1b5f7baf
parent a6a7e029
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
@@ -170,10 +171,13 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
        }

        final int side = device.getDeviceSide();
        if (side == HearingAidProfile.DeviceSide.SIDE_LEFT) {
        if (side == HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT) {
            return mContext.getString(
                    R.string.accessibility_hearingaid_left_and_right_side_device_summary, name);
        } else if (side == HearingAidInfo.DeviceSide.SIDE_LEFT) {
            return mContext.getString(
                    R.string.accessibility_hearingaid_left_side_device_summary, name);
        } else if (side == HearingAidProfile.DeviceSide.SIDE_RIGHT) {
        } else if (side == HearingAidInfo.DeviceSide.SIDE_RIGHT) {
            return mContext.getString(
                    R.string.accessibility_hearingaid_right_side_device_summary, name);
        }
+3 −3
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import androidx.fragment.app.FragmentManager;

import com.android.settings.bluetooth.HearingAidPairingDialogFragment;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;

/** Provides utility methods related hearing aids. */
public final class HearingAidUtils {
@@ -41,7 +41,7 @@ public final class HearingAidUtils {
    public static void launchHearingAidPairingDialog(FragmentManager fragmentManager,
            @NonNull CachedBluetoothDevice device) {
        if (device.isConnectedAshaHearingAidDevice()
                && device.getDeviceMode() == HearingAidProfile.DeviceMode.MODE_BINAURAL
                && device.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL
                && device.getSubDevice() == null) {
            launchHearingAidPairingDialogInternal(fragmentManager, device);
        }
@@ -49,7 +49,7 @@ public final class HearingAidUtils {

    private static void launchHearingAidPairingDialogInternal(FragmentManager fragmentManager,
            @NonNull CachedBluetoothDevice device) {
        if (device.getDeviceSide() == HearingAidProfile.DeviceSide.SIDE_INVALID) {
        if (device.getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_INVALID) {
            Log.w(TAG, "Can not launch hearing aid pairing dialog for invalid side");
            return;
        }
+3 −3
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import com.android.settings.R;
import com.android.settings.applications.SpacePreference;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.ButtonPreference;

@@ -78,7 +78,7 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl

    private void updateButtonPreferenceTitle(ButtonPreference preference) {
        final int side = mCachedDevice.getDeviceSide();
        final int stringRes = (side == HearingAidProfile.DeviceSide.SIDE_LEFT)
        final int stringRes = (side == HearingAidInfo.DeviceSide.SIDE_LEFT)
                ? R.string.bluetooth_pair_right_ear_button
                : R.string.bluetooth_pair_left_ear_button;

@@ -103,7 +103,7 @@ public class BluetoothDetailsPairOtherController extends BluetoothDetailsControl
    }

    private boolean isBinauralMode(CachedBluetoothDevice cachedDevice) {
        return cachedDevice.getDeviceMode() == HearingAidProfile.DeviceMode.MODE_BINAURAL;
        return cachedDevice.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL;
    }

    private boolean isOnlyOneSideConnected(CachedBluetoothDevice cachedDevice) {
+3 −3
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.LocalBluetoothManager;

/**
@@ -95,10 +95,10 @@ public class HearingAidPairingDialogFragment extends InstrumentedDialogFragment
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        final int deviceSide = mDevice.getDeviceSide();
        final int titleId = R.string.bluetooth_pair_other_ear_dialog_title;
        final int messageId = (deviceSide == HearingAidProfile.DeviceSide.SIDE_LEFT)
        final int messageId = (deviceSide == HearingAidInfo.DeviceSide.SIDE_LEFT)
                        ? R.string.bluetooth_pair_other_ear_dialog_left_ear_message
                        : R.string.bluetooth_pair_other_ear_dialog_right_ear_message;
        final int pairBtnId = (deviceSide == HearingAidProfile.DeviceSide.SIDE_LEFT)
        final int pairBtnId = (deviceSide == HearingAidInfo.DeviceSide.SIDE_LEFT)
                        ? R.string.bluetooth_pair_other_ear_dialog_right_ear_positive_button
                        : R.string.bluetooth_pair_other_ear_dialog_left_ear_positive_button;

+44 −11
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HapClientProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
@@ -124,7 +125,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
    @Test
    public void getSummary_connectedAshaHearingAidRightSide_connectedRightSideSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidProfile.DeviceSide.SIDE_RIGHT);
                HearingAidInfo.DeviceSide.SIDE_RIGHT);
        when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());

        mPreferenceController.onStart();
@@ -139,7 +140,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
    @Test
    public void getSummary_connectedAshaHearingAidBothSide_connectedBothSideSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidProfile.DeviceSide.SIDE_LEFT);
                HearingAidInfo.DeviceSide.SIDE_LEFT);
        when(mCachedSubBluetoothDevice.isConnected()).thenReturn(true);
        when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mCachedSubBluetoothDevice);
        when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());
@@ -154,9 +155,9 @@ public class AccessibilityHearingAidPreferenceControllerTest {
    }

    @Test
    public void getSummary_connectedLeAudioHearingAidOneSide_connectedOneSideSummary() {
    public void getSummary_connectedLeAudioHearingAidLeftSide_connectedLeftSideSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidProfile.DeviceSide.SIDE_INVALID);
                HearingAidInfo.DeviceSide.SIDE_LEFT);
        when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(new HashSet<>());
        when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());

@@ -166,7 +167,39 @@ public class AccessibilityHearingAidPreferenceControllerTest {
        sendIntent(intent);

        assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
                "TEST_HEARING_AID_BT_DEVICE_NAME active")).isTrue();
                "TEST_HEARING_AID_BT_DEVICE_NAME, left only")).isTrue();
    }

    @Test
    public void getSummary_connectedLeAudioHearingAidRightSide_connectedRightSideSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidInfo.DeviceSide.SIDE_RIGHT);
        when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(new HashSet<>());
        when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());

        mPreferenceController.onStart();
        Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
        intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHapClient.STATE_CONNECTED);
        sendIntent(intent);

        assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
                "TEST_HEARING_AID_BT_DEVICE_NAME, right only")).isTrue();
    }

    @Test
    public void getSummary_connectedLeAudioHearingAidLeftAndRightSide_connectedSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidInfo.DeviceSide.SIDE_LEFT_AND_RIGHT);
        when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(new HashSet<>());
        when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());

        mPreferenceController.onStart();
        Intent intent = new Intent(BluetoothHapClient.ACTION_HAP_CONNECTION_STATE_CHANGED);
        intent.putExtra(BluetoothHearingAid.EXTRA_STATE, BluetoothHapClient.STATE_CONNECTED);
        sendIntent(intent);

        assertThat(mHearingAidPreference.getSummary().toString().contentEquals(
                "TEST_HEARING_AID_BT_DEVICE_NAME, left and right")).isTrue();
    }

    @Test
@@ -187,7 +220,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
    @Test
    public void getSummary_connectedMultipleHearingAids_connectedMultipleDevicesSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidProfile.DeviceSide.SIDE_LEFT);
                HearingAidInfo.DeviceSide.SIDE_LEFT);
        when(mHearingAidProfile.getConnectedDevices()).thenReturn(
                generateMultipleHearingAidDeviceList());

@@ -282,9 +315,9 @@ public class AccessibilityHearingAidPreferenceControllerTest {
        final FragmentActivity mActivity = Robolectric.setupActivity(FragmentActivity.class);
        when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
        when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
                HearingAidProfile.DeviceMode.MODE_BINAURAL);
                HearingAidInfo.DeviceMode.MODE_BINAURAL);
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidProfile.DeviceSide.SIDE_LEFT);
                HearingAidInfo.DeviceSide.SIDE_LEFT);
        mPreferenceController.setFragmentManager(mActivity.getSupportFragmentManager());

        mPreferenceController.onActiveDeviceChanged(mCachedBluetoothDevice,
@@ -297,7 +330,7 @@ public class AccessibilityHearingAidPreferenceControllerTest {
    @Test
    public void onServiceConnected_onHearingAidProfileConnected_updateSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidProfile.DeviceSide.SIDE_LEFT);
                HearingAidInfo.DeviceSide.SIDE_LEFT);
        when(mHearingAidProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());

        mPreferenceController.onStart();
@@ -310,14 +343,14 @@ public class AccessibilityHearingAidPreferenceControllerTest {
    @Test
    public void onServiceConnected_onHapClientProfileConnected_updateSummary() {
        when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
                HearingAidProfile.DeviceSide.SIDE_INVALID);
                HearingAidInfo.DeviceSide.SIDE_RIGHT);
        when(mHapClientProfile.getConnectedDevices()).thenReturn(generateHearingAidDeviceList());

        mPreferenceController.onStart();
        mPreferenceController.onServiceConnected();

        assertThat(mHearingAidPreference.getSummary().toString()).isEqualTo(
                "TEST_HEARING_AID_BT_DEVICE_NAME active");
                "TEST_HEARING_AID_BT_DEVICE_NAME, right only");
    }

    private void setupEnvironment() {
Loading