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

Commit 3ce6d435 authored by joonhunshin's avatar joonhunshin Committed by Aishwarya Mallampati
Browse files

Add disabling satellite when display off inactivity timer expired

Bug: 350518479
Test: atest SatelliteSessionControllerTest
      manual test in demo and real network (b/355117404)
Flag: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn

Change-Id: I21c1a1b2608cc9f8c4460b252fe2d49415005ca7
parent c2edf980
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ public class DeviceStateMonitor extends Handler {
    private final RegistrantList mPhysicalChannelConfigRegistrants = new RegistrantList();
    private final RegistrantList mSignalStrengthReportDecisionCallbackRegistrants =
            new RegistrantList();
    private final RegistrantList mScreenStateRegistrants = new RegistrantList();

    private final NetworkRequest mWifiNetworkRequest =
            new NetworkRequest.Builder()
@@ -515,6 +516,7 @@ public class DeviceStateMonitor extends Handler {
    private void onUpdateDeviceState(int eventType, boolean state) {
        final boolean shouldEnableBarringInfoReportsOld = shouldEnableBarringInfoReports();
        final boolean wasHighPowerEnabled = shouldEnableHighPowerConsumptionIndications();
        boolean wasScreenOn = mIsScreenOn;
        switch (eventType) {
            case EVENT_SCREEN_STATE_CHANGED:
                if (mIsScreenOn == state) return;
@@ -624,6 +626,13 @@ public class DeviceStateMonitor extends Handler {
                mSignalStrengthReportDecisionCallbackRegistrants.notifyResult(false);
            }
        }

        if (mFeatureFlags.carrierRoamingNbIotNtn()) {
            // Determine whether to notify registrants about the screen on, off state change.
            if (wasScreenOn != mIsScreenOn) {
                mScreenStateRegistrants.notifyResult(mIsScreenOn);
            }
        }
    }

    /**
@@ -814,6 +823,37 @@ public class DeviceStateMonitor extends Handler {
        mSignalStrengthReportDecisionCallbackRegistrants.add(r);
    }

    /**
     * Unregister for Screen on, off notifications changed.
     * @param h Handler to notify
     */
    public void unregisterForScreenStateChanged(Handler h) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            Rlog.d(TAG, "unregisterForScreenStateChanged: carrierRoamingNbIotNtn is disabled");
            return;
        }

        mScreenStateRegistrants.remove(h);
    }

    /**
     * Register a callback to receive the screen on or off.
     * @param h Handler to notify
     * @param what msg.what when the message is delivered
     * @param obj AsyncResult.userObj when the message is delivered
     */
    public void registerForScreenStateChanged(Handler h, int what, Object obj) {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            Rlog.d(TAG, "registerForScreenStateChanged: carrierRoamingNbIotNtn is disabled");
            return;
        }
        Registrant r = new Registrant(h, what, obj);
        mScreenStateRegistrants.add(r);

        // Initial notification
        mScreenStateRegistrants.notifyResult(mIsScreenOn);
    }

    /**
     * Register a callback to decide whether signal strength should be notified or not.
     * @param h Handler to notify
+11 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import static android.telephony.CarrierConfigManager.KEY_EMERGENCY_CALL_TO_SATEL
import static android.telephony.CarrierConfigManager.KEY_EMERGENCY_MESSAGING_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ATTACH_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC_INT;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ENTITLEMENT_SUPPORTED_BOOL;
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ESOS_SUPPORTED_BOOL;
import static android.telephony.SubscriptionManager.SATELLITE_ATTACH_ENABLED_FOR_CARRIER;
@@ -4179,7 +4180,8 @@ public class SatelliteController extends Handler {
                    KEY_EMERGENCY_CALL_TO_SATELLITE_T911_HANDOVER_TIMEOUT_MILLIS_INT,
                    KEY_SATELLITE_ESOS_SUPPORTED_BOOL,
                    KEY_CARRIER_ROAMING_NTN_CONNECT_TYPE_INT,
                    KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT
                    KEY_CARRIER_SUPPORTED_SATELLITE_NOTIFICATION_HYSTERESIS_SEC_INT,
                    KEY_SATELLITE_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC_INT
            );
        }
        if (config == null || config.isEmpty()) {
@@ -5183,8 +5185,15 @@ public class SatelliteController extends Handler {
        }
    }

    /**
     * Read carrier config items for satellite
     *
     * @param subId Associated subscription ID
     * @return PersistableBundle including carrier config values
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    @NonNull
    private PersistableBundle getPersistableBundle(int subId) {
    public PersistableBundle getPersistableBundle(int subId) {
        synchronized (mCarrierConfigArrayLock) {
            PersistableBundle config = mCarrierConfigArray.get(subId);
            if (config == null) {
+171 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony.satellite;

import static android.telephony.CarrierConfigManager.KEY_SATELLITE_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC_INT;
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;
@@ -37,6 +38,7 @@ import android.os.Build;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.telephony.DropBoxManagerLoggerBackend;
@@ -51,10 +53,14 @@ import android.util.Log;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.DeviceStateMonitor;
import com.android.internal.telephony.ExponentialBackoff;
import com.android.internal.telephony.IIntegerConsumer;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.flags.FeatureFlags;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.telephony.Rlog;

import java.util.ArrayList;
import java.util.List;
@@ -105,18 +111,24 @@ public class SatelliteSessionController extends StateMachine {
    protected static final int EVENT_NB_IOT_INACTIVITY_TIMER_TIMED_OUT = 6;
    private static final int EVENT_SATELLITE_ENABLEMENT_STARTED = 7;
    private static final int EVENT_SATELLITE_ENABLEMENT_FAILED = 8;
    private static final int EVENT_SCREEN_STATE_CHANGED = 9;
    protected static final int EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT = 10;

    private static final long REBIND_INITIAL_DELAY = 2 * 1000; // 2 seconds
    private static final long REBIND_MAXIMUM_DELAY = 64 * 1000; // 1 minute
    private static final int REBIND_MULTIPLIER = 2;
    private static final int DEFAULT_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC = 30;

    @NonNull private final ExponentialBackoff mExponentialBackoff;
    @NonNull private final Object mLock = new Object();
    @NonNull private final Phone mPhone;
    @Nullable
    private ISatelliteGateway mSatelliteGatewayService;
    private String mSatelliteGatewayServicePackageName = "";
    @Nullable private SatelliteGatewayServiceConnection mSatelliteGatewayServiceConnection;
    private boolean mIsBound;
    private boolean mIsBinding;
    private boolean mIsRegisteredScreenStateChanged = false;

    @NonNull private static SatelliteSessionController sInstance;

@@ -141,11 +153,16 @@ public class SatelliteSessionController extends StateMachine {
    @SatelliteManager.SatelliteModemState private int mPreviousState;
    final boolean mIsSatelliteSupported;
    private boolean mIsDemoMode = false;
    // Interested in screen off, so use default value true
    boolean mIsScreenOn = true;
    @GuardedBy("mLock")
    @NonNull private boolean mIsDisableCellularModemInProgress = false;
    @NonNull private final SatelliteController mSatelliteController;
    @NonNull private final DatagramController mDatagramController;
    @Nullable private PersistentLogger mPersistentLogger = null;
    @Nullable private DeviceStateMonitor mDeviceStateMonitor;

    @NonNull private FeatureFlags mFeatureFlags;

    /**
     * @return The singleton instance of SatelliteSessionController.
@@ -172,6 +189,10 @@ public class SatelliteSessionController extends StateMachine {
            @NonNull FeatureFlags featureFlags,
            boolean isSatelliteSupported) {
        if (sInstance == null || isSatelliteSupported != sInstance.mIsSatelliteSupported) {
            if (sInstance != null) {
                sInstance.cleanUpResource();
            }

            sInstance = new SatelliteSessionController(
                    context,
                    looper,
@@ -204,6 +225,7 @@ public class SatelliteSessionController extends StateMachine {
        }

        mContext = context;
        mFeatureFlags = featureFlags;
        mSatelliteModemInterface = satelliteModemInterface;
        mSatelliteController = SatelliteController.getInstance();
        mDatagramController = DatagramController.getInstance();
@@ -234,6 +256,9 @@ public class SatelliteSessionController extends StateMachine {
            bindService();
        });

        mPhone = SatelliteServiceUtils.getPhone();
        mDeviceStateMonitor = mPhone.getDeviceStateMonitor();

        addState(mUnavailableState);
        addState(mPowerOffState);
        addState(mEnablingState);
@@ -422,6 +447,15 @@ public class SatelliteSessionController extends StateMachine {
        return getCurrentState() == mEnablingState;
    }

    /**
     * Release all resource.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public void cleanUpResource() {
        if (DBG) plogd("cleanUpResource");
        unregisterForScreenStateChanged();
    }

    private boolean isDemoMode() {
        return mIsDemoMode;
    }
@@ -468,6 +502,8 @@ public class SatelliteSessionController extends StateMachine {
            stopNbIotInactivityTimer();
            DemoSimulator.getInstance().onSatelliteModeOff();
            notifyStateChangedEvent(SatelliteManager.SATELLITE_MODEM_STATE_OFF);

            unregisterForScreenStateChanged();
        }

        @Override
@@ -539,6 +575,8 @@ public class SatelliteSessionController extends StateMachine {
                    transitionTo(mIdleState);
                }
                DemoSimulator.getInstance().onSatelliteModeOn();

                registerForScreenStateChanged();
            } else {
                /*
                 * During the state transition from ENABLING to NOT_CONNECTED, modem might be
@@ -560,6 +598,8 @@ public class SatelliteSessionController extends StateMachine {
            mPreviousState = mCurrentState;
            mCurrentState = SatelliteManager.SATELLITE_MODEM_STATE_DISABLING_SATELLITE;
            notifyStateChangedEvent(SatelliteManager.SATELLITE_MODEM_STATE_DISABLING_SATELLITE);

            unregisterForScreenStateChanged();
        }

        @Override
@@ -638,6 +678,12 @@ public class SatelliteSessionController extends StateMachine {
                case EVENT_SATELLITE_ENABLEMENT_STARTED:
                    handleSatelliteEnablementStarted((boolean) msg.obj);
                    break;
                case EVENT_SCREEN_STATE_CHANGED:
                    handleEventScreenStateChanged((AsyncResult) msg.obj);
                    break;
                case EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT:
                    handleEventScreenOffInactivityTimerTimedOut();
                    break;
            }
            // Ignore all unexpected events.
            return HANDLED;
@@ -732,6 +778,12 @@ public class SatelliteSessionController extends StateMachine {
                case EVENT_SATELLITE_ENABLEMENT_STARTED:
                    handleSatelliteEnablementStarted((boolean) msg.obj);
                    break;
                case EVENT_SCREEN_STATE_CHANGED:
                    handleEventScreenStateChanged((AsyncResult) msg.obj);
                    break;
                case EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT:
                    handleEventScreenOffInactivityTimerTimedOut();
                    break;
            }
            // Ignore all unexpected events.
            return HANDLED;
@@ -803,6 +855,12 @@ public class SatelliteSessionController extends StateMachine {
                case EVENT_SATELLITE_ENABLEMENT_STARTED:
                    handleSatelliteEnablementStarted((boolean) msg.obj);
                    break;
                case EVENT_SCREEN_STATE_CHANGED:
                    handleEventScreenStateChanged((AsyncResult) msg.obj);
                    break;
                case EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT:
                    handleEventScreenOffInactivityTimerTimedOut();
                    break;
            }
            // Ignore all unexpected events.
            return HANDLED;
@@ -866,6 +924,12 @@ public class SatelliteSessionController extends StateMachine {
                case EVENT_SATELLITE_ENABLEMENT_STARTED:
                    handleSatelliteEnablementStarted((boolean) msg.obj);
                    break;
                case EVENT_SCREEN_STATE_CHANGED:
                    handleEventScreenStateChanged((AsyncResult) msg.obj);
                    break;
                case EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT:
                    handleEventScreenOffInactivityTimerTimedOut();
                    break;
            }
            // Ignore all unexpected events.
            return HANDLED;
@@ -932,6 +996,12 @@ public class SatelliteSessionController extends StateMachine {
                case EVENT_SATELLITE_ENABLEMENT_STARTED:
                    handleSatelliteEnablementStarted((boolean) msg.obj);
                    break;
                case EVENT_SCREEN_STATE_CHANGED:
                    handleEventScreenStateChanged((AsyncResult) msg.obj);
                    break;
                case EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT:
                    handleEventScreenOffInactivityTimerTimedOut();
                    break;
            }
            // Ignore all unexpected events.
            return HANDLED;
@@ -984,6 +1054,12 @@ public class SatelliteSessionController extends StateMachine {
            case EVENT_SATELLITE_ENABLEMENT_FAILED:
                whatString = "EVENT_SATELLITE_ENABLEMENT_FAILED";
                break;
            case EVENT_SCREEN_STATE_CHANGED:
                whatString = "EVENT_SCREEN_STATE_CHANGED";
                break;
            case EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT:
                whatString = "EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT";
                break;
            default:
                whatString = "UNKNOWN EVENT " + what;
        }
@@ -1103,6 +1179,7 @@ public class SatelliteSessionController extends StateMachine {
            mSatelliteGatewayServiceConnection = null;
        }
    }

    private class SatelliteGatewayServiceConnection implements ServiceConnection {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
@@ -1143,6 +1220,100 @@ public class SatelliteSessionController extends StateMachine {
        }
    }

    private void registerForScreenStateChanged() {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            Rlog.d(TAG, "registerForScreenStateChanged: carrierRoamingNbIotNtn is disabled");
            return;
        }

        if (mSatelliteController.getRequestIsEmergency()) {
            if (DBG) logd("registerScreenOnOffChanged: Emergency mode");
            // screen on/off timer is available in not emergency mode
            return;
        }

        if (!mIsRegisteredScreenStateChanged && mDeviceStateMonitor != null) {
            mDeviceStateMonitor.registerForScreenStateChanged(
                    getHandler(), EVENT_SCREEN_STATE_CHANGED, null);

            mIsRegisteredScreenStateChanged = true;
            plogd("registerForScreenStateChanged: registered");
        } else {
            plogw("registerForScreenStateChanged: skip register, mIsRegisteredScreenStateChanged="
                    + mIsRegisteredScreenStateChanged + ","
                    + " mDeviceStateMonitor=" + (mDeviceStateMonitor != null));
        }
    }

    private void unregisterForScreenStateChanged() {
        if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
            Rlog.d(TAG, "unregisterForScreenStateChanged: carrierRoamingNbIotNtn is disabled");
            return;
        }

        if (mIsRegisteredScreenStateChanged && mDeviceStateMonitor != null) {
            mDeviceStateMonitor.unregisterForScreenStateChanged(getHandler());
            removeMessages(EVENT_SCREEN_STATE_CHANGED);
            removeMessages(EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT);

            removeDeferredMessages(EVENT_SCREEN_STATE_CHANGED);
            removeDeferredMessages(EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT);

            mIsRegisteredScreenStateChanged = false;
            plogd("unregisterForScreenStateChanged: unregistered");
        }
    }

    private void handleEventScreenStateChanged(AsyncResult asyncResult) {
        if (asyncResult == null) {
            ploge("handleEventScreenStateChanged: asyncResult is null");
            return;
        }

        boolean screenOn = (boolean) asyncResult.result;
        if (mIsScreenOn == screenOn) {
            if (DBG) plogd("handleEventScreenStateChanged: screen state is not changed");
            return;
        }
        mIsScreenOn = screenOn;

        if (!screenOn) {
            // Screen off, start timer
            int timeoutMillis = getScreenOffInactivityTimeoutDurationSec() * 1000;
            sendMessageDelayed(EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT, timeoutMillis);

            plogd("handleEventScreenStateChanged: start timer " + timeoutMillis);
        } else {
            // Screen on, stop timer
            removeMessages(EVENT_SCREEN_OFF_INACTIVITY_TIMER_TIMED_OUT);

            plogd("handleEventScreenStateChanged: stop timer");
        }
    }

    private int getScreenOffInactivityTimeoutDurationSec() {
        PersistableBundle config = mSatelliteController.getPersistableBundle(
                mPhone.getSubId());

        return config.getInt(KEY_SATELLITE_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC_INT,
                DEFAULT_SCREEN_OFF_INACTIVITY_TIMEOUT_SEC);
    }

    private void handleEventScreenOffInactivityTimerTimedOut() {
        plogd("handleEventScreenOffInactivityTimerTimedOut: request disable satellite");

        mSatelliteController.requestSatelliteEnabled(mPhone.getSubId(),
                false /*enableSatellite*/,
                false /*enableDemoMode*/,
                mSatelliteController.getRequestIsEmergency() /*isEmergency*/,
                new IIntegerConsumer.Stub() {
                    @Override
                    public void accept(int result) {
                        plogd("requestSatelliteEnabled result=" + result);
                    }
                });
    }

    private boolean isMockModemAllowed() {
        return (DEBUG || SystemProperties.getBoolean(ALLOW_MOCK_MODEM_PROPERTY, false));
    }
