Merge "Update AppListRepository getSystemPackageNames" into udc-dev
This commit is contained in:
@@ -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>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -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 {
|
||||
@@ -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) }
|
||||
@@ -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(
|
||||
|
||||
@@ -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
|
||||
})
|
||||
@@ -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
|
||||
@@ -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) =
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user