• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 com.android.server.nearby.common.bluetooth;
18 
19 import java.util.UUID;
20 
21 /**
22  * Reserved UUIDS by BT SIG.
23  * <p>
24  * See https://developer.bluetooth.org for more details.
25  */
26 public class ReservedUuids {
27     /** UUIDs reserved for services. */
28     public static class Services {
29         /**
30          * The Device Information Service exposes manufacturer and/or vendor info about a device.
31          * <p>
32          * See reserved UUID org.bluetooth.service.device_information.
33          */
34         public static final UUID DEVICE_INFORMATION = fromShortUuid((short) 0x180A);
35 
36         /**
37          * Generic attribute service.
38          * <p>
39          * See reserved UUID org.bluetooth.service.generic_attribute.
40          */
41         public static final UUID GENERIC_ATTRIBUTE = fromShortUuid((short) 0x1801);
42     }
43 
44     /** UUIDs reserved for characteristics. */
45     public static class Characteristics {
46         /**
47          * The value of this characteristic is a UTF-8 string representing the firmware revision for
48          * the firmware within the device.
49          * <p>
50          * See reserved UUID org.bluetooth.characteristic.firmware_revision_string.
51          */
52         public static final UUID FIRMWARE_REVISION_STRING = fromShortUuid((short) 0x2A26);
53 
54         /**
55          * Service change characteristic.
56          * <p>
57          * See reserved UUID org.bluetooth.characteristic.gatt.service_changed.
58          */
59         public static final UUID SERVICE_CHANGE = fromShortUuid((short) 0x2A05);
60     }
61 
62     /** UUIDs reserved for descriptors. */
63     public static class Descriptors {
64         /**
65          * This descriptor shall be persistent across connections for bonded devices. The Client
66          * Characteristic Configuration descriptor is unique for each client. A client may read and
67          * write this descriptor to determine and set the configuration for that client.
68          * Authentication and authorization may be required by the server to write this descriptor.
69          * The default value for the Client Characteristic Configuration descriptor is 0x00. Upon
70          * connection of non-binded clients, this descriptor is set to the default value.
71          * <p>
72          * See reserved UUID org.bluetooth.descriptor.gatt.client_characteristic_configuration.
73          */
74         public static final UUID CLIENT_CHARACTERISTIC_CONFIGURATION =
75                 fromShortUuid((short) 0x2902);
76     }
77 
78     /** The base 128-bit UUID representation of a 16-bit UUID */
79     public static final UUID BASE_16_BIT_UUID =
80             UUID.fromString("00000000-0000-1000-8000-00805F9B34FB");
81 
82     /** Converts from short UUId to UUID. */
fromShortUuid(short shortUuid)83     public static UUID fromShortUuid(short shortUuid) {
84         return new UUID(((((long) shortUuid) << 32) & 0x0000FFFF00000000L)
85                 | ReservedUuids.BASE_16_BIT_UUID.getMostSignificantBits(),
86                 ReservedUuids.BASE_16_BIT_UUID.getLeastSignificantBits());
87     }
88 }
89