Merge "Redirect user to original pairing page from pair dialog" into main
This commit is contained in:
@@ -184,7 +184,8 @@ public class AccessibilityHearingAidPreferenceController extends BasePreferenceC
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
|
if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(
|
||||||
|
mFragmentManager, activeDevice, getMetricsCategory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,8 @@ public class AvailableHearingDevicePreferenceController extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
|
if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice,
|
||||||
|
getMetricsCategory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ public final class HearingAidUtils {
|
|||||||
*
|
*
|
||||||
* @param fragmentManager The {@link FragmentManager} used to show dialog fragment
|
* @param fragmentManager The {@link FragmentManager} used to show dialog fragment
|
||||||
* @param device The {@link CachedBluetoothDevice} need to be hearing aid device
|
* @param device The {@link CachedBluetoothDevice} need to be hearing aid device
|
||||||
|
* @param launchPage The page id where the dialog is launched
|
||||||
*/
|
*/
|
||||||
public static void launchHearingAidPairingDialog(FragmentManager fragmentManager,
|
public static void launchHearingAidPairingDialog(FragmentManager fragmentManager,
|
||||||
@NonNull CachedBluetoothDevice device) {
|
@NonNull CachedBluetoothDevice device, int launchPage) {
|
||||||
// No need to show the pair another ear dialog if the device supports and enables CSIP.
|
// No need to show the pair another ear dialog if the device supports and enables CSIP.
|
||||||
// CSIP will pair other devices in the same set automatically.
|
// CSIP will pair other devices in the same set automatically.
|
||||||
if (isCsipSupportedAndEnabled(device)) {
|
if (isCsipSupportedAndEnabled(device)) {
|
||||||
@@ -49,18 +50,18 @@ public final class HearingAidUtils {
|
|||||||
if (device.isConnectedAshaHearingAidDevice()
|
if (device.isConnectedAshaHearingAidDevice()
|
||||||
&& device.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL
|
&& device.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL
|
||||||
&& device.getSubDevice() == null) {
|
&& device.getSubDevice() == null) {
|
||||||
launchHearingAidPairingDialogInternal(fragmentManager, device);
|
launchHearingAidPairingDialogInternal(fragmentManager, device, launchPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void launchHearingAidPairingDialogInternal(FragmentManager fragmentManager,
|
private static void launchHearingAidPairingDialogInternal(FragmentManager fragmentManager,
|
||||||
@NonNull CachedBluetoothDevice device) {
|
@NonNull CachedBluetoothDevice device, int launchPage) {
|
||||||
if (device.getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_INVALID) {
|
if (device.getDeviceSide() == HearingAidInfo.DeviceSide.SIDE_INVALID) {
|
||||||
Log.w(TAG, "Can not launch hearing aid pairing dialog for invalid side");
|
Log.w(TAG, "Can not launch hearing aid pairing dialog for invalid side");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HearingAidPairingDialogFragment.newInstance(device.getAddress()).show(fragmentManager,
|
HearingAidPairingDialogFragment.newInstance(device.getAddress(), launchPage)
|
||||||
HearingAidPairingDialogFragment.TAG);
|
.show(fragmentManager, HearingAidPairingDialogFragment.TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isCsipSupportedAndEnabled(@NonNull CachedBluetoothDevice device) {
|
private static boolean isCsipSupportedAndEnabled(@NonNull CachedBluetoothDevice device) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.accessibility.HearingDevicePairingDetail;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
@@ -41,6 +42,8 @@ public class HearingAidPairingDialogFragment extends InstrumentedDialogFragment
|
|||||||
CachedBluetoothDevice.Callback {
|
CachedBluetoothDevice.Callback {
|
||||||
public static final String TAG = "HearingAidPairingDialogFragment";
|
public static final String TAG = "HearingAidPairingDialogFragment";
|
||||||
private static final String KEY_DEVICE_ADDRESS = "device_address";
|
private static final String KEY_DEVICE_ADDRESS = "device_address";
|
||||||
|
private static final String KEY_LAUNCH_PAGE = "launch_page";
|
||||||
|
|
||||||
private LocalBluetoothManager mLocalBluetoothManager;
|
private LocalBluetoothManager mLocalBluetoothManager;
|
||||||
private CachedBluetoothDevice mDevice;
|
private CachedBluetoothDevice mDevice;
|
||||||
|
|
||||||
@@ -50,11 +53,17 @@ public class HearingAidPairingDialogFragment extends InstrumentedDialogFragment
|
|||||||
*
|
*
|
||||||
* @param deviceAddress The remote Bluetooth device address, that needs to be a hearing aid
|
* @param deviceAddress The remote Bluetooth device address, that needs to be a hearing aid
|
||||||
* device.
|
* device.
|
||||||
|
* @param launchPage The id of the page where this dialog launch from. Should be one of
|
||||||
|
* {@link SettingsEnums#ACCESSIBILITY},
|
||||||
|
* {@link SettingsEnums#ACCESSIBILITY_HEARING_AID_SETTINGS}, or
|
||||||
|
* {@link SettingsEnums#SETTINGS_CONNECTED_DEVICE_CATEGORY}
|
||||||
* @return a DialogFragment
|
* @return a DialogFragment
|
||||||
*/
|
*/
|
||||||
public static HearingAidPairingDialogFragment newInstance(String deviceAddress) {
|
public static HearingAidPairingDialogFragment newInstance(String deviceAddress,
|
||||||
|
int launchPage) {
|
||||||
Bundle args = new Bundle(1);
|
Bundle args = new Bundle(1);
|
||||||
args.putString(KEY_DEVICE_ADDRESS, deviceAddress);
|
args.putString(KEY_DEVICE_ADDRESS, deviceAddress);
|
||||||
|
args.putInt(KEY_LAUNCH_PAGE, launchPage);
|
||||||
final HearingAidPairingDialogFragment fragment = new HearingAidPairingDialogFragment();
|
final HearingAidPairingDialogFragment fragment = new HearingAidPairingDialogFragment();
|
||||||
fragment.setArguments(args);
|
fragment.setArguments(args);
|
||||||
return fragment;
|
return fragment;
|
||||||
@@ -111,8 +120,14 @@ public class HearingAidPairingDialogFragment extends InstrumentedDialogFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void positiveButtonListener() {
|
private void positiveButtonListener() {
|
||||||
|
final int launchPage = getArguments().getInt(KEY_LAUNCH_PAGE);
|
||||||
|
final boolean launchFromA11y = (launchPage == SettingsEnums.ACCESSIBILITY)
|
||||||
|
|| (launchPage == SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS);
|
||||||
|
final String destination = launchFromA11y
|
||||||
|
? HearingDevicePairingDetail.class.getName()
|
||||||
|
: BluetoothPairingDetail.class.getName();
|
||||||
new SubSettingLauncher(getActivity())
|
new SubSettingLauncher(getActivity())
|
||||||
.setDestination(BluetoothPairingDetail.class.getName())
|
.setDestination(destination)
|
||||||
.setSourceMetricsCategory(getMetricsCategory())
|
.setSourceMetricsCategory(getMetricsCategory())
|
||||||
.launch();
|
.launch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,8 @@ public class AvailableMediaDeviceGroupController extends BasePreferenceControlle
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
|
if (bluetoothProfile == BluetoothProfile.HEARING_AID) {
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, activeDevice,
|
||||||
|
getMetricsCategory());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class HearingAidPairingDialogFragmentTest {
|
|||||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||||
|
|
||||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||||
|
private static final int TEST_LAUNCH_PAGE = SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY;
|
||||||
|
|
||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
@Mock
|
@Mock
|
||||||
@@ -99,13 +100,7 @@ public class HearingAidPairingDialogFragmentTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
setupEnvironment();
|
setupEnvironment();
|
||||||
mFragment = spy(HearingAidPairingDialogFragment.newInstance(TEST_DEVICE_ADDRESS));
|
setupDialog(TEST_LAUNCH_PAGE);
|
||||||
mActivity = (FragmentActivity) ActivityControllerWrapper.setup(
|
|
||||||
Robolectric.buildActivity(FragmentActivity.class)).get();
|
|
||||||
mFragmentManager = mActivity.getSupportFragmentManager();
|
|
||||||
when(mFragment.getActivity()).thenReturn(mActivity);
|
|
||||||
doReturn(mFragmentManager).when(mFragment).getParentFragmentManager();
|
|
||||||
mFragment.onAttach(mContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -122,7 +117,8 @@ public class HearingAidPairingDialogFragmentTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dialogPositiveButtonClick_intentToExpectedClass() {
|
public void dialogPositiveButtonClick_intentToBluetoothPairingPage() {
|
||||||
|
setupDialog(SettingsEnums.SETTINGS_CONNECTED_DEVICE_CATEGORY);
|
||||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
@@ -133,6 +129,19 @@ public class HearingAidPairingDialogFragmentTest {
|
|||||||
.isEqualTo(BluetoothPairingDetail.class.getName());
|
.isEqualTo(BluetoothPairingDetail.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dialogPositiveButtonClick_intentToA11yPairingPage() {
|
||||||
|
setupDialog(SettingsEnums.ACCESSIBILITY);
|
||||||
|
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||||
|
dialog.show();
|
||||||
|
|
||||||
|
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
|
||||||
|
|
||||||
|
final Intent intent = shadowOf(mActivity).getNextStartedActivity();
|
||||||
|
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||||
|
.isEqualTo(HearingDevicePairingDetail.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dialogNegativeButtonClick_dismissDialog() {
|
public void dialogNegativeButtonClick_dismissDialog() {
|
||||||
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
final AlertDialog dialog = (AlertDialog) mFragment.onCreateDialog(Bundle.EMPTY);
|
||||||
@@ -159,6 +168,17 @@ public class HearingAidPairingDialogFragmentTest {
|
|||||||
verify(mFragment).dismiss();
|
verify(mFragment).dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupDialog(int launchPage) {
|
||||||
|
mFragment = spy(
|
||||||
|
HearingAidPairingDialogFragment.newInstance(TEST_DEVICE_ADDRESS, launchPage));
|
||||||
|
mActivity = (FragmentActivity) ActivityControllerWrapper.setup(
|
||||||
|
Robolectric.buildActivity(FragmentActivity.class)).get();
|
||||||
|
mFragmentManager = mActivity.getSupportFragmentManager();
|
||||||
|
when(mFragment.getActivity()).thenReturn(mActivity);
|
||||||
|
doReturn(mFragmentManager).when(mFragment).getParentFragmentManager();
|
||||||
|
mFragment.onAttach(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
private void setupEnvironment() {
|
private void setupEnvironment() {
|
||||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager;
|
||||||
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class HearingAidUtilsTest {
|
|||||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
private static final String TEST_DEVICE_ADDRESS = "00:A1:A1:A1:A1:A1";
|
||||||
|
private static final int TEST_LAUNCH_PAGE = 1;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||||
@@ -103,7 +104,8 @@ public class HearingAidUtilsTest {
|
|||||||
public void launchHearingAidPairingDialog_deviceIsNotConnectedAshaHearingAid_noDialog() {
|
public void launchHearingAidPairingDialog_deviceIsNotConnectedAshaHearingAid_noDialog() {
|
||||||
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
|
when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(false);
|
||||||
|
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
|
||||||
|
TEST_LAUNCH_PAGE);
|
||||||
|
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
@@ -116,7 +118,8 @@ public class HearingAidUtilsTest {
|
|||||||
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
|
when(mCachedBluetoothDevice.getDeviceMode()).thenReturn(
|
||||||
HearingAidInfo.DeviceMode.MODE_MONAURAL);
|
HearingAidInfo.DeviceMode.MODE_MONAURAL);
|
||||||
|
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
|
||||||
|
TEST_LAUNCH_PAGE);
|
||||||
|
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
@@ -130,7 +133,8 @@ public class HearingAidUtilsTest {
|
|||||||
HearingAidInfo.DeviceMode.MODE_BINAURAL);
|
HearingAidInfo.DeviceMode.MODE_BINAURAL);
|
||||||
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
|
when(mCachedBluetoothDevice.getSubDevice()).thenReturn(mSubCachedBluetoothDevice);
|
||||||
|
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
|
||||||
|
TEST_LAUNCH_PAGE);
|
||||||
|
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
@@ -145,7 +149,8 @@ public class HearingAidUtilsTest {
|
|||||||
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||||
HearingAidInfo.DeviceSide.SIDE_INVALID);
|
HearingAidInfo.DeviceSide.SIDE_INVALID);
|
||||||
|
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
|
||||||
|
TEST_LAUNCH_PAGE);
|
||||||
|
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
@@ -162,7 +167,8 @@ public class HearingAidUtilsTest {
|
|||||||
makeDeviceSupportCsip();
|
makeDeviceSupportCsip();
|
||||||
makeDeviceEnableCsip(true);
|
makeDeviceEnableCsip(true);
|
||||||
|
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
|
||||||
|
TEST_LAUNCH_PAGE);
|
||||||
|
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
@@ -179,7 +185,8 @@ public class HearingAidUtilsTest {
|
|||||||
makeDeviceSupportCsip();
|
makeDeviceSupportCsip();
|
||||||
makeDeviceEnableCsip(false);
|
makeDeviceEnableCsip(false);
|
||||||
|
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
|
||||||
|
TEST_LAUNCH_PAGE);
|
||||||
|
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
@@ -194,7 +201,8 @@ public class HearingAidUtilsTest {
|
|||||||
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
when(mCachedBluetoothDevice.getDeviceSide()).thenReturn(
|
||||||
HearingAidInfo.DeviceSide.SIDE_LEFT);
|
HearingAidInfo.DeviceSide.SIDE_LEFT);
|
||||||
|
|
||||||
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice);
|
HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice,
|
||||||
|
TEST_LAUNCH_PAGE);
|
||||||
|
|
||||||
shadowMainLooper().idle();
|
shadowMainLooper().idle();
|
||||||
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
|||||||
Reference in New Issue
Block a user