Skip to content

Commit

Permalink
clean up libs and fix AOSP build
Browse files Browse the repository at this point in the history
  • Loading branch information
grote committed Aug 29, 2024
1 parent 48aea1d commit c1a8bbc
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +37,6 @@ android_app {
// WebDAV
"seedvault-lib-dav4jvm",
"seedvault-lib-okhttp",
"seedvault-lib-okio",
],
manifest: "app/src/main/AndroidManifest.xml",

Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/com/stevesoltys/seedvault/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) }
Expand Down Expand Up @@ -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()) {
Expand Down
35 changes: 35 additions & 0 deletions core/Android.bp
Original file line number Diff line number Diff line change
@@ -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",
"slf4j-api",
"seedvault-lib-kotlin-logging-jvm",
// WebDAV
"seedvault-lib-dav4jvm",
"seedvault-lib-okhttp",
"okio-lib",
],
manifest: "src/main/AndroidManifest.xml",
optimize: {
enabled: false,
},
kotlincflags: [
"-opt-in=kotlin.RequiresOptIn",
],
}
8 changes: 4 additions & 4 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
3 changes: 2 additions & 1 deletion core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
24 changes: 0 additions & 24 deletions core/src/main/java/org/calyxos/seedvault/core/Utils.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dokka = "1.9.20" # Dokka has no releases after 1.9.20

# Lint versions
lint-rules = { strictly = "0.1.0" }
logging = { strictly = "6.0.3" }

# Google versions
# https://android.googlesource.com/platform/external/protobuf/+/refs/tags/android-14.0.0_r53/java/pom.xml#7
Expand Down Expand Up @@ -73,6 +74,11 @@ androidx-documentfile = { strictly = "1.1.0-alpha01" } # 1.1.0-alpha02 in AOSP b
# https://android.googlesource.com/platform/prebuilts/sdk/+/android-14.0.0_r53/current/androidx/m2repository/androidx/work/work-runtime-ktx?autodive=0
androidx-work-runtime = { strictly = "2.10.0-alpha01" }

# https://android.googlesource.com/platform/external/okio/+/refs/tags/android-14.0.0_r53/CHANGELOG.md
squareup-okio = { strictly = "3.7.0" }
# https://android.googlesource.com/platform/external/slf4j/+/refs/tags/android-14.0.0_r53/slf4j-api/pom.xml#10
slf4j-api = { strictly = "2.0.12" }

[libraries]
# Kotlin standard dependencies
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
Expand Down Expand Up @@ -104,6 +110,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"]
Expand Down
6 changes: 6 additions & 0 deletions libs/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ 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",
}
6 changes: 0 additions & 6 deletions libs/dav4jvm/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -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 removed libs/dav4jvm/okio-jvm-3.7.0.jar
Binary file not shown.
Binary file added libs/kotlin-logging-jvm-6.0.3.jar
Binary file not shown.
1 change: 1 addition & 0 deletions storage/lib/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions storage/lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c1a8bbc

Please sign in to comment.