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

Commit e8bc7318 authored by Naveen Kalla's avatar Naveen Kalla
Browse files

DO NOT MERGE: Collect telephony metrics for CS Calls.

Log Dial, Hangup and CS Call state changes in telephony.

Bug: 32885463
Change-Id: I0191f30a691bb0496600cba608387b06e7b3d6dd
parent 173f6b86
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1018,6 +1018,13 @@ message TelephonyCallSession {
      optional CallState state = 2;

      optional Type type = 3;

      // For possible values for a call end reason check
      // frameworks/base/telephony/java/android/telephony/DisconnectCause.java
      optional int32 call_end_reason = 4;

      // This field is true for Conference Calls
      optional bool is_multiparty = 5;
    }

    // Single Radio Voice Call Continuity(SRVCC) progress state
+46 −9
Original line number Diff line number Diff line
@@ -88,6 +88,8 @@ public class GsmCdmaCallTracker extends CallTracker {

    public PhoneConstants.State mState = PhoneConstants.State.IDLE;

    private TelephonyMetrics mMetrics = TelephonyMetrics.getInstance();

    // Following member variables are for CDMA only
    private RegistrantList mCallWaitingRegistrants = new RegistrantList();
    private boolean mPendingCallInEcm;
@@ -303,6 +305,8 @@ public class GsmCdmaCallTracker extends CallTracker {
        mPendingMO = new GsmCdmaConnection(mPhone, checkForTestEmergencyNumber(dialString),
                this, mForegroundCall, isEmergencyCall);
        mHangupPendingMO = false;
        mMetrics.writeRilDial(mPhone.getPhoneId(), mPendingMO, clirMode, uusInfo);


        if ( mPendingMO.getAddress() == null || mPendingMO.getAddress().length() == 0
                || mPendingMO.getAddress().indexOf(PhoneNumberUtils.WILD) >= 0) {
@@ -715,7 +719,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        }
        if (mState != oldState) {
            mPhone.notifyPhoneStateChanged();
            TelephonyMetrics.getInstance().writePhoneState(mPhone.getPhoneId(), mState);
            mMetrics.writePhoneState(mPhone.getPhoneId(), mState);
        }
    }

@@ -863,9 +867,6 @@ public class GsmCdmaCallTracker extends CallTracker {
                    // Connection missing in CLCC response that we were
                    // tracking.
                    mDroppedDuringPoll.add(conn);
                    // Dropped connections are removed from the CallTracker
                    // list but kept in the GsmCdmaCall list
                    mConnections[i] = null;
                } else {
                    // This case means the RIL has no more active call anymore and
                    // we need to clean up the foregroundCall and ringingCall.
@@ -892,12 +893,10 @@ public class GsmCdmaCallTracker extends CallTracker {
                    }
                    // If emergency call is not going through while dialing
                    checkAndEnableDataCallAfterEmergencyCallDropped();

                }
                // Dropped connections are removed from the CallTracker
                // list but kept in the Call list
                mConnections[i] = null;

                }
            } else if (conn != null && dc != null && !conn.compareTo(dc) && isPhoneTypeGsm()) {
                // Connection in CLCC response does not match what
                // we were tracking. Assume dropped call and new call
@@ -987,6 +986,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        // clear the "local hangup" and "missed/rejected call"
        // cases from the "dropped during poll" list
        // These cases need no "last call fail" reason
        ArrayList<GsmCdmaConnection> locallyDisconnectedConnections = new ArrayList<>();
        for (int i = mDroppedDuringPoll.size() - 1; i >= 0 ; i--) {
            GsmCdmaConnection conn = mDroppedDuringPoll.get(i);
            //CDMA
@@ -1008,11 +1008,13 @@ public class GsmCdmaCallTracker extends CallTracker {
                mDroppedDuringPoll.remove(i);
                hasAnyCallDisconnected |= conn.onDisconnect(cause);
                wasDisconnected = true;
                locallyDisconnectedConnections.add(conn);
            } else if (conn.mCause == DisconnectCause.LOCAL
                    || conn.mCause == DisconnectCause.INVALID_NUMBER) {
                mDroppedDuringPoll.remove(i);
                hasAnyCallDisconnected |= conn.onDisconnect(conn.mCause);
                wasDisconnected = true;
                locallyDisconnectedConnections.add(conn);
            }

            if (!isPhoneTypeGsm() && wasDisconnected && unknownConnectionAppeared
@@ -1021,6 +1023,9 @@ public class GsmCdmaCallTracker extends CallTracker {
                newUnknownConnectionCdma = null;
            }
        }
        if (locallyDisconnectedConnections.size() > 0) {
            mMetrics.writeRilCallList(mPhone.getPhoneId(), locallyDisconnectedConnections);
        }

        /* Disconnect any pending Handover connections */
        for (Iterator<Connection> it = mHandoverConnections.iterator();
@@ -1033,6 +1038,7 @@ public class GsmCdmaCallTracker extends CallTracker {
            } else {
                hoConnection.onDisconnect(DisconnectCause.NOT_VALID);
            }
            // TODO: Do we need to update these hoConnections in Metrics ?
            it.remove();
        }

@@ -1071,6 +1077,7 @@ public class GsmCdmaCallTracker extends CallTracker {

        if (hasNonHangupStateChanged || newRinging != null || hasAnyCallDisconnected) {
            mPhone.notifyPreciseCallStateChanged();
            updateMetrics(mConnections);
        }

        // If all handover connections are mapped during this poll process clean it up
@@ -1083,6 +1090,14 @@ public class GsmCdmaCallTracker extends CallTracker {
        //dumpState();
    }

    private void updateMetrics(GsmCdmaConnection []connections) {
        ArrayList<GsmCdmaConnection> activeConnections = new ArrayList<>();
        for(GsmCdmaConnection conn : connections) {
            if(conn != null) activeConnections.add(conn);
        }
        mMetrics.writeRilCallList(mPhone.getPhoneId(), activeConnections);
    }

    private void handleRadioNotAvailable() {
        // handlePollCalls will clear out its
        // call list when it gets the CommandException
@@ -1153,6 +1168,7 @@ public class GsmCdmaCallTracker extends CallTracker {
            return;
        } else {
            try {
                mMetrics.writeRilHangup(mPhone.getPhoneId(), conn, conn.getGsmCdmaIndex());
                mCi.hangupConnection (conn.getGsmCdmaIndex(), obtainCompleteMessage());
            } catch (CallStateException ex) {
                // Ignore "connection not found"
@@ -1201,6 +1217,7 @@ public class GsmCdmaCallTracker extends CallTracker {

        if (call == mRingingCall) {
            if (Phone.DEBUG_PHONE) log("(ringing) hangup waiting or background");
            logHangupEvent(call);
            mCi.hangupWaitingOrBackground(obtainCompleteMessage());
        } else if (call == mForegroundCall) {
            if (call.isDialingOrAlerting()) {
@@ -1214,6 +1231,7 @@ public class GsmCdmaCallTracker extends CallTracker {
                log("hangup all conns in active/background call, without affecting ringing call");
                hangupAllConnections(call);
            } else {
                logHangupEvent(call);
                hangupForegroundResumeBackground();
            }
        } else if (call == mBackgroundCall) {
@@ -1234,8 +1252,24 @@ public class GsmCdmaCallTracker extends CallTracker {
        mPhone.notifyPreciseCallStateChanged();
    }

    private void logHangupEvent(GsmCdmaCall call) {
        int count = call.mConnections.size();
        for (int i = 0; i < count; i++) {
            GsmCdmaConnection cn = (GsmCdmaConnection) call.mConnections.get(i);
            int call_index;
            try {
                call_index = cn.getGsmCdmaIndex();
            } catch (CallStateException ex) {
                call_index = -1;
            }
            mMetrics.writeRilHangup(mPhone.getPhoneId(), cn, call_index);
        }
        if (VDBG) Rlog.v(LOG_TAG, "logHangupEvent logged " + count + " Connections ");
    }

    public void hangupWaitingOrBackground() {
        if (Phone.DEBUG_PHONE) log("hangupWaitingOrBackground");
        logHangupEvent(mBackgroundCall);
        mCi.hangupWaitingOrBackground(obtainCompleteMessage());
    }

@@ -1250,6 +1284,7 @@ public class GsmCdmaCallTracker extends CallTracker {
        for (int i = 0; i < count; i++) {
            GsmCdmaConnection cn = (GsmCdmaConnection)call.mConnections.get(i);
            if (cn.getGsmCdmaIndex() == index) {
                mMetrics.writeRilHangup(mPhone.getPhoneId(), cn, cn.getGsmCdmaIndex());
                mCi.hangupConnection(index, obtainCompleteMessage());
                return;
            }
@@ -1263,6 +1298,7 @@ public class GsmCdmaCallTracker extends CallTracker {
            int count = call.mConnections.size();
            for (int i = 0; i < count; i++) {
                GsmCdmaConnection cn = (GsmCdmaConnection)call.mConnections.get(i);
                mMetrics.writeRilHangup(mPhone.getPhoneId(), cn, cn.getGsmCdmaIndex());
                mCi.hangupConnection(cn.getGsmCdmaIndex(), obtainCompleteMessage());
            }
        } catch (CallStateException ex) {
@@ -1416,6 +1452,7 @@ public class GsmCdmaCallTracker extends CallTracker {
                updatePhoneState();

                mPhone.notifyPreciseCallStateChanged();
                mMetrics.writeRilCallList(mPhone.getPhoneId(), mDroppedDuringPoll);
                mDroppedDuringPoll.clear();
            break;

+0 −8
Original line number Diff line number Diff line
@@ -1076,8 +1076,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {

        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

        mMetrics.writeRilDial(mInstanceId, rr.mSerial, clirMode, uusInfo);

        send(rr);
    }

@@ -1133,8 +1131,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest) + " " +
                gsmIndex);

        mMetrics.writeRilHangup(mInstanceId, rr.mSerial, gsmIndex);

        rr.mParcel.writeInt(1);
        rr.mParcel.writeInt(gsmIndex);

@@ -1149,8 +1145,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {

        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

        mMetrics.writeRilHangup(mInstanceId, rr.mSerial, -1);

        send(rr);
    }

@@ -1163,8 +1157,6 @@ public final class RIL extends BaseCommands implements CommandsInterface {
                                        result);
        if (RILJ_LOGD) riljLog(rr.serialString() + "> " + requestToString(rr.mRequest));

        mMetrics.writeRilHangup(mInstanceId, rr.mSerial, -1);

        send(rr);
    }

+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import com.android.internal.telephony.TelephonyProto.ImsConnectionState;
import com.android.internal.telephony.TelephonyProto.ImsReasonInfo;
import com.android.internal.telephony.TelephonyProto.RilDataCall;
import com.android.internal.telephony.TelephonyProto.TelephonyCallSession;
import com.android.internal.telephony.TelephonyProto.TelephonyCallSession.Event.RilCall;
import com.android.internal.telephony.TelephonyProto.TelephonyServiceState;
import com.android.internal.telephony.TelephonyProto.TelephonySettings;

@@ -124,4 +125,9 @@ public class CallSessionEventBuilder {
        mEvent.setNitzTimestampMillis(timestamp);
        return this;
    }

    public CallSessionEventBuilder setRilCalls(RilCall[] rilCalls) {
        mEvent.calls = rilCalls;
        return this;
    }
}
+112 −17
Original line number Diff line number Diff line
@@ -21,11 +21,14 @@ import android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.TelephonyHistogram;
import android.util.Base64;
import android.util.Log;
import android.util.SparseArray;

import com.android.ims.ImsConfig;
import com.android.ims.ImsReasonInfo;
import com.android.ims.internal.ImsCallSession;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.GsmCdmaConnection;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.RIL;
import com.android.internal.telephony.RILConstants;
@@ -36,6 +39,9 @@ import com.android.internal.telephony.TelephonyProto.ImsConnectionState;
import com.android.internal.telephony.TelephonyProto.RilDataCall;
import com.android.internal.telephony.TelephonyProto.SmsSession;
import com.android.internal.telephony.TelephonyProto.TelephonyCallSession;
import com.android.internal.telephony.TelephonyProto.TelephonyCallSession.Event.RilCall;
import com.android.internal.telephony.TelephonyProto.TelephonyCallSession.Event.RilCall.Type.*;
import com.android.internal.telephony.TelephonyProto.TelephonyCallSession.Event.CallState.*;
import com.android.internal.telephony.TelephonyProto.TelephonyEvent;
import com.android.internal.telephony.TelephonyProto.TelephonyEvent.RilDeactivateDataCall;
import com.android.internal.telephony.TelephonyProto.TelephonyEvent.RilSetupDataCall;
@@ -58,6 +64,7 @@ import java.util.Deque;
import java.util.List;

import static android.text.format.DateUtils.MINUTE_IN_MILLIS;

import static com.android.internal.telephony.RILConstants.RIL_REQUEST_ANSWER;
import static com.android.internal.telephony.RILConstants.RIL_REQUEST_CDMA_SEND_SMS;
import static com.android.internal.telephony.RILConstants.RIL_REQUEST_DEACTIVATE_DATA_CALL;
@@ -1011,23 +1018,107 @@ public class TelephonyMetrics {
        addTelephonyEvent(new TelephonyEventBuilder(phoneId).setDataCalls(dataCalls).build());
    }

    /**
     * Write CS call list event
     *
     * @param phoneId    Phone id
     * @param connections Array of GsmCdmaConnection objects
     */
    public void writeRilCallList(int phoneId, ArrayList<GsmCdmaConnection> connections) {
        if (VDBG) {
            Rlog.v(TAG, "Logging CallList Changed Connections Size = " + connections.size());
        }
        InProgressCallSession callSession = startNewCallSessionIfNeeded(phoneId);
        if (callSession == null) {
            Rlog.e(TAG, "writeRilCallList: Call session is missing");
        } else {
            RilCall[] calls = convertConnectionsToRilCalls(connections);
            callSession.addEvent(
                    new CallSessionEventBuilder(
                            TelephonyCallSession.Event.Type.RIL_CALL_LIST_CHANGED)
                            .setRilCalls(calls)
            );
            if (VDBG)  Rlog.v(TAG, "Logged Call list changed");
        }
    }

    private RilCall[] convertConnectionsToRilCalls(ArrayList<GsmCdmaConnection> mConnections) {
        RilCall[] calls = new RilCall[mConnections.size()];
        for (int i = 0; i < mConnections.size(); i++) {
            calls[i] = new RilCall();
            calls[i].setIndex(i);
            convertConnectionToRilCall(mConnections.get(i), calls[i]);
        }
        return calls;
    }

    private void convertConnectionToRilCall(GsmCdmaConnection conn, RilCall call) {
        if (conn.isIncoming()) {
            call.setType(TelephonyCallSession.Event.RilCall.Type.MT);
        } else {
            call.setType(TelephonyCallSession.Event.RilCall.Type.MO);
        }
        switch (conn.getState()) {
            case IDLE:
                call.setState(TelephonyCallSession.Event.CallState.CALL_IDLE);
                break;
            case ACTIVE:
                call.setState(TelephonyCallSession.Event.CallState.CALL_ACTIVE);
                break;
            case HOLDING:
                call.setState(TelephonyCallSession.Event.CallState.CALL_HOLDING);
                break;
            case DIALING:
                call.setState(TelephonyCallSession.Event.CallState.CALL_DIALING);
                break;
            case ALERTING:
                call.setState(TelephonyCallSession.Event.CallState.CALL_ALERTING);
                break;
            case INCOMING:
                call.setState(TelephonyCallSession.Event.CallState.CALL_INCOMING);
                break;
            case WAITING:
                call.setState(TelephonyCallSession.Event.CallState.CALL_WAITING);
                break;
            case DISCONNECTED:
                call.setState(TelephonyCallSession.Event.CallState.CALL_DISCONNECTED);
                break;
            case DISCONNECTING:
                call.setState(TelephonyCallSession.Event.CallState.CALL_DISCONNECTING);
                break;
            default:
                call.setState(TelephonyCallSession.Event.CallState.CALL_UNKNOWN);
                break;
        }
        call.setCallEndReason(conn.getDisconnectCause());
        call.setIsMultiparty(conn.isMultiparty());
    }

    /**
     * Write dial event
     *
     * @param phoneId Phone id
     * @param rilSerial RIL request serial number
     * @param conn Connection object created to track this call
     * @param clirMode CLIR (Calling Line Identification Restriction) mode
     * @param uusInfo User-to-User signaling Info
     */
    public void writeRilDial(int phoneId, int rilSerial, int clirMode, UUSInfo uusInfo) {
    public void writeRilDial(int phoneId, GsmCdmaConnection conn, int clirMode, UUSInfo uusInfo) {

        InProgressCallSession callSession = startNewCallSessionIfNeeded(phoneId);

        if (VDBG) Rlog.v(TAG, "Logging Dial Connection = " + conn);
        if (callSession == null) {
            Rlog.e(TAG, "writeRilDial: Call session is missing");
        } else {
            RilCall[] calls = new RilCall[1];
            calls[0] = new RilCall();
            calls[0].setIndex(-1);
            convertConnectionToRilCall(conn, calls[0]);
            callSession.addEvent(callSession.startElapsedTimeMs,
                    new CallSessionEventBuilder(TelephonyCallSession.Event.Type.RIL_REQUEST)
                            .setRilRequest(TelephonyCallSession.Event.RilRequest.RIL_REQUEST_DIAL)
                        .setRilRequestId(rilSerial)
        );
                            .setRilCalls(calls));
            if (VDBG) Rlog.v(TAG, "Logged Dial event");
        }
    }

    /**
@@ -1047,19 +1138,23 @@ public class TelephonyMetrics {
     * Write call hangup event
     *
     * @param phoneId Phone id
     * @param rilSerial RIL request serial number
     * @param conn Connection object associated with the call that is being hung-up
     * @param callId Call id
     */
    public void writeRilHangup(int phoneId, int rilSerial, int callId) {
    public void writeRilHangup(int phoneId, GsmCdmaConnection conn, int callId) {
        InProgressCallSession callSession = mInProgressCallSessions.get(phoneId);
        if (callSession == null) {
            Rlog.e(TAG, "Call session is missing");
            Rlog.e(TAG, "writeRilHangup: Call session is missing");
        } else {
            RilCall[] calls = new RilCall[1];
            calls[0] = new RilCall();
            calls[0].setIndex(callId);
            convertConnectionToRilCall(conn, calls[0]);
            callSession.addEvent(
                    new CallSessionEventBuilder(TelephonyCallSession.Event.Type.RIL_REQUEST)
                            .setRilRequest(TelephonyCallSession.Event.RilRequest.RIL_REQUEST_HANGUP)
                            .setRilRequestId(rilSerial)
                            .setCallIndex(callId));
                            .setRilCalls(calls));
            if (VDBG) Rlog.v(TAG, "Logged Hangup event");
        }
    }

@@ -1072,7 +1167,7 @@ public class TelephonyMetrics {
    public void writeRilAnswer(int phoneId, int rilSerial) {
        InProgressCallSession callSession = mInProgressCallSessions.get(phoneId);
        if (callSession == null) {
            Rlog.e(TAG, "Call session is missing");
            Rlog.e(TAG, "writeRilAnswer: Call session is missing");
        } else {
            callSession.addEvent(
                    new CallSessionEventBuilder(TelephonyCallSession.Event.Type.RIL_REQUEST)
@@ -1090,7 +1185,7 @@ public class TelephonyMetrics {
    public void writeRilSrvcc(int phoneId, int rilSrvccState) {
        InProgressCallSession callSession =  mInProgressCallSessions.get(phoneId);
        if (callSession == null) {
            Rlog.e(TAG, "Call session is missing");
            Rlog.e(TAG, "writeRilSrvcc: Call session is missing");
        } else {
            callSession.addEvent(
                    new CallSessionEventBuilder(TelephonyCallSession.Event.Type.RIL_CALL_SRVCC)
@@ -1180,7 +1275,7 @@ public class TelephonyMetrics {
                                              int rilRequest) {
        InProgressCallSession callSession = mInProgressCallSessions.get(phoneId);
        if (callSession == null) {
            Rlog.e(TAG, "Call session is missing");
            Rlog.e(TAG, "writeOnCallSolicitedResponse: Call session is missing");
        } else {
            callSession.addEvent(new CallSessionEventBuilder(
                    TelephonyCallSession.Event.Type.RIL_RESPONSE)
@@ -1295,7 +1390,7 @@ public class TelephonyMetrics {

        InProgressCallSession callSession = mInProgressCallSessions.get(phoneId);
        if (callSession == null) {
            Rlog.e(TAG, "Call session is missing");
            Rlog.e(TAG, "writePhoneState: Call session is missing");
        } else {
            if (state == TelephonyCallSession.Event.PhoneState.STATE_IDLE) {
                finishCallSession(callSession);
Loading