feat(android): SDK AAR (UniFFI) + Compose APK, Arti rustls feature split
All checks were successful
ci / test (pull_request) Successful in 3m22s
All checks were successful
ci / test (pull_request) Successful in 3m22s
Adds the Android product alongside the existing Linux TUI, in one repo. SDK — crates/onionwire-sdk is a UniFFI facade over the very same `onionwire` crate the TUI runs on. Identity, invite, friend upsert, send/receive, rotate and wipe all delegate; no protocol is reimplemented, so an Android peer and a Linux peer interoperate. It is its own Cargo workspace because Arti's TLS backends are non-additive: the TUI keeps native-tls (OpenSSL), Android needs rustls + static-sqlite (no OpenSSL, no system libsqlite3 in the NDK). android/ — Gradle project. :sdk produces the AAR (Kotlin bindings generated at build time + libonionwire_sdk.so via cargo-ndk), :app is a Kotlin/Compose/M3 messenger depending on :sdk only. minSdk 26, targetSdk/compileSdk 36, INTERNET-only, data in filesDir, backups excluded. Root Cargo.toml grows `native-tls` (default) and `rustls` features so exactly one Arti TLS backend is selected per build graph. The default build is unchanged: same backend, ratatui still a normal dependency, src/tui.rs untouched. Also: Store::self_fingerprint/set_petname + Node wrappers (additive only), scripts/build-android-local.sh, README sections, .gitignore for local SDK paths.
This commit is contained in:
parent
2b42864eba
commit
672f2c9990
41 changed files with 9387 additions and 1 deletions
|
|
@ -0,0 +1,124 @@
|
|||
package com.siriusdevops.onionwire
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import uniffi.onionwire_sdk.ChatMessage
|
||||
import uniffi.onionwire_sdk.FriendInfo
|
||||
import uniffi.onionwire_sdk.InviteInfo
|
||||
import uniffi.onionwire_sdk.RotateOutcome
|
||||
import uniffi.onionwire_sdk.Wire
|
||||
import uniffi.onionwire_sdk.decodeInvite
|
||||
import uniffi.onionwire_sdk.openWire
|
||||
import java.io.File
|
||||
|
||||
sealed interface Phase {
|
||||
/** No identity unlocked. Nothing Tor-related is running. */
|
||||
data object Locked : Phase
|
||||
|
||||
/** Bootstrap + onion publish. Cold start is minutes, not seconds. */
|
||||
data object Opening : Phase
|
||||
|
||||
data class Ready(
|
||||
val fingerprint: String,
|
||||
val onion: String,
|
||||
val sdkVersion: String,
|
||||
) : Phase
|
||||
|
||||
data class Failed(val message: String) : Phase
|
||||
}
|
||||
|
||||
/**
|
||||
* Owns the single Wire node for the process.
|
||||
*
|
||||
* The node lives in the ViewModel because a configuration change must not
|
||||
* drop a published onion service and re-bootstrap Tor.
|
||||
*/
|
||||
class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||
|
||||
/** `context.filesDir` — app-private, never external storage. */
|
||||
private val home: File = File(app.filesDir, "onionwire")
|
||||
|
||||
private val _phase = MutableStateFlow<Phase>(Phase.Locked)
|
||||
val phase: StateFlow<Phase> = _phase.asStateFlow()
|
||||
|
||||
private val _friends = MutableStateFlow<List<FriendInfo>>(emptyList())
|
||||
val friends: StateFlow<List<FriendInfo>> = _friends.asStateFlow()
|
||||
|
||||
private var wire: Wire? = null
|
||||
|
||||
/**
|
||||
* Opens (or on first run, creates) the identity and starts hosting.
|
||||
*
|
||||
* An empty passphrase fails closed — the SDK maps it straight to an error,
|
||||
* it is not a "skip" path.
|
||||
*/
|
||||
fun unlock(passphrase: String) {
|
||||
if (_phase.value is Phase.Opening) return
|
||||
_phase.value = Phase.Opening
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val w = openWire(home.absolutePath, passphrase)
|
||||
wire = w
|
||||
_phase.value = Phase.Ready(
|
||||
fingerprint = w.fingerprint(),
|
||||
onion = w.onion(),
|
||||
sdkVersion = w.version(),
|
||||
)
|
||||
refreshFriends()
|
||||
} catch (t: Throwable) {
|
||||
_phase.value = Phase.Failed(t.message ?: t.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Drops our handle. The onion service stops; nothing is sent after this. */
|
||||
fun lock() {
|
||||
wire = null
|
||||
_friends.value = emptyList()
|
||||
_phase.value = Phase.Locked
|
||||
}
|
||||
|
||||
private fun requireWire(): Wire = wire ?: error("locked")
|
||||
|
||||
suspend fun refreshFriends() {
|
||||
_friends.value = requireWire().friends()
|
||||
}
|
||||
|
||||
suspend fun invite(): String = requireWire().invite()
|
||||
|
||||
suspend fun addFriend(invite: String): FriendInfo {
|
||||
val f = requireWire().addFriend(invite)
|
||||
refreshFriends()
|
||||
return f
|
||||
}
|
||||
|
||||
suspend fun setPetname(pubkeyHex: String, petname: String?) {
|
||||
requireWire().setPetname(pubkeyHex, petname?.takeIf { it.isNotBlank() })
|
||||
refreshFriends()
|
||||
}
|
||||
|
||||
suspend fun messages(pubkeyHex: String): List<ChatMessage> =
|
||||
requireWire().messages(pubkeyHex)
|
||||
|
||||
suspend fun send(pubkeyHex: String, body: String) =
|
||||
requireWire().send(pubkeyHex, body)
|
||||
|
||||
suspend fun wipeMessages() {
|
||||
requireWire().wipeMessages()
|
||||
}
|
||||
|
||||
suspend fun rotateOnion(): RotateOutcome {
|
||||
val out = requireWire().rotateOnion()
|
||||
_phase.value = (_phase.value as? Phase.Ready)?.copy(onion = requireWire().onion())
|
||||
?: _phase.value
|
||||
refreshFriends()
|
||||
return out
|
||||
}
|
||||
|
||||
suspend fun decode(invite: String): InviteInfo = decodeInvite(invite)
|
||||
}
|
||||
Loading…
Reference in a new issue