summaryrefslogtreecommitdiff
path: root/framework/java/android
diff options
context:
space:
mode:
authorEtienne Ruffieux <eruffieux@google.com>2022-03-30 15:43:14 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-03-30 15:43:14 +0000
commit65b8a67060b9ac8a423f1b35c6edef5ce76d35fe (patch)
tree008c7e9c0a77e22f2d715383d036f93cb1cf3e1d /framework/java/android
parentbd5eed4990647306de04a873898614af8f2ee353 (diff)
parent1bd612d1df968ab3ba0ebf8ac81e9f9fbd3de11b (diff)
Merge "Store Binder.clearCallingIdentity value as final var" am: e2f11e80d1 am: 45b30f756a am: 1bd612d1df
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2049285 Change-Id: I56966db0baa98929d4cbd62fe99ede6491e4dce8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'framework/java/android')
-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 0a2fb4fb44..4e950e31f8 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -902,16 +902,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);
}
}
}
@@ -2792,21 +2819,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();
}