-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use BackupManagerMonitor to handle K/V with no data changed
The fake package manager package is essential for the backup, but when its data doesn't change and we request a normal incremental backup, it doesn't get included, because our transport doesn't even get called for it. Only the BackupMonitor gets a hint that it had no (new?) data via LOG_EVENT_ID_NO_DATA_TO_SEND. This behavior started with Android 15 that fixed a bug that caused @pm@ to always backup. However, other K/V apps were probably affected before.
- Loading branch information
Showing
12 changed files
with
245 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupTransportMonitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 The Calyx Institute | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.stevesoltys.seedvault.transport.backup | ||
|
||
import android.app.backup.BackupManagerMonitor.LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY | ||
import android.app.backup.BackupManagerMonitor.LOG_EVENT_ID_NO_DATA_TO_SEND | ||
import android.os.Bundle | ||
import com.stevesoltys.seedvault.BackupMonitor | ||
import com.stevesoltys.seedvault.repo.AppBackupManager | ||
import com.stevesoltys.seedvault.repo.SnapshotManager | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
|
||
internal class BackupTransportMonitor( | ||
private val appBackupManager: AppBackupManager, | ||
private val snapshotManager: SnapshotManager, | ||
) : BackupMonitor() { | ||
|
||
private val log = KotlinLogging.logger { } | ||
|
||
override fun onEvent(id: Int, category: Int, packageName: String, bundle: Bundle) { | ||
super.onEvent(id, category, packageName, bundle) | ||
if (id == LOG_EVENT_ID_NO_DATA_TO_SEND && | ||
category == LOG_EVENT_CATEGORY_BACKUP_MANAGER_POLICY | ||
) { | ||
sendNoDataChanged(packageName) | ||
} | ||
} | ||
|
||
private fun sendNoDataChanged(packageName: String) { | ||
log.info { "sendNoDataChanged($packageName)" } | ||
|
||
val snapshot = snapshotManager.latestSnapshot | ||
if (snapshot == null) { | ||
log.error { "No latest snapshot!" } | ||
} else { | ||
val snapshotCreator = appBackupManager.snapshotCreator ?: error("No SnapshotCreator") | ||
snapshotCreator.onNoDataInCurrentRun(snapshot, packageName) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.