From 4c2ce6e1885c73085bd2eece5cdc53e141348258 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Wed, 5 May 2021 14:04:04 -0700 Subject: Update BluetoothDevice#setAlias based on API council feedback: now accepts null input and returns an int (with error codes). Update CompanionDeviceManager#canPairWithoutPrompt to take a UserHandle instead of an int. Adds BluetoothStatusCodes class for all new Bluetooth error / success codes. Moved OOB and hci disconnect constants to the new BluetoothStatusCodes class. Tag: #feature Bug: 184714087 Test: atest BluetoothDeviceTest#test_setAlias_getAlias Change-Id: Ife03506f2cf68800f5824cb5fa94fec8aa34a39c --- .../android/bluetooth/BluetoothStatusCodes.java | 205 +++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 framework/java/android/bluetooth/BluetoothStatusCodes.java (limited to 'framework/java/android/bluetooth/BluetoothStatusCodes.java') diff --git a/framework/java/android/bluetooth/BluetoothStatusCodes.java b/framework/java/android/bluetooth/BluetoothStatusCodes.java new file mode 100644 index 0000000000..31bb0f68c6 --- /dev/null +++ b/framework/java/android/bluetooth/BluetoothStatusCodes.java @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.bluetooth; + +import android.annotation.SystemApi; + +/** + * A class with constants representing possible return values for Bluetooth APIs. General return + * values occupy the range 0 to 99. Profile-specific return values occupy the range 100-999. + * API-specific return values start at 1000. The exception to this is the "other" error code which + * occupies the max integer value. + */ +public final class BluetoothStatusCodes { + + private BluetoothStatusCodes() {} + + /** + * Indicates that the API call was successful + */ + public static final int SUCCESS = 0; + + /** + * Error code indicating that Bluetooth is not enabled + */ + public static final int ERROR_BLUETOOTH_NOT_ENABLED = 1; + + /** + * Error code indicating that the API call was initiated by neither the system nor the active + * Zuser + */ + public static final int ERROR_BLUETOOTH_NOT_ALLOWED = 2; + + /** + * Error code indicating that the Bluetooth Device specified is not bonded + */ + public static final int ERROR_DEVICE_NOT_BONDED = 3; + + /** + * Error code indicating that the Bluetooth Device specified is not connected, but is bonded + * + * @hide + */ + public static final int ERROR_DEVICE_NOT_CONNECTED = 4; + + /** + * 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; + + /** + * Error code indicating that the caller does not have the + * {@link android.Manifest.permission#BLUETOOTH_SCAN} permission + * + * @hide + */ + public static final int ERROR_MISSING_BLUETOOTH_SCAN_PERMISSION = 7; + + /** + * If another application has already requested {@link OobData} then another fetch will be + * disallowed until the callback is removed. + * + * @hide + */ + @SystemApi + public static final int ERROR_ANOTHER_ACTIVE_OOB_REQUEST = 1000; + + /** + * Indicates that the ACL disconnected due to an explicit request from the local device. + *

