clean up libs and fix AOSP build

This commit is contained in:
Torsten Grote 2024-08-28 17:08:40 -03:00
parent 206affee00
commit 78ef0caea7
No known key found for this signature in database
GPG key ID: 3E5F77D92CF891FF
17 changed files with 88 additions and 53 deletions

View file

@ -26,7 +26,8 @@ android_app {
"com.google.android.material_material",
"kotlinx-coroutines-android",
"kotlinx-coroutines-core",
// storage backup lib
// our own gradle module libs
"seedvault-lib-core",
"seedvault-lib-storage",
// koin
"seedvault-lib-koin-core-jvm", // did not manage to add this as transitive dependency
@ -36,7 +37,6 @@ android_app {
// WebDAV
"seedvault-lib-dav4jvm",
"seedvault-lib-okhttp",
"seedvault-lib-okio",
],
manifest: "app/src/main/AndroidManifest.xml",

View file

@ -20,13 +20,13 @@ import android.os.UserManager
import androidx.work.ExistingPeriodicWorkPolicy.UPDATE
import androidx.work.WorkManager
import com.google.android.material.color.DynamicColors
import com.stevesoltys.seedvault.backend.BackendManager
import com.stevesoltys.seedvault.backend.saf.storagePluginModuleSaf
import com.stevesoltys.seedvault.backend.webdav.storagePluginModuleWebDav
import com.stevesoltys.seedvault.crypto.cryptoModule
import com.stevesoltys.seedvault.header.headerModule
import com.stevesoltys.seedvault.metadata.MetadataManager
import com.stevesoltys.seedvault.metadata.metadataModule
import com.stevesoltys.seedvault.backend.BackendManager
import com.stevesoltys.seedvault.backend.saf.storagePluginModuleSaf
import com.stevesoltys.seedvault.backend.webdav.storagePluginModuleWebDav
import com.stevesoltys.seedvault.restore.install.installModule
import com.stevesoltys.seedvault.restore.restoreUiModule
import com.stevesoltys.seedvault.settings.AppListRetriever
@ -63,7 +63,14 @@ open class App : Application() {
single { SettingsManager(this@App) }
single { BackupNotificationManager(this@App) }
single { BackendManager(this@App, get(), get()) }
single { BackendFactory(this@App) }
single {
BackendFactory {
// uses context of the device's main user to be able to access USB storage
this@App.applicationContext.getStorageContext {
get<SettingsManager>().getSafProperties()?.isUsb == true
}
}
}
single { BackupStateManager(this@App) }
single { Clock() }
factory<IBackupManager> { IBackupManager.Stub.asInterface(getService(BACKUP_SERVICE)) }
@ -215,6 +222,10 @@ fun <T> permitDiskReads(func: () -> T): T {
}
}
/**
* Hack to allow other profiles access to USB backend.
* @return the context of the device's main user, so use with great care!
*/
@Suppress("MissingPermission")
fun Context.getStorageContext(isUsbStorage: () -> Boolean): Context {
if (checkSelfPermission(INTERACT_ACROSS_USERS_FULL) == PERMISSION_GRANTED && isUsbStorage()) {

35
core/Android.bp Normal file
View file

@ -0,0 +1,35 @@
//
// SPDX-FileCopyrightText: 2021 The Calyx Institute
// SPDX-License-Identifier: Apache-2.0
//
android_library {
name: "seedvault-lib-core",
sdk_version: "current",
srcs: [
"src/main/java/**/*.kt",
"src/main/java/**/*.java",
],
exclude_srcs: [
"src/main/java/org/calyxos/seedvault/core/backends/BackendTest.kt",
],
static_libs: [
"androidx.core_core-ktx",
"androidx.documentfile_documentfile",
"kotlinx-coroutines-android",
"kotlinx-coroutines-core",
"seedvault-lib-kotlin-logging-jvm",
"seedvault-lib-slf4j-api",
// WebDAV
"seedvault-lib-dav4jvm",
"seedvault-lib-okhttp",
"okio-lib",
],
manifest: "src/main/AndroidManifest.xml",
optimize: {
enabled: false,
},
kotlincflags: [
"-opt-in=kotlin.RequiresOptIn",
],
}

View file

@ -36,17 +36,17 @@ android {
dependencies {
val aospLibs: FileTree by rootProject.extra
compileOnly(aospLibs)
compileOnly("org.ogce:xpp3:1.1.6")
compileOnly(kotlin("test"))
implementation(libs.bundles.kotlin)
implementation(libs.bundles.coroutines)
implementation(libs.androidx.documentfile)
implementation(libs.androidx.core.ktx)
// implementation(fileTree("${rootProject.rootDir}/libs/dav4jvm").include("okio-jvm-3.7.0.jar"))
implementation(fileTree("${rootProject.rootDir}/libs/dav4jvm").include("*.jar"))
implementation("io.github.oshai:kotlin-logging-jvm:6.0.3")
implementation("org.slf4j:slf4j-simple:2.0.3")
implementation(libs.squareup.okio)
implementation(libs.kotlin.logging)
implementation(libs.slf4j.api)
testImplementation(kotlin("test"))
testImplementation("org.ogce:xpp3:1.1.6")
testImplementation("org.slf4j:slf4j-simple:2.0.3")
}

View file

@ -2,7 +2,8 @@
SPDX-FileCopyrightText: 2021 The Calyx Institute
SPDX-License-Identifier: Apache-2.0
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.calyxos.seedvault.core">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

View file

@ -1,24 +0,0 @@
/*
* SPDX-FileCopyrightText: 2024 The Calyx Institute
* SPDX-License-Identifier: Apache-2.0
*/
package org.calyxos.seedvault.core
import android.Manifest.permission.INTERACT_ACROSS_USERS_FULL
import android.content.Context
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.os.UserManager
/**
* Hack to allow other profiles access to USB backend.
* @return the context of the device's main user, so use with great care!
*/
@Suppress("MissingPermission")
public fun Context.getBackendContext(isUsbStorage: () -> Boolean): Context {
if (checkSelfPermission(INTERACT_ACROSS_USERS_FULL) == PERMISSION_GRANTED && isUsbStorage()) {
UserManager.get(this).getProfileParent(user)
?.let { parent -> return createContextAsUser(parent, 0) }
}
return this
}

View file

@ -12,8 +12,10 @@ import org.calyxos.seedvault.core.backends.webdav.WebDavBackend
import org.calyxos.seedvault.core.backends.webdav.WebDavConfig
public class BackendFactory(
private val context: Context,
private val contextGetter: () -> Context,
) {
public fun createSafBackend(config: SafProperties): Backend = SafBackend(context, config)
public fun createSafBackend(config: SafProperties): Backend =
SafBackend(contextGetter(), config)
public fun createWebDavBackend(config: WebDavConfig): Backend = WebDavBackend(config)
}

View file

@ -5,10 +5,10 @@
package org.calyxos.seedvault.core.backends
import android.annotation.WorkerThread
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET
import androidx.annotation.WorkerThread
import at.bitfire.dav4jvm.exception.HttpException
import java.io.IOException

View file

@ -29,7 +29,6 @@ import org.calyxos.seedvault.core.backends.FileHandle
import org.calyxos.seedvault.core.backends.FileInfo
import org.calyxos.seedvault.core.backends.LegacyAppBackupFile
import org.calyxos.seedvault.core.backends.TopLevelFolder
import org.calyxos.seedvault.core.getBackendContext
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
@ -41,17 +40,13 @@ internal const val ROOT_ID_DEVICE = "primary"
private const val DEBUG_LOG = true
public class SafBackend(
private val appContext: Context,
private val context: Context,
private val safProperties: SafProperties,
root: String = DIRECTORY_ROOT,
) : Backend {
private val log = KotlinLogging.logger {}
/**
* Attention: This context might be from a different user. Use with care.
*/
private val context: Context get() = appContext.getBackendContext { safProperties.isUsb }
private val cache = DocumentFileCache(context, safProperties.getDocumentFile(context), root)
override suspend fun test(): Boolean {

View file

@ -40,6 +40,10 @@ dokka = "1.9.20" # Dokka has no releases after 1.9.20
# Lint versions
lint-rules = { strictly = "0.1.0" }
# Logging libs (check versions at /libs)
logging = { strictly = "6.0.3" }
slf4j-api = { strictly = "2.0.16" }
# Google versions
# https://android.googlesource.com/platform/external/protobuf/+/refs/tags/android-15.0.0_r1/java/pom.xml#7
protobuf = { strictly = "3.21.12" }
@ -74,6 +78,9 @@ androidx-documentfile = { strictly = "1.1.0-alpha01" } # 1.1.0-alpha02 in AOSP b
# https://android.googlesource.com/platform/prebuilts/sdk/+/android-15.0.0_r1/current/androidx/m2repository/androidx/work/work-runtime-ktx?autodive=0
androidx-work-runtime = { strictly = "2.10.0-alpha02" }
# https://android.googlesource.com/platform/external/okio/+/refs/tags/android-14.0.0_r53/CHANGELOG.md
squareup-okio = { strictly = "3.7.0" }
[libraries]
# Kotlin standard dependencies
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
@ -105,6 +112,10 @@ androidx-documentfile = { module = "androidx.documentfile:documentfile", version
androidx-work-runtime-ktx = { module = "androidx.work:work-runtime-ktx", version.ref = "androidx-work-runtime" }
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
squareup-okio = { module= "com.squareup.okio:okio", version.ref = "squareup-okio" }
kotlin-logging = { module = "io.github.oshai:kotlin-logging-jvm", version.ref = "logging" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j-api" }
[bundles]
kotlin = ["kotlin-stdlib", "kotlin-stdlib-jdk8", "kotlin-stdlib-common"]
coroutines = ["kotlinx-coroutines-core-jvm", "kotlinx-coroutines-android"]

View file

@ -8,3 +8,15 @@ java_import {
jars: ["kotlin-bip39-jvm-1.0.6.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",
}

View file

@ -14,9 +14,3 @@ java_import {
jars: ["okhttp-4.12.0.jar"],
sdk_version: "current",
}
java_import {
name: "seedvault-lib-okio",
jars: ["okio-jvm-3.7.0.jar"],
sdk_version: "current",
}

Binary file not shown.

Binary file not shown.

BIN
libs/slf4j-api-2.0.16.jar Normal file

Binary file not shown.

View file

@ -19,6 +19,7 @@ android_library {
local_include_dirs: ["src/main/proto"],
},
static_libs: [
"seedvault-lib-core",
"seedvault-lib-tink-android",
"libprotobuf-java-lite",
"androidx.core_core-ktx",

View file

@ -94,9 +94,6 @@ dependencies {
implementation(libs.androidx.room.runtime)
implementation(libs.google.protobuf.javalite)
implementation(libs.google.tink.android)
// TODO include via gradle and AOSP
// https://android.googlesource.com/platform/external/okio/+/refs/tags/android-14.0.0_r53/CHANGELOG.md
implementation(fileTree("${rootProject.rootDir}/libs/dav4jvm").include("okio-jvm-3.7.0.jar"))
ksp(group = "androidx.room", name = "room-compiler", version = libs.versions.room.get())
lintChecks(libs.thirdegg.lint.rules)