app: keep patch method across process death

The patch dialog restores its state after process death, including a
pending file pick, but the selected install method only lived in
InstallViewModel. If the app was killed while the file picker was open,
the new ViewModel had no method, so picking the image closed the dialog
and silently did nothing.

On Pixel and Googlebook devices, the dialog also keyed its source
choice on the downloadable firmware image. That is only found after
the firmware search, which runs again after process death, so a file
chosen before was reset to the downloadable image.

Set the patch method when an image is selected, and save the user's
source choice without keying it on the firmware image.

Assisted-by: Claude Opus 5.5
This commit is contained in:
topjohnwu
2026-10-24 13:01:45 -07:00
committed by John Wu
parent 8acbd6305e
commit 9ee6815a54
2 changed files with 16 additions and 14 deletions
@@ -301,9 +301,11 @@ fun PatchComposableDialog(
showUsbDestination: Boolean = false,
) {
val context = LocalContext.current
var source by rememberSaveable(candidate) {
mutableStateOf(if (candidate != null) PatchSource.CANDIDATE else PatchSource.FILE)
}
// The user's choice, defaulting to the downloadable image when there is one. Not keyed on the
// candidate: it is only found after the firmware search, which runs again after the process
// is recreated, and must not reset a choice made before that
var chosenSource by rememberSaveable { mutableStateOf<PatchSource?>(null) }
val source = chosenSource ?: if (candidate != null) PatchSource.CANDIDATE else PatchSource.FILE
var localFileUri by rememberSaveable { mutableStateOf<Uri?>(null) }
var pendingSubmitAfterPick by rememberSaveable { mutableStateOf(false) }
var url by rememberSaveable { mutableStateOf("") }
@@ -358,7 +360,7 @@ fun PatchComposableDialog(
pendingSubmitAfterPick = false
if (uri != null) {
localFileUri = uri
source = PatchSource.FILE
chosenSource = PatchSource.FILE
if (shouldSubmit) {
confirmWithUri(uri)
}
@@ -460,7 +462,7 @@ fun PatchComposableDialog(
.clip(RoundedCornerShape(12.dp))
.selectable(
selected = source == PatchSource.CANDIDATE,
onClick = { source = PatchSource.CANDIDATE },
onClick = { chosenSource = PatchSource.CANDIDATE },
role = Role.RadioButton
)
.padding(vertical = 10.dp),
@@ -495,7 +497,7 @@ fun PatchComposableDialog(
.selectable(
selected = source == PatchSource.FILE,
onClick = {
source = PatchSource.FILE
chosenSource = PatchSource.FILE
pendingSubmitAfterPick = false
localFilePicker.launch("*/*")
},
@@ -534,7 +536,7 @@ fun PatchComposableDialog(
.clip(RoundedCornerShape(12.dp))
.selectable(
selected = source == PatchSource.URL,
onClick = { source = PatchSource.URL },
onClick = { chosenSource = PatchSource.URL },
role = Role.RadioButton
)
.padding(vertical = 10.dp),
@@ -102,21 +102,21 @@ class InstallViewModel(
_uiState.update { it.copy(showPatchDialog = false) }
}
// Also sets the method: it is only kept in memory, and the image may be picked after the
// process was recreated, e.g. if it was killed while the file picker was open
fun onPatchSelected(uri: Uri, usbDeviceName: String? = null) {
if (usbDeviceName != null) {
viewModelScope.launch {
if (UsbBlockDevice.requestPermission(AppContext, usbDeviceName)) {
_uiState.update { it.copy(patchUri = uri, usbDevice = usbDeviceName) }
if (_uiState.value.method == Method.PATCH) {
install()
_uiState.update {
it.copy(method = Method.PATCH, patchUri = uri, usbDevice = usbDeviceName)
}
install()
}
}
} else {
_uiState.update { it.copy(patchUri = uri, usbDevice = null) }
if (_uiState.value.method == Method.PATCH) {
install()
}
_uiState.update { it.copy(method = Method.PATCH, patchUri = uri, usbDevice = null) }
install()
}
}