blob: 24ad06a997a46e02c37efdf81a979c47adbd9fdc [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
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070019import java.util.Arrays;
20import java.util.HashSet;
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070021
22/**
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070023* Static helper methods and constants to decode the ParcelUuid of remote devices.
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070024* @hide
25*/
26public final class BluetoothUuid {
27
28 /* See Bluetooth Assigned Numbers document - SDP section, to get the values of UUIDs
29 * for the various services.
30 *
31 * The following 128 bit values are calculated as:
32 * uuid * 2^96 + BASE_UUID
33 */
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070034 public static final ParcelUuid AudioSink =
35 ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
36 public static final ParcelUuid AudioSource =
37 ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
38 public static final ParcelUuid AdvAudioDist =
39 ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB");
40 public static final ParcelUuid HSP =
41 ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB");
42 public static final ParcelUuid Handsfree =
43 ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB");
44 public static final ParcelUuid AvrcpController =
45 ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB");
46 public static final ParcelUuid AvrcpTarget =
47 ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB");
48 public static final ParcelUuid ObexObjectPush =
49 ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb");
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070050
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070051 public static boolean isAudioSource(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070052 return uuid.equals(AudioSource);
53 }
54
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070055 public static boolean isAudioSink(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070056 return uuid.equals(AudioSink);
57 }
58
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070059 public static boolean isAdvAudioDist(ParcelUuid uuid) {
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070060 return uuid.equals(AdvAudioDist);
61 }
62
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070063 public static boolean isHandsfree(ParcelUuid uuid) {
Jaikumar Ganesh4eb5ccc2009-07-14 12:21:26 -070064 return uuid.equals(Handsfree);
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070065 }
66
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070067 public static boolean isHeadset(ParcelUuid uuid) {
Jaikumar Ganesh671065d2009-07-30 13:32:25 -070068 return uuid.equals(HSP);
69 }
70
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070071 public static boolean isAvrcpController(ParcelUuid uuid) {
Jaikumar Ganesh671065d2009-07-30 13:32:25 -070072 return uuid.equals(AvrcpController);
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -070073 }
Jackson Fan0d538762009-08-19 21:01:29 +080074
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070075 public static boolean isAvrcpTarget(ParcelUuid uuid) {
Jackson Fan0d538762009-08-19 21:01:29 +080076 return uuid.equals(AvrcpTarget);
77 }
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070078
79 /**
80 * Returns true if ParcelUuid is present in uuidArray
81 *
82 * @param uuidArray - Array of ParcelUuids
83 * @param uuid
84 */
85 public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
Jaikumar Ganesh391e8a72009-09-21 12:48:51 -070086 if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
87 return true;
88
89 if (uuidArray == null)
90 return false;
91
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -070092 for (ParcelUuid element: uuidArray) {
93 if (element.equals(uuid)) return true;
94 }
95 return false;
96 }
97
98 /**
99 * Returns true if there any common ParcelUuids in uuidA and uuidB.
100 *
101 * @param uuidA - List of ParcelUuids
102 * @param uuidB - List of ParcelUuids
103 *
104 */
105 public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
106 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganesh97c84ce2009-09-16 17:50:52 -0700107
108 if (uuidA == null) {
109 return uuidB.length == 0 ? true : false;
110 }
111
112 if (uuidB == null) {
113 return uuidA.length == 0 ? true : false;
114 }
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700115
116 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
117 for (ParcelUuid uuid: uuidB) {
118 if (uuidSet.contains(uuid)) return true;
119 }
120 return false;
121 }
122
123 /**
124 * Returns true if all the ParcelUuids in ParcelUuidB are present in
125 * ParcelUuidA
126 *
127 * @param uuidA - Array of ParcelUuidsA
128 * @param uuidB - Array of ParcelUuidsB
129 *
130 */
131 public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
132 if (uuidA == null && uuidB == null) return true;
Jaikumar Ganesh97c84ce2009-09-16 17:50:52 -0700133
134 if (uuidA == null) {
135 return uuidB.length == 0 ? true : false;
136 }
137
138 if (uuidB == null) return true;
Jaikumar Ganesh55a0c032009-09-16 12:30:02 -0700139
140 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
141 for (ParcelUuid uuid: uuidB) {
142 if (!uuidSet.contains(uuid)) return false;
143 }
144 return true;
145 }
146
Jaikumar Ganesh879bf5b2009-05-05 22:26:12 -0700147}