A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
feat(app): parallel asset extraction; combined settings flow; defensive update check
ExTvfea023559846
diff --git a/app/src/main/java/com/excp/podroid/PodroidApplication.kt b/app/src/main/java/com/excp/podroid/PodroidApplication.ktindex 9e0547f..33a3bdd 100644--- a/app/src/main/java/com/excp/podroid/PodroidApplication.kt+++ b/app/src/main/java/com/excp/podroid/PodroidApplication.kt@@ -11,6 +11,8 @@ import android.app.Applicationimport android.util.Logimport dagger.hilt.android.HiltAndroidAppimport java.io.File+import java.util.concurrent.Executors+import java.util.concurrent.TimeUnit@HiltAndroidAppclass PodroidApplication : Application() {@@ -21,10 +23,38 @@ class PodroidApplication : Application() {}private fun extractAssets() {- copyAssetDir("qemu", filesDir)- copyAssetIfNeeded("vmlinuz-virt", filesDir)- copyAssetIfNeeded("initrd.img", filesDir)- copyAssetIfNeeded("alpine-rootfs.squashfs", filesDir)+ // Fan out the four top-level extractions across a small thread pool.+ // Disk-write throughput is the bottleneck for the squashfs (~41 MB),+ // but decompression, asset-FD lookup, and skip-when-size-matches all+ // overlap usefully across threads. Must complete before onCreate+ // returns — the QEMU launch path reads these files synchronously.+ val tasks: List<() -> Unit> = listOf(+ { copyAssetDir("qemu", filesDir) },+ { copyAssetIfNeeded("vmlinuz-virt", filesDir) },+ { copyAssetIfNeeded("initrd.img", filesDir) },+ { copyAssetIfNeeded("alpine-rootfs.squashfs", filesDir) },+ )+ val pool = Executors.newFixedThreadPool(tasks.size.coerceAtMost(4))+ try {+ // invokeAll blocks until every Callable finishes (or times out).+ // Each Callable wraps the task so a thrown exception is captured+ // in the returned Future rather than killing the worker silently.+ val futures = pool.invokeAll(tasks.map { task ->+ java.util.concurrent.Callable<Unit> { task() }+ })+ for (f in futures) {+ try { f.get() } catch (e: Exception) {+ // copyAssetIfNeeded / copyAssetFileIfNeeded already log+ // their own failures; this catches anything that escaped.+ Log.w(TAG, "Asset extraction task failed", e)+ }+ }+ } finally {+ pool.shutdown()+ if (!pool.awaitTermination(5, TimeUnit.SECONDS)) {+ pool.shutdownNow()+ }+ }}/**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.ktindex 84199fe..7fec04c 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@@ -49,9 +49,13 @@ class HomeViewModel @Inject constructor(private fun checkForUpdate() {viewModelScope.launch {- val info = updateRepository.checkForUpdate(BuildConfig.VERSION_NAME) ?: return@launch- if (!updateRepository.isDismissed(info.latestVersion)) {- _updateInfo.value = info+ try {+ val info = updateRepository.checkForUpdate(BuildConfig.VERSION_NAME) ?: return@launch+ if (!updateRepository.isDismissed(info.latestVersion)) {+ _updateInfo.value = info+ }+ } catch (_: Exception) {+ // Network errors during init shouldn't crash the app — just skip.}}}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.ktindex d071bb5..8f026a4 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@@ -52,7 +52,9 @@ import androidx.compose.material3.TextButtonimport androidx.compose.material3.TopAppBarimport androidx.compose.material3.windowsizeclass.WindowSizeClassimport androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.getValue+import androidx.compose.runtime.keyimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.rememberimport androidx.compose.runtime.setValue@@ -81,16 +83,20 @@ fun SettingsScreen(onThemeOrFontChanged: () -> Unit = {},viewModel: SettingsViewModel = hiltViewModel(),) {- val darkTheme by viewModel.darkTheme.collectAsStateWithLifecycle(false)+ // 8 form-style rows in one subscription via combine(...) in the ViewModel —+ // single recomposition wave per emit instead of one per source flow.+ val ui by viewModel.uiState.collectAsStateWithLifecycle()+ val darkTheme = ui.darkTheme+ val vmRamMb = ui.vmRamMb+ val vmCpus = ui.vmCpus+ val storageSizeGb = ui.storageSizeGb+ val sshEnabled = ui.sshEnabled+ val storageAccessEnabled = ui.storageAccessEnabled+ val qemuExtraArgs = ui.qemuExtraArgs+ val kernelExtraCmdline = ui.kernelExtraCmdline+ // Kept separate — different cadence/consumer than the form rows.val portForwardRules by viewModel.portForwardRules.collectAsStateWithLifecycle()val vmState by viewModel.vmState.collectAsStateWithLifecycle()- val vmRamMb by viewModel.vmRamMb.collectAsStateWithLifecycle()- val vmCpus by viewModel.vmCpus.collectAsStateWithLifecycle()- val storageSizeGb by viewModel.storageSizeGb.collectAsStateWithLifecycle()- val sshEnabled by viewModel.sshEnabled.collectAsStateWithLifecycle(false)- val storageAccessEnabled by viewModel.storageAccessEnabled.collectAsStateWithLifecycle(false)- val qemuExtraArgs by viewModel.qemuExtraArgs.collectAsStateWithLifecycle()- val kernelExtraCmdline by viewModel.kernelExtraCmdline.collectAsStateWithLifecycle()var advancedExpanded by remember { mutableStateOf(false) }var showAddDialog by remember { mutableStateOf(false) }var showResetDialog by remember { mutableStateOf(false) }@@ -228,10 +234,12 @@ fun SettingsScreen()} else {portForwardRules.forEach { rule ->- PortForwardRuleRow(- rule = rule,- onDelete = { viewModel.removePortForward(rule) },- )+ key(rule.hostPort, rule.protocol) {+ PortForwardRuleRow(+ rule = rule,+ onDelete = { viewModel.removePortForward(rule) },+ )+ }}}Spacer(Modifier.height(8.dp))@@ -795,7 +803,13 @@ private fun AdvancedTextSetting() {// Editing is local; we only persist when the field loses focus. Avoids// round-tripping every keystroke through DataStore on a multi-line config field.- var localValue by remember(value) { mutableStateOf(value) }+ // Don't reset local edits on every external emit — only sync when the upstream+ // value actually drifts from what we have buffered (e.g. a Reset tap).+ val localState = remember { mutableStateOf(value) }+ var localValue by localState+ LaunchedEffect(value) {+ if (localValue != value) localValue = value+ }var hadFocus by remember { mutableStateOf(false) }Column(modifier = Modifier.fillMaxWidth()) {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.ktindex 1ed8172..a47a9a4 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@@ -25,6 +25,7 @@ import kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.flow.Flowimport kotlinx.coroutines.flow.SharingStartedimport kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.combineimport kotlinx.coroutines.flow.stateInimport kotlinx.coroutines.launchimport kotlinx.coroutines.withContext@@ -34,6 +35,24 @@ import java.util.Dateimport java.util.Localeimport javax.inject.Inject+/**+ * Snapshot of the form-style settings rows that SettingsScreen reads together.+ * Combined into one StateFlow so an emit on any one source produces a single+ * recomposition instead of one per source. Does *not* include flows with+ * different update cadences or consumers (vmState, portForwardRules, updateInfo,+ * terminal-only theme/font/size) — those stay separate.+ */+data class SettingsUiState(+ val vmRamMb: Int = 512,+ val vmCpus: Int = 1,+ val storageSizeGb: Int = 2,+ val sshEnabled: Boolean = false,+ val storageAccessEnabled: Boolean = false,+ val qemuExtraArgs: String = SettingsRepository.DEFAULT_QEMU_EXTRA_ARGS,+ val kernelExtraCmdline: String = SettingsRepository.DEFAULT_KERNEL_EXTRA_CMDLINE,+ val darkTheme: Boolean = false,+)+@HiltViewModelclass SettingsViewModel @Inject constructor(@ApplicationContext private val context: Context,@@ -65,6 +84,43 @@ class SettingsViewModel @Inject constructor(val kernelExtraCmdline: StateFlow<String> = settingsRepository.kernelExtraCmdline.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), SettingsRepository.DEFAULT_KERNEL_EXTRA_CMDLINE)+ /**+ * Single combined stream of the 8 form-style rows. SettingsScreen can collect+ * this once with collectAsStateWithLifecycle instead of subscribing 8 times.+ * The original per-flow StateFlows above are kept so callers that want one+ * value (e.g. the About section reading storageSizeGb) don't pay for the+ * combined object on every emit.+ */+ val uiState: StateFlow<SettingsUiState> = combine(+ combine(+ settingsRepository.vmRamMb,+ settingsRepository.vmCpus,+ settingsRepository.storageSizeGb,+ settingsRepository.sshEnabled,+ ) { ram, cpus, storage, ssh ->+ arrayOf(ram, cpus, storage, ssh)+ },+ combine(+ settingsRepository.storageAccessEnabled,+ settingsRepository.qemuExtraArgs,+ settingsRepository.kernelExtraCmdline,+ settingsRepository.darkTheme,+ ) { storageAccess, qemu, kernel, dark ->+ arrayOf(storageAccess, qemu, kernel, dark)+ },+ ) { a, b ->+ SettingsUiState(+ vmRamMb = a[0] as Int,+ vmCpus = a[1] as Int,+ storageSizeGb = a[2] as Int,+ sshEnabled = a[3] as Boolean,+ storageAccessEnabled = b[0] as Boolean,+ qemuExtraArgs = b[1] as String,+ kernelExtraCmdline = b[2] as String,+ darkTheme = b[3] as Boolean,+ )+ }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), SettingsUiState())+fun setQemuExtraArgs(value: String) {viewModelScope.launch { settingsRepository.setQemuExtraArgs(value) }}