Loading core/java/android/companion/BluetoothDeviceFilterUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ public class BluetoothDeviceFilterUtils { static boolean matchesAddress(String deviceAddress, BluetoothDevice device) { final boolean result = deviceAddress == null || (device == null || !deviceAddress.equals(device.getAddress())); || (device != null && deviceAddress.equals(device.getAddress())); if (DEBUG) debugLogMatchResult(result, device, deviceAddress); return result; } Loading core/java/com/android/internal/util/CollectionUtils.java +13 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.Function; import java.util.stream.Stream; Loading Loading @@ -101,7 +102,7 @@ public class CollectionUtils { /** * Returns the given list, or an immutable empty list if the provided list is null * * This can be used to guaranty null-safety without paying the price of extra allocations * This can be used to guarantee null-safety without paying the price of extra allocations * * @see Collections#emptyList */ Loading @@ -109,6 +110,17 @@ public class CollectionUtils { return cur == null ? Collections.emptyList() : cur; } /** * Returns the given set, or an immutable empty set if the provided set is null * * This can be used to guarantee null-safety without paying the price of extra allocations * * @see Collections#emptySet */ public static @NonNull <T> Set<T> emptyIfNull(@Nullable Set<T> cur) { return cur == null ? Collections.emptySet() : cur; } /** * Returns the size of the given list, or 0 if the list is null */ Loading packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java +24 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -211,6 +232,8 @@ public class DeviceDiscoveryService extends Service { } private void onDeviceFound(@Nullable DeviceFilterPair device) { if (device == null) return; if (mDevicesFound.contains(device)) { return; } Loading Loading @@ -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)); } } } } } Loading
core/java/android/companion/BluetoothDeviceFilterUtils.java +1 −1 Original line number Diff line number Diff line Loading @@ -58,7 +58,7 @@ public class BluetoothDeviceFilterUtils { static boolean matchesAddress(String deviceAddress, BluetoothDevice device) { final boolean result = deviceAddress == null || (device == null || !deviceAddress.equals(device.getAddress())); || (device != null && deviceAddress.equals(device.getAddress())); if (DEBUG) debugLogMatchResult(result, device, deviceAddress); return result; } Loading
core/java/com/android/internal/util/CollectionUtils.java +13 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.Function; import java.util.stream.Stream; Loading Loading @@ -101,7 +102,7 @@ public class CollectionUtils { /** * Returns the given list, or an immutable empty list if the provided list is null * * This can be used to guaranty null-safety without paying the price of extra allocations * This can be used to guarantee null-safety without paying the price of extra allocations * * @see Collections#emptyList */ Loading @@ -109,6 +110,17 @@ public class CollectionUtils { return cur == null ? Collections.emptyList() : cur; } /** * Returns the given set, or an immutable empty set if the provided set is null * * This can be used to guarantee null-safety without paying the price of extra allocations * * @see Collections#emptySet */ public static @NonNull <T> Set<T> emptyIfNull(@Nullable Set<T> cur) { return cur == null ? Collections.emptySet() : cur; } /** * Returns the size of the given list, or 0 if the list is null */ Loading
packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java +24 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -211,6 +232,8 @@ public class DeviceDiscoveryService extends Service { } private void onDeviceFound(@Nullable DeviceFilterPair device) { if (device == null) return; if (mDevicesFound.contains(device)) { return; } Loading Loading @@ -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)); } } } } }