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

Commit d4c91e12 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "[SB][Bluetooth] Remove NEW_BLUETOOTH_REPOSITORY flag." into main

parents 153582b9 b387c512
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -384,9 +384,6 @@ object Flags {
    // TODO(b/265892345): Tracking Bug
    val PLUG_IN_STATUS_BAR_CHIP = releasedFlag("plug_in_status_bar_chip")

    // TODO(b/280426085): Tracking Bug
    @JvmField val NEW_BLUETOOTH_REPOSITORY = releasedFlag("new_bluetooth_repository")

    // TODO(b/292533677): Tracking Bug
    val WIFI_TRACKER_LIB_FOR_WIFI_ICON = releasedFlag("wifi_tracker_lib_for_wifi_icon")

+2 −36
Original line number Diff line number Diff line
@@ -38,8 +38,6 @@ import com.android.systemui.bluetooth.BluetoothLogger;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.bluetooth.BluetoothRepository;
import com.android.systemui.statusbar.policy.bluetooth.ConnectionStatusModel;
@@ -64,7 +62,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
        CachedBluetoothDevice.Callback, LocalBluetoothProfileManager.ServiceListener {
    private static final String TAG = "BluetoothController";

    private final FeatureFlags mFeatureFlags;
    private final DumpManager mDumpManager;
    private final BluetoothLogger mLogger;
    private final BluetoothRepository mBluetoothRepository;
@@ -89,7 +86,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
    @Inject
    public BluetoothControllerImpl(
            Context context,
            FeatureFlags featureFlags,
            UserTracker userTracker,
            DumpManager dumpManager,
            BluetoothLogger logger,
@@ -97,7 +93,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
            @Main Looper mainLooper,
            @Nullable LocalBluetoothManager localBluetoothManager,
            @Nullable BluetoothAdapter bluetoothAdapter) {
        mFeatureFlags = featureFlags;
        mDumpManager = dumpManager;
        mLogger = logger;
        mBluetoothRepository = bluetoothRepository;
@@ -252,37 +247,8 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
    }

    private void updateConnected() {
        if (mFeatureFlags.isEnabled(Flags.NEW_BLUETOOTH_REPOSITORY)) {
        mBluetoothRepository.fetchConnectionStatusInBackground(
                getDevices(), this::onConnectionStatusFetched);
        } else {
            updateConnectedOld();
        }
    }

    /** Used only if {@link Flags.NEW_BLUETOOTH_REPOSITORY} is *not* enabled. */
    private void updateConnectedOld() {
        // Make sure our connection state is up to date.
        int state = mLocalBluetoothManager.getBluetoothAdapter().getConnectionState();
        List<CachedBluetoothDevice> newList = new ArrayList<>();
        // If any of the devices are in a higher state than the adapter, move the adapter into
        // that state.
        for (CachedBluetoothDevice device : getDevices()) {
            int maxDeviceState = device.getMaxConnectionState();
            if (maxDeviceState > state) {
                state = maxDeviceState;
            }
            if (device.isConnected()) {
                newList.add(device);
            }
        }

        if (newList.isEmpty() && state == BluetoothAdapter.STATE_CONNECTED) {
            // If somehow we think we are connected, but have no connected devices, we aren't
            // connected.
            state = BluetoothAdapter.STATE_DISCONNECTED;
        }
        onConnectionStatusFetched(new ConnectionStatusModel(state, newList));
    }

    private void onConnectionStatusFetched(ConnectionStatusModel status) {
+4 −89
Original line number Diff line number Diff line
@@ -46,8 +46,6 @@ import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.bluetooth.BluetoothLogger;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.flags.FakeFeatureFlags;
import com.android.systemui.flags.Flags;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.bluetooth.BluetoothRepository;
import com.android.systemui.statusbar.policy.bluetooth.FakeBluetoothRepository;
@@ -75,8 +73,6 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
    private DumpManager mMockDumpManager;
    private BluetoothControllerImpl mBluetoothControllerImpl;
    private BluetoothAdapter mMockAdapter;
    private final FakeFeatureFlags mFakeFeatureFlags = new FakeFeatureFlags();

    private List<CachedBluetoothDevice> mDevices;

    @Before
@@ -98,11 +94,9 @@ public class BluetoothControllerImplTest extends SysuiTestCase {

        BluetoothRepository bluetoothRepository =
                new FakeBluetoothRepository(mMockBluetoothManager);
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, true);

        mBluetoothControllerImpl = new BluetoothControllerImpl(
                mContext,
                mFakeFeatureFlags,
                mUserTracker,
                mMockDumpManager,
                mock(BluetoothLogger.class),
@@ -111,27 +105,8 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
                mMockBluetoothManager,
                mMockAdapter);
    }

    @Test
    public void testNoConnectionWithDevices_repoFlagOff() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, false);

        CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
        when(device.isConnected()).thenReturn(true);
        when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED);
        mDevices.add(device);
        when(mMockLocalAdapter.getConnectionState())
                .thenReturn(BluetoothAdapter.STATE_DISCONNECTED);

        mBluetoothControllerImpl.onConnectionStateChanged(null,
                BluetoothAdapter.STATE_DISCONNECTED);
        assertTrue(mBluetoothControllerImpl.isBluetoothConnected());
    }

    @Test
    public void testNoConnectionWithDevices_repoFlagOn() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, true);

    public void testNoConnectionWithDevices() {
        CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
        when(device.isConnected()).thenReturn(true);
        when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED);
