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

Commit 29dfc0b5 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Remove mIsRadioOnLock

The following variables are changed to atomic variables:
- mIsRadioOn
- mRadioOffRequested

Bug: 409584433
Test: atest
Flag: com.android.internal.telephony.flags.satellite_improve_multi_thread_design
Change-Id: Iabcc99c38825656a841a07b715cae131a31547a1
parent 227e1473
Loading
Loading
Loading
Loading
+39 −58
Original line number Diff line number Diff line
@@ -388,6 +388,10 @@ public class SatelliteController extends Handler {
    private AtomicBoolean mIsDemoModeEnabled = new AtomicBoolean(false);
    private AtomicBoolean mIsEmergency = new AtomicBoolean(false);
    private AtomicBoolean mIsSatelliteEnabled = null;
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected AtomicBoolean mIsRadioOn = new AtomicBoolean(false);
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected AtomicBoolean mRadioOffRequested = new AtomicBoolean(false);
    private AtomicBoolean mIgnorePlmnListFromStorage = new AtomicBoolean(false);

    private final Object mSatelliteEnabledRequestLock = new Object();
@@ -481,13 +485,6 @@ public class SatelliteController extends Handler {
    private final ConcurrentHashMap<IBinder, ISelectedNbIotSatelliteSubscriptionCallback>
            mSelectedNbIotSatelliteSubscriptionChangedListeners = new ConcurrentHashMap<>();

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected final Object mIsRadioOnLock = new Object();
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected boolean mIsRadioOn;
    @GuardedBy("mIsRadioOnLock")
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected boolean mRadioOffRequested = false;
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected final Object mDeviceProvisionLock = new Object();
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
@@ -944,9 +941,7 @@ public class SatelliteController extends Handler {
                mContext, looper, mFeatureFlags, mPointingAppController);

        mCi.registerForRadioStateChanged(this, EVENT_RADIO_STATE_CHANGED, null);
        synchronized (mIsRadioOnLock) {
            mIsRadioOn = phone.isRadioOn();
        }
        mIsRadioOn.set(phone.isRadioOn());

        registerForPendingDatagramCount();
        registerForSatelliteModemStateChanged();
@@ -1833,20 +1828,16 @@ public class SatelliteController extends Handler {
            }

            case EVENT_RADIO_STATE_CHANGED: {
                synchronized (mIsRadioOnLock) {
                logd("EVENT_RADIO_STATE_CHANGED: radioState=" + mCi.getRadioState());
                if (mCi.getRadioState() == TelephonyManager.RADIO_POWER_ON) {
                        mIsRadioOn = true;
                    mIsRadioOn.set(true);
                } else if (mCi.getRadioState() == TelephonyManager.RADIO_POWER_OFF) {
                    resetCarrierRoamingSatelliteModeParams();
                        synchronized (mIsRadioOnLock) {
                            if (mRadioOffRequested) {
                    if (mRadioOffRequested.get()) {
                        logd("EVENT_RADIO_STATE_CHANGED: set mIsRadioOn to false");
                        stopWaitForCellularModemOffTimer();
                                mIsRadioOn = false;
                                mRadioOffRequested = false;
                            }
                        }
                        mIsRadioOn.set(false);
                        mRadioOffRequested.set(false);
                    }
                }

@@ -2163,9 +2154,7 @@ public class SatelliteController extends Handler {

            case EVENT_WAIT_FOR_CELLULAR_MODEM_OFF_TIMED_OUT: {
                plogw("Timed out to wait for cellular modem OFF state");
                synchronized (mIsRadioOnLock) {
                    mRadioOffRequested = false;
                }
                mRadioOffRequested.set(false);
                break;
            }

@@ -2698,20 +2687,18 @@ public class SatelliteController extends Handler {
        }

        if (enableSatellite) {
            synchronized (mIsRadioOnLock) {
                if (!mIsRadioOn) {
            if (!mIsRadioOn.get()) {
                ploge("Radio is not on, can not enable satellite");
                sendErrorAndReportSessionMetrics(
                        SatelliteManager.SATELLITE_RESULT_INVALID_MODEM_STATE, result);
                return;
            }
                if (mRadioOffRequested) {
            if (mRadioOffRequested.get()) {
                ploge("Radio is being powering off, can not enable satellite");
                sendErrorAndReportSessionMetrics(
                        SatelliteManager.SATELLITE_RESULT_INVALID_MODEM_STATE, result);
                return;
            }
            }

            if (mTelecomManager.isInEmergencyCall()) {
                plogd("requestSatelliteEnabled: reject as emergency call is ongoing.");
@@ -4362,9 +4349,7 @@ public class SatelliteController extends Handler {
    public void onSetCellularRadioPowerStateRequested(boolean powerOn) {
        logd("onSetCellularRadioPowerStateRequested: powerOn=" + powerOn);

        synchronized (mIsRadioOnLock) {
            mRadioOffRequested = !powerOn;
        }
        mRadioOffRequested.set(!powerOn);
        if (powerOn) {
            stopWaitForCellularModemOffTimer();
        } else {
@@ -4389,11 +4374,9 @@ public class SatelliteController extends Handler {
     */
    public void onPowerOffCellularRadioFailed() {
        logd("onPowerOffCellularRadioFailed");
        synchronized (mIsRadioOnLock) {
            mRadioOffRequested = false;
        mRadioOffRequested.set(false);
        stopWaitForCellularModemOffTimer();
    }
    }

    /**
     * Notify SMS received.
@@ -7175,7 +7158,6 @@ public class SatelliteController extends Handler {
    }

    private void startWaitForCellularModemOffTimer() {
        synchronized (mIsRadioOnLock) {
        if (hasMessages(EVENT_WAIT_FOR_CELLULAR_MODEM_OFF_TIMED_OUT)) {
            plogd("startWaitForCellularModemOffTimer: the timer was already started");
            return;
@@ -7186,7 +7168,6 @@ public class SatelliteController extends Handler {
        sendMessageDelayed(obtainMessage(EVENT_WAIT_FOR_CELLULAR_MODEM_OFF_TIMED_OUT),
                timeoutMillis);
    }
    }

    private void stopWaitForCellularModemOffTimer() {
        synchronized (mSatelliteEnabledRequestLock) {
@@ -8778,7 +8759,7 @@ public class SatelliteController extends Handler {
            return false;
        }

        if (!mIsRadioOn) {
        if (!mIsRadioOn.get()) {
            plogd("isCarrierRoamingNtnEligible: radio is off");
            return false;
        }
+2 −6
Original line number Diff line number Diff line
@@ -6099,15 +6099,11 @@ public class SatelliteControllerTest extends TelephonyTest {
        }

        public boolean isRadioOn() {
            synchronized (mIsRadioOnLock) {
                return mIsRadioOn;
            }
            return mIsRadioOn.get();
        }

        public boolean isRadioOffRequested() {
            synchronized (mIsRadioOnLock) {
                return mRadioOffRequested;
            }
            return mRadioOffRequested.get();
        }

        public boolean isWaitForCellularModemOffTimerStarted() {