OSDN Git Service

Read by UUID for PTS tests (1/5)
authorJakub Pawlowski <jpawlowski@google.com>
Fri, 14 Apr 2017 14:21:20 +0000 (07:21 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Thu, 27 Apr 2017 20:15:43 +0000 (13:15 -0700)
Add a hidden api for reading characteristic by UUID for PTS.

Bug: 35150313
Test: sl4a GattReadTest.byUuid
Change-Id: Ice4076d99e4694d20374ba0fdcae74d5ae841147
(cherry picked from commit de74891d1c603326691678ec301c80b4525bc4ef)

core/java/android/bluetooth/BluetoothGatt.java
core/java/android/bluetooth/IBluetoothGatt.aidl

index 713dbf4..e77ab2e 100644 (file)
@@ -973,6 +973,41 @@ public final class BluetoothGatt implements BluetoothProfile {
     }
 
     /**
+     * Reads the characteristic using its UUID from the associated remote device.
+     *
+     * <p>This is an asynchronous operation. The result of the read operation
+     * is reported by the {@link BluetoothGattCallback#onCharacteristicRead}
+     * callback.
+     *
+     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
+     *
+     * @param uuid UUID of characteristic to read from the remote device
+     * @return true, if the read operation was initiated successfully
+     * @hide
+     */
+    public boolean readUsingCharacteristicUuid(UUID uuid, int startHandle, int endHandle) {
+        if (VDBG) Log.d(TAG, "readUsingCharacteristicUuid() - uuid: " + uuid);
+        if (mService == null || mClientIf == 0) return false;
+
+        synchronized(mDeviceBusy) {
+            if (mDeviceBusy) return false;
+            mDeviceBusy = true;
+        }
+
+        try {
+            mService.readUsingCharacteristicUuid(mClientIf, mDevice.getAddress(),
+                new ParcelUuid(uuid), startHandle, endHandle, AUTHENTICATION_NONE);
+        } catch (RemoteException e) {
+            Log.e(TAG,"",e);
+            mDeviceBusy = false;
+            return false;
+        }
+
+        return true;
+    }
+
+
+    /**
      * Writes a given characteristic and its values to the associated remote device.
      *
      * <p>Once the write operation has been completed, the
index 12e9baa..9e6d700 100644 (file)
@@ -80,6 +80,8 @@ interface IBluetoothGatt {
     void refreshDevice(in int clientIf, in String address);
     void discoverServices(in int clientIf, in String address);
     void readCharacteristic(in int clientIf, in String address, in int handle, in int authReq);
+    void readUsingCharacteristicUuid(in int clientIf, in String address, in ParcelUuid uuid,
+                           in int startHandle, in int endHandle, in int authReq);
     void writeCharacteristic(in int clientIf, in String address, in int handle,
                             in int writeType, in int authReq, in byte[] value);
     void readDescriptor(in int clientIf, in String address, in int handle, in int authReq);