diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-03-18 01:09:07 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-03-18 01:09:07 +0000 |
commit | 9b52556d5cd7842ebfb13f13f3dc9ca68ae018c3 (patch) | |
tree | 72f48848f750d5fff52fee563cad8e952abcfd43 /framework/java/android/bluetooth/BluetoothAdapter.java | |
parent | ad221bf0c86a98f68d69e06ad79e025a38563881 (diff) | |
parent | 1d06e1a4e899e5a0d22905241ea5cf935224ef81 (diff) |
Snap for 8317698 from 1d06e1a4e899e5a0d22905241ea5cf935224ef81 to tm-release
Change-Id: I50c536ec3728a64771a134f3c4eba5c68465e640
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 81 |
1 files changed, 70 insertions, 11 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index de3f570d96..58ab06dffb 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -59,7 +59,6 @@ import android.os.IBinder; import android.os.IpcDataCache; import android.os.ParcelUuid; import android.os.RemoteException; -import android.os.ResultReceiver; import android.sysprop.BluetoothProperties; import android.util.Log; import android.util.Pair; @@ -832,6 +831,55 @@ public final class BluetoothAdapter { }; /** + * Interface for Bluetooth activity energy info listener. Should be implemented by applications + * and set when calling {@link BluetoothAdapter#requestControllerActivityEnergyInfo}. + * + * @hide + */ + @SystemApi + public interface OnBluetoothActivityEnergyInfoListener { + /** + * Called when Bluetooth activity energy info is available. + * Note: this listener is triggered at most once for each call to + * {@link #requestControllerActivityEnergyInfo}. + * + * @param info the latest {@link BluetoothActivityEnergyInfo}, or null if unavailable. + */ + void onBluetoothActivityEnergyInfo(@Nullable BluetoothActivityEnergyInfo info); + } + + private static class OnBluetoothActivityEnergyInfoProxy + extends IBluetoothActivityEnergyInfoListener.Stub { + private final Object mLock = new Object(); + @Nullable @GuardedBy("mLock") private Executor mExecutor; + @Nullable @GuardedBy("mLock") private OnBluetoothActivityEnergyInfoListener mListener; + + OnBluetoothActivityEnergyInfoProxy(Executor executor, + OnBluetoothActivityEnergyInfoListener listener) { + mExecutor = executor; + mListener = listener; + } + + @Override + public void onBluetoothActivityEnergyInfo(BluetoothActivityEnergyInfo info) { + Executor executor; + OnBluetoothActivityEnergyInfoListener listener; + synchronized (mLock) { + if (mExecutor == null || mListener == null) { + return; + } + executor = mExecutor; + listener = mListener; + // null out to allow garbage collection, prevent triggering listener more than once + mExecutor = null; + mListener = null; + } + Binder.clearCallingIdentity(); + executor.execute(() -> listener.onBluetoothActivityEnergyInfo(info)); + } + } + + /** * Get a handle to the default local Bluetooth adapter. * <p> * Currently Android only supports one Bluetooth adapter, but the API could @@ -1488,11 +1536,10 @@ public final class BluetoothAdapter { * @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]; @@ -1516,6 +1563,18 @@ public final class BluetoothAdapter { } /** + * 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() { + return Arrays.asList(getUuids()); + } + + /** * Set the friendly Bluetooth name of the local Bluetooth adapter. * <p>This name is visible to remote Bluetooth devices. * <p>Valid Bluetooth names are a maximum of 248 bytes using UTF-8 @@ -2675,22 +2734,22 @@ public final class BluetoothAdapter { android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, }) - public void requestControllerActivityEnergyInfo(@NonNull ResultReceiver result) { - requireNonNull(result, "ResultReceiver cannot be null"); + public void requestControllerActivityEnergyInfo( + @NonNull @CallbackExecutor Executor executor, + @NonNull OnBluetoothActivityEnergyInfoListener listener) { + requireNonNull(executor, "executor cannot be null"); + requireNonNull(listener, "listener cannot be null"); try { mServiceLock.readLock().lock(); if (mService != null) { - mService.requestActivityInfo(result, mAttributionSource); - result = null; + mService.requestActivityInfo( + new OnBluetoothActivityEnergyInfoProxy(executor, listener), + mAttributionSource); } } catch (RemoteException e) { Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e); } finally { mServiceLock.readLock().unlock(); - if (result != null) { - // Only send an immediate result if we failed. - result.send(0, null); - } } } |