1475beaaca2a2644f3d10355f443948243f787b77Arman Uguray/*
25b790feeeb211c42bf78ca3ae9c26aa30e516765Jakub Pawlowski * Copyright 2015, The Android Open Source Project
3475beaaca2a2644f3d10355f443948243f787b77Arman Uguray *
4475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * Licensed under the Apache License, Version 2.0 (the "License");
5475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * you may not use this file except in compliance with the License.
6475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * You may obtain a copy of the License at
7475beaaca2a2644f3d10355f443948243f787b77Arman Uguray *
8475beaaca2a2644f3d10355f443948243f787b77Arman Uguray *     http://www.apache.org/licenses/LICENSE-2.0
9475beaaca2a2644f3d10355f443948243f787b77Arman Uguray *
10475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * Unless required by applicable law or agreed to in writing, software
11475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * distributed under the License is distributed on an "AS IS" BASIS,
12475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * See the License for the specific language governing permissions and
14475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * limitations under the License.
15475beaaca2a2644f3d10355f443948243f787b77Arman Uguray */
16475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
17475beaaca2a2644f3d10355f443948243f787b77Arman Uguray/**
18475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * Binder IPC interface for interacting with Bluetooth GATT client-role
19475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * features.
20475beaaca2a2644f3d10355f443948243f787b77Arman Uguray * TODO(armansito): Not yet supported.
21475beaaca2a2644f3d10355f443948243f787b77Arman Uguray */
22475beaaca2a2644f3d10355f443948243f787b77Arman Ugurayinterface IBluetoothGattClient {
23475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
24475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Registers a client application with this interface. This creates a unique
25475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * GATT client instance for the application. Returns true on success; false
26475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * otherwise. If successful, the caller will be assigned a "client_id" which
27475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * will be reported asynchronously via
28475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * IBluetoothGattClientCallback.onRegistered. This ID is required to make
29475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * calls to the functions defined below.
30475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
31475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean registerClient(in IBluetoothGattClientCallback callback);
32475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
33475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
34475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Unregisters a previously registered client with interface ID |client_id|.
35475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
36475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  void unregisterClient(in int client_id);
37475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
38475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
39475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Unregisters all previously registered clients.
40475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
41475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  void unregisterAll();
42475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
43475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
44475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Refreshes the local client-side attribute cache that mirrors the attribute
45475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * database of remote device with address |device_address|. Returns false in
46475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * case of an error. |client_id| is the identifier obtained via
47475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * registerClient.
48475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
49475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean refreshDevice(in int client_id, in String device_address);
50475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
51475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
52475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Returns the GATT services, characteristics, and descriptors on the remote
53475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * device with address |device_address| asynchronously via the corresponding
54475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * IBluetoothGattClientCallback callbacks. Based on the current connection and
55475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * bonding state, either GATT service discovery will be initiated or the
56475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * results will be returned from the attribute cache. Returns false in case of
57475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * an error. |client_id| is the identifier obtained via registerClient.
58475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
59475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean discoverServices(in int client_id, in String device_address);
60475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
61475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
62475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Initiate a read request for the remote characteristic with identifier
63475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |characteristic_id|. The result will be asynchronously reported in
64475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * IBluetoothGattClientCallback.onCharacteristicRead. Returns false if the
65475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * request cannot be started, e.g. if a read is already pending on this remote
66475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * device. If the read request fails due to characteristic permissions,
67475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * this function will try to raise the connection security level based on the
68475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * characteristic's permission requirements. If that operation fails, then the
69475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |status| parameter of the onCharacteristicRead callback will contain the
70475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * appropriate ATT protocol error code. |client_id| is obtained via
71475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * registerClient.
72475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
73475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean readCharacteristic(in int client_id,
74475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                             in GattIdentifier characteristic_id);
75475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
76475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
77475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Initiate a write request for the remote characteristic with identifier
78475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |characteristic_id| with the value |value|. The |write_type| parameter
79475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * indicates which of the following GATT write procedure should be used:
80475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *
81475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *   - WRITE_TYPE_DEFAULT (0x02): Regular Write Procedure
82475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *   - WRITE_TYPE_NO_RESPONSE (0x01): Write Without Response procedure
83475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *   - WRITE_TYPE_SIGNED (0x04): Signed Write Without Response procedure.
84475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *
85475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * The result will be asynchronously reported in
86475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * IBluetoothGattClientCallback.onCharacteristicWrite. Returns false if the
87475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * request cannot be started. If the write request fails due to attribute
88475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * permissions, this function will try to raise the connection security level
89475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * based on the characteristic's permission requirements. If that operation
90475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * fails, then the |status| parameter of the onCharacteristicWrite callback
91475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * will contain the appropriate ATT protocol error code. |client_id| is
92475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * obtained via registerClient.
93475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
94475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean writeCharacteristic(in int client_id,
95475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                              in GattIdentifier characteristic_id,
96475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                              in int write_type,
97475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                              in byte[] value);
98475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
99475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
100475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Initiate a read request for the remote descriptor with identifier
101475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |descriptor_id|. The result will be asynchronously reported in
102475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * IBluetoothGattClientCallback.onDescriptorRead. Returns false if the
103475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * request cannot be started, e.g. if a read is already pending on this remote
104475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * device. If the read request fails due to descriptor permissions,
105475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * this function will try to raise the connection security level based on the
106475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * descriptor's permission requirements. If that operation fails, then the
107475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |status| parameter of the onDescriptorRead callback will contain the
108475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * appropriate ATT protocol error code. |client_id| is obtained via
109475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * registerClient.
110475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
111475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean readDescriptor(in int client_id,
112475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                         in GattIdentifier descriptor_id);
113475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
114475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
115475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Initiate a write request for the remote descriptor with identifier
116475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |descriptor_id| with the value |value|. The |write_type| parameter
117475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * indicates which of the following GATT write procedure should be used:
118475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *
119475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *   - WRITE_TYPE_DEFAULT (0x02): Regular write procedure
120475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *   - WRITE_TYPE_NO_RESPONSE (0x01): Write without response procedure
121475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *   - WRITE_TYPE_SIGNED (0x04): Authenticated-signed write procedure
122475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   *
123475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * The result will be asynchronously reported in
124475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * IBluetoothGattClientCallback.onDescriptorWrite. Returns false if the
125475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * request cannot be started. If the write request fails due to attribute
126475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * permissions, this function will try to raise the connection security level
127475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * based on the descriptor's permission requirements. If that operation fails,
128475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * then the |status| parameter of the onDescriptorWrite callback will contain
129475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * the appropriate ATT protocol error code. |client_id| is obtained via
130475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * registerClient.
131475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
132475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean writeDescriptor(in int client_id,
133475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                          in GattIdentifier descriptor_id,
134475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                          in int write_type,
135475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                          in byte[] value);
136475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
137475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
138475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Enables handle-value notifications from the remote characteristic with ID
139475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |characteristic_id|. If successful, notifications will be signaled via
140475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * IBluetoothGattClientCallback.onNotify. Returns false if the request cannot
141475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * be initiated. |client_id| is obtained via registerClient.
142475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
143475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean registerForNotifications(in int client_id,
144475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                                   in GattIdentifier characteristic_id);
145475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
146475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
147475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Disables handle-value notifications from the remote characteristic with ID
148475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |characteristic_id|. Returns false if the request cannot be initiated, e.g.
149475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * if notifications from this characteristic have not been enabled.
150475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |client_id| is obtained via registerClient.
151475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
152475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean unregisterForNotifications(in int client_id,
153475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                                     in GattIdentifier characteristic_id);
154475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
155475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
156475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Initiates a reliable write procedure for the remote device with address
157475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |device_address|. Once a reliable write transaction has been initiated, all
158475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * calls to writeCharacteristic are sent to the remote device for verification
159475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * and queued up for atomic execution. The application can verify each write
160475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * payload using the IBluetoothGattClientCallback.onCharacteristicWrite
161475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * callback and abort reliable write in case of a mismatch. The queued writes
162475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * will be processed atomically by the remote device after calling
163475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * endReliableWrite. Returns false if the procedure cannot be started, e.g. if
164475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * it has already been started earlier. |client_id| is obtained via
165475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * registerClient.
166475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
167475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean beginReliableWrite(in int client_id, in String device_address);
168475beaaca2a2644f3d10355f443948243f787b77Arman Uguray
169475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  /**
170475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * Ends a previously started reliable write procedure for the remote device
171475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * with address |device_address|. If |execute| is true, then a request will be
172475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * sent to execute the queued writes, else a request will be sent to abort the
173475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * queued writes. Returns false in case of a failure, e.g. if a reliable write
174475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * procedure was not started. IBluetoothGattClientCallback.onExecuteWrite will
175475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * be used to asynchronously report the result of the execute write request.
176475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   * |client_id| is obtained via registerClient.
177475beaaca2a2644f3d10355f443948243f787b77Arman Uguray   */
178475beaaca2a2644f3d10355f443948243f787b77Arman Uguray  boolean endReliableWrite(in int client_id, in String device_address,
179475beaaca2a2644f3d10355f443948243f787b77Arman Uguray                           in boolean execute);
180475beaaca2a2644f3d10355f443948243f787b77Arman Uguray}
181