Don't try to install system apps without APK

during restore process. These can usually not be manually installed anyway and just clutter the list making it harder for the user to find their important apps and potential failures there.
This commit is contained in:
Torsten Grote 2024-05-31 12:16:01 -03:00
parent f408381d18
commit ebf68cfe73
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 29 additions and 0 deletions

View file

@ -63,6 +63,9 @@ internal class ApkRestore(
// The @pm@ package needs to be included in [backup], but can't be installed like an app
if (packageName == MAGIC_PACKAGE_MANAGER) return@mapNotNull null
// we don't filter out apps without APK, so the user can manually install them
// exception is system apps without APK, as those can usually not be installed manually
if (metadata.system && !metadata.hasApk()) return@mapNotNull null
// apps that made it here get a state class for tracking
ApkInstallResult(
packageName = packageName,
state = if (isAllowedToInstallApks) QUEUED else FAILED,

View file

@ -427,6 +427,32 @@ internal class ApkRestoreTest : TransportTest() {
}
}
@Test
fun `system app without APK get filtered out`() = runBlocking {
// only backed up package is a system app without an APK
packageMetadataMap[packageName] = PackageMetadata(
time = 23L,
system = true,
isLaunchableSystemApp = Random.nextBoolean(),
).also { assertFalse(it.hasApk()) }
every { installRestriction.isAllowedToInstallApks() } returns true
every { storagePlugin.providerPackageName } returns storageProviderPackageName
apkRestore.installResult.test {
awaitItem() // initial empty state
apkRestore.restore(backup)
awaitItem().also { finishedItem ->
println(finishedItem.installResults.values.toList())
// the only package provided should have been filtered, leaving 0 packages.
assertEquals(0, finishedItem.total)
assertTrue(finishedItem.isFinished)
}
ensureAllEventsConsumed()
}
}
@Test
fun `no apks get installed when blocked by policy`() = runBlocking {
every { installRestriction.isAllowedToInstallApks() } returns false