Skip to content

Commit

Permalink
During restore, show apps without APK as failed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
grote committed Feb 22, 2024
1 parent 82e7057 commit eb159cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit eb159cb

Please sign in to comment.