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

Commit 544ecb7a authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Android Build Coastguard Worker
Browse files

Update carrier roaming ntn eligibility whenever satellite access allowed

changes.

Bug: 384236738
Test: atest SatelliteControllerTest
Test: 384939192
FLAG: EXEMPT bugfix
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:d953275c5e5c4917440ae23c573bb5b1d2feee4d)
Merged-In: Ibfd4a6df2045fdfb40868d4905d32202a8174528
Change-Id: Ibfd4a6df2045fdfb40868d4905d32202a8174528
parent 825fa72c
Loading
Loading
Loading
Loading
+9 −81
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ import android.os.IBinder;
import android.os.ICancellationSignal;
import android.os.Looper;
import android.os.Message;
import android.os.OutcomeReceiver;
import android.os.PersistableBundle;
import android.os.Registrant;
import android.os.RegistrantList;
@@ -138,6 +137,7 @@ import android.telephony.satellite.ISatelliteSupportedStateCallback;
import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback;
import android.telephony.satellite.NtnSignalStrength;
import android.telephony.satellite.SatelliteAccessConfiguration;
import android.telephony.satellite.SatelliteCapabilities;
import android.telephony.satellite.SatelliteCommunicationAllowedStateCallback;
import android.telephony.satellite.SatelliteDatagram;
@@ -147,7 +147,6 @@ import android.telephony.satellite.SatelliteSubscriberInfo;
import android.telephony.satellite.SatelliteSubscriberProvisionStatus;
import android.telephony.satellite.SatelliteSubscriptionInfo;
import android.telephony.satellite.SystemSelectionSpecifier;
import android.telephony.satellite.SatelliteAccessConfiguration;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
@@ -295,7 +294,6 @@ public class SatelliteController extends Handler {
    private static final int EVENT_UPDATE_PROVISION_SATELLITE_TOKEN_DONE = 45;
    private static final int EVENT_NOTIFY_NTN_ELIGIBILITY_HYSTERESIS_TIMED_OUT = 46;
    private static final int EVENT_WIFI_CONNECTIVITY_STATE_CHANGED = 47;
    private static final int EVENT_SATELLITE_ACCESS_RESTRICTION_CHECKING_RESULT = 48;
    protected static final int EVENT_WAIT_FOR_CELLULAR_MODEM_OFF_TIMED_OUT = 49;
    private static final int CMD_UPDATE_SATELLITE_ENABLE_ATTRIBUTES = 50;
    private static final int EVENT_UPDATE_SATELLITE_ENABLE_ATTRIBUTES_DONE = 51;
@@ -535,8 +533,6 @@ public class SatelliteController extends Handler {
    @GuardedBy("mSatellitePhoneLock")
    private Boolean mLastNotifiedNtnEligibility = null;
    @GuardedBy("mSatellitePhoneLock")
    private boolean mNtnEligibilityHysteresisTimedOut = false;
    @GuardedBy("mSatellitePhoneLock")
    private boolean mCheckingAccessRestrictionInProgress = false;

    @GuardedBy("mSatelliteConnectedLock")
@@ -1968,16 +1964,10 @@ public class SatelliteController extends Handler {
            }

            case EVENT_NOTIFY_NTN_ELIGIBILITY_HYSTERESIS_TIMED_OUT: {
                synchronized (mSatellitePhoneLock) {
                    mNtnEligibilityHysteresisTimedOut = true;
                }

                boolean eligible = isCarrierRoamingNtnEligible(mSatellitePhone);
                plogd("EVENT_NOTIFY_NTN_ELIGIBILITY_HYSTERESIS_TIMED_OUT:"
                        + " isCarrierRoamingNtnEligible=" + eligible);
                if (eligible) {
                    requestIsSatelliteAllowedForCurrentLocation();
                }
                updateLastNotifiedNtnEligibilityAndNotify(eligible);
                break;
            }

@@ -2052,10 +2042,6 @@ public class SatelliteController extends Handler {
                evaluateCarrierRoamingNtnEligibilityChange();
                break;
            }
            case EVENT_SATELLITE_ACCESS_RESTRICTION_CHECKING_RESULT: {
                handleSatelliteAccessRestrictionCheckingResult((boolean) msg.obj);
                break;
            }

            case EVENT_WAIT_FOR_CELLULAR_MODEM_OFF_TIMED_OUT: {
                plogw("Timed out to wait for cellular modem OFF state");
@@ -6118,9 +6104,6 @@ public class SatelliteController extends Handler {
                startNtnEligibilityHysteresisTimer();
            }
        } else {
            synchronized (mSatellitePhoneLock) {
                mNtnEligibilityHysteresisTimedOut = false;
            }
            stopNtnEligibilityHysteresisTimer();
            updateLastNotifiedNtnEligibilityAndNotify(false);
        }
@@ -6154,9 +6137,6 @@ public class SatelliteController extends Handler {

        int subId = getSelectedSatelliteSubId();
        long timeout = getCarrierSupportedSatelliteNotificationHysteresisTimeMillis(subId);
        synchronized (mSatellitePhoneLock) {
            mNtnEligibilityHysteresisTimedOut = false;
        }
        plogd("startNtnEligibilityHysteresisTimer: sendMessageDelayed subId=" + subId
                    + ", phoneId=" + satellitePhone.getPhoneId() + ", timeout=" + timeout);
        sendMessageDelayed(obtainMessage(EVENT_NOTIFY_NTN_ELIGIBILITY_HYSTERESIS_TIMED_OUT),
@@ -7748,6 +7728,12 @@ public class SatelliteController extends Handler {
            return false;
        }

        boolean isSatelliteAccessAllowed = isSatelliteAccessAllowedAtCurrentLocation();
        if (!isSatelliteAccessAllowed) {
            plogd("isCarrierRoamingNtnEligible: satellite access is not allowed");
            return false;
        }

        if (phone == null) {
            plogd("isCarrierRoamingNtnEligible: phone is null");
            return false;
@@ -7771,7 +7757,6 @@ public class SatelliteController extends Handler {
            return false;
        }


        int[] services = getSupportedServicesOnCarrierRoamingNtn(subId);
        if (!ArrayUtils.contains(services, NetworkRegistrationInfo.SERVICE_TYPE_SMS)) {
            plogd("isCarrierRoamingNtnEligible[phoneId=" + phone.getPhoneId()
@@ -7848,64 +7833,6 @@ public class SatelliteController extends Handler {
        }
    }

    private void requestIsSatelliteAllowedForCurrentLocation() {
        plogd("requestIsSatelliteAllowedForCurrentLocation()");
        synchronized (mSatellitePhoneLock) {
            if (mCheckingAccessRestrictionInProgress) {
                plogd("requestIsSatelliteCommunicationAllowedForCurrentLocation was already sent");
                return;
            }
            mCheckingAccessRestrictionInProgress = true;
        }

        OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> callback =
                new OutcomeReceiver<>() {
                    @Override
                    public void onResult(Boolean result) {
                        plogd("requestIsSatelliteAllowedForCurrentLocation: result=" + result);
                        sendMessage(obtainMessage(
                                EVENT_SATELLITE_ACCESS_RESTRICTION_CHECKING_RESULT, result));
                    }

                    @Override
                    public void onError(SatelliteManager.SatelliteException ex) {
                        plogd("requestIsSatelliteAllowedForCurrentLocation: onError, ex=" + ex);
                        sendMessage(obtainMessage(
                                EVENT_SATELLITE_ACCESS_RESTRICTION_CHECKING_RESULT, false));
                    }
                };
        requestIsSatelliteCommunicationAllowedForCurrentLocation(callback);
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void requestIsSatelliteCommunicationAllowedForCurrentLocation(
            @NonNull OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> callback) {
        SatelliteManager satelliteManager = mContext.getSystemService(SatelliteManager.class);
        if (satelliteManager == null) {
            ploge("requestIsSatelliteCommunicationAllowedForCurrentLocation: "
                    + "SatelliteManager is null");
            return;
        }

        satelliteManager.requestIsCommunicationAllowedForCurrentLocation(
                this::post, callback);
    }

    private void handleSatelliteAccessRestrictionCheckingResult(boolean satelliteAllowed) {
        synchronized (mSatellitePhoneLock) {
            mCheckingAccessRestrictionInProgress = false;
            boolean eligible = isCarrierRoamingNtnEligible(mSatellitePhone);
            plogd("handleSatelliteAccessRestrictionCheckingResult:"
                    + " satelliteAllowed=" + satelliteAllowed
                    + ", isCarrierRoamingNtnEligible=" + eligible
                    + ", mNtnEligibilityHysteresisTimedOut=" + mNtnEligibilityHysteresisTimedOut);
            if (satelliteAllowed && eligible && mNtnEligibilityHysteresisTimedOut) {
                updateLastNotifiedNtnEligibilityAndNotify(true);
                mNtnEligibilityHysteresisTimedOut = false;
            }
        }
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void registerForSatelliteCommunicationAllowedStateChanged() {
        if (mRegisteredForSatelliteCommunicationAllowedStateChanged.get()) {
@@ -7930,6 +7857,7 @@ public class SatelliteController extends Handler {
                    synchronized (mSatelliteAccessConfigLock) {
                        mSatelliteAccessAllowed = isAllowed;
                    }
                    evaluateCarrierRoamingNtnEligibilityChange();
                }

                @Override
+2 −39
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ROAMING_P2P_S
import static android.telephony.CarrierConfigManager.KEY_SATELLITE_ROAMING_TURN_OFF_SESSION_FOR_EMERGENCY_CALL_BOOL;
import static android.telephony.CarrierConfigManager.SATELLITE_DATA_SUPPORT_ALL;
import static android.telephony.CarrierConfigManager.SATELLITE_DATA_SUPPORT_BANDWIDTH_CONSTRAINED;
import static android.telephony.CarrierConfigManager.SATELLITE_DATA_SUPPORT_ONLY_RESTRICTED;
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_DATA;
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_SMS;
import static android.telephony.NetworkRegistrationInfo.SERVICE_TYPE_VOICE;
@@ -169,7 +168,6 @@ import android.telephony.satellite.ISatelliteSupportedStateCallback;
import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback;
import android.telephony.satellite.NtnSignalStrength;
import android.telephony.satellite.SatelliteAccessConfiguration;
import android.telephony.satellite.SatelliteCapabilities;
import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteInfo;
@@ -4259,6 +4257,7 @@ public class SatelliteControllerTest extends TelephonyTest {
            );
        }
        mSatelliteControllerUT.setSatellitePhone(1);
        mSatelliteControllerUT.setIsSatelliteAllowedState(true);
        processAllMessages();

        assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
@@ -4326,6 +4325,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        mSatelliteControllerUT.setSatellitePhone(1);
        mSatelliteControllerUT.isSatelliteAllowedCallback = null;
        setUpResponseForRequestIsSatelliteSupported(true, SATELLITE_RESULT_SUCCESS);
        mSatelliteControllerUT.setIsSatelliteAllowedState(true);
        processAllMessages();
        mSatelliteControllerUT.elapsedRealtime = 0;
        assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
@@ -4337,10 +4337,6 @@ public class SatelliteControllerTest extends TelephonyTest {
        mSatelliteControllerUT.elapsedRealtime = 2 * 60 * 1000;
        moveTimeForward(2 * 60 * 1000);
        processAllMessages();
        assertNotNull(mSatelliteControllerUT.isSatelliteAllowedCallback);

        mSatelliteControllerUT.isSatelliteAllowedCallback.onResult(true);
        processAllMessages();
        assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
        verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
        verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean());
@@ -4354,31 +4350,6 @@ public class SatelliteControllerTest extends TelephonyTest {
        assertFalse(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
        verify(mPhone, times(1)).notifyCarrierRoamingNtnEligibleStateChanged(eq(false));
        verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean());

        // isSatelliteAllowedCallback.onError() returns error
        when(mServiceState.getState()).thenReturn(ServiceState.STATE_OUT_OF_SERVICE);
        sendServiceStateChangedEvent();
        processAllMessages();
        mSatelliteControllerUT.elapsedRealtime = 0;
        assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
        verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
        verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean());
        clearInvocations(mPhone);

        // 2 minutes later and hysteresis timeout is 1 minute
        mSatelliteControllerUT.elapsedRealtime = 2 * 60 * 1000;
        moveTimeForward(2 * 60 * 1000);
        processAllMessages();
        assertNotNull(mSatelliteControllerUT.isSatelliteAllowedCallback);

        mSatelliteControllerUT.isSatelliteAllowedCallback.onError(new SatelliteException(
                SATELLITE_RESULT_ERROR));
        processAllMessages();
        assertTrue(mSatelliteControllerUT.isCarrierRoamingNtnEligible(mPhone));
        verify(mPhone, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(eq(true));
        verify(mPhone2, times(0)).notifyCarrierRoamingNtnEligibleStateChanged(anyBoolean());
        verify(mMockNotificationManager, times(2)).cancelAsUser(anyString(), anyInt(),
                any());
    }

    @Test
@@ -6255,14 +6226,6 @@ public class SatelliteControllerTest extends TelephonyTest {
            }
        }

        @Override
        protected void requestIsSatelliteCommunicationAllowedForCurrentLocation(
                @NonNull OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> callback) {
            logd("requestIsSatelliteCommunicationAllowedForCurrentLocation: callback="
                    + callback);
            isSatelliteAllowedCallback = callback;
        }

        @Override
        protected boolean isSubscriptionProvisioned(int subId) {
            synchronized (mSatellitePhoneLock) {