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

Commit 8313a370 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Change variables to atomic variables.

Following variables are converted to atomic variables:
- mNtnSmsSupportedByMessagesApp
- mIsWifiConnected
- mHasSentBroadcast
- mSatelliteModemState

Bug: 409608013
Test: atest
Flag: com.android.internal.telephony.flags.satellite_improve_multi_thread_design
Change-Id: I86029af167c342db19cea7d960faa16fd564fa4a
parent ebb43b43
Loading
Loading
Loading
Loading
+54 −74
Original line number Diff line number Diff line
@@ -203,6 +203,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -396,6 +397,12 @@ public class SatelliteController extends Handler {
    protected AtomicBoolean mIsDeviceProvisioned = null;
    private AtomicBoolean mOverriddenIsSatelliteViaOemProvisioned = null;
    private AtomicBoolean mIgnorePlmnListFromStorage = new AtomicBoolean(false);
    private AtomicBoolean mNtnSmsSupportedByMessagesApp = null;
    private AtomicBoolean mIsWifiConnected = new AtomicBoolean(false);
    private AtomicBoolean mHasSentBroadcast = new AtomicBoolean(false);
    @SatelliteManager.SatelliteModemState
    private AtomicInteger mSatelliteModemState = new AtomicInteger(
            SatelliteManager.SATELLITE_MODEM_STATE_UNKNOWN);

    private final Object mSatelliteEnabledRequestLock = new Object();
    /* This variable is used to store the first enable request that framework has received in the
@@ -523,10 +530,8 @@ public class SatelliteController extends Handler {
    /** Key: subId, value: (key: Regional satellite config Id string, value: Integer
     * arrays of earfcns in the corresponding regions.)
     */
    @GuardedBy("mRegionalSatelliteEarfcnsLock")
    @NonNull private final Map<Integer, Map<String, Set<Integer>>>
            mRegionalSatelliteEarfcns = new HashMap<>();
    @NonNull private final Object mRegionalSatelliteEarfcnsLock = new Object();
    @NonNull private final ConcurrentHashMap<Integer, Map<String, Set<Integer>>>
            mRegionalSatelliteEarfcns = new ConcurrentHashMap<>();
    @NonNull private final FeatureFlags mFeatureFlags;
    @NonNull private final Object mSatelliteConnectedLock = new Object();
    /** Key: Subscription ID; Value: Last satellite connected time */
@@ -680,10 +685,6 @@ public class SatelliteController extends Handler {
    // mocked. Using this to inject a mock SubscriptionManager to work around this limitation.
    private SubscriptionManager mInjectSubscriptionManager = null;

    private final Object mIsWifiConnectedLock = new Object();
    @GuardedBy("mIsWifiConnectedLock")
    private boolean mIsWifiConnected = false;
    private boolean mHasSentBroadcast = false;
    // For satellite CTS test which to configure intent component with the necessary values.
    private boolean mChangeIntentComponent = false;
    private String mConfigSatelliteGatewayServicePackage = "";
@@ -700,19 +701,11 @@ public class SatelliteController extends Handler {
    private String mOverriddenSatelliteGatewayServicePackageName = "";
    private Boolean mOverriddenDisableSatelliteWhileEnableInProgressSupported = null;

    private final Object mNtnSmsSupportedByMessagesAppLock = new Object();
    @GuardedBy("mNtnSmsSupportedByMessagesAppLock")
    private Boolean mNtnSmsSupportedByMessagesApp = null;

    private final Object mCarrierRoamingNtnAllSatellitePlmnSetLock = new Object();
    @GuardedBy("mCarrierRoamingNtnAllSatellitePlmnSetLock")
    private Set<String> mCarrierRoamingNtnAllSatellitePlmnSet = null;

    private final Object mSatelliteModemStateLock = new Object();
    @GuardedBy("mSatelliteModemStateLock")
    @SatelliteManager.SatelliteModemState
    private int mSatelliteModemState = SatelliteManager.SATELLITE_MODEM_STATE_UNKNOWN;

    // Data Plan types at entitlement for the plmn allowed
    public static final int SATELLITE_DATA_PLAN_METERED = 0;
    public static final int SATELLITE_DATA_PLAN_UNMETERED = 1;
@@ -993,10 +986,8 @@ public class SatelliteController extends Handler {
        loadSatelliteSharedPreferences();
        if (mSharedPreferences != null) {
            try {
                synchronized (mNtnSmsSupportedByMessagesAppLock) {
                    mNtnSmsSupportedByMessagesApp = mSharedPreferences.getBoolean(
                            NTN_SMS_SUPPORTED_BY_MESSAGES_APP_KEY, false);
                }
                setNtnSmsSupportedByMessagesAppCache(mSharedPreferences.getBoolean(
                        NTN_SMS_SUPPORTED_BY_MESSAGES_APP_KEY, false));

                synchronized (mCarrierRoamingNtnAllSatellitePlmnSetLock) {
                    mCarrierRoamingNtnAllSatellitePlmnSet = mSharedPreferences.getStringSet(
@@ -2138,12 +2129,10 @@ public class SatelliteController extends Handler {
            }

            case EVENT_WIFI_CONNECTIVITY_STATE_CHANGED: {
                synchronized (mIsWifiConnectedLock) {
                ar = (AsyncResult) msg.obj;
                    mIsWifiConnected = (boolean) ar.result;
                mIsWifiConnected.set((boolean) ar.result);
                plogd("EVENT_WIFI_CONNECTIVITY_STATE_CHANGED: mIsWifiConnected="
                            + mIsWifiConnected);
                }
                        + mIsWifiConnected.get());
                evaluateCarrierRoamingNtnEligibilityChange();
                break;
            }
@@ -5472,11 +5461,7 @@ public class SatelliteController extends Handler {
    private void handleEventSatelliteModemStateChanged(
            @SatelliteManager.SatelliteModemState int state) {
        plogd("handleEventSatelliteModemStateChanged: state=" + state);

        synchronized (mSatelliteModemStateLock) {
            mSatelliteModemState = state;
        }

        mSatelliteModemState.set(state);
        if (state == SatelliteManager.SATELLITE_MODEM_STATE_UNAVAILABLE
                || state == SatelliteManager.SATELLITE_MODEM_STATE_OFF) {
            if (!isWaitingForDisableSatelliteModemResponse()) {
@@ -7988,7 +7973,7 @@ public class SatelliteController extends Handler {
        plogd("evaluateESOSProfilesPrioritization: newSubsInfoListPerPriority.size()="
                  + newSubsInfoListPerPriority.size());

        if (!mHasSentBroadcast && newSubsInfoListPerPriority.size() == 0) {
        if (!mHasSentBroadcast.get() && newSubsInfoListPerPriority.size() == 0) {
            logd("evaluateESOSProfilesPrioritization: no satellite subscription available");
            return;
        }
@@ -8005,7 +7990,7 @@ public class SatelliteController extends Handler {
                mSubsInfoListPerPriority = newSubsInfoListPerPriority;
                mLastEvaluatedSubscriberProvisionStatus = newEvaluatedSubscriberProvisionStatus;
                sendBroadCastForProvisionedESOSSubs();
                mHasSentBroadcast = true;
                mHasSentBroadcast.set(true);
                selectBindingSatelliteSubscription(false);
            }
        }
@@ -8567,7 +8552,7 @@ public class SatelliteController extends Handler {
            logd("getRegionalSatelliteEarfcns: carrierRoamingNbIotNtnFlag is disabled");
            return new HashMap<>();
        }
        synchronized (mRegionalSatelliteEarfcnsLock) {

        if (mRegionalSatelliteEarfcns.containsKey(subId)) {
            return mRegionalSatelliteEarfcns.get(subId);
        } else {
@@ -8575,7 +8560,6 @@ public class SatelliteController extends Handler {
            return new HashMap<>();
        }
    }
    }

    /**
     * Update regional satellite earfcn information from carrier config.
@@ -8588,11 +8572,9 @@ public class SatelliteController extends Handler {
            return;
        }

        synchronized (mRegionalSatelliteEarfcnsLock) {
        mRegionalSatelliteEarfcns.put(subId,
                readRegionalSatelliteEarfcnsFromCarrierConfig(subId));
    }
    }

    /**
     * Deliver the list of deprovisioned satellite subscriber ids.
@@ -8668,18 +8650,22 @@ public class SatelliteController extends Handler {
        } else {
            mSharedPreferences.edit().putBoolean(
                    NTN_SMS_SUPPORTED_BY_MESSAGES_APP_KEY, ntnSmsSupported).apply();
            synchronized (mNtnSmsSupportedByMessagesAppLock) {
                mNtnSmsSupportedByMessagesApp = ntnSmsSupported;
            setNtnSmsSupportedByMessagesAppCache(ntnSmsSupported);
        }
    }

    private void setNtnSmsSupportedByMessagesAppCache(boolean ntnSmsSupported) {
        if (mNtnSmsSupportedByMessagesApp == null) {
            mNtnSmsSupportedByMessagesApp = new AtomicBoolean(ntnSmsSupported);
        } else {
            mNtnSmsSupportedByMessagesApp.set(ntnSmsSupported);
        }
    }

    private boolean isNtnSmsSupportedByMessagesApp() {
        synchronized (mNtnSmsSupportedByMessagesAppLock) {
        if (mNtnSmsSupportedByMessagesApp != null) {
                plogd("isNtnSmsSupportedByMessagesApp:" + mNtnSmsSupportedByMessagesApp);
                return mNtnSmsSupportedByMessagesApp;
            }
            plogd("isNtnSmsSupportedByMessagesApp:" + mNtnSmsSupportedByMessagesApp.get());
            return mNtnSmsSupportedByMessagesApp.get();
        }

        if (!loadSatelliteSharedPreferences()) return false;
@@ -8690,10 +8676,8 @@ public class SatelliteController extends Handler {
        } else {
            boolean ntnSmsSupported = mSharedPreferences.getBoolean(
                    NTN_SMS_SUPPORTED_BY_MESSAGES_APP_KEY, false);
            synchronized (mNtnSmsSupportedByMessagesAppLock) {
                mNtnSmsSupportedByMessagesApp = ntnSmsSupported;
                plogd("isNtnSmsSupportedByMessagesApp:" + mNtnSmsSupportedByMessagesApp);
            }
            setNtnSmsSupportedByMessagesAppCache(ntnSmsSupported);
            plogd("isNtnSmsSupportedByMessagesApp:" + ntnSmsSupported);
            return ntnSmsSupported;
        }
    }
@@ -8813,13 +8797,11 @@ public class SatelliteController extends Handler {
            return false;
        }

        synchronized (mIsWifiConnectedLock) {
            if (mIsWifiConnected) {
        if (mIsWifiConnected.get()) {
            plogd("isCarrierRoamingNtnEligible[phoneId=" + phone.getPhoneId()
                    + "]: Wi-Fi is connected");
            return false;
        }
        }

        return true;
    }
@@ -9526,8 +9508,7 @@ public class SatelliteController extends Handler {
     * Returns satellite connected state from modem, return true if connected.
     */
    public boolean isInConnectedState() {
        synchronized (mSatelliteModemStateLock) {
            switch (mSatelliteModemState) {
        switch (mSatelliteModemState.get()) {
            case SatelliteManager.SATELLITE_MODEM_STATE_CONNECTED: //fallthrough
            case SatelliteManager.SATELLITE_MODEM_STATE_DATAGRAM_TRANSFERRING: //fallthrough
            case SatelliteManager.SATELLITE_MODEM_STATE_DATAGRAM_RETRYING: //fallthrough
@@ -9539,7 +9520,6 @@ public class SatelliteController extends Handler {
                return false;
        }
    }
    }

    protected void updateLastNotifiedCarrierRoamingNtnSignalStrengthAndNotify(
            @Nullable Phone phone) {