Skip to content

Commit

Permalink
Don't try to install system apps without APK
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grote committed May 31, 2024
1 parent f408381 commit ebf68cf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ebf68cf

Please sign in to comment.