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

Commit 66aef20f authored by Chi Zhang's avatar Chi Zhang Committed by Gerrit Code Review
Browse files

Merge "fix incorrect fields in DataCallSession."

parents f9dd93a4 80b24364
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -2255,10 +2255,10 @@ public class DataConnection extends StateMachine {
    private class DcActivatingState extends State {
    private class DcActivatingState extends State {
        @Override
        @Override
        public void enter() {
        public void enter() {
            int apnTypeBitmask = mApnSetting != null ? mApnSetting.getApnTypeBitmask() : 0;
            TelephonyStatsLog.write(TelephonyStatsLog.MOBILE_CONNECTION_STATE_CHANGED,
            TelephonyStatsLog.write(TelephonyStatsLog.MOBILE_CONNECTION_STATE_CHANGED,
                    TelephonyStatsLog.MOBILE_CONNECTION_STATE_CHANGED__STATE__ACTIVATING,
                    TelephonyStatsLog.MOBILE_CONNECTION_STATE_CHANGED__STATE__ACTIVATING,
                    mPhone.getPhoneId(), mId,
                    mPhone.getPhoneId(), mId, (long) apnTypeBitmask,
                    mApnSetting != null ? (long) mApnSetting.getApnTypeBitmask() : 0L,
                    mApnSetting != null
                    mApnSetting != null
                        ? mApnSetting.canHandleType(ApnSetting.TYPE_DEFAULT) : false);
                        ? mApnSetting.canHandleType(ApnSetting.TYPE_DEFAULT) : false);
            setHandoverState(HANDOVER_STATE_IDLE);
            setHandoverState(HANDOVER_STATE_IDLE);
@@ -2275,7 +2275,7 @@ public class DataConnection extends StateMachine {
                    .registerCarrierPrivilegesListener(
                    .registerCarrierPrivilegesListener(
                            getHandler(), EVENT_CARRIER_PRIVILEGED_UIDS_CHANGED, null);
                            getHandler(), EVENT_CARRIER_PRIVILEGED_UIDS_CHANGED, null);
            notifyDataConnectionState();
            notifyDataConnectionState();
            mDataCallSessionStats.onSetupDataCall(mApnSetting.getApnTypeBitmask());
            mDataCallSessionStats.onSetupDataCall(apnTypeBitmask);
        }
        }
        @Override
        @Override
        public boolean processMessage(Message msg) {
        public boolean processMessage(Message msg) {
@@ -2561,7 +2561,7 @@ public class DataConnection extends StateMachine {


            TelephonyMetrics.getInstance().writeRilDataCallEvent(mPhone.getPhoneId(),
            TelephonyMetrics.getInstance().writeRilDataCallEvent(mPhone.getPhoneId(),
                    mCid, mApnSetting.getApnTypeBitmask(), RilDataCall.State.DISCONNECTED);
                    mCid, mApnSetting.getApnTypeBitmask(), RilDataCall.State.DISCONNECTED);
            mDataCallSessionStats.onDataCallDisconnected(mCid);
            mDataCallSessionStats.onDataCallDisconnected();


            mPhone.getCarrierPrivilegesTracker().unregisterCarrierPrivilegesListener(getHandler());
            mPhone.getCarrierPrivilegesTracker().unregisterCarrierPrivilegesListener(getHandler());
        }
        }
+24 −27
Original line number Original line Diff line number Diff line
@@ -22,16 +22,19 @@ import static com.android.internal.telephony.TelephonyStatsLog.DATA_CALL_SESSION
import static com.android.internal.telephony.TelephonyStatsLog.DATA_CALL_SESSION__DEACTIVATE_REASON__DEACTIVATE_REASON_UNKNOWN;
import static com.android.internal.telephony.TelephonyStatsLog.DATA_CALL_SESSION__DEACTIVATE_REASON__DEACTIVATE_REASON_UNKNOWN;
import static com.android.internal.telephony.TelephonyStatsLog.DATA_CALL_SESSION__IP_TYPE__APN_PROTOCOL_IPV4;
import static com.android.internal.telephony.TelephonyStatsLog.DATA_CALL_SESSION__IP_TYPE__APN_PROTOCOL_IPV4;


import android.os.SystemClock;
import android.telephony.Annotation.ApnType;
import android.telephony.Annotation.ApnType;
import android.telephony.Annotation.NetworkType;
import android.telephony.Annotation.NetworkType;
import android.telephony.DataFailCause;
import android.telephony.DataFailCause;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.ServiceState.RilRadioTechnology;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.data.ApnSetting.ProtocolType;
import android.telephony.data.ApnSetting.ProtocolType;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataCallResponse;
import android.telephony.data.DataService;
import android.telephony.data.DataService;
import android.telephony.data.DataService.DeactivateDataReason;
import android.telephony.data.DataService.DeactivateDataReason;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.ServiceStateTracker;
import com.android.internal.telephony.ServiceStateTracker;
@@ -41,7 +44,7 @@ import com.android.telephony.Rlog;


import java.util.Random;
import java.util.Random;


/** Collects data call change events per DcTracker for the pulled atom. */
/** Collects data call change events per DataConnection for the pulled atom. */
public class DataCallSessionStats {
public class DataCallSessionStats {
    private static final String TAG = DataCallSessionStats.class.getSimpleName();
    private static final String TAG = DataCallSessionStats.class.getSimpleName();


@@ -59,22 +62,18 @@ public class DataCallSessionStats {
        mPhone = phone;
        mPhone = phone;
    }
    }


    /** create a new ongoing atom when data cal is set up */
    /** Creates a new ongoing atom when data call is set up. */
    public synchronized void onSetupDataCall(@ApnType int apnTypeBitMask) {
    public synchronized void onSetupDataCall(@ApnType int apnTypeBitMask) {
        if (!mOnRatChangedCalledBeforeSetup) {
        if (!mOnRatChangedCalledBeforeSetup) {
            // there shouldn't be an ongoing dataCall here, if that's the case, it means that
            // there shouldn't be an ongoing data call here, if that's the case, it means that
            // deactivateDataCall hasn't been processed properly, so we save the previous atom here
            // deactivateDataCall hasn't been processed properly, so we save the previous atom here
            // and move on to create a new atom.
            // and move on to create a new atom.
            if (mOngoingDataCall != null) {
            if (mOngoingDataCall != null) {
                mOngoingDataCall.failureCause = DataFailCause.UNKNOWN;
                mOngoingDataCall.failureCause = DataFailCause.UNKNOWN;
                mOngoingDataCall.durationMinutes =
                onDataCallDisconnected();
                        convertMillisToMinutes(System.currentTimeMillis() - mStartTime);
                mOngoingDataCall.ongoing = false;
                mAtomsStorage.addDataCallSession(mOngoingDataCall);
                mOngoingDataCall = null;
            }
            }
            mOngoingDataCall = getDefaultProto(apnTypeBitMask);
            mOngoingDataCall = getDefaultProto(apnTypeBitMask);
            mStartTime = System.currentTimeMillis();
            mStartTime = getTimeMillis();
        } else {
        } else {
            // if onRatChanged was called before onSetupDataCall, the atom is already initialized
            // if onRatChanged was called before onSetupDataCall, the atom is already initialized
            // but apnTypeBitMask is initialized to 0, so we need to update it
            // but apnTypeBitMask is initialized to 0, so we need to update it
@@ -84,7 +83,8 @@ public class DataCallSessionStats {
    }
    }


    /**
    /**
     * update the ongoing dataCall's atom for data call response event
     * Updates the ongoing dataCall's atom for data call response event.
     *
     * @param response setup Data call response
     * @param response setup Data call response
     * @param radioTechnology The data call RAT
     * @param radioTechnology The data call RAT
     * @param apnTypeBitmask APN type bitmask
     * @param apnTypeBitmask APN type bitmask
@@ -93,7 +93,7 @@ public class DataCallSessionStats {
     */
     */
    public synchronized void onSetupDataCallResponse(
    public synchronized void onSetupDataCallResponse(
            DataCallResponse response,
            DataCallResponse response,
            @ServiceState.RilRadioTechnology int radioTechnology,
            @RilRadioTechnology int radioTechnology,
            @ApnType int apnTypeBitmask,
            @ApnType int apnTypeBitmask,
            @ProtocolType int protocol,
            @ProtocolType int protocol,
            int failureCause) {
            int failureCause) {
@@ -103,8 +103,7 @@ public class DataCallSessionStats {
            loge("onSetupDataCallResponse: no DataCallSession atom has been initiated.");
            loge("onSetupDataCallResponse: no DataCallSession atom has been initiated.");
            return;
            return;
        }
        }
        mOngoingDataCall.ratAtEnd =
        mOngoingDataCall.ratAtEnd = ServiceState.rilRadioTechnologyToNetworkType(radioTechnology);
                ServiceState.rilRadioTechnologyToNetworkType(radioTechnology);


        // only set if apn hasn't been set during setup
        // only set if apn hasn't been set during setup
        if (mOngoingDataCall.apnTypeBitmask == 0) {
        if (mOngoingDataCall.apnTypeBitmask == 0) {
@@ -129,11 +128,11 @@ public class DataCallSessionStats {
    }
    }


    /**
    /**
     * update the ongoing dataCall's atom when data call is deactivated
     * Updates the ongoing dataCall's atom when data call is deactivated.
     *
     *
     * @param reason Deactivate reason
     * @param reason Deactivate reason
     */
     */
    public void setDeactivateDataCallReason(@DeactivateDataReason int reason) {
    public synchronized void setDeactivateDataCallReason(@DeactivateDataReason int reason) {
        // there should've been another call to initiate the atom,
        // there should've been another call to initiate the atom,
        // so this method is being called out of order -> no metric will be logged
        // so this method is being called out of order -> no metric will be logged
        if (mOngoingDataCall == null) {
        if (mOngoingDataCall == null) {
@@ -162,22 +161,16 @@ public class DataCallSessionStats {
        mOngoingDataCall.oosAtEnd = getIsOos();
        mOngoingDataCall.oosAtEnd = getIsOos();
    }
    }


    /**
    /** Stores the atom when DataConnection reaches DISCONNECTED state. */
     * store the atom, when DataConnection reaches DISCONNECTED state
    public synchronized void onDataCallDisconnected() {
     *
     * @param cid Context Id, uniquely identifies the call
     */
    public void onDataCallDisconnected(int cid) {
        // there should've been another call to initiate the atom,
        // there should've been another call to initiate the atom,
        // so this method is being called out of order -> no atom will be saved
        // so this method is being called out of order -> no atom will be saved
        if (mOngoingDataCall == null) {
        if (mOngoingDataCall == null) {
            loge("onSetupDataCallResponse: no DataCallSession atom has been initiated.");
            loge("onSetupDataCallResponse: no DataCallSession atom has been initiated.");
            return;
            return;
        }
        }
        mOngoingDataCall.carrierId = cid;
        mOngoingDataCall.ongoing = false;
        mOngoingDataCall.ongoing = false;
        mOngoingDataCall.durationMinutes =
        mOngoingDataCall.durationMinutes = convertMillisToMinutes(getTimeMillis() - mStartTime);
                convertMillisToMinutes(System.currentTimeMillis() - mStartTime);
        // store for the data call list event, after DataCall is disconnected and entered into
        // store for the data call list event, after DataCall is disconnected and entered into
        // inactive mode
        // inactive mode
        mAtomsStorage.addDataCallSession(mOngoingDataCall);
        mAtomsStorage.addDataCallSession(mOngoingDataCall);
@@ -190,15 +183,14 @@ public class DataCallSessionStats {
     * <p>NOTE: in {@link ServiceStateTracker}, change of channel number will trigger data
     * <p>NOTE: in {@link ServiceStateTracker}, change of channel number will trigger data
     * registration state change.
     * registration state change.
     */
     */
    public synchronized void onDrsOrRatChanged(
    public synchronized void onDrsOrRatChanged(@RilRadioTechnology int radioTechnology) {
            @ServiceState.RilRadioTechnology int radioTechnology) {
        @NetworkType int rat = ServiceState.rilRadioTechnologyToNetworkType(radioTechnology);
        @NetworkType int rat = ServiceState.rilRadioTechnologyToNetworkType(radioTechnology);
        // if no data call is initiated, or we have a new data call while the last one has ended
        // if no data call is initiated, or we have a new data call while the last one has ended
        // because onRatChanged might be called before onSetupDataCall
        // because onRatChanged might be called before onSetupDataCall
        if (mOngoingDataCall == null) {
        if (mOngoingDataCall == null) {
            mOngoingDataCall = getDefaultProto(0);
            mOngoingDataCall = getDefaultProto(0);
            mOngoingDataCall.ratAtEnd = rat;
            mOngoingDataCall.ratAtEnd = rat;
            mStartTime = System.currentTimeMillis();
            mStartTime = getTimeMillis();
            mOnRatChangedCalledBeforeSetup = true;
            mOnRatChangedCalledBeforeSetup = true;
        }
        }
        if (rat != TelephonyManager.NETWORK_TYPE_UNKNOWN && mOngoingDataCall.ratAtEnd != rat) {
        if (rat != TelephonyManager.NETWORK_TYPE_UNKNOWN && mOngoingDataCall.ratAtEnd != rat) {
@@ -258,4 +250,9 @@ public class DataCallSessionStats {
    private void loge(String format, Object... args) {
    private void loge(String format, Object... args) {
        Rlog.e(TAG, "[" + mPhone.getPhoneId() + "]" + String.format(format, args));
        Rlog.e(TAG, "[" + mPhone.getPhoneId() + "]" + String.format(format, args));
    }
    }

    @VisibleForTesting
    protected long getTimeMillis() {
        return SystemClock.elapsedRealtime();
    }
}
}
+3 −2
Original line number Original line Diff line number Diff line
@@ -517,7 +517,8 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
                .writeInt(dataCallSession.failureCause)
                .writeInt(dataCallSession.failureCause)
                .writeInt(dataCallSession.suggestedRetryMillis)
                .writeInt(dataCallSession.suggestedRetryMillis)
                .writeInt(dataCallSession.deactivateReason)
                .writeInt(dataCallSession.deactivateReason)
                .writeLong(dataCallSession.durationMinutes)
                .writeLong(round(
                        dataCallSession.durationMinutes, DURATION_BUCKET_MILLIS / MINUTE_IN_MILLIS))
                .writeBoolean(dataCallSession.ongoing)
                .writeBoolean(dataCallSession.ongoing)
                .writeInt(dataCallSession.bandAtEnd)
                .writeInt(dataCallSession.bandAtEnd)
                .build();
                .build();
@@ -594,6 +595,6 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {


    /** Returns the value rounded to the bucket. */
    /** Returns the value rounded to the bucket. */
    private static long round(long value, long bucket) {
    private static long round(long value, long bucket) {
        return ((value + bucket / 2) / bucket) * bucket;
        return bucket == 0 ? value : ((value + bucket / 2) / bucket) * bucket;
    }
    }
}
}