diff options
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 78 |
1 files changed, 55 insertions, 23 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 46d19217dd..aedd85d156 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -188,6 +188,16 @@ public final class BluetoothAdapter { STATE_BLE_TURNING_OFF }) @Retention(RetentionPolicy.SOURCE) + public @interface InternalAdapterState {} + + /** @hide */ + @IntDef(prefix = { "STATE_" }, value = { + STATE_OFF, + STATE_TURNING_ON, + STATE_ON, + STATE_TURNING_OFF, + }) + @Retention(RetentionPolicy.SOURCE) public @interface AdapterState {} /** @@ -268,14 +278,14 @@ public final class BluetoothAdapter { public @interface RfcommListenerResult {} /** - * Human-readable string helper for AdapterState + * Human-readable string helper for AdapterState and InternalAdapterState * * @hide */ @SystemApi @RequiresNoPermission @NonNull - public static String nameForState(@AdapterState int state) { + public static String nameForState(@InternalAdapterState int state) { switch (state) { case STATE_OFF: return "OFF"; @@ -1151,8 +1161,7 @@ public final class BluetoothAdapter { * Fetch the current bluetooth state. If the service is down, return * OFF. */ - @AdapterState - private int getStateInternal() { + private @InternalAdapterState int getStateInternal() { int state = BluetoothAdapter.STATE_OFF; try { mServiceLock.readLock().lock(); @@ -1183,8 +1192,7 @@ public final class BluetoothAdapter { */ @RequiresLegacyBluetoothPermission @RequiresNoPermission - @AdapterState - public int getState() { + public @AdapterState int getState() { int state = getStateInternal(); // Consider all internal states as OFF @@ -1220,10 +1228,9 @@ public final class BluetoothAdapter { */ @RequiresLegacyBluetoothPermission @RequiresNoPermission - @AdapterState @UnsupportedAppUsage(publicAlternatives = "Use {@link #getState()} instead to determine " + "whether you can use BLE & BT classic.") - public int getLeState() { + public @InternalAdapterState int getLeState() { int state = getStateInternal(); if (VDBG) { @@ -1405,7 +1412,7 @@ public final class BluetoothAdapter { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) - public boolean factoryReset() { + public boolean clearBluetooth() { try { mServiceLock.readLock().lock(); if (mService != null) { @@ -1427,37 +1434,62 @@ public final class BluetoothAdapter { return false; } + /** + * See {@link #clearBluetooth()} + * + * @return true to indicate that the config file was successfully cleared + * @hide + */ + @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) + @RequiresBluetoothConnectPermission + @RequiresPermission(allOf = { + android.Manifest.permission.BLUETOOTH_CONNECT, + android.Manifest.permission.BLUETOOTH_PRIVILEGED, + }) + public boolean factoryReset() { + return clearBluetooth(); + } + /** * Get the UUIDs supported by the local Bluetooth adapter. * * @return the UUIDs supported by the local Bluetooth Adapter. * @hide */ - @SystemApi + @UnsupportedAppUsage @RequiresLegacyBluetoothPermission @RequiresBluetoothConnectPermission @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) - @SuppressLint(value = {"ArrayReturn", "NullableCollection"}) public @NonNull ParcelUuid[] getUuids() { - if (getState() != STATE_ON) { - return new ParcelUuid[0]; + List<ParcelUuid> parcels = getUuidsList(); + return parcels.toArray(new ParcelUuid[parcels.size()]); + } + + /** + * Get the UUIDs supported by the local Bluetooth adapter. + * + * @return a list of the UUIDs supported by the local Bluetooth Adapter. + * @hide + */ + @SystemApi + @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) + public @NonNull List<ParcelUuid> getUuidsList() { + List<ParcelUuid> defaultValue = new ArrayList<>(); + if (getState() != STATE_ON || mService == null) { + return defaultValue; } + mServiceLock.readLock().lock(); try { - mServiceLock.readLock().lock(); - if (mService != null) { - final SynchronousResultReceiver<List<ParcelUuid>> recv = - new SynchronousResultReceiver(); - mService.getUuids(mAttributionSource, recv); - List<ParcelUuid> parcels = recv.awaitResultNoInterrupt(getSyncTimeout()) - .getValue(new ArrayList<>()); - return parcels.toArray(new ParcelUuid[parcels.size()]); - } + final SynchronousResultReceiver<List<ParcelUuid>> recv = + new SynchronousResultReceiver(); + mService.getUuids(mAttributionSource, recv); + return recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue); } catch (RemoteException | TimeoutException e) { Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } finally { mServiceLock.readLock().unlock(); } - return new ParcelUuid[0]; + return defaultValue; } /** |
