diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt index 2e1d6fe9..ff26c3a8 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsFragment.kt @@ -3,6 +3,7 @@ package com.stevesoltys.seedvault.settings import android.app.backup.IBackupManager import android.content.Intent import android.os.Bundle +import android.os.PowerManager import android.os.RemoteException import android.provider.Settings import android.provider.Settings.Secure.BACKUP_AUTO_RESTORE @@ -11,6 +12,8 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View +import android.widget.Toast +import android.widget.Toast.LENGTH_LONG import androidx.appcompat.app.AlertDialog import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceChangeListener @@ -228,6 +231,14 @@ class SettingsFragment : PreferenceFragmentCompat() { .setTitle(R.string.settings_backup_storage_dialog_title) .setMessage(R.string.settings_backup_storage_dialog_message) .setPositiveButton(R.string.settings_backup_storage_dialog_ok) { dialog, _ -> + // warn if battery optimization is active + // we don't bother with yet another dialog, because the ROM should handle it + val context = requireContext() + val powerManager = context.getSystemService(PowerManager::class.java) + if (!powerManager.isIgnoringBatteryOptimizations(context.packageName)) { + Toast.makeText(context, R.string.settings_backup_storage_battery_optimization, + LENGTH_LONG).show() + } viewModel.enableStorageBackup() backupStorage.isChecked = true dialog.dismiss() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1b2fdafe..a1d26c5b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,6 +38,7 @@ Experimental feature Backing up files is still experimental and might not work. Do not rely on it for important data. Enable anyway + Warning: No automatic backups, because battery optimization is active. New recovery code required To continue using app backups, you need to generate a new recovery code.\n\nWe are sorry for the inconvenience. New code diff --git a/storage/lib/src/main/java/org/calyxos/backup/storage/backup/BackupJobService.kt b/storage/lib/src/main/java/org/calyxos/backup/storage/backup/BackupJobService.kt index e4419b1c..a3ba3965 100644 --- a/storage/lib/src/main/java/org/calyxos/backup/storage/backup/BackupJobService.kt +++ b/storage/lib/src/main/java/org/calyxos/backup/storage/backup/BackupJobService.kt @@ -18,6 +18,9 @@ public abstract class BackupJobService(private val serviceClass: Class, diff --git a/storage/lib/src/main/java/org/calyxos/backup/storage/ui/Notifications.kt b/storage/lib/src/main/java/org/calyxos/backup/storage/ui/Notifications.kt index fccb3834..7f979eb5 100644 --- a/storage/lib/src/main/java/org/calyxos/backup/storage/ui/Notifications.kt +++ b/storage/lib/src/main/java/org/calyxos/backup/storage/ui/Notifications.kt @@ -1,15 +1,16 @@ package org.calyxos.backup.storage.ui import android.app.Notification +import android.app.Notification.FOREGROUND_SERVICE_IMMEDIATE import android.app.NotificationChannel import android.app.NotificationManager import android.app.NotificationManager.IMPORTANCE_LOW import android.app.PendingIntent import android.content.Context +import android.os.Build.VERSION.SDK_INT import androidx.annotation.DrawableRes import androidx.annotation.StringRes import androidx.core.app.NotificationCompat -import androidx.core.app.NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT import org.calyxos.backup.storage.R @@ -136,7 +137,7 @@ internal class Notifications(private val context: Context) { infoText: CharSequence?, transferred: Int = 0, expected: Int = 0, - ) = NotificationCompat.Builder(context, CHANNEL_ID_BACKUP).apply { + ) = Notification.Builder(context, CHANNEL_ID_BACKUP).apply { setSmallIcon(icon) setContentTitle(title) setContentText(infoText) @@ -144,8 +145,7 @@ internal class Notifications(private val context: Context) { setShowWhen(false) setWhen(System.currentTimeMillis()) setProgress(expected, transferred, expected == 0) - foregroundServiceBehavior = FOREGROUND_SERVICE_IMMEDIATE - priority = PRIORITY_DEFAULT + if (SDK_INT >= 31) setForegroundServiceBehavior(FOREGROUND_SERVICE_IMMEDIATE) }.build() } diff --git a/whitelist_com.stevesoltys.seedvault.xml b/whitelist_com.stevesoltys.seedvault.xml index c3c2877b..0f4ad181 100644 --- a/whitelist_com.stevesoltys.seedvault.xml +++ b/whitelist_com.stevesoltys.seedvault.xml @@ -3,4 +3,6 @@ + +