From 1e5a4deedf9cdb1e00d03134dc43f6153678b115 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Mon, 23 Sep 2024 09:30:43 -0300 Subject: [PATCH] Clean up libraries, move to where they are included --- Android.bp | 6 +-- app/build.gradle.kts | 2 - .../seedvault/backend/BackendExt.kt | 38 ------------------ .../seedvault/backend/saf/SafHandler.kt | 1 - .../seedvault/backend/webdav/WebDavHandler.kt | 5 +-- .../transport/backup/BackupCoordinator.kt | 2 +- .../seedvault/transport/backup/FullBackup.kt | 2 +- .../transport/restore/RestoreCoordinator.kt | 1 - .../seedvault/worker/ApkBackupManager.kt | 4 +- core/Android.bp | 10 ++--- core/build.gradle.kts | 2 +- core/libs/Android.bp | 22 ++++++++++ {libs => core/libs}/dav4jvm/Android.bp | 0 .../libs}/dav4jvm/dav4jvm-c1bc143.jar | Bin {libs => core/libs}/dav4jvm/okhttp-4.12.0.jar | Bin .../libs}/kotlin-logging-jvm-6.0.3.jar | Bin {libs => core/libs}/slf4j-api-2.0.16.jar | Bin .../seedvault/core/backends/Backend.kt | 14 +++++++ libs/Android.bp | 12 ------ 19 files changed, 48 insertions(+), 73 deletions(-) delete mode 100644 app/src/main/java/com/stevesoltys/seedvault/backend/BackendExt.kt create mode 100644 core/libs/Android.bp rename {libs => core/libs}/dav4jvm/Android.bp (100%) rename {libs => core/libs}/dav4jvm/dav4jvm-c1bc143.jar (100%) rename {libs => core/libs}/dav4jvm/okhttp-4.12.0.jar (100%) rename {libs => core/libs}/kotlin-logging-jvm-6.0.3.jar (100%) rename {libs => core/libs}/slf4j-api-2.0.16.jar (100%) diff --git a/Android.bp b/Android.bp index 98c53fc4..4dfa5b50 100644 --- a/Android.bp +++ b/Android.bp @@ -37,12 +37,13 @@ android_app { "com.google.android.material_material", "kotlinx-coroutines-android", "kotlinx-coroutines-core", + "seedvault-lib-kotlin-logging-jvm", // app backup related libs "seedvault-lib-protobuf-kotlin-lite", - "seedvault-lib-kotlin-logging-jvm", "seedvault-logback-android", "seedvault-lib-chunker", "seedvault-lib-zstd-jni", + "okio-lib", // our own gradle module libs "seedvault-lib-core", "seedvault-lib-storage", @@ -51,9 +52,6 @@ android_app { "seedvault-lib-koin-android", // bip39 "seedvault-lib-kotlin-bip39", - // WebDAV - "seedvault-lib-dav4jvm", - "seedvault-lib-okhttp", ], use_embedded_native_libs: true, manifest: "app/src/main/AndroidManifest.xml", diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 681a28e5..6a577a10 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -185,8 +185,6 @@ dependencies { implementation(fileTree("${rootProject.rootDir}/libs").include("kotlin-bip39-jvm-1.0.8.jar")) implementation(fileTree("${rootProject.rootDir}/libs").include("logback-android-3.0.0.aar")) - implementation(fileTree("${rootProject.rootDir}/libs/dav4jvm").include("*.jar")) - /** * Test Dependencies (do not concern the AOSP build) */ diff --git a/app/src/main/java/com/stevesoltys/seedvault/backend/BackendExt.kt b/app/src/main/java/com/stevesoltys/seedvault/backend/BackendExt.kt deleted file mode 100644 index f5f6fc21..00000000 --- a/app/src/main/java/com/stevesoltys/seedvault/backend/BackendExt.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2024 The Calyx Institute - * SPDX-License-Identifier: Apache-2.0 - */ - -package com.stevesoltys.seedvault.backend - -import at.bitfire.dav4jvm.exception.HttpException -import org.calyxos.seedvault.core.backends.AppBackupFileType -import org.calyxos.seedvault.core.backends.Backend -import org.calyxos.seedvault.core.backends.FileHandle -import org.calyxos.seedvault.core.backends.LegacyAppBackupFile -import java.io.IOException - -suspend fun Backend.getAvailableBackupFileHandles(): List { - // v1 get all restore set tokens in root folder that have a metadata file - // v2 get all snapshots in all repository folders - return ArrayList().apply { - list( - null, - AppBackupFileType.Snapshot::class, - LegacyAppBackupFile.Metadata::class, - ) { fileInfo -> - add(fileInfo.fileHandle) - } - } -} - -fun Exception.isOutOfSpace(): Boolean { - return when (this) { - is IOException -> message?.contains("No space left on device") == true || - (cause as? HttpException)?.code == 507 - - is HttpException -> code == 507 - - else -> false - } -} diff --git a/app/src/main/java/com/stevesoltys/seedvault/backend/saf/SafHandler.kt b/app/src/main/java/com/stevesoltys/seedvault/backend/saf/SafHandler.kt index 5160639c..b296bc57 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/backend/saf/SafHandler.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/backend/saf/SafHandler.kt @@ -15,7 +15,6 @@ import android.util.Log import androidx.annotation.WorkerThread import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.backend.BackendManager -import com.stevesoltys.seedvault.backend.getAvailableBackupFileHandles import com.stevesoltys.seedvault.isMassStorage import com.stevesoltys.seedvault.settings.FlashDrive import com.stevesoltys.seedvault.settings.SettingsManager diff --git a/app/src/main/java/com/stevesoltys/seedvault/backend/webdav/WebDavHandler.kt b/app/src/main/java/com/stevesoltys/seedvault/backend/webdav/WebDavHandler.kt index e46941d8..02c43942 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/backend/webdav/WebDavHandler.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/backend/webdav/WebDavHandler.kt @@ -6,15 +6,14 @@ package com.stevesoltys.seedvault.backend.webdav import android.content.Context +import android.net.Uri import android.util.Log import androidx.annotation.WorkerThread import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.backend.BackendManager -import com.stevesoltys.seedvault.backend.getAvailableBackupFileHandles import com.stevesoltys.seedvault.settings.SettingsManager import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow -import okhttp3.HttpUrl.Companion.toHttpUrl import org.calyxos.seedvault.core.backends.Backend import org.calyxos.seedvault.core.backends.BackendFactory import org.calyxos.seedvault.core.backends.webdav.WebDavConfig @@ -43,7 +42,7 @@ internal class WebDavHandler( companion object { fun createWebDavProperties(context: Context, config: WebDavConfig): WebDavProperties { - val host = config.url.toHttpUrl().host + val host = Uri.parse(config.url).host return WebDavProperties( config = config, name = context.getString(R.string.storage_webdav_name, host), diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt index 93f66014..291c6df4 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/BackupCoordinator.kt @@ -22,7 +22,6 @@ import android.util.Log import androidx.annotation.WorkerThread import com.stevesoltys.seedvault.Clock import com.stevesoltys.seedvault.backend.BackendManager -import com.stevesoltys.seedvault.backend.isOutOfSpace import com.stevesoltys.seedvault.metadata.BackupType import com.stevesoltys.seedvault.metadata.MetadataManager import com.stevesoltys.seedvault.metadata.PackageState @@ -32,6 +31,7 @@ import com.stevesoltys.seedvault.metadata.PackageState.UNKNOWN_ERROR import com.stevesoltys.seedvault.repo.AppBackupManager import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager +import org.calyxos.seedvault.core.backends.isOutOfSpace import java.io.IOException import java.util.concurrent.TimeUnit.DAYS import java.util.concurrent.TimeUnit.HOURS diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt index 2156bedd..d23a6445 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/backup/FullBackup.kt @@ -13,11 +13,11 @@ import android.app.backup.BackupTransport.TRANSPORT_QUOTA_EXCEEDED import android.content.pm.PackageInfo import android.os.ParcelFileDescriptor import android.util.Log -import com.stevesoltys.seedvault.backend.isOutOfSpace import com.stevesoltys.seedvault.repo.BackupData import com.stevesoltys.seedvault.repo.BackupReceiver import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager +import org.calyxos.seedvault.core.backends.isOutOfSpace import java.io.Closeable import java.io.EOFException import java.io.IOException diff --git a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt index f8b76198..15fd465f 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/transport/restore/RestoreCoordinator.kt @@ -19,7 +19,6 @@ import android.util.Log import com.stevesoltys.seedvault.MAGIC_PACKAGE_MANAGER import com.stevesoltys.seedvault.R import com.stevesoltys.seedvault.backend.BackendManager -import com.stevesoltys.seedvault.backend.getAvailableBackupFileHandles import com.stevesoltys.seedvault.crypto.Crypto import com.stevesoltys.seedvault.header.UnsupportedVersionException import com.stevesoltys.seedvault.metadata.BackupType diff --git a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt index 7f12415e..65d9b400 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/worker/ApkBackupManager.kt @@ -8,16 +8,16 @@ package com.stevesoltys.seedvault.worker import android.content.Context import android.content.pm.PackageInfo import android.util.Log -import com.stevesoltys.seedvault.backend.isOutOfSpace import com.stevesoltys.seedvault.metadata.MetadataManager import com.stevesoltys.seedvault.metadata.PackageState.NOT_ALLOWED import com.stevesoltys.seedvault.metadata.PackageState.WAS_STOPPED -import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.repo.SnapshotManager +import com.stevesoltys.seedvault.settings.SettingsManager import com.stevesoltys.seedvault.transport.backup.PackageService import com.stevesoltys.seedvault.transport.backup.isStopped import com.stevesoltys.seedvault.ui.notification.BackupNotificationManager import com.stevesoltys.seedvault.ui.notification.getAppName +import org.calyxos.seedvault.core.backends.isOutOfSpace import java.io.IOException internal class ApkBackupManager( diff --git a/core/Android.bp b/core/Android.bp index 00148d2c..3d7e9b79 100644 --- a/core/Android.bp +++ b/core/Android.bp @@ -14,11 +14,13 @@ android_library { "src/main/java/org/calyxos/seedvault/core/backends/BackendTest.kt", ], static_libs: [ - "seedvault-lib-tink-android", "androidx.core_core-ktx", "androidx.documentfile_documentfile", "kotlinx-coroutines-android", "kotlinx-coroutines-core", + // Crypto + "seedvault-lib-tink-android", + // Logging "seedvault-lib-kotlin-logging-jvm", "seedvault-lib-slf4j-api", // WebDAV @@ -34,9 +36,3 @@ android_library { "-opt-in=kotlin.RequiresOptIn", ], } - -java_import { - name: "seedvault-lib-tink-android", - jars: ["libs/tink-android-1.15.0.jar"], - sdk_version: "current", -} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index b0752895..2c5b9400 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -42,7 +42,7 @@ dependencies { implementation(libs.androidx.documentfile) implementation(libs.androidx.core.ktx) implementation(libs.google.tink.android) - implementation(fileTree("${rootProject.rootDir}/libs/dav4jvm").include("*.jar")) + implementation(fileTree("$projectDir/libs/dav4jvm").include("*.jar")) implementation(libs.squareup.okio) implementation(libs.kotlin.logging) implementation(libs.slf4j.api) diff --git a/core/libs/Android.bp b/core/libs/Android.bp new file mode 100644 index 00000000..ca05671e --- /dev/null +++ b/core/libs/Android.bp @@ -0,0 +1,22 @@ +// +// SPDX-FileCopyrightText: 2024 The Calyx Institute +// SPDX-License-Identifier: Apache-2.0 +// + +java_import { + name: "seedvault-lib-tink-android", + jars: ["tink-android-1.15.0.jar"], + sdk_version: "current", +} + +java_import { + name: "seedvault-lib-kotlin-logging-jvm", + jars: ["kotlin-logging-jvm-6.0.3.jar"], + sdk_version: "current", +} + +java_import { + name: "seedvault-lib-slf4j-api", + jars: ["slf4j-api-2.0.16.jar"], + sdk_version: "current", +} diff --git a/libs/dav4jvm/Android.bp b/core/libs/dav4jvm/Android.bp similarity index 100% rename from libs/dav4jvm/Android.bp rename to core/libs/dav4jvm/Android.bp diff --git a/libs/dav4jvm/dav4jvm-c1bc143.jar b/core/libs/dav4jvm/dav4jvm-c1bc143.jar similarity index 100% rename from libs/dav4jvm/dav4jvm-c1bc143.jar rename to core/libs/dav4jvm/dav4jvm-c1bc143.jar diff --git a/libs/dav4jvm/okhttp-4.12.0.jar b/core/libs/dav4jvm/okhttp-4.12.0.jar similarity index 100% rename from libs/dav4jvm/okhttp-4.12.0.jar rename to core/libs/dav4jvm/okhttp-4.12.0.jar diff --git a/libs/kotlin-logging-jvm-6.0.3.jar b/core/libs/kotlin-logging-jvm-6.0.3.jar similarity index 100% rename from libs/kotlin-logging-jvm-6.0.3.jar rename to core/libs/kotlin-logging-jvm-6.0.3.jar diff --git a/libs/slf4j-api-2.0.16.jar b/core/libs/slf4j-api-2.0.16.jar similarity index 100% rename from libs/slf4j-api-2.0.16.jar rename to core/libs/slf4j-api-2.0.16.jar diff --git a/core/src/main/java/org/calyxos/seedvault/core/backends/Backend.kt b/core/src/main/java/org/calyxos/seedvault/core/backends/Backend.kt index 03c711ca..9d6d99fc 100644 --- a/core/src/main/java/org/calyxos/seedvault/core/backends/Backend.kt +++ b/core/src/main/java/org/calyxos/seedvault/core/backends/Backend.kt @@ -51,4 +51,18 @@ public interface Backend { * @return null if no package name could be found */ public val providerPackageName: String? + + public suspend fun getAvailableBackupFileHandles(): List { + // v1 get all restore set tokens in root folder that have a metadata file + // v2 get all snapshots in all repository folders + return ArrayList().apply { + list( + null, + AppBackupFileType.Snapshot::class, + LegacyAppBackupFile.Metadata::class, + ) { fileInfo -> + add(fileInfo.fileHandle) + } + } + } } diff --git a/libs/Android.bp b/libs/Android.bp index 51ddb1df..82a1361e 100644 --- a/libs/Android.bp +++ b/libs/Android.bp @@ -33,15 +33,3 @@ java_import { jars: ["seedvault-chunker-0.1.jar"], sdk_version: "current", } - -java_import { - name: "seedvault-lib-kotlin-logging-jvm", - jars: ["kotlin-logging-jvm-6.0.3.jar"], - sdk_version: "current", -} - -java_import { - name: "seedvault-lib-slf4j-api", - jars: ["slf4j-api-2.0.16.jar"], - sdk_version: "current", -}