19908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/*
29908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Copyright (C) 2013 The Android Open Source Project
39908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta *
49908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Licensed under the Apache License, Version 2.0 (the "License");
59908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * you may not use this file except in compliance with the License.
69908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * You may obtain a copy of the License at
79908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta *
89908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta *      http://www.apache.org/licenses/LICENSE-2.0
99908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta *
109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * Unless required by applicable law or agreed to in writing, software
119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * distributed under the License is distributed on an "AS IS" BASIS,
129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * See the License for the specific language governing permissions and
149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta * limitations under the License.
159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */
169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battapackage android.bluetooth;
189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
19bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowskiimport android.os.Parcel;
20bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowskiimport android.os.Parcelable;
21bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowskiimport android.os.ParcelUuid;
229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Battaimport java.util.UUID;
239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
249908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta/**
25ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie * Represents a Bluetooth GATT Descriptor
2633ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie *
2733ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * <p> GATT Descriptors contain additional information and attributes of a GATT
2833ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * characteristic, {@link BluetoothGattCharacteristic}. They can be used to describe
2933ec9840c70ddc7cd008ecf2660c441defc5f302Matthew Xie * the characteristic's features or to control certain behaviours of the characteristic.
309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta */
31bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowskipublic class BluetoothGattDescriptor implements Parcelable {
329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Value used to enable notification for a client configuration descriptor
359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final byte[] ENABLE_NOTIFICATION_VALUE = {0x01, 0x00};
379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Value used to enable indication for a client configuration descriptor
409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final byte[] ENABLE_INDICATION_VALUE = {0x02, 0x00};
429908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Value used to disable notifications or indicatinos
459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final byte[] DISABLE_NOTIFICATION_VALUE = {0x00, 0x00};
479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor read permission
509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_READ = 0x01;
529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor permission: Allow encrypted read operations
559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_READ_ENCRYPTED = 0x02;
579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor permission: Allow reading with man-in-the-middle protection
609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_READ_ENCRYPTED_MITM = 0x04;
629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor write permission
659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_WRITE = 0x10;
679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
699908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor permission: Allow encrypted writes
709908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
719908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_WRITE_ENCRYPTED = 0x20;
729908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
739908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
749908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor permission: Allow encrypted writes with man-in-the-middle
759908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * protection
769908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
779908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_WRITE_ENCRYPTED_MITM = 0x40;
789908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
799908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
809908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor permission: Allow signed write operations
819908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
829908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_WRITE_SIGNED = 0x80;
839908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
849908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
859908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Descriptor permission: Allow signed write operations with
869908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * man-in-the-middle protection
879908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
889908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public static final int PERMISSION_WRITE_SIGNED_MITM = 0x100;
899908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
909908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
919908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * The UUID of this descriptor.
929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected UUID mUuid;
959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
9725b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * Instance ID for this descriptor.
9825b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * @hide
9925b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     */
10025b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach    protected int mInstance;
10125b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach
10225b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach    /**
1039908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Permissions for this descriptor
1049908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1059908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected int mPermissions;
1079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Back-reference to the characteristic this descriptor belongs to.
1109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected BluetoothGattCharacteristic mCharacteristic;
1139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1159908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * The value for this descriptor.
1169908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @hide
1179908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1189908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    protected byte[] mValue;
1199908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1209908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
1219908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Create a new BluetoothGattDescriptor.
1229908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
1239908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
124ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param uuid The UUID for this descriptor
125ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @param permissions Permissions for this descriptor
126ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
127ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    public BluetoothGattDescriptor(UUID uuid, int permissions) {
12825b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach        initDescriptor(null, uuid, 0, permissions);
129ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
130ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie
131ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
132ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Create a new BluetoothGattDescriptor.
133ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
134ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     *
1359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param characteristic The characteristic this descriptor belongs to
1369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param uuid The UUID for this descriptor
1379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param permissions Permissions for this descriptor
1389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /*package*/ BluetoothGattDescriptor(BluetoothGattCharacteristic characteristic, UUID uuid,
14025b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach                                    int instance, int permissions) {
14125b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach        initDescriptor(characteristic, uuid, instance, permissions);
142ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
143ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie
144bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    /**
145bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski     * @hide
146bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski     */
147bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    public BluetoothGattDescriptor(UUID uuid, int instance, int permissions) {
148bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        initDescriptor(null, uuid, instance, permissions);
149bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    }
150bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski
151ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    private void initDescriptor(BluetoothGattCharacteristic characteristic, UUID uuid,
15225b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach                                int instance, int permissions) {
1539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mCharacteristic = characteristic;
1549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mUuid = uuid;
15525b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach        mInstance = instance;
1569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mPermissions = permissions;
1579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
160bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski     * @hide
161bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski     */
162bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    public int describeContents() {
163bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        return 0;
164bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    }
165bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski
166bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    public void writeToParcel(Parcel out, int flags) {
167bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        out.writeParcelable(new ParcelUuid(mUuid), 0);
168bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        out.writeInt(mInstance);
169bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        out.writeInt(mPermissions);
170bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    }
171bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski
172bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    public static final Parcelable.Creator<BluetoothGattDescriptor> CREATOR
173bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski            = new Parcelable.Creator<BluetoothGattDescriptor>() {
174bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        public BluetoothGattDescriptor createFromParcel(Parcel in) {
175bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski            return new BluetoothGattDescriptor(in);
176bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        }
177bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski
178bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        public BluetoothGattDescriptor[] newArray(int size) {
179bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski            return new BluetoothGattDescriptor[size];
180bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        }
181bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    };
182bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski
183bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    private BluetoothGattDescriptor(Parcel in) {
184bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        mUuid = ((ParcelUuid)in.readParcelable(null)).getUuid();
185bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        mInstance = in.readInt();
186bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski        mPermissions = in.readInt();
187bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    }
188bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski
189bf0faed3597b92d950febafcf555ad05529559d6Jakub Pawlowski    /**
1909908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns the characteristic this descriptor belongs to.
1919908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return The characteristic.
1929908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
1939908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public BluetoothGattCharacteristic getCharacteristic() {
1949908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mCharacteristic;
1959908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
1969908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
1979908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
198ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * Set the back-reference to the associated characteristic
199ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * @hide
200ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     */
201ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /*package*/ void setCharacteristic(BluetoothGattCharacteristic characteristic) {
202ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie        mCharacteristic = characteristic;
203ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    }
204ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie
205ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie    /**
2069908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns the UUID of this descriptor.
2079908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2089908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return UUID of this descriptor
2099908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2109908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public UUID getUuid() {
2119908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mUuid;
2129908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2139908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2149908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
21525b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * Returns the instance ID for this descriptor.
21625b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     *
21725b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * <p>If a remote device offers multiple descriptors with the same UUID,
21825b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * the instance ID is used to distuinguish between descriptors.
21925b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     *
22025b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
22125b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     *
22225b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * @return Instance ID of this descriptor
22325b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     * @hide
22425b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach     */
22525b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach    public int getInstanceId() {
22625b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach        return mInstance;
22725b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach    }
22825b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach
22925b9cf953bd3e97f726f8c27d7a752b27c9a2373Andre Eisenbach    /**
2309908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns the permissions for this descriptor.
2319908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2329908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return Permissions of this descriptor
2339908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2349908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public int getPermissions() {
2359908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mPermissions;
2369908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2379908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2389908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
2399908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Returns the stored value for this descriptor
2409908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2419908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>This function returns the stored value for this descriptor as
242ddf7e4756c31d0ed90802f98abeaa79df6d16b2aMatthew Xie     * retrieved by calling {@link BluetoothGatt#readDescriptor}. The cached
2439908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * value of the descriptor is updated as a result of a descriptor read
2449908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * operation.
2459908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2469908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return Cached value of the descriptor
2479908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2489908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public byte[] getValue() {
2499908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return mValue;
2509908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2519908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta
2529908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    /**
2539908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * Updates the locally stored value of this descriptor.
2549908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2559908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * <p>This function modifies the locally stored cached value of this
2569908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * descriptor. To send the value to the remote device, call
2579908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * {@link BluetoothGatt#writeDescriptor} to send the value to the
2589908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * remote device.
2599908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *
2609908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @param value New value for this descriptor
2619908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     * @return true if the locally stored value has been set, false if the
2629908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     *              requested value could not be stored locally.
2639908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta     */
2649908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    public boolean setValue(byte[] value) {
2659908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        mValue = value;
2669908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta        return true;
2679908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta    }
2689908112fd085d8b0d91e0562d32eebd1884f09a5Ganesh Ganapathi Batta}
269