BluetoothUuid.java revision dd0463aef18d251c741bfc9dc7a2787443ef36f1
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
17package android.bluetooth;
18
19import java.util.Arrays;
20import java.util.HashSet;
21
22/**
23* Static helper methods and constants to decode the ParcelUuid of remote devices.
24*  @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     */
34    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");
50
51    public static boolean isAudioSource(ParcelUuid uuid) {
52        return uuid.equals(AudioSource);
53    }
54
55    public static boolean isAudioSink(ParcelUuid uuid) {
56        return uuid.equals(AudioSink);
57    }
58
59    public static boolean isAdvAudioDist(ParcelUuid uuid) {
60        return uuid.equals(AdvAudioDist);
61    }
62
63    public static boolean isHandsfree(ParcelUuid uuid) {
64        return uuid.equals(Handsfree);
65    }
66
67    public static boolean isHeadset(ParcelUuid uuid) {
68        return uuid.equals(HSP);
69    }
70
71    public static boolean isAvrcpController(ParcelUuid uuid) {
72        return uuid.equals(AvrcpController);
73    }
74
75    public static boolean isAvrcpTarget(ParcelUuid uuid) {
76        return uuid.equals(AvrcpTarget);
77    }
78
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) {
86        for (ParcelUuid element: uuidArray) {
87            if (element.equals(uuid)) return true;
88        }
89        return false;
90    }
91
92    /**
93     * Returns true if there any common ParcelUuids in uuidA and uuidB.
94     *
95     * @param uuidA - List of ParcelUuids
96     * @param uuidB - List of ParcelUuids
97     *
98     */
99    public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
100        if (uuidA == null && uuidB == null) return true;
101        if (uuidA == null || uuidB == null) return false;
102
103        HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
104        for (ParcelUuid uuid: uuidB) {
105            if (uuidSet.contains(uuid)) return true;
106        }
107        return false;
108    }
109
110    /**
111     * Returns true if all the ParcelUuids in ParcelUuidB are present in
112     * ParcelUuidA
113     *
114     * @param uuidA - Array of ParcelUuidsA
115     * @param uuidB - Array of ParcelUuidsB
116     *
117     */
118    public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
119        if (uuidA == null && uuidB == null) return true;
120        if (uuidA == null || uuidB == null) return false;
121
122        HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
123        for (ParcelUuid uuid: uuidB) {
124            if (!uuidSet.contains(uuid)) return false;
125        }
126        return true;
127    }
128
129}
130