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

Commit ee351182 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Add AppListPage.showSystemAppsInitially

Default false. If true, show system apps initially.

Bug: 357790508
Flag: EXEMPT bug fix
Test: unit test
Change-Id: I1f4d943da7c4329d10f0368a13db9cb9afed7c4f
parent 3bd7f0c3
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 },