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

Commit d7db3050 authored by Thomas Nguyen's avatar Thomas Nguyen
Browse files

Support satellite states overriding for CTS test

- Set SatelliteAccessAllowedForSubscriptions
- SetSatelliteTnScanningSupport

Change-Id: I29ea89f53b287e43561e4c9ec015d8c7a78b2b8e
Flag: EXEMPT bugfix
Bug: 397980611 
Test: System test and SatelliteManagerTestOnMockService
parent 4d6fd152
Loading
Loading
Loading
Loading
+141 −39
Original line number Diff line number Diff line
@@ -317,6 +317,8 @@ public class SatelliteController extends Handler {
    private static final int EVENT_SELECTED_NB_IOT_SATELLITE_SUBSCRIPTION_CHANGED = 60;
    private static final int CMD_EVALUATE_CARRIER_ROAMING_NTN_ELIGIBILITY_CHANGE = 61;
    private static final int CMD_LOCATION_SERVICE_STATE_CHANGED = 62;
    protected static final int
        EVENT_WAIT_FOR_UPDATE_SYSTEM_SELECTION_CHANNELS_RESPONSE_TIMED_OUT = 63;

    @NonNull private static SatelliteController sInstance;
    @NonNull private final Context mContext;
@@ -606,6 +608,7 @@ public class SatelliteController extends Handler {
    SparseArray<Map<String, Integer>> mEntitlementVoiceServicePolicyMapPerCarrier =
            new SparseArray<>();
    private static AtomicLong sNextSatelliteEnableRequestId = new AtomicLong(0);
    private static AtomicLong sNextSystemSelectionChannelsUpdateRequestId = new AtomicLong(0);
    // key : subscriberId, value : provisioned or not.
    @GuardedBy("mSatelliteTokenProvisionedLock")
    private Map<String, Boolean> mProvisionedSubscriberId = new HashMap<>();
@@ -658,6 +661,7 @@ public class SatelliteController extends Handler {
    private final RegistrantList mSatelliteSubIdChangedRegistrants = new RegistrantList();
    private final BTWifiNFCStateReceiver mBTWifiNFCSateReceiver;
    private final UwbAdapterStateCallback mUwbAdapterStateCallback;
    private final List<Integer> mCtsSatelliteAccessAllowedSubIds = new ArrayList<>();

    private long mSessionStartTimeStamp;
    private long mSessionProcessingTimeStamp;
@@ -1343,14 +1347,17 @@ public class SatelliteController extends Handler {
    }

    private static final class UpdateSystemSelectionChannelsArgument {
        @NonNull List<SystemSelectionSpecifier> mSystemSelectionSpecifiers;
        @NonNull ResultReceiver mResult;
        public @NonNull List<SystemSelectionSpecifier> systemSelectionSpecifiers;
        public @NonNull ResultReceiver result;
        public long requestId;

        UpdateSystemSelectionChannelsArgument(
                @NonNull List<SystemSelectionSpecifier> systemSelectionSpecifiers,
                @NonNull ResultReceiver result) {
            this.mSystemSelectionSpecifiers = systemSelectionSpecifiers;
            this.mResult = result;
            this.systemSelectionSpecifiers = systemSelectionSpecifiers;
            this.result = result;
            this.requestId = sNextSystemSelectionChannelsUpdateRequestId.getAndUpdate(
                    n -> ((n + 1) % Long.MAX_VALUE));
        }
    }

@@ -2179,11 +2186,13 @@ public class SatelliteController extends Handler {
            case CMD_UPDATE_SYSTEM_SELECTION_CHANNELS: {
                plogd("CMD_UPDATE_SYSTEM_SELECTION_CHANNELS");
                request = (SatelliteControllerHandlerRequest) msg.obj;
                onCompleted = obtainMessage(EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE, request);
                onCompleted =
                    obtainMessage(EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE, request);
                UpdateSystemSelectionChannelsArgument argument =
                        (UpdateSystemSelectionChannelsArgument) request.argument;
                mSatelliteModemInterface.updateSystemSelectionChannels(
                        ((UpdateSystemSelectionChannelsArgument) (request.argument))
                                .mSystemSelectionSpecifiers,
                        onCompleted);
                        argument.systemSelectionSpecifiers, onCompleted);
                startWaitForUpdateSystemSelectionChannelsResponseTimer(argument);
                break;
            }

@@ -2193,8 +2202,25 @@ public class SatelliteController extends Handler {
                int error =  SatelliteServiceUtils.getSatelliteError(
                        ar, "updateSystemSelectionChannel");
                plogd("EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE = " + error);
                ((UpdateSystemSelectionChannelsArgument) (request.argument)).mResult.send(error,
                        null);
                UpdateSystemSelectionChannelsArgument argument =
                        (UpdateSystemSelectionChannelsArgument) request.argument;
                if (shouldProcessEventUpdateSystemSelectionChannelsDone(argument)) {
                    argument.result.send(error, null);
                    stopWaitForUpdateSystemSelectionChannelsResponseTimer(argument);
                } else {
                    plogd("EVENT_UPDATE_SYSTEM_SELECTION_CHANNELS_DONE: the timer of "
                              + "the request ID " + argument.requestId
                              + " has already expired.");
                }
                break;
            }

            case EVENT_WAIT_FOR_UPDATE_SYSTEM_SELECTION_CHANNELS_RESPONSE_TIMED_OUT: {
                UpdateSystemSelectionChannelsArgument argument =
                        (UpdateSystemSelectionChannelsArgument) msg.obj;
                argument.result.send(SATELLITE_RESULT_MODEM_TIMEOUT, null);
                plogd("Timed out to wait for response of the system selection channels"
                          + " update request ID " + argument.requestId);
                break;
            }

@@ -3437,12 +3463,6 @@ public class SatelliteController extends Handler {
        synchronized (mIsSatelliteSupportedLock) {
            mIsSatelliteSupported = null;
        }
        synchronized (mDeviceProvisionLock) {
            mIsDeviceProvisioned = Optional.ofNullable(provisioned)
                    .filter(s -> s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false"))
                    .map(s -> s.equalsIgnoreCase("true"))
                    .orElse(null);
        }
        synchronized (mIsSatelliteEnabledLock) {
            mIsSatelliteEnabled = null;
        }
@@ -3469,6 +3489,25 @@ public class SatelliteController extends Handler {
        return mSatelliteSessionController.setSatelliteListeningTimeoutDuration(timeoutMillis);
    }

    /**
     * This API can be used by only CTS to override TN scanning support.
     *
     * @param concurrentTnScanningSupported Whether concurrent TN scanning is supported.
     * @param tnScanningDuringSatelliteSessionAllowed Whether TN scanning is allowed during
     * a satellite session.
     * @return {@code true} if the TN scanning support is set successfully,
     * {@code false} otherwise.
     */
    public boolean setTnScanningSupport(boolean reset, boolean concurrentTnScanningSupported,
        boolean tnScanningDuringSatelliteSessionAllowed) {
        if (mSatelliteSessionController == null) {
            ploge("setTnScanningSupport: mSatelliteSessionController is not initialized yet");
            return false;
        }
        return mSatelliteSessionController.setTnScanningSupport(reset,
                concurrentTnScanningSupported, tnScanningDuringSatelliteSessionAllowed);
    }

    /**
     * This API can be used by only CTS to control ingoring cellular service state event.
     *
@@ -4401,11 +4440,8 @@ public class SatelliteController extends Handler {
        if (result == SATELLITE_RESULT_SUCCESS
                || result == SATELLITE_RESULT_REQUEST_NOT_SUPPORTED) {
            persistOemEnabledSatelliteProvisionStatus(true);
            synchronized (mDeviceProvisionLock) {
                mIsDeviceProvisioned = true;
            }
            callback.accept(SATELLITE_RESULT_SUCCESS);
            handleEventSatelliteProvisionStateChanged(true);
            updateCachedDeviceProvisionStatus();
        } else {
            callback.accept(result);
        }
@@ -4430,13 +4466,10 @@ public class SatelliteController extends Handler {
        if (result == SATELLITE_RESULT_SUCCESS
                || result == SATELLITE_RESULT_REQUEST_NOT_SUPPORTED) {
            persistOemEnabledSatelliteProvisionStatus(false);
            synchronized (mDeviceProvisionLock) {
                mIsDeviceProvisioned = false;
            }
            if (arg.callback != null) {
                arg.callback.accept(SATELLITE_RESULT_SUCCESS);
            }
            handleEventSatelliteProvisionStateChanged(false);
            updateCachedDeviceProvisionStatus();
        } else if (arg.callback != null) {
            arg.callback.accept(result);
        }
@@ -4730,23 +4763,13 @@ public class SatelliteController extends Handler {
        }
    }

    private void handleEventSatelliteProvisionStateChanged(boolean provisioned) {
        plogd("handleSatelliteProvisionStateChangedEvent: provisioned=" + provisioned);

        synchronized (mDeviceProvisionLock) {
            persistOemEnabledSatelliteProvisionStatus(provisioned);
            mIsDeviceProvisioned = provisioned;
        }
        notifyDeviceProvisionStateChanged(provisioned);
    }

    private void notifyDeviceProvisionStateChanged(boolean provisioned) {
        List<ISatelliteProvisionStateCallback> deadCallersList = new ArrayList<>();
        mSatelliteProvisionStateChangedListeners.values().forEach(listener -> {
            try {
                listener.onSatelliteProvisionStateChanged(provisioned);
            } catch (RemoteException e) {
                plogd("handleSatelliteProvisionStateChangedEvent RemoteException: " + e);
                plogd("notifyDeviceProvisionStateChanged RemoteException: " + e);
                deadCallersList.add(listener);
            }
        });
@@ -4806,7 +4829,7 @@ public class SatelliteController extends Handler {
                getPrioritizedSatelliteSubscriberProvisionStatusList();
        plogd("handleEventSatelliteSubscriptionProvisionStateChanged: " + informList);
        notifySatelliteSubscriptionProvisionStateChanged(informList);
        updateDeviceProvisionStatus();
        updateCachedDeviceProvisionStatus();
        // Report updated provisioned status to metrics.
        synchronized (mSatelliteTokenProvisionedLock) {
            boolean isProvisioned = !mProvisionedSubscriberId.isEmpty()
@@ -4817,9 +4840,9 @@ public class SatelliteController extends Handler {
        evaluateCarrierRoamingNtnEligibilityChange();
    }

    private void updateDeviceProvisionStatus() {
    private void updateCachedDeviceProvisionStatus() {
        boolean isProvisioned = getPersistedDeviceProvisionStatus();
        plogd("updateDeviceProvisionStatus: isProvisioned=" + isProvisioned);
        plogd("updateCachedDeviceProvisionStatus: isProvisioned=" + isProvisioned);
        synchronized (mDeviceProvisionLock) {
            if (mIsDeviceProvisioned == null || mIsDeviceProvisioned != isProvisioned) {
                mIsDeviceProvisioned = isProvisioned;
@@ -5574,7 +5597,7 @@ public class SatelliteController extends Handler {
            }
        }
        // Need to update the provision status of the device
        updateDeviceProvisionStatus();
        updateCachedDeviceProvisionStatus();
    }

    @NonNull
@@ -6427,6 +6450,45 @@ public class SatelliteController extends Handler {
        }
    }

    private void startWaitForUpdateSystemSelectionChannelsResponseTimer(
            @NonNull UpdateSystemSelectionChannelsArgument argument) {
        synchronized (mSatelliteEnabledRequestLock) {
            if (hasMessages(
                    EVENT_WAIT_FOR_UPDATE_SYSTEM_SELECTION_CHANNELS_RESPONSE_TIMED_OUT, argument)) {
                plogd("WaitForUpdateSystemSelectionChannelsResponseTimer of request ID "
                        + argument.requestId + " was already started");
                return;
            }
            plogd("Start timer to wait for response of the system selection channels update request"
                    + " ID=" + argument.requestId + ", mWaitTimeForSatelliteEnablingResponse="
                    + mWaitTimeForSatelliteEnablingResponse);
            sendMessageDelayed(
                obtainMessage(EVENT_WAIT_FOR_UPDATE_SYSTEM_SELECTION_CHANNELS_RESPONSE_TIMED_OUT,
                    argument), mWaitTimeForSatelliteEnablingResponse);
        }
    }

    private void stopWaitForUpdateSystemSelectionChannelsResponseTimer(
            @NonNull UpdateSystemSelectionChannelsArgument argument) {
        synchronized (mSatelliteEnabledRequestLock) {
            plogd("Stop timer to wait for response of the system selection channels"
                      + " update request ID=" + argument.requestId);
            removeMessages(
                EVENT_WAIT_FOR_UPDATE_SYSTEM_SELECTION_CHANNELS_RESPONSE_TIMED_OUT, argument);
        }
    }

    private boolean shouldProcessEventUpdateSystemSelectionChannelsDone(
            @NonNull UpdateSystemSelectionChannelsArgument argument) {
        synchronized (mSatelliteEnabledRequestLock) {
            if (hasMessages(
                    EVENT_WAIT_FOR_UPDATE_SYSTEM_SELECTION_CHANNELS_RESPONSE_TIMED_OUT, argument)) {
                return true;
            }
            return false;
        }
    }

    private void startWaitForUpdateSatelliteEnableAttributesResponseTimer(
            @NonNull RequestSatelliteEnabledArgument argument) {
        synchronized (mSatelliteEnabledRequestLock) {
@@ -7552,6 +7614,11 @@ public class SatelliteController extends Handler {
            plogd("isSatelliteAvailableAtCurrentLocation: subscriptionInfo is null");
            return false;
        }
        if (mCtsSatelliteAccessAllowedSubIds.contains(info.getSubscriptionId())) {
            plogd("isSatelliteAvailableAtCurrentLocation: subscriptionId="
                      + info.getSubscriptionId() + " is allowed for CTS testing");
            return true;
        }
        if (!isSatelliteAccessAllowedAtCurrentLocation()) {
            plogd("isSatelliteAvailableAtCurrentLocation: satellite access is not allowed at " +
                    "current location");
@@ -8135,6 +8202,41 @@ public class SatelliteController extends Handler {
        return result;
    }

    /**
     * This API can be used by only CTS to override the satellite access allowed state for
     * a list of subscription IDs.
     *
     * @param subIdListStr The string representation of the list of subscription IDs,
     *                     which are numbers separated by comma.
     * @return {@code true} if the satellite access allowed state is set successfully,
     * {@code false} otherwise.
     */
    public boolean setSatelliteAccessAllowedForSubscriptions(@Nullable String subIdListStr) {
        if (!isMockModemAllowed()) {
            plogd("setSatelliteAccessAllowedForSubscriptions: mock modem not allowed");
            return false;
        }

        plogd("setSatelliteAccessAllowedForSubscriptions: subIdListStr=" + subIdListStr);
        if (subIdListStr == null) {
            mCtsSatelliteAccessAllowedSubIds.clear();
            return true;
        }

        List<Integer> subIdList = new ArrayList<>();
        for (String subIdStr : subIdListStr.split(",")) {
            try {
                subIdList.add(Integer.parseInt(subIdStr));
            } catch (NumberFormatException e) {
                plogd("setSatelliteAccessAllowedForSubscriptions: invalid subIdStr=" + subIdStr);
                return false;
            }
        }
        mCtsSatelliteAccessAllowedSubIds.clear();
        mCtsSatelliteAccessAllowedSubIds.addAll(subIdList);
        return true;
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected String getConfigSatelliteGatewayServicePackage() {
        if (!mChangeIntentComponent) {
+44 −0
Original line number Diff line number Diff line
@@ -176,6 +176,8 @@ public class SatelliteSessionController extends StateMachine {
    private long mSatelliteStayAtListeningFromReceivingMillis;
    private long mSatelliteNbIotInactivityTimeoutMillis;
    private boolean mIgnoreCellularServiceState = false;
    private Boolean mIsConcurrentTnScanningSupportedForCtsTest = null;
    private Boolean mIsTnScanningDuringSatelliteSessionAllowedForCtsTest = null;
    private final ConcurrentHashMap<IBinder, ISatelliteModemStateCallback> mListeners;
    @SatelliteManager.SatelliteModemState private int mCurrentState;
    @SatelliteManager.SatelliteModemState private int mPreviousState;
@@ -541,6 +543,37 @@ public class SatelliteSessionController extends StateMachine {
        return true;
    }

    /**
     * This API can be used by only CTS to override TN scanning support.
     *
     * @param concurrentTnScanningSupported Whether concurrent TN scanning is supported.
     * @param tnScanningDuringSatelliteSessionAllowed Whether TN scanning is allowed during
     * a satellite session.
     * @return {@code true} if the TN scanning support is set successfully,
     * {@code false} otherwise.
     */
    boolean setTnScanningSupport(boolean reset, boolean concurrentTnScanningSupported,
        boolean tnScanningDuringSatelliteSessionAllowed) {
        if (!isMockModemAllowed()) {
            ploge("setTnScanningSupport: modifying TN scanning support is not allowed");
            return false;
        }

        plogd("setTnScanningSupport: reset=" + reset
                  + ", concurrentTnScanningSupported=" + concurrentTnScanningSupported
                  + ", tnScanningDuringSatelliteSessionAllowed="
                  + tnScanningDuringSatelliteSessionAllowed);
        if (reset) {
            mIsConcurrentTnScanningSupportedForCtsTest = null;
            mIsTnScanningDuringSatelliteSessionAllowedForCtsTest = null;
        } else {
            mIsConcurrentTnScanningSupportedForCtsTest = concurrentTnScanningSupported;
            mIsTnScanningDuringSatelliteSessionAllowedForCtsTest =
                    tnScanningDuringSatelliteSessionAllowed;
        }
        return true;
    }

    /**
     * Adjusts listening timeout duration when demo mode is on
     *
@@ -2023,6 +2056,11 @@ public class SatelliteSessionController extends StateMachine {
    }

    private boolean isConcurrentTnScanningSupported() {
        if (mIsConcurrentTnScanningSupportedForCtsTest != null) {
            plogd("isConcurrentTnScanningSupported: mIsConcurrentTnScanningSupportedForCtsTest="
                    + mIsConcurrentTnScanningSupportedForCtsTest);
            return mIsConcurrentTnScanningSupportedForCtsTest;
        }
        try {
            return mContext.getResources().getBoolean(
                R.bool.config_satellite_modem_support_concurrent_tn_scanning);
@@ -2033,6 +2071,12 @@ public class SatelliteSessionController extends StateMachine {
    }

    private boolean isTnScanningAllowedDuringSatelliteSession() {
        if (mIsTnScanningDuringSatelliteSessionAllowedForCtsTest != null) {
            plogd("isTnScanningAllowedDuringSatelliteSession: "
                    + "mIsTnScanningDuringSatelliteSessionAllowedForCtsTest="
                    + mIsTnScanningDuringSatelliteSessionAllowedForCtsTest);
            return mIsTnScanningDuringSatelliteSessionAllowedForCtsTest;
        }
        try {
            return mContext.getResources().getBoolean(
                    R.bool.config_satellite_allow_tn_scanning_during_satellite_session);