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

Commit 42a13a50 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Change mIsAligned to AtomicBoolean" into main

parents 39267397 812deaa7
Loading
Loading
Loading
Loading
+11 −17
Original line number Original line Diff line number Diff line
@@ -28,11 +28,12 @@ import android.telephony.satellite.stub.SatelliteModemState;
import android.telephony.satellite.stub.SatelliteResult;
import android.telephony.satellite.stub.SatelliteResult;
import android.util.Log;
import android.util.Log;


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


import java.util.concurrent.atomic.AtomicBoolean;

public class DemoSimulator extends StateMachine {
public class DemoSimulator extends StateMachine {
    private static final String TAG = "DemoSimulator";
    private static final String TAG = "DemoSimulator";
    private static final boolean DBG = true;
    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 PowerOffState mPowerOffState = new PowerOffState();
    @NonNull private final NotConnectedState mNotConnectedState = new NotConnectedState();
    @NonNull private final NotConnectedState mNotConnectedState = new NotConnectedState();
    @NonNull private final ConnectedState mConnectedState = new ConnectedState();
    @NonNull private final ConnectedState mConnectedState = new ConnectedState();
    @NonNull private final Object mLock = new Object();
    @GuardedBy("mLock")
    private boolean mIsAligned = false;
    private ISatelliteListener mISatelliteListener;
    private ISatelliteListener mISatelliteListener;


    private AtomicBoolean mIsAligned = new AtomicBoolean(false);

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


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


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


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