@@ -147,9 +122,7 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
    }

    @Test
    public void testOnServiceConnected_updatesConnectionState_repoFlagOff() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, false);

    public void testOnServiceConnected_updatesConnectionState() {
        when(mMockLocalAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTING);

        mBluetoothControllerImpl.onServiceConnected();
@@ -159,41 +132,7 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
    }

    @Test
    public void testOnServiceConnected_updatesConnectionState_repoFlagOn() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, true);

        when(mMockLocalAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTING);

        mBluetoothControllerImpl.onServiceConnected();

        assertTrue(mBluetoothControllerImpl.isBluetoothConnecting());
        assertFalse(mBluetoothControllerImpl.isBluetoothConnected());
    }

    @Test
    public void getConnectedDevices_onlyReturnsConnected_repoFlagOff() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, false);

        CachedBluetoothDevice device1Disconnected = mock(CachedBluetoothDevice.class);
        when(device1Disconnected.isConnected()).thenReturn(false);
        mDevices.add(device1Disconnected);

        CachedBluetoothDevice device2Connected = mock(CachedBluetoothDevice.class);
        when(device2Connected.isConnected()).thenReturn(true);
        mDevices.add(device2Connected);

        mBluetoothControllerImpl.onDeviceAdded(device1Disconnected);
        mBluetoothControllerImpl.onDeviceAdded(device2Connected);

        assertThat(mBluetoothControllerImpl.getConnectedDevices()).hasSize(1);
        assertThat(mBluetoothControllerImpl.getConnectedDevices().get(0))
                .isEqualTo(device2Connected);
    }

    @Test
    public void getConnectedDevices_onlyReturnsConnected_repoFlagOn() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, true);

    public void getConnectedDevices_onlyReturnsConnected() {
        CachedBluetoothDevice device1Disconnected = mock(CachedBluetoothDevice.class);
        when(device1Disconnected.isConnected()).thenReturn(false);
        mDevices.add(device1Disconnected);
@@ -235,31 +174,7 @@ public class BluetoothControllerImplTest extends SysuiTestCase {
    }

    @Test
    public void testOnACLConnectionStateChange_updatesBluetoothStateOnConnection_repoFlagOff() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, false);

        BluetoothController.Callback callback = mock(BluetoothController.Callback.class);
        mBluetoothControllerImpl.addCallback(callback);

        assertFalse(mBluetoothControllerImpl.isBluetoothConnected());
        CachedBluetoothDevice device = mock(CachedBluetoothDevice.class);
        mDevices.add(device);
        when(device.isConnected()).thenReturn(true);
        when(device.getMaxConnectionState()).thenReturn(BluetoothProfile.STATE_CONNECTED);
        reset(callback);
        mBluetoothControllerImpl.onAclConnectionStateChanged(device,
                BluetoothProfile.STATE_CONNECTED);

        mTestableLooper.processAllMessages();

        assertTrue(mBluetoothControllerImpl.isBluetoothConnected());
        verify(callback, atLeastOnce()).onBluetoothStateChange(anyBoolean());
    }

    @Test
    public void testOnACLConnectionStateChange_updatesBluetoothStateOnConnection_repoFlagOn() {
        mFakeFeatureFlags.set(Flags.NEW_BLUETOOTH_REPOSITORY, true);

    public void testOnACLConnectionStateChange_updatesBluetoothStateOnConnection() {
        BluetoothController.Callback callback = mock(BluetoothController.Callback.class);
        mBluetoothControllerImpl.addCallback(callback);