Show when package restore failed
This commit is contained in:
parent
9f01d09962
commit
5632f11878
4 changed files with 36 additions and 8 deletions
|
@ -35,16 +35,25 @@ internal class RestoreProgressAdapter : Adapter<PackageViewHolder>() {
|
|||
holder.bind(items[position], position == 0)
|
||||
}
|
||||
|
||||
fun getLatest(): AppRestoreResult {
|
||||
return items[0]
|
||||
}
|
||||
|
||||
fun setLatestFailed() {
|
||||
items[0] = AppRestoreResult(items[0].packageName, false)
|
||||
notifyItemChanged(0, items[0])
|
||||
}
|
||||
|
||||
fun add(item: AppRestoreResult) {
|
||||
items.addFirst(item)
|
||||
notifyItemInserted(0)
|
||||
notifyItemRangeChanged(1, items.size - 1)
|
||||
}
|
||||
|
||||
fun setComplete(): LinkedList<AppRestoreResult> {
|
||||
fun setComplete(): List<String> {
|
||||
isComplete = true
|
||||
notifyItemChanged(0)
|
||||
return items
|
||||
return items.map { it.packageName }
|
||||
}
|
||||
|
||||
inner class PackageViewHolder(v: View) : ViewHolder(v) {
|
||||
|
|
|
@ -53,20 +53,23 @@ class RestoreProgressFragment : Fragment() {
|
|||
|
||||
viewModel.restoreProgress.observe(this, Observer { currentPackage ->
|
||||
stayScrolledAtTop {
|
||||
val latest = adapter.getLatest()
|
||||
if (viewModel.isFailedPackage(latest.packageName)) {
|
||||
adapter.setLatestFailed()
|
||||
}
|
||||
adapter.add(AppRestoreResult(currentPackage, true))
|
||||
}
|
||||
})
|
||||
|
||||
viewModel.restoreBackupResult.observe(this, Observer { finished ->
|
||||
val list = adapter.setComplete()
|
||||
val seenPackages = adapter.setComplete()
|
||||
stayScrolledAtTop {
|
||||
// add missing packages as failed
|
||||
val restorableBackup = viewModel.chosenRestorableBackup.value!!
|
||||
val expectedPackages = restorableBackup.packageMetadataMap.keys
|
||||
expectedPackages.removeAll(seenPackages)
|
||||
for (packageName: String in expectedPackages) {
|
||||
if (AppRestoreResult(packageName, true) !in list) {
|
||||
adapter.add(AppRestoreResult(packageName, false))
|
||||
}
|
||||
adapter.add(AppRestoreResult(packageName, false))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,6 +164,8 @@ internal class RestoreViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
fun isFailedPackage(packageName: String) = restoreCoordinator.isFailedPackage(packageName)
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
closeSession()
|
||||
|
|
|
@ -20,7 +20,8 @@ import java.io.IOException
|
|||
|
||||
private class RestoreCoordinatorState(
|
||||
internal val token: Long,
|
||||
internal val packages: Iterator<PackageInfo>)
|
||||
internal val packages: Iterator<PackageInfo>,
|
||||
internal var currentPackage: String? = null)
|
||||
|
||||
private val TAG = RestoreCoordinator::class.java.simpleName
|
||||
|
||||
|
@ -33,6 +34,7 @@ internal class RestoreCoordinator(
|
|||
|
||||
private var state: RestoreCoordinatorState? = null
|
||||
private var backupMetadata: LongSparseArray<BackupMetadata>? = null
|
||||
private val failedPackages = ArrayList<String>()
|
||||
|
||||
/**
|
||||
* Get the set of all backups currently available over this transport.
|
||||
|
@ -103,6 +105,7 @@ internal class RestoreCoordinator(
|
|||
check(state == null) { "Started new restore with existing state" }
|
||||
Log.i(TAG, "Start restore with ${packages.map { info -> info.packageName }}")
|
||||
state = RestoreCoordinatorState(token, packages.iterator())
|
||||
failedPackages.clear()
|
||||
return TRANSPORT_OK
|
||||
}
|
||||
|
||||
|
@ -146,11 +149,13 @@ internal class RestoreCoordinator(
|
|||
kv.hasDataForPackage(state.token, packageInfo) -> {
|
||||
Log.i(TAG, "Found K/V data for $packageName.")
|
||||
kv.initializeState(state.token, packageInfo)
|
||||
state.currentPackage = packageName
|
||||
TYPE_KEY_VALUE
|
||||
}
|
||||
full.hasDataForPackage(state.token, packageInfo) -> {
|
||||
Log.i(TAG, "Found full backup data for $packageName.")
|
||||
full.initializeState(state.token, packageInfo)
|
||||
state.currentPackage = packageName
|
||||
TYPE_FULL_STREAM
|
||||
}
|
||||
else -> {
|
||||
|
@ -160,6 +165,7 @@ internal class RestoreCoordinator(
|
|||
}
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Error finding restore data for $packageName.", e)
|
||||
failedPackages.add(packageName)
|
||||
return null
|
||||
}
|
||||
return RestoreDescription(packageName, type)
|
||||
|
@ -174,7 +180,12 @@ internal class RestoreCoordinator(
|
|||
* @return the same error codes as [startRestore].
|
||||
*/
|
||||
fun getRestoreData(data: ParcelFileDescriptor): Int {
|
||||
return kv.getRestoreData(data)
|
||||
return kv.getRestoreData(data).apply {
|
||||
if (this != TRANSPORT_OK) {
|
||||
// add current package to failed ones
|
||||
state?.currentPackage?.let { failedPackages.add(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,6 +206,7 @@ internal class RestoreCoordinator(
|
|||
* or will call [finishRestore] to shut down the restore operation.
|
||||
*/
|
||||
fun abortFullRestore(): Int {
|
||||
state?.currentPackage?.let { failedPackages.add(it) }
|
||||
return full.abortFullRestore()
|
||||
}
|
||||
|
||||
|
@ -218,4 +230,6 @@ internal class RestoreCoordinator(
|
|||
return result
|
||||
}
|
||||
|
||||
fun isFailedPackage(packageName: String) = packageName in failedPackages
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue