• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.os.ParcelUuid;
20 
21 import java.util.Arrays;
22 import java.util.HashSet;
23 
24 /**
25 * Static helper methods and constants to decode the ParcelUuid of remote devices.
26 *  @hide
27 */
28 public 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      */
36     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");
52 
53     public static final ParcelUuid[] RESERVED_UUIDS = {
54         AudioSink, AudioSource, AdvAudioDist, HSP, Handsfree, AvrcpController, AvrcpTarget,
55         ObexObjectPush};
56 
isAudioSource(ParcelUuid uuid)57     public static boolean isAudioSource(ParcelUuid uuid) {
58         return uuid.equals(AudioSource);
59     }
60 
isAudioSink(ParcelUuid uuid)61     public static boolean isAudioSink(ParcelUuid uuid) {
62         return uuid.equals(AudioSink);
63     }
64 
isAdvAudioDist(ParcelUuid uuid)65     public static boolean isAdvAudioDist(ParcelUuid uuid) {
66         return uuid.equals(AdvAudioDist);
67     }
68 
isHandsfree(ParcelUuid uuid)69     public static boolean isHandsfree(ParcelUuid uuid) {
70         return uuid.equals(Handsfree);
71     }
72 
isHeadset(ParcelUuid uuid)73     public static boolean isHeadset(ParcelUuid uuid) {
74         return uuid.equals(HSP);
75     }
76 
isAvrcpController(ParcelUuid uuid)77     public static boolean isAvrcpController(ParcelUuid uuid) {
78         return uuid.equals(AvrcpController);
79     }
80 
isAvrcpTarget(ParcelUuid uuid)81     public static boolean isAvrcpTarget(ParcelUuid uuid) {
82         return uuid.equals(AvrcpTarget);
83     }
84 
85     /**
86      * Returns true if ParcelUuid is present in uuidArray
87      *
88      * @param uuidArray - Array of ParcelUuids
89      * @param uuid
90      */
isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid)91     public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
92         if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
93             return true;
94 
95         if (uuidArray == null)
96             return false;
97 
98         for (ParcelUuid element: uuidArray) {
99             if (element.equals(uuid)) return true;
100         }
101         return false;
102     }
103 
104     /**
105      * Returns true if there any common ParcelUuids in uuidA and uuidB.
106      *
107      * @param uuidA - List of ParcelUuids
108      * @param uuidB - List of ParcelUuids
109      *
110      */
containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB)111     public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
112         if (uuidA == null && uuidB == null) return true;
113 
114         if (uuidA == null) {
115             return uuidB.length == 0 ? true : false;
116         }
117 
118         if (uuidB == null) {
119             return uuidA.length == 0 ? true : false;
120         }
121 
122         HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
123         for (ParcelUuid uuid: uuidB) {
124             if (uuidSet.contains(uuid)) return true;
125         }
126         return false;
127     }
128 
129     /**
130      * Returns true if all the ParcelUuids in ParcelUuidB are present in
131      * ParcelUuidA
132      *
133      * @param uuidA - Array of ParcelUuidsA
134      * @param uuidB - Array of ParcelUuidsB
135      *
136      */
containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB)137     public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
138         if (uuidA == null && uuidB == null) return true;
139 
140         if (uuidA == null) {
141             return uuidB.length == 0 ? true : false;
142         }
143 
144         if (uuidB == null) return true;
145 
146         HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
147         for (ParcelUuid uuid: uuidB) {
148             if (!uuidSet.contains(uuid)) return false;
149         }
150         return true;
151     }
152 
153 }
154