Skip to content

A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.

fix(ui): real uptime baseline, memoize settings probes, resync storage toggle, surface export errors

ExTvf0224c518e87
diff --git a/app/src/main/java/com/excp/podroid/engine/EngineHolder.kt b/app/src/main/java/com/excp/podroid/engine/EngineHolder.kt
index 77464fd..8c54251 100644
--- a/app/src/main/java/com/excp/podroid/engine/EngineHolder.kt
+++ b/app/src/main/java/com/excp/podroid/engine/EngineHolder.kt
@@ -282,6 +282,8 @@ class EngineHolder @Inject constructor(
_currentFlow.value = next
}
+ override val runningSinceMs: Long? get() = current.runningSinceMs
+
// ── VmEngine: flows that follow the currently-selected engine ──────────
// A freshly (re)selected engine that hasn't been started this cycle has its
// retained terminal state (Stopped/Error) normalized to Idle, so a swap-back
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.kt
index 680f296..a05d70d 100644
--- a/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.kt
+++ b/app/src/main/java/com/excp/podroid/ui/screens/home/HomeViewModel.kt
@@ -127,17 +127,28 @@ class HomeViewModel @Inject constructor(
}
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), false)
- private var runningSinceMs: Long? = null
+ // Fallback timestamp stamped the first time we observe Running, used when the
+ // engine doesn't supply runningSinceMs (e.g. a future engine that omits the override).
+ private var fallbackRunningSinceMs: Long? = null
+
+ // The uptime baseline: prefer the real →Running timestamp from the engine so
+ // rotation / Activity recreation doesn't reset the displayed uptime to "Up 0s"
+ // while the VM has actually been running for minutes.
+ private val runningSinceMs: Long?
+ get() = engine.runningSinceMs ?: fallbackRunningSinceMs
init {
checkForUpdate()
- // Maintain runningSinceMs for the synchronous read path used by uptime formatter.
+ // Maintain fallbackRunningSinceMs for engines that don't override runningSinceMs.
viewModelScope.launch {
var lastWasRunning = false
engine.state.collect { state ->
val nowRunning = state is VmState.Running
- if (nowRunning && !lastWasRunning) runningSinceMs = System.currentTimeMillis()
- if (!nowRunning) runningSinceMs = null
+ if (nowRunning && !lastWasRunning) {
+ // Only stamp the fallback when the engine doesn't provide the real time.
+ if (engine.runningSinceMs == null) fallbackRunningSinceMs = System.currentTimeMillis()
+ }
+ if (!nowRunning) fallbackRunningSinceMs = null
lastWasRunning = nowRunning
}
}
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt
index 44c83f9..5d0857a 100644
--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt
+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsScreen.kt
@@ -33,11 +33,14 @@ import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
@@ -54,6 +57,9 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleEventObserver
+import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.excp.podroid.BuildConfig
import com.excp.podroid.data.repository.PortForwardRule
@@ -86,6 +92,7 @@ fun SettingsScreen(
val ui by viewModel.uiState.collectAsStateWithLifecycle()
val portForwardRules by viewModel.portForwardRules.collectAsStateWithLifecycle()
val vmState by viewModel.vmState.collectAsStateWithLifecycle()
+ val exportError by viewModel.exportError.collectAsStateWithLifecycle()
var advancedExpanded by remember { mutableStateOf(false) }
var showAddDialog by remember { mutableStateOf(false) }
@@ -96,6 +103,35 @@ fun SettingsScreen(
val ctx = LocalContext.current
val vmNotRunning = vmState !is VmState.Running && vmState !is VmState.Starting
+ // Memoize: both values are constant for the process lifetime / until a backend
+ // swap, so there's no point re-running reflection on every recomposition.
+ val isDownloadsShareAvailable = remember { viewModel.isDownloadsShareAvailable() }
+ val activeBackendId = remember { viewModel.activeBackendId() }
+
+ // Re-sync the persisted storageAccessEnabled flag against the real OS grant on
+ // every resume (user may have denied all-files-access on the system screen we
+ // sent them to, but the DataStore flag still reads true).
+ val lifecycleOwner = LocalLifecycleOwner.current
+ DisposableEffect(lifecycleOwner) {
+ val observer = LifecycleEventObserver { _, event ->
+ if (event == Lifecycle.Event.ON_RESUME &&
+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.R &&
+ !Environment.isExternalStorageManager()
+ ) {
+ viewModel.setStorageAccessEnabled(false)
+ }
+ }
+ lifecycleOwner.lifecycle.addObserver(observer)
+ onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }
+ }
+
+ val snackbarHostState = remember { SnackbarHostState() }
+ LaunchedEffect(exportError) {
+ val msg = exportError ?: return@LaunchedEffect
+ snackbarHostState.showSnackbar(msg)
+ viewModel.clearExportError()
+ }
+
Scaffold(
topBar = {
PodroidTopBar(
@@ -107,6 +143,7 @@ fun SettingsScreen(
},
)
},
+ snackbarHost = { SnackbarHost(snackbarHostState) },
containerColor = MaterialTheme.colorScheme.background,
) { innerPadding ->
val isCompactHeight = windowSizeClass.heightSizeClass == WindowHeightSizeClass.Compact
@@ -203,8 +240,8 @@ fun SettingsScreen(
DownloadsSharingRow(
enabled = ui.storageAccessEnabled,
vmNotRunning = vmNotRunning,
- available = viewModel.isDownloadsShareAvailable(),
- activeBackendId = viewModel.activeBackendId(),
+ available = isDownloadsShareAvailable,
+ activeBackendId = activeBackendId,
onToggle = { viewModel.setStorageAccessEnabled(it) },
)
Spacer(Modifier.height(PodroidTokens.Spacing.MD))
@@ -295,7 +332,7 @@ fun SettingsScreen(
} else null
avfReportText = probe.copy(
smokeTestResult = smoke,
- activeBackend = viewModel.activeBackendId(),
+ activeBackend = activeBackendId,
).pretty()
avfRunning = false
}
diff --git a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt
index bc30f96..263baf8 100644
--- a/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt
+++ b/app/src/main/java/com/excp/podroid/ui/screens/settings/SettingsViewModel.kt
@@ -24,8 +24,10 @@ import com.excp.podroid.util.NetworkUtils
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
@@ -228,6 +230,12 @@ class SettingsViewModel @Inject constructor(
else -> true
}
+ private val _exportError = MutableStateFlow<String?>(null)
+ /** One-shot export failure message; clear after showing with [clearExportError]. */
+ val exportError: StateFlow<String?> = _exportError.asStateFlow()
+
+ fun clearExportError() { _exportError.value = null }
+
fun removePortForward(rule: PortForwardRule) {
viewModelScope.launch { portForwardRepository.removeRule(rule) }
}
@@ -279,6 +287,7 @@ class SettingsViewModel @Inject constructor(
})
} catch (e: Exception) {
Log.w(TAG, "Export failed", e)
+ _exportError.value = "Export failed: ${e.message ?: "unknown error"}"
}
}
}