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

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

Merge "Check for satellite before toggling bt." into main

parents 018b6c29 1fef71c3
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -175,13 +175,15 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {

    @Override
    protected void handleSecondaryClick(@Nullable Expandable expandable) {
        handleClickWithSatelliteCheck(() -> {
            if (!mController.canConfigBluetooth()) {
                mActivityStarter.postStartActivityDismissingKeyguard(
                        new Intent(Settings.ACTION_BLUETOOTH_SETTINGS), 0);
            return;
        }
            } else {
                toggleBluetooth();
            }
        });
    }

    @Override
    public CharSequence getTileLabel() {
+38 −9
Original line number Diff line number Diff line
@@ -16,11 +16,13 @@ import android.service.quicksettings.Tile
import android.testing.TestableLooper
import android.testing.TestableLooper.RunWithLooper
import androidx.test.filters.SmallTest
import com.android.dx.mockito.inline.extended.ExtendedMockito
import com.android.internal.logging.MetricsLogger
import com.android.settingslib.Utils
import com.android.settingslib.bluetooth.BatteryLevelsInfo
import com.android.settingslib.bluetooth.CachedBluetoothDevice
import com.android.settingslib.flags.Flags.FLAG_REFACTOR_BATTERY_LEVEL_DISPLAY
import com.android.settingslib.satellite.SatelliteDialogUtils
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.bluetooth.ui.viewModel.BluetoothDetailsContentViewModel
@@ -50,6 +52,7 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mock
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
@@ -345,6 +348,7 @@ class BluetoothTileTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Test
    @EnableFlags(QSComposeFragment.FLAG_NAME)
    fun disableBluetooth_transientTurningOff() {
        bypassingSatelliteDialog {
            enableBluetooth()
            tile.refreshState()
            testableLooper.processAllMessages()
@@ -358,6 +362,7 @@ class BluetoothTileTest(flags: FlagsParameterization) : SysuiTestCase() {
            assertThat(state.isTransient).isTrue()
            assertThat(state.icon).isEqualTo(createExpectedIcon(R.drawable.qs_bluetooth_icon_off))
        }
    }

    @Test
    @EnableFlags(QSComposeFragment.FLAG_NAME)
@@ -461,6 +466,30 @@ class BluetoothTileTest(flags: FlagsParameterization) : SysuiTestCase() {
        tile.handleUpdateState(state, /* arg= */ null)
    }

    private inline fun bypassingSatelliteDialog(testBody: () -> Unit) {
        val mockitoSession =
            ExtendedMockito.mockitoSession()
                .mockStatic(SatelliteDialogUtils::class.java)
                .startMocking()

        whenever(
                SatelliteDialogUtils.mayStartSatelliteWarningDialog(
                    eq(mContext),
                    eq(tile),
                    anyInt(),
                    any(),
                )
            )
            .thenAnswer { invocation ->
                (invocation.arguments[3] as (Boolean) -> Unit).invoke(true)
                mock<Job>()
            }

        testBody()

        mockitoSession.finishMocking()
    }

    private fun listenToDeviceBatteryLevelsInfo(
        state: QSTile.BooleanState,
        cachedDevice: CachedBluetoothDevice,