Compare commits
12 changed files with 33 additions and 251 deletions
|
|
@ -154,12 +154,6 @@ jobs:
|
||||||
rustc --version
|
rustc --version
|
||||||
cargo ndk --version
|
cargo ndk --version
|
||||||
du -sh /opt/android-sdk /cargo /cargo-target /gradle || true
|
du -sh /opt/android-sdk /cargo /cargo-target /gradle || true
|
||||||
# Shared /gradle volume: a killed container leaves journal-1.lock.
|
|
||||||
# android/gradle.properties also sets org.gradle.parallel=true, which
|
|
||||||
# is how two JVMs (PIDs ~5 apart) show up on one lock. Drop the
|
|
||||||
# stale locks and force one Gradle process for this container.
|
|
||||||
find /gradle -name '*.lock' -type f -delete 2>/dev/null || true
|
|
||||||
export GRADLE_OPTS="${GRADLE_OPTS:-} -Dorg.gradle.parallel=false -Dorg.gradle.daemon=false"
|
|
||||||
# No keystore here on purpose: this is a verification build, not a
|
# No keystore here on purpose: this is a verification build, not a
|
||||||
# release build. The script warns that Gradle fell back to the debug
|
# release build. The script warns that Gradle fell back to the debug
|
||||||
# key; that warning is expected in this job.
|
# key; that warning is expected in this job.
|
||||||
|
|
@ -234,12 +228,6 @@ jobs:
|
||||||
docker volume create "$CARGO_VOLUME" >/dev/null
|
docker volume create "$CARGO_VOLUME" >/dev/null
|
||||||
docker volume create "$TARGET_VOLUME" >/dev/null
|
docker volume create "$TARGET_VOLUME" >/dev/null
|
||||||
docker volume create "$GRADLE_VOLUME" >/dev/null
|
docker volume create "$GRADLE_VOLUME" >/dev/null
|
||||||
# Cancelled jobs never reach the trailing `docker rm`, so a previous
|
|
||||||
# onionwire-android-* container can still hold GRADLE_VOLUME. The next
|
|
||||||
# Gradle then dies LockTimeoutException on /gradle/caches/journal-1
|
|
||||||
# (owner PID vs our PID a few numbers apart — two JVMs, one volume).
|
|
||||||
trap 'docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true' EXIT
|
|
||||||
docker ps -aq --filter name=onionwire-android- | xargs -r docker rm -f || true
|
|
||||||
docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true
|
docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true
|
||||||
docker pull "$ANDROID_IMAGE"
|
docker pull "$ANDROID_IMAGE"
|
||||||
# 2 GB of Gradle heap, not 1: the only budget in this build that is close
|
# 2 GB of Gradle heap, not 1: the only budget in this build that is close
|
||||||
|
|
@ -262,7 +250,7 @@ jobs:
|
||||||
-e ONIONWIRE_REQUIRE_RELEASE_KEY=false \
|
-e ONIONWIRE_REQUIRE_RELEASE_KEY=false \
|
||||||
-e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \
|
-e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \
|
||||||
-e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \
|
-e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \
|
||||||
-e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
|
-e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
|
||||||
-v "$SDK_VOLUME":/opt/android-sdk \
|
-v "$SDK_VOLUME":/opt/android-sdk \
|
||||||
-v "$CARGO_VOLUME":/cargo \
|
-v "$CARGO_VOLUME":/cargo \
|
||||||
-v "$TARGET_VOLUME":/cargo-target \
|
-v "$TARGET_VOLUME":/cargo-target \
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,6 @@ jobs:
|
||||||
rustc --version
|
rustc --version
|
||||||
cargo ndk --version
|
cargo ndk --version
|
||||||
du -sh /opt/android-sdk /cargo /cargo-target /gradle || true
|
du -sh /opt/android-sdk /cargo /cargo-target /gradle || true
|
||||||
find /gradle -name '*.lock' -type f -delete 2>/dev/null || true
|
|
||||||
export GRADLE_OPTS="${GRADLE_OPTS:-} -Dorg.gradle.parallel=false -Dorg.gradle.daemon=false"
|
|
||||||
scripts/build-android-local.sh "$ONIONWIRE_VERSION"
|
scripts/build-android-local.sh "$ONIONWIRE_VERSION"
|
||||||
version="$ONIONWIRE_VERSION"
|
version="$ONIONWIRE_VERSION"
|
||||||
abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}"
|
abi="${ONIONWIRE_ANDROID_ABI:-arm64-v8a}"
|
||||||
|
|
@ -299,10 +297,6 @@ jobs:
|
||||||
docker volume create "$CARGO_VOLUME" >/dev/null
|
docker volume create "$CARGO_VOLUME" >/dev/null
|
||||||
docker volume create "$TARGET_VOLUME" >/dev/null
|
docker volume create "$TARGET_VOLUME" >/dev/null
|
||||||
docker volume create "$GRADLE_VOLUME" >/dev/null
|
docker volume create "$GRADLE_VOLUME" >/dev/null
|
||||||
# Same shared GRADLE_VOLUME as android-ci.yml. A cancelled job leaves
|
|
||||||
# the build container running and journal-1.lock held.
|
|
||||||
trap 'docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true' EXIT
|
|
||||||
docker ps -aq --filter name=onionwire-android- | xargs -r docker rm -f || true
|
|
||||||
docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true
|
docker rm -f "$BUILD_CONTAINER" >/dev/null 2>&1 || true
|
||||||
docker pull "$ANDROID_IMAGE"
|
docker pull "$ANDROID_IMAGE"
|
||||||
# 2 GB of Gradle heap, not 1: the only budget in this build that is close
|
# 2 GB of Gradle heap, not 1: the only budget in this build that is close
|
||||||
|
|
@ -327,7 +321,7 @@ jobs:
|
||||||
-e ONIONWIRE_VERSION="$VERSION" \
|
-e ONIONWIRE_VERSION="$VERSION" \
|
||||||
-e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \
|
-e RUST_TOOLCHAIN="$RUST_TOOLCHAIN" \
|
||||||
-e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \
|
-e ANDROID_CMDLINE_TOOLS_URL="$ANDROID_CMDLINE_TOOLS_URL" \
|
||||||
-e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
|
-e GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \
|
||||||
-v "$SDK_VOLUME":/opt/android-sdk \
|
-v "$SDK_VOLUME":/opt/android-sdk \
|
||||||
-v "$CARGO_VOLUME":/cargo \
|
-v "$CARGO_VOLUME":/cargo \
|
||||||
-v "$TARGET_VOLUME":/cargo-target \
|
-v "$TARGET_VOLUME":/cargo-target \
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import com.siriusdevops.onionwire.wallet.ChainStorage
|
||||||
import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE
|
import com.siriusdevops.onionwire.wallet.NO_WALLET_RPC_MESSAGE
|
||||||
import com.siriusdevops.onionwire.wallet.WalletChildBinaries
|
import com.siriusdevops.onionwire.wallet.WalletChildBinaries
|
||||||
import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths
|
import com.siriusdevops.onionwire.wallet.WalletChildBinaryPaths
|
||||||
import kotlinx.coroutines.CancellationException
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.currentCoroutineContext
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
|
@ -152,13 +151,10 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||||
// is already open would be theatre, and unlocking again would race the
|
// is already open would be theatre, and unlocking again would race the
|
||||||
// live node for the sqlite file.
|
// live node for the sqlite file.
|
||||||
val existing = NodeHost.current()
|
val existing = NodeHost.current()
|
||||||
when {
|
if (existing != null) {
|
||||||
existing != null -> viewModelScope.launch { adopt(existing) }
|
viewModelScope.launch { adopt(existing) }
|
||||||
NodeHost.isOpening() -> {
|
} else {
|
||||||
_phase.value = Phase.Opening
|
refreshUnlockState()
|
||||||
viewModelScope.launch { resumeOpening() }
|
|
||||||
}
|
|
||||||
else -> refreshUnlockState()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|
@ -312,23 +308,17 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_phase.value = Phase.Opening
|
_phase.value = Phase.Opening
|
||||||
NodeHost.noteOpening()
|
|
||||||
// Hold the process from this tap, not after Tor publishes: otherwise
|
|
||||||
// closing the activity cancels viewModelScope and kills bootstrap.
|
|
||||||
KeepAliveService.start(getApplication(), "")
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
|
// The SDK open is dispatched to Dispatchers.IO inside NodeHost:
|
||||||
|
// cold start is minutes of Tor bootstrap, which the main thread
|
||||||
|
// does not survive.
|
||||||
val w = NodeHost.open(home, secret.concatToString())
|
val w = NodeHost.open(home, secret.concatToString())
|
||||||
if (storeAfterwards) store(secret)
|
if (storeAfterwards) store(secret)
|
||||||
adopt(w)
|
adopt(w)
|
||||||
startKeepAlive(w)
|
startKeepAlive(w)
|
||||||
} catch (t: CancellationException) {
|
|
||||||
throw t
|
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
_phase.value = Phase.Failed(t.message ?: t.toString())
|
_phase.value = Phase.Failed(t.message ?: t.toString())
|
||||||
if (!NodeHost.hasWorkForKeepAlive()) {
|
|
||||||
KeepAliveService.stop(getApplication())
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
StoreSecret.wipe(secret)
|
StoreSecret.wipe(secret)
|
||||||
}
|
}
|
||||||
|
|
@ -348,19 +338,6 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
||||||
runCatching { refreshFriends() }
|
runCatching { refreshFriends() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Re-attach after the activity died mid-bootstrap. */
|
|
||||||
private suspend fun resumeOpening() {
|
|
||||||
try {
|
|
||||||
val w = NodeHost.awaitOpen()
|
|
||||||
adopt(w)
|
|
||||||
startKeepAlive(w)
|
|
||||||
} catch (t: CancellationException) {
|
|
||||||
throw t
|
|
||||||
} catch (t: Throwable) {
|
|
||||||
_phase.value = Phase.Failed(t.message ?: t.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the foreground keep-alive. Always reached from a user-visible
|
* Starts the foreground keep-alive. Always reached from a user-visible
|
||||||
* unlock, so the API 31+ background-start restriction does not apply; if
|
* unlock, so the API 31+ background-start restriction does not apply; if
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
package com.siriusdevops.onionwire.keepalive
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the foreground service has anything to hold.
|
|
||||||
*
|
|
||||||
* Bootstrap used to not count: the service bailed when `Wire` was still null,
|
|
||||||
* and `openWire` ran on the UI ViewModel scope, so closing the activity
|
|
||||||
* cancelled Tor bring-up. Opening is work; a published node is work; locked
|
|
||||||
* and idle is not.
|
|
||||||
*/
|
|
||||||
fun keepAliveHasWork(nodeOpen: Boolean, bootstrapInFlight: Boolean): Boolean =
|
|
||||||
nodeOpen || bootstrapInFlight
|
|
||||||
|
|
@ -44,10 +44,8 @@ class KeepAliveService : Service() {
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!NodeHost.hasWorkForKeepAlive()) {
|
if (NodeHost.current() == null) {
|
||||||
// Nothing to keep alive. A notification here would be a lie.
|
// Nothing to keep alive. A notification here would be a lie.
|
||||||
// Bootstrap counts: the node is not `current()` until Tor has
|
|
||||||
// published, and that is exactly the window Android used to kill.
|
|
||||||
stopSelf()
|
stopSelf()
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
|
|
@ -127,20 +125,14 @@ class KeepAliveService : Service() {
|
||||||
)
|
)
|
||||||
// Never the full v3 locator: a notification body is lock-screen public.
|
// Never the full v3 locator: a notification body is lock-screen public.
|
||||||
val short = onion.take(ONION_PREFIX)
|
val short = onion.take(ONION_PREFIX)
|
||||||
val opening = short.isEmpty() && NodeHost.isOpening()
|
val text = if (short.isEmpty()) {
|
||||||
val title = if (opening) {
|
getString(R.string.keep_alive_text)
|
||||||
getString(R.string.keep_alive_title_opening)
|
|
||||||
} else {
|
} else {
|
||||||
getString(R.string.keep_alive_title)
|
getString(R.string.keep_alive_text_onion, short)
|
||||||
}
|
|
||||||
val text = when {
|
|
||||||
opening -> getString(R.string.keep_alive_text_opening)
|
|
||||||
short.isEmpty() -> getString(R.string.keep_alive_text)
|
|
||||||
else -> getString(R.string.keep_alive_text_onion, short)
|
|
||||||
}
|
}
|
||||||
return NotificationCompat.Builder(this, CHANNEL_ID)
|
return NotificationCompat.Builder(this, CHANNEL_ID)
|
||||||
.setSmallIcon(R.drawable.ic_stat_onion)
|
.setSmallIcon(R.drawable.ic_stat_onion)
|
||||||
.setContentTitle(title)
|
.setContentTitle(getString(R.string.keep_alive_title))
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setContentIntent(open)
|
.setContentIntent(open)
|
||||||
.addAction(0, getString(R.string.keep_alive_stop), stop)
|
.addAction(0, getString(R.string.keep_alive_stop), stop)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
package com.siriusdevops.onionwire.keepalive
|
package com.siriusdevops.onionwire.keepalive
|
||||||
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Deferred
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import uniffi.onionwire_sdk.Wire
|
import uniffi.onionwire_sdk.Wire
|
||||||
import uniffi.onionwire_sdk.openWire
|
import uniffi.onionwire_sdk.openWire
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
@ -46,8 +45,8 @@ sealed interface KeepAliveStatus {
|
||||||
* service would have kept a notification up for a node the UI had already
|
* service would have kept a notification up for a node the UI had already
|
||||||
* killed. Neither side owns the node now; the policy does.
|
* killed. Neither side owns the node now; the policy does.
|
||||||
*
|
*
|
||||||
* Threading: [open] runs on [scope] (IO). [wire] is volatile so the main
|
* Threading: every mutation runs on the main thread except the SDK call inside
|
||||||
* thread can read [current] while bootstrap completes off-main.
|
* [open], which is dispatched to [Dispatchers.IO] and hops back.
|
||||||
*/
|
*/
|
||||||
object NodeHost {
|
object NodeHost {
|
||||||
|
|
||||||
|
|
@ -61,23 +60,8 @@ object NodeHost {
|
||||||
|
|
||||||
private val lifetime = NodeLifetime()
|
private val lifetime = NodeLifetime()
|
||||||
|
|
||||||
@Volatile
|
|
||||||
private var wire: Wire? = null
|
private var wire: Wire? = null
|
||||||
|
|
||||||
/**
|
|
||||||
* In-flight `openWire`. Lives on [scope], not the UI ViewModel: closing the
|
|
||||||
* activity must not cancel Tor bootstrap. Null when idle or already open.
|
|
||||||
*/
|
|
||||||
@Volatile
|
|
||||||
private var bootstrap: Deferred<Wire>? = null
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set before the keep-alive starts, before [bootstrap] exists, so the
|
|
||||||
* service does not `stopSelf` in the gap between Unlock and `openWire`.
|
|
||||||
*/
|
|
||||||
@Volatile
|
|
||||||
private var claimedOpening: Boolean = false
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The in-flight teardown, if any. Re-opening has to wait for it: the old
|
* The in-flight teardown, if any. Re-opening has to wait for it: the old
|
||||||
* node holds the sqlite file and Arti's state lock until `shutdown()`
|
* node holds the sqlite file and Arti's state lock until `shutdown()`
|
||||||
|
|
@ -91,21 +75,6 @@ object NodeHost {
|
||||||
/** The live node, or null when locked. */
|
/** The live node, or null when locked. */
|
||||||
fun current(): Wire? = wire
|
fun current(): Wire? = wire
|
||||||
|
|
||||||
/** Tor bring-up is running on [scope]. The UI may be gone. */
|
|
||||||
fun isOpening(): Boolean = claimedOpening || bootstrap?.isActive == true
|
|
||||||
|
|
||||||
/** The foreground service holds a published node *or* an in-flight open. */
|
|
||||||
fun hasWorkForKeepAlive(): Boolean =
|
|
||||||
keepAliveHasWork(nodeOpen = wire != null, bootstrapInFlight = isOpening())
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call *before* [KeepAliveService.start] on the unlock path so the service
|
|
||||||
* sees bootstrap work before `openWire` has a job.
|
|
||||||
*/
|
|
||||||
fun noteOpening() {
|
|
||||||
claimedOpening = true
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The live node, or a hard error. Callers are UI paths that require unlock. */
|
/** The live node, or a hard error. Callers are UI paths that require unlock. */
|
||||||
fun requireOpen(): Wire = wire ?: error("locked")
|
fun requireOpen(): Wire = wire ?: error("locked")
|
||||||
|
|
||||||
|
|
@ -113,37 +82,15 @@ object NodeHost {
|
||||||
* Opens the node and anchors it to the UI.
|
* Opens the node and anchors it to the UI.
|
||||||
*
|
*
|
||||||
* Suspends inside Arti's bootstrap — minutes on a cold start — so this must
|
* Suspends inside Arti's bootstrap — minutes on a cold start — so this must
|
||||||
* never run on the main thread. The *work* runs on [scope], not the caller's
|
* never run on the main thread. Callers are `viewModelScope` coroutines.
|
||||||
* job: a `viewModelScope` cancellation (activity gone) must not abort Tor.
|
|
||||||
* A second call while bootstrap is in flight joins the same job.
|
|
||||||
*/
|
*/
|
||||||
suspend fun open(home: File, passphrase: String): Wire {
|
suspend fun open(home: File, passphrase: String): Wire {
|
||||||
stopping?.join()
|
stopping?.join()
|
||||||
wire?.let { return it }
|
val opened = withContext(Dispatchers.IO) { openWire(home.absolutePath, passphrase) }
|
||||||
bootstrap?.let { return it.await() }
|
|
||||||
val job = scope.async {
|
|
||||||
val opened = openWire(home.absolutePath, passphrase)
|
|
||||||
wire = opened
|
wire = opened
|
||||||
// Keep-alive may already be On: it starts at unlock so Android
|
|
||||||
// will not kill us mid-bootstrap. Do not stomp that.
|
|
||||||
if (_keepAlive.value !is KeepAliveStatus.On) {
|
|
||||||
_keepAlive.value = KeepAliveStatus.Off
|
_keepAlive.value = KeepAliveStatus.Off
|
||||||
}
|
|
||||||
lifetime.onOpened()
|
lifetime.onOpened()
|
||||||
opened
|
return opened
|
||||||
}
|
|
||||||
bootstrap = job
|
|
||||||
job.invokeOnCompletion {
|
|
||||||
if (bootstrap === job) bootstrap = null
|
|
||||||
claimedOpening = false
|
|
||||||
}
|
|
||||||
return job.await()
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Join an in-flight [open] without starting a second `openWire`. */
|
|
||||||
suspend fun awaitOpen(): Wire {
|
|
||||||
wire?.let { return it }
|
|
||||||
return bootstrap?.await() ?: error("locked")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The UI is going away: finish, task swipe, or process death. */
|
/** The UI is going away: finish, task swipe, or process death. */
|
||||||
|
|
@ -176,12 +123,7 @@ object NodeHost {
|
||||||
* stops the keep-alive first — a service that is still running would
|
* stops the keep-alive first — a service that is still running would
|
||||||
* re-anchor a node that no longer exists.
|
* re-anchor a node that no longer exists.
|
||||||
*/
|
*/
|
||||||
fun lock(): NodeAction {
|
fun lock(): NodeAction = apply(lifetime.onLocked())
|
||||||
bootstrap?.cancel()
|
|
||||||
bootstrap = null
|
|
||||||
claimedOpening = false
|
|
||||||
return apply(lifetime.onLocked())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun apply(action: NodeAction): NodeAction {
|
private fun apply(action: NodeAction): NodeAction {
|
||||||
when (action) {
|
when (action) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
|
@ -28,7 +27,6 @@ import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
|
@ -63,19 +61,10 @@ fun UnlockScreen(
|
||||||
// Only meaningful under OneTap: reveal the form without giving up the
|
// Only meaningful under OneTap: reveal the form without giving up the
|
||||||
// stored passphrase.
|
// stored passphrase.
|
||||||
var typeInstead by remember { mutableStateOf(false) }
|
var typeInstead by remember { mutableStateOf(false) }
|
||||||
val keyboard = LocalSoftwareKeyboardController.current
|
|
||||||
|
|
||||||
val oneTap = unlock as? Unlock.OneTap
|
val oneTap = unlock as? Unlock.OneTap
|
||||||
val failed = phase is Phase.Failed
|
val failed = phase is Phase.Failed
|
||||||
val showForm = oneTap == null || typeInstead || failed
|
val showForm = oneTap == null || typeInstead || failed
|
||||||
// IME Done and Open share this. Done with no KeyboardActions used to
|
|
||||||
// dismiss the keyboard and never call unlock, so bootstrap never started.
|
|
||||||
fun submit() {
|
|
||||||
val handed = unlockSubmit(pass, storePassphrase) ?: return
|
|
||||||
pass = ""
|
|
||||||
keyboard?.hide()
|
|
||||||
onUnlock(handed.passphrase, handed.remember)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
@ -162,11 +151,7 @@ fun UnlockScreen(
|
||||||
visualTransformation = PasswordVisualTransformation(),
|
visualTransformation = PasswordVisualTransformation(),
|
||||||
keyboardOptions = KeyboardOptions(
|
keyboardOptions = KeyboardOptions(
|
||||||
keyboardType = KeyboardType.Password,
|
keyboardType = KeyboardType.Password,
|
||||||
imeAction = ImeAction.Go,
|
imeAction = ImeAction.Done,
|
||||||
),
|
|
||||||
keyboardActions = KeyboardActions(
|
|
||||||
onGo = { submit() },
|
|
||||||
onDone = { submit() },
|
|
||||||
),
|
),
|
||||||
label = { Text("wraps the local message key") },
|
label = { Text("wraps the local message key") },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
|
@ -204,7 +189,13 @@ fun UnlockScreen(
|
||||||
|
|
||||||
Spacer(Modifier.height(20.dp))
|
Spacer(Modifier.height(20.dp))
|
||||||
Button(
|
Button(
|
||||||
onClick = { submit() },
|
onClick = {
|
||||||
|
val typed = pass
|
||||||
|
// Drop the plaintext from Compose state the moment
|
||||||
|
// it is handed over; the ViewModel wipes its copy.
|
||||||
|
pass = ""
|
||||||
|
onUnlock(typed, storePassphrase)
|
||||||
|
},
|
||||||
enabled = pass.isNotEmpty(),
|
enabled = pass.isNotEmpty(),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) { Text("Open") }
|
) { Text("Open") }
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package com.siriusdevops.onionwire.ui
|
|
||||||
|
|
||||||
/**
|
|
||||||
* One submit for IME Done and the Open button.
|
|
||||||
*
|
|
||||||
* The IME action used to be `Done` with no [androidx.compose.foundation.text.KeyboardActions]:
|
|
||||||
* the keyboard closed and [com.siriusdevops.onionwire.WireViewModel.unlock] was never
|
|
||||||
* called, so bootstrap never started. Empty stays a no-op — the SDK fails closed
|
|
||||||
* on an empty passphrase, and we do not open the node for it.
|
|
||||||
*/
|
|
||||||
internal data class UnlockSubmit(val passphrase: String, val remember: Boolean)
|
|
||||||
|
|
||||||
internal fun unlockSubmit(pass: String, remember: Boolean): UnlockSubmit? {
|
|
||||||
if (pass.isEmpty()) return null
|
|
||||||
return UnlockSubmit(passphrase = pass, remember = remember)
|
|
||||||
}
|
|
||||||
|
|
@ -10,9 +10,7 @@
|
||||||
<string name="keep_alive_channel_name">Node keep-alive</string>
|
<string name="keep_alive_channel_name">Node keep-alive</string>
|
||||||
<string name="keep_alive_channel_description">Shown while OnionWire keeps your onion address reachable in the background.</string>
|
<string name="keep_alive_channel_description">Shown while OnionWire keeps your onion address reachable in the background.</string>
|
||||||
<string name="keep_alive_title">OnionWire is reachable</string>
|
<string name="keep_alive_title">OnionWire is reachable</string>
|
||||||
<string name="keep_alive_title_opening">OnionWire is starting</string>
|
|
||||||
<string name="keep_alive_text">Tor and the outbox are running so peers can deliver messages.</string>
|
<string name="keep_alive_text">Tor and the outbox are running so peers can deliver messages.</string>
|
||||||
<string name="keep_alive_text_opening">Bootstrapping Tor. This can take minutes — keep the device awake.</string>
|
|
||||||
<string name="keep_alive_text_onion">Tor and the outbox are running so peers can reach %1$s…</string>
|
<string name="keep_alive_text_onion">Tor and the outbox are running so peers can reach %1$s…</string>
|
||||||
<string name="keep_alive_stop">Stop keep-alive</string>
|
<string name="keep_alive_stop">Stop keep-alive</string>
|
||||||
<string name="keep_alive_note_off">Reachable only while this app is open.</string>
|
<string name="keep_alive_note_off">Reachable only while this app is open.</string>
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package com.siriusdevops.onionwire.keepalive
|
|
||||||
|
|
||||||
import org.junit.Assert.assertFalse
|
|
||||||
import org.junit.Assert.assertTrue
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The keep-alive used to refuse to start until [NodeHost.current] was set —
|
|
||||||
* which is only after Tor has published. Bootstrap itself ran on the UI
|
|
||||||
* ViewModel scope, so closing the activity cancelled `openWire` and the
|
|
||||||
* spinner vanished with no onion.
|
|
||||||
*/
|
|
||||||
class KeepAlivePolicyTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun bootstrap_in_flight_is_work_the_service_must_hold() {
|
|
||||||
assertTrue(keepAliveHasWork(nodeOpen = false, bootstrapInFlight = true))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun a_live_node_is_work_the_service_must_hold() {
|
|
||||||
assertTrue(keepAliveHasWork(nodeOpen = true, bootstrapInFlight = false))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun locked_and_idle_is_not_work() {
|
|
||||||
assertFalse(keepAliveHasWork(nodeOpen = false, bootstrapInFlight = false))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
package com.siriusdevops.onionwire.ui
|
|
||||||
|
|
||||||
import org.junit.Assert.assertEquals
|
|
||||||
import org.junit.Assert.assertNull
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IME Done and the Open button must share one submit: the keyboard's action
|
|
||||||
* key used to dismiss the IME and never call unlock, so bootstrap never
|
|
||||||
* started. Empty stays a no-op (the SDK would fail closed; we never open).
|
|
||||||
*/
|
|
||||||
class UnlockSubmitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun empty_passphrase_does_not_submit() {
|
|
||||||
assertNull(unlockSubmit("", remember = true))
|
|
||||||
assertNull(unlockSubmit("", remember = false))
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun typed_passphrase_is_handed_over_with_the_remember_flag() {
|
|
||||||
assertEquals(
|
|
||||||
UnlockSubmit(passphrase = "correct horse", remember = true),
|
|
||||||
unlockSubmit("correct horse", remember = true),
|
|
||||||
)
|
|
||||||
assertEquals(
|
|
||||||
UnlockSubmit(passphrase = "correct horse", remember = false),
|
|
||||||
unlockSubmit("correct horse", remember = false),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun interior_spaces_are_part_of_the_passphrase_not_trimmed() {
|
|
||||||
assertEquals(
|
|
||||||
UnlockSubmit(passphrase = " lead", remember = false),
|
|
||||||
unlockSubmit(" lead", remember = false),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -59,11 +59,7 @@ echo "==> verifying bundled native executables against $BINARY_MANIFEST"
|
||||||
( cd android && sha256sum -c "$(basename "$BINARY_MANIFEST")" )
|
( cd android && sha256sum -c "$(basename "$BINARY_MANIFEST")" )
|
||||||
|
|
||||||
echo "==> android build: version $version (versionCode $ONIONWIRE_VERSION_CODE), abi $abi"
|
echo "==> android build: version $version (versionCode $ONIONWIRE_VERSION_CODE), abi $abi"
|
||||||
# --stacktrace only changes output on failure. Without it a Gradle task failure
|
( cd android && "./gradlew" --no-daemon \
|
||||||
# can land in the CI log with an empty cause chain (e.g. run 414:
|
|
||||||
# `:app:packageRelease ... IncrementalSplitterRunnable` and no `Caused by:`),
|
|
||||||
# which makes a one-off failure undiagnosable after the fact.
|
|
||||||
( cd android && "./gradlew" --no-daemon --stacktrace \
|
|
||||||
"-Ponionwire.abis=$abi" \
|
"-Ponionwire.abis=$abi" \
|
||||||
"-Ponionwire.versionName=$version" \
|
"-Ponionwire.versionName=$version" \
|
||||||
"-Ponionwire.versionCode=$ONIONWIRE_VERSION_CODE" \
|
"-Ponionwire.versionCode=$ONIONWIRE_VERSION_CODE" \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue