blob: bc3c9a9ebf4b38ed29fb2a83d502b27e54e672c1 [file] [log] [blame]
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.bluetooth;
18
Mathew Inwood7acad5e2018-08-01 15:00:35 +010019import android.annotation.UnsupportedAppUsage;
Mathew Inwood31755f92018-12-20 13:53:36 +000020import android.os.Build;
Nick Pellyaef439e2009-09-28 12:33:17 -070021import android.os.ParcelUuid;
22
Wei Wang82500dd2014-04-15 14:57:16 -070023import java.nio.ByteBuffer;
24import java.nio.ByteOrder;
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -070025import java.util.Arrays;
26import java.util.HashSet;
Jaikumar Ganesh84690c82010-12-10 12:48:58 -080027import java.util.UUID;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -070028
29/**
Jack Hea355e5e2017-08-22 16:06:54 -070030 * Static helper methods and constants to decode the ParcelUuid of remote devices.
31 *
32 * @hide
33 */
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -070034public final class BluetoothUuid {
35
36 /* See Bluetooth Assigned Numbers document - SDP section, to get the values of UUIDs
37 * for the various services.
38 *
39 * The following 128 bit values are calculated as:
40 * uuid * 2^96 + BASE_UUID
41 */
Mathew Inwood31755f92018-12-20 13:53:36 +000042 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -070043 public static final ParcelUuid AudioSink =
44 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
45 public static final ParcelUuid AudioSource =
46 ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
Mathew Inwood31755f92018-12-20 13:53:36 +000047 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -070048 public static final ParcelUuid AdvAudioDist =
49 ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB");
Mathew Inwood31755f92018-12-20 13:53:36 +000050 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -070051 public static final ParcelUuid HSP =
52 ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh84690c82010-12-10 12:48:58 -080053 public static final ParcelUuid HSP_AG =
54 ParcelUuid.fromString("00001112-0000-1000-8000-00805F9B34FB");
Mathew Inwood31755f92018-12-20 13:53:36 +000055 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -070056 public static final ParcelUuid Handsfree =
57 ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh84690c82010-12-10 12:48:58 -080058 public static final ParcelUuid Handsfree_AG =
59 ParcelUuid.fromString("0000111F-0000-1000-8000-00805F9B34FB");
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -070060 public static final ParcelUuid AvrcpController =
61 ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB");
62 public static final ParcelUuid AvrcpTarget =
63 ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB");
Mathew Inwood7acad5e2018-08-01 15:00:35 +010064 @UnsupportedAppUsage
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -070065 public static final ParcelUuid ObexObjectPush =
66 ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb");
Jaikumar Ganesh545e6702010-06-04 10:23:03 -070067 public static final ParcelUuid Hid =
Adam Powelldf7627d2010-06-21 16:23:42 -070068 ParcelUuid.fromString("00001124-0000-1000-8000-00805f9b34fb");
Mathew Inwood7acad5e2018-08-01 15:00:35 +010069 @UnsupportedAppUsage
Andre Eisenbachc60bed42013-03-07 18:07:35 -080070 public static final ParcelUuid Hogp =
71 ParcelUuid.fromString("00001812-0000-1000-8000-00805f9b34fb");
Danica Chang6fdd0c62010-08-11 14:54:43 -070072 public static final ParcelUuid PANU =
73 ParcelUuid.fromString("00001115-0000-1000-8000-00805F9B34FB");
Mathew Inwood7acad5e2018-08-01 15:00:35 +010074 @UnsupportedAppUsage
Danica Chang6fdd0c62010-08-11 14:54:43 -070075 public static final ParcelUuid NAP =
76 ParcelUuid.fromString("00001116-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh34536182010-08-23 18:32:03 -070077 public static final ParcelUuid BNEP =
78 ParcelUuid.fromString("0000000f-0000-1000-8000-00805F9B34FB");
Matthew Xie68623612014-11-20 21:53:26 -080079 public static final ParcelUuid PBAP_PCE =
80 ParcelUuid.fromString("0000112e-0000-1000-8000-00805F9B34FB");
Mathew Inwood7acad5e2018-08-01 15:00:35 +010081 @UnsupportedAppUsage
Jaikumar Ganesh84690c82010-12-10 12:48:58 -080082 public static final ParcelUuid PBAP_PSE =
83 ParcelUuid.fromString("0000112f-0000-1000-8000-00805F9B34FB");
Matthew Xiefe3807a2013-07-18 17:31:50 -070084 public static final ParcelUuid MAP =
Kim Schulz0d376052013-08-22 11:18:02 +020085 ParcelUuid.fromString("00001134-0000-1000-8000-00805F9B34FB");
Matthew Xiefe3807a2013-07-18 17:31:50 -070086 public static final ParcelUuid MNS =
87 ParcelUuid.fromString("00001133-0000-1000-8000-00805F9B34FB");
Kim Schulz0d376052013-08-22 11:18:02 +020088 public static final ParcelUuid MAS =
89 ParcelUuid.fromString("00001132-0000-1000-8000-00805F9B34FB");
Jack Hea355e5e2017-08-22 16:06:54 -070090 public static final ParcelUuid SAP =
Casper Bonde2a5f6082015-03-19 10:36:45 +010091 ParcelUuid.fromString("0000112D-0000-1000-8000-00805F9B34FB");
Jakub Pawlowskiea580fa2017-11-22 11:02:34 -080092 public static final ParcelUuid HearingAid =
Jakub Pawlowski50276792018-02-22 15:10:08 -080093 ParcelUuid.fromString("0000FDF0-0000-1000-8000-00805f9b34fb");
Jack Hea355e5e2017-08-22 16:06:54 -070094
Wei Wang18c76932013-10-29 21:05:37 -070095 public static final ParcelUuid BASE_UUID =
96 ParcelUuid.fromString("00000000-0000-1000-8000-00805F9B34FB");
97
Wei Wang82500dd2014-04-15 14:57:16 -070098 /** Length of bytes for 16 bit UUID */
99 public static final int UUID_BYTES_16_BIT = 2;
100 /** Length of bytes for 32 bit UUID */
101 public static final int UUID_BYTES_32_BIT = 4;
102 /** Length of bytes for 128 bit UUID */
103 public static final int UUID_BYTES_128_BIT = 16;
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700104
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100105 @UnsupportedAppUsage
Nick Pelly24bb9b82009-10-02 20:34:18 -0700106 public static final ParcelUuid[] RESERVED_UUIDS = {
Jack Hea355e5e2017-08-22 16:06:54 -0700107 AudioSink, AudioSource, AdvAudioDist, HSP, Handsfree, AvrcpController, AvrcpTarget,
108 ObexObjectPush, PANU, NAP, MAP, MNS, MAS, SAP};
Nick Pelly24bb9b82009-10-02 20:34:18 -0700109
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100110 @UnsupportedAppUsage
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700111 public static boolean isAudioSource(ParcelUuid uuid) {
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700112 return uuid.equals(AudioSource);
113 }
114
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700115 public static boolean isAudioSink(ParcelUuid uuid) {
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700116 return uuid.equals(AudioSink);
117 }
118
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100119 @UnsupportedAppUsage
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700120 public static boolean isAdvAudioDist(ParcelUuid uuid) {
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700121 return uuid.equals(AdvAudioDist);
122 }
123
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700124 public static boolean isHandsfree(ParcelUuid uuid) {
Jaikumar Ganesh7f74d532009-07-14 12:21:26 -0700125 return uuid.equals(Handsfree);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700126 }
127
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700128 public static boolean isHeadset(ParcelUuid uuid) {
Jaikumar Ganeshade40522009-07-30 13:32:25 -0700129 return uuid.equals(HSP);
130 }
131
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700132 public static boolean isAvrcpController(ParcelUuid uuid) {
Jaikumar Ganeshade40522009-07-30 13:32:25 -0700133 return uuid.equals(AvrcpController);
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700134 }
Jackson Fan9abcf092009-08-19 21:01:29 +0800135
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100136 @UnsupportedAppUsage
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700137 public static boolean isAvrcpTarget(ParcelUuid uuid) {
Jackson Fan9abcf092009-08-19 21:01:29 +0800138 return uuid.equals(AvrcpTarget);
139 }
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700140
Jaikumar Ganesh545e6702010-06-04 10:23:03 -0700141 public static boolean isInputDevice(ParcelUuid uuid) {
142 return uuid.equals(Hid);
143 }
144
Jaikumar Ganesh34536182010-08-23 18:32:03 -0700145 public static boolean isPanu(ParcelUuid uuid) {
Danica Chang6fdd0c62010-08-11 14:54:43 -0700146 return uuid.equals(PANU);
147 }
148
Jaikumar Ganesh34536182010-08-23 18:32:03 -0700149 public static boolean isNap(ParcelUuid uuid) {
Danica Chang6fdd0c62010-08-11 14:54:43 -0700150 return uuid.equals(NAP);
151 }
Jaikumar Ganesh34536182010-08-23 18:32:03 -0700152
153 public static boolean isBnep(ParcelUuid uuid) {
154 return uuid.equals(BNEP);
155 }
Jack Hea355e5e2017-08-22 16:06:54 -0700156
Matthew Xiefe3807a2013-07-18 17:31:50 -0700157 public static boolean isMap(ParcelUuid uuid) {
158 return uuid.equals(MAP);
159 }
Jack Hea355e5e2017-08-22 16:06:54 -0700160
Matthew Xiefe3807a2013-07-18 17:31:50 -0700161 public static boolean isMns(ParcelUuid uuid) {
162 return uuid.equals(MNS);
163 }
Jack Hea355e5e2017-08-22 16:06:54 -0700164
Kim Schulz0d376052013-08-22 11:18:02 +0200165 public static boolean isMas(ParcelUuid uuid) {
166 return uuid.equals(MAS);
167 }
Jack Hea355e5e2017-08-22 16:06:54 -0700168
Casper Bonde2a5f6082015-03-19 10:36:45 +0100169 public static boolean isSap(ParcelUuid uuid) {
170 return uuid.equals(SAP);
171 }
Matthew Xiefe3807a2013-07-18 17:31:50 -0700172
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700173 /**
174 * Returns true if ParcelUuid is present in uuidArray
175 *
176 * @param uuidArray - Array of ParcelUuids
177 * @param uuid
178 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100179 @UnsupportedAppUsage
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700180 public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
Jack Hea355e5e2017-08-22 16:06:54 -0700181 if ((uuidArray == null || uuidArray.length == 0) && uuid == null) {
Jaikumar Ganesh10eac972009-09-21 12:48:51 -0700182 return true;
Jack Hea355e5e2017-08-22 16:06:54 -0700183 }
Jaikumar Ganesh10eac972009-09-21 12:48:51 -0700184
Jack Hea355e5e2017-08-22 16:06:54 -0700185 if (uuidArray == null) {
Jaikumar Ganesh10eac972009-09-21 12:48:51 -0700186 return false;
Jack Hea355e5e2017-08-22 16:06:54 -0700187 }
Jaikumar Ganesh10eac972009-09-21 12:48:51 -0700188
Jack Hea355e5e2017-08-22 16:06:54 -0700189 for (ParcelUuid element : uuidArray) {
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700190 if (element.equals(uuid)) return true;
191 }
192 return false;
193 }
194
195 /**
196 * Returns true if there any common ParcelUuids in uuidA and uuidB.
197 *
198 * @param uuidA - List of ParcelUuids
199 * @param uuidB - List of ParcelUuids
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700200 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100201 @UnsupportedAppUsage
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700202 public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
203 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganeshdca2f0f2009-09-16 17:50:52 -0700204
205 if (uuidA == null) {
Jack He2992cd02017-08-22 21:21:23 -0700206 return uuidB.length == 0;
Jaikumar Ganeshdca2f0f2009-09-16 17:50:52 -0700207 }
208
209 if (uuidB == null) {
Jack He2992cd02017-08-22 21:21:23 -0700210 return uuidA.length == 0;
Jaikumar Ganeshdca2f0f2009-09-16 17:50:52 -0700211 }
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700212
Jack Hea355e5e2017-08-22 16:06:54 -0700213 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
214 for (ParcelUuid uuid : uuidB) {
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700215 if (uuidSet.contains(uuid)) return true;
216 }
217 return false;
218 }
219
220 /**
221 * Returns true if all the ParcelUuids in ParcelUuidB are present in
222 * ParcelUuidA
223 *
224 * @param uuidA - Array of ParcelUuidsA
225 * @param uuidB - Array of ParcelUuidsB
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700226 */
227 public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
228 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganeshdca2f0f2009-09-16 17:50:52 -0700229
230 if (uuidA == null) {
Jack He2992cd02017-08-22 21:21:23 -0700231 return uuidB.length == 0;
Jaikumar Ganeshdca2f0f2009-09-16 17:50:52 -0700232 }
233
234 if (uuidB == null) return true;
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700235
Jack Hea355e5e2017-08-22 16:06:54 -0700236 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid>(Arrays.asList(uuidA));
237 for (ParcelUuid uuid : uuidB) {
Jaikumar Ganeshdd0463a2009-09-16 12:30:02 -0700238 if (!uuidSet.contains(uuid)) return false;
239 }
240 return true;
241 }
242
Jaikumar Ganesh84690c82010-12-10 12:48:58 -0800243 /**
244 * Extract the Service Identifier or the actual uuid from the Parcel Uuid.
245 * For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid,
246 * this function will return 110B
Jack Hea355e5e2017-08-22 16:06:54 -0700247 *
Jaikumar Ganesh84690c82010-12-10 12:48:58 -0800248 * @param parcelUuid
249 * @return the service identifier.
250 */
251 public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
252 UUID uuid = parcelUuid.getUuid();
Ruina Liu044e0fe2017-07-22 18:41:48 +0800253 long value = (uuid.getMostSignificantBits() & 0xFFFFFFFF00000000L) >>> 32;
Jack Hea355e5e2017-08-22 16:06:54 -0700254 return (int) value;
Jaikumar Ganesh84690c82010-12-10 12:48:58 -0800255 }
Wei Wang18c76932013-10-29 21:05:37 -0700256
257 /**
Wei Wang82500dd2014-04-15 14:57:16 -0700258 * Parse UUID from bytes. The {@code uuidBytes} can represent a 16-bit, 32-bit or 128-bit UUID,
259 * but the returned UUID is always in 128-bit format.
260 * Note UUID is little endian in Bluetooth.
261 *
262 * @param uuidBytes Byte representation of uuid.
263 * @return {@link ParcelUuid} parsed from bytes.
264 * @throws IllegalArgumentException If the {@code uuidBytes} cannot be parsed.
265 */
266 public static ParcelUuid parseUuidFrom(byte[] uuidBytes) {
267 if (uuidBytes == null) {
268 throw new IllegalArgumentException("uuidBytes cannot be null");
269 }
270 int length = uuidBytes.length;
Jack He2992cd02017-08-22 21:21:23 -0700271 if (length != UUID_BYTES_16_BIT && length != UUID_BYTES_32_BIT
272 && length != UUID_BYTES_128_BIT) {
Wei Wang82500dd2014-04-15 14:57:16 -0700273 throw new IllegalArgumentException("uuidBytes length invalid - " + length);
274 }
275
276 // Construct a 128 bit UUID.
277 if (length == UUID_BYTES_128_BIT) {
278 ByteBuffer buf = ByteBuffer.wrap(uuidBytes).order(ByteOrder.LITTLE_ENDIAN);
279 long msb = buf.getLong(8);
280 long lsb = buf.getLong(0);
281 return new ParcelUuid(new UUID(msb, lsb));
282 }
283
284 // For 16 bit and 32 bit UUID we need to convert them to 128 bit value.
285 // 128_bit_value = uuid * 2^96 + BASE_UUID
286 long shortUuid;
287 if (length == UUID_BYTES_16_BIT) {
288 shortUuid = uuidBytes[0] & 0xFF;
289 shortUuid += (uuidBytes[1] & 0xFF) << 8;
290 } else {
Jack Hea355e5e2017-08-22 16:06:54 -0700291 shortUuid = uuidBytes[0] & 0xFF;
Wei Wang82500dd2014-04-15 14:57:16 -0700292 shortUuid += (uuidBytes[1] & 0xFF) << 8;
293 shortUuid += (uuidBytes[2] & 0xFF) << 16;
294 shortUuid += (uuidBytes[3] & 0xFF) << 24;
295 }
296 long msb = BASE_UUID.getUuid().getMostSignificantBits() + (shortUuid << 32);
297 long lsb = BASE_UUID.getUuid().getLeastSignificantBits();
298 return new ParcelUuid(new UUID(msb, lsb));
299 }
300
301 /**
Jack Hea355e5e2017-08-22 16:06:54 -0700302 * Parse UUID to bytes. The returned value is shortest representation, a 16-bit, 32-bit or
303 * 128-bit UUID, Note returned value is little endian (Bluetooth).
Jakub Pawlowskif67ee832016-10-24 13:56:54 -0700304 *
305 * @param uuid uuid to parse.
306 * @return shortest representation of {@code uuid} as bytes.
307 * @throws IllegalArgumentException If the {@code uuid} is null.
308 */
309 public static byte[] uuidToBytes(ParcelUuid uuid) {
310 if (uuid == null) {
311 throw new IllegalArgumentException("uuid cannot be null");
312 }
313
314 if (is16BitUuid(uuid)) {
315 byte[] uuidBytes = new byte[UUID_BYTES_16_BIT];
316 int uuidVal = getServiceIdentifierFromParcelUuid(uuid);
Jack Hea355e5e2017-08-22 16:06:54 -0700317 uuidBytes[0] = (byte) (uuidVal & 0xFF);
318 uuidBytes[1] = (byte) ((uuidVal & 0xFF00) >> 8);
Jakub Pawlowskif67ee832016-10-24 13:56:54 -0700319 return uuidBytes;
320 }
321
322 if (is32BitUuid(uuid)) {
323 byte[] uuidBytes = new byte[UUID_BYTES_32_BIT];
324 int uuidVal = getServiceIdentifierFromParcelUuid(uuid);
Jack Hea355e5e2017-08-22 16:06:54 -0700325 uuidBytes[0] = (byte) (uuidVal & 0xFF);
326 uuidBytes[1] = (byte) ((uuidVal & 0xFF00) >> 8);
327 uuidBytes[2] = (byte) ((uuidVal & 0xFF0000) >> 16);
328 uuidBytes[3] = (byte) ((uuidVal & 0xFF000000) >> 24);
Jakub Pawlowskif67ee832016-10-24 13:56:54 -0700329 return uuidBytes;
330 }
331
332 // Construct a 128 bit UUID.
333 long msb = uuid.getUuid().getMostSignificantBits();
334 long lsb = uuid.getUuid().getLeastSignificantBits();
335
336 byte[] uuidBytes = new byte[UUID_BYTES_128_BIT];
337 ByteBuffer buf = ByteBuffer.wrap(uuidBytes).order(ByteOrder.LITTLE_ENDIAN);
338 buf.putLong(8, msb);
339 buf.putLong(0, lsb);
340 return uuidBytes;
341 }
342
343 /**
Wei Wang18c76932013-10-29 21:05:37 -0700344 * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid.
Wei Wang82500dd2014-04-15 14:57:16 -0700345 *
Wei Wang18c76932013-10-29 21:05:37 -0700346 * @param parcelUuid
347 * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise.
348 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100349 @UnsupportedAppUsage
Wei Wang51800842014-05-07 14:54:43 -0700350 public static boolean is16BitUuid(ParcelUuid parcelUuid) {
Wei Wang82500dd2014-04-15 14:57:16 -0700351 UUID uuid = parcelUuid.getUuid();
352 if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
353 return false;
354 }
355 return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L);
Wei Wang18c76932013-10-29 21:05:37 -0700356 }
Wei Wang51800842014-05-07 14:54:43 -0700357
358
359 /**
360 * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid.
361 *
362 * @param parcelUuid
363 * @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise.
364 */
Mathew Inwood7acad5e2018-08-01 15:00:35 +0100365 @UnsupportedAppUsage
Wei Wang51800842014-05-07 14:54:43 -0700366 public static boolean is32BitUuid(ParcelUuid parcelUuid) {
367 UUID uuid = parcelUuid.getUuid();
368 if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) {
369 return false;
370 }
371 if (is16BitUuid(parcelUuid)) {
372 return false;
373 }
374 return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L);
375 }
Jaikumar Ganeshd5ac1ae2009-05-05 22:26:12 -0700376}