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

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

Merge "Change boolean to AtomicBoolean" into main

parents f40c3324 7c3b2a07
Loading
Loading
Loading
Loading
+29 −34
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ public class SatelliteSOSMessageRecommender extends Handler {
    private static final int CMD_SEND_EVENT_DISPLAY_EMERGENCY_MESSAGE_FORCEFULLY = 6;
    private static final int EVENT_SATELLITE_ACCESS_RESTRICTION_CHECKING_RESULT = 7;

    /** All the variables initialized inside the constructor are declared here. */
    @NonNull private final Context mContext;
    @NonNull
    private final SatelliteController mSatelliteController;
@@ -106,29 +107,31 @@ public class SatelliteSOSMessageRecommender extends Handler {
    private ImsManager mImsManager;
    @NonNull
    private final FeatureFlags mFeatureFlags;
    @Nullable private PersistentLogger mPersistentLogger = null;
    private final ISatelliteProvisionStateCallback mISatelliteProvisionStateCallback;

    /** All the atomic variables are declared here. */
    private AtomicBoolean mIsSatelliteAllowedForCurrentLocation = new AtomicBoolean(false);
    private AtomicBoolean mCheckingAccessRestrictionInProgress = new AtomicBoolean(false);
    protected final AtomicBoolean mIsSatelliteConnectedViaCarrierWithinHysteresisTime =
            new AtomicBoolean(false);
    protected final AtomicInteger mSubIdOfSatelliteConnectedViaCarrierWithinHysteresisTime =
            new AtomicInteger(SubscriptionManager.INVALID_SUBSCRIPTION_ID);


    private Connection mEmergencyConnection = null;
    private final ISatelliteProvisionStateCallback mISatelliteProvisionStateCallback;
    /** Key: Phone ID; Value: IMS RegistrationCallback */
    private SparseArray<RegistrationManager.RegistrationCallback>
            mImsRegistrationCallbacks = new SparseArray<>();
    @GuardedBy("mLock")
    private boolean mIsSatelliteAllowedForCurrentLocation = false;
    @GuardedBy("mLock")
    private boolean mCheckingAccessRestrictionInProgress = false;

    protected long mTimeoutMillis = 0;
    private final long mOemEnabledTimeoutMillis;
    protected final AtomicBoolean mIsSatelliteConnectedViaCarrierWithinHysteresisTime =
            new AtomicBoolean(false);
    protected final AtomicInteger mSubIdOfSatelliteConnectedViaCarrierWithinHysteresisTime =
            new AtomicInteger(SubscriptionManager.INVALID_SUBSCRIPTION_ID);

    @GuardedBy("mLock")
    private boolean mIsTimerTimedOut = false;
    protected int mCountOfTimerStarted = 0;
    private final Object mLock = new Object();

    @Nullable private PersistentLogger mPersistentLogger = null;

    private boolean mIsTestEmergencyNumber = false;

    /**
@@ -299,10 +302,8 @@ public class SatelliteSOSMessageRecommender extends Handler {
        mEmergencyConnection = connection;
        handleStateChangedEventForHysteresisTimer();

        synchronized (mLock) {
            mCheckingAccessRestrictionInProgress = false;
            mIsSatelliteAllowedForCurrentLocation = false;
        }
        mCheckingAccessRestrictionInProgress.set(false);
        mIsSatelliteAllowedForCurrentLocation.set(false);
    }

    private void handleSatelliteProvisionStateChangedEvent(boolean provisioned) {
@@ -326,10 +327,10 @@ public class SatelliteSOSMessageRecommender extends Handler {
                return;
            }

            if (!mIsTimerTimedOut || mCheckingAccessRestrictionInProgress) {
            if (!mIsTimerTimedOut || mCheckingAccessRestrictionInProgress.get()) {
                plogd("mIsTimerTimedOut=" + mIsTimerTimedOut
                        + ", mCheckingAccessRestrictionInProgress="
                        + mCheckingAccessRestrictionInProgress);
                        + mCheckingAccessRestrictionInProgress.get());
                return;
            }

@@ -366,10 +367,8 @@ public class SatelliteSOSMessageRecommender extends Handler {
    }

    private boolean isSatelliteAllowed() {
        synchronized (mLock) {
        if (isSatelliteEmergencyMessagingViaCarrierAvailable()) return true;
            return mIsSatelliteAllowedForCurrentLocation;
        }
        return mIsSatelliteAllowedForCurrentLocation.get();
    }

    private void updateSatelliteViaCarrierAvailability() {
@@ -459,8 +458,8 @@ public class SatelliteSOSMessageRecommender extends Handler {
            mEmergencyConnection = null;
            mCountOfTimerStarted = 0;
            mIsTimerTimedOut = false;
            mCheckingAccessRestrictionInProgress = false;
            mIsSatelliteAllowedForCurrentLocation = false;
            mCheckingAccessRestrictionInProgress.set(false);
            mIsSatelliteAllowedForCurrentLocation.set(false);
            mIsTestEmergencyNumber = false;
        }
    }
@@ -564,12 +563,10 @@ public class SatelliteSOSMessageRecommender extends Handler {
    }

    private void handleSatelliteAccessRestrictionCheckingResult(boolean satelliteAllowed) {
        synchronized (mLock) {
            mIsSatelliteAllowedForCurrentLocation = satelliteAllowed;
            mCheckingAccessRestrictionInProgress = false;
        mIsSatelliteAllowedForCurrentLocation.set(satelliteAllowed);
        mCheckingAccessRestrictionInProgress.set(false);
        evaluateSendingConnectionEventDisplayEmergencyMessage();
    }
    }

    private void selectEmergencyCallWaitForConnectionTimeoutDuration() {
        if (isSatelliteEmergencyMessagingViaCarrierAvailable()) {
@@ -790,13 +787,11 @@ public class SatelliteSOSMessageRecommender extends Handler {
    }

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

        OutcomeReceiver<Boolean, SatelliteManager.SatelliteException> callback =
                new OutcomeReceiver<>() {