Skip to content

Commit 3282955

Browse files
committed
Enable Both slot Flash options (Add Inactive slot flash warning) : Try 16
1 parent bc647c1 commit 3282955

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotFlashContent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fun ColumnScope.SlotFlashContent(
186186
OutlinedButton(
187187
onClick = {
188188
viewModel.hideCautionDialog()
189-
// Add slot-switching logic here
189+
viewModel.switchSlot(context)
190190
},
191191
shape = RoundedCornerShape(4.dp),
192192
colors = ButtonDefaults.outlinedButtonColors(

app/src/main/java/com/github/capntrips/kernelflasher/ui/screens/slot/SlotViewModel.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,41 @@ class SlotViewModel(
531531
} finally {
532532
uiPrint("")
533533
if (wasSlotReset) {
534-
uiPrint("CAUTION: You have flashed AnyKernel Zip to inactive slot!")
535-
uiPrint("But the active slot is not changed after flashing.")
536-
uiPrint("Use bootctl to change active slot or Return to System Updater to complete OTA.")
537-
uiPrint("Do not reboot from here, unless you know what you are doing.")
534+
// uiPrint("CAUTION: You have flashed AnyKernel Zip to inactive slot!")
535+
// uiPrint("But the active slot is not changed after flashing.")
536+
// uiPrint("Use bootctl to change active slot or Return to System Updater to complete OTA.")
537+
// uiPrint("Do not reboot from here, unless you know what you are doing.")
538538
resetSlot()
539539
viewModelScope.launch(Dispatchers.Main) {
540540
showCautionDialog() // Show dialog instead of uiPrint
541541
}
542542
}
543543
}
544544
}
545+
546+
fun switchSlot(context: Context) {
547+
viewModelScope.launch(Dispatchers.IO) {
548+
try {
549+
// Get current slot
550+
val currentSlot = Shell.cmd("getprop ro.boot.slot_suffix").exec().out.firstOrNull() ?: "_a"
551+
val targetSlot = if (currentSlot == "_a") "b" else "a"
552+
553+
// Execute bootctl command
554+
val result = Shell.cmd("bootctl set-active-boot-slot $targetSlot").exec()
555+
556+
if (result.isSuccess) {
557+
log(context, "Slot was successfully switched to $targetSlot", shouldThrow = false)
558+
} else {
559+
log(context, "Failed to switch slot", shouldThrow = false)
560+
}
561+
} catch (e: Exception) {
562+
withContext(Dispatchers.Main) {
563+
Toast.makeText(context, "Error: ${e.message}", Toast.LENGTH_SHORT).show()
564+
}
565+
throw e
566+
}
567+
}
568+
}
545569

546570
fun flashAk3(context: Context, currentBackup: String, filename: String) {
547571
launch {

0 commit comments

Comments
 (0)