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

Commit a0273706 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Merge "Add lock on mCallbacks in ServiceBinder" am: fa65601a am: be57778d

am: 02b4bc1e

Change-Id: I210cd7852922fb6b883345f4eb8e8722ad79651d
parents 7e070a08 02b4bc1e
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -73,13 +73,15 @@ public abstract class ServiceBinder {
            // Reset any abort request if we're asked to bind again.
            clearAbort();

            synchronized (mCallbacks) {
                if (!mCallbacks.isEmpty()) {
                    // Binding already in progress, append to the list of callbacks and bail out.
                    mCallbacks.add(callback);
                    return;
                }

                mCallbacks.add(callback);
            }

            if (mServiceConnection == null) {
                Intent serviceIntent = new Intent(mServiceAction).setComponent(mComponentName);
                ServiceConnection connection = new ServiceBinderConnection(call);
@@ -351,10 +353,16 @@ public abstract class ServiceBinder {
     * outstanding callbacks is cleared afterwards.
     */
    private void handleSuccessfulConnection() {
        for (BindCallback callback : mCallbacks) {
        // Make a copy so that we don't have a deadlock inside one of the callbacks.
        Set<BindCallback> callbacksCopy = new ArraySet<>();
        synchronized (mCallbacks) {
            callbacksCopy.addAll(mCallbacks);
            mCallbacks.clear();
        }

        for (BindCallback callback : callbacksCopy) {
            callback.onSuccess();
        }
        mCallbacks.clear();
    }

    /**
@@ -362,10 +370,16 @@ public abstract class ServiceBinder {
     * outstanding callbacks is cleared afterwards.
     */
    private void handleFailedConnection() {
        for (BindCallback callback : mCallbacks) {
        // Make a copy so that we don't have a deadlock inside one of the callbacks.
        Set<BindCallback> callbacksCopy = new ArraySet<>();
        synchronized (mCallbacks) {
            callbacksCopy.addAll(mCallbacks);
            mCallbacks.clear();
        }

        for (BindCallback callback : callbacksCopy) {
            callback.onFailure();
        }
        mCallbacks.clear();
    }

    /**