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

This commit is contained in:
Angela Wang
2022-11-28 14:26:43 +00:00
committed by Android (Google) Code Review
9 changed files with 79 additions and 42 deletions

View File

@@ -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);
}

View File

@@ -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;
}

View File

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

View File

@@ -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;

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,