• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.nearby.fastpair.provider.bluetooth;
18 
19 import android.annotation.TargetApi;
20 import android.bluetooth.BluetoothGatt;
21 import android.bluetooth.BluetoothGattCharacteristic;
22 import android.bluetooth.BluetoothGattDescriptor;
23 import android.nearby.fastpair.provider.bluetooth.BluetoothGattServerConnection.Notifier;
24 
25 import com.android.server.nearby.common.bluetooth.BluetoothGattException;
26 
27 /** Servlet to handle GATT operations on a characteristic. */
28 @TargetApi(18)
29 public abstract class BluetoothGattServlet {
read(BluetoothGattServerConnection connection, @SuppressWarnings("unused") int offset)30     public byte[] read(BluetoothGattServerConnection connection,
31             @SuppressWarnings("unused") int offset) throws BluetoothGattException {
32         throw new BluetoothGattException("Read not supported.",
33                 BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED);
34     }
35 
write(BluetoothGattServerConnection connection, @SuppressWarnings("unused") int offset, @SuppressWarnings("unused") byte[] value)36     public void write(BluetoothGattServerConnection connection,
37             @SuppressWarnings("unused") int offset, @SuppressWarnings("unused") byte[] value)
38             throws BluetoothGattException {
39         throw new BluetoothGattException("Write not supported.",
40                 BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED);
41     }
42 
readDescriptor(BluetoothGattServerConnection connection, BluetoothGattDescriptor descriptor, @SuppressWarnings("unused") int offset)43     public byte[] readDescriptor(BluetoothGattServerConnection connection,
44             BluetoothGattDescriptor descriptor, @SuppressWarnings("unused") int offset)
45             throws BluetoothGattException {
46         throw new BluetoothGattException("Read not supported.",
47                 BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED);
48     }
49 
writeDescriptor(BluetoothGattServerConnection connection, BluetoothGattDescriptor descriptor, @SuppressWarnings("unused") int offset, @SuppressWarnings("unused") byte[] value)50     public void writeDescriptor(BluetoothGattServerConnection connection,
51             BluetoothGattDescriptor descriptor,
52             @SuppressWarnings("unused") int offset, @SuppressWarnings("unused") byte[] value)
53             throws BluetoothGattException {
54         throw new BluetoothGattException("Write not supported.",
55                 BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED);
56     }
57 
enableNotification(BluetoothGattServerConnection connection, Notifier notifier)58     public void enableNotification(BluetoothGattServerConnection connection, Notifier notifier)
59             throws BluetoothGattException {
60         throw new BluetoothGattException("Notification not supported.",
61                 BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED);
62     }
63 
disableNotification(BluetoothGattServerConnection connection, Notifier notifier)64     public void disableNotification(BluetoothGattServerConnection connection, Notifier notifier)
65             throws BluetoothGattException {
66         throw new BluetoothGattException("Notification not supported.",
67                 BluetoothGatt.GATT_REQUEST_NOT_SUPPORTED);
68     }
69 
getCharacteristic()70     public abstract BluetoothGattCharacteristic getCharacteristic();
71 }
72