From 848ed51de4441863ac4f7dcce74a774fa4db47ba Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 8 Sep 2022 17:40:41 -0300 Subject: [PATCH 1/2] Expect ApplicationInfo#splitSourceDirs to be null Also handle errors like these a bit better --- .../stevesoltys/seedvault/transport/backup/ApkBackup.kt | 3 ++- .../seedvault/transport/backup/BackupCoordinator.kt | 8 +++++++- .../stevesoltys/seedvault/transport/backup/KVBackup.kt | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt index 60c9c9aa..02208eb0 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/ApkBackup.kt @@ -154,7 +154,8 @@ internal class ApkBackup( streamGetter: suspend (name: String) -> OutputStream, ): List { check(packageInfo.splitNames != null) - val splitSourceDirs = packageInfo.applicationInfo.splitSourceDirs + // attention: though not documented, splitSourceDirs can be null + val splitSourceDirs = packageInfo.applicationInfo.splitSourceDirs ?: emptyArray() check(packageInfo.splitNames.size == splitSourceDirs.size) { "Size Mismatch! ${packageInfo.splitNames.size} != ${splitSourceDirs.size} " + "splitNames is ${packageInfo.splitNames.toList()}, " + diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt index ac779830..5d791fc4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt @@ -381,7 +381,13 @@ internal class BackupCoordinator( } // hook in here to back up APKs of apps that are otherwise not allowed for backup if (isPmBackup && settingsManager.canDoBackupNow()) { - backUpApksOfNotBackedUpPackages() + try { + backUpApksOfNotBackedUpPackages() + } catch (e: Exception) { + Log.e(TAG, "Error backing up APKs of opt-out apps: ", e) + // We are re-throwing this, because we want to know about problems here + throw e + } } } result diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt index dd89cad8..060f5431 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/KVBackup.kt @@ -209,6 +209,7 @@ internal class KVBackup( else state.db.close() TRANSPORT_OK } catch (e: IOException) { + Log.e(TAG, "Error uploading DB", e) TRANSPORT_ERROR } finally { this.state = null From dfc9aeee28952435bbc0801142c0632eee3512f0 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Thu, 8 Sep 2022 17:45:17 -0300 Subject: [PATCH 2/2] Expect BackupObserver to be called with null packages --- .../ui/notification/NotificationBackupObserver.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt index 6eb60079..d35971fc 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/notification/NotificationBackupObserver.kt @@ -43,7 +43,7 @@ internal class NotificationBackupObserver( * @param currentBackupPackage The name of the package that now being backed up. * @param backupProgress Current progress of backup for the package. */ - override fun onUpdate(currentBackupPackage: String, backupProgress: BackupProgress) { + override fun onUpdate(currentBackupPackage: String?, backupProgress: BackupProgress) { showProgressNotification(currentBackupPackage) } @@ -57,7 +57,7 @@ internal class NotificationBackupObserver( * that was initialized * @param status Zero on success; a nonzero error code if the backup operation failed. */ - override fun onResult(target: String, status: Int) { + override fun onResult(target: String?, status: Int) { if (isLoggable(TAG, INFO)) { Log.i(TAG, "Completed. Target: $target, status: $status") } @@ -81,8 +81,8 @@ internal class NotificationBackupObserver( nm.onBackupFinished(success, numBackedUp) } - private fun showProgressNotification(packageName: String) { - if (currentPackage == packageName) return + private fun showProgressNotification(packageName: String?) { + if (packageName == null || currentPackage == packageName) return if (isLoggable(TAG, INFO)) { "Showing progress notification for $currentPackage $numPackages/$expectedPackages".let {