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

Commit 9db36867 authored by Parvathy Shanmugam's avatar Parvathy Shanmugam Committed by sparvathy
Browse files

(IMS Threading refactoring) Telephony IMS classes to schedule IMS callback on the main thread

Modified to schedule callbacks on main thread or callback executor rather than on binder thread
Achieved by using the utility api runWithCleanCallingIdentity to run the action in executor
In ImsCall Passing the main executor from context for callback exector.

Test: atest ImsCommonTests
Bug: 197989471
Change-Id: Ib047b7daadf9e979983552a3a027bb80b5250302
Merged-In: Ib047b7daadf9e979983552a3a027bb80b5250302
parent d92dddbb
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -1123,7 +1123,7 @@ public class ImsCall implements ICall {
             mSession = session;

             try {
                 mSession.setListener(createCallSessionListener());
                 mSession.setListener(createCallSessionListener(), mContext.getMainExecutor());
             } catch (Throwable t) {
                 loge("attachSession :: ", t);
                 throwImsException(t, 0);
@@ -1147,7 +1147,7 @@ public class ImsCall implements ICall {
            mSession = session;

            try {
                session.setListener(createCallSessionListener());
                session.setListener(createCallSessionListener(), mContext.getMainExecutor());
                session.start(callee, mCallProfile);
            } catch (Throwable t) {
                loge("start(1) :: ", t);
@@ -1173,7 +1173,7 @@ public class ImsCall implements ICall {
            mIsConferenceHost = true;

            try {
                session.setListener(createCallSessionListener());
                session.setListener(createCallSessionListener(), mContext.getMainExecutor());
                session.start(participants, mCallProfile);
            } catch (Throwable t) {
                loge("start(n) :: ", t);
@@ -2097,9 +2097,9 @@ public class ImsCall implements ICall {

    private void setTransientSessionAsPrimary(ImsCallSession transientSession) {
        synchronized (ImsCall.this) {
            mSession.setListener(null);
            mSession.setListener(null, null);
            mSession = transientSession;
            mSession.setListener(createCallSessionListener());
            mSession.setListener(createCallSessionListener(), mContext.getMainExecutor());
        }
    }

@@ -2214,7 +2214,7 @@ public class ImsCall implements ICall {

                // Clear the listener for this transient session, we'll create a new listener
                // when it is attached to the final ImsCall that it should live on.
                transientConferenceSession.setListener(null);
                transientConferenceSession.setListener(null, null);

                // Determine which call the transient session should be moved to.  If the current
                // call session is still alive and the merge peer's session is not, we have a
@@ -2409,7 +2409,7 @@ public class ImsCall implements ICall {

            // Try to clean up the transient session if it exists.
            if (mTransientConferenceSession != null) {
                mTransientConferenceSession.setListener(null);
                mTransientConferenceSession.setListener(null, null);
                mTransientConferenceSession = null;
            }

+60 −38
Original line number Diff line number Diff line
@@ -33,9 +33,11 @@ import com.android.ims.internal.IImsUt;
import com.android.ims.internal.IImsUtListener;
import com.android.internal.annotations.VisibleForTesting;
import com.android.telephony.Rlog;
import com.android.internal.telephony.util.TelephonyUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;

/**
 * Provides APIs for the supplementary service settings using IMS (Ut interface).
@@ -85,9 +87,13 @@ public class ImsUt implements ImsUtInterface {
    private HashMap<Integer, Message> mPendingCmds =
            new HashMap<Integer, Message>();
    private Registrant mSsIndicationRegistrant;
    private Executor mExecutor = Runnable::run;

    public ImsUt(IImsUt iUt) {
    public ImsUt(IImsUt iUt, Executor executor) {
        miUt = iUt;
        if (executor != null) {
            mExecutor = executor;
        }

        if (miUt != null) {
            try {
@@ -664,22 +670,26 @@ public class ImsUt implements ImsUtInterface {
         */
        @Override
        public void utConfigurationUpdated(IImsUt ut, int id) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                Integer key = Integer.valueOf(id);

                synchronized(mLockObj) {
                    sendSuccessReport(mPendingCmds.get(key));
                    mPendingCmds.remove(key);
                }
            }, mExecutor);
        }

        @Override
        public void utConfigurationUpdateFailed(IImsUt ut, int id, ImsReasonInfo error) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                Integer key = Integer.valueOf(id);

                synchronized(mLockObj) {
                    sendFailureReport(mPendingCmds.get(key), error);
                    mPendingCmds.remove(key);
                }
            }, mExecutor);
        }

        /**
@@ -710,20 +720,24 @@ public class ImsUt implements ImsUtInterface {
         */
        @Override
        public void lineIdentificationSupplementaryServiceResponse(int id, ImsSsInfo config) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                synchronized(mLockObj) {
                    sendSuccessReport(mPendingCmds.get(id), config);
                    mPendingCmds.remove(id);
                }
            }, mExecutor);
        }

        @Override
        public void utConfigurationQueryFailed(IImsUt ut, int id, ImsReasonInfo error) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                Integer key = Integer.valueOf(id);

                synchronized(mLockObj) {
                    sendFailureReport(mPendingCmds.get(key), error);
                    mPendingCmds.remove(key);
                }
            }, mExecutor);
        }

        /**
@@ -732,12 +746,14 @@ public class ImsUt implements ImsUtInterface {
        @Override
        public void utConfigurationCallBarringQueried(IImsUt ut,
                int id, ImsSsInfo[] cbInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                Integer key = Integer.valueOf(id);

                synchronized(mLockObj) {
                    sendSuccessReport(mPendingCmds.get(key), cbInfo);
                    mPendingCmds.remove(key);
                }
            }, mExecutor);
        }

        /**
@@ -746,12 +762,14 @@ public class ImsUt implements ImsUtInterface {
        @Override
        public void utConfigurationCallForwardQueried(IImsUt ut,
                int id, ImsCallForwardInfo[] cfInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                Integer key = Integer.valueOf(id);

                synchronized(mLockObj) {
                    sendSuccessReport(mPendingCmds.get(key), cfInfo);
                    mPendingCmds.remove(key);
                }
            }, mExecutor);
        }

        /**
@@ -760,12 +778,14 @@ public class ImsUt implements ImsUtInterface {
        @Override
        public void utConfigurationCallWaitingQueried(IImsUt ut,
                int id, ImsSsInfo[] cwInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                Integer key = Integer.valueOf(id);

                synchronized(mLockObj) {
                    sendSuccessReport(mPendingCmds.get(key), cwInfo);
                    mPendingCmds.remove(key);
                }
            }, mExecutor);
        }

        /**
@@ -773,9 +793,11 @@ public class ImsUt implements ImsUtInterface {
         */
        @Override
        public void onSupplementaryServiceIndication(ImsSsData ssData) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mSsIndicationRegistrant != null) {
                    mSsIndicationRegistrant.notifyResult(ssData);
                }
            }, mExecutor);
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -436,7 +436,7 @@ public class MmTelFeatureConnection extends FeatureConnection {
            // This will internally set up a listener on the ImsUtImplBase interface, and there is
            // a limitation that there can only be one. If multiple connections try to create this
            // UT interface, it will throw an IllegalStateException.
            mUt = (imsUt != null) ? new ImsUt(imsUt) : null;
            mUt = (imsUt != null) ? new ImsUt(imsUt, mContext.getMainExecutor()) : null;
            return mUt;
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ public class ImsUtTest extends ImsTestBase {
    public void testClirConversionCompat() throws Exception {
        ArgumentCaptor<ImsUt.IImsUtListenerProxy> captor =
                ArgumentCaptor.forClass(ImsUt.IImsUtListenerProxy.class);
        ImsUt mImsUt = new ImsUt(mImsUtBinder);
        ImsUt mImsUt = new ImsUt(mImsUtBinder, Runnable::run);
        verify(mImsUtBinder).setListener(captor.capture());
        ImsUt.IImsUtListenerProxy proxy = captor.getValue();
        assertNotNull(proxy);
@@ -125,7 +125,7 @@ public class ImsUtTest extends ImsTestBase {
    public void testClipConversionCompat() throws Exception {
        ArgumentCaptor<ImsUt.IImsUtListenerProxy> captor =
                ArgumentCaptor.forClass(ImsUt.IImsUtListenerProxy.class);
        ImsUt mImsUt = new ImsUt(mImsUtBinder);
        ImsUt mImsUt = new ImsUt(mImsUtBinder, Runnable::run);
        verify(mImsUtBinder).setListener(captor.capture());
        ImsUt.IImsUtListenerProxy proxy = captor.getValue();
        assertNotNull(proxy);