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

Commit 0a9d7d9e authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Change variables to atomic variables

The following variables are updated in this cl:
- mTimeoutMillis
- mOemEnabledTimeoutMillis
- mIsTimerTimedOut
- mCountOfTimerStarted
- mIsTestEmergencyNumber

Bug: 410859840
Test: atest
Flag: com.android.internal.telephony.flags.satellite_improve_multi_thread_design
Change-Id: Icf9f725eb5a57e7f68218ae6caca045b409a42a8
parent 7c3b2a07
Loading
Loading
Loading
Loading
+76 −90
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import android.util.SparseArray;
import com.android.ims.ImsException;
import com.android.ims.ImsManager;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
@@ -78,6 +77,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;


/**
@@ -117,23 +117,21 @@ public class SatelliteSOSMessageRecommender extends Handler {
            new AtomicBoolean(false);
    protected final AtomicInteger mSubIdOfSatelliteConnectedViaCarrierWithinHysteresisTime =
            new AtomicInteger(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
    protected AtomicLong mTimeoutMillis = new AtomicLong(0);
    private final AtomicLong mOemEnabledTimeoutMillis = new AtomicLong(0);
    private AtomicBoolean mIsTimerTimedOut = new AtomicBoolean(false);
    protected AtomicInteger mCountOfTimerStarted = new AtomicInteger(0);
    private AtomicBoolean mIsTestEmergencyNumber = new AtomicBoolean(false);


    /**
     * All the variables declared here should only be accessed by methods that run inside the
     * handler thread.
     */
    private Connection mEmergencyConnection = null;
    /** Key: Phone ID; Value: IMS RegistrationCallback */
    private SparseArray<RegistrationManager.RegistrationCallback>
            mImsRegistrationCallbacks = new SparseArray<>();

    protected long mTimeoutMillis = 0;
    private final long mOemEnabledTimeoutMillis;

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

    private boolean mIsTestEmergencyNumber = false;

    /**
     * Create an instance of SatelliteSOSMessageRecommender.
     *
@@ -166,8 +164,8 @@ public class SatelliteSOSMessageRecommender extends Handler {
        mFeatureFlags = mSatelliteController.getFeatureFlags();
        mCountryDetector = TelephonyCountryDetector.getInstance(context, mFeatureFlags);
        mImsManager = imsManager;
        mOemEnabledTimeoutMillis =
                getOemEnabledEmergencyCallWaitForConnectionTimeoutMillis(context);
        mOemEnabledTimeoutMillis.set(
                getOemEnabledEmergencyCallWaitForConnectionTimeoutMillis(context));
        mISatelliteProvisionStateCallback = new ISatelliteProvisionStateCallback.Stub() {
            @Override
            public void onSatelliteProvisionStateChanged(boolean provisioned) {
@@ -226,7 +224,7 @@ public class SatelliteSOSMessageRecommender extends Handler {
            plogd("onEmergencyCallStarted: satellite is not supported");
            return;
        }
        mIsTestEmergencyNumber = isTestEmergencyNumber;
        mIsTestEmergencyNumber.set(isTestEmergencyNumber);

        if (hasMessages(EVENT_EMERGENCY_CALL_STARTED)) {
            logd("onEmergencyCallStarted: Ignoring due to ongoing event:");
@@ -314,21 +312,18 @@ public class SatelliteSOSMessageRecommender extends Handler {
    }

    private void handleTimeoutEvent() {
        synchronized (mLock) {
            mIsTimerTimedOut = true;
        mIsTimerTimedOut.set(true);
        evaluateSendingConnectionEventDisplayEmergencyMessage();
    }
    }

    private void evaluateSendingConnectionEventDisplayEmergencyMessage() {
        synchronized (mLock) {
        if (mEmergencyConnection == null) {
            ploge("No emergency call is ongoing...");
            return;
        }

            if (!mIsTimerTimedOut || mCheckingAccessRestrictionInProgress.get()) {
                plogd("mIsTimerTimedOut=" + mIsTimerTimedOut
        if (!mIsTimerTimedOut.get() || mCheckingAccessRestrictionInProgress.get()) {
            plogd("mIsTimerTimedOut=" + mIsTimerTimedOut.get()
                    + ", mCheckingAccessRestrictionInProgress="
                    + mCheckingAccessRestrictionInProgress.get());
            return;
@@ -352,7 +347,7 @@ public class SatelliteSOSMessageRecommender extends Handler {
                && shouldTrackCall(mEmergencyConnection.getState())) {
            plogd("handleTimeoutEvent: Sent EVENT_DISPLAY_EMERGENCY_MESSAGE to Dialer");
            Bundle extras = createExtraBundleForEventDisplayEmergencyMessage(
                        mIsTestEmergencyNumber);
                    mIsTestEmergencyNumber.get());
            mEmergencyConnection.sendConnectionEvent(
                    TelephonyManager.EVENT_DISPLAY_EMERGENCY_MESSAGE, extras);
            isDialerNotified = true;
@@ -364,7 +359,6 @@ public class SatelliteSOSMessageRecommender extends Handler {
                + ", shouldTrackCall=" + shouldTrackCall(mEmergencyConnection.getState()));
        cleanUpResources(isDialerNotified);
    }
    }

    private boolean isSatelliteAllowed() {
        if (isSatelliteEmergencyMessagingViaCarrierAvailable()) return true;
@@ -436,7 +430,7 @@ public class SatelliteSOSMessageRecommender extends Handler {
        SatelliteStats.getInstance().onSatelliteSosMessageRecommender(
                new SatelliteStats.SatelliteSosMessageRecommenderParams.Builder()
                        .setDisplaySosMessageSent(isDialerNotified)
                        .setCountOfTimerStarted(mCountOfTimerStarted)
                        .setCountOfTimerStarted(mCountOfTimerStarted.get())
                        .setImsRegistered(isImsRegistered())
                        .setCellularServiceState(getBestCellularServiceState())
                        .setIsMultiSim(isMultiSim())
@@ -450,18 +444,16 @@ public class SatelliteSOSMessageRecommender extends Handler {
    private void cleanUpResources(boolean isDialerNotified) {
        plogd("cleanUpResources");
        reportESosRecommenderDecision(isDialerNotified);
        synchronized (mLock) {
        stopTimer();
        if (mEmergencyConnection != null) {
            unregisterForInterestedStateChangedEvents();
        }
        mEmergencyConnection = null;
            mCountOfTimerStarted = 0;
            mIsTimerTimedOut = false;
        mCountOfTimerStarted.set(0);
        mIsTimerTimedOut.set(false);
        mCheckingAccessRestrictionInProgress.set(false);
        mIsSatelliteAllowedForCurrentLocation.set(false);
            mIsTestEmergencyNumber = false;
        }
        mIsTestEmergencyNumber.set(false);
    }

    private void registerForInterestedStateChangedEvents() {
@@ -545,22 +537,18 @@ public class SatelliteSOSMessageRecommender extends Handler {
    }

    private void startTimer() {
        synchronized (mLock) {
        if (hasMessages(EVENT_TIME_OUT)) {
            return;
        }
            sendMessageDelayed(obtainMessage(EVENT_TIME_OUT), mTimeoutMillis);
            mCountOfTimerStarted++;
            mIsTimerTimedOut = false;
            plogd("startTimer mCountOfTimerStarted=" + mCountOfTimerStarted);
        }
        sendMessageDelayed(obtainMessage(EVENT_TIME_OUT), mTimeoutMillis.get());
        int count = mCountOfTimerStarted.incrementAndGet();
        mIsTimerTimedOut.set(false);
        plogd("startTimer mCountOfTimerStarted=" + count);
    }

    private void stopTimer() {
        synchronized (mLock) {
        removeMessages(EVENT_TIME_OUT);
    }
    }

    private void handleSatelliteAccessRestrictionCheckingResult(boolean satelliteAllowed) {
        mIsSatelliteAllowedForCurrentLocation.set(satelliteAllowed);
@@ -571,20 +559,18 @@ public class SatelliteSOSMessageRecommender extends Handler {
    private void selectEmergencyCallWaitForConnectionTimeoutDuration() {
        if (isSatelliteEmergencyMessagingViaCarrierAvailable()) {
            int satelliteSubId = mSubIdOfSatelliteConnectedViaCarrierWithinHysteresisTime.get();
            mTimeoutMillis =
                    mSatelliteController.getCarrierEmergencyCallWaitForConnectionTimeoutMillis(
                            satelliteSubId);
            mTimeoutMillis.set(mSatelliteController
                    .getCarrierEmergencyCallWaitForConnectionTimeoutMillis(satelliteSubId));
        } else {
            int satelliteSubId = mSatelliteController.getSelectedSatelliteSubId();
            if (!SatelliteServiceUtils.isNtnOnlySubscriptionId(satelliteSubId)) {
                mTimeoutMillis =
                    mSatelliteController.getCarrierEmergencyCallWaitForConnectionTimeoutMillis(
                        satelliteSubId);
                mTimeoutMillis.set(mSatelliteController
                        .getCarrierEmergencyCallWaitForConnectionTimeoutMillis(satelliteSubId));
            } else {
                mTimeoutMillis = mOemEnabledTimeoutMillis;
                mTimeoutMillis.set(mOemEnabledTimeoutMillis.get());
            }
        }
        plogd("mTimeoutMillis = " + mTimeoutMillis);
        plogd("mTimeoutMillis = " + mTimeoutMillis.get());
    }

    private static long getOemEnabledEmergencyCallWaitForConnectionTimeoutMillis(
+2 −2
Original line number Diff line number Diff line
@@ -1203,7 +1203,7 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {
        }

        public int getCountOfTimerStarted() {
            return mCountOfTimerStarted;
            return mCountOfTimerStarted.get();
        }

        public void sendServiceStateChangedEvent() {
@@ -1211,7 +1211,7 @@ public class SatelliteSOSMessageRecommenderTest extends TelephonyTest {
        }

        public long getTimeOutMillis() {
            return mTimeoutMillis;
            return mTimeoutMillis.get();
        }

        public boolean isDialerNotified() {