+ * Example cause: This is a normal disconnect reason, e.g., user/app initiates + * disconnection. + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_LOCAL_REQUEST = 1100; + + /** + * Indicates that the ACL disconnected due to an explicit request from the remote device. + *

+ * Example cause: This is a normal disconnect reason, e.g., user/app initiates + * disconnection. + *

+ * Example solution: The app can also prompt the user to check their remote device. + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_REMOTE_REQUEST = 1101; + + /** + * Generic disconnect reason indicating the ACL disconnected due to an error on the local + * device. + *

+ * Example solution: Prompt the user to check their local device (e.g., phone, car + * headunit). + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_LOCAL = 1102; + + /** + * Generic disconnect reason indicating the ACL disconnected due to an error on the remote + * device. + *

+ * Example solution: Prompt the user to check their remote device (e.g., headset, car + * headunit, watch). + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_REMOTE = 1103; + + /** + * Indicates that the ACL disconnected due to a timeout. + *

+ * Example cause: remote device might be out of range. + *

+ * Example solution: Prompt user to verify their remote device is on or in + * connection/pairing mode. + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_TIMEOUT = 1104; + + /** + * Indicates that the ACL disconnected due to link key issues. + *

+ * Example cause: Devices are either unpaired or remote device is refusing our pairing + * request. + *

+ * Example solution: Prompt user to unpair and pair again. + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_SECURITY = 1105; + + /** + * Indicates that the ACL disconnected due to the local device's system policy. + *

+ * Example cause: privacy policy, power management policy, permissions, etc. + *

+ * Example solution: Prompt the user to check settings, or check with their system + * administrator (e.g. some corp-managed devices do not allow OPP connection). + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_SYSTEM_POLICY = 1106; + + /** + * Indicates that the ACL disconnected due to resource constraints, either on the local + * device or the remote device. + *

+ * Example cause: controller is busy, memory limit reached, maximum number of connections + * reached. + *

+ * Example solution: The app should wait and try again. If still failing, prompt the user + * to disconnect some devices, or toggle Bluetooth on the local and/or the remote device. + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_RESOURCE_LIMIT_REACHED = 1107; + + /** + * Indicates that the ACL disconnected because another ACL connection already exists. + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_CONNECTION_ALREADY_EXISTS = 1108; + + /** + * Indicates that the ACL disconnected due to incorrect parameters passed in from the app. + *

+ * Example solution: Change parameters and try again. If error persists, the app can report + * telemetry and/or log the error in a bugreport. + * + * @hide + */ + public static final int ERROR_DISCONNECT_REASON_BAD_PARAMETERS = 1109; + + /** + * Indicates that an unknown error has occurred has occurred. + */ + public static final int ERROR_UNKNOWN = Integer.MAX_VALUE; +} -- cgit v1.2.3 From d00916c7fe16c0ae0c107b7b343e85085836e27d Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Tue, 28 Sep 2021 16:16:07 -0700 Subject: Add BluetoothDevice#connect and BluetoothDevice#disconnect as System APIs Tag: #feature Bug: 201462141 Test: Manual Change-Id: I79332c63e99efd9e90036ba2c693835151cc1240 --- framework/java/android/bluetooth/BluetoothStatusCodes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothStatusCodes.java') diff --git a/framework/java/android/bluetooth/BluetoothStatusCodes.java b/framework/java/android/bluetooth/BluetoothStatusCodes.java index 31bb0f68c6..3e46c498e3 100644 --- a/framework/java/android/bluetooth/BluetoothStatusCodes.java +++ b/framework/java/android/bluetooth/BluetoothStatusCodes.java @@ -21,7 +21,7 @@ import android.annotation.SystemApi; /** * A class with constants representing possible return values for Bluetooth APIs. General return * values occupy the range 0 to 99. Profile-specific return values occupy the range 100-999. - * API-specific return values start at 1000. The exception to this is the "other" error code which + * API-specific return values start at 1000. The exception to this is the "UNKNOWN" error code which * occupies the max integer value. */ public final class BluetoothStatusCodes { -- cgit v1.2.3 From f3fc3166c04cbe693abdef14ef3088550f7c4d37 Mon Sep 17 00:00:00 2001 From: Patty Date: Mon, 18 Oct 2021 19:44:36 +0800 Subject: Expose isCISCentralSupported() and isLePeriodicAdvertisingSyncTransferSenderSupported() API Tag: #feature Bug: 200749925 Bug: 150670922 Test: Compile Change-Id: I45c674dcc8719d209f0e790aa9716bbbf0052fce --- framework/java/android/bluetooth/BluetoothStatusCodes.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothStatusCodes.java') diff --git a/framework/java/android/bluetooth/BluetoothStatusCodes.java b/framework/java/android/bluetooth/BluetoothStatusCodes.java index 3e46c498e3..63e84eddc7 100644 --- a/framework/java/android/bluetooth/BluetoothStatusCodes.java +++ b/framework/java/android/bluetooth/BluetoothStatusCodes.java @@ -78,6 +78,11 @@ public final class BluetoothStatusCodes { */ public static final int ERROR_MISSING_BLUETOOTH_SCAN_PERMISSION = 7; + /** + * Error code indicating that the feature is not supported. + */ + public static final int ERROR_FEATURE_NOT_SUPPORTED = 8; + /** * If another application has already requested {@link OobData} then another fetch will be * disallowed until the callback is removed. -- cgit v1.2.3 From f95c619d25acce658c84861dbbe8e0bf35b6e1d7 Mon Sep 17 00:00:00 2001 From: Rahul Sabnis Date: Wed, 13 Oct 2021 10:56:50 -0700 Subject: Deprecate GATT callbacks and methods that were not memory safe and replace with memory safe versions. Tag: #feature Bug: 195157393 Test: Manual CTS-Coverage-Bug: 205190062 Merged-In: I5ae604ec20febcf646bfe6a8f866b218448349c1 Change-Id: I5ae604ec20febcf646bfe6a8f866b218448349c1 --- .../android/bluetooth/BluetoothStatusCodes.java | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'framework/java/android/bluetooth/BluetoothStatusCodes.java') diff --git a/framework/java/android/bluetooth/BluetoothStatusCodes.java b/framework/java/android/bluetooth/BluetoothStatusCodes.java index 63e84eddc7..ca01784efd 100644 --- a/framework/java/android/bluetooth/BluetoothStatusCodes.java +++ b/framework/java/android/bluetooth/BluetoothStatusCodes.java @@ -78,10 +78,32 @@ 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} + */ + public static final int ERROR_PROFILE_SERVICE_NOT_BOUND = 9; + /** * Error code indicating that the feature is not supported. */ - public static final int ERROR_FEATURE_NOT_SUPPORTED = 8; + public static final int ERROR_FEATURE_NOT_SUPPORTED = 10; + + /** + * A GATT writeCharacteristic request is not permitted on the remote device. + */ + public static final int ERROR_GATT_WRITE_NOT_ALLOWED = 101; + + /** + * A GATT writeCharacteristic request is issued to a busy remote device. + */ + public static final int ERROR_GATT_WRITE_REQUEST_BUSY = 102; /** * If another application has already requested {@link OobData} then another fetch will be -- cgit v1.2.3 From 2eb043e7e5273b0f8e70c00c71361a17d97262ee Mon Sep 17 00:00:00 2001 From: Qasim Javed Date: Thu, 4 Nov 2021 12:57:33 -0700 Subject: Add BluetoothLeBroadcast profile API. Implementation for the APIs will be added later. Bug: 205174140 Bug: 208222281 Tag: #feature Test: gd/cert/run Change-Id: I8781be89cba45a6e7a76fec7df24790a9f02d6a6 --- .../android/bluetooth/BluetoothStatusCodes.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'framework/java/android/bluetooth/BluetoothStatusCodes.java') diff --git a/framework/java/android/bluetooth/BluetoothStatusCodes.java b/framework/java/android/bluetooth/BluetoothStatusCodes.java index ca01784efd..9dafa073ab 100644 --- a/framework/java/android/bluetooth/BluetoothStatusCodes.java +++ b/framework/java/android/bluetooth/BluetoothStatusCodes.java @@ -225,6 +225,66 @@ public final class BluetoothStatusCodes { */ public static final int ERROR_DISCONNECT_REASON_BAD_PARAMETERS = 1109; + /** + * Indicates that setting the LE Audio Broadcast mode failed. + *

