Skip to content

Commit

Permalink
Cancel ongoing notification as soon as possible in case system kills …
Browse files Browse the repository at this point in the history
…us fast
  • Loading branch information
grote committed Jun 19, 2024
1 parent 22ca255 commit 3061dcc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ internal class BackupNotificationManager(private val context: Context) {
nm.cancel(NOTIFICATION_ID_OBSERVER)
}

fun cancelObserverNotification() = this::onApkBackupDone

/**
* Call this right after starting a backup.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ internal class NotificationBackupObserver(
* as a whole failed.
*/
override fun backupFinished(status: Int) {
// cancel ongoing notification as first thing because system may kill us any millisecond
if (!backupRequester.hasNext()) nm.cancelObserverNotification()

if (status == ERROR_BACKUP_CANCELLED) {
val packageName = errorPackageName
if (packageName == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ internal class BackupRequester(
}
}

fun hasNext(): Boolean = packageIndex < packages.size

private fun request(chunk: Array<String>): Boolean {
Log.i(TAG, "${chunk.toList()}")
val result = try {
Expand Down

0 comments on commit 3061dcc

Please sign in to comment.