summaryrefslogtreecommitdiff
path: root/packages/CompanionDeviceManager/src
diff options
context:
space:
mode:
author Evan Chen <evanxinchen@google.com> 2024-04-22 21:23:43 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-04-22 21:23:43 +0000
commit840d5522175943264547a06b767fcbf7fc85d2c6 (patch)
tree5c9ea3d45559592f45ac1f1aedf086e20de14a7f /packages/CompanionDeviceManager/src
parent016ce9ef3e0e36f0bb406550c8019ff0a82d2bb7 (diff)
parent6aeff5698590ca108e338012b06f63aa3e25a9db (diff)
Merge "Revert^2 "Do not need to startDiscovery if a bound device need to be assoicated."" into main
Diffstat (limited to 'packages/CompanionDeviceManager/src')
-rw-r--r--packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java29
1 files changed, 19 insertions, 10 deletions
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java
index c8801bb5ded2..a5bb34f4422b 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/CompanionDeviceDiscoveryService.java
@@ -188,7 +188,12 @@ public class CompanionDeviceDiscoveryService extends Service {
filter(allFilters, BluetoothLeDeviceFilter.class);
final List<WifiDeviceFilter> wifiFilters = filter(allFilters, WifiDeviceFilter.class);
- checkBoundDevicesIfNeeded(request, btFilters);
+ // No need to startDiscovery if the device is already bound or connected for
+ // singleDevice dialog.
+ if (checkBoundDevicesIfNeeded(request, btFilters)) {
+ stopSelf();
+ return;
+ }
// If no filters are specified: look for everything.
final boolean forceStartScanningAll = isEmpty(allFilters);
@@ -248,33 +253,37 @@ public class CompanionDeviceDiscoveryService extends Service {
stopSelf();
}
- private void checkBoundDevicesIfNeeded(@NonNull AssociationRequest request,
+ private boolean checkBoundDevicesIfNeeded(@NonNull AssociationRequest request,
@NonNull List<BluetoothDeviceFilter> btFilters) {
// If filtering to get single device by mac address, also search in the set of already
// bonded devices to allow linking those directly
- if (btFilters.isEmpty() || !request.isSingleDevice()) return;
+ if (btFilters.isEmpty() || !request.isSingleDevice()) return false;
final BluetoothDeviceFilter singleMacAddressFilter =
find(btFilters, filter -> !TextUtils.isEmpty(filter.getAddress()));
- if (singleMacAddressFilter == null) return;
+ if (singleMacAddressFilter == null) return false;
- findAndReportMatches(mBtAdapter.getBondedDevices(), btFilters);
- findAndReportMatches(mBtManager.getConnectedDevices(BluetoothProfile.GATT), btFilters);
- findAndReportMatches(
- mBtManager.getConnectedDevices(BluetoothProfile.GATT_SERVER), btFilters);
+ return findAndReportMatches(mBtAdapter.getBondedDevices(), btFilters)
+ || findAndReportMatches(mBtManager.getConnectedDevices(
+ BluetoothProfile.GATT), btFilters)
+ || findAndReportMatches(mBtManager.getConnectedDevices(
+ BluetoothProfile.GATT_SERVER), btFilters);
}
- private void findAndReportMatches(@Nullable Collection<BluetoothDevice> devices,
+ private boolean findAndReportMatches(@Nullable Collection<BluetoothDevice> devices,
@NonNull List<BluetoothDeviceFilter> filters) {
- if (devices == null) return;
+ if (devices == null) return false;
for (BluetoothDevice device : devices) {
final DeviceFilterPair<BluetoothDevice> match = findMatch(device, filters);
if (match != null) {
onDeviceFound(match);
+ return true;
}
}
+
+ return false;
}
private BluetoothBroadcastReceiver startBtScanningIfNeeded(