diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-10-25 18:55:33 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-10-25 18:55:33 +0000 |
| commit | c898a4bd43a960cd9d53c9c4431fc117b07b3753 (patch) | |
| tree | 8665eb209ded9838d30e0700a266fd2e9e984cdd /core/java/android | |
| parent | d1fb5a812e017037fd2fe2f80fd5b74274946819 (diff) | |
| parent | e7ccfccd7d6949868e8b3f5e85e65126272af935 (diff) | |
Merge "Replaced BitUtils#maskedEquals hidden API call" am: 3d4a7e57fe am: f1d8cbb46c am: 395496ff6a am: 49832ec945 am: e7ccfccd7d
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1868764
Change-Id: I87dc103d79d2fbf63e2653f85575a9ad1161f356
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/bluetooth/le/BluetoothLeUtils.java | 18 | ||||
| -rw-r--r-- | core/java/android/bluetooth/le/ScanFilter.java | 6 |
2 files changed, 20 insertions, 4 deletions
diff --git a/core/java/android/bluetooth/le/BluetoothLeUtils.java b/core/java/android/bluetooth/le/BluetoothLeUtils.java index 6381f557c1b2..ed50b09597bb 100644 --- a/core/java/android/bluetooth/le/BluetoothLeUtils.java +++ b/core/java/android/bluetooth/le/BluetoothLeUtils.java @@ -24,6 +24,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.UUID; /** * Helper class for Bluetooth LE utils. @@ -137,4 +138,21 @@ public class BluetoothLeUtils { } } + /** + * Compares two UUIDs with a UUID mask. + * + * @param data first {@link #UUID} to compare. + * @param uuid second {@link #UUID} to compare. + * @param mask mask {@link #UUID}. + * @return true if both UUIDs are equals when masked, false otherwise. + */ + static boolean maskedEquals(UUID data, UUID uuid, UUID mask) { + if (mask == null) { + return Objects.equals(data, uuid); + } + return (data.getLeastSignificantBits() & mask.getLeastSignificantBits()) + == (uuid.getLeastSignificantBits() & mask.getLeastSignificantBits()) + && (data.getMostSignificantBits() & mask.getMostSignificantBits()) + == (uuid.getMostSignificantBits() & mask.getMostSignificantBits()); + } } diff --git a/core/java/android/bluetooth/le/ScanFilter.java b/core/java/android/bluetooth/le/ScanFilter.java index 8ff018121ab0..b059193ae03f 100644 --- a/core/java/android/bluetooth/le/ScanFilter.java +++ b/core/java/android/bluetooth/le/ScanFilter.java @@ -28,8 +28,6 @@ import android.os.Parcel; import android.os.ParcelUuid; import android.os.Parcelable; -import com.android.internal.util.BitUtils; - import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -448,7 +446,7 @@ public final class ScanFilter implements Parcelable { // Check if the uuid pattern matches the particular service uuid. private static boolean matchesServiceUuid(UUID uuid, UUID mask, UUID data) { - return BitUtils.maskedEquals(data, uuid, mask); + return BluetoothLeUtils.maskedEquals(data, uuid, mask); } /** @@ -478,7 +476,7 @@ public final class ScanFilter implements Parcelable { // Check if the solicitation uuid pattern matches the particular service solicitation uuid. private static boolean matchesServiceSolicitationUuid(UUID solicitationUuid, UUID solicitationUuidMask, UUID data) { - return BitUtils.maskedEquals(data, solicitationUuid, solicitationUuidMask); + return BluetoothLeUtils.maskedEquals(data, solicitationUuid, solicitationUuidMask); } // Check whether the data pattern matches the parsed data. |