+2 −0
Original line number Diff line number Diff line
@@ -543,6 +543,7 @@ public class SatelliteControllerTest extends TelephonyTest {
                .onSatelliteEnabledStateChanged(anyBoolean());
        doNothing().when(mMockSatelliteSessionController).onSatelliteModemStateChanged(anyInt());
        doNothing().when(mMockSatelliteSessionController).setDemoMode(anyBoolean());
        doNothing().when(mMockSatelliteSessionController).cleanUpResource();
        doNothing().when(mMockControllerMetricsStats).onSatelliteEnabled();
        doNothing().when(mMockControllerMetricsStats).reportServiceEnablementSuccessCount();
        doNothing().when(mMockControllerMetricsStats).reportServiceEnablementFailCount();
@@ -569,6 +570,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        doNothing().when(mMockProvisionMetricsStats).reportProvisionMetrics();
        doNothing().when(mMockControllerMetricsStats).reportDeprovisionCount(anyInt());
        when(mFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true);
        when(mFeatureFlags.carrierRoamingNbIotNtn()).thenReturn(false);
        doReturn(mSST).when(mPhone).getServiceStateTracker();
        doReturn(mSST).when(mPhone2).getServiceStateTracker();
        doReturn(mServiceState).when(mSST).getServiceState();
+115 −1

File changed.

Preview size limit exceeded, changes collapsed.