Bluetooth: Always scan while on pairing or DevicePicker page
* Modified DeviceListPreferenceFragment to have enable/disable scanning methods. In ENABLE state, each onScanningStateChanged(false) will restart another round of scanning * Subclasses of DeviceListPreferenceFragment should call enable/disable scanning when scanning is needed for long period of time * Currently, BluetoothPairingDetail and DevicePickerFragment call enableScanning() when Bluetooth is turned ON and call disableScanning when some device is picked in their lists * Both BluetoothPairingDetail and DevicePickerFragment will re-enable scanning if pairing failed for selected device * Added associated unit tests as well Bug: 32172815 Test: make, pair Bluetooth device, send file over Bluetooth Opp Change-Id: I99325e06aadd7b00e7a7ba6d6c282a6831859d8b
This commit is contained in:
@@ -54,6 +54,9 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
|
||||
private BluetoothDeviceFilter.Filter mFilter;
|
||||
|
||||
@VisibleForTesting
|
||||
boolean mScanEnabled;
|
||||
|
||||
BluetoothDevice mSelectedDevice;
|
||||
|
||||
LocalBluetoothAdapter mLocalAdapter;
|
||||
@@ -216,8 +219,25 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void enableScanning() {
|
||||
// LocalBluetoothAdapter already handles repeated scan requests
|
||||
mLocalAdapter.startScanning(true);
|
||||
mScanEnabled = true;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void disableScanning() {
|
||||
mLocalAdapter.stopScanning();
|
||||
mScanEnabled = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanningStateChanged(boolean started) {}
|
||||
public void onScanningStateChanged(boolean started) {
|
||||
if (!started && mScanEnabled) {
|
||||
mLocalAdapter.startScanning(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBluetoothStateChanged(int bluetoothState) {}
|
||||
|
Reference in New Issue
Block a user