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

Commit eb74339c authored by chelseahao's avatar chelseahao Committed by Chelsea Hao
Browse files

Make BT dialog view model lazy. It could be constructed only when needed.

This change is to prevent BT dialog related classes construct right after reboot, before bluetooth profiles are ready.

Test: atest
Bug: 382397280
Flag: com.android.settingslib.flags.enable_le_audio_sharing
Change-Id: Iaf1d766d423b81295ac781a9338f6fdf85573be8
parent 645fcbae
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -61,6 +61,8 @@ import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.policy.BluetoothController;

import dagger.Lazy;

import kotlinx.coroutines.Job;

import java.util.List;
@@ -84,7 +86,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {

    private final Executor mExecutor;

    private final BluetoothDetailsContentViewModel mDetailsContentViewModel;
    private final Lazy<BluetoothDetailsContentViewModel> mDetailsContentViewModel;

    private final FeatureFlags mFeatureFlags;
    @Nullable
@@ -104,7 +106,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
            QSLogger qsLogger,
            BluetoothController bluetoothController,
            FeatureFlags featureFlags,
            BluetoothDetailsContentViewModel detailsContentViewModel
            Lazy<BluetoothDetailsContentViewModel> detailsContentViewModel
    ) {
        super(host, uiEventLogger, backgroundLooper, mainHandler, falsingManager, metricsLogger,
                statusBarStateController, activityStarter, qsLogger);
@@ -133,7 +135,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
                callback.accept(new BluetoothDetailsViewModel(() -> {
                    longClick(null);
                    return null;
                }, mDetailsContentViewModel))
                }, mDetailsContentViewModel.get()))
        );
        return true;
    }
@@ -158,7 +160,7 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {

    private void handleClickEvent(@Nullable Expandable expandable) {
        if (mFeatureFlags.isEnabled(Flags.BLUETOOTH_QS_TILE_DIALOG)) {
            mDetailsContentViewModel.showDetailsContent(expandable, /* view= */ null);
            mDetailsContentViewModel.get().showDetailsContent(expandable, /* view= */ null);
        } else {
            // Secondary clicks are header clicks, just toggle.
            toggleBluetooth();
+4 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import dagger.Lazy
import kotlin.test.assertTrue
import kotlinx.coroutines.Job
import org.junit.After
@@ -96,8 +97,7 @@ class BluetoothTileTest(flags: FlagsParameterization) : SysuiTestCase() {
                qsLogger,
                bluetoothController,
                featureFlags,
                bluetoothDetailsContentViewModel,
            )
            ) { bluetoothDetailsContentViewModel }

        tile.initialize()
        testableLooper.processAllMessages()
@@ -308,7 +308,7 @@ class BluetoothTileTest(flags: FlagsParameterization) : SysuiTestCase() {
        qsLogger: QSLogger,
        bluetoothController: BluetoothController,
        featureFlags: FeatureFlagsClassic,
        bluetoothDetailsContentViewModel: BluetoothDetailsContentViewModel,
        lazyBluetoothDetailsContentViewModel: Lazy<BluetoothDetailsContentViewModel>,
    ) :
        BluetoothTile(
            qsHost,
@@ -322,7 +322,7 @@ class BluetoothTileTest(flags: FlagsParameterization) : SysuiTestCase() {
            qsLogger,
            bluetoothController,
            featureFlags,
            bluetoothDetailsContentViewModel,
            lazyBluetoothDetailsContentViewModel,
        ) {
        var restrictionChecked: String? = null