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

Commit ad33b578 authored by David Duarte's avatar David Duarte Committed by Gerrit Code Review
Browse files

Merge changes I6e73c14a,Ib823568a,Icbfe21ae into main

* changes:
  SystemServer: Prevent Exception in tearDown
  SystemServer: initialize new listener separatly
  SystemServer: Force Flag to off in general tests
parents e1a59478 2a7fd906
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -1527,13 +1527,13 @@ class BluetoothManagerService {
        mHandler.post(() -> internalHandleOnBootPhase(userHandle));
    }

    private void internalHandleOnBootPhase(UserHandle userHandle) {
        if (DBG) {
            Log.d(TAG, "Bluetooth boot completed");
        }

    @VisibleForTesting
    void initialize(UserHandle userHandle) {
        if (mUseNewAirplaneMode) {
            mCurrentUserContext = mContext.createContextAsUser(userHandle, 0);
            mCurrentUserContext =
                    requireNonNull(
                            mContext.createContextAsUser(userHandle, 0),
                            "Current User Context cannot be null");
            AirplaneModeListener.initialize(
                    mLooper,
                    mContentResolver,
@@ -1549,6 +1549,14 @@ class BluetoothManagerService {
            SatelliteModeListener.initialize(
                    mLooper, mContentResolver, this::onSatelliteModeChanged);
        }
    }

    private void internalHandleOnBootPhase(UserHandle userHandle) {
        if (DBG) {
            Log.d(TAG, "Bluetooth boot completed");
        }

        initialize(userHandle);

        final boolean isBluetoothDisallowed = isBluetoothDisallowed();
        if (isBluetoothDisallowed) {
+19 −8
Original line number Diff line number Diff line
@@ -60,8 +60,8 @@ import android.provider.Settings;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.flags.FeatureFlags;
import com.android.bluetooth.flags.FeatureFlagsImpl;
import com.android.bluetooth.flags.FakeFeatureFlagsImpl;
import com.android.bluetooth.flags.Flags;

import org.junit.After;
import org.junit.Before;
@@ -77,8 +77,8 @@ import java.util.stream.IntStream;
@RunWith(AndroidJUnit4.class)
public class BluetoothManagerServiceTest {
    private static final String TAG = BluetoothManagerServiceTest.class.getSimpleName();
    static final int STATE_BLE_TURNING_ON = 14; // can't find the symbol because hidden api
    static final int TIMEOUT_MS = 1000; // TO use to wait for handler execution
    private static final int STATE_BLE_TURNING_ON = 14; // can't find the symbol because hidden api
    private static final int TIMEOUT_MS = 1000; // TO use to wait for handler execution

    BluetoothManagerService mManagerService;

@@ -88,6 +88,7 @@ public class BluetoothManagerServiceTest {

    @Spy BluetoothServerProxy mBluetoothServerProxy;
    @Mock UserManager mUserManager;
    @Mock UserHandle mUserHandle;

    @Mock IBinder mBinder;
    @Mock IBluetoothManagerCallback mManagerCallback;
@@ -95,7 +96,7 @@ public class BluetoothManagerServiceTest {

    @Mock IBluetooth mAdapterService;
    @Mock AdapterBinder mAdapterBinder;
    @Spy private final FeatureFlags mFeatureFlags = new FeatureFlagsImpl();
    private FakeFeatureFlagsImpl mFakeFlagsImpl;

    TestLooper mLooper;

@@ -146,19 +147,29 @@ public class BluetoothManagerServiceTest {

        mLooper = new TestLooper();

        mManagerService = new BluetoothManagerService(mContext, mLooper.getLooper(), mFeatureFlags);
        mFakeFlagsImpl = new FakeFeatureFlagsImpl();
        mFakeFlagsImpl.setFlag(Flags.FLAG_AIRPLANE_RESSOURCES_IN_APP, false);
        mFakeFlagsImpl.setFlag(Flags.FLAG_USE_NEW_AIRPLANE_MODE, false);
        mFakeFlagsImpl.setFlag(Flags.FLAG_USE_NEW_SATELLITE_MODE, false);

        mManagerService =
                new BluetoothManagerService(mContext, mLooper.getLooper(), mFakeFlagsImpl);
        mManagerService.initialize(mUserHandle);

        mManagerService.registerAdapter(mManagerCallback);
    }

    @After
    public void tearDown() {
        if (mManagerService != null) {
            mManagerService.unregisterAdapter(mManagerCallback);
            mManagerService = null;
        }
        mLooper.moveTimeForward(120_000); // 120 seconds
        // Do not try to assert if `syncHandler()` already raised an exception for it
        if (!mHasException) {
            assertThat(mLooper.nextMessage()).isNull();
        }
        mManagerService = null;
        validateMockitoUsage();
    }