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

Commit d6911b14 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[VZW P2P] Add metric for Carrier Roaming NB-IoT NTN module,...

Merge "[VZW P2P] Add metric for Carrier Roaming NB-IoT NTN module, maxInactivityDurationSec, to track the maximum user inactivity duration of a satellite session." into main
parents 8848d8c5 1bcb3d70
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -749,6 +749,7 @@ message SatelliteSession {
    optional int32 count_of_auto_exit_due_to_tn_network = 17;
    optional bool is_emergency = 18;
    optional bool is_ntn_only_carrier = 19;
    optional int32 max_inactivity_duration_sec = 20;
}

message SatelliteIncomingDatagram {
+2 −1
Original line number Diff line number Diff line
@@ -1508,7 +1508,8 @@ public class MetricsCollector implements StatsManager.StatsPullAtomCallback {
                satelliteSession.countOfAutoExitDueToScreenOff,
                satelliteSession.countOfAutoExitDueToTnNetwork,
                satelliteSession.isEmergency,
                satelliteSession.isNtnOnlyCarrier);
                satelliteSession.isNtnOnlyCarrier,
                satelliteSession.maxInactivityDurationSec);
    }

    private static StatsEvent buildStatsEvent(SatelliteIncomingDatagram stats) {
+2 −1
Original line number Diff line number Diff line
@@ -2347,7 +2347,8 @@ public class PersistAtomsStorage {
                    == key.countOfSatelliteNotificationDisplayed
                    && stats.countOfAutoExitDueToScreenOff == key.countOfAutoExitDueToScreenOff
                    && stats.countOfAutoExitDueToTnNetwork == key.countOfAutoExitDueToTnNetwork
                    && stats.isEmergency == key.isEmergency) {
                    && stats.isEmergency == key.isEmergency
                    && stats.maxInactivityDurationSec == key.maxInactivityDurationSec) {
                return stats;
            }
        }
