| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 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 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 19 | import java.util.Arrays; |
| 20 | import java.util.HashSet; |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 23 | * Static helper methods and constants to decode the ParcelUuid of remote devices. |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 24 | * @hide |
| 25 | */ |
| 26 | public 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 Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 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"); |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 50 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 51 | public static boolean isAudioSource(ParcelUuid uuid) { |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 52 | return uuid.equals(AudioSource); |
| 53 | } |
| 54 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 55 | public static boolean isAudioSink(ParcelUuid uuid) { |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 56 | return uuid.equals(AudioSink); |
| 57 | } |
| 58 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 59 | public static boolean isAdvAudioDist(ParcelUuid uuid) { |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 60 | return uuid.equals(AdvAudioDist); |
| 61 | } |
| 62 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 63 | public static boolean isHandsfree(ParcelUuid uuid) { |
| Jaikumar Ganesh | 4eb5ccc | 2009-07-14 12:21:26 -0700 | [diff] [blame] | 64 | return uuid.equals(Handsfree); |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 67 | public static boolean isHeadset(ParcelUuid uuid) { |
| Jaikumar Ganesh | 671065d | 2009-07-30 13:32:25 -0700 | [diff] [blame] | 68 | return uuid.equals(HSP); |
| 69 | } |
| 70 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 71 | public static boolean isAvrcpController(ParcelUuid uuid) { |
| Jaikumar Ganesh | 671065d | 2009-07-30 13:32:25 -0700 | [diff] [blame] | 72 | return uuid.equals(AvrcpController); |
| Jaikumar Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 73 | } |
| Jackson Fan | 0d53876 | 2009-08-19 21:01:29 +0800 | [diff] [blame] | 74 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 75 | public static boolean isAvrcpTarget(ParcelUuid uuid) { |
| Jackson Fan | 0d53876 | 2009-08-19 21:01:29 +0800 | [diff] [blame] | 76 | return uuid.equals(AvrcpTarget); |
| 77 | } |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 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) { |
| Jaikumar Ganesh | 391e8a7 | 2009-09-21 12:48:51 -0700 | [diff] [blame^] | 86 | if ((uuidArray == null || uuidArray.length == 0) && uuid == null) |
| 87 | return true; |
| 88 | |
| 89 | if (uuidArray == null) |
| 90 | return false; |
| 91 | |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 92 | 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 Ganesh | 97c84ce | 2009-09-16 17:50:52 -0700 | [diff] [blame] | 107 | |
| 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 Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 115 | |
| 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 Ganesh | 97c84ce | 2009-09-16 17:50:52 -0700 | [diff] [blame] | 133 | |
| 134 | if (uuidA == null) { |
| 135 | return uuidB.length == 0 ? true : false; |
| 136 | } |
| 137 | |
| 138 | if (uuidB == null) return true; |
| Jaikumar Ganesh | 55a0c03 | 2009-09-16 12:30:02 -0700 | [diff] [blame] | 139 | |
| 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 Ganesh | 879bf5b | 2009-05-05 22:26:12 -0700 | [diff] [blame] | 147 | } |