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

Commit 1c7ef28d authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Add AppListPage.showSystemAppsInitially" into main

parents aa475e91 ee351182
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.settingslib.spaprivileged.template.common.UserProfilePager
/**
 * The full screen template for an App List page.
 *
 * @param showSystemAppsInitially default false. If true, show system apps initially.
 * @param noMoreOptions default false. If true, then do not display more options action button,
 *   including the "Show System" / "Hide System" action.
 * @param header the description header appears before all the applications.
@@ -42,6 +43,7 @@ fun <T : AppRecord> AppListPage(
    title: String,
    listModel: AppListModel<T>,
    showInstantApps: Boolean = false,
    showSystemAppsInitially: Boolean = false,
    noMoreOptions: Boolean = false,
    matchAnyUserForAdmin: Boolean = false,
    noItemMessage: String? = null,
@@ -49,7 +51,7 @@ fun <T : AppRecord> AppListPage(
    header: @Composable () -> Unit = {},
    appList: @Composable AppListInput<T>.() -> Unit = { AppList() },
) {
    var showSystem by rememberSaveable { mutableStateOf(false) }
    var showSystem by rememberSaveable { mutableStateOf(showSystemAppsInitially) }
    SearchScaffold(
        title = title,
        actions = {
+4 −0
Original line number Diff line number Diff line
@@ -53,6 +53,10 @@ interface TogglePermissionAppListModel<T : AppRecord> {
    val enhancedConfirmationKey: String?
        get() = null

    /** Whether the App List page shows the system apps initially. */
    val showSystemAppsInitially: Boolean
        get() = false

    /**
     * Loads the extra info for the App List, and generates the [AppRecord] List.
     *
+1 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ internal fun <T : AppRecord> TogglePermissionAppListModel<T>.TogglePermissionApp
                restrictionsProviderFactory = restrictionsProviderFactory,
            )
        },
        showSystemAppsInitially = showSystemAppsInitially,
        appList = appList,
    )
}
+40 −6
Original line number Diff line number Diff line
@@ -51,8 +51,8 @@ class AppListPageTest {
    }

    @Test
    fun appListState_hasCorrectInitialState() {
        val inputState by setContent()
    fun appListState_hideSystemAppsInitially_hasCorrectInitialState() {
        val inputState by setContent(showSystemAppsInitially = false)

        val state = inputState!!.state
        assertThat(state.showSystem()).isFalse()
@@ -60,8 +60,17 @@ class AppListPageTest {
    }

    @Test
    fun canShowSystem() {
        val inputState by setContent()
    fun appListState_showSystemAppsInitially_hasCorrectInitialState() {
        val inputState by setContent(showSystemAppsInitially = true)

        val state = inputState!!.state
        assertThat(state.showSystem()).isTrue()
        assertThat(state.searchQuery()).isEqualTo("")
    }

    @Test
    fun hideSystemAppsInitially_canShowSystem() {
        val inputState by setContent(showSystemAppsInitially = false)

        onMoreOptions().performClick()
        composeTestRule.onNodeWithText(context.getString(R.string.menu_show_system)).performClick()
@@ -71,8 +80,19 @@ class AppListPageTest {
    }

    @Test
    fun afterShowSystem_displayHideSystem() {
        setContent()
    fun showSystemAppsInitially_canHideSystem() {
        val inputState by setContent(showSystemAppsInitially = true)

        onMoreOptions().performClick()
        composeTestRule.onNodeWithText(context.getString(R.string.menu_hide_system)).performClick()

        val state = inputState!!.state
        assertThat(state.showSystem()).isFalse()
    }

    @Test
    fun hideSystemAppsInitially_afterShowSystem_displayHideSystem() {
        setContent(showSystemAppsInitially = false)
        onMoreOptions().performClick()
        composeTestRule.onNodeWithText(context.getString(R.string.menu_show_system)).performClick()

@@ -82,6 +102,18 @@ class AppListPageTest {
            .assertIsDisplayed()
    }

    @Test
    fun showSystemAppsInitially_afterHideSystem_displayShowSystem() {
        setContent(showSystemAppsInitially = true)
        onMoreOptions().performClick()
        composeTestRule.onNodeWithText(context.getString(R.string.menu_hide_system)).performClick()

        onMoreOptions().performClick()

        composeTestRule.onNodeWithText(context.getString(R.string.menu_show_system))
            .assertIsDisplayed()
    }

    @Test
    fun noMoreOptions_notDisplayMoreOptions() {
        setContent(noMoreOptions = true)
@@ -98,6 +130,7 @@ class AppListPageTest {
    }

    private fun setContent(
        showSystemAppsInitially: Boolean = false,
        noMoreOptions: Boolean = false,
        header: @Composable () -> Unit = {},
    ): State<AppListInput<TestAppRecord>?> {
@@ -106,6 +139,7 @@ class AppListPageTest {
            AppListPage(
                title = TITLE,
                listModel = TestAppListModel(),
                showSystemAppsInitially = showSystemAppsInitially,
                noMoreOptions = noMoreOptions,
                header = header,
                appList = { appListState.value = this },