Loading packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListRepository.kt +9 −15 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ internal interface AppListRepository { ): Flow<(app: ApplicationInfo) -> Boolean> /** Gets the system app package names. */ fun getSystemPackageNamesBlocking(userId: Int, showInstantApps: Boolean): Set<String> fun getSystemPackageNamesBlocking(userId: Int): Set<String> } /** Loading @@ -58,12 +58,8 @@ internal interface AppListRepository { object AppListRepositoryUtil { /** Gets the system app package names. */ @JvmStatic fun getSystemPackageNames( context: Context, userId: Int, showInstantApps: Boolean, ): Set<String> = AppListRepositoryImpl(context).getSystemPackageNamesBlocking(userId, showInstantApps) fun getSystemPackageNames(context: Context, userId: Int): Set<String> = AppListRepositoryImpl(context).getSystemPackageNamesBlocking(userId) } internal class AppListRepositoryImpl(private val context: Context) : AppListRepository { Loading Loading @@ -140,12 +136,12 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo ): Flow<(app: ApplicationInfo) -> Boolean> = userIdFlow.combine(showSystemFlow, ::showSystemPredicate) override fun getSystemPackageNamesBlocking(userId: Int, showInstantApps: Boolean) = runBlocking { getSystemPackageNames(userId, showInstantApps) } override fun getSystemPackageNamesBlocking(userId: Int) = runBlocking { getSystemPackageNames(userId) } private suspend fun getSystemPackageNames(userId: Int, showInstantApps: Boolean): Set<String> = private suspend fun getSystemPackageNames(userId: Int): Set<String> = coroutineScope { val loadAppsDeferred = async { loadApps(userId, showInstantApps) } val loadAppsDeferred = async { loadApps(userId) } val homeOrLauncherPackages = loadHomeOrLauncherPackages(userId) val showSystemPredicate = { app: ApplicationInfo -> isSystemApp(app, homeOrLauncherPackages) } Loading Loading @@ -184,10 +180,8 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo } } private fun isSystemApp(app: ApplicationInfo, homeOrLauncherPackages: Set<String>): Boolean { return !app.isUpdatedSystemApp && app.isSystemApp && !(app.packageName in homeOrLauncherPackages) } private fun isSystemApp(app: ApplicationInfo, homeOrLauncherPackages: Set<String>): Boolean = app.isSystemApp && !app.isUpdatedSystemApp && app.packageName !in homeOrLauncherPackages companion object { private fun ApplicationInfo.isInAppList( Loading packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListRepositoryTest.kt +10 −24 Original line number Diff line number Diff line Loading @@ -78,9 +78,15 @@ class AppListRepositoryTest { whenever(context.packageManager).thenReturn(packageManager) whenever(context.userManager).thenReturn(userManager) whenever(packageManager.getInstalledModules(anyInt())).thenReturn(emptyList()) whenever(packageManager.getHomeActivities(any())).thenAnswer { @Suppress("UNCHECKED_CAST") val resolveInfos = it.arguments[0] as MutableList<ResolveInfo> resolveInfos += resolveInfoOf(packageName = HOME_APP.packageName) null } whenever( packageManager.queryIntentActivitiesAsUser(any(), any<ResolveInfoFlags>(), anyInt()) ).thenReturn(emptyList()) ).thenReturn(listOf(resolveInfoOf(packageName = IN_LAUNCHER_APP.packageName))) whenever(userManager.getUserInfo(ADMIN_USER_ID)).thenReturn(UserInfo().apply { flags = UserInfo.FLAG_ADMIN }) Loading Loading @@ -290,35 +296,16 @@ class AppListRepositoryTest { @Test fun showSystemPredicate_isHome() = runTest { val app = HOME_APP whenever(packageManager.getHomeActivities(any())).thenAnswer { @Suppress("UNCHECKED_CAST") val resolveInfos = it.arguments[0] as MutableList<ResolveInfo> resolveInfos.add(resolveInfoOf(packageName = app.packageName)) null } val showSystemPredicate = getShowSystemPredicate(showSystem = false) assertThat(showSystemPredicate(app)).isTrue() assertThat(showSystemPredicate(HOME_APP)).isTrue() } @Test fun showSystemPredicate_appInLauncher() = runTest { val app = IN_LAUNCHER_APP whenever( packageManager.queryIntentActivitiesAsUser( any(), any<ResolveInfoFlags>(), eq(ADMIN_USER_ID) ) ).thenReturn(listOf(resolveInfoOf(packageName = app.packageName))) val showSystemPredicate = getShowSystemPredicate(showSystem = false) assertThat(showSystemPredicate(app)).isTrue() assertThat(showSystemPredicate(IN_LAUNCHER_APP)).isTrue() } @Test Loading @@ -333,10 +320,9 @@ class AppListRepositoryTest { val systemPackageNames = AppListRepositoryUtil.getSystemPackageNames( context = context, userId = ADMIN_USER_ID, showInstantApps = false, ) assertThat(systemPackageNames).containsExactly("system.app", "home.app", "app.in.launcher") assertThat(systemPackageNames).containsExactly(SYSTEM_APP.packageName) } private suspend fun getShowSystemPredicate(showSystem: Boolean) = Loading packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListViewModelTest.kt +1 −4 Original line number Diff line number Diff line Loading @@ -96,10 +96,7 @@ class AppListViewModelTest { showSystemFlow: Flow<Boolean>, ): Flow<(app: ApplicationInfo) -> Boolean> = flowOf { true } override fun getSystemPackageNamesBlocking( userId: Int, showInstantApps: Boolean, ): Set<String> = emptySet() override fun getSystemPackageNamesBlocking(userId: Int): Set<String> = emptySet() } private object FakeAppRepository : AppRepository { Loading Loading
packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/model/app/AppListRepository.kt +9 −15 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ internal interface AppListRepository { ): Flow<(app: ApplicationInfo) -> Boolean> /** Gets the system app package names. */ fun getSystemPackageNamesBlocking(userId: Int, showInstantApps: Boolean): Set<String> fun getSystemPackageNamesBlocking(userId: Int): Set<String> } /** Loading @@ -58,12 +58,8 @@ internal interface AppListRepository { object AppListRepositoryUtil { /** Gets the system app package names. */ @JvmStatic fun getSystemPackageNames( context: Context, userId: Int, showInstantApps: Boolean, ): Set<String> = AppListRepositoryImpl(context).getSystemPackageNamesBlocking(userId, showInstantApps) fun getSystemPackageNames(context: Context, userId: Int): Set<String> = AppListRepositoryImpl(context).getSystemPackageNamesBlocking(userId) } internal class AppListRepositoryImpl(private val context: Context) : AppListRepository { Loading Loading @@ -140,12 +136,12 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo ): Flow<(app: ApplicationInfo) -> Boolean> = userIdFlow.combine(showSystemFlow, ::showSystemPredicate) override fun getSystemPackageNamesBlocking(userId: Int, showInstantApps: Boolean) = runBlocking { getSystemPackageNames(userId, showInstantApps) } override fun getSystemPackageNamesBlocking(userId: Int) = runBlocking { getSystemPackageNames(userId) } private suspend fun getSystemPackageNames(userId: Int, showInstantApps: Boolean): Set<String> = private suspend fun getSystemPackageNames(userId: Int): Set<String> = coroutineScope { val loadAppsDeferred = async { loadApps(userId, showInstantApps) } val loadAppsDeferred = async { loadApps(userId) } val homeOrLauncherPackages = loadHomeOrLauncherPackages(userId) val showSystemPredicate = { app: ApplicationInfo -> isSystemApp(app, homeOrLauncherPackages) } Loading Loading @@ -184,10 +180,8 @@ internal class AppListRepositoryImpl(private val context: Context) : AppListRepo } } private fun isSystemApp(app: ApplicationInfo, homeOrLauncherPackages: Set<String>): Boolean { return !app.isUpdatedSystemApp && app.isSystemApp && !(app.packageName in homeOrLauncherPackages) } private fun isSystemApp(app: ApplicationInfo, homeOrLauncherPackages: Set<String>): Boolean = app.isSystemApp && !app.isUpdatedSystemApp && app.packageName !in homeOrLauncherPackages companion object { private fun ApplicationInfo.isInAppList( Loading
packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListRepositoryTest.kt +10 −24 Original line number Diff line number Diff line Loading @@ -78,9 +78,15 @@ class AppListRepositoryTest { whenever(context.packageManager).thenReturn(packageManager) whenever(context.userManager).thenReturn(userManager) whenever(packageManager.getInstalledModules(anyInt())).thenReturn(emptyList()) whenever(packageManager.getHomeActivities(any())).thenAnswer { @Suppress("UNCHECKED_CAST") val resolveInfos = it.arguments[0] as MutableList<ResolveInfo> resolveInfos += resolveInfoOf(packageName = HOME_APP.packageName) null } whenever( packageManager.queryIntentActivitiesAsUser(any(), any<ResolveInfoFlags>(), anyInt()) ).thenReturn(emptyList()) ).thenReturn(listOf(resolveInfoOf(packageName = IN_LAUNCHER_APP.packageName))) whenever(userManager.getUserInfo(ADMIN_USER_ID)).thenReturn(UserInfo().apply { flags = UserInfo.FLAG_ADMIN }) Loading Loading @@ -290,35 +296,16 @@ class AppListRepositoryTest { @Test fun showSystemPredicate_isHome() = runTest { val app = HOME_APP whenever(packageManager.getHomeActivities(any())).thenAnswer { @Suppress("UNCHECKED_CAST") val resolveInfos = it.arguments[0] as MutableList<ResolveInfo> resolveInfos.add(resolveInfoOf(packageName = app.packageName)) null } val showSystemPredicate = getShowSystemPredicate(showSystem = false) assertThat(showSystemPredicate(app)).isTrue() assertThat(showSystemPredicate(HOME_APP)).isTrue() } @Test fun showSystemPredicate_appInLauncher() = runTest { val app = IN_LAUNCHER_APP whenever( packageManager.queryIntentActivitiesAsUser( any(), any<ResolveInfoFlags>(), eq(ADMIN_USER_ID) ) ).thenReturn(listOf(resolveInfoOf(packageName = app.packageName))) val showSystemPredicate = getShowSystemPredicate(showSystem = false) assertThat(showSystemPredicate(app)).isTrue() assertThat(showSystemPredicate(IN_LAUNCHER_APP)).isTrue() } @Test Loading @@ -333,10 +320,9 @@ class AppListRepositoryTest { val systemPackageNames = AppListRepositoryUtil.getSystemPackageNames( context = context, userId = ADMIN_USER_ID, showInstantApps = false, ) assertThat(systemPackageNames).containsExactly("system.app", "home.app", "app.in.launcher") assertThat(systemPackageNames).containsExactly(SYSTEM_APP.packageName) } private suspend fun getShowSystemPredicate(showSystem: Boolean) = Loading
packages/SettingsLib/SpaPrivileged/tests/src/com/android/settingslib/spaprivileged/model/app/AppListViewModelTest.kt +1 −4 Original line number Diff line number Diff line Loading @@ -96,10 +96,7 @@ class AppListViewModelTest { showSystemFlow: Flow<Boolean>, ): Flow<(app: ApplicationInfo) -> Boolean> = flowOf { true } override fun getSystemPackageNamesBlocking( userId: Int, showInstantApps: Boolean, ): Set<String> = emptySet() override fun getSystemPackageNamesBlocking(userId: Int): Set<String> = emptySet() } private object FakeAppRepository : AppRepository { Loading