diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallDialog.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallDialog.kt index 52252aaf4..dafb09c3c 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallDialog.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallDialog.kt @@ -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(null) } + val source = chosenSource ?: if (candidate != null) PatchSource.CANDIDATE else PatchSource.FILE var localFileUri by rememberSaveable { mutableStateOf(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), diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt index ea3abd31b..348913e0f 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt @@ -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() } }