blob: da0564a2a057aa608e31f2e9aca58aa12a22718b [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 Ganesh879bf5b2009-05-05 22:26:12 -070023
24/**
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070025* Static helper methods and constants to decode the ParcelUuid of remote devices.
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070026* @hide
27*/
28public final class BluetoothUuid {
29
30 /* See Bluetooth Assigned Numbers document - SDP section, to get the values of UUIDs
31 * for the various services.
32 *
33 * The following 128 bit values are calculated as:
34 * uuid * 2^96 + BASE_UUID
35 */
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070036 public static final ParcelUuid AudioSink =
37 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
38 public static final ParcelUuid AudioSource =
39 ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
40 public static final ParcelUuid AdvAudioDist =
41 ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB");
42 public static final ParcelUuid HSP =
43 ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB");
44 public static final ParcelUuid Handsfree =
45 ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB");
46 public static final ParcelUuid AvrcpController =
47 ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB");
48 public static final ParcelUuid AvrcpTarget =
49 ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB");
50 public static final ParcelUuid ObexObjectPush =
51 ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb");
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070052
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070053 public static boolean isAudioSource(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070054 return uuid.equals(AudioSource);
55 }
56
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070057 public static boolean isAudioSink(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070058 return uuid.equals(AudioSink);
59 }
60
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070061 public static boolean isAdvAudioDist(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070062 return uuid.equals(AdvAudioDist);
63 }
64
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070065 public static boolean isHandsfree(ParcelUuid uuid) {
Jaikumar Ganesh4eb5ccc2009-07-14 12:21:26 -070066 return uuid.equals(Handsfree);
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070067 }
68
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070069 public static boolean isHeadset(ParcelUuid uuid) {
Jaikumar Ganesh671065d2009-07-30 13:32:25 -070070 return uuid.equals(HSP);
71 }
72
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070073 public static boolean isAvrcpController(ParcelUuid uuid) {
Jaikumar Ganesh671065d2009-07-30 13:32:25 -070074 return uuid.equals(AvrcpController);
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070075 }
Jackson Fan0d538762009-08-19 21:01:29 +080076
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070077 public static boolean isAvrcpTarget(ParcelUuid uuid) {
Jackson Fan0d538762009-08-19 21:01:29 +080078 return uuid.equals(AvrcpTarget);
79 }
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070080
81 /**
82 * Returns true if ParcelUuid is present in uuidArray
83 *
84 * @param uuidArray - Array of ParcelUuids
85 * @param uuid
86 */
87 public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
Jaikumar Ganesh391e8a72009-09-21 12:48:51 -070088 if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
89 return true;
90
91 if (uuidArray == null)
92 return false;
93
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070094 for (ParcelUuid element: uuidArray) {
95 if (element.equals(uuid)) return true;
96 }
97 return false;
98 }
99
100 /**
101 * Returns true if there any common ParcelUuids in uuidA and uuidB.
102 *
103 * @param uuidA - List of ParcelUuids
104 * @param uuidB - List of ParcelUuids
105 *
106 */
107 public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
108 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganesh97c84ce2009-09-16 17:50:52 -0700109
110 if (uuidA == null) {
111 return uuidB.length == 0 ? true : false;
112 }
113
114 if (uuidB == null) {
115 return uuidA.length == 0 ? true : false;
116 }
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700117
118 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
119 for (ParcelUuid uuid: uuidB) {
120 if (uuidSet.contains(uuid)) return true;
121 }
122 return false;
123 }
124
125 /**
126 * Returns true if all the ParcelUuids in ParcelUuidB are present in
127 * ParcelUuidA
128 *
129 * @param uuidA - Array of ParcelUuidsA
130 * @param uuidB - Array of ParcelUuidsB
131 *
132 */
133 public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
134 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganesh97c84ce2009-09-16 17:50:52 -0700135
136 if (uuidA == null) {
137 return uuidB.length == 0 ? true : false;
138 }
139
140 if (uuidB == null) return true;
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700141
142 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
143 for (ParcelUuid uuid: uuidB) {
144 if (!uuidSet.contains(uuid)) return false;
145 }
146 return true;
147 }
148
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -0700149}