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

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

Merge "Change boolean to AtomicBoolean" into main

parents 2c363dc5 4ebad821
Loading
Loading
Loading
Loading
+29 −40
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.internal.telephony.flags.FeatureFlags;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Satellite modem interface to manage connections with the satellite service and HAL interface.
@@ -67,6 +68,7 @@ public class SatelliteModemInterface {
    private static final long REBIND_MAXIMUM_DELAY = 64 * 1000; // 1 minute
    private static final int REBIND_MULTIPLIER = 2;

    /** All the variables initialized inside the constructor are declared here. */
    @NonNull private static SatelliteModemInterface sInstance;
    @NonNull private final Context mContext;
    @NonNull private final DemoSimulator mDemoSimulator;
@@ -74,8 +76,16 @@ public class SatelliteModemInterface {
    @NonNull private final SatelliteListener mDemoListener;
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    @NonNull protected final ExponentialBackoff mExponentialBackoff;
    @NonNull private final Object mLock = new Object();

    @NonNull private final SatelliteController mSatelliteController;

    @Nullable private PersistentLogger mPersistentLogger = null;

    /** All the atomic variables are declared here. */
    private AtomicBoolean mIsBound = new AtomicBoolean(false);
    private AtomicBoolean mIsBinding = new AtomicBoolean(false);

    @NonNull private final Object mLock = new Object();
    /**
     * {@code true} to use the vendor satellite service and {@code false} to use the HAL.
     */
@@ -83,9 +93,6 @@ public class SatelliteModemInterface {
    @Nullable private ISatellite mSatelliteService;
    @Nullable private SatelliteServiceConnection mSatelliteServiceConnection;
    @NonNull private String mVendorSatellitePackageName = "";
    private boolean mIsBound;
    private boolean mIsBinding;
    @Nullable private PersistentLogger mPersistentLogger = null;

    @NonNull private final RegistrantList mSatellitePositionInfoChangedRegistrants =
            new RegistrantList();
@@ -263,16 +270,13 @@ public class SatelliteModemInterface {
        mSatelliteController = satelliteController;
        mExponentialBackoff = new ExponentialBackoff(REBIND_INITIAL_DELAY, REBIND_MAXIMUM_DELAY,
                REBIND_MULTIPLIER, looper, () -> {
            synchronized (mLock) {
                if ((mIsBound && mSatelliteService != null) || mIsBinding) {
            if ((mIsBound.get() && mSatelliteService != null) || mIsBinding.get()) {
                return;
            }
            }

            if (mSatelliteServiceConnection != null) {
                synchronized (mLock) {
                    mIsBound = false;
                    mIsBinding = false;
                }
                mIsBound.set(false);
                mIsBinding.set(false);
                unbindService();
            }
            bindService();
@@ -305,18 +309,15 @@ public class SatelliteModemInterface {

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void bindService() {
        synchronized (mLock) {
            if (mIsBinding || mIsBound) return;
            mIsBinding = true;
        }
        if (mIsBinding.get() || mIsBound.get()) return;
        mIsBinding.set(true);

        String packageName = getSatellitePackageName();
        if (TextUtils.isEmpty(packageName)) {
            ploge("Unable to bind to the satellite service because the package is undefined.");
            // Since the package name comes from static device configs, stop retry because
            // rebind will continue to fail without a valid package name.
            synchronized (mLock) {
                mIsBinding = false;
            }
            mIsBinding.set(false);
            mExponentialBackoff.stop();
            return;
        }
@@ -331,17 +332,13 @@ public class SatelliteModemInterface {
            if (success) {
                plogd("Successfully bound to the satellite service.");
            } else {
                synchronized (mLock) {
                    mIsBinding = false;
                }
                mIsBinding.set(false);
                mExponentialBackoff.notifyFailed();
                ploge("Error binding to the satellite service. Retrying in "
                        + mExponentialBackoff.getCurrentDelay() + " ms.");
            }
        } catch (Exception e) {
            synchronized (mLock) {
                mIsBinding = false;
            }
            mIsBinding.set(false);
            mExponentialBackoff.notifyFailed();
            ploge("Exception binding to the satellite service. Retrying in "
                    + mExponentialBackoff.getCurrentDelay() + " ms. Exception: " + e);
@@ -364,10 +361,8 @@ public class SatelliteModemInterface {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            plogd("onServiceConnected: ComponentName=" + name);
            synchronized (mLock) {
                mIsBound = true;
                mIsBinding = false;
            }
            mIsBound.set(true);
            mIsBinding.set(false);
            mSatelliteService = ISatellite.Stub.asInterface(service);
            mExponentialBackoff.stop();
            try {
@@ -383,9 +378,7 @@ public class SatelliteModemInterface {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            ploge("onServiceDisconnected: Waiting for reconnect.");
            synchronized (mLock) {
                mIsBinding = false;
            }
            mIsBinding.set(false);
            // Since we are still technically bound, clear the service and wait for reconnect.
            disconnectSatelliteService();
        }
@@ -393,10 +386,8 @@ public class SatelliteModemInterface {
        @Override
        public void onBindingDied(ComponentName name) {
            ploge("onBindingDied: Unbinding and rebinding service.");
            synchronized (mLock) {
                mIsBound = false;
                mIsBinding = false;
            }
            mIsBound.set(false);
            mIsBinding.set(false);
            unbindService();
            mExponentialBackoff.start();
        }
@@ -1359,10 +1350,8 @@ public class SatelliteModemInterface {
                + "updated, new packageName=" + servicePackageName);
        mExponentialBackoff.stop();
        if (mSatelliteServiceConnection != null) {
            synchronized (mLock) {
                mIsBound = false;
                mIsBinding = false;
            }
            mIsBound.set(false);
            mIsBinding.set(false);
            unbindService();
        }