summaryrefslogtreecommitdiff
path: root/framework/java
diff options
context:
space:
mode:
authorRahul Sabnis <rahulsabnis@google.com>2022-03-17 22:17:14 -0700
committerRahul Sabnis <rahulsabnis@google.com>2022-03-17 22:18:56 -0700
commit61e8f11e2359d0b087321b2a7b8b5c94a57afaed (patch)
treea0ebf028430ade208310f71c30236e544483d4c2 /framework/java
parentdc7a3d9999f3935010d66319a38cd98f9f021d34 (diff)
Address API council feedback on GATT API changes.
This CL also updates the permission enforcement mechanism for GATT APIs so it now throws a SecurityException on new APIs as well as on older APIs called by apps targeting T+. Tag: #feature Bug: 217742355 Test: Manual Change-Id: I87fe2ffd088cbce4a9887538964e73f3f5198157
Diffstat (limited to 'framework/java')
-rw-r--r--framework/java/android/bluetooth/BluetoothGatt.java19
-rw-r--r--framework/java/android/bluetooth/BluetoothGattCallback.java3
-rw-r--r--framework/java/android/bluetooth/BluetoothGattCharacteristic.java14
-rw-r--r--framework/java/android/bluetooth/BluetoothGattServer.java3
-rw-r--r--framework/java/android/bluetooth/BluetoothStatusCodes.java14
5 files changed, 22 insertions, 31 deletions
diff --git a/framework/java/android/bluetooth/BluetoothGatt.java b/framework/java/android/bluetooth/BluetoothGatt.java
index 70266741ad..ee9c691134 100644
--- a/framework/java/android/bluetooth/BluetoothGatt.java
+++ b/framework/java/android/bluetooth/BluetoothGatt.java
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.RequiresNoPermission;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
+import android.bluetooth.BluetoothGattCharacteristic.WriteType;
import android.bluetooth.annotations.RequiresBluetoothConnectPermission;
import android.bluetooth.annotations.RequiresLegacyBluetoothPermission;
import android.compat.annotation.UnsupportedAppUsage;
@@ -423,9 +424,6 @@ public final class BluetoothGatt implements BluetoothProfile {
if (status == 0) characteristic.setValue(value);
callback.onCharacteristicRead(BluetoothGatt.this, characteristic,
value, status);
- // Keep calling deprecated callback to maintain app compatibility
- callback.onCharacteristicRead(BluetoothGatt.this, characteristic,
- status);
}
}
});
@@ -526,9 +524,6 @@ public final class BluetoothGatt implements BluetoothProfile {
characteristic.setValue(value);
callback.onCharacteristicChanged(BluetoothGatt.this,
characteristic, value);
- // Keep calling deprecated callback to maintain app compatibility
- callback.onCharacteristicChanged(BluetoothGatt.this,
- characteristic);
}
}
});
@@ -585,8 +580,6 @@ public final class BluetoothGatt implements BluetoothProfile {
if (status == 0) descriptor.setValue(value);
callback.onDescriptorRead(BluetoothGatt.this, descriptor, status,
value);
- // Keep calling deprecated callback to maintain app compatibility
- callback.onDescriptorRead(BluetoothGatt.this, descriptor, status);
}
}
});
@@ -1305,7 +1298,6 @@ public final class BluetoothGatt implements BluetoothProfile {
return true;
}
-
/**
* Writes a given characteristic and its values to the associated remote device.
*
@@ -1318,7 +1310,8 @@ public final class BluetoothGatt implements BluetoothProfile {
* @throws IllegalArgumentException if characteristic or its value are null
*
* @deprecated Use {@link BluetoothGatt#writeCharacteristic(BluetoothGattCharacteristic, byte[],
- * int)} as this is not memory safe.
+ * int)} as this is not memory safe because it relies on a {@link BluetoothGattCharacteristic}
+ * object whose underlying fields are subject to change outside this method.
*/
@Deprecated
@RequiresLegacyBluetoothPermission
@@ -1338,7 +1331,6 @@ public final class BluetoothGatt implements BluetoothProfile {
@IntDef(value = {
BluetoothStatusCodes.SUCCESS,
BluetoothStatusCodes.ERROR_MISSING_BLUETOOTH_CONNECT_PERMISSION,
- BluetoothStatusCodes.ERROR_MISSING_BLUETOOTH_PRIVILEGED_PERMISSION,
BluetoothStatusCodes.ERROR_DEVICE_NOT_CONNECTED,
BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND,
BluetoothStatusCodes.ERROR_GATT_WRITE_NOT_ALLOWED,
@@ -1362,7 +1354,7 @@ public final class BluetoothGatt implements BluetoothProfile {
@RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
@WriteOperationReturnValues
public int writeCharacteristic(@NonNull BluetoothGattCharacteristic characteristic,
- @NonNull byte[] value, int writeType) {
+ @NonNull byte[] value, @WriteType int writeType) {
if (characteristic == null) {
throw new IllegalArgumentException("characteristic must not be null");
}
@@ -1487,7 +1479,8 @@ public final class BluetoothGatt implements BluetoothProfile {
* @throws IllegalArgumentException if descriptor or its value are null
*
* @deprecated Use {@link BluetoothGatt#writeDescriptor(BluetoothGattDescriptor, byte[])} as
- * this is not memory safe.
+ * this is not memory safe because it relies on a {@link BluetoothGattDescriptor} object
+ * whose underlying fields are subject to change outside this method.
*/
@Deprecated
@RequiresLegacyBluetoothPermission
diff --git a/framework/java/android/bluetooth/BluetoothGattCallback.java b/framework/java/android/bluetooth/BluetoothGattCallback.java
index d0a5a1e729..3852d508c0 100644
--- a/framework/java/android/bluetooth/BluetoothGattCallback.java
+++ b/framework/java/android/bluetooth/BluetoothGattCallback.java
@@ -105,6 +105,7 @@ public abstract class BluetoothGattCallback {
*/
public void onCharacteristicRead(@NonNull BluetoothGatt gatt, @NonNull
BluetoothGattCharacteristic characteristic, @NonNull byte[] value, int status) {
+ onCharacteristicRead(gatt, characteristic, status);
}
/**
@@ -155,6 +156,7 @@ public abstract class BluetoothGattCallback {
*/
public void onCharacteristicChanged(@NonNull BluetoothGatt gatt,
@NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] value) {
+ onCharacteristicChanged(gatt, characteristic);
}
/**
@@ -184,6 +186,7 @@ public abstract class BluetoothGattCallback {
*/
public void onDescriptorRead(@NonNull BluetoothGatt gatt,
@NonNull BluetoothGattDescriptor descriptor, int status, @NonNull byte[] value) {
+ onDescriptorRead(gatt, descriptor, status);
}
/**
diff --git a/framework/java/android/bluetooth/BluetoothGattCharacteristic.java b/framework/java/android/bluetooth/BluetoothGattCharacteristic.java
index c5e986e895..92bbfcefaf 100644
--- a/framework/java/android/bluetooth/BluetoothGattCharacteristic.java
+++ b/framework/java/android/bluetooth/BluetoothGattCharacteristic.java
@@ -15,11 +15,14 @@
*/
package android.bluetooth;
+import android.annotation.IntDef;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.ParcelUuid;
import android.os.Parcelable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -115,8 +118,17 @@ public class BluetoothGattCharacteristic implements Parcelable {
*/
public static final int PERMISSION_WRITE_SIGNED_MITM = 0x100;
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(prefix = "WRITE_TYPE_", value = {
+ WRITE_TYPE_DEFAULT,
+ WRITE_TYPE_NO_RESPONSE,
+ WRITE_TYPE_SIGNED
+ })
+ public @interface WriteType{}
+
/**
- * Write characteristic, requesting acknoledgement by the remote device
+ * Write characteristic, requesting acknowledgement by the remote device
*/
public static final int WRITE_TYPE_DEFAULT = 0x02;
diff --git a/framework/java/android/bluetooth/BluetoothGattServer.java b/framework/java/android/bluetooth/BluetoothGattServer.java
index 27d78475a3..8b84505e36 100644
--- a/framework/java/android/bluetooth/BluetoothGattServer.java
+++ b/framework/java/android/bluetooth/BluetoothGattServer.java
@@ -751,11 +751,8 @@ public final class BluetoothGattServer implements BluetoothProfile {
@IntDef(value = {
BluetoothStatusCodes.SUCCESS,
BluetoothStatusCodes.ERROR_MISSING_BLUETOOTH_CONNECT_PERMISSION,
- BluetoothStatusCodes.ERROR_MISSING_BLUETOOTH_PRIVILEGED_PERMISSION,
BluetoothStatusCodes.ERROR_DEVICE_NOT_CONNECTED,
BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND,
- BluetoothStatusCodes.ERROR_GATT_WRITE_NOT_ALLOWED,
- BluetoothStatusCodes.ERROR_GATT_WRITE_REQUEST_BUSY,
BluetoothStatusCodes.ERROR_UNKNOWN
})
public @interface NotifyCharacteristicReturnValues{}
diff --git a/framework/java/android/bluetooth/BluetoothStatusCodes.java b/framework/java/android/bluetooth/BluetoothStatusCodes.java
index 49b0578f8c..c81c6830eb 100644
--- a/framework/java/android/bluetooth/BluetoothStatusCodes.java
+++ b/framework/java/android/bluetooth/BluetoothStatusCodes.java
@@ -58,14 +58,6 @@ public final class BluetoothStatusCodes {
/**
* Error code indicating that the caller does not have the
- * {@link android.Manifest.permission#BLUETOOTH_ADVERTISE} permission.
- *
- * @hide
- */
- public static final int ERROR_MISSING_BLUETOOTH_ADVERTISE_PERMISSION = 5;
-
- /**
- * Error code indicating that the caller does not have the
* {@link android.Manifest.permission#BLUETOOTH_CONNECT} permission.
*/
public static final int ERROR_MISSING_BLUETOOTH_CONNECT_PERMISSION = 6;
@@ -79,12 +71,6 @@ public final class BluetoothStatusCodes {
public static final int ERROR_MISSING_BLUETOOTH_SCAN_PERMISSION = 7;
/**
- * Error code indicating that the caller does not have the
- * {@link android.Manifest.permission#BLUETOOTH_PRIVILEGED} permission.
- */
- public static final int ERROR_MISSING_BLUETOOTH_PRIVILEGED_PERMISSION = 8;
-
- /**
* Error code indicating that the profile service is not bound. You can bind a profile service
* by calling {@link BluetoothAdapter#getProfileProxy}.
*/