BluetoothUuid.java revision dca2f0fec30e6acbdc466fd6dffb425877e7728a
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 102 if (uuidA == null) { 103 return uuidB.length == 0 ? true : false; 104 } 105 106 if (uuidB == null) { 107 return uuidA.length == 0 ? true : false; 108 } 109 110 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA)); 111 for (ParcelUuid uuid: uuidB) { 112 if (uuidSet.contains(uuid)) return true; 113 } 114 return false; 115 } 116 117 /** 118 * Returns true if all the ParcelUuids in ParcelUuidB are present in 119 * ParcelUuidA 120 * 121 * @param uuidA - Array of ParcelUuidsA 122 * @param uuidB - Array of ParcelUuidsB 123 * 124 */ 125 public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) { 126 if (uuidA == null && uuidB == null) return true; 127 128 if (uuidA == null) { 129 return uuidB.length == 0 ? true : false; 130 } 131 132 if (uuidB == null) return true; 133 134 HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA)); 135 for (ParcelUuid uuid: uuidB) { 136 if (!uuidSet.contains(uuid)) return false; 137 } 138 return true; 139 } 140 141} 142