blob: 6609b988b253b1445efd0d9bef700cf0da541b0a [file] [log] [blame]
Jaikumar Ganesh879bf5b2009-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
Nick Pelly03759e52009-09-28 12:33:17 -070019import android.os.ParcelUuid;
20
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070021import java.util.Arrays;
22import java.util.HashSet;
Jaikumar Ganesh166a60e2010-12-10 12:48:58 -080023import java.util.UUID;
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070024
25/**
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070026* Static helper methods and constants to decode the ParcelUuid of remote devices.
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070027* @hide
28*/
29public final class BluetoothUuid {
30
31 /* See Bluetooth Assigned Numbers document - SDP section, to get the values of UUIDs
32 * for the various services.
33 *
34 * The following 128 bit values are calculated as:
35 * uuid * 2^96 + BASE_UUID
36 */
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070037 public static final ParcelUuid AudioSink =
38 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
39 public static final ParcelUuid AudioSource =
40 ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
41 public static final ParcelUuid AdvAudioDist =
42 ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB");
43 public static final ParcelUuid HSP =
44 ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh166a60e2010-12-10 12:48:58 -080045 public static final ParcelUuid HSP_AG =
46 ParcelUuid.fromString("00001112-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070047 public static final ParcelUuid Handsfree =
48 ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh166a60e2010-12-10 12:48:58 -080049 public static final ParcelUuid Handsfree_AG =
50 ParcelUuid.fromString("0000111F-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070051 public static final ParcelUuid AvrcpController =
52 ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB");
53 public static final ParcelUuid AvrcpTarget =
54 ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB");
55 public static final ParcelUuid ObexObjectPush =
56 ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb");
Jaikumar Ganesh5d0b83e2010-06-04 10:23:03 -070057 public static final ParcelUuid Hid =
Adam Powell026e8572010-06-21 16:23:42 -070058 ParcelUuid.fromString("00001124-0000-1000-8000-00805f9b34fb");
Andre Eisenbach1f0c3da2013-03-07 18:07:35 -080059 public static final ParcelUuid Hogp =
60 ParcelUuid.fromString("00001812-0000-1000-8000-00805f9b34fb");
Danica Chang41f1a092010-08-11 14:54:43 -070061 public static final ParcelUuid PANU =
62 ParcelUuid.fromString("00001115-0000-1000-8000-00805F9B34FB");
63 public static final ParcelUuid NAP =
64 ParcelUuid.fromString("00001116-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh43d545d2010-08-23 18:32:03 -070065 public static final ParcelUuid BNEP =
66 ParcelUuid.fromString("0000000f-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh166a60e2010-12-10 12:48:58 -080067 public static final ParcelUuid PBAP_PSE =
68 ParcelUuid.fromString("0000112f-0000-1000-8000-00805F9B34FB");
Matthew Xiece145222013-07-18 17:31:50 -070069 public static final ParcelUuid MAP =
70 ParcelUuid.fromString("00001132-0000-1000-8000-00805F9B34FB");
71 public static final ParcelUuid MNS =
72 ParcelUuid.fromString("00001133-0000-1000-8000-00805F9B34FB");
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070073
Nick Pellyee1402d2009-10-02 20:34:18 -070074 public static final ParcelUuid[] RESERVED_UUIDS = {
75 AudioSink, AudioSource, AdvAudioDist, HSP, Handsfree, AvrcpController, AvrcpTarget,
Matthew Xiece145222013-07-18 17:31:50 -070076 ObexObjectPush, PANU, NAP, MAP, MNS};
Nick Pellyee1402d2009-10-02 20:34:18 -070077
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070078 public static boolean isAudioSource(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070079 return uuid.equals(AudioSource);
80 }
81
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070082 public static boolean isAudioSink(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070083 return uuid.equals(AudioSink);
84 }
85
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070086 public static boolean isAdvAudioDist(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070087 return uuid.equals(AdvAudioDist);
88 }
89
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070090 public static boolean isHandsfree(ParcelUuid uuid) {
Jaikumar Ganesh4eb5ccc2009-07-14 12:21:26 -070091 return uuid.equals(Handsfree);
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070092 }
93
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070094 public static boolean isHeadset(ParcelUuid uuid) {
Jaikumar Ganesh671065d2009-07-30 13:32:25 -070095 return uuid.equals(HSP);
96 }
97
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070098 public static boolean isAvrcpController(ParcelUuid uuid) {
Jaikumar Ganesh671065d2009-07-30 13:32:25 -070099 return uuid.equals(AvrcpController);
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -0700100 }
Jackson Fan0d538762009-08-19 21:01:29 +0800101
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700102 public static boolean isAvrcpTarget(ParcelUuid uuid) {
Jackson Fan0d538762009-08-19 21:01:29 +0800103 return uuid.equals(AvrcpTarget);
104 }
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700105
Jaikumar Ganesh5d0b83e2010-06-04 10:23:03 -0700106 public static boolean isInputDevice(ParcelUuid uuid) {
107 return uuid.equals(Hid);
108 }
109
Jaikumar Ganesh43d545d2010-08-23 18:32:03 -0700110 public static boolean isPanu(ParcelUuid uuid) {
Danica Chang41f1a092010-08-11 14:54:43 -0700111 return uuid.equals(PANU);
112 }
113
Jaikumar Ganesh43d545d2010-08-23 18:32:03 -0700114 public static boolean isNap(ParcelUuid uuid) {
Danica Chang41f1a092010-08-11 14:54:43 -0700115 return uuid.equals(NAP);
116 }
Jaikumar Ganesh43d545d2010-08-23 18:32:03 -0700117
118 public static boolean isBnep(ParcelUuid uuid) {
119 return uuid.equals(BNEP);
120 }
Matthew Xiece145222013-07-18 17:31:50 -0700121 public static boolean isMap(ParcelUuid uuid) {
122 return uuid.equals(MAP);
123 }
124 public static boolean isMns(ParcelUuid uuid) {
125 return uuid.equals(MNS);
126 }
127
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700128 /**
129 * Returns true if ParcelUuid is present in uuidArray
130 *
131 * @param uuidArray - Array of ParcelUuids
132 * @param uuid
133 */
134 public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
Jaikumar Ganesh391e8a72009-09-21 12:48:51 -0700135 if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
136 return true;
137
138 if (uuidArray == null)
139 return false;
140
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700141 for (ParcelUuid element: uuidArray) {
142 if (element.equals(uuid)) return true;
143 }
144 return false;
145 }
146
147 /**
148 * Returns true if there any common ParcelUuids in uuidA and uuidB.
149 *
150 * @param uuidA - List of ParcelUuids
151 * @param uuidB - List of ParcelUuids
152 *
153 */
154 public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
155 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganesh97c84ce2009-09-16 17:50:52 -0700156
157 if (uuidA == null) {
158 return uuidB.length == 0 ? true : false;
159 }
160
161 if (uuidB == null) {
162 return uuidA.length == 0 ? true : false;
163 }
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700164
165 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
166 for (ParcelUuid uuid: uuidB) {
167 if (uuidSet.contains(uuid)) return true;
168 }
169 return false;
170 }
171
172 /**
173 * Returns true if all the ParcelUuids in ParcelUuidB are present in
174 * ParcelUuidA
175 *
176 * @param uuidA - Array of ParcelUuidsA
177 * @param uuidB - Array of ParcelUuidsB
178 *
179 */
180 public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
181 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganesh97c84ce2009-09-16 17:50:52 -0700182
183 if (uuidA == null) {
184 return uuidB.length == 0 ? true : false;
185 }
186
187 if (uuidB == null) return true;
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700188
189 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
190 for (ParcelUuid uuid: uuidB) {
191 if (!uuidSet.contains(uuid)) return false;
192 }
193 return true;
194 }
195
Jaikumar Ganesh166a60e2010-12-10 12:48:58 -0800196 /**
197 * Extract the Service Identifier or the actual uuid from the Parcel Uuid.
198 * For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid,
199 * this function will return 110B
200 * @param parcelUuid
201 * @return the service identifier.
202 */
203 public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
204 UUID uuid = parcelUuid.getUuid();
205 long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32;
206 return (int)value;
207 }
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -0700208}