Improve notification progress reporting
It is still somewhat buggy when d2d is on, but this is easier to resolve when moving everything to own scheduling.
This commit is contained in:
parent
86c603e2d2
commit
4014666c15
5 changed files with 44 additions and 23 deletions
|
@ -426,10 +426,12 @@ internal class BackupCoordinator(
|
||||||
val packageName = packageInfo.packageName
|
val packageName = packageInfo.packageName
|
||||||
try {
|
try {
|
||||||
nm.onOptOutAppBackup(packageName, i + 1, notBackedUpPackages.size)
|
nm.onOptOutAppBackup(packageName, i + 1, notBackedUpPackages.size)
|
||||||
val packageState =
|
val packageState = if (packageInfo.isStopped()) WAS_STOPPED else NOT_ALLOWED
|
||||||
if (packageInfo.isStopped()) WAS_STOPPED else NOT_ALLOWED
|
|
||||||
val wasBackedUp = backUpApk(packageInfo, packageState)
|
val wasBackedUp = backUpApk(packageInfo, packageState)
|
||||||
if (!wasBackedUp) {
|
if (wasBackedUp) {
|
||||||
|
Log.d(TAG, "Was backed up: $packageName")
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Not backed up: $packageName - ${packageState.name}")
|
||||||
val packageMetadata =
|
val packageMetadata =
|
||||||
metadataManager.getPackageMetadata(packageName)
|
metadataManager.getPackageMetadata(packageName)
|
||||||
val oldPackageState = packageMetadata?.state
|
val oldPackageState = packageMetadata?.state
|
||||||
|
|
|
@ -38,7 +38,7 @@ internal class BackupRequester(
|
||||||
private val observer = NotificationBackupObserver(
|
private val observer = NotificationBackupObserver(
|
||||||
context = context,
|
context = context,
|
||||||
backupRequester = this,
|
backupRequester = this,
|
||||||
expectedPackages = packages.size,
|
requestedPackages = packages.size,
|
||||||
appTotals = packageService.expectedAppTotals,
|
appTotals = packageService.expectedAppTotals,
|
||||||
)
|
)
|
||||||
private val monitor = BackupMonitor()
|
private val monitor = BackupMonitor()
|
||||||
|
@ -50,6 +50,9 @@ internal class BackupRequester(
|
||||||
*/
|
*/
|
||||||
private var packageIndex: Int = 0
|
private var packageIndex: Int = 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request the backup to happen. Should be called short after constructing this object.
|
||||||
|
*/
|
||||||
fun requestBackup(): Boolean {
|
fun requestBackup(): Boolean {
|
||||||
if (packageIndex != 0) error("requestBackup() called more than once!")
|
if (packageIndex != 0) error("requestBackup() called more than once!")
|
||||||
|
|
||||||
|
|
|
@ -128,16 +128,16 @@ internal class PackageService(
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
get() {
|
get() {
|
||||||
var appsTotal = 0
|
var appsTotal = 0
|
||||||
var appsOptOut = 0
|
var appsNotIncluded = 0
|
||||||
packageManager.getInstalledPackages(GET_INSTRUMENTATION).forEach { packageInfo ->
|
packageManager.getInstalledPackages(GET_INSTRUMENTATION).forEach { packageInfo ->
|
||||||
if (packageInfo.isUserVisible(context)) {
|
if (packageInfo.isUserVisible(context)) {
|
||||||
appsTotal++
|
appsTotal++
|
||||||
if (packageInfo.doesNotGetBackedUp()) {
|
if (packageInfo.doesNotGetBackedUp()) {
|
||||||
appsOptOut++
|
appsNotIncluded++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ExpectedAppTotals(appsTotal, appsOptOut)
|
return ExpectedAppTotals(appsTotal, appsNotIncluded)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVersionName(packageName: String): String? = try {
|
fun getVersionName(packageName: String): String? = try {
|
||||||
|
@ -202,6 +202,7 @@ internal class PackageService(
|
||||||
*/
|
*/
|
||||||
private fun PackageInfo.doesNotGetBackedUp(): Boolean {
|
private fun PackageInfo.doesNotGetBackedUp(): Boolean {
|
||||||
if (packageName == MAGIC_PACKAGE_MANAGER || applicationInfo == null) return true
|
if (packageName == MAGIC_PACKAGE_MANAGER || applicationInfo == null) return true
|
||||||
|
if (packageName == plugin.providerPackageName) return true
|
||||||
return !allowsBackup() || isStopped()
|
return !allowsBackup() || isStopped()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,9 +213,11 @@ internal data class ExpectedAppTotals(
|
||||||
*/
|
*/
|
||||||
val appsTotal: Int,
|
val appsTotal: Int,
|
||||||
/**
|
/**
|
||||||
* The number of non-system apps that has opted-out of backup.
|
* The number of non-system apps that do not get backed up.
|
||||||
|
* These are included here, because we'll at least back up their APKs,
|
||||||
|
* so at least the app itself does get restored.
|
||||||
*/
|
*/
|
||||||
val appsOptOut: Int,
|
val appsNotGettingBackedUp: Int,
|
||||||
)
|
)
|
||||||
|
|
||||||
internal fun PackageInfo.isUserVisible(context: Context): Boolean {
|
internal fun PackageInfo.isUserVisible(context: Context): Boolean {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import com.stevesoltys.seedvault.restore.REQUEST_CODE_UNINSTALL
|
||||||
import com.stevesoltys.seedvault.settings.ACTION_APP_STATUS_LIST
|
import com.stevesoltys.seedvault.settings.ACTION_APP_STATUS_LIST
|
||||||
import com.stevesoltys.seedvault.settings.SettingsActivity
|
import com.stevesoltys.seedvault.settings.SettingsActivity
|
||||||
import com.stevesoltys.seedvault.transport.backup.ExpectedAppTotals
|
import com.stevesoltys.seedvault.transport.backup.ExpectedAppTotals
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
private const val CHANNEL_ID_OBSERVER = "NotificationBackupObserver"
|
private const val CHANNEL_ID_OBSERVER = "NotificationBackupObserver"
|
||||||
private const val CHANNEL_ID_SUCCESS = "NotificationBackupSuccess"
|
private const val CHANNEL_ID_SUCCESS = "NotificationBackupSuccess"
|
||||||
|
@ -92,25 +93,34 @@ internal class BackupNotificationManager(private val context: Context) {
|
||||||
updateBackupNotification(
|
updateBackupNotification(
|
||||||
infoText = "", // This passes quickly, no need to show something here
|
infoText = "", // This passes quickly, no need to show something here
|
||||||
transferred = 0,
|
transferred = 0,
|
||||||
expected = expectedPackages
|
expected = appTotals.appsTotal
|
||||||
)
|
)
|
||||||
expectedApps = expectedPackages
|
expectedApps = expectedPackages
|
||||||
expectedOptOutApps = appTotals.appsOptOut
|
expectedOptOutApps = appTotals.appsNotGettingBackedUp
|
||||||
expectedAppTotals = appTotals
|
expectedAppTotals = appTotals
|
||||||
|
optOutAppsDone = false
|
||||||
|
Log.i(TAG, "onBackupStarted $expectedApps + $expectedOptOutApps = ${appTotals.appsTotal}")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This should get called before [onBackupUpdate].
|
* This should get called before [onBackupUpdate].
|
||||||
|
* In case of d2d backups, this actually gets called some time after
|
||||||
|
* some apps were already backed up, so [onBackupUpdate] was called several times.
|
||||||
*/
|
*/
|
||||||
fun onOptOutAppBackup(packageName: String, transferred: Int, expected: Int) {
|
fun onOptOutAppBackup(packageName: String, transferred: Int, expected: Int) {
|
||||||
if (optOutAppsDone) return
|
if (optOutAppsDone) return
|
||||||
|
|
||||||
val text = "Opt-out APK for $packageName"
|
val text = "APK for $packageName"
|
||||||
if (expectedApps == null) {
|
if (expectedApps == null) {
|
||||||
updateBackgroundBackupNotification(text)
|
updateBackgroundBackupNotification(text)
|
||||||
} else {
|
} else {
|
||||||
updateBackupNotification(text, transferred, expected + (expectedApps ?: 0))
|
updateBackupNotification(text, transferred, expected + (expectedApps ?: 0))
|
||||||
|
if (expectedOptOutApps != null && expectedOptOutApps != expected) {
|
||||||
|
Log.w(TAG, "Number of packages not getting backed up mismatch: " +
|
||||||
|
"$expectedOptOutApps != $expected")
|
||||||
|
}
|
||||||
expectedOptOutApps = expected
|
expectedOptOutApps = expected
|
||||||
|
if (transferred == expected) optOutAppsDone = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,12 +129,11 @@ internal class BackupNotificationManager(private val context: Context) {
|
||||||
* this type is is expected to get called after [onOptOutAppBackup].
|
* this type is is expected to get called after [onOptOutAppBackup].
|
||||||
*/
|
*/
|
||||||
fun onBackupUpdate(app: CharSequence, transferred: Int) {
|
fun onBackupUpdate(app: CharSequence, transferred: Int) {
|
||||||
optOutAppsDone = true
|
|
||||||
val expected = expectedApps ?: error("expectedApps is null")
|
val expected = expectedApps ?: error("expectedApps is null")
|
||||||
val addend = expectedOptOutApps ?: 0
|
val addend = expectedOptOutApps ?: 0
|
||||||
updateBackupNotification(
|
updateBackupNotification(
|
||||||
infoText = app,
|
infoText = app,
|
||||||
transferred = transferred + addend,
|
transferred = min(transferred + addend, expected + addend),
|
||||||
expected = expected + addend
|
expected = expected + addend
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ private val TAG = NotificationBackupObserver::class.java.simpleName
|
||||||
internal class NotificationBackupObserver(
|
internal class NotificationBackupObserver(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val backupRequester: BackupRequester,
|
private val backupRequester: BackupRequester,
|
||||||
private val expectedPackages: Int,
|
private val requestedPackages: Int,
|
||||||
appTotals: ExpectedAppTotals,
|
appTotals: ExpectedAppTotals,
|
||||||
) : IBackupObserver.Stub(), KoinComponent {
|
) : IBackupObserver.Stub(), KoinComponent {
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ internal class NotificationBackupObserver(
|
||||||
init {
|
init {
|
||||||
// Inform the notification manager that a backup has started
|
// Inform the notification manager that a backup has started
|
||||||
// and inform about the expected numbers, so it can compute a total.
|
// and inform about the expected numbers, so it can compute a total.
|
||||||
nm.onBackupStarted(expectedPackages, appTotals)
|
nm.onBackupStarted(requestedPackages, appTotals)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +77,7 @@ internal class NotificationBackupObserver(
|
||||||
override fun backupFinished(status: Int) {
|
override fun backupFinished(status: Int) {
|
||||||
if (backupRequester.requestNext()) {
|
if (backupRequester.requestNext()) {
|
||||||
if (isLoggable(TAG, INFO)) {
|
if (isLoggable(TAG, INFO)) {
|
||||||
Log.i(TAG, "Backup finished $numPackages/$expectedPackages. Status: $status")
|
Log.i(TAG, "Backup finished $numPackages/$requestedPackages. Status: $status")
|
||||||
}
|
}
|
||||||
val success = status == 0
|
val success = status == 0
|
||||||
val numBackedUp = if (success) metadataManager.getPackagesNumBackedUp() else null
|
val numBackedUp = if (success) metadataManager.getPackagesNumBackedUp() else null
|
||||||
|
@ -89,13 +89,17 @@ internal class NotificationBackupObserver(
|
||||||
private fun showProgressNotification(packageName: String?) {
|
private fun showProgressNotification(packageName: String?) {
|
||||||
if (packageName == null || currentPackage == packageName) return
|
if (packageName == null || currentPackage == packageName) return
|
||||||
|
|
||||||
if (isLoggable(TAG, INFO)) {
|
if (isLoggable(TAG, INFO)) Log.i(
|
||||||
"Showing progress notification for $currentPackage $numPackages/$expectedPackages".let {
|
TAG, "Showing progress notification for " +
|
||||||
Log.i(TAG, it)
|
"$currentPackage $numPackages/$requestedPackages"
|
||||||
}
|
)
|
||||||
}
|
|
||||||
currentPackage = packageName
|
currentPackage = packageName
|
||||||
val app = getAppName(packageName)
|
val appName = getAppName(packageName)
|
||||||
|
val app = if (appName != packageName) {
|
||||||
|
"${getAppName(packageName)} ($packageName)"
|
||||||
|
} else {
|
||||||
|
packageName
|
||||||
|
}
|
||||||
numPackages += 1
|
numPackages += 1
|
||||||
nm.onBackupUpdate(app, numPackages)
|
nm.onBackupUpdate(app, numPackages)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue