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

Commit a9492910 authored by Joshua Mokut's avatar Joshua Mokut Committed by Android (Google) Code Review
Browse files

Merge changes from topic "shortcut helper multi display" into main

* changes:
  Added multi-display support for shortcut helper
  Added multi-display support flag for shortcut helper
parents 4ee187ee 92cdc169
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2146,3 +2146,13 @@ flag {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "shortcut_helper_multi_display_support"
    namespace: "systemui"
    description: "Shortcut helper is triggered on the current display"
    bug: "406740115"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+23 −5
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState.Active
import com.android.systemui.keyboard.shortcut.shortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
@@ -51,7 +54,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() {

            helper.toggle(deviceId)

            assertThat(state).isEqualTo(ShortcutHelperState.Active(deviceId))
            assertThat(state).isEqualTo(Active(deviceId))
        }

    @Test
@@ -61,7 +64,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() {

            helper.showFromActivity()

            assertThat(state).isEqualTo(ShortcutHelperState.Active(VIRTUAL_KEYBOARD))
            assertThat(state).isEqualTo(Active(VIRTUAL_KEYBOARD))
        }

    @Test
@@ -73,7 +76,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() {
            fakeInputManager.addPhysicalKeyboard(deviceId)
            helper.showFromActivity()

            assertThat(state).isEqualTo(ShortcutHelperState.Active(deviceId))
            assertThat(state).isEqualTo(Active(deviceId))
        }

    @Test
@@ -86,6 +89,21 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() {
            fakeInputManager.inputManager.disableInputDevice(deviceId)
            helper.showFromActivity()

            assertThat(state).isEqualTo(ShortcutHelperState.Active(VIRTUAL_KEYBOARD))
            assertThat(state).isEqualTo(Active(VIRTUAL_KEYBOARD))
        }

    @Test
    fun activeStateDisplayId_isFocusedDisplay() =
        kosmos.runTest {
            val state by collectLastValue(repo.state)

            fakeFocusedDisplayRepository.setDisplayId(DISPLAY_ID)
            helper.showFromActivity()

            assertThat((state as Active).displayId).isEqualTo(DISPLAY_ID)
        }

    private companion object {
        const val DISPLAY_ID = 5
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.keyboard.shortcut.ui

import android.content.Context
import android.content.Context.INPUT_SERVICE
import android.content.applicationContext
import android.hardware.input.fakeInputManager
import androidx.test.annotation.UiThreadTest
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -83,10 +84,12 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() {
        with(kosmos) {
            ShortcutHelperDialogStarter(
                coroutineScope,
                applicationContext,
                viewModel,
                shortcutCustomizationDialogStarterFactory,
                dialogFactory,
                activityStarter,
                testDispatcher,
            )
        }

+45 −0
Original line number Diff line number Diff line
@@ -19,9 +19,11 @@ package com.android.systemui.keyboard.shortcut.ui.viewmodel
import android.app.role.RoleManager
import android.app.role.mockRoleManager
import android.content.Context
import android.content.applicationContext
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.PackageManager.NameNotFoundException
import android.view.Display
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Tv
import androidx.compose.material.icons.filled.VerticalSplit
@@ -42,18 +44,24 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory
import com.android.systemui.keyboard.shortcut.shared.model.shortcut
import com.android.systemui.keyboard.shortcut.shortcutHelperCategoriesInteractor
import com.android.systemui.keyboard.shortcut.shortcutHelperCustomizationModeInteractor
import com.android.systemui.keyboard.shortcut.shortcutHelperStateInteractor
import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper
import com.android.systemui.keyboard.shortcut.shortcutHelperViewModel
import com.android.systemui.keyboard.shortcut.ui.model.IconSource
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCategoryUi
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutHelperViewModel.Companion.EXTENDED_APPS_SHORTCUT_CUSTOMIZATION_LIMIT
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.model.sysUiState
import com.android.systemui.settings.FakeUserTracker
import com.android.systemui.settings.fakeUserTracker
import com.android.systemui.settings.userTracker
import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository
import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -89,6 +97,20 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
    private val fakeUserTracker = kosmos.fakeUserTracker
    private val mockRoleManager = kosmos.mockRoleManager
    private val underTest = kosmos.shortcutHelperViewModel
    private val secondaryDisplayViewModel =
        with(kosmos) {
            ShortcutHelperViewModel(
                applicationContext,
                mockRoleManager,
                userTracker,
                applicationCoroutineScope,
                testDispatcher,
                shortcutHelperStateInteractor,
                shortcutHelperCategoriesInteractor,
                shortcutHelperCustomizationModeInteractor,
                displayId = SECONDARY_DISPLAY,
            )
        }
    private val fakeDefaultShortcutCategoriesRepository =
        kosmos.fakeDefaultShortcutCategoriesRepository
    private val fakeCustomShortcutCategoriesRepository =
@@ -199,6 +221,28 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
            assertThat(shouldShowNew).isEqualTo(shouldShow)
        }

    @Test
    fun shouldShow_falseWhenShortcutHelperTriggeredFromDifferentDisplay() =
        testScope.runTest {
            kosmos.fakeFocusedDisplayRepository.setDisplayId(Display.DEFAULT_DISPLAY)
            val shouldShow by collectLastValue(secondaryDisplayViewModel.shouldShow)

            testHelper.showFromActivity()

            assertThat(shouldShow).isFalse()
        }

    @Test
    fun shouldShow_TrueWhenShortcutHelperTriggeredFromSameDisplay() =
        testScope.runTest {
            kosmos.fakeFocusedDisplayRepository.setDisplayId(SECONDARY_DISPLAY)
            val shouldShow by collectLastValue(secondaryDisplayViewModel.shouldShow)

            testHelper.showFromActivity()

            assertThat(shouldShow).isTrue()
        }

    @Test
    fun sysUiStateFlag_disabledByDefault() =
        testScope.runTest {
@@ -664,5 +708,6 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
        const val FIRST_SIMPLE_GROUP_LABEL = "simple group 1"
        const val SECOND_SIMPLE_GROUP_LABEL = "simple group 2"
        const val TEST_PACKAGE = "test.package.name"
        const val SECONDARY_DISPLAY = 5
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -110,5 +110,9 @@ interface SystemUIDisplaySubcomponent {
         * removed, and the component will be destroyed.
         */
        fun stop() {}

        companion object {
            val NOP: LifecycleListener = object : LifecycleListener {}
        }
    }
}
Loading