Merge "Redirects to connected devices page in a11y pairing page" into main
This commit is contained in:
@@ -16,27 +16,19 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.bluetooth.BluetoothPairingDetail;
|
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
/** Preference controller for all bluetooth device preference. */
|
/** Preference controller for all bluetooth device preference. */
|
||||||
public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController implements
|
public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController {
|
||||||
PreferenceManager.OnActivityResultListener {
|
|
||||||
|
|
||||||
private static final int REQUEST_CODE_BONDED_DEVICE = 270;
|
|
||||||
private DashboardFragment mFragment;
|
private DashboardFragment mFragment;
|
||||||
|
|
||||||
public ViewAllBluetoothDevicesPreferenceController(Context context, String preferenceKey) {
|
public ViewAllBluetoothDevicesPreferenceController(Context context, String preferenceKey) {
|
||||||
@@ -60,29 +52,18 @@ public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceC
|
|||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||||
launchBluetoothPairingDetail();
|
launchConnectedDevicePage();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
// If back from BONDED device page, then no need to show scan result again.
|
|
||||||
// Finish the fragment.
|
|
||||||
if (requestCode == REQUEST_CODE_BONDED_DEVICE && resultCode == RESULT_OK) {
|
|
||||||
mFragment.finish();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void launchBluetoothPairingDetail() {
|
void launchConnectedDevicePage() {
|
||||||
new SubSettingLauncher(mContext)
|
new SubSettingLauncher(mContext)
|
||||||
.setDestination(BluetoothPairingDetail.class.getName())
|
.setDestination(ConnectedDeviceDashboardFragment.class.getName())
|
||||||
.setSourceMetricsCategory(mFragment.getMetricsCategory())
|
.setSourceMetricsCategory(mFragment.getMetricsCategory())
|
||||||
.setResultListener(mFragment, REQUEST_CODE_BONDED_DEVICE)
|
|
||||||
.launch();
|
.launch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
import static android.app.Activity.RESULT_OK;
|
|
||||||
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -94,7 +93,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
|
public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
|
||||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||||
// If one device is connected(bonded), then close this fragment.
|
// If one device is connected(bonded), then close this fragment.
|
||||||
setResult(RESULT_OK);
|
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
} else if (bondState == BluetoothDevice.BOND_BONDING) {
|
} else if (bondState == BluetoothDevice.BOND_BONDING) {
|
||||||
@@ -126,7 +124,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere
|
|||||||
if (cachedDevice != null && cachedDevice.isConnected()) {
|
if (cachedDevice != null && cachedDevice.isConnected()) {
|
||||||
final BluetoothDevice device = cachedDevice.getDevice();
|
final BluetoothDevice device = cachedDevice.getDevice();
|
||||||
if (device != null && mSelectedList.contains(device)) {
|
if (device != null && mSelectedList.contains(device)) {
|
||||||
setResult(RESULT_OK);
|
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
onDeviceDeleted(cachedDevice);
|
onDeviceDeleted(cachedDevice);
|
||||||
|
@@ -74,13 +74,13 @@ public class ViewAllBluetoothDevicesPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handlePreferenceTreeClick_expectedPreference_launchBluetoothPairingDetail() {
|
public void handlePreferenceTreeClick_expectedPreference_launchConnectedDevicePage() {
|
||||||
doNothing().when(mController).launchBluetoothPairingDetail();
|
doNothing().when(mController).launchConnectedDevicePage();
|
||||||
mPreference.setKey(TEST_KEY);
|
mPreference.setKey(TEST_KEY);
|
||||||
|
|
||||||
boolean status = mController.handlePreferenceTreeClick(mPreference);
|
boolean status = mController.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
verify(mController).launchBluetoothPairingDetail();
|
verify(mController).launchConnectedDevicePage();
|
||||||
assertThat(status).isTrue();
|
assertThat(status).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user