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

Commit 47830584 authored by Nazanin's avatar Nazanin
Browse files

Change logic of Data Call atoms to align with one datacall per

DataConnection instance

Bug: 187393008
Test: manual bugreport
Change-Id: Iea29576f252ec6aea083d89823d4a18033b1b83a
parent f3ace853
Loading
Loading
Loading
Loading
+49 −61
Original line number Diff line number Diff line
@@ -51,8 +51,9 @@ public class DataCallSessionStats {

    private final Phone mPhone;
    private long mStartTime;
    private boolean mOnRatChangedCalledBeforeSetup = false;
    DataCallSession mOngoingDataCall;
    private DataCallSession mDataCallSession;
    private @NetworkType int mCurrentRat;
    private int mCurrentBand;

    private final PersistAtomsStorage mAtomsStorage =
            PhoneFactory.getMetricsCollector().getAtomsStorage();
@@ -65,21 +66,8 @@ public class DataCallSessionStats {

    /** Creates a new ongoing atom when data call is set up. */
    public synchronized void onSetupDataCall(@ApnType int apnTypeBitMask) {
        if (!mOnRatChangedCalledBeforeSetup) {
            // 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
            // and move on to create a new atom.
            if (mOngoingDataCall != null) {
                onDataCallDisconnected(DataFailCause.UNKNOWN);
            }
            mOngoingDataCall = getDefaultProto(apnTypeBitMask);
        mDataCallSession = getDefaultProto(apnTypeBitMask);
        mStartTime = getTimeMillis();
        } else {
            // if onRatChanged was called before onSetupDataCall, the atom is already initialized
            // but apnTypeBitMask is initialized to 0, so we need to update it
            mOngoingDataCall.apnTypeBitmask = apnTypeBitMask;
        }
        mOnRatChangedCalledBeforeSetup = false;
    }

    /**
@@ -97,68 +85,70 @@ public class DataCallSessionStats {
            @ApnType int apnTypeBitmask,
            @ProtocolType int protocol,
            @DataFailureCause int failureCause) {
        // there should've been another call to initiate the atom,
        // there should've been a call to onSetupataCall to initiate the atom,
        // so this method is being called out of order -> no metric will be logged
        if (mOngoingDataCall == null) {
        if (mDataCallSession == null) {
            loge("onSetupDataCallResponse: no DataCallSession atom has been initiated.");
            return;
        }
        mOngoingDataCall.ratAtEnd = ServiceState.rilRadioTechnologyToNetworkType(radioTechnology);
        mCurrentRat = ServiceState.rilRadioTechnologyToNetworkType(radioTechnology);
        mCurrentBand = mCurrentRat == TelephonyManager.NETWORK_TYPE_IWLAN
                ? 0 : ServiceStateStats.getBand(mPhone);
        mDataCallSession.ratAtEnd = mCurrentRat;
        mDataCallSession.bandAtEnd = mCurrentBand;

        // only set if apn hasn't been set during setup
        if (mOngoingDataCall.apnTypeBitmask == 0) {
            mOngoingDataCall.apnTypeBitmask = apnTypeBitmask;
        if (mDataCallSession.apnTypeBitmask == 0) {
            mDataCallSession.apnTypeBitmask = apnTypeBitmask;
        }

        mOngoingDataCall.ipType = protocol;
        mOngoingDataCall.failureCause = failureCause;
        mDataCallSession.ipType = protocol;
        mDataCallSession.failureCause = failureCause;
        if (response != null) {
            mOngoingDataCall.suggestedRetryMillis =
            mDataCallSession.suggestedRetryMillis =
                    (int) Math.min(response.getRetryDurationMillis(), Integer.MAX_VALUE);
            // store and set atom as inactive only if setup has failed
            if (failureCause != DataFailCause.NONE) {
                mOngoingDataCall.failureCause = failureCause;
                mOngoingDataCall.setupFailed = true;
                // set dataCall as inactive
                mOngoingDataCall.ongoing = false;
                // store it only if setup has failed
                mAtomsStorage.addDataCallSession(mOngoingDataCall);
                mOngoingDataCall = null;
                mDataCallSession.failureCause = failureCause;
                mDataCallSession.setupFailed = true;
                mDataCallSession.ongoing = false;
                mAtomsStorage.addDataCallSession(mDataCallSession);
                mDataCallSession = null;
            }
        }
    }

    /**
     * Updates the ongoing dataCall's atom when data call is deactivated.
     * Updates the dataCall atom when data call is deactivated.
     *
     * @param reason Deactivate reason
     */
    public synchronized void setDeactivateDataCallReason(@DeactivateDataReason int reason) {
        // there should've been another call to initiate the atom,
        // so this method is being called out of order -> no metric will be logged
        if (mOngoingDataCall == null) {
            loge("onSetupDataCallResponse: no DataCallSession atom has been initiated.");
        if (mDataCallSession == null) {
            loge("setDeactivateDataCallReason: no DataCallSession atom has been initiated.");
            return;
        }
        switch (reason) {
            case DataService.REQUEST_REASON_NORMAL:
                mOngoingDataCall.deactivateReason =
                mDataCallSession.deactivateReason =
                        DATA_CALL_SESSION__DEACTIVATE_REASON__DEACTIVATE_REASON_NORMAL;
                break;
            case DataService.REQUEST_REASON_SHUTDOWN:
                mOngoingDataCall.deactivateReason =
                mDataCallSession.deactivateReason =
                        DATA_CALL_SESSION__DEACTIVATE_REASON__DEACTIVATE_REASON_RADIO_OFF;
                break;
            case DataService.REQUEST_REASON_HANDOVER:
                mOngoingDataCall.deactivateReason =
                mDataCallSession.deactivateReason =
                        DATA_CALL_SESSION__DEACTIVATE_REASON__DEACTIVATE_REASON_HANDOVER;
                break;
            default:
                mOngoingDataCall.deactivateReason =
                mDataCallSession.deactivateReason =
                        DATA_CALL_SESSION__DEACTIVATE_REASON__DEACTIVATE_REASON_UNKNOWN;
                break;
        }

        mOngoingDataCall.oosAtEnd = getIsOos();
        mDataCallSession.oosAtEnd = getIsOos();
    }

    /** Stores the atom when DataConnection reaches DISCONNECTED state.
@@ -167,17 +157,19 @@ public class DataCallSessionStats {
    public synchronized void onDataCallDisconnected(@DataFailureCause int failureCause) {
        // there should've been another call to initiate the atom,
        // so this method is being called out of order -> no atom will be saved
        if (mOngoingDataCall == null) {
            loge("onSetupDataCallResponse: no DataCallSession atom has been initiated.");
        if (mDataCallSession == null) {
            loge("onDataCallDisconnected: no DataCallSession atom has been initiated.");
            return;
        }
        mOngoingDataCall.failureCause = failureCause;
        mOngoingDataCall.ongoing = false;
        mOngoingDataCall.durationMinutes = convertMillisToMinutes(getTimeMillis() - mStartTime);
        mDataCallSession.failureCause = failureCause;
        mDataCallSession.ratAtEnd = mCurrentRat;
        mDataCallSession.bandAtEnd = mCurrentBand;
        mDataCallSession.ongoing = false;
        mDataCallSession.durationMinutes = convertMillisToMinutes(getTimeMillis() - mStartTime);
        // store for the data call list event, after DataCall is disconnected and entered into
        // inactive mode
        mAtomsStorage.addDataCallSession(mOngoingDataCall);
        mOngoingDataCall = null;
        mAtomsStorage.addDataCallSession(mDataCallSession);
        mDataCallSession = null;
    }

    /**
@@ -187,20 +179,16 @@ public class DataCallSessionStats {
     * registration state change.
     */
    public synchronized void onDrsOrRatChanged(@RilRadioTechnology int 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
        // because onRatChanged might be called before onSetupDataCall
        if (mOngoingDataCall == null) {
            mOngoingDataCall = getDefaultProto(0);
            mOngoingDataCall.ratAtEnd = rat;
            mStartTime = getTimeMillis();
            mOnRatChangedCalledBeforeSetup = true;
        }
        if (rat != TelephonyManager.NETWORK_TYPE_UNKNOWN && mOngoingDataCall.ratAtEnd != rat) {
            mOngoingDataCall.ratSwitchCount++;
            mOngoingDataCall.ratAtEnd = rat;
        mCurrentRat = ServiceState.rilRadioTechnologyToNetworkType(radioTechnology);
        mCurrentBand = mCurrentRat == TelephonyManager.NETWORK_TYPE_IWLAN
                ? 0 : ServiceStateStats.getBand(mPhone);
        // if no data call is initiated, we just keep track of the current rat that is changed
        if (mDataCallSession != null
                && mCurrentRat != TelephonyManager.NETWORK_TYPE_UNKNOWN
                && mDataCallSession.ratAtEnd != mCurrentRat) {
            mDataCallSession.ratSwitchCount++;
            mDataCallSession.ratAtEnd = mCurrentRat;
        }
        mOngoingDataCall.bandAtEnd = ServiceStateStats.getBand(mPhone, rat);
    }

    private static long convertMillisToMinutes(long millis) {
+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ public class DataStallRecoveryStats {

        int carrierId = phone.getCarrierId();
        int rat = getRat(phone);
        int band = ServiceStateStats.getBand(phone, rat);
        int band = rat == TelephonyManager.NETWORK_TYPE_IWLAN
                ? 0 : ServiceStateStats.getBand(phone);
        // the number returned here matches the SignalStrength enum we have
        int signalStrength = phone.getSignalStrength().getLevel();
        boolean isOpportunistic = getIsOpportunistic(phone);
+6 −5
Original line number Diff line number Diff line
@@ -132,23 +132,24 @@ public class ServiceStateStats {
    }

    /**
     * Returns the band used from the given phone and RAT, or {@code 0} if it is invalid or cannot
     * Returns the band used from the given phone, or {@code 0} if it is invalid or cannot
     * be determined.
     */
    static int getBand(Phone phone, @NetworkType int rat) {
    static int getBand(Phone phone) {
        ServiceState serviceState = getServiceStateForPhone(phone);
        return getBand(serviceState, rat);
        return getBand(serviceState);
    }

    /**
     * Returns the band used from the given service state and RAT, or {@code 0} if it is invalid or
     * Returns the band used from the given service state, or {@code 0} if it is invalid or
     * cannot be determined.
     */
    static int getBand(@Nullable ServiceState serviceState, @NetworkType int rat) {
    static int getBand(@Nullable ServiceState serviceState) {
        if (serviceState == null) {
            return 0; // Band unknown
        }
        int chNumber = serviceState.getChannelNumber();
        @NetworkType int rat = serviceState.getDataNetworkType();
        int band;
        switch (rat) {
            case TelephonyManager.NETWORK_TYPE_GSM:
+5 −1
Original line number Diff line number Diff line
@@ -519,7 +519,11 @@ public class VoiceCallSessionStats {

    private void updateRatTracker(ServiceState state) {
        @NetworkType int rat = getRat(state);
        int band = ServiceStateStats.getBand(state, rat);
        boolean isWifiCall =
                mPhone.getImsPhone() != null
                        && mPhone.getImsPhone().isWifiCallingEnabled()
                        && state.getDataNetworkType() == TelephonyManager.NETWORK_TYPE_IWLAN;
        int band = isWifiCall ? 0 : ServiceStateStats.getBand(state);

        mRatUsage.add(mPhone.getCarrierId(), rat, getTimeMillis(), getConnectionIds());
        for (int i = 0; i < mCallProtos.size(); i++) {