OSDN Git Service

Read by UUID for PTS tests (2/5)
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 14 Apr 2017 14:26:22 +0000 (07:26 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 27 Apr 2017 19:57:00 +0000 (12:57 -0700)
Add a hidden api for reading characteristic by UUID for PTS.

Bug: 35150313
Test: sl4a GattReadTest.byUuid
Change-Id: I6ec848eac1ecfbd1a4ec2bc968faff8a082d9c79
(cherry picked from commit 5fc203008497b071dc583450a53c93e11dd561ff)

jni/com_android_bluetooth_gatt.cpp
src/com/android/bluetooth/gatt/GattService.java

index 9548f19..d05247b 100644 (file)
@@ -1083,6 +1083,17 @@ static void gattClientReadCharacteristicNative(JNIEnv* env, jobject object,
   sGattIf->client->read_characteristic(conn_id, handle, authReq);
 }
 
+static void gattClientReadUsingCharacteristicUuidNative(
+    JNIEnv* env, jobject object, jint conn_id, jlong uuid_lsb, jlong uuid_msb,
+    jint s_handle, jint e_handle, jint authReq) {
+  if (!sGattIf) return;
+
+  bt_uuid_t uuid;
+  set_uuid(uuid.uu, uuid_msb, uuid_lsb);
+  sGattIf->client->read_using_characteristic_uuid(conn_id, &uuid, s_handle,
+                                                  e_handle, authReq);
+}
+
 static void gattClientReadDescriptorNative(JNIEnv* env, jobject object,
                                            jint conn_id, jint handle,
                                            jint authReq) {
@@ -2142,6 +2153,8 @@ static JNINativeMethod sMethods[] = {
     {"gattClientGetGattDbNative", "(I)V", (void*)gattClientGetGattDbNative},
     {"gattClientReadCharacteristicNative", "(III)V",
      (void*)gattClientReadCharacteristicNative},
+    {"gattClientReadUsingCharacteristicUuidNative", "(IJJIII)V",
+     (void*)gattClientReadUsingCharacteristicUuidNative},
     {"gattClientReadDescriptorNative", "(III)V",
      (void*)gattClientReadDescriptorNative},
     {"gattClientWriteCharacteristicNative", "(IIII[B)V",
index 48af96a..1be8eeb 100644 (file)
@@ -219,6 +219,13 @@ public class GattService extends ProfileService {
         return true;
     }
 
+    boolean permissionCheck(UUID uuid) {
+        if (isRestrictedCharUuid(uuid) && (0 != checkCallingOrSelfPermission(BLUETOOTH_PRIVILEGED)))
+            return false;
+        else
+            return true;
+    }
+
     boolean permissionCheck(int connId, int handle) {
         List<BluetoothGattService> db = gattClientDatabases.get(connId);
         if (db == null) return true;
@@ -460,6 +467,14 @@ public class GattService extends ProfileService {
             service.readCharacteristic(clientIf, address, handle, authReq);
         }
 
+        public void readUsingCharacteristicUuid(int clientIf, String address, ParcelUuid uuid,
+                int startHandle, int endHandle, int authReq) {
+            GattService service = getService();
+            if (service == null) return;
+            service.readUsingCharacteristicUuid(
+                    clientIf, address, uuid.getUuid(), startHandle, endHandle, authReq);
+        }
+
         public void writeCharacteristic(int clientIf, String address, int handle,
                              int writeType, int authReq, byte[] value) {
             GattService service = getService();
@@ -1871,6 +1886,27 @@ public class GattService extends ProfileService {
         gattClientReadCharacteristicNative(connId, handle, authReq);
     }
 
+    void readUsingCharacteristicUuid(
+            int clientIf, String address, UUID uuid, int startHandle, int endHandle, int authReq) {
+        enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+
+        if (VDBG) Log.d(TAG, "readUsingCharacteristicUuid() - address=" + address);
+
+        Integer connId = mClientMap.connIdByAddress(clientIf, address);
+        if (connId == null) {
+            Log.e(TAG, "readUsingCharacteristicUuid() - No connection for " + address + "...");
+            return;
+        }
+
+        if (!permissionCheck(uuid)) {
+            Log.w(TAG, "readUsingCharacteristicUuid() - permission check failed!");
+            return;
+        }
+
+        gattClientReadUsingCharacteristicUuidNative(connId, uuid.getLeastSignificantBits(),
+                uuid.getMostSignificantBits(), startHandle, endHandle, authReq);
+    }
+
     void writeCharacteristic(int clientIf, String address, int handle, int writeType,
                              int authReq, byte[] value) {
         enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
@@ -2646,6 +2682,9 @@ public class GattService extends ProfileService {
 
     private native void gattClientReadCharacteristicNative(int conn_id, int handle, int authReq);
 
+    private native void gattClientReadUsingCharacteristicUuidNative(
+            int conn_id, long uuid_msb, long uuid_lsb, int s_handle, int e_handle, int authReq);
+
     private native void gattClientReadDescriptorNative(int conn_id, int handle, int authReq);
 
     private native void gattClientWriteCharacteristicNative(int conn_id,