Loading packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListRepository.kt +17 −14 Original line number Diff line number Diff line Loading @@ -34,11 +34,11 @@ import kotlinx.coroutines.runBlocking /** * The repository to load the App List data. */ internal interface AppListRepository { interface AppListRepository { /** Loads the list of [ApplicationInfo]. */ suspend fun loadApps( userId: Int, showInstantApps: Boolean = false, loadInstantApps: Boolean = false, matchAnyUserForAdmin: Boolean = false, ): List<ApplicationInfo> Loading @@ -50,6 +50,9 @@ internal interface AppListRepository { /** Gets the system app package names. */ fun getSystemPackageNamesBlocking(userId: Int): Set<String> /** Loads the list of [ApplicationInfo], and filter base on `isSystemApp`. */ suspend fun loadAndFilterApps(userId: Int, isSystemApp: Boolean): List<ApplicationInfo> } /** Loading @@ -62,13 +65,13 @@ object AppListRepositoryUtil { AppListRepositoryImpl(context).getSystemPackageNamesBlocking(userId) } internal class AppListRepositoryImpl(private val context: Context) : AppListRepository { class AppListRepositoryImpl(private val context: Context) : AppListRepository { private val packageManager = context.packageManager private val userManager = context.userManager override suspend fun loadApps( userId: Int, showInstantApps: Boolean, loadInstantApps: Boolean, matchAnyUserForAdmin: Boolean, ): List<ApplicationInfo> = coroutineScope { val hiddenSystemModulesDeferred = async { Loading @@ -86,7 +89,7 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo val hiddenSystemModules = hiddenSystemModulesDeferred.await() val hideWhenDisabledPackages = hideWhenDisabledPackagesDeferred.await() installedApplicationsAsUser.filter { app -> app.isInAppList(showInstantApps, hiddenSystemModules, hideWhenDisabledPackages) app.isInAppList(loadInstantApps, hiddenSystemModules, hideWhenDisabledPackages) } } Loading Loading @@ -136,16 +139,16 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo ): Flow<(app: ApplicationInfo) -> Boolean> = userIdFlow.combine(showSystemFlow, ::showSystemPredicate) override fun getSystemPackageNamesBlocking(userId: Int) = runBlocking { getSystemPackageNames(userId) } override fun getSystemPackageNamesBlocking(userId: Int) = runBlocking { loadAndFilterApps(userId = userId, isSystemApp = true).map { it.packageName }.toSet() } private suspend fun getSystemPackageNames(userId: Int): Set<String> = coroutineScope { override suspend fun loadAndFilterApps(userId: Int, isSystemApp: Boolean) = coroutineScope { val loadAppsDeferred = async { loadApps(userId) } val homeOrLauncherPackages = loadHomeOrLauncherPackages(userId) val showSystemPredicate = { app: ApplicationInfo -> isSystemApp(app, homeOrLauncherPackages) } loadAppsDeferred.await().filter(showSystemPredicate).map { it.packageName }.toSet() loadAppsDeferred.await().filter { app -> isSystemApp(app, homeOrLauncherPackages) == isSystemApp } } private suspend fun showSystemPredicate( Loading packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListRepositoryTest.kt +17 −2 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ class AppListRepositoryTest { val appList = repository.loadApps( userId = ADMIN_USER_ID, showInstantApps = false, loadInstantApps = false, ) assertThat(appList).containsExactly(NORMAL_APP) Loading @@ -120,7 +120,7 @@ class AppListRepositoryTest { val appList = repository.loadApps( userId = ADMIN_USER_ID, showInstantApps = true, loadInstantApps = true, ) assertThat(appList).containsExactly(NORMAL_APP, INSTANT_APP) Loading Loading @@ -325,6 +325,21 @@ class AppListRepositoryTest { assertThat(systemPackageNames).containsExactly(SYSTEM_APP.packageName) } @Test fun loadAndFilterApps_loadNonSystemApp_returnExpectedValues() = runTest { mockInstalledApplications( apps = listOf( NORMAL_APP, INSTANT_APP, SYSTEM_APP, UPDATED_SYSTEM_APP, HOME_APP, IN_LAUNCHER_APP ), userId = ADMIN_USER_ID, ) val appList = repository.loadAndFilterApps(userId = ADMIN_USER_ID, isSystemApp = false) assertThat(appList) .containsExactly(NORMAL_APP, UPDATED_SYSTEM_APP, HOME_APP, IN_LAUNCHER_APP) } private suspend fun getShowSystemPredicate(showSystem: Boolean) = repository.showSystemPredicate( userIdFlow = flowOf(ADMIN_USER_ID), Loading packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListViewModelTest.kt +4 −1 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ class AppListViewModelTest { private object FakeAppListRepository : AppListRepository { override suspend fun loadApps( userId: Int, showInstantApps: Boolean, loadInstantApps: Boolean, matchAnyUserForAdmin: Boolean, ) = listOf(APP) Loading @@ -97,6 +97,9 @@ class AppListViewModelTest { ): Flow<(app: ApplicationInfo) -> Boolean> = flowOf { true } override fun getSystemPackageNamesBlocking(userId: Int): Set<String> = emptySet() override suspend fun loadAndFilterApps(userId: Int, isSystemApp: Boolean) = emptyList<ApplicationInfo>() } private object FakeAppRepository : AppRepository { Loading Loading
packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListRepository.kt +17 −14 Original line number Diff line number Diff line Loading @@ -34,11 +34,11 @@ import kotlinx.coroutines.runBlocking /** * The repository to load the App List data. */ internal interface AppListRepository { interface AppListRepository { /** Loads the list of [ApplicationInfo]. */ suspend fun loadApps( userId: Int, showInstantApps: Boolean = false, loadInstantApps: Boolean = false, matchAnyUserForAdmin: Boolean = false, ): List<ApplicationInfo> Loading @@ -50,6 +50,9 @@ internal interface AppListRepository { /** Gets the system app package names. */ fun getSystemPackageNamesBlocking(userId: Int): Set<String> /** Loads the list of [ApplicationInfo], and filter base on `isSystemApp`. */ suspend fun loadAndFilterApps(userId: Int, isSystemApp: Boolean): List<ApplicationInfo> } /** Loading @@ -62,13 +65,13 @@ object AppListRepositoryUtil { AppListRepositoryImpl(context).getSystemPackageNamesBlocking(userId) } internal class AppListRepositoryImpl(private val context: Context) : AppListRepository { class AppListRepositoryImpl(private val context: Context) : AppListRepository { private val packageManager = context.packageManager private val userManager = context.userManager override suspend fun loadApps( userId: Int, showInstantApps: Boolean, loadInstantApps: Boolean, matchAnyUserForAdmin: Boolean, ): List<ApplicationInfo> = coroutineScope { val hiddenSystemModulesDeferred = async { Loading @@ -86,7 +89,7 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo val hiddenSystemModules = hiddenSystemModulesDeferred.await() val hideWhenDisabledPackages = hideWhenDisabledPackagesDeferred.await() installedApplicationsAsUser.filter { app -> app.isInAppList(showInstantApps, hiddenSystemModules, hideWhenDisabledPackages) app.isInAppList(loadInstantApps, hiddenSystemModules, hideWhenDisabledPackages) } } Loading Loading @@ -136,16 +139,16 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo ): Flow<(app: ApplicationInfo) -> Boolean> = userIdFlow.combine(showSystemFlow, ::showSystemPredicate) override fun getSystemPackageNamesBlocking(userId: Int) = runBlocking { getSystemPackageNames(userId) } override fun getSystemPackageNamesBlocking(userId: Int) = runBlocking { loadAndFilterApps(userId = userId, isSystemApp = true).map { it.packageName }.toSet() } private suspend fun getSystemPackageNames(userId: Int): Set<String> = coroutineScope { override suspend fun loadAndFilterApps(userId: Int, isSystemApp: Boolean) = coroutineScope { val loadAppsDeferred = async { loadApps(userId) } val homeOrLauncherPackages = loadHomeOrLauncherPackages(userId) val showSystemPredicate = { app: ApplicationInfo -> isSystemApp(app, homeOrLauncherPackages) } loadAppsDeferred.await().filter(showSystemPredicate).map { it.packageName }.toSet() loadAppsDeferred.await().filter { app -> isSystemApp(app, homeOrLauncherPackages) == isSystemApp } } private suspend fun showSystemPredicate( Loading
packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListRepositoryTest.kt +17 −2 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ class AppListRepositoryTest { val appList = repository.loadApps( userId = ADMIN_USER_ID, showInstantApps = false, loadInstantApps = false, ) assertThat(appList).containsExactly(NORMAL_APP) Loading @@ -120,7 +120,7 @@ class AppListRepositoryTest { val appList = repository.loadApps( userId = ADMIN_USER_ID, showInstantApps = true, loadInstantApps = true, ) assertThat(appList).containsExactly(NORMAL_APP, INSTANT_APP) Loading Loading @@ -325,6 +325,21 @@ class AppListRepositoryTest { assertThat(systemPackageNames).containsExactly(SYSTEM_APP.packageName) } @Test fun loadAndFilterApps_loadNonSystemApp_returnExpectedValues() = runTest { mockInstalledApplications( apps = listOf( NORMAL_APP, INSTANT_APP, SYSTEM_APP, UPDATED_SYSTEM_APP, HOME_APP, IN_LAUNCHER_APP ), userId = ADMIN_USER_ID, ) val appList = repository.loadAndFilterApps(userId = ADMIN_USER_ID, isSystemApp = false) assertThat(appList) .containsExactly(NORMAL_APP, UPDATED_SYSTEM_APP, HOME_APP, IN_LAUNCHER_APP) } private suspend fun getShowSystemPredicate(showSystem: Boolean) = repository.showSystemPredicate( userIdFlow = flowOf(ADMIN_USER_ID), Loading
packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListViewModelTest.kt +4 −1 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ class AppListViewModelTest { private object FakeAppListRepository : AppListRepository { override suspend fun loadApps( userId: Int, showInstantApps: Boolean, loadInstantApps: Boolean, matchAnyUserForAdmin: Boolean, ) = listOf(APP) Loading @@ -97,6 +97,9 @@ class AppListViewModelTest { ): Flow<(app: ApplicationInfo) -> Boolean> = flowOf { true } override fun getSystemPackageNamesBlocking(userId: Int): Set<String> = emptySet() override suspend fun loadAndFilterApps(userId: Int, isSystemApp: Boolean) = emptyList<ApplicationInfo>() } private object FakeAppRepository : AppRepository { Loading