From 870797ff63640d88d04e4335c31b8e6f94adbb73 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 1 Aug 2024 21:56:03 -0700 Subject: [PATCH 1/3] Fix db backup oom issue --- .../java/f/cking/software/data/database/AppDatabase.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/f/cking/software/data/database/AppDatabase.kt b/app/src/main/java/f/cking/software/data/database/AppDatabase.kt index 7678024..30d395f 100644 --- a/app/src/main/java/f/cking/software/data/database/AppDatabase.kt +++ b/app/src/main/java/f/cking/software/data/database/AppDatabase.kt @@ -64,7 +64,13 @@ abstract class AppDatabase : RoomDatabase() { throw IllegalStateException("The database file doesn't exist") } context.contentResolver.openOutputStream(toUri)?.use { outputStream -> - outputStream.write(dbFile.readBytes()) + dbFile.inputStream().use { inputStream -> + val buffer = ByteArray(1024) + var bytesRead: Int + while ((inputStream.read(buffer).also { bytesRead = it }) != -1) { + outputStream.write(buffer, 0, bytesRead) + } + } } } } From 3ad164535ea42fe53c8235839bfff56214c38469 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 1 Aug 2024 22:02:35 -0700 Subject: [PATCH 2/3] Update the app version --- app/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0ae9917..913d316 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -25,8 +25,8 @@ android { minSdk = 29 targetSdk = 34 - versionCode = 1708536356 - versionName = "0.26.0-beta" + versionCode = 1708536357 + versionName = "0.26.1-beta" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" From 4551028205670677d414c245d30070dab83a1c33 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 1 Aug 2024 22:34:34 -0700 Subject: [PATCH 3/3] Use std method for buffered writing --- .../java/f/cking/software/data/database/AppDatabase.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/f/cking/software/data/database/AppDatabase.kt b/app/src/main/java/f/cking/software/data/database/AppDatabase.kt index 30d395f..e2276ce 100644 --- a/app/src/main/java/f/cking/software/data/database/AppDatabase.kt +++ b/app/src/main/java/f/cking/software/data/database/AppDatabase.kt @@ -65,13 +65,9 @@ abstract class AppDatabase : RoomDatabase() { } context.contentResolver.openOutputStream(toUri)?.use { outputStream -> dbFile.inputStream().use { inputStream -> - val buffer = ByteArray(1024) - var bytesRead: Int - while ((inputStream.read(buffer).also { bytesRead = it }) != -1) { - outputStream.write(buffer, 0, bytesRead) - } + inputStream.copyTo(outputStream) } - } + } ?: throw RuntimeException("Cannot create a backup file stream") } }