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
This commit is contained in:
Angela Wang
2022-10-13 09:27:37 +00:00
parent a6a7e029d7
commit 416b5bd63f
9 changed files with 79 additions and 42 deletions

View File

@@ -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() {

View File

@@ -48,7 +48,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
@@ -104,7 +104,7 @@ public class HearingAidPairingDialogFragmentTest {
@Test
public void newInstance_deviceSideRight_argumentSideRight() {
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_RIGHT);
HearingAidInfo.DeviceSide.SIDE_RIGHT);
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
dialog.show();

View File

@@ -36,7 +36,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
@@ -99,7 +99,7 @@ public class HearingAidUtilsTest {
public void launchHearingAidPairingDialog_deviceIsMonauralMode_noDialog() {
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_MONAURAL);
HearingAidInfo.DeviceMode.MODE_MONAURAL);
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
@@ -111,7 +111,7 @@ public class HearingAidUtilsTest {
public void launchHearingAidPairingDialog_deviceHasSubDevice_noDialog() {
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL);
HearingAidInfo.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
@@ -124,9 +124,9 @@ public class HearingAidUtilsTest {
public void launchHearingAidPairingDialog_deviceIsInvalidSide_noDialog() {
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
HearingAidProfile.DeviceMode.MODE_BINAURAL);
HearingAidInfo.DeviceMode.MODE_BINAURAL);
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
HearingAidProfile.DeviceSide.SIDE_INVALID);
HearingAidInfo.DeviceSide.SIDE_INVALID);
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
@@ -138,9 +138,9 @@ public class HearingAidUtilsTest {
public void launchHearingAidPairingDialog_dialogShown() {
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);
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);

View File

@@ -23,7 +23,7 @@ import static org.mockito.Mockito.when;
import com.android.settings.R;
import com.android.settings.applications.SpacePreference;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.widget.ButtonPreference;
import org.junit.Rule;
@@ -62,7 +62,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test
public void init_leftSideDevice_rightSideButtonTitle() {
when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidProfile.DeviceSide.SIDE_LEFT);
when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidInfo.DeviceSide.SIDE_LEFT);
mController.init(mScreen);
@@ -72,7 +72,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test
public void init_rightSideDevice_leftSideButtonTitle() {
when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidProfile.DeviceSide.SIDE_RIGHT);
when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidInfo.DeviceSide.SIDE_RIGHT);
mController.init(mScreen);
@@ -100,7 +100,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test
public void isAvailable_isConnectedAshaHearingAidDevice_isMonaural_notAvailable() {
when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_MONAURAL);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_MONAURAL);
assertThat(mController.isAvailable()).isFalse();
}
@@ -108,7 +108,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test
public void isAvailable_subDeviceIsConnectedAshaHearingAidDevice_notAvailable() {
when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
when(mSubCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice);
@@ -118,7 +118,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test
public void isAvailable_subDeviceIsNotConnectedAshaHearingAidDevice_available() {
when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
when(mSubCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
when(mCachedDevice.getSubDevice()).thenReturn(mSubCachedDevice);
@@ -128,7 +128,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test
public void isAvailable_subDeviceNotExist_available() {
when(mCachedDevice.isConnectedAshaHearingAidDevice()).thenReturn(true);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidProfile.DeviceMode.MODE_BINAURAL);
when(mCachedDevice.getDeviceMode()).thenReturn(HearingAidInfo.DeviceMode.MODE_BINAURAL);
when(mCachedDevice.getSubDevice()).thenReturn(null);
assertThat(mController.isAvailable()).isTrue();
@@ -136,7 +136,7 @@ public class BluetoothDetailsPairOtherControllerTest extends BluetoothDetailsCon
@Test
public void refresh_leftSideDevice_leftSideButtonTitle() {
when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidProfile.DeviceSide.SIDE_RIGHT);
when(mCachedDevice.getDeviceSide()).thenReturn(HearingAidInfo.DeviceSide.SIDE_RIGHT);
mController.init(mScreen);
mController.refresh();

View File

@@ -52,7 +52,7 @@ import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothEventManager;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager;
import com.android.settingslib.bluetooth.HearingAidProfile;
import com.android.settingslib.bluetooth.HearingAidInfo;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
@@ -246,9 +246,9 @@ public class AvailableMediaDeviceGroupControllerTest {
public void onActiveDeviceChanged_hearingAidProfile_launchHearingAidPairingDialog() {
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);
mAvailableMediaDeviceGroupController.init(mDashboardFragment);
mAvailableMediaDeviceGroupController.onActiveDeviceChanged(mCachedBluetoothDevice,