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

Commit a28bba3e authored by Parvathy Shanmugam's avatar Parvathy Shanmugam Committed by Gerrit Code Review
Browse files

Merge changes from topic "IMS Threading Refactoring"

* changes:
  Fix for crash while merging 2 audio calls for initiating conference call
  (IMS Threading refactoring) Telephony IMS classes to schedule IMS callback on the main thread
parents cd247361 be7c8dca
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -107,6 +107,25 @@ public final class TelephonyUtils {
        }
    }

    /**
     * Convenience method for running the provided action in the provided
     * executor enclosed in
     * {@link Binder#clearCallingIdentity}/{@link Binder#restoreCallingIdentity}
     *
     * Any exception thrown by the given action will need to be handled by caller.
     *
     */
    public static void runWithCleanCallingIdentity(
            @NonNull Runnable action, @NonNull Executor executor) {
        if (action != null) {
            if (executor != null) {
                executor.execute(() -> runWithCleanCallingIdentity(action));
            } else {
                runWithCleanCallingIdentity(action);
            }
        }
    }


    /**
     * Convenience method for running the provided action enclosed in
+235 −140
Original line number Diff line number Diff line
@@ -27,10 +27,12 @@ import android.util.Log;

import com.android.ims.internal.IImsCallSession;
import com.android.ims.internal.IImsVideoCallProvider;
import com.android.internal.telephony.util.TelephonyUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;

/**
 * Provides the call initiation/termination, and media exchange between two IMS endpoints.
@@ -522,6 +524,7 @@ public class ImsCallSession {
    private final IImsCallSession miSession;
    private boolean mClosed = false;
    private Listener mListener;
    private Executor mListenerExecutor = Runnable::run;

    /** @hide */
    public ImsCallSession(IImsCallSession iSession) {
@@ -538,9 +541,9 @@ public class ImsCallSession {
    }

    /** @hide */
    public ImsCallSession(IImsCallSession iSession, Listener listener) {
    public ImsCallSession(IImsCallSession iSession, Listener listener, Executor executor) {
        this(iSession);
        setListener(listener);
        setListener(listener, executor);
    }

    /**
@@ -738,10 +741,14 @@ public class ImsCallSession {
     * override the previous listener.
     *
     * @param listener to listen to the session events of this object
     * @param executor an Executor that will execute callbacks
     * @hide
     */
    public void setListener(Listener listener) {
    public void setListener(Listener listener, Executor executor) {
        mListener = listener;
        if (executor != null) {
            mListenerExecutor = executor;
        }
    }

    /**
@@ -1205,44 +1212,56 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionInitiating(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionInitiating(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionProgressing(ImsStreamMediaProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionProgressing(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionInitiated(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionStarted(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionInitiatingFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionStartFailed(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionInitiatedFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionStartFailed(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionTerminated(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionTerminated(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1250,44 +1269,56 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionHeld(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionHeld(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionHoldFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionHoldFailed(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionHoldReceived(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionHoldReceived(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionResumed(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionResumed(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionResumeFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionResumeFailed(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionResumeReceived(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionResumeReceived(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1310,6 +1341,7 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionMergeComplete(IImsCallSession newSession) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    if (newSession != null) {
                        // New session created after conference
@@ -1319,6 +1351,7 @@ public class ImsCallSession {
                        mListener.callSessionMergeComplete(null);
                    }
                }
            }, mListenerExecutor);
        }

        /**
@@ -1328,9 +1361,11 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionMergeFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionMergeFailed(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1338,23 +1373,29 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionUpdated(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionUpdated(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionUpdateFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionUpdateFailed(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionUpdateReceived(ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionUpdateReceived(ImsCallSession.this, profile);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1363,26 +1404,33 @@ public class ImsCallSession {
        @Override
        public void callSessionConferenceExtended(IImsCallSession newSession,
                ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionConferenceExtended(ImsCallSession.this,
                            new ImsCallSession(newSession), profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionConferenceExtendFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                mListener.callSessionConferenceExtendFailed(ImsCallSession.this, reasonInfo);
                    mListener.callSessionConferenceExtendFailed(
                            ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionConferenceExtendReceived(IImsCallSession newSession,
                ImsCallProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionConferenceExtendReceived(ImsCallSession.this,
                            new ImsCallSession(newSession), profile);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1391,32 +1439,41 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionInviteParticipantsRequestDelivered() {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                mListener.callSessionInviteParticipantsRequestDelivered(ImsCallSession.this);
                    mListener.callSessionInviteParticipantsRequestDelivered(
                            ImsCallSession.this);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionInviteParticipantsRequestFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionInviteParticipantsRequestFailed(ImsCallSession.this,
                            reasonInfo);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionRemoveParticipantsRequestDelivered() {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionRemoveParticipantsRequestDelivered(ImsCallSession.this);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionRemoveParticipantsRequestFailed(ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionRemoveParticipantsRequestFailed(ImsCallSession.this,
                            reasonInfo);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1424,9 +1481,11 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionConferenceStateUpdated(ImsConferenceState state) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionConferenceStateUpdated(ImsCallSession.this, state);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1434,9 +1493,12 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionUssdMessageReceived(int mode, String ussdMessage) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                mListener.callSessionUssdMessageReceived(ImsCallSession.this, mode, ussdMessage);
                    mListener.callSessionUssdMessageReceived(ImsCallSession.this, mode,
                            ussdMessage);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1452,10 +1514,12 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionMayHandover(int srcNetworkType, int targetNetworkType) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionMayHandover(ImsCallSession.this, srcNetworkType,
                            targetNetworkType);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1464,10 +1528,12 @@ public class ImsCallSession {
        @Override
        public void callSessionHandover(int srcNetworkType, int targetNetworkType,
                ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionHandover(ImsCallSession.this, srcNetworkType,
                            targetNetworkType, reasonInfo);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1476,10 +1542,12 @@ public class ImsCallSession {
        @Override
        public void callSessionHandoverFailed(int srcNetworkType, int targetNetworkType,
                ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionHandoverFailed(ImsCallSession.this, srcNetworkType,
                            targetNetworkType, reasonInfo);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1487,9 +1555,11 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionTtyModeReceived(int mode) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionTtyModeReceived(ImsCallSession.this, mode);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1499,16 +1569,22 @@ public class ImsCallSession {
         *      otherwise.
         */
        public void callSessionMultipartyStateChanged(boolean isMultiParty) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                mListener.callSessionMultipartyStateChanged(ImsCallSession.this, isMultiParty);
                    mListener.callSessionMultipartyStateChanged(ImsCallSession.this,
                            isMultiParty);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionSuppServiceReceived(ImsSuppServiceNotification suppServiceInfo ) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                mListener.callSessionSuppServiceReceived(ImsCallSession.this, suppServiceInfo);
                    mListener.callSessionSuppServiceReceived(ImsCallSession.this,
                            suppServiceInfo);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1516,9 +1592,12 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionRttModifyRequestReceived(ImsCallProfile callProfile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                mListener.callSessionRttModifyRequestReceived(ImsCallSession.this, callProfile);
                    mListener.callSessionRttModifyRequestReceived(ImsCallSession.this,
                            callProfile);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1526,9 +1605,11 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionRttModifyResponseReceived(int status) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionRttModifyResponseReceived(status);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1536,9 +1617,11 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionRttMessageReceived(String rttMessage) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionRttMessageReceived(rttMessage);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1546,23 +1629,29 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionRttAudioIndicatorChanged(ImsStreamMediaProfile profile) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionRttAudioIndicatorChanged(profile);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionTransferred() {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionTransferred(ImsCallSession.this);
                }
            }, mListenerExecutor);
        }

        @Override
        public void callSessionTransferFailed(@Nullable ImsReasonInfo reasonInfo) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionTransferFailed(ImsCallSession.this, reasonInfo);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1571,9 +1660,11 @@ public class ImsCallSession {
         */
        @Override
        public void callSessionDtmfReceived(char dtmf) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionDtmfReceived(dtmf);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1581,9 +1672,11 @@ public class ImsCallSession {
         */
        @Override
        public void callQualityChanged(CallQuality callQuality) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callQualityChanged(callQuality);
                }
            }, mListenerExecutor);
        }

        /**
@@ -1593,10 +1686,12 @@ public class ImsCallSession {
        @Override
        public void callSessionRtpHeaderExtensionsReceived(
                @NonNull List<RtpHeaderExtension> extensions) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mListener != null) {
                    mListener.callSessionRtpHeaderExtensionsReceived(
                            new ArraySet<RtpHeaderExtension>(extensions));
                }
            }, mListenerExecutor);
        }
    }