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

Commit e1c268a2 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Change boolean to AtomicBoolean

Following variables are updated to AtomicBoolean:
- mWaitingForRadioDisabled
- mWaitingForDisableSatelliteModemResponse
- mWaitingForSatelliteModemOff
- mLastNotifiedNtnEligibility
- mChangeIntentComponent
- mIsNotificationShowing
- mSatelliteAccessAllowed
- mOverriddenDisableSatelliteWhileEnableInProgressSupported

Bug: 409608013
Test: atest
Flag: com.android.internal.telephony.flags.satellite_improve_multi_thread_design
Change-Id: I25e9c7cb33111d052872644e1e33de99bf408ae7
parent 8313a370
Loading
Loading
Loading
Loading
+77 −96
Original line number Diff line number Diff line
@@ -403,6 +403,24 @@ public class SatelliteController extends Handler {
    @SatelliteManager.SatelliteModemState
    private AtomicInteger mSatelliteModemState = new AtomicInteger(
            SatelliteManager.SATELLITE_MODEM_STATE_UNKNOWN);
    /** Flag to indicate that satellite is enabled successfully
     * and waiting for all the radios to be disabled so that success can be sent to callback
     */
    private AtomicBoolean mWaitingForRadioDisabled = new AtomicBoolean(false);
    private AtomicBoolean mWaitingForDisableSatelliteModemResponse = new AtomicBoolean(false);
    private AtomicBoolean mWaitingForSatelliteModemOff = new AtomicBoolean(false);
    /**
     * Boolean set to {@code true} when device is eligible to connect to carrier roaming
     * non-terrestrial network else set to {@code false}.
     */
    private AtomicBoolean mLastNotifiedNtnEligibility = null;
    // For satellite CTS test which to configure intent component with the necessary values.
    private AtomicBoolean mChangeIntentComponent = new AtomicBoolean(false);
    private AtomicBoolean mIsNotificationShowing = new AtomicBoolean(false);
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected AtomicBoolean mSatelliteAccessAllowed = new AtomicBoolean(false);
    private AtomicBoolean mOverrideNtnEligibility;
    private AtomicBoolean mOverriddenDisableSatelliteWhileEnableInProgressSupported = null;

    private final Object mSatelliteEnabledRequestLock = new Object();
    /* This variable is used to store the first enable request that framework has received in the
@@ -419,15 +437,6 @@ public class SatelliteController extends Handler {
     */
    @GuardedBy("mSatelliteEnabledRequestLock")
    private RequestSatelliteEnabledArgument mSatelliteEnableAttributesUpdateRequest = null;
    /** Flag to indicate that satellite is enabled successfully
     * and waiting for all the radios to be disabled so that success can be sent to callback
     */
    @GuardedBy("mSatelliteEnabledRequestLock")
    private boolean mWaitingForRadioDisabled = false;
    @GuardedBy("mSatelliteEnabledRequestLock")
    private boolean mWaitingForDisableSatelliteModemResponse = false;
    @GuardedBy("mSatelliteEnabledRequestLock")
    private boolean mWaitingForSatelliteModemOff = false;

    private final AtomicBoolean mRegisteredForPendingDatagramCountWithSatelliteService =
            new AtomicBoolean(false);
@@ -552,15 +561,6 @@ public class SatelliteController extends Handler {
    @GuardedBy("mSatelliteConnectedLock")
    @NonNull private final SparseBooleanArray mInitialized = new SparseBooleanArray();

    /**
     * Boolean set to {@code true} when device is eligible to connect to carrier roaming
     * non-terrestrial network else set to {@code false}.
     */
    @GuardedBy("mSatellitePhoneLock")
    private Boolean mLastNotifiedNtnEligibility = null;
    @GuardedBy("mSatellitePhoneLock")
    private boolean mCheckingAccessRestrictionInProgress = false;

    @GuardedBy("mSatelliteConnectedLock")
    @NonNull private final Map<Integer, CarrierRoamingSatelliteSessionStats>
            mCarrierRoamingSatelliteSessionStatsMap = new HashMap<>();
@@ -684,23 +684,15 @@ public class SatelliteController extends Handler {
    // This is used for testing only. Context#getSystemService is a final API and cannot be
    // mocked. Using this to inject a mock SubscriptionManager to work around this limitation.
    private SubscriptionManager mInjectSubscriptionManager = null;

    // For satellite CTS test which to configure intent component with the necessary values.
    private boolean mChangeIntentComponent = false;
    private String mConfigSatelliteGatewayServicePackage = "";
    private String mConfigSatelliteCarrierRoamingEsosProvisionedClass = "";

    private boolean mIsNotificationShowing = false;
    private static final String OPEN_MESSAGE_BUTTON = "open_message_button";
    private static final String HOW_IT_WORKS_BUTTON = "how_it_works_button";
    private static final String ACTION_NOTIFICATION_CLICK = "action_notification_click";
    private static final String ACTION_NOTIFICATION_DISMISS = "action_notification_dismiss";
    private AtomicBoolean mOverrideNtnEligibility;
    private String mDefaultSmsPackageName = "";
    private String mSatelliteGatewayServicePackageName = "";
    private String mOverriddenSatelliteGatewayServicePackageName = "";
    private Boolean mOverriddenDisableSatelliteWhileEnableInProgressSupported = null;


    private final Object mCarrierRoamingNtnAllSatellitePlmnSetLock = new Object();
    @GuardedBy("mCarrierRoamingNtnAllSatellitePlmnSetLock")
@@ -773,9 +765,6 @@ public class SatelliteController extends Handler {
    @GuardedBy("mSatelliteAccessConfigLock")
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected List<Integer> mCurrentLocationTagIds = new ArrayList();
    @GuardedBy("mSatelliteAccessConfigLock")
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected boolean mSatelliteAccessAllowed = false;

    public static final int RESULT_RECEIVER_COUNT_ANOMALY_THRESHOLD = 500;
    protected final Object mResultReceiverTotalCountLock = new Object();
@@ -1517,10 +1506,8 @@ public class SatelliteController extends Handler {

                if (error == SATELLITE_RESULT_SUCCESS) {
                    if (argument.enableSatellite) {
                        synchronized (mSatelliteEnabledRequestLock) {
                            mWaitingForRadioDisabled = true;
                        mWaitingForRadioDisabled.set(true);
                        setDemoModeEnabled(argument.enableDemoMode);
                        }
                        // TODO (b/361139260): Start a timer to wait for other radios off
                        setSettingsKeyForSatelliteMode(SATELLITE_MODE_ENABLED_TRUE);
                        setSettingsKeyToAllowDeviceRotation(SATELLITE_MODE_ENABLED_TRUE);
@@ -1535,9 +1522,7 @@ public class SatelliteController extends Handler {
                            moveSatelliteToOffStateAndCleanUpResources(SATELLITE_RESULT_SUCCESS);
                        }

                        synchronized (mSatelliteEnabledRequestLock) {
                            mWaitingForDisableSatelliteModemResponse = false;
                        }
                        mWaitingForDisableSatelliteModemResponse.set(false);
                    }
                    // Request NTN signal strength report when satellite enabled or disabled done.
                    mLatestRequestedStateForNtnSignalStrengthReport.set(argument.enableSatellite);
@@ -1586,9 +1571,7 @@ public class SatelliteController extends Handler {
                    mSessionProcessingTimeStamp = 0;
                    mControllerMetricsStats.onSatelliteDisabled();
                    handlePersistentLoggingOnSessionEnd(mIsEmergency.get());
                    synchronized (mSatelliteEnabledRequestLock) {
                        mWaitingForDisableSatelliteModemResponse = false;
                    }
                    mWaitingForDisableSatelliteModemResponse.set(false);
                }
                break;
            }
@@ -2254,9 +2237,7 @@ public class SatelliteController extends Handler {
                int selectedSatelliteSubId = getSelectedSatelliteSubId();
                Phone phone = SatelliteServiceUtils.getPhone(selectedSatelliteSubId);
                if (eligible) {
                    synchronized (mSatellitePhoneLock) {
                        mLastNotifiedNtnEligibility = eligible;
                    }
                    setLastNotifiedNtnEligibility(eligible);
                    phone.notifyCarrierRoamingNtnEligibleStateChanged(eligible);
                }
                break;
@@ -2810,7 +2791,7 @@ public class SatelliteController extends Handler {

    private boolean isDisableSatelliteWhileEnableInProgressSupported() {
        if (mOverriddenDisableSatelliteWhileEnableInProgressSupported != null) {
            return mOverriddenDisableSatelliteWhileEnableInProgressSupported;
            return mOverriddenDisableSatelliteWhileEnableInProgressSupported.get();
        }
        return mContext.getResources().getBoolean(
            R.bool.config_support_disable_satellite_while_enable_in_progress);
@@ -4083,7 +4064,8 @@ public class SatelliteController extends Handler {
        if (reset) {
            mOverriddenDisableSatelliteWhileEnableInProgressSupported = null;
        } else {
            mOverriddenDisableSatelliteWhileEnableInProgressSupported = supported;
            mOverriddenDisableSatelliteWhileEnableInProgressSupported =
                    new AtomicBoolean(supported);
        }
        return true;
    }
@@ -5159,10 +5141,8 @@ public class SatelliteController extends Handler {
         * modem is not in OFF state.
         */
        if (!argument.enableSatellite && mSatelliteModemInterface.isSatelliteServiceSupported()) {
            synchronized (mSatelliteEnabledRequestLock) {
                mWaitingForDisableSatelliteModemResponse = true;
                if (!isSatelliteDisabled()) mWaitingForSatelliteModemOff = true;
            }
            mWaitingForDisableSatelliteModemResponse.set(true);
            if (!isSatelliteDisabled()) mWaitingForSatelliteModemOff.set(true);
        }

        Message onCompleted = obtainMessage(EVENT_SET_SATELLITE_ENABLED_DONE, request);
@@ -5470,10 +5450,7 @@ public class SatelliteController extends Handler {
                notifyModemStateChangedToSessionController(
                        SatelliteManager.SATELLITE_MODEM_STATE_OFF);
            }

            synchronized (mSatelliteEnabledRequestLock) {
                mWaitingForSatelliteModemOff = false;
            }
            mWaitingForSatelliteModemOff.set(false);
        } else {
            if (isSatelliteEnabledOrBeingEnabled() || isSatelliteBeingDisabled()) {
                notifyModemStateChangedToSessionController(state);
@@ -5756,7 +5733,7 @@ public class SatelliteController extends Handler {
        plogd("evaluateToSendSatelliteEnabledSuccess");
        synchronized (mSatelliteEnabledRequestLock) {
            if (areAllRadiosDisabled() && (mSatelliteEnabledRequest != null)
                    && mWaitingForRadioDisabled) {
                    && mWaitingForRadioDisabled.get()) {
                plogd("Sending success to callback that sent enable satellite request");
                setIsSatelliteEnabled(mSatelliteEnabledRequest.enableSatellite);
                mSatelliteEnabledRequest.callback.accept(SATELLITE_RESULT_SUCCESS);
@@ -5772,7 +5749,7 @@ public class SatelliteController extends Handler {
                    mPointingAppController.startPointingUI(true, mIsDemoModeEnabled.get(), false);
                }
                mSatelliteEnabledRequest = null;
                mWaitingForRadioDisabled = false;
                mWaitingForRadioDisabled.set(false);

                if (mSatelliteEnableAttributesUpdateRequest != null) {
                    sendRequestAsync(CMD_UPDATE_SATELLITE_ENABLE_ATTRIBUTES,
@@ -5791,7 +5768,7 @@ public class SatelliteController extends Handler {
        plogd("resetSatelliteEnabledRequest");
        synchronized (mSatelliteEnabledRequestLock) {
            mSatelliteEnabledRequest = null;
            mWaitingForRadioDisabled = false;
            mWaitingForRadioDisabled.set(false);
        }
    }

@@ -5799,8 +5776,8 @@ public class SatelliteController extends Handler {
        plogd("resetSatelliteDisabledRequest");
        synchronized (mSatelliteEnabledRequestLock) {
            mSatelliteDisabledRequest = null;
            mWaitingForDisableSatelliteModemResponse = false;
            mWaitingForSatelliteModemOff = false;
            mWaitingForDisableSatelliteModemResponse.set(false);
            mWaitingForSatelliteModemOff.set(false);
        }
    }

@@ -6818,7 +6795,7 @@ public class SatelliteController extends Handler {
                phone.notifyCarrierRoamingNtnModeChanged(currNtnMode);
                updateLastNotifiedCarrierRoamingNtnSignalStrengthAndNotify(phone);
                logCarrierRoamingSatelliteSessionStats(phone, lastNotifiedNtnMode, currNtnMode);
                if(mIsNotificationShowing && !currNtnMode) {
                if (mIsNotificationShowing.get() && !currNtnMode) {
                    dismissSatelliteNotification();
                }
            }
@@ -6932,11 +6909,10 @@ public class SatelliteController extends Handler {
            return false;
        }

        synchronized (mSatellitePhoneLock) {
            if (mLastNotifiedNtnEligibility != null && mLastNotifiedNtnEligibility) {
        Boolean lastNotifiedNtnEligibility = getLastNotifiedNtnEligibility();
        if (lastNotifiedNtnEligibility != null && lastNotifiedNtnEligibility) {
            return false;
        }
        }

        return true;
    }
@@ -6984,9 +6960,10 @@ public class SatelliteController extends Handler {
        synchronized (mSatellitePhoneLock) {
            plogd("notifyNtnEligibility: phoneId=" + satellitePhone.getPhoneId()
                    + " currentNtnEligibility=" + currentNtnEligibility);
            if (mLastNotifiedNtnEligibility == null
                    || mLastNotifiedNtnEligibility != currentNtnEligibility) {
                mLastNotifiedNtnEligibility = currentNtnEligibility;
            Boolean lastNotifiedNtnEligibility = getLastNotifiedNtnEligibility();
            if (lastNotifiedNtnEligibility == null
                    || lastNotifiedNtnEligibility != currentNtnEligibility) {
                setLastNotifiedNtnEligibility(currentNtnEligibility);
                satellitePhone.notifyCarrierRoamingNtnEligibleStateChanged(currentNtnEligibility);
                updateSatelliteSystemNotification(selectedSatelliteSubId,
                        CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_MANUAL,
@@ -7005,12 +6982,29 @@ public class SatelliteController extends Handler {
            return false;
        }

        synchronized (mSatellitePhoneLock) {
            plogd("getLastNotifiedNtnEligibility: return " + mLastNotifiedNtnEligibility);
            return mLastNotifiedNtnEligibility;
        Boolean lastNotifiedNtnEligibility = getLastNotifiedNtnEligibility();
        plogd("getLastNotifiedNtnEligibility: return " + lastNotifiedNtnEligibility);
        if (lastNotifiedNtnEligibility == null) {
            return false;
        }
        return lastNotifiedNtnEligibility;
    }

    private void setLastNotifiedNtnEligibility(boolean eligibility) {
        if (mLastNotifiedNtnEligibility == null) {
            mLastNotifiedNtnEligibility = new AtomicBoolean(eligibility);
        } else {
            mLastNotifiedNtnEligibility.set(eligibility);
        }
    }

    private Boolean getLastNotifiedNtnEligibility() {
        if (mLastNotifiedNtnEligibility == null) {
            return null;
        }
        return mLastNotifiedNtnEligibility.get();
    }

    private long getSatelliteConnectionHysteresisTimeMillis(int subId) {
        PersistableBundle config = getPersistableBundle(subId);
        return (config.getInt(
@@ -7394,7 +7388,7 @@ public class SatelliteController extends Handler {
        if (DEBUG) {
            logd("determineAutoConnectSystemNotification: isNtn.first = " + isNtn.first
                    + " IsNotiToShow = " + !suppressSatelliteNotification
                    + " mIsNotificationShowing = " + mIsNotificationShowing);
                    + " mIsNotificationShowing = " + mIsNotificationShowing.get());
        }
        if (isNtn.first) {
            if (!suppressSatelliteNotification && getCarrierRoamingNtnConnectType(isNtn.second)
@@ -7403,7 +7397,7 @@ public class SatelliteController extends Handler {
                        CarrierConfigManager.CARRIER_ROAMING_NTN_CONNECT_AUTOMATIC,
                        /*visible*/ true);
            }
        } else if (mIsNotificationShowing
        } else if (mIsNotificationShowing.get()
                && !isSatelliteConnectedViaCarrierWithinHysteresisTime().first) {
            // Dismiss the notification if it is still displaying.
            dismissSatelliteNotification();
@@ -7411,7 +7405,7 @@ public class SatelliteController extends Handler {
    }

    private void dismissSatelliteNotification() {
        mIsNotificationShowing = false;
        mIsNotificationShowing.set(false);
        updateSatelliteSystemNotification(-1, -1,/*visible*/ false);
    }

@@ -7554,7 +7548,7 @@ public class SatelliteController extends Handler {
        mContext.registerReceiver(mNotificationInteractionBroadcastReceiver, filter,
                Context.RECEIVER_EXPORTED);

        mIsNotificationShowing = true;
        mIsNotificationShowing.set(true);
        mCarrierRoamingSatelliteControllerStats.reportCountOfSatelliteNotificationDisplayed(subId);
        mCarrierRoamingSatelliteControllerStats.reportCarrierId(getSatelliteCarrierId());
        mSessionMetricsStats.addCountOfSatelliteNotificationDisplayed();
@@ -8867,9 +8861,7 @@ public class SatelliteController extends Handler {
                    if (mFeatureFlags.satelliteExitP2pSessionOutsideGeofence()) {
                        handleSatelliteAccessAllowedStateChanged(isAllowed);
                    } else {
                        synchronized (mSatelliteAccessConfigLock) {
                            mSatelliteAccessAllowed = isAllowed;
                        }
                        mSatelliteAccessAllowed.set(isAllowed);
                        evaluateESOSProfilesPrioritization();
                        evaluateCarrierRoamingNtnEligibilityChange();
                        handleCarrierRoamingNtnAvailableServicesChanged();
@@ -8900,10 +8892,7 @@ public class SatelliteController extends Handler {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public void handleSatelliteAccessAllowedStateChanged(boolean isAllowed) {
        plogd("handleSatelliteAccessAllowedStateChanged: isAllowed=" + isAllowed);
        synchronized (mSatelliteAccessConfigLock) {
            mSatelliteAccessAllowed = isAllowed;
        }

        mSatelliteAccessAllowed.set(isAllowed);
        evaluateESOSProfilesPrioritization();
        selectBindingSatelliteSubscription(false);
        evaluateCarrierRoamingNtnEligibilityChange();
@@ -9035,9 +9024,9 @@ public class SatelliteController extends Handler {
        logd("setSatelliteSubscriberIdListChangedIntentComponent:" + name);

        if (name.contains("/")) {
            mChangeIntentComponent = true;
            mChangeIntentComponent.set(true);
        } else {
            mChangeIntentComponent = false;
            mChangeIntentComponent.set(false);
            return true;
        }
        boolean result = true;
@@ -9097,7 +9086,7 @@ public class SatelliteController extends Handler {

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected String getConfigSatelliteGatewayServicePackage() {
        if (!mChangeIntentComponent) {
        if (!mChangeIntentComponent.get()) {
            return getStringFromOverlayConfig(
                    R.string.config_satellite_gateway_service_package);
        }
@@ -9106,7 +9095,7 @@ public class SatelliteController extends Handler {
    }

    private String getConfigSatelliteCarrierRoamingEsosProvisionedClass() {
        if (!mChangeIntentComponent) {
        if (!mChangeIntentComponent.get()) {
            return getStringFromOverlayConfig(
                    R.string.config_satellite_carrier_roaming_esos_provisioned_class);
        }
@@ -9142,9 +9131,7 @@ public class SatelliteController extends Handler {
    private boolean shouldStopWaitForEnableResponseTimer(
            @NonNull RequestSatelliteEnabledArgument argument) {
        if (argument.enableSatellite) return true;
        synchronized (mSatelliteEnabledRequestLock) {
            return !mWaitingForSatelliteModemOff;
        }
        return !mWaitingForSatelliteModemOff.get();
    }

    /**
@@ -9576,9 +9563,7 @@ public class SatelliteController extends Handler {
    }

    private boolean isWaitingForSatelliteModemOff() {
        synchronized (mSatelliteEnabledRequestLock) {
            return mWaitingForSatelliteModemOff;
        }
        return mWaitingForSatelliteModemOff.get();
    }

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
@@ -9599,15 +9584,11 @@ public class SatelliteController extends Handler {
    }

    private boolean isWaitingForDisableSatelliteModemResponse() {
        synchronized (mSatelliteEnabledRequestLock) {
            return mWaitingForDisableSatelliteModemResponse;
        }
        return mWaitingForDisableSatelliteModemResponse.get();
    }

    private boolean isSatelliteAccessAllowedAtCurrentLocation() {
        synchronized (mSatelliteAccessConfigLock) {
            return mSatelliteAccessAllowed;
        }
        return mSatelliteAccessAllowed.get();
    }

    private void setIsSatelliteEnabled(boolean enabled) {
+1 −3
Original line number Diff line number Diff line
@@ -6159,9 +6159,7 @@ public class SatelliteControllerTest extends TelephonyTest {
        }

        public void setIsSatelliteAllowedState(boolean isAllowed) {
            synchronized(mSatelliteAccessConfigLock) {
                mSatelliteAccessAllowed = isAllowed;
            }
            mSatelliteAccessAllowed = new AtomicBoolean(isAllowed);
        }

        public void setCallOnlySuperMethod() {