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

Commit 15ccd9bc authored by Tyler Gunn's avatar Tyler Gunn Committed by Brad Ebinger
Browse files

Enhance logs and cleanup removed connections.

Enhancing the log of the updatePhoneState logs to include the ids of
the connections instead of just a count.
Adding a new cleanupAndRemoveConnection method which is used to
remove a connection which was replaced when a new unknown connection
replaces a dialing connection (ie both on IMS).

Test: Add unit test for connection cleanup/removal.
Test: Manual call tests to verify logs.
Bug: 225961946
Change-Id: I4d9f633d5c1ebe9021cf5929a5b56f1807114e62
Merged-In: I4d9f633d5c1ebe9021cf5929a5b56f1807114e62
parent 7dfa08a1
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.telephony.Rlog;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * {@hide}
@@ -121,6 +122,17 @@ public abstract class Call {
        }
    }

    /**
     * @return returns a summary of the connections held in this call.
     */
    public String getConnectionSummary() {
        synchronized (mLock) {
            return mConnections.stream()
                    .map(c -> c.getTelecomCallId() + "/objId:" + System.identityHashCode(c))
                    .collect(Collectors.joining(", "));
        }
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public abstract Phone getPhone();
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
+49 −5
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Queue;
import java.util.Set;
@@ -204,7 +205,6 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {

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

            if (extras == null) extras = new Bundle();
            if (mImsManager == null) return;
@@ -274,6 +274,9 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    }
                }

                mOperationLocalLog.log("onIncomingCall: isUnknown=" + isUnknown + ", connId="
                        + System.identityHashCode(conn));

                addConnection(conn);

                setVideoCallProvider(conn, imsCall);
@@ -283,6 +286,13 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                mPhone.getVoiceCallSessionStats().onImsCallReceived(conn);

                if (isUnknown) {
                    // Check for condition where an unknown connection replaces a pending
                    // MO call.  This will cause problems later in all likelihood.
                    if (mPendingMO != null
                            && Objects.equals(mPendingMO.getAddress(), conn.getAddress())) {
                        mOperationLocalLog.log("onIncomingCall: unknown call " + conn
                                + " replaces " + mPendingMO);
                    }
                    mPhone.notifyUnknownConnection(conn);
                } else {
                    if ((mForegroundCall.getState() != ImsPhoneCall.State.IDLE)
@@ -2209,6 +2219,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        return !isImsAudioCallActiveOrHolding || !VideoProfile.isVideo(videoState);
    }


    /**
     * Determines if there are issues which would preclude dialing an outgoing call.  Throws a
     * {@link CallStateException} if there is an issue.
@@ -2276,9 +2287,14 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {

        if (DBG) {
            log("updatePhoneState pendingMo = " + (mPendingMO == null ? "null"
                    : mPendingMO.getState()) + ", fg= " + mForegroundCall.getState() + "("
                    + mForegroundCall.getConnectionsCount() + "), bg= " + mBackgroundCall
                    .getState() + "(" + mBackgroundCall.getConnectionsCount() + ")");
                    : mPendingMO.getState() + "(" + mPendingMO.getTelecomCallId() + "/objId:"
                            + System.identityHashCode(mPendingMO) + ")")
                    + ", rng= " + mRingingCall.getState() + "("
                    + mRingingCall.getConnectionSummary()
                    + "), fg= " + mForegroundCall.getState() + "("
                    + mForegroundCall.getConnectionSummary()
                    + "), bg= " + mBackgroundCall.getState()
                    + "(" + mBackgroundCall.getConnectionSummary() + ")");
            log("updatePhoneState oldState=" + oldState + ", newState=" + mState);
        }

@@ -2569,9 +2585,32 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        return null;
    }

    /**
     * Given a connection, detach it from any {@link ImsPhoneCall} it is associated with, remove it
     * from the connections lists, and ensure if it was the pending MO connection it gets removed
     * from there as well.
     * @param conn The connection to cleanup and remove.
     */
    public synchronized void cleanupAndRemoveConnection(ImsPhoneConnection conn) {
        mOperationLocalLog.log("cleanupAndRemoveConnection: " + conn);
        // If the connection is attached to a call, detach it.
        if (conn.getCall() != null) {
            conn.getCall().detach(conn);
        }
        // Remove it from the connection list.
        removeConnection(conn);

        // Finally, if it was the pending MO, then ensure that connection gets cleaned up as well.
        if (conn == mPendingMO) {
            mPendingMO.finalize();
            mPendingMO = null;
        }
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private synchronized void removeConnection(ImsPhoneConnection conn) {
    public synchronized void removeConnection(ImsPhoneConnection conn) {
        mConnections.remove(conn);

        // If not emergency call is remaining, notify emergency call registrants
        if (mIsInEmergencyCall) {
            boolean isEmergencyCallInList = false;
@@ -5264,6 +5303,11 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        return mConnections;
    }

    @VisibleForTesting
    public ImsPhoneConnection getPendingMO() {
        return mPendingMO;
    }

    /**
     * Set up static configuration from package/services/Telephony's config.xml.
     * @param config the config.
+26 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static junit.framework.Assert.assertNotNull;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyString;
@@ -1577,6 +1578,20 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
        verify(mImsManager, never()).setOfferedRtpHeaderExtensionTypes(any());
    }

    @Test
    @SmallTest
    public void testCleanupAndRemoveConnection() throws Exception {
        ImsPhoneConnection conn = placeCall();
        assertEquals(1, mCTUT.getConnections().size());
        assertNotNull(mCTUT.getPendingMO());
        assertEquals(Call.State.DIALING, mCTUT.mForegroundCall.getState());

        mCTUT.cleanupAndRemoveConnection(conn);
        assertEquals(0, mCTUT.getConnections().size());
        assertNull(mCTUT.getPendingMO());
        assertEquals(Call.State.IDLE, mCTUT.mForegroundCall.getState());
    }

    private void sendCarrierConfigChanged() {
        Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        intent.putExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, mPhone.getSubId());
@@ -1612,6 +1627,16 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
    }

    private ImsPhoneConnection placeCallAndMakeActive() {
        ImsPhoneConnection connection = placeCall();
        ImsCall imsCall = connection.getImsCall();
        imsCall.getImsCallSessionListenerProxy().callSessionProgressing(imsCall.getSession(),
                new ImsStreamMediaProfile());
        imsCall.getImsCallSessionListenerProxy().callSessionStarted(imsCall.getSession(),
                new ImsCallProfile());
        return connection;
    }

    private ImsPhoneConnection placeCall() {
        try {
            doAnswer(new Answer<ImsCall>() {
                @Override
@@ -1623,6 +1648,7 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
                    imsCallMocking(imsCall);
                    return imsCall;
                }

            }).when(mImsManager).makeCall(eq(mImsCallProfile), (String[]) any(),
                    (ImsCall.Listener) any());
        } catch (ImsException ie) {
@@ -1639,11 +1665,6 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
        if (connection == null) {
            Assert.fail("connection is null");
        }
        ImsCall imsCall = connection.getImsCall();
        imsCall.getImsCallSessionListenerProxy().callSessionProgressing(imsCall.getSession(),
                new ImsStreamMediaProfile());
        imsCall.getImsCallSessionListenerProxy().callSessionStarted(imsCall.getSession(),
                new ImsCallProfile());
        return connection;
    }
}