Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.bluetooth; |
| 18 | |
Nick Pelly | aef439e | 2009-09-28 12:33:17 -0700 | [diff] [blame] | 19 | import android.os.ParcelUuid; |
| 20 | |
Wei Wang | 82500dd | 2014-04-15 14:57:16 -0700 | [diff] [blame] | 21 | import java.nio.ByteBuffer; |
| 22 | import java.nio.ByteOrder; |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 23 | import java.util.Arrays; |
| 24 | import java.util.HashSet; |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 25 | import java.util.UUID; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 28 | * Static helper methods and constants to decode the ParcelUuid of remote devices. |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 29 | * @hide |
| 30 | */ |
| 31 | public final class BluetoothUuid { |
| 32 | |
| 33 | /* See Bluetooth Assigned Numbers document - SDP section, to get the values of UUIDs |
| 34 | * for the various services. |
| 35 | * |
| 36 | * The following 128 bit values are calculated as: |
| 37 | * uuid * 2^96 + BASE_UUID |
| 38 | */ |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 39 | public static final ParcelUuid AudioSink = |
| 40 | ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB"); |
| 41 | public static final ParcelUuid AudioSource = |
| 42 | ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB"); |
| 43 | public static final ParcelUuid AdvAudioDist = |
| 44 | ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB"); |
| 45 | public static final ParcelUuid HSP = |
| 46 | ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB"); |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 47 | public static final ParcelUuid HSP_AG = |
| 48 | ParcelUuid.fromString("00001112-0000-1000-8000-00805F9B34FB"); |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 49 | public static final ParcelUuid Handsfree = |
| 50 | ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB"); |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 51 | public static final ParcelUuid Handsfree_AG = |
| 52 | ParcelUuid.fromString("0000111F-0000-1000-8000-00805F9B34FB"); |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 53 | public static final ParcelUuid AvrcpController = |
| 54 | ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB"); |
| 55 | public static final ParcelUuid AvrcpTarget = |
| 56 | ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB"); |
| 57 | public static final ParcelUuid ObexObjectPush = |
| 58 | ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb"); |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 59 | public static final ParcelUuid Hid = |
Adam Powell | df7627d | 2010-06-21 16:23:42 -0700 | [diff] [blame] | 60 | ParcelUuid.fromString("00001124-0000-1000-8000-00805f9b34fb"); |
Andre Eisenbach | c60bed4 | 2013-03-07 18:07:35 -0800 | [diff] [blame] | 61 | public static final ParcelUuid Hogp = |
| 62 | ParcelUuid.fromString("00001812-0000-1000-8000-00805f9b34fb"); |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 63 | public static final ParcelUuid PANU = |
| 64 | ParcelUuid.fromString("00001115-0000-1000-8000-00805F9B34FB"); |
| 65 | public static final ParcelUuid NAP = |
| 66 | ParcelUuid.fromString("00001116-0000-1000-8000-00805F9B34FB"); |
Jaikumar Ganesh | 3453618 | 2010-08-23 18:32:03 -0700 | [diff] [blame] | 67 | public static final ParcelUuid BNEP = |
| 68 | ParcelUuid.fromString("0000000f-0000-1000-8000-00805F9B34FB"); |
Matthew Xie | 6862361 | 2014-11-20 21:53:26 -0800 | [diff] [blame] | 69 | public static final ParcelUuid PBAP_PCE = |
| 70 | ParcelUuid.fromString("0000112e-0000-1000-8000-00805F9B34FB"); |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 71 | public static final ParcelUuid PBAP_PSE = |
| 72 | ParcelUuid.fromString("0000112f-0000-1000-8000-00805F9B34FB"); |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 73 | public static final ParcelUuid MAP = |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 74 | ParcelUuid.fromString("00001134-0000-1000-8000-00805F9B34FB"); |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 75 | public static final ParcelUuid MNS = |
| 76 | ParcelUuid.fromString("00001133-0000-1000-8000-00805F9B34FB"); |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 77 | public static final ParcelUuid MAS = |
| 78 | ParcelUuid.fromString("00001132-0000-1000-8000-00805F9B34FB"); |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 79 | public static final ParcelUuid SAP = |
| 80 | ParcelUuid.fromString("0000112D-0000-1000-8000-00805F9B34FB"); |
| 81 | |
Wei Wang | 18c7693 | 2013-10-29 21:05:37 -0700 | [diff] [blame] | 82 | public static final ParcelUuid BASE_UUID = |
| 83 | ParcelUuid.fromString("00000000-0000-1000-8000-00805F9B34FB"); |
| 84 | |
Wei Wang | 82500dd | 2014-04-15 14:57:16 -0700 | [diff] [blame] | 85 | /** Length of bytes for 16 bit UUID */ |
| 86 | public static final int UUID_BYTES_16_BIT = 2; |
| 87 | /** Length of bytes for 32 bit UUID */ |
| 88 | public static final int UUID_BYTES_32_BIT = 4; |
| 89 | /** Length of bytes for 128 bit UUID */ |
| 90 | public static final int UUID_BYTES_128_BIT = 16; |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 91 | |
Nick Pelly | 24bb9b8 | 2009-10-02 20:34:18 -0700 | [diff] [blame] | 92 | public static final ParcelUuid[] RESERVED_UUIDS = { |
| 93 | AudioSink, AudioSource, AdvAudioDist, HSP, Handsfree, AvrcpController, AvrcpTarget, |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 94 | ObexObjectPush, PANU, NAP, MAP, MNS, MAS, SAP}; |
Nick Pelly | 24bb9b8 | 2009-10-02 20:34:18 -0700 | [diff] [blame] | 95 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 96 | public static boolean isAudioSource(ParcelUuid uuid) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 97 | return uuid.equals(AudioSource); |
| 98 | } |
| 99 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 100 | public static boolean isAudioSink(ParcelUuid uuid) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 101 | return uuid.equals(AudioSink); |
| 102 | } |
| 103 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 104 | public static boolean isAdvAudioDist(ParcelUuid uuid) { |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 105 | return uuid.equals(AdvAudioDist); |
| 106 | } |
| 107 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 108 | public static boolean isHandsfree(ParcelUuid uuid) { |
Jaikumar Ganesh | 7f74d53 | 2009-07-14 12:21:26 -0700 | [diff] [blame] | 109 | return uuid.equals(Handsfree); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 112 | public static boolean isHeadset(ParcelUuid uuid) { |
Jaikumar Ganesh | ade4052 | 2009-07-30 13:32:25 -0700 | [diff] [blame] | 113 | return uuid.equals(HSP); |
| 114 | } |
| 115 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 116 | public static boolean isAvrcpController(ParcelUuid uuid) { |
Jaikumar Ganesh | ade4052 | 2009-07-30 13:32:25 -0700 | [diff] [blame] | 117 | return uuid.equals(AvrcpController); |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 118 | } |
Jackson Fan | 9abcf09 | 2009-08-19 21:01:29 +0800 | [diff] [blame] | 119 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 120 | public static boolean isAvrcpTarget(ParcelUuid uuid) { |
Jackson Fan | 9abcf09 | 2009-08-19 21:01:29 +0800 | [diff] [blame] | 121 | return uuid.equals(AvrcpTarget); |
| 122 | } |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 123 | |
Jaikumar Ganesh | 545e670 | 2010-06-04 10:23:03 -0700 | [diff] [blame] | 124 | public static boolean isInputDevice(ParcelUuid uuid) { |
| 125 | return uuid.equals(Hid); |
| 126 | } |
| 127 | |
Jaikumar Ganesh | 3453618 | 2010-08-23 18:32:03 -0700 | [diff] [blame] | 128 | public static boolean isPanu(ParcelUuid uuid) { |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 129 | return uuid.equals(PANU); |
| 130 | } |
| 131 | |
Jaikumar Ganesh | 3453618 | 2010-08-23 18:32:03 -0700 | [diff] [blame] | 132 | public static boolean isNap(ParcelUuid uuid) { |
Danica Chang | 6fdd0c6 | 2010-08-11 14:54:43 -0700 | [diff] [blame] | 133 | return uuid.equals(NAP); |
| 134 | } |
Jaikumar Ganesh | 3453618 | 2010-08-23 18:32:03 -0700 | [diff] [blame] | 135 | |
| 136 | public static boolean isBnep(ParcelUuid uuid) { |
| 137 | return uuid.equals(BNEP); |
| 138 | } |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 139 | public static boolean isMap(ParcelUuid uuid) { |
| 140 | return uuid.equals(MAP); |
| 141 | } |
| 142 | public static boolean isMns(ParcelUuid uuid) { |
| 143 | return uuid.equals(MNS); |
| 144 | } |
Kim Schulz | 0d37605 | 2013-08-22 11:18:02 +0200 | [diff] [blame] | 145 | public static boolean isMas(ParcelUuid uuid) { |
| 146 | return uuid.equals(MAS); |
| 147 | } |
Casper Bonde | 2a5f608 | 2015-03-19 10:36:45 +0100 | [diff] [blame] | 148 | public static boolean isSap(ParcelUuid uuid) { |
| 149 | return uuid.equals(SAP); |
| 150 | } |
Matthew Xie | fe3807a | 2013-07-18 17:31:50 -0700 | [diff] [blame] | 151 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 152 | /** |
| 153 | * Returns true if ParcelUuid is present in uuidArray |
| 154 | * |
| 155 | * @param uuidArray - Array of ParcelUuids |
| 156 | * @param uuid |
| 157 | */ |
| 158 | public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) { |
Jaikumar Ganesh | 10eac97 | 2009-09-21 12:48:51 -0700 | [diff] [blame] | 159 | if ((uuidArray == null || uuidArray.length == 0) && uuid == null) |
| 160 | return true; |
| 161 | |
| 162 | if (uuidArray == null) |
| 163 | return false; |
| 164 | |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 165 | for (ParcelUuid element: uuidArray) { |
| 166 | if (element.equals(uuid)) return true; |
| 167 | } |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Returns true if there any common ParcelUuids in uuidA and uuidB. |
| 173 | * |
| 174 | * @param uuidA - List of ParcelUuids |
| 175 | * @param uuidB - List of ParcelUuids |
| 176 | * |
| 177 | */ |
| 178 | public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) { |
| 179 | if (uuidA == null && uuidB == null) return true; |
Jaikumar Ganesh | dca2f0f | 2009-09-16 17:50:52 -0700 | [diff] [blame] | 180 | |
| 181 | if (uuidA == null) { |
| 182 | return uuidB.length == 0 ? true : false; |
| 183 | } |
| 184 | |
| 185 | if (uuidB == null) { |
| 186 | return uuidA.length == 0 ? true : false; |
| 187 | } |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 188 | |
| 189 | HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA)); |
| 190 | for (ParcelUuid uuid: uuidB) { |
| 191 | if (uuidSet.contains(uuid)) return true; |
| 192 | } |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Returns true if all the ParcelUuids in ParcelUuidB are present in |
| 198 | * ParcelUuidA |
| 199 | * |
| 200 | * @param uuidA - Array of ParcelUuidsA |
| 201 | * @param uuidB - Array of ParcelUuidsB |
| 202 | * |
| 203 | */ |
| 204 | public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) { |
| 205 | if (uuidA == null && uuidB == null) return true; |
Jaikumar Ganesh | dca2f0f | 2009-09-16 17:50:52 -0700 | [diff] [blame] | 206 | |
| 207 | if (uuidA == null) { |
| 208 | return uuidB.length == 0 ? true : false; |
| 209 | } |
| 210 | |
| 211 | if (uuidB == null) return true; |
Jaikumar Ganesh | dd0463a | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 212 | |
| 213 | HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA)); |
| 214 | for (ParcelUuid uuid: uuidB) { |
| 215 | if (!uuidSet.contains(uuid)) return false; |
| 216 | } |
| 217 | return true; |
| 218 | } |
| 219 | |
Jaikumar Ganesh | 84690c8 | 2010-12-10 12:48:58 -0800 | [diff] [blame] | 220 | /** |
| 221 | * Extract the Service Identifier or the actual uuid from the Parcel Uuid. |
| 222 | * For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid, |
| 223 | * this function will return 110B |
| 224 | * @param parcelUuid |
| 225 | * @return the service identifier. |
| 226 | */ |
| 227 | public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) { |
| 228 | UUID uuid = parcelUuid.getUuid(); |
| 229 | long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32; |
| 230 | return (int)value; |
| 231 | } |
Wei Wang | 18c7693 | 2013-10-29 21:05:37 -0700 | [diff] [blame] | 232 | |
| 233 | /** |
Wei Wang | 82500dd | 2014-04-15 14:57:16 -0700 | [diff] [blame] | 234 | * Parse UUID from bytes. The {@code uuidBytes} can represent a 16-bit, 32-bit or 128-bit UUID, |
| 235 | * but the returned UUID is always in 128-bit format. |
| 236 | * Note UUID is little endian in Bluetooth. |
| 237 | * |
| 238 | * @param uuidBytes Byte representation of uuid. |
| 239 | * @return {@link ParcelUuid} parsed from bytes. |
| 240 | * @throws IllegalArgumentException If the {@code uuidBytes} cannot be parsed. |
| 241 | */ |
| 242 | public static ParcelUuid parseUuidFrom(byte[] uuidBytes) { |
| 243 | if (uuidBytes == null) { |
| 244 | throw new IllegalArgumentException("uuidBytes cannot be null"); |
| 245 | } |
| 246 | int length = uuidBytes.length; |
| 247 | if (length != UUID_BYTES_16_BIT && length != UUID_BYTES_32_BIT && |
| 248 | length != UUID_BYTES_128_BIT) { |
| 249 | throw new IllegalArgumentException("uuidBytes length invalid - " + length); |
| 250 | } |
| 251 | |
| 252 | // Construct a 128 bit UUID. |
| 253 | if (length == UUID_BYTES_128_BIT) { |
| 254 | ByteBuffer buf = ByteBuffer.wrap(uuidBytes).order(ByteOrder.LITTLE_ENDIAN); |
| 255 | long msb = buf.getLong(8); |
| 256 | long lsb = buf.getLong(0); |
| 257 | return new ParcelUuid(new UUID(msb, lsb)); |
| 258 | } |
| 259 | |
| 260 | // For 16 bit and 32 bit UUID we need to convert them to 128 bit value. |
| 261 | // 128_bit_value = uuid * 2^96 + BASE_UUID |
| 262 | long shortUuid; |
| 263 | if (length == UUID_BYTES_16_BIT) { |
| 264 | shortUuid = uuidBytes[0] & 0xFF; |
| 265 | shortUuid += (uuidBytes[1] & 0xFF) << 8; |
| 266 | } else { |
| 267 | shortUuid = uuidBytes[0] & 0xFF ; |
| 268 | shortUuid += (uuidBytes[1] & 0xFF) << 8; |
| 269 | shortUuid += (uuidBytes[2] & 0xFF) << 16; |
| 270 | shortUuid += (uuidBytes[3] & 0xFF) << 24; |
| 271 | } |
| 272 | long msb = BASE_UUID.getUuid().getMostSignificantBits() + (shortUuid << 32); |
| 273 | long lsb = BASE_UUID.getUuid().getLeastSignificantBits(); |
| 274 | return new ParcelUuid(new UUID(msb, lsb)); |
| 275 | } |
| 276 | |
| 277 | /** |
Jakub Pawlowski | f67ee83 | 2016-10-24 13:56:54 -0700 | [diff] [blame] | 278 | * Parse UUID to bytes. The returned value is shortest representation, a 16-bit, 32-bit or 128-bit UUID, |
| 279 | * Note returned value is little endian (Bluetooth). |
| 280 | * |
| 281 | * @param uuid uuid to parse. |
| 282 | * @return shortest representation of {@code uuid} as bytes. |
| 283 | * @throws IllegalArgumentException If the {@code uuid} is null. |
| 284 | */ |
| 285 | public static byte[] uuidToBytes(ParcelUuid uuid) { |
| 286 | if (uuid == null) { |
| 287 | throw new IllegalArgumentException("uuid cannot be null"); |
| 288 | } |
| 289 | |
| 290 | if (is16BitUuid(uuid)) { |
| 291 | byte[] uuidBytes = new byte[UUID_BYTES_16_BIT]; |
| 292 | int uuidVal = getServiceIdentifierFromParcelUuid(uuid); |
| 293 | uuidBytes[0] = (byte)(uuidVal & 0xFF); |
| 294 | uuidBytes[1] = (byte)((uuidVal & 0xFF00) >> 8); |
| 295 | return uuidBytes; |
| 296 | } |
| 297 | |
| 298 | if (is32BitUuid(uuid)) { |
| 299 | byte[] uuidBytes = new byte[UUID_BYTES_32_BIT]; |
| 300 | int uuidVal = getServiceIdentifierFromParcelUuid(uuid); |
| 301 | uuidBytes[0] = (byte)(uuidVal & 0xFF); |
| 302 | uuidBytes[1] = (byte)((uuidVal & 0xFF00) >> 8); |
| 303 | uuidBytes[2] = (byte)((uuidVal & 0xFF0000) >> 16); |
| 304 | uuidBytes[3] = (byte)((uuidVal & 0xFF000000) >> 24); |
| 305 | return uuidBytes; |
| 306 | } |
| 307 | |
| 308 | // Construct a 128 bit UUID. |
| 309 | long msb = uuid.getUuid().getMostSignificantBits(); |
| 310 | long lsb = uuid.getUuid().getLeastSignificantBits(); |
| 311 | |
| 312 | byte[] uuidBytes = new byte[UUID_BYTES_128_BIT]; |
| 313 | ByteBuffer buf = ByteBuffer.wrap(uuidBytes).order(ByteOrder.LITTLE_ENDIAN); |
| 314 | buf.putLong(8, msb); |
| 315 | buf.putLong(0, lsb); |
| 316 | return uuidBytes; |
| 317 | } |
| 318 | |
| 319 | /** |
Wei Wang | 18c7693 | 2013-10-29 21:05:37 -0700 | [diff] [blame] | 320 | * Check whether the given parcelUuid can be converted to 16 bit bluetooth uuid. |
Wei Wang | 82500dd | 2014-04-15 14:57:16 -0700 | [diff] [blame] | 321 | * |
Wei Wang | 18c7693 | 2013-10-29 21:05:37 -0700 | [diff] [blame] | 322 | * @param parcelUuid |
| 323 | * @return true if the parcelUuid can be converted to 16 bit uuid, false otherwise. |
| 324 | */ |
Wei Wang | 5180084 | 2014-05-07 14:54:43 -0700 | [diff] [blame] | 325 | public static boolean is16BitUuid(ParcelUuid parcelUuid) { |
Wei Wang | 82500dd | 2014-04-15 14:57:16 -0700 | [diff] [blame] | 326 | UUID uuid = parcelUuid.getUuid(); |
| 327 | if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) { |
| 328 | return false; |
| 329 | } |
| 330 | return ((uuid.getMostSignificantBits() & 0xFFFF0000FFFFFFFFL) == 0x1000L); |
Wei Wang | 18c7693 | 2013-10-29 21:05:37 -0700 | [diff] [blame] | 331 | } |
Wei Wang | 5180084 | 2014-05-07 14:54:43 -0700 | [diff] [blame] | 332 | |
| 333 | |
| 334 | /** |
| 335 | * Check whether the given parcelUuid can be converted to 32 bit bluetooth uuid. |
| 336 | * |
| 337 | * @param parcelUuid |
| 338 | * @return true if the parcelUuid can be converted to 32 bit uuid, false otherwise. |
| 339 | */ |
| 340 | public static boolean is32BitUuid(ParcelUuid parcelUuid) { |
| 341 | UUID uuid = parcelUuid.getUuid(); |
| 342 | if (uuid.getLeastSignificantBits() != BASE_UUID.getUuid().getLeastSignificantBits()) { |
| 343 | return false; |
| 344 | } |
| 345 | if (is16BitUuid(parcelUuid)) { |
| 346 | return false; |
| 347 | } |
| 348 | return ((uuid.getMostSignificantBits() & 0xFFFFFFFFL) == 0x1000L); |
| 349 | } |
Jaikumar Ganesh | d5ac1ae | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 350 | } |