Skip to content

Commit 33ec4af

Browse files
committed
Add latest bootctl and fix slot switch and other issues
1. Add Latest available bootctl. 2. Use local bootctl. 3. Display slot status.
1 parent 7f06dfc commit 33ec4af

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

app/src/main/java/com/github/capntrips/kernelflasher/MainActivity.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.app.Activity
66
import android.content.ComponentName
77
import android.content.Intent
88
import android.content.ServiceConnection
9+
import android.os.Build
910
import android.os.Bundle
1011
import android.os.IBinder
1112
import android.util.Log
@@ -189,6 +190,7 @@ class MainActivity : ComponentActivity() {
189190
copyNativeBinary("lptools_static") // v20220825
190191
copyNativeBinary("httools_static") // v3.2.0
191192
copyNativeBinary("magiskboot") // v29.0
193+
copyNativeBinary("bootctl") // aosp_arm64-img-13613025 android14
192194
copyAsset("mkbootfs")
193195
copyAsset("ksuinit")
194196
copyAsset("flash_ak3.sh")

app/src/main/java/com/github/capntrips/kernelflasher/ui/components/SlotCard.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.compose.material3.MaterialTheme
77
import androidx.compose.runtime.Composable
88
import androidx.compose.runtime.mutableIntStateOf
99
import androidx.compose.runtime.remember
10+
import androidx.compose.ui.graphics.Color
1011
import androidx.compose.ui.res.stringResource
1112
import androidx.compose.ui.text.font.FontFamily
1213
import androidx.compose.ui.text.font.FontWeight
@@ -76,6 +77,21 @@ fun SlotCard(
7677
value = viewModel.bootInfo.initBootFmt ?: stringResource(R.string.not_found),
7778
mutableMaxWidth = cardWidth
7879
)
80+
if(isSlotScreen && viewModel.slotSuffix != "")
81+
{
82+
DataRow(
83+
label = "Unbootable",
84+
value = viewModel.bootSlotInfo.unbootable ?: stringResource(R.string.not_found),
85+
mutableMaxWidth = cardWidth,
86+
valueColor = if (viewModel.bootSlotInfo.unbootable == "Yes") Color.Red else Color.Unspecified
87+
)
88+
DataRow(
89+
label = "Successful",
90+
value = viewModel.bootSlotInfo.successful ?: stringResource(R.string.not_found),
91+
mutableMaxWidth = cardWidth,
92+
valueColor = if (viewModel.bootSlotInfo.successful == "No") Color.Red else Color.Unspecified
93+
)
94+
}
7995
if (!viewModel.isRefreshing.value && viewModel.hasError) {
8096
Row {
8197
DataValue(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ fun ColumnScope.MainContent(
4444
{
4545
DataRow(stringResource(R.string.susfs_version), viewModel.susfsVersion, mutableMaxWidth = cardWidth)
4646
}
47+
if(viewModel.halInfo != "")
48+
{
49+
DataRow("Boot HAL version", viewModel.halInfo, mutableMaxWidth = cardWidth)
50+
}
4751
}
4852
Spacer(Modifier.height(16.dp))
4953
SlotCard(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class MainViewModel(
3939
val slotSuffix: String
4040

4141
val kernelVersion: String
42+
val halInfo: String
4243
val susfsVersion: String
4344
val isAb: Boolean
4445
val slotA: SlotViewModel
@@ -78,6 +79,10 @@ class MainViewModel(
7879

7980
init {
8081
PartitionUtil.init(context, fileSystemManager)
82+
val bootctl = File(context.filesDir, "bootctl")
83+
halInfo = runCatching { Shell.cmd("$bootctl hal-info").exec().out[0].substringAfter("HAL Version: ").trim() }
84+
.recoverCatching { "" }
85+
.getOrDefault("")
8186
kernelVersion = Shell.cmd("echo $(uname -r) $(uname -v)").exec().out[0]
8287
susfsVersion = runCatching { Shell.cmd("susfsd version").exec().out[0] }
8388
.recoverCatching { Shell.cmd("ksu_susfs show version").exec().out[0] }

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class SlotViewModel(
5353
const val RAMDISK_FMT = "RAMDISK_FMT"
5454
}
5555

56+
data class BootSlotInfo(
57+
var unbootable: String? = null,
58+
var successful: String? = null,
59+
)
60+
5661
data class BootInfo(
5762
var kernelVersion: String? = null,
5863
var bootFmt: String? = null,
@@ -63,6 +68,7 @@ class SlotViewModel(
6368

6469
private var _sha1: String? = null
6570
private val _bootInfo: MutableState<BootInfo> = mutableStateOf(BootInfo())
71+
private val _bootSlotInfo: MutableState<BootSlotInfo> = mutableStateOf(BootSlotInfo())
6672
var hasVendorDlkm: Boolean = false
6773
var isVendorDlkmMapped: Boolean = false
6874
var isVendorDlkmMounted: Boolean = false
@@ -97,6 +103,8 @@ class SlotViewModel(
97103
get() = _showCautionDialog.value
98104
val bootInfo: BootInfo
99105
get() = _bootInfo.value
106+
val bootSlotInfo: BootSlotInfo
107+
get() = _bootSlotInfo.value
100108

101109
init {
102110
refresh(context)
@@ -117,12 +125,20 @@ class SlotViewModel(
117125
}
118126

119127
val magiskboot = File(context.filesDir, "magiskboot")
128+
val bootctl = File(context.filesDir, "bootctl")
120129
Shell.cmd("$magiskboot cleanup").exec()
121130

122131
val unpackBootOutput = mutableListOf<String>()
123132
Shell.cmd("$magiskboot unpack $boot").to(unpackBootOutput, unpackBootOutput).exec()
124133
val bootUnpackOp = unpackBootOutput.joinToString("\n")
125134

135+
if(slotSuffix != "") {
136+
val resCode1 = Shell.cmd("$bootctl is-slot-bootable " + if (slotSuffix == "_a") "0" else "1").exec().code
137+
_bootSlotInfo.value.unbootable = if(resCode1 == 0) "No" else "Yes"
138+
val resCode2 = Shell.cmd("$bootctl is-slot-marked-successful " + if (slotSuffix == "_a") "0" else "1").exec().code
139+
_bootSlotInfo.value.successful = if(resCode2 == 0) "Yes" else "No"
140+
}
141+
126142
_bootInfo.value.headerVersion = extractKernelValues(bootUnpackOp.trimIndent(), HEADER_VER)
127143
_bootInfo.value.bootFmt = extractKernelValues(bootUnpackOp.trimIndent(), KERNEL_FMT)
128144
_bootInfo.value.initBootFmt = extractKernelValues(bootUnpackOp.trimIndent(), RAMDISK_FMT)
@@ -615,7 +631,8 @@ class SlotViewModel(
615631
val targetSlot = if (currentSlot == "_a") "b" else "a"
616632

617633
// Execute bootctl command
618-
val result = Shell.cmd("bootctl set-active-boot-slot $targetSlot").exec()
634+
val bootctl = File(context.filesDir, "bootctl")
635+
val result = Shell.cmd("$bootctl set-active-boot-slot $targetSlot").exec()
619636

620637
if (result.isSuccess) {
621638
log(context, "Slot was successfully switched to $targetSlot", shouldThrow = false)
132 KB
Binary file not shown.

0 commit comments

Comments
 (0)