Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5b15f829 authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

Store Binder.clearCallingIdentity value as final var

Bug: 227412240
Test: manual
Tag: #feature
Change-Id: I91d6b0dd0d21767a9abad7e196e8f54eeb818217
parent 26217c47
Loading
Loading
Loading
Loading
+38 −12
Original line number Original line Diff line number Diff line
@@ -880,17 +880,44 @@ public final class BluetoothAdapter {
                }
                }
                executor = mExecutor;
                executor = mExecutor;
                callback = mCallback;
                callback = mCallback;
                // null out to allow garbage collection, prevent triggering callback more than once
                mExecutor = null;
                mExecutor = null;
                mCallback = null;
                mCallback = null;
            }
            }
            Binder.clearCallingIdentity();
            final long identity = Binder.clearCallingIdentity();
            try {
                if (info == null) {
                if (info == null) {
                    executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
                    executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
                            BluetoothStatusCodes.FEATURE_NOT_SUPPORTED));
                            BluetoothStatusCodes.FEATURE_NOT_SUPPORTED));
                } else {
                } else {
                    executor.execute(() -> callback.onBluetoothActivityEnergyInfoAvailable(info));
                    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(
                        errorCode));
            } finally {
                Binder.restoreCallingIdentity(identity);
            }
        }
        }
    }
    }


@@ -2780,21 +2807,20 @@ public final class BluetoothAdapter {
            @NonNull OnBluetoothActivityEnergyInfoCallback callback) {
            @NonNull OnBluetoothActivityEnergyInfoCallback callback) {
        requireNonNull(executor, "executor cannot be null");
        requireNonNull(executor, "executor cannot be null");
        requireNonNull(callback, "callback cannot be null");
        requireNonNull(callback, "callback cannot be null");
        OnBluetoothActivityEnergyInfoProxy proxy =
                new OnBluetoothActivityEnergyInfoProxy(executor, callback);
        try {
        try {
            mServiceLock.readLock().lock();
            mServiceLock.readLock().lock();
            if (mService != null) {
            if (mService != null) {
                mService.requestActivityInfo(
                mService.requestActivityInfo(
                        new OnBluetoothActivityEnergyInfoProxy(executor, callback),
                        proxy,
                        mAttributionSource);
                        mAttributionSource);
            } else {
            } else {
                executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
                proxy.onError(BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND);
                        BluetoothStatusCodes.ERROR_PROFILE_SERVICE_NOT_BOUND));
            }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
            Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
            Binder.clearCallingIdentity();
            proxy.onError(BluetoothStatusCodes.ERROR_UNKNOWN);
            executor.execute(() -> callback.onBluetoothActivityEnergyInfoError(
                    BluetoothStatusCodes.ERROR_UNKNOWN));
        } finally {
        } finally {
            mServiceLock.readLock().unlock();
            mServiceLock.readLock().unlock();
        }
        }