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

Commit 79dca65d authored by Brad Ebinger's avatar Brad Ebinger Committed by Gerrit Code Review
Browse files

Merge "Fix deadlock during Testing"

parents 36db0d2f 510677ba
Loading
Loading
Loading
Loading
+34 −30
Original line number Diff line number Diff line
@@ -44,8 +44,10 @@ import com.android.ims.internal.IImsMultiEndpoint;
import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.ims.internal.IImsUt;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * A container of the IImsServiceController binder, which implements all of the ImsFeatures that
@@ -76,7 +78,8 @@ public class MmTelFeatureConnection {
    private abstract class CallbackAdapterManager<T> {
        private static final String TAG = "CallbackAdapterManager";

        protected final Set<T> mLocalCallbacks = new HashSet<>();
        protected final Set<T> mLocalCallbacks =
                Collections.newSetFromMap(new ConcurrentHashMap<>());
        private boolean mHasConnected = false;

        public void addCallback(T localCallback) throws RemoteException {
@@ -91,16 +94,16 @@ public class MmTelFeatureConnection {
                        throw new RemoteException("Can not create connection!");
                    }
                }
            }
            Log.i(TAG, "Local callback added: " + localCallback);
            mLocalCallbacks.add(localCallback);
        }
        }

        public void removeCallback(T localCallback) {
            // We only maintain one binding to the ImsService per process.
            synchronized (mLock) {
            Log.i(TAG, "Local callback removed: " + localCallback);
            mLocalCallbacks.remove(localCallback);
            synchronized (mLock) {
                // If we have removed all local callbacks, remove callback to ImsService.
                if(mHasConnected) {
                    if (mLocalCallbacks.isEmpty()) {
@@ -118,10 +121,10 @@ public class MmTelFeatureConnection {
                    // Still mark the connection as disconnected, even if this fails.
                    mHasConnected = false;
                }
            }
            Log.i(TAG, "Closing connection and clearing callbacks");
            mLocalCallbacks.clear();
        }
        }

        abstract boolean createConnection() throws RemoteException;

@@ -140,48 +143,39 @@ public class MmTelFeatureConnection {
            public void onRegistered(int imsRadioTech) {
                Log.i(TAG, "onRegistered ::");

                synchronized (mLock) {
                mLocalCallbacks.forEach(l -> l.onRegistered(imsRadioTech));
            }
            }

            @Override
            public void onRegistering(int imsRadioTech) {
                Log.i(TAG, "onRegistering ::");

                synchronized (mLock) {
                mLocalCallbacks.forEach(l -> l.onRegistering(imsRadioTech));
            }
            }

            @Override
            public void onDeregistered(ImsReasonInfo imsReasonInfo) {
                Log.i(TAG, "onDeregistered ::");

                synchronized (mLock) {
                mLocalCallbacks.forEach(l -> l.onDeregistered(imsReasonInfo));
            }
            }

            @Override
            public void onTechnologyChangeFailed(int targetRadioTech, ImsReasonInfo imsReasonInfo) {
                Log.i(TAG, "onTechnologyChangeFailed :: targetAccessTech=" + targetRadioTech +
                        ", imsReasonInfo=" + imsReasonInfo);

                synchronized (mLock) {
                    mLocalCallbacks.forEach(l -> l.onTechnologyChangeFailed(targetRadioTech,
                            imsReasonInfo));
            }
            }

            @Override
            public void onSubscriberAssociatedUriChanged(Uri[] uris) {
                Log.i(TAG, "onSubscriberAssociatedUriChanged");
                synchronized (mLock) {

                mLocalCallbacks.forEach(l -> l.onSubscriberAssociatedUriChanged(uris));
            }
        }
        }

        @Override
        boolean createConnection() throws RemoteException {
@@ -220,16 +214,18 @@ public class MmTelFeatureConnection {
            // Called when the Capabilities Status on this connection have changed.
            @Override
            public void onCapabilitiesStatusChanged(ImsFeature.Capabilities config) {
                synchronized (mLock) {
                mLocalCallbacks.forEach(
                        callback -> callback.onCapabilitiesStatusChanged(config));
            }
        }
        }

        @Override
        boolean createConnection() throws RemoteException {
            IImsMmTelFeature binder = getServiceInterface(mBinder);
            IImsMmTelFeature binder;
            synchronized (mLock) {
                checkServiceIsReady();
                binder = getServiceInterface(mBinder);
            }
            if (binder != null) {
                binder.addCapabilityCallback(mCallbackAdapter);
                return true;
@@ -241,7 +237,15 @@ public class MmTelFeatureConnection {

        @Override
        void removeConnection() {
            IImsMmTelFeature binder = getServiceInterface(mBinder);
            IImsMmTelFeature binder = null;
            synchronized (mLock) {
                try {
                    checkServiceIsReady();
                    binder = getServiceInterface(mBinder);
                } catch (RemoteException e) {
                    // binder is null
                }
            }
            if (binder != null) {
                try {
                    binder.removeCapabilityCallback(mCallbackAdapter);