Backup-restore fixes

This commit is contained in:
Koitharu
2025-10-14 14:38:54 +03:00
parent 391c8ab649
commit 07af3ea703
5 changed files with 38 additions and 12 deletions

View File

@@ -55,6 +55,7 @@
android:fullBackupContent="@xml/backup_content"
android:fullBackupOnly="true"
android:hasFragileUserData="true"
android:restoreAnyVersion="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"

View File

@@ -36,15 +36,14 @@ class AppBackupAgent : BackupAgent() {
override fun onFullBackup(data: FullBackupDataOutput) {
super.onFullBackup(data)
val file =
createBackupFile(
this,
BackupRepository(
MangaDatabase(context = applicationContext),
AppSettings(applicationContext),
TapGridSettings(applicationContext),
),
)
val file = createBackupFile(
this,
BackupRepository(
MangaDatabase(context = applicationContext),
AppSettings(applicationContext),
TapGridSettings(applicationContext),
),
)
try {
fullBackupFile(file, data)
} finally {
@@ -90,8 +89,12 @@ class AppBackupAgent : BackupAgent() {
@VisibleForTesting
fun restoreBackupFile(fd: FileDescriptor, size: Long, repository: BackupRepository) {
ZipInputStream(ByteStreams.limit(FileInputStream(fd), size)).use { input ->
val sections = EnumSet.allOf(BackupSection::class.java)
// managed externally
sections.remove(BackupSection.SETTINGS)
sections.remove(BackupSection.SETTINGS_READER_GRID)
runBlocking {
repository.restoreBackup(input, EnumSet.allOf(BackupSection::class.java), null)
repository.restoreBackup(input, sections, null)
}
}
}

View File

@@ -21,7 +21,7 @@ enum class BackupSection(
fun of(entry: ZipEntry): BackupSection? {
val name = entry.name.lowercase(Locale.ROOT)
return entries.first { x -> x.entryName == name }
return entries.find { x -> x.entryName == name }
}
}
}

View File

@@ -3,4 +3,16 @@
<include
domain="sharedpref"
path="." />
<exclude
domain="sharedpref"
path="_local_index.xml" />
<exclude
domain="database"
path="." />
<exclude
domain="device_database"
path="." />
<exclude
domain="external"
path="." />
</full-backup-content>

View File

@@ -2,5 +2,15 @@
<data-extraction-rules>
<cloud-backup disableIfNoEncryptionCapabilities="false">
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="_local_index.xml"/>
<exclude domain="database" path="." />
<exclude domain="device_database" path="." />
<exclude domain="external" path="." />
</cloud-backup>
</data-extraction-rules>
<device-transfer>
<include domain="sharedpref" path="."/>
<exclude domain="sharedpref" path="_local_index.xml"/>
<exclude domain="database" path="." />
<exclude domain="device_database" path="." />
</device-transfer>
</data-extraction-rules>