+15 −0
Original line number Diff line number Diff line
@@ -804,6 +804,7 @@ public class SatelliteStats {
        private final int mCountOfAutoExitDueToScreenOff;
        private final int mCountOfAutoExitDueToTnNetwork;
        private final boolean mIsEmergency;
        private final int mMaxInactivityDurationSec;
        private final boolean mIsNtnOnlyCarrier;

        private SatelliteSessionParams(Builder builder) {
@@ -828,6 +829,7 @@ public class SatelliteStats {
            this.mCountOfAutoExitDueToTnNetwork = builder.mCountOfAutoExitDueToTnNetwork;
            this.mIsEmergency = builder.mIsEmergency;
            this.mIsNtnOnlyCarrier = builder.mIsNtnOnlyCarrier;
            this.mMaxInactivityDurationSec = builder.mMaxInactivityDurationSec;
        }

        public int getSatelliteServiceInitializationResult() {
@@ -902,6 +904,10 @@ public class SatelliteStats {
            return mIsNtnOnlyCarrier;
        }

        public int getMaxInactivityDurationSec() {
            return mMaxInactivityDurationSec;
        }

        /**
         * A builder class to create {@link SatelliteSessionParams} data structure class
         */
@@ -925,6 +931,7 @@ public class SatelliteStats {
            private int mCountOfAutoExitDueToTnNetwork = -1;
            private boolean mIsEmergency = false;
            private boolean mIsNtnOnlyCarrier = false;
            private int mMaxInactivityDurationSec = -1;

            /**
             * Sets satelliteServiceInitializationResult value of {@link SatelliteSession}
@@ -1058,6 +1065,12 @@ public class SatelliteStats {
                return this;
            }

            /** Sets the max user inactivity duration in seconds. */
            public Builder setMaxInactivityDurationSec(int maxInactivityDurationSec) {
                this.mMaxInactivityDurationSec = maxInactivityDurationSec;
                return this;
            }

            /**
             * Returns SessionParams, which contains whole component of
             * {@link SatelliteSession} atom
@@ -1090,6 +1103,7 @@ public class SatelliteStats {
                    + ", CountOfAutoExitDueToTnNetwork" + mCountOfAutoExitDueToTnNetwork
                    + ", IsEmergency=" + mIsEmergency
                    + ", IsNtnOnlyCarrier=" + mIsNtnOnlyCarrier
                    + ", MaxInactivityDurationSec=" + mMaxInactivityDurationSec
                    + ")";
        }
    }
@@ -2715,6 +2729,7 @@ public class SatelliteStats {
        proto.countOfAutoExitDueToTnNetwork = param.getCountOfAutoExitDueToTnNetwork();
        proto.isEmergency = param.getIsEmergency();
        proto.isNtnOnlyCarrier = param.isNtnOnlyCarrier();
        proto.maxInactivityDurationSec = param.getMaxInactivityDurationSec();
        mAtomsStorage.addSatelliteSessionStats(proto);
    }

+74 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ROAMING_P2P_S
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ROAMING_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC_INT;
import static android.telephony.satellite.SatelliteManager.DATAGRAM_TYPE_SMS;
import static android.telephony.satellite.SatelliteManager.DATAGRAM_TYPE_SOS_MESSAGE;
import static android.telephony.satellite.SatelliteManager.DATAGRAM_TYPE_UNKNOWN;
import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_IDLE;
import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_RECEIVE_FAILED;
import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_RECEIVE_NONE;
@@ -30,6 +31,7 @@ import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TR
import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_SEND_FAILED;
import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_SEND_SUCCESS;
import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_WAITING_TO_CONNECT;
import static android.telephony.satellite.SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_UNKNOWN;
import static android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED;
import static android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_DATAGRAM_TRANSFERRING;
import static android.telephony.satellite.SatelliteManager.SATELLITE_MODEM_STATE_ENABLING_SATELLITE;
@@ -143,6 +145,7 @@ public class SatelliteSessionController extends StateMachine {
    private static final int DEFAULT_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC = 30;
    private static final int DEFAULT_P2P_SMS_INACTIVITY_TIMEOUT_SEC = 180;
    private static final int DEFAULT_ESOS_INACTIVITY_TIMEOUT_SEC = 600;
    private static final long UNDEFINED_TIMESTAMP = 0L;

    @NonNull private final ExponentialBackoff mExponentialBackoff;
    @NonNull private final Object mLock = new Object();
@@ -181,6 +184,12 @@ public class SatelliteSessionController extends StateMachine {
    // Interested in screen off, so use default value true
    boolean mIsScreenOn = true;
    private boolean mIsDeviceAlignedWithSatellite = false;
    private long mInactivityStartTimestamp = UNDEFINED_TIMESTAMP;
    private DatagramTransferState mLastDatagramTransferState =
            new DatagramTransferState(
                    SATELLITE_DATAGRAM_TRANSFER_STATE_UNKNOWN,
                    SATELLITE_DATAGRAM_TRANSFER_STATE_UNKNOWN,
                    DATAGRAM_TYPE_UNKNOWN);

    @NonNull private final SatelliteController mSatelliteController;
    @NonNull private final DatagramController mDatagramController;
@@ -334,11 +343,21 @@ public class SatelliteSessionController extends StateMachine {
            @SatelliteManager.SatelliteDatagramTransferState int sendState,
            @SatelliteManager.SatelliteDatagramTransferState int receiveState,
            @SatelliteManager.DatagramType int datagramType) {
        sendMessage(EVENT_DATAGRAM_TRANSFER_STATE_CHANGED,
                new DatagramTransferState(sendState, receiveState, datagramType));
        DatagramTransferState datagramTransferState =
                new DatagramTransferState(sendState, receiveState, datagramType);
        mLastDatagramTransferState = datagramTransferState;

        sendMessage(EVENT_DATAGRAM_TRANSFER_STATE_CHANGED, datagramTransferState);

        if (sendState == SATELLITE_DATAGRAM_TRANSFER_STATE_SENDING) {
            mIsSendingTriggeredDuringTransferringState.set(true);
        }

        if (datagramTransferState.isIdle()) {
            checkForInactivity();
        } else {
            endUserInactivity();
        }
    }

    /**
@@ -556,11 +575,13 @@ public class SatelliteSessionController extends StateMachine {
        if (mIsDeviceAlignedWithSatellite) {
            stopEsosInactivityTimer();
            stopP2pSmsInactivityTimer();
            endUserInactivity();
        } else {
            if (mCurrentState == SatelliteManager.SATELLITE_MODEM_STATE_NOT_CONNECTED) {
                evaluateStartingEsosInactivityTimer();
                evaluateStartingP2pSmsInactivityTimer();
            }
            checkForInactivity();
        }
    }

@@ -591,6 +612,7 @@ public class SatelliteSessionController extends StateMachine {
    public void cleanUpResource() {
        plogd("cleanUpResource");
        mIsDeviceAlignedWithSatellite = false;
        mInactivityStartTimestamp = UNDEFINED_TIMESTAMP;
        unregisterForScreenStateChanged();
        if (mAlarmManager != null) {
            mAlarmManager.cancel(mAlarmListener);
@@ -648,6 +670,11 @@ public class SatelliteSessionController extends StateMachine {
            this.receiveState = receiveState;
            this.datagramType = datagramType;
        }

        public boolean isIdle() {
            return (sendState == SATELLITE_DATAGRAM_TRANSFER_STATE_IDLE
                    && receiveState == SATELLITE_DATAGRAM_TRANSFER_STATE_IDLE);
        }
    }

    private class UnavailableState extends State {
@@ -678,6 +705,7 @@ public class SatelliteSessionController extends StateMachine {
            mIsSendingTriggeredDuringTransferringState.set(false);
            unbindService();
            stopNbIotInactivityTimer();
            endUserInactivity();
            DemoSimulator.getInstance().onSatelliteModeOff();
            notifyStateChangedEvent(SatelliteManager.SATELLITE_MODEM_STATE_OFF);

@@ -1834,6 +1862,50 @@ public class SatelliteSessionController extends StateMachine {
        return hasMessages(EVENT_P2P_SMS_INACTIVITY_TIMER_TIMED_OUT);
    }

    /**
     * Initializes the inactivity start timestamp.
     *
     * <p>This method is called when 1) the datagram transfer state changes to idle or 2) the
     * device is unaligned with the satellite.
     */
    private void checkForInactivity() {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            return;
        }

        // If the inactivity start timestamp is not undefined, it means the inactivity has already
        // started.
        if (mInactivityStartTimestamp != UNDEFINED_TIMESTAMP) {
            return;
        }

        boolean isInactive = mLastDatagramTransferState.isIdle() && !mIsDeviceAlignedWithSatellite;
        if (isInactive) {
            mInactivityStartTimestamp = SystemClock.elapsedRealtime();
        }
    }

    /**
     * Updates the max inactivity duration session metric.
     *
     * <p>This method is called when 1) the datagram transfer state changes to not idle, 2) the
     * device is aligned with the satellite, or 3) modem state moves to PowerOffState.
     */
    private void endUserInactivity() {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            plogd("endUserInactivity: carrierRoamingNbIotNtn is disabled");
            return;
        }

        if (mInactivityStartTimestamp != UNDEFINED_TIMESTAMP) {
            long inactivityDurationMs = SystemClock.elapsedRealtime() - mInactivityStartTimestamp;
            int inactivityDurationSec = (int) (inactivityDurationMs / 1000);
            mSessionMetricsStats.updateMaxInactivityDurationSec(inactivityDurationSec);

            mInactivityStartTimestamp = UNDEFINED_TIMESTAMP;
        }
    }

    private void handleEventScreenOffInactivityTimerTimedOut() {
        if (mSatelliteController.getRequestIsEmergency()) {
            loge("handleEventScreenOffInactivityTimerTimedOut: Emergency mode");
Loading