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

Commit 0838901d authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Android (Google) Code Review
Browse files

Merge "Change variables to atomic variables." into main

parents 4e4b2a90 8313a370
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(
@@ -2140,12 +2131,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;
            }
@@ -5474,11 +5463,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()) {
@@ -8041,7 +8026,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;
        }
@@ -8058,7 +8043,7 @@ public class SatelliteController extends Handler {
                mSubsInfoListPerPriority = newSubsInfoListPerPriority;
                mLastEvaluatedSubscriberProvisionStatus = newEvaluatedSubscriberProvisionStatus;
                sendBroadCastForProvisionedESOSSubs();
                mHasSentBroadcast = true;
                mHasSentBroadcast.set(true);
                selectBindingSatelliteSubscription(false);
            }
        }
@@ -8620,7 +8605,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 {
@@ -8628,7 +8613,6 @@ public class SatelliteController extends Handler {
            return new HashMap<>();
        }
    }
    }

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

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

    /**
     * Deliver the list of deprovisioned satellite subscriber ids.
@@ -8721,18 +8703,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;
@@ -8743,10 +8729,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;
        }
    }
@@ -8866,13 +8850,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;
    }
@@ -9579,8 +9561,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
@@ -9592,7 +9573,6 @@ public class SatelliteController extends Handler {
                return false;
        }
    }
    }

    protected void updateLastNotifiedCarrierRoamingNtnSignalStrengthAndNotify(
            @Nullable Phone phone) {