Home | History | Annotate | Download | only in bluetooth
      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 import java.util.UUID;
     24 
     25 /**
     26 * Static helper methods and constants to decode the ParcelUuid of remote devices.
     27 *  @hide
     28 */
     29 public final class BluetoothUuid {
     30 
     31     /* See Bluetooth Assigned Numbers document - SDP section, to get the values of UUIDs
     32      * for the various services.
     33      *
     34      * The following 128 bit values are calculated as:
     35      *  uuid * 2^96 + BASE_UUID
     36      */
     37     public static final ParcelUuid AudioSink =
     38             ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
     39     public static final ParcelUuid AudioSource =
     40             ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
     41     public static final ParcelUuid AdvAudioDist =
     42             ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB");
     43     public static final ParcelUuid HSP =
     44             ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB");
     45     public static final ParcelUuid HSP_AG =
     46             ParcelUuid.fromString("00001112-0000-1000-8000-00805F9B34FB");
     47     public static final ParcelUuid Handsfree =
     48             ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB");
     49     public static final ParcelUuid Handsfree_AG =
     50             ParcelUuid.fromString("0000111F-0000-1000-8000-00805F9B34FB");
     51     public static final ParcelUuid AvrcpController =
     52             ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB");
     53     public static final ParcelUuid AvrcpTarget =
     54             ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB");
     55     public static final ParcelUuid ObexObjectPush =
     56             ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb");
     57     public static final ParcelUuid Hid =
     58             ParcelUuid.fromString("00001124-0000-1000-8000-00805f9b34fb");
     59     public static final ParcelUuid Hogp =
     60             ParcelUuid.fromString("00001812-0000-1000-8000-00805f9b34fb");
     61     public static final ParcelUuid PANU =
     62             ParcelUuid.fromString("00001115-0000-1000-8000-00805F9B34FB");
     63     public static final ParcelUuid NAP =
     64             ParcelUuid.fromString("00001116-0000-1000-8000-00805F9B34FB");
     65     public static final ParcelUuid BNEP =
     66             ParcelUuid.fromString("0000000f-0000-1000-8000-00805F9B34FB");
     67     public static final ParcelUuid PBAP_PSE =
     68             ParcelUuid.fromString("0000112f-0000-1000-8000-00805F9B34FB");
     69     public static final ParcelUuid MAP =
     70             ParcelUuid.fromString("00001134-0000-1000-8000-00805F9B34FB");
     71     public static final ParcelUuid MNS =
     72             ParcelUuid.fromString("00001133-0000-1000-8000-00805F9B34FB");
     73     public static final ParcelUuid MAS =
     74             ParcelUuid.fromString("00001132-0000-1000-8000-00805F9B34FB");
     75 
     76 
     77     public static final ParcelUuid[] RESERVED_UUIDS = {
     78         AudioSink, AudioSource, AdvAudioDist, HSP, Handsfree, AvrcpController, AvrcpTarget,
     79         ObexObjectPush, PANU, NAP, MAP, MNS, MAS};
     80 
     81     public static boolean isAudioSource(ParcelUuid uuid) {
     82         return uuid.equals(AudioSource);
     83     }
     84 
     85     public static boolean isAudioSink(ParcelUuid uuid) {
     86         return uuid.equals(AudioSink);
     87     }
     88 
     89     public static boolean isAdvAudioDist(ParcelUuid uuid) {
     90         return uuid.equals(AdvAudioDist);
     91     }
     92 
     93     public static boolean isHandsfree(ParcelUuid uuid) {
     94         return uuid.equals(Handsfree);
     95     }
     96 
     97     public static boolean isHeadset(ParcelUuid uuid) {
     98         return uuid.equals(HSP);
     99     }
    100 
    101     public static boolean isAvrcpController(ParcelUuid uuid) {
    102         return uuid.equals(AvrcpController);
    103     }
    104 
    105     public static boolean isAvrcpTarget(ParcelUuid uuid) {
    106         return uuid.equals(AvrcpTarget);
    107     }
    108 
    109     public static boolean isInputDevice(ParcelUuid uuid) {
    110         return uuid.equals(Hid);
    111     }
    112 
    113     public static boolean isPanu(ParcelUuid uuid) {
    114         return uuid.equals(PANU);
    115     }
    116 
    117     public static boolean isNap(ParcelUuid uuid) {
    118         return uuid.equals(NAP);
    119     }
    120 
    121     public static boolean isBnep(ParcelUuid uuid) {
    122         return uuid.equals(BNEP);
    123     }
    124     public static boolean isMap(ParcelUuid uuid) {
    125         return uuid.equals(MAP);
    126     }
    127     public static boolean isMns(ParcelUuid uuid) {
    128         return uuid.equals(MNS);
    129     }
    130     public static boolean isMas(ParcelUuid uuid) {
    131         return uuid.equals(MAS);
    132     }
    133 
    134     /**
    135      * Returns true if ParcelUuid is present in uuidArray
    136      *
    137      * @param uuidArray - Array of ParcelUuids
    138      * @param uuid
    139      */
    140     public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
    141         if ((uuidArray == null || uuidArray.length == 0) && uuid == null)
    142             return true;
    143 
    144         if (uuidArray == null)
    145             return false;
    146 
    147         for (ParcelUuid element: uuidArray) {
    148             if (element.equals(uuid)) return true;
    149         }
    150         return false;
    151     }
    152 
    153     /**
    154      * Returns true if there any common ParcelUuids in uuidA and uuidB.
    155      *
    156      * @param uuidA - List of ParcelUuids
    157      * @param uuidB - List of ParcelUuids
    158      *
    159      */
    160     public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    161         if (uuidA == null && uuidB == null) return true;
    162 
    163         if (uuidA == null) {
    164             return uuidB.length == 0 ? true : false;
    165         }
    166 
    167         if (uuidB == null) {
    168             return uuidA.length == 0 ? true : false;
    169         }
    170 
    171         HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
    172         for (ParcelUuid uuid: uuidB) {
    173             if (uuidSet.contains(uuid)) return true;
    174         }
    175         return false;
    176     }
    177 
    178     /**
    179      * Returns true if all the ParcelUuids in ParcelUuidB are present in
    180      * ParcelUuidA
    181      *
    182      * @param uuidA - Array of ParcelUuidsA
    183      * @param uuidB - Array of ParcelUuidsB
    184      *
    185      */
    186     public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
    187         if (uuidA == null && uuidB == null) return true;
    188 
    189         if (uuidA == null) {
    190             return uuidB.length == 0 ? true : false;
    191         }
    192 
    193         if (uuidB == null) return true;
    194 
    195         HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
    196         for (ParcelUuid uuid: uuidB) {
    197             if (!uuidSet.contains(uuid)) return false;
    198         }
    199         return true;
    200     }
    201 
    202     /**
    203      * Extract the Service Identifier or the actual uuid from the Parcel Uuid.
    204      * For example, if 0000110B-0000-1000-8000-00805F9B34FB is the parcel Uuid,
    205      * this function will return 110B
    206      * @param parcelUuid
    207      * @return the service identifier.
    208      */
    209     public static int getServiceIdentifierFromParcelUuid(ParcelUuid parcelUuid) {
    210         UUID uuid = parcelUuid.getUuid();
    211         long value = (uuid.getMostSignificantBits() & 0x0000FFFF00000000L) >>> 32;
    212         return (int)value;
    213     }
    214 }
    215