Loading core/java/android/companion/BluetoothDeviceFilterUtils.java +4 −2 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ public class BluetoothDeviceFilterUtils { private BluetoothDeviceFilterUtils() {} private static final boolean DEBUG = false; private static final String LOG_TAG = "BluetoothDeviceFilterUtil"; private static final String LOG_TAG = "BluetoothDeviceFilterUtils"; @Nullable static String patternToString(@Nullable Pattern p) { Loading @@ -50,8 +50,10 @@ public class BluetoothDeviceFilterUtils { } static boolean matches(ScanFilter filter, BluetoothDevice device) { return matchesAddress(filter.getDeviceAddress(), device) boolean result = matchesAddress(filter.getDeviceAddress(), device) && matchesServiceUuid(filter.getServiceUuid(), filter.getServiceUuidMask(), device); if (DEBUG) debugLogMatchResult(result, device, filter); return result; } static boolean matchesAddress(String deviceAddress, BluetoothDevice device) { Loading core/java/android/companion/BluetoothLEDeviceFilter.java +11 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.bluetooth.le.ScanResult; import android.os.Parcel; import android.provider.OneTimeUseBuilder; import android.text.TextUtils; import android.util.Log; import com.android.internal.util.BitUtils; import com.android.internal.util.ObjectUtils; Loading @@ -47,6 +48,9 @@ import java.util.regex.Pattern; */ public final class BluetoothLEDeviceFilter implements DeviceFilter<ScanResult> { private static final boolean DEBUG = false; private static final String LOG_TAG = "BluetoothLEDeviceFilter"; private static final int RENAME_PREFIX_LENGTH_LIMIT = 10; private final Pattern mNamePattern; Loading Loading @@ -145,9 +149,13 @@ public final class BluetoothLEDeviceFilter implements DeviceFilter<ScanResult> { /** @hide */ @Override public boolean matches(ScanResult device) { return matches(device.getDevice()) && BitUtils.maskedEquals(device.getScanRecord().getBytes(), mRawDataFilter, mRawDataFilterMask); boolean result = matches(device.getDevice()) && (mRawDataFilter == null || BitUtils.maskedEquals(device.getScanRecord().getBytes(), mRawDataFilter, mRawDataFilterMask)); if (DEBUG) Log.i(LOG_TAG, "matches(this = " + this + ", device = " + device + ") -> " + result); return result; } private boolean matches(BluetoothDevice device) { Loading packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java +23 −3 Original line number Diff line number Diff line Loading @@ -110,6 +110,11 @@ public class DeviceDiscoveryService extends Service { private final ScanCallback mBLEScanCallback = new ScanCallback() { @Override public void onScanResult(int callbackType, ScanResult result) { if (DEBUG) { Log.i(LOG_TAG, "BLE.onScanResult(callbackType = " + callbackType + ", result = " + result + ")"); } final DeviceFilterPair<ScanResult> deviceFilterPair = DeviceFilterPair.findMatch(result, mBLEFilters); if (deviceFilterPair == null) return; Loading @@ -126,6 +131,10 @@ public class DeviceDiscoveryService extends Service { private BroadcastReceiver mBluetoothDeviceFoundBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (DEBUG) { Log.i(LOG_TAG, "BL.onReceive(context = " + context + ", intent = " + intent + ")"); } final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); final DeviceFilterPair<BluetoothDevice> deviceFilterPair = DeviceFilterPair.findMatch(device, mBluetoothFilters); Loading Loading @@ -191,7 +200,10 @@ public class DeviceDiscoveryService extends Service { mBLEScanFilters = CollectionUtils.map(mBLEFilters, BluetoothLEDeviceFilter::getScanFilter); reset(); } } else if (DEBUG) Log.i(LOG_TAG, "startDiscovery: duplicate request: " + request); if (!ArrayUtils.isEmpty(mDevicesFound)) { onReadyToShowUI(); } Loading Loading @@ -221,6 +233,7 @@ public class DeviceDiscoveryService extends Service { } private void reset() { if (DEBUG) Log.i(LOG_TAG, "reset()"); mDevicesFound.clear(); mSelectedDevice = null; mDevicesAdapter.notifyDataSetChanged(); Loading Loading @@ -369,8 +382,15 @@ public class DeviceDiscoveryService extends Service { public static <T extends Parcelable> DeviceFilterPair<T> findMatch( T dev, @Nullable List<? extends DeviceFilter<T>> filters) { if (isEmpty(filters)) return new DeviceFilterPair<>(dev, null); final DeviceFilter<T> matchingFilter = CollectionUtils.find(filters, (f) -> f.matches(dev)); return matchingFilter != null ? new DeviceFilterPair<>(dev, matchingFilter) : null; final DeviceFilter<T> matchingFilter = CollectionUtils.find(filters, f -> f.matches(dev)); DeviceFilterPair<T> result = matchingFilter != null ? new DeviceFilterPair<>(dev, matchingFilter) : null; if (DEBUG) Log.i(LOG_TAG, "findMatch(dev = " + dev + ", filters = " + filters + ") -> " + result); return result; } public String getDisplayName() { Loading Loading
core/java/android/companion/BluetoothDeviceFilterUtils.java +4 −2 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ public class BluetoothDeviceFilterUtils { private BluetoothDeviceFilterUtils() {} private static final boolean DEBUG = false; private static final String LOG_TAG = "BluetoothDeviceFilterUtil"; private static final String LOG_TAG = "BluetoothDeviceFilterUtils"; @Nullable static String patternToString(@Nullable Pattern p) { Loading @@ -50,8 +50,10 @@ public class BluetoothDeviceFilterUtils { } static boolean matches(ScanFilter filter, BluetoothDevice device) { return matchesAddress(filter.getDeviceAddress(), device) boolean result = matchesAddress(filter.getDeviceAddress(), device) && matchesServiceUuid(filter.getServiceUuid(), filter.getServiceUuidMask(), device); if (DEBUG) debugLogMatchResult(result, device, filter); return result; } static boolean matchesAddress(String deviceAddress, BluetoothDevice device) { Loading
core/java/android/companion/BluetoothLEDeviceFilter.java +11 −3 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.bluetooth.le.ScanResult; import android.os.Parcel; import android.provider.OneTimeUseBuilder; import android.text.TextUtils; import android.util.Log; import com.android.internal.util.BitUtils; import com.android.internal.util.ObjectUtils; Loading @@ -47,6 +48,9 @@ import java.util.regex.Pattern; */ public final class BluetoothLEDeviceFilter implements DeviceFilter<ScanResult> { private static final boolean DEBUG = false; private static final String LOG_TAG = "BluetoothLEDeviceFilter"; private static final int RENAME_PREFIX_LENGTH_LIMIT = 10; private final Pattern mNamePattern; Loading Loading @@ -145,9 +149,13 @@ public final class BluetoothLEDeviceFilter implements DeviceFilter<ScanResult> { /** @hide */ @Override public boolean matches(ScanResult device) { return matches(device.getDevice()) && BitUtils.maskedEquals(device.getScanRecord().getBytes(), mRawDataFilter, mRawDataFilterMask); boolean result = matches(device.getDevice()) && (mRawDataFilter == null || BitUtils.maskedEquals(device.getScanRecord().getBytes(), mRawDataFilter, mRawDataFilterMask)); if (DEBUG) Log.i(LOG_TAG, "matches(this = " + this + ", device = " + device + ") -> " + result); return result; } private boolean matches(BluetoothDevice device) { Loading
packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java +23 −3 Original line number Diff line number Diff line Loading @@ -110,6 +110,11 @@ public class DeviceDiscoveryService extends Service { private final ScanCallback mBLEScanCallback = new ScanCallback() { @Override public void onScanResult(int callbackType, ScanResult result) { if (DEBUG) { Log.i(LOG_TAG, "BLE.onScanResult(callbackType = " + callbackType + ", result = " + result + ")"); } final DeviceFilterPair<ScanResult> deviceFilterPair = DeviceFilterPair.findMatch(result, mBLEFilters); if (deviceFilterPair == null) return; Loading @@ -126,6 +131,10 @@ public class DeviceDiscoveryService extends Service { private BroadcastReceiver mBluetoothDeviceFoundBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (DEBUG) { Log.i(LOG_TAG, "BL.onReceive(context = " + context + ", intent = " + intent + ")"); } final BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); final DeviceFilterPair<BluetoothDevice> deviceFilterPair = DeviceFilterPair.findMatch(device, mBluetoothFilters); Loading Loading @@ -191,7 +200,10 @@ public class DeviceDiscoveryService extends Service { mBLEScanFilters = CollectionUtils.map(mBLEFilters, BluetoothLEDeviceFilter::getScanFilter); reset(); } } else if (DEBUG) Log.i(LOG_TAG, "startDiscovery: duplicate request: " + request); if (!ArrayUtils.isEmpty(mDevicesFound)) { onReadyToShowUI(); } Loading Loading @@ -221,6 +233,7 @@ public class DeviceDiscoveryService extends Service { } private void reset() { if (DEBUG) Log.i(LOG_TAG, "reset()"); mDevicesFound.clear(); mSelectedDevice = null; mDevicesAdapter.notifyDataSetChanged(); Loading Loading @@ -369,8 +382,15 @@ public class DeviceDiscoveryService extends Service { public static <T extends Parcelable> DeviceFilterPair<T> findMatch( T dev, @Nullable List<? extends DeviceFilter<T>> filters) { if (isEmpty(filters)) return new DeviceFilterPair<>(dev, null); final DeviceFilter<T> matchingFilter = CollectionUtils.find(filters, (f) -> f.matches(dev)); return matchingFilter != null ? new DeviceFilterPair<>(dev, matchingFilter) : null; final DeviceFilter<T> matchingFilter = CollectionUtils.find(filters, f -> f.matches(dev)); DeviceFilterPair<T> result = matchingFilter != null ? new DeviceFilterPair<>(dev, matchingFilter) : null; if (DEBUG) Log.i(LOG_TAG, "findMatch(dev = " + dev + ", filters = " + filters + ") -> " + result); return result; } public String getDisplayName() { Loading