During restore, show apps without APK as failed

Previously, we backed up APKs of apps we could not back up (even if APK backup was disabled) so the user had a chance to get at least the apps back when restoring. Now, it is enough to record metadata about the app and the user will be able to manually install the app. The install apps step won't be skipped anymore.
This commit is contained in:
Torsten Grote 2024-02-22 09:41:53 -03:00
parent 6e7bc89e2f
commit e615402458
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
2 changed files with 9 additions and 7 deletions

View file

@ -38,14 +38,12 @@ internal class ApkRestore(
private val pm = context.packageManager
@Suppress("BlockingMethodInNonBlockingContext")
fun restore(backup: RestorableBackup) = flow {
// filter out packages without APK and get total
// we don't filter out apps without APK, so the user can manually install them
val packages = backup.packageMetadataMap.filter {
// We also need to exclude the DocumentsProvider used to retrieve backup data.
// We need to exclude the DocumentsProvider used to retrieve backup data.
// Otherwise, it gets killed when we install it, terminating our restoration.
val isStorageProvider = it.key == storagePlugin.providerPackageName
it.value.hasApk() && !isStorageProvider
it.key != storagePlugin.providerPackageName
}
val total = packages.size
var progress = 0
@ -66,7 +64,11 @@ internal class ApkRestore(
// re-install individual packages and emit updates
for ((packageName, metadata) in packages) {
try {
restore(this, backup, packageName, metadata, installResult)
if (metadata.hasApk()) {
restore(this, backup, packageName, metadata, installResult)
} else {
emit(installResult.fail(packageName))
}
} catch (e: IOException) {
Log.e(TAG, "Error re-installing APK for $packageName.", e)
emit(installResult.fail(packageName))

View file

@ -102,7 +102,7 @@ internal class BackupRequester(
(packageIndex + NUM_PACKAGES_PER_TRANSACTION).coerceAtMost(packages.size)
val packageChunk = packages.subList(packageIndex, nextChunkIndex).toTypedArray()
val numBackingUp = packageIndex + packageChunk.size
Log.i(TAG, "Requesting backup for $numBackingUp/${packages.size} packages...")
Log.i(TAG, "Requesting backup for $numBackingUp of ${packages.size} packages...")
packageIndex += packageChunk.size
return packageChunk
}