Skip to content

Commit

Permalink
Show success notification in a separate notification channel
Browse files Browse the repository at this point in the history
so the user can disable it. This will be more of an issue now that it comes also for scheduled background backups.
  • Loading branch information
grote committed Feb 1, 2024
1 parent d361767 commit daf3ed3
Show file tree
Hide file tree
Showing 32 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ internal class MetadataManager(
}.count()
}

@Synchronized
fun getPackagesBackupSize(): Long {
return metadata.packageMetadataMap.values.sumOf { it.size ?: 0L }
}

@Synchronized
@VisibleForTesting
private fun getMetadataFromCache(): BackupMetadata? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.app.PendingIntent.FLAG_UPDATE_CURRENT
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager.NameNotFoundException
import android.text.format.Formatter
import android.util.Log
import androidx.core.app.NotificationCompat.Action
import androidx.core.app.NotificationCompat.Builder
Expand All @@ -28,6 +29,7 @@ import com.stevesoltys.seedvault.settings.SettingsActivity
import com.stevesoltys.seedvault.transport.backup.ExpectedAppTotals

private const val CHANNEL_ID_OBSERVER = "NotificationBackupObserver"
private const val CHANNEL_ID_SUCCESS = "NotificationBackupSuccess"
private const val CHANNEL_ID_ERROR = "NotificationError"
private const val CHANNEL_ID_RESTORE_ERROR = "NotificationRestoreError"
private const val NOTIFICATION_ID_OBSERVER = 1
Expand All @@ -42,6 +44,7 @@ internal class BackupNotificationManager(private val context: Context) {

private val nm = context.getSystemService(NotificationManager::class.java)!!.apply {
createNotificationChannel(getObserverChannel())
createNotificationChannel(getSuccessChannel())
createNotificationChannel(getErrorChannel())
createNotificationChannel(getRestoreErrorChannel())
}
Expand All @@ -56,6 +59,13 @@ internal class BackupNotificationManager(private val context: Context) {
}
}

private fun getSuccessChannel(): NotificationChannel {
val title = context.getString(R.string.notification_success_channel_title)
return NotificationChannel(CHANNEL_ID_SUCCESS, title, IMPORTANCE_LOW).apply {
enableVibration(false)
}
}

private fun getErrorChannel(): NotificationChannel {
val title = context.getString(R.string.notification_error_channel_title)
return NotificationChannel(CHANNEL_ID_ERROR, title, IMPORTANCE_DEFAULT)
Expand Down Expand Up @@ -165,19 +175,20 @@ internal class BackupNotificationManager(private val context: Context) {
}
}

