summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothAdapter.java
diff options
context:
space:
mode:
authorEtienne Ruffieux <eruffieux@google.com>2022-03-30 06:51:34 +0000
committerEtienne Ruffieux <eruffieux@google.com>2022-03-30 08:54:39 +0000
commit5b15f829211398f73deec0bc644382c16770b3e6 (patch)
treeb25a4423629d25aea66c666dcf11545640bfc268 /framework/java/android/bluetooth/BluetoothAdapter.java
parent26217c47024b7ae237626d0dc46b3111520f2ead (diff)
Store Binder.clearCallingIdentity value as final var
Bug: 227412240 Test: manual Tag: #feature Change-Id: I91d6b0dd0d21767a9abad7e196e8f54eeb818217
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothAdapter.java50
1 files changed, 38 insertions, 12 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index 0db80ad786..9d391a03fd 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -880,16 +880,43 @@ public final class BluetoothAdapter {
}
executor = mExecutor;
callback = mCallback;
- // null out to allow garbage collection, prevent triggering callback more than once
mExecutor = null;
mCallback = null;
}
- Binder.clearCallingIdentity();
- if (info == null) {
+ final long identity = Binder.clearCallingIdentity();
+ try {
+ if (info == null) {
+ executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
+ BluetoothStatusCodes.FEATURE_NOT_SUPPORTED));
+ } else {
+ executor.execute(() -> callback.onBluetoothActivityEnergyInfoAvailable(info));
+ }
+ } finally {
+ Binder.restoreCallingIdentity(identity);
+ }
+ }
+
+ /**
+ * Framework only method that is called when the service can't be reached.
+ */
+ public void onError(int errorCode) {
+ Executor executor;
+ OnBluetoothActivityEnergyInfoCallback callback;
+ synchronized (mLock) {
+ if (mExecutor == null || mCallback == null) {
+ return;
+ }
+ executor = mExecutor;
+ callback = mCallback;
+ mExecutor = null;
+ mCallback = null;
+ }
+ final long identity = Binder.clearCallingIdentity();
+ try {
executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
- BluetoothStatusCodes.FEATURE_NOT_SUPPORTED));
- } else {
- executor.execute(() -> callback.onBluetoothActivityEnergyInfoAvailable(info));
+ errorCode));
+ } finally {
+ Binder.restoreCallingIdentity(identity);
}
}
}
@@ -2780,21 +2807,20 @@ public final class BluetoothAdapter {
@NonNull OnBluetoothActivityEnergyInfoCallback callback) {
requireNonNull(executor, "executor cannot be null");
requireNonNull(callback, "callback cannot be null");
+ OnBluetoothActivityEnergyInfoProxy proxy =
+ new OnBluetoothActivityEnergyInfoProxy(executor, callback);
try {
mServiceLock.readLock().lock();
if (mService != null) {
mService.requestActivityInfo(
- new OnBluetoothActivityEnergyInfoProxy(executor, callback),
+ proxy,
mAttributionSource);
} else {
- executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
- BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND));
+ proxy.onError(BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND);
}
} catch (RemoteException e) {
Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
- Binder.clearCallingIdentity();
- executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
- BluetoothStatusCodes.ERROR_UNKNOWN));
+ proxy.onError(BluetoothStatusCodes.ERROR_UNKNOWN);
} finally {
mServiceLock.readLock().unlock();
}