@@ -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