fun onBackupFinished(success: Boolean, numBackedUp: Int?) {
fun onBackupFinished(success: Boolean, numBackedUp: Int?, size: Long) {
val titleRes =
if (success) R.string.notification_success_title else R.string.notification_failed_title
val total = expectedAppTotals?.appsTotal
val contentText = if (numBackedUp == null || total == null) null else {
context.getString(R.string.notification_success_text, numBackedUp, total)
val sizeStr = Formatter.formatShortFileSize(context, size)
context.getString(R.string.notification_success_text, numBackedUp, total, sizeStr)
}
val iconRes = if (success) R.drawable.ic_cloud_done else R.drawable.ic_cloud_error
val intent = Intent(context, SettingsActivity::class.java).apply {
if (success) action = ACTION_APP_STATUS_LIST
}
val pendingIntent = PendingIntent.getActivity(context, 0, intent, FLAG_IMMUTABLE)
val notification = Builder(context, CHANNEL_ID_OBSERVER).apply {
val notification = Builder(context, CHANNEL_ID_SUCCESS).apply {
setSmallIcon(iconRes)
setContentTitle(context.getString(titleRes))
setContentText(contentText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ internal class NotificationBackupObserver(
}
val success = status == 0
val numBackedUp = if (success) metadataManager.getPackagesNumBackedUp() else null
nm.onBackupFinished(success, numBackedUp)
val size = if (success) metadataManager.getPackagesBackupSize() else 0L
nm.onBackupFinished(success, numBackedUp, size)
}

private fun showProgressNotification(packageName: String?) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<string name="recovery_code_input_hint_12">Paraula 12</string>
<string name="recovery_code_error_checksum_word">El codi no és vàlid. Comprova totes les paraules així com la seva posició i torna-ho a provar!</string>
<string name="recovery_code_verification_ok_title">Codi de recuperació verificat</string>
<string name="notification_success_text">%1$d de %2$d aplicacions amb còpia de seguretat. Fes un toc per saber-ne més.</string>
<string name="notification_success_text">%1$d de %2$d aplicacions amb còpia de seguretat (%3$s). Fes un toc per saber-ne més.</string>
<string name="recovery_code_verification_new_dialog_message">Generar un codi nou farà que les teves còpies de seguretat existents siguin inaccessibles. Intentarem suprimir-los si és possible.
\n
\nSegur que vols fer-ho\?</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<string name="notification_error_title">Chyba zálohování</string>
<string name="notification_error_channel_title">Oznámení o chybě</string>
<string name="notification_failed_title">Zálohování selhalo</string>
<string name="notification_success_text">%1$d z %2$d aplikací zálohováno. Klepnutím zobrazíte další informace.</string>
<string name="notification_success_text">%1$d z %2$d aplikací zálohováno (%3$s). Klepnutím zobrazíte další informace.</string>
<string name="notification_success_title">Zálohování dokončeno</string>
<string name="notification_backup_already_running">Zálohování již probíhá</string>
<string name="notification_title">Probíhá zálohování</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<string name="restore_restore_set_times">Letzte Sicherung %1$s · Erste %2$s.</string>
<string name="restore_choose_restore_set">Wähle eine Sicherung aus, um sie wiederherzustellen</string>
<string name="notification_restore_error_action">App deinstallieren</string>
<string name="notification_success_text">%1$d von %2$d Apps gesichert. Tippe, um mehr zu erfahren.</string>
<string name="notification_success_text">%1$d von %2$d Apps gesichert (%3$s). Tippe, um mehr zu erfahren.</string>
<string name="notification_backup_already_running">Sicherung wird bereits durchgeführt</string>
<string name="storage_fake_nextcloud_summary_unavailable">Konto nicht verfügbar. Richte ein Konto ein (oder deaktivieren Passcode).</string>
<string name="current_destination_string">Sicherungsstatus und Einstellungen</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<string name="notification_error_title">Σφάλμα δημιουργίας αντιγράφων ασφαλείας</string>
<string name="notification_error_channel_title">Ειδοποίηση σφάλματος</string>
<string name="notification_failed_title">Η δημιουργία αντιγράφων ασφαλείας απέτυχε</string>
<string name="notification_success_text">Δημιουργήθηκαν αντίγραφα ασφαλείας για %1$d από %2$d εφαρμογές. Πατήστε για να μάθετε περισσότερα.</string>
<string name="notification_success_text">Δημιουργήθηκαν αντίγραφα ασφαλείας για %1$d από %2$d εφαρμογές (%3$s). Πατήστε για να μάθετε περισσότερα.</string>
<string name="notification_success_title">Η δημιουργία αντιγράφων ασφαλείας ολοκληρώθηκε</string>
<string name="notification_backup_already_running">Η δημιουργία αντιγράφων ασφαλείας βρίσκεται ήδη σε εξέλιξη</string>
<string name="notification_title">Εκτελείται δημιουργία αντιγράφων ασφαλείας</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-en-rAU/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<string name="notification_backup_already_running">Backup already in progress</string>
<string name="notification_backup_disabled">Backup not enabled</string>
<string name="notification_success_title">Backup finished</string>
<string name="notification_success_text">%1$d of %2$d apps backed up. Tap to learn more.</string>
<string name="notification_success_text">%1$d of %2$d apps backed up (%3$s). Tap to learn more.</string>
<string name="notification_error_channel_title">Error notification</string>
<string name="notification_error_action">Fix</string>
<string name="notification_restore_error_channel_title">Auto restore flash drive error</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<string name="settings_backup">Copia de seguridad de mis apps</string>
<string name="restore_backup_button">Restaurar la copia de seguridad</string>
<string name="backup">Copia de seguridad</string>
<string name="notification_success_text">%1$d de %2$d aplicaciones con copia de seguridad. Pulse para obtener más información.</string>
<string name="notification_success_text">%1$d de %2$d aplicaciones con copia de seguridad (%3$s). Pulse para obtener más información.</string>
<string name="notification_backup_already_running">Copia de seguridad en curso</string>
<string name="restore_app_not_yet_backed_up">Todavía no se ha hecho una copia de seguridad</string>
<string name="restore_app_was_stopped">No se hizo una copia de seguridad porque no se había utilizado recientemente</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<string name="notification_error_title">Varmuuskopiointivirhe</string>
<string name="notification_error_channel_title">Virheilmoitus</string>
<string name="notification_failed_title">Varmuuskopiointi epäonnistui</string>
<string name="notification_success_text">%1$d/%2$d sovellusta varmuuskopioitu. Napauta saadaksesi lisätietoja.</string>
<string name="notification_success_text">%1$d/%2$d sovellusta varmuuskopioitu (%3$s). Napauta saadaksesi lisätietoja.</string>
<string name="notification_success_title">Varmuuskopiointi valmis</string>
<string name="notification_backup_already_running">Varmuuskopiointi on jo käynnissä</string>
<string name="notification_title">Varmuuskopiointi on käynnissä</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<string name="settings_backup_apk_summary">Sauvegardez les applications elles-mêmes. Sinon, seules les données des applications sont sauvegardées.</string>
<string name="restore_app_was_stopped">N\'a pas été sauvegardé car n\'a pas été utilisé récemment</string>
<string name="restore_app_not_yet_backed_up">Pas encore sauvegardé</string>
<string name="notification_success_text">%1$d des applications %2$d sauvegardées. Appuyez pour en savoir plus.</string>
<string name="notification_success_text">%1$d des applications %2$d sauvegardées (%3$s). Appuyez pour en savoir plus.</string>
<string name="notification_backup_already_running">Sauvegarde déjà en cours</string>
<string name="storage_fake_nextcloud_summary_unavailable">Compte non disponible. Configurez-en un (ou désactivez le mot de passe).</string>
<string name="current_destination_string">Statut et paramètres de sauvegarde</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-hr/strings.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="notification_success_text">Sigurnosne kopije spremljene za %1$d od %2$d aplikacija. Dodirni i saznaj više.</string>
<string name="notification_success_text">Sigurnosne kopije spremljene za %1$d od %2$d aplikacija (%3$s). Dodirni i saznaj više.</string>
<string name="notification_backup_already_running">Spremanje sigurnosne kopije je u tijeku</string>
<string name="about_summary">Aplikacija za izradu sigurnosnih kopija koja koristi Androidovo interno sučelje.</string>
<string name="about_title">Informacije</string>
<string name="storage_internal_warning_use_anyway">Svejedno koristi</string>
<string name="storage_internal_warning_choose_other">Odaberi drugo</string>
<string name="storage_internal_warning_message">Za sigurnosnu kopiju odabrano je interno spremište. Neće biti dostupno ako se telefon izgubi ili pokvari.</string>
<string name="storage_internal_warning_message">Za sigurnosnu kopiju odabrano je interno spremište (%3$s). Neće biti dostupno ako se telefon izgubi ili pokvari.</string>
<string name="storage_internal_warning_title">Upozorenje</string>
<string name="restore_finished_button">Završi</string>
<string name="restore_finished_error">Došlo je do greške prilikom vraćanja sigurnosne kopije.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<string name="notification_error_text">Il backup del dispositivo non e\' partito.</string>
<string name="notification_error_title">Errore di backup</string>
<string name="notification_error_channel_title">Notifica d\'errore</string>
<string name="notification_success_text">%1$d di %2$d app gia\' in backup. Tocca per ulteriori informazioni.</string>
<string name="notification_success_text">%1$d di %2$d app gia\' in backup (%3$s). Tocca per ulteriori informazioni.</string>
<string name="notification_backup_already_running">Backup gia\' in corso</string>
<string name="recovery_code_confirm_intro">Inserisci il tuo codice di recupero composto da 12 parole per controllare ora che il tutto funzionera\' correttamente quando sara\' necessario.</string>
<string name="recovery_code_input_intro">Inserisi il tuo codice di recupero composto da 12 parole che ti sei annotato quando hai inizializzato i backup.</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-iw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
<string name="notification_error_title">שגיאת גיבוי</string>
<string name="notification_error_channel_title">התראת שגיאה</string>
<string name="notification_failed_title">הגיבוי נכשל</string>
<string name="notification_success_text">%1$d מתוך %2$d יישומונים גובו. הקש למידע נוסף.</string>
<string name="notification_success_title">הגיבוי הסתיים</string>
<string name="notification_backup_already_running">הגיבוי כבר מתבצע</string>
<string name="about_summary">יישומון גיבוי שמשתמש ב־API הפנימי לגיבוי של Android. תוכנה חופשית שכפופה לרישיון Apache 2.
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<string name="notification_error_action">修正する</string>
<string name="notification_error_text">デバイスのバックアップを実行できませんでした。</string>
<string name="notification_error_channel_title">エラーの通知</string>
<string name="notification_success_text">%2$d 個の内 %1$d 個のアプリがバックアップされました。タップすると詳細が表示されます。</string>
<string name="notification_success_text">%2$d 個の内 %1$d 個のアプリがバックアップされました (%3$s)。タップすると詳細が表示されます。</string>
<string name="notification_channel_title">バックアップの通知</string>
<string name="recovery_code_verification_ok_message">コードは正しく、バックアップを復元するために機能します。</string>
<string name="recovery_code_error_invalid_word">単語が間違っています。</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<string name="notification_error_title">백업 오류</string>
<string name="notification_error_channel_title">오류 알림</string>
<string name="notification_failed_title">백업 실패</string>
<string name="notification_success_text">%2$d개 중 %1$d개 앱을 백업했습니다. 여기를 눌러서 더 알아보세요.</string>
<string name="notification_success_text">%2$d개 중 %1$d개 앱을 백업했습니다 (%3$s). 여기를 눌러서 더 알아보세요.</string>
<string name="notification_success_title">백업 완료</string>
<string name="notification_title">백업 실행 중</string>
<string name="notification_channel_title">백업 알림</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-lt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<string name="notification_error_title">Atsarginės kopijos kūrimo klaida</string>
<string name="notification_error_channel_title">Klaidos pranešimas</string>
<string name="notification_failed_title">Atsarginė kopija nepavyko</string>
<string name="notification_success_text">%1$d iš %2$d programėlių atsarginės kopijos sukurtos. Palieskite, kad sužinotumėte daugiau.</string>
<string name="notification_success_text">%1$d iš %2$d programėlių atsarginės kopijos sukurtos (%3$s). Palieskite, kad sužinotumėte daugiau.</string>
<string name="notification_success_title">Atsarginė kopija baigta</string>
<string name="notification_backup_already_running">Jau yra kuriama atsarginė kopija</string>
<string name="notification_title">Atsarginis kopijavimas veikia</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nb-rNO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<string name="settings_backup">Sikkerhetskopier dataen min</string>
<string name="restore_backup_button">Gjenopprett sikkerhetskopi</string>
<string name="backup">Sikkerhetskopier</string>
<string name="notification_success_text">%1$d av %2$d programmer sikkerhetskopiert. Trykk for mer info.</string>
<string name="notification_success_text">%1$d av %2$d programmer sikkerhetskopiert (%3$s). Trykk for mer info.</string>
<string name="notification_backup_already_running">Sikkerhetskopi allerede underveis</string>
<string name="settings_backup_status_title">Sikkerhetskopieringsstatus</string>
<string name="recovery_code_verification_error_title">Feil gjenopprettingskode</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<string name="backup_contacts">Lokale contacten</string>
<string name="notification_restore_error_text">Plug je %1$s in voordat je de app installeert om de gegevens daarvan te herstellen uit je back-up.</string>
<string name="notification_restore_error_title">Gegevens voor %1$s konden niet worden hersteld</string>
<string name="notification_success_text">%1$d van de %2$d apps zijn geback-upt. Tik om meer te weten te komen.</string>
<string name="notification_success_text">%1$d van de %2$d apps zijn geback-upt (%3$s). Tik om meer te weten te komen.</string>
<string name="notification_error_text">Een apparaatback-up kon niet worden gestart.</string>
<string name="notification_error_no_main_key_text">Maak een nieuwe herstelcode aan om de upgrade af te ronden en door te gaan met het maken van back-ups.</string>
<string name="restore_app_not_yet_backed_up">Was nog niet geback-upt</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<string name="backup_settings">Ustawienia urządzenia</string>
<string name="backup_sms">Wiadomości tekstowe SMS</string>
<string name="backup_section_system">Aplikacje systemowe</string>
<string name="notification_success_text">Skopiowano %1$d z %2$d aplikacji. Naciśnij, aby dowiedzieć się więcej.</string>
<string name="notification_success_text">Skopiowano %1$d z %2$d aplikacji (%3$s). Naciśnij, aby dowiedzieć się więcej.</string>
<string name="notification_backup_already_running">Kopia zapasowa jest już tworzona</string>
<string name="storage_fake_nextcloud_summary_unavailable">Konto nie jest dostępne. Skonfiguruj jakieś (lub wyłącz hasło).</string>
<string name="about_summary">Aplikacja do tworzenia kopii zapasowych wykorzystująca wewnętrzny interfejs API systemu Android do tworzenia kopii zapasowych.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<string name="restore_set_empty_result">Nenhum backup adequado encontrado no local dado.
\n
\nIsso provavelmente se deve a um código de recuperação errado ou a um erro de armazenamento.</string>
<string name="notification_success_text">%1$d de %2$d aplicativos com backup. Toque para saber mais.</string>
<string name="notification_success_text">%1$d de %2$d aplicativos com backup (%3$s). Toque para saber mais.</string>
<string name="notification_backup_already_running">Backup já em andamento</string>
<string name="restore_app_was_stopped">Não feito nenhum backup desde que não foi utilizado recentemente</string>
<string name="restore_app_not_yet_backed_up">Nenhum backup foi feito ainda</string>
Expand Down
Loading

0 comments on commit daf3ed3

Please sign in to comment.