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

Commit 812deaa7 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati
Browse files

Change mIsAligned to AtomicBoolean

Bug: 410308796
Test: atest
Test: 410837979
Flag: com.android.internal.telephony.flags.satellite_improve_multi_thread_design
Change-Id: Ie9418d34b60113d9f144c20197e27731f8fbdc93
parent 0bf5f4bd
Loading
Loading
Loading
Loading
+11 −17
Original line number Diff line number Diff line
@@ -28,11 +28,12 @@ import android.telephony.satellite.stub.SatelliteModemState;
import android.telephony.satellite.stub.SatelliteResult;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;

import java.util.concurrent.atomic.AtomicBoolean;

public class DemoSimulator extends StateMachine {
    private static final String TAG = "DemoSimulator";
    private static final boolean DBG = true;
@@ -50,11 +51,10 @@ public class DemoSimulator extends StateMachine {
    @NonNull private final PowerOffState mPowerOffState = new PowerOffState();
    @NonNull private final NotConnectedState mNotConnectedState = new NotConnectedState();
    @NonNull private final ConnectedState mConnectedState = new ConnectedState();
    @NonNull private final Object mLock = new Object();
    @GuardedBy("mLock")
    private boolean mIsAligned = false;
    private ISatelliteListener mISatelliteListener;

    private AtomicBoolean mIsAligned = new AtomicBoolean(false);

    /**
     * @return The singleton instance of DemoSimulator.
     */
@@ -134,11 +134,9 @@ public class DemoSimulator extends StateMachine {
                        SatelliteModemState.SATELLITE_MODEM_STATE_OUT_OF_SERVICE);
                mISatelliteListener.onNtnSignalStrengthChanged(ntnSignalStrength);

                synchronized (mLock) {
                    if (mIsAligned) {
                if (mIsAligned.get()) {
                    handleEventDeviceAlignedWithSatellite(true);
                }
                }
            } catch (RemoteException e) {
                loge("NotConnectedState: RemoteException " + e);
            }
@@ -194,11 +192,9 @@ public class DemoSimulator extends StateMachine {
                        SatelliteModemState.SATELLITE_MODEM_STATE_IN_SERVICE);
                mISatelliteListener.onNtnSignalStrengthChanged(ntnSignalStrength);

                synchronized (mLock) {
                    if (!mIsAligned) {
                if (!mIsAligned.get()) {
                    handleEventDeviceAlignedWithSatellite(false);
                }
                }
            } catch (RemoteException e) {
                loge("ConnectedState: RemoteException " + e);
            }
@@ -319,11 +315,9 @@ public class DemoSimulator extends StateMachine {
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public void setDeviceAlignedWithSatellite(boolean isAligned) {
        synchronized (mLock) {
        if (mSatelliteController.isDemoModeEnabled()) {
                mIsAligned = isAligned;
            mIsAligned.set(isAligned);
            sendMessage(EVENT_DEVICE_ALIGNED_WITH_SATELLITE, isAligned);
        }
    }
}
}
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -73,6 +74,7 @@ public class DemoSimulatorTest extends TelephonyTest {
        when(mMockSatelliteController.getDemoPointingNotAlignedDurationMillis()).thenReturn(
                TEST_DEVICE_POINTING_NOT_ALIGNED_DURATION_MILLIS);

        doReturn(true).when(mFeatureFlags).satelliteImproveMultiThreadDesign();
        mTestDemoSimulator = new TestDemoSimulator(mContext, Looper.myLooper(),
                mMockSatelliteController);
        mTestDemoSimulator.setSatelliteListener(mISatelliteListener);