+ * Example solution: Change parameters and try again. If error persists, the app can report + * telemetry and/or log the error in a bugreport. + * + * @hide + */ + public static final int ERROR_LE_AUDIO_BROADCAST_SOURCE_SET_BROADCAST_MODE_FAILED = 1110; + + /** + * Indicates that setting a new encryption key for Bluetooth LE Audio Broadcast Source failed. + *

+ * Example solution: Change parameters and try again. If error persists, the app can report + * telemetry and/or log the error in a bugreport. + * + * @hide + */ + public static final int ERROR_LE_AUDIO_BROADCAST_SOURCE_SET_ENCRYPTION_KEY_FAILED = 1111; + + /** + * Indicates that connecting to a remote Broadcast Audio Scan Service failed. + *

+ * Example solution: Change parameters and try again. If error persists, the app can report + * telemetry and/or log the error in a bugreport. + * + * @hide + */ + public static final int ERROR_LE_AUDIO_BROADCAST_AUDIO_SCAN_SERVICE_CONNECT_FAILED = 1112; + + /** + * Indicates that disconnecting from a remote Broadcast Audio Scan Service failed. + *

+ * Example solution: Change parameters and try again. If error persists, the app can report + * telemetry and/or log the error in a bugreport. + * + * @hide + */ + public static final int ERROR_LE_AUDIO_BROADCAST_AUDIO_SCAN_SERVICE_DISCONNECT_FAILED = 1113; + + /** + * Indicates that enabling LE Audio Broadcast encryption failed + *

+ * Example solution: Change parameters and try again. If error persists, the app can report + * telemetry and/or log the error in a bugreport. + * + * @hide + */ + public static final int ERROR_LE_AUDIO_BROADCAST_SOURCE_ENABLE_ENCRYPTION_FAILED = 1114; + + /** + * Indicates that disabling LE Audio Broadcast encryption failed + *

+ * Example solution: Change parameters and try again. If error persists, the app can report + * telemetry and/or log the error in a bugreport. + * + * @hide + */ + public static final int ERROR_LE_AUDIO_BROADCAST_SOURCE_DISABLE_ENCRYPTION_FAILED = 1115; + /** * Indicates that an unknown error has occurred has occurred. */ -- cgit v1.2.3