Don't let the user start a new backup when one is already in progress
This commit is contained in:
parent
b9ffe2c03e
commit
30e70527fb
5 changed files with 23 additions and 2 deletions
|
@ -39,7 +39,7 @@ class App : Application() {
|
|||
single { Clock() }
|
||||
factory<IBackupManager> { IBackupManager.Stub.asInterface(getService(BACKUP_SERVICE)) }
|
||||
|
||||
viewModel { SettingsViewModel(this@App, get(), get(), get(), get()) }
|
||||
viewModel { SettingsViewModel(this@App, get(), get(), get(), get(), get()) }
|
||||
viewModel { RecoveryCodeViewModel(this@App, get()) }
|
||||
viewModel { BackupStorageViewModel(this@App, get(), get(), get()) }
|
||||
viewModel { RestoreStorageViewModel(this@App, get(), get()) }
|
||||
|
|
|
@ -199,6 +199,8 @@ class MetadataManager(
|
|||
|
||||
@Synchronized
|
||||
fun getPackagesNumBackedUp(): Int {
|
||||
// FIXME we are under-reporting packages here,
|
||||
// because we have no way to also include upgraded system apps
|
||||
return metadata.packageMetadataMap.filter { (_, packageMetadata) ->
|
||||
!packageMetadata.system && ( // ignore system apps
|
||||
packageMetadata.state == APK_AND_DATA || // either full success
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.app.Application
|
|||
import android.content.pm.PackageManager.NameNotFoundException
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import android.widget.Toast.LENGTH_LONG
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.core.content.ContextCompat.getDrawable
|
||||
import androidx.lifecycle.LiveData
|
||||
|
@ -30,6 +32,7 @@ import com.stevesoltys.seedvault.restore.AppRestoreStatus.SUCCEEDED
|
|||
import com.stevesoltys.seedvault.transport.backup.PackageService
|
||||
import com.stevesoltys.seedvault.transport.requestBackup
|
||||
import com.stevesoltys.seedvault.ui.RequireProvisioningViewModel
|
||||
import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager
|
||||
import com.stevesoltys.seedvault.ui.notification.getAppName
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -43,6 +46,7 @@ internal class SettingsViewModel(
|
|||
app: Application,
|
||||
settingsManager: SettingsManager,
|
||||
keyManager: KeyManager,
|
||||
private val notificationManager: BackupNotificationManager,
|
||||
private val metadataManager: MetadataManager,
|
||||
private val packageService: PackageService
|
||||
) : RequireProvisioningViewModel(app, settingsManager, keyManager) {
|
||||
|
@ -68,7 +72,11 @@ internal class SettingsViewModel(
|
|||
}
|
||||
|
||||
internal fun backupNow() {
|
||||
Thread { requestBackup(app) }.start()
|
||||
if (notificationManager.hasActiveBackupNotifications()) {
|
||||
Toast.makeText(app, R.string.notification_backup_already_running, LENGTH_LONG).show()
|
||||
} else {
|
||||
Thread { requestBackup(app) }.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAppStatusResult(): LiveData<AppStatusResult> = liveData {
|
||||
|
|
|
@ -16,6 +16,7 @@ import androidx.core.app.NotificationCompat.Builder
|
|||
import androidx.core.app.NotificationCompat.PRIORITY_DEFAULT
|
||||
import androidx.core.app.NotificationCompat.PRIORITY_HIGH
|
||||
import androidx.core.app.NotificationCompat.PRIORITY_LOW
|
||||
import com.stevesoltys.seedvault.BuildConfig.APPLICATION_ID
|
||||
import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER
|
||||
import com.stevesoltys.seedvault.R
|
||||
import com.stevesoltys.seedvault.restore.ACTION_RESTORE_ERROR_UNINSTALL
|
||||
|
@ -204,6 +205,15 @@ internal class BackupNotificationManager(private val context: Context) {
|
|||
expectedAppTotals = null
|
||||
}
|
||||
|
||||
fun hasActiveBackupNotifications(): Boolean {
|
||||
nm.activeNotifications.forEach {
|
||||
if (it.packageName == APPLICATION_ID &&
|
||||
(it.id == NOTIFICATION_ID_OBSERVER || it.id == NOTIFICATION_ID_BACKGROUND)
|
||||
) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun onBackupError() {
|
||||
val intent = Intent(context, SettingsActivity::class.java)
|
||||
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
<string name="notification_backup_result_complete">Backup complete</string>
|
||||
<string name="notification_backup_result_rejected">Not backed up</string>
|
||||
<string name="notification_backup_result_error">Backup failed</string>
|
||||
<string name="notification_backup_already_running">Backup already in progress</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>
|
||||
|
|
Loading…
Reference in a new issue