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

Commit 0e8e4ebe authored by Nicolo' Mazzucato's avatar Nicolo' Mazzucato
Browse files

Use correct context when creating dialogs from QS tiles

This ensures that we launch the dialog in the display QS actually are (e.g. when the shade window is in a different display)

A linter will be added to prevent dialog creation without passing the context explicitly in shade window classes.

Bug: 362719719
Bug: 383294128
Test: InternetDialogDelegateTest, UserSwitchDialogControllerTest, DataSaverTileTest
Flag: com.android.systemui.shade_window_goes_around
Change-Id: Iadc5255f33f5f87b673a33352efd8340a705d365
parent 835ae299
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ public class FgsManagerControllerTest extends SysuiTestCase {
        mSystemClock = new FakeSystemClock();
        mMainExecutor = new FakeExecutor(mSystemClock);
        mBackgroundExecutor = new FakeExecutor(mSystemClock);
        when(mSystemUIDialogFactory.create()).thenReturn(mSystemUIDialog);
        when(mSystemUIDialogFactory.create(eq(mContext))).thenReturn(mSystemUIDialog);

        mUserProfiles = new ArrayList<>();
        Mockito.doReturn(mUserProfiles).when(mUserTracker).getUserProfiles();
@@ -346,6 +346,7 @@ public class FgsManagerControllerTest extends SysuiTestCase {
                SystemUiDeviceConfigFlags.TASK_MANAGER_SHOW_USER_VISIBLE_JOBS,
                "true", false);
        FgsManagerController fmc = new FgsManagerControllerImpl(
                mContext,
                mContext.getResources(),
                mMainExecutor,
                mBackgroundExecutor,
@@ -373,6 +374,7 @@ public class FgsManagerControllerTest extends SysuiTestCase {
                SystemUiDeviceConfigFlags.TASK_MANAGER_SHOW_USER_VISIBLE_JOBS,
                "false", false);
        fmc = new FgsManagerControllerImpl(
                mContext,
                mContext.getResources(),
                mMainExecutor,
                mBackgroundExecutor,
@@ -485,6 +487,7 @@ public class FgsManagerControllerTest extends SysuiTestCase {
                ArgumentCaptor.forClass(BroadcastReceiver.class);

        FgsManagerController result = new FgsManagerControllerImpl(
                mContext,
                mContext.getResources(),
                mMainExecutor,
                mBackgroundExecutor,
+2 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.eq
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@@ -79,7 +80,7 @@ class DataSaverTileTest(flags: FlagsParameterization) : SysuiTestCase() {
        testableLooper = TestableLooper.get(this)

        whenever(mHost.context).thenReturn(mContext)
        whenever(systemUIDialogFactory.create()).thenReturn(systemUIDialog)
        whenever(systemUIDialogFactory.create(eq(mContext))).thenReturn(systemUIDialog)

        tile =
            DataSaverTile(
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import com.android.systemui.qs.PseudoGridView
import com.android.systemui.qs.QSUserSwitcherEvent
import com.android.systemui.qs.tiles.UserDetailView
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
@@ -51,6 +50,7 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when`
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -84,7 +84,7 @@ class UserSwitchDialogControllerTest : SysuiTestCase() {
        MockitoAnnotations.initMocks(this)

        whenever(dialog.context).thenReturn(mContext)
        whenever(dialogFactory.create()).thenReturn(dialog)
        whenever(dialogFactory.create(eq(mContext))).thenReturn(dialog)

        controller = UserSwitchDialogController(
            { userDetailViewAdapter },
+2 −1
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ interface FgsManagerController {
class FgsManagerControllerImpl
@Inject
constructor(
    @ShadeDisplayAware private val context: Context,
    @ShadeDisplayAware private val resources: Resources,
    @Main private val mainExecutor: Executor,
    @Background private val backgroundExecutor: Executor,
@@ -387,7 +388,7 @@ constructor(
    override fun showDialog(expandable: Expandable?) {
        synchronized(lock) {
            if (dialog == null) {
                val dialog = systemUIDialogFactory.create()
                val dialog = systemUIDialogFactory.create(context)
                dialog.setTitle(R.string.fgs_manager_dialog_title)
                dialog.setMessage(R.string.fgs_manager_dialog_message)

+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ public class DataSaverTile extends QSTileImpl<BooleanState> implements
        // Show a dialog to confirm first. Dialogs shown by the DialogTransitionAnimator must be
        // created and shown on the main thread, so we post it to the UI handler.
        mUiHandler.post(() -> {
            SystemUIDialog dialog = mSystemUIDialogFactory.create();
            SystemUIDialog dialog = mSystemUIDialogFactory.create(mContext);
            dialog.setTitle(com.android.internal.R.string.data_saver_enable_title);
            dialog.setMessage(com.android.internal.R.string.data_saver_description);
            dialog.setPositiveButton(com.android.internal.R.string.data_saver_enable_button,
Loading