Loading src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceController.java +6 −25 Original line number Diff line number Diff line Loading @@ -16,27 +16,19 @@ package com.android.settings.accessibility; import static android.app.Activity.RESULT_OK; import android.content.Context; import android.content.Intent; import android.preference.PreferenceManager; import android.text.TextUtils; import androidx.annotation.VisibleForTesting; 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.SubSettingLauncher; import com.android.settings.dashboard.DashboardFragment; import androidx.annotation.VisibleForTesting; /** Preference controller for all bluetooth device preference. */ public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController implements PreferenceManager.OnActivityResultListener { private static final int REQUEST_CODE_BONDED_DEVICE = 270; public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController { private DashboardFragment mFragment; public ViewAllBluetoothDevicesPreferenceController(Context context, String preferenceKey) { Loading @@ -60,29 +52,18 @@ public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceC @Override public boolean handlePreferenceTreeClick(Preference preference) { if (TextUtils.equals(preference.getKey(), getPreferenceKey())) { launchBluetoothPairingDetail(); launchConnectedDevicePage(); return true; } 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 void launchBluetoothPairingDetail() { void launchConnectedDevicePage() { new SubSettingLauncher(mContext) .setDestination(BluetoothPairingDetail.class.getName()) .setDestination(ConnectedDeviceDashboardFragment.class.getName()) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .setResultListener(mFragment, REQUEST_CODE_BONDED_DEVICE) .launch(); } } src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBase.java +0 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.settings.bluetooth; import static android.app.Activity.RESULT_OK; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; import android.bluetooth.BluetoothAdapter; Loading Loading @@ -94,7 +93,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { if (bondState == BluetoothDevice.BOND_BONDED) { // If one device is connected(bonded), then close this fragment. setResult(RESULT_OK); finish(); return; } else if (bondState == BluetoothDevice.BOND_BONDING) { Loading Loading @@ -126,7 +124,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere if (cachedDevice != null && cachedDevice.isConnected()) { final BluetoothDevice device = cachedDevice.getDevice(); if (device != null && mSelectedList.contains(device)) { setResult(RESULT_OK); finish(); } else { onDeviceDeleted(cachedDevice); Loading tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -74,13 +74,13 @@ public class ViewAllBluetoothDevicesPreferenceControllerTest { } @Test public void handlePreferenceTreeClick_expectedPreference_launchBluetoothPairingDetail() { doNothing().when(mController).launchBluetoothPairingDetail(); public void handlePreferenceTreeClick_expectedPreference_launchConnectedDevicePage() { doNothing().when(mController).launchConnectedDevicePage(); mPreference.setKey(TEST_KEY); boolean status = mController.handlePreferenceTreeClick(mPreference); verify(mController).launchBluetoothPairingDetail(); verify(mController).launchConnectedDevicePage(); assertThat(status).isTrue(); } } Loading
src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceController.java +6 −25 Original line number Diff line number Diff line Loading @@ -16,27 +16,19 @@ package com.android.settings.accessibility; import static android.app.Activity.RESULT_OK; import android.content.Context; import android.content.Intent; import android.preference.PreferenceManager; import android.text.TextUtils; import androidx.annotation.VisibleForTesting; 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.SubSettingLauncher; import com.android.settings.dashboard.DashboardFragment; import androidx.annotation.VisibleForTesting; /** Preference controller for all bluetooth device preference. */ public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController implements PreferenceManager.OnActivityResultListener { private static final int REQUEST_CODE_BONDED_DEVICE = 270; public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceController { private DashboardFragment mFragment; public ViewAllBluetoothDevicesPreferenceController(Context context, String preferenceKey) { Loading @@ -60,29 +52,18 @@ public class ViewAllBluetoothDevicesPreferenceController extends BasePreferenceC @Override public boolean handlePreferenceTreeClick(Preference preference) { if (TextUtils.equals(preference.getKey(), getPreferenceKey())) { launchBluetoothPairingDetail(); launchConnectedDevicePage(); return true; } 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 void launchBluetoothPairingDetail() { void launchConnectedDevicePage() { new SubSettingLauncher(mContext) .setDestination(BluetoothPairingDetail.class.getName()) .setDestination(ConnectedDeviceDashboardFragment.class.getName()) .setSourceMetricsCategory(mFragment.getMetricsCategory()) .setResultListener(mFragment, REQUEST_CODE_BONDED_DEVICE) .launch(); } }
src/com/android/settings/bluetooth/BluetoothDevicePairingDetailBase.java +0 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.settings.bluetooth; import static android.app.Activity.RESULT_OK; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; import android.bluetooth.BluetoothAdapter; Loading Loading @@ -94,7 +93,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) { if (bondState == BluetoothDevice.BOND_BONDED) { // If one device is connected(bonded), then close this fragment. setResult(RESULT_OK); finish(); return; } else if (bondState == BluetoothDevice.BOND_BONDING) { Loading Loading @@ -126,7 +124,6 @@ public abstract class BluetoothDevicePairingDetailBase extends DeviceListPrefere if (cachedDevice != null && cachedDevice.isConnected()) { final BluetoothDevice device = cachedDevice.getDevice(); if (device != null && mSelectedList.contains(device)) { setResult(RESULT_OK); finish(); } else { onDeviceDeleted(cachedDevice); Loading
tests/robotests/src/com/android/settings/accessibility/ViewAllBluetoothDevicesPreferenceControllerTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -74,13 +74,13 @@ public class ViewAllBluetoothDevicesPreferenceControllerTest { } @Test public void handlePreferenceTreeClick_expectedPreference_launchBluetoothPairingDetail() { doNothing().when(mController).launchBluetoothPairingDetail(); public void handlePreferenceTreeClick_expectedPreference_launchConnectedDevicePage() { doNothing().when(mController).launchConnectedDevicePage(); mPreference.setKey(TEST_KEY); boolean status = mController.handlePreferenceTreeClick(mPreference); verify(mController).launchBluetoothPairingDetail(); verify(mController).launchConnectedDevicePage(); assertThat(status).isTrue(); } }