diff options
author | Eugene Susla <eugenesusla@google.com> | 2017-06-09 18:03:14 -0700 |
---|---|---|
committer | Eugene Susla <eugenesusla@google.com> | 2017-06-12 16:21:51 -0700 |
commit | 0c4a9266264d37e724f7372ef7ef932cf60c505c (patch) | |
tree | 063e57a2358af8c523c82eca6e3b392c5b444a77 /packages/CompanionDeviceManager/src | |
parent | ffd8343ba87c7cdf84287b91972b987ffc41d4fb (diff) |
Support associating with an already-paired device
This is required for migration scenario, where device(s) are already
paired(and thus no longer discoverable) but didn't go through companion
flow.
This also fixes a bug with filtering by mac address, which is also relevant to
the use-case of associating a specific device
Test: Pair with a device first, and call associate with a filter with its MAC
address and single device requested. Ensure the device is found.
Ensure only that device is ever returned when filtering by MAC address.
Bug: 62487084
Change-Id: Ic7cc6affc0648ad85b15620e8c3aba4b9fc91aa1
Diffstat (limited to 'packages/CompanionDeviceManager/src')
-rw-r--r-- | packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java index 2a4ab0f550e5..3b29a6cd7b6c 100644 --- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java +++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java @@ -20,6 +20,8 @@ import static android.companion.BluetoothDeviceFilterUtils.getDeviceDisplayNameI import static android.companion.BluetoothDeviceFilterUtils.getDeviceMacAddress; import static com.android.internal.util.ArrayUtils.isEmpty; +import static com.android.internal.util.CollectionUtils.emptyIfNull; +import static com.android.internal.util.CollectionUtils.size; import android.annotation.NonNull; import android.annotation.Nullable; @@ -154,6 +156,25 @@ public class DeviceDiscoveryService extends Service { onReadyToShowUI(); } + // If filtering to get single device by mac address, also search in the set of already + // bonded devices to allow linking those directly + String singleMacAddressFilter = null; + if (mRequest.isSingleDevice()) { + int numFilters = size(mBluetoothFilters); + for (int i = 0; i < numFilters; i++) { + BluetoothDeviceFilter filter = mBluetoothFilters.get(i); + if (!TextUtils.isEmpty(filter.getAddress())) { + singleMacAddressFilter = filter.getAddress(); + break; + } + } + } + if (singleMacAddressFilter != null) { + for (BluetoothDevice dev : emptyIfNull(mBluetoothAdapter.getBondedDevices())) { + onDeviceFound(DeviceFilterPair.findMatch(dev, mBluetoothFilters)); + } + } + if (shouldScan(mBluetoothFilters)) { final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothDevice.ACTION_FOUND); @@ -211,6 +232,8 @@ public class DeviceDiscoveryService extends Service { } private void onDeviceFound(@Nullable DeviceFilterPair device) { + if (device == null) return; + if (mDevicesFound.contains(device)) { return; } @@ -444,12 +467,9 @@ public class DeviceDiscoveryService extends Service { } for (int i = 0; i < scanResults.size(); i++) { - DeviceFilterPair<android.net.wifi.ScanResult> deviceFilterPair = - DeviceFilterPair.findMatch(scanResults.get(i), mWifiFilters); - if (deviceFilterPair != null) onDeviceFound(deviceFilterPair); + onDeviceFound(DeviceFilterPair.findMatch(scanResults.get(i), mWifiFilters)); } } - } } } |