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

Commit 196c498a authored by Parvathy Shanmugam's avatar Parvathy Shanmugam
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

Test: atest FrameworksTelephonyTests:ImsPhoneCallTrackerTest,
atest FrameworksTelephonyTests:ImsCallTest
Bug: 197989471
Change-Id: I2b1e5234d7d9966c96f9fdc58bea9844543ccaae
parent 03ee9992
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ import com.android.internal.telephony.metrics.CallQualityMetrics;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession;
import com.android.internal.telephony.nano.TelephonyProto.TelephonyCallSession.Event.ImsCommand;
import com.android.internal.telephony.util.TelephonyUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.telephony.Rlog;

@@ -191,8 +192,8 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {

    private final MmTelFeatureListener mMmTelFeatureListener = new MmTelFeatureListener();
    private class MmTelFeatureListener extends MmTelFeature.Listener {
        @Override
        public void onIncomingCall(IImsCallSession c, Bundle extras) {

        private void processIncomingCall(IImsCallSession c, Bundle extras) {
            if (DBG) log("onReceive : incoming call intent");
            mOperationLocalLog.log("onIncomingCall Received");

@@ -292,14 +293,22 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            }
        }

        @Override
        public void onIncomingCall(IImsCallSession c, Bundle extras) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> processIncomingCall(c, extras),
                    mExecutor);
        }

        @Override
        public void onVoiceMessageCountUpdate(int count) {
            TelephonyUtils.runWithCleanCallingIdentity(()-> {
                if (mPhone != null && mPhone.mDefaultPhone != null) {
                    if (DBG) log("onVoiceMessageCountChanged :: count=" + count);
                    mPhone.mDefaultPhone.setVoiceMessageCount(count);
                } else {
                    loge("onVoiceMessageCountUpdate: null phone");
                }
            }, mExecutor);
        }
    }

@@ -548,6 +557,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {

    private String mLastDialString = null;
    private ImsDialArgs mLastDialArgs = null;
    private Executor mExecutor = Runnable::run;

    /**
     * Listeners to changes in the phone state.  Intended for use by other interested IMS components
@@ -928,6 +938,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
    public ImsPhoneCallTracker(ImsPhone phone, ConnectorFactory factory, Executor executor) {
        this.mPhone = phone;
        mConnectorFactory = factory;
        if (executor != null) {
            mExecutor = executor;
        }

        mMetrics = TelephonyMetrics.getInstance();

+12 −1
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -42,16 +44,25 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import java.util.concurrent.Executor;

public class ImsCallTest extends TelephonyTest {

    private Bundle mBundle;
    private ImsCallProfile mTestCallProfile;

    private Executor mExecutor = new Executor() {
        @Override
        public void execute(Runnable r) {
            r.run();
        }
    };
    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        mTestCallProfile = new ImsCallProfile();
        mBundle = mTestCallProfile.mCallExtras;
        doReturn(mExecutor).when(mContext).getMainExecutor();
    }

    @After
@@ -70,7 +81,7 @@ public class ImsCallTest extends TelephonyTest {

        ArgumentCaptor<ImsCallSession.Listener> listenerCaptor =
                ArgumentCaptor.forClass(ImsCallSession.Listener.class);
        verify(mockSession).setListener(listenerCaptor.capture());
        verify(mockSession).setListener(listenerCaptor.capture(), any());
        ImsCallSession.Listener listener = listenerCaptor.getValue();
        assertNotNull(listener);

+9 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

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

@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -141,6 +142,13 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
    @Captor
    private ArgumentCaptor<Set<RtpHeaderExtensionType>> mRtpHeaderExtensionTypeCaptor;

    private Executor mExecutor = new Executor() {
        @Override
        public void execute(Runnable r) {
            r.run();
        }
    };

    private void imsCallMocking(final ImsCall imsCall) throws Exception {

        doAnswer(new Answer<Void>() {
@@ -189,6 +197,7 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
            }
        }).when(imsCall).hold();

        doReturn(mExecutor).when(mContext).getMainExecutor();
        imsCall.attachSession(mImsCallSession);
        doReturn("1").when(mImsCallSession).getCallId();
        doReturn(mImsCallProfile).when(mImsCallSession).getCallProfile();