@@ -60,17 +60,26 @@ class SlotViewModel(
60
60
var successful : String? = null ,
61
61
)
62
62
63
- data class BootInfo (
63
+ data class BootImgInfo (
64
64
var kernelVersion : String? = null ,
65
65
var bootFmt : String? = null ,
66
66
var headerVersion : String? = null ,
67
- var initBootFmt : String? = null ,
68
- var ramdiskLocation : String? = null
67
+ )
68
+
69
+ data class RamdiskInfo (
70
+ var headerVersion : String? = null ,
71
+ var ramdiskFmt : String? = null ,
72
+ var ramdiskLocation : String? = null ,
73
+ )
74
+
75
+ data class SlotInfo (
76
+ var bootSlotInfo : BootSlotInfo ,
77
+ var bootImgInfo : BootImgInfo ,
78
+ var ramdiskInfo : RamdiskInfo ,
69
79
)
70
80
71
81
private var _sha1 : String? = null
72
- private val _bootInfo : MutableState <BootInfo > = mutableStateOf(BootInfo ())
73
- private val _bootSlotInfo : MutableState <BootSlotInfo > = mutableStateOf(BootSlotInfo ())
82
+ private val _slotInfo : MutableState <SlotInfo > = mutableStateOf(SlotInfo (BootSlotInfo (), BootImgInfo (), RamdiskInfo ()))
74
83
var hasVendorDlkm: Boolean = false
75
84
var isVendorDlkmMapped: Boolean = false
76
85
var isVendorDlkmMounted: Boolean = false
@@ -103,10 +112,8 @@ class SlotViewModel(
103
112
get() = _error
104
113
val showCautionDialog: Boolean
105
114
get() = _showCautionDialog .value
106
- val bootInfo: BootInfo
107
- get() = _bootInfo .value
108
- val bootSlotInfo: BootSlotInfo
109
- get() = _bootSlotInfo .value
115
+ val slotInfo: SlotInfo
116
+ get() = _slotInfo .value
110
117
111
118
init {
112
119
refresh(context)
@@ -120,7 +127,9 @@ class SlotViewModel(
120
127
fun refresh (context : Context ) {
121
128
_error = null
122
129
_sha1 = null
123
- _bootInfo .value = _bootInfo .value.copy(kernelVersion = null , bootFmt = null , headerVersion = null , initBootFmt = null , ramdiskLocation = null )
130
+ _slotInfo .value.bootSlotInfo = _slotInfo .value.bootSlotInfo.copy(null , null )
131
+ _slotInfo .value.bootImgInfo = _slotInfo .value.bootImgInfo.copy(null , null , null )
132
+ _slotInfo .value.ramdiskInfo = _slotInfo .value.ramdiskInfo.copy(null , null , null )
124
133
125
134
if (! isActive) {
126
135
inInit = true
@@ -136,25 +145,28 @@ class SlotViewModel(
136
145
137
146
if (slotSuffix != " " ) {
138
147
val resCode1 = Shell .cmd(" $bootctl is-slot-bootable " + if (slotSuffix == " _a" ) " 0" else " 1" ).exec().code
139
- _bootSlotInfo .value.unbootable = if (resCode1 == 0 ) " No" else " Yes"
148
+ _slotInfo .value.bootSlotInfo .unbootable = if (resCode1 == 0 ) " No" else " Yes"
140
149
val resCode2 = Shell .cmd(" $bootctl is-slot-marked-successful " + if (slotSuffix == " _a" ) " 0" else " 1" ).exec().code
141
- _bootSlotInfo .value.successful = if (resCode2 == 0 ) " Yes" else " No"
150
+ _slotInfo .value.bootSlotInfo .successful = if (resCode2 == 0 ) " Yes" else " No"
142
151
}
143
152
144
- _bootInfo .value.headerVersion = extractKernelValues(bootUnpackOp.trimIndent(), HEADER_VER )
145
- _bootInfo .value.bootFmt = extractKernelValues(bootUnpackOp.trimIndent(), KERNEL_FMT )
146
- _bootInfo .value.initBootFmt = extractKernelValues(bootUnpackOp.trimIndent(), RAMDISK_FMT )
147
- if (_bootInfo .value.initBootFmt != null )
148
- _bootInfo .value.ramdiskLocation = " boot.img"
153
+ _slotInfo .value.bootImgInfo.headerVersion = extractKernelValues(bootUnpackOp.trimIndent(), HEADER_VER )
154
+ _slotInfo .value.bootImgInfo.bootFmt = extractKernelValues(bootUnpackOp.trimIndent(), KERNEL_FMT )
155
+ _slotInfo .value.ramdiskInfo.ramdiskFmt = extractKernelValues(bootUnpackOp.trimIndent(), RAMDISK_FMT )
156
+ if (_slotInfo .value.ramdiskInfo.ramdiskFmt != null )
157
+ {
158
+ _slotInfo .value.ramdiskInfo.ramdiskLocation = " boot.img"
159
+ _slotInfo .value.ramdiskInfo.headerVersion = _slotInfo .value.bootImgInfo.headerVersion
160
+ }
161
+ Log .d(TAG , _slotInfo .value.bootImgInfo.toString())
149
162
150
- Log .d(TAG , _bootInfo .value.toString())
151
- if (initBoot != null && _bootInfo .value.initBootFmt == null ) {
163
+ if (initBoot != null && _slotInfo .value.ramdiskInfo.ramdiskFmt == null ) {
152
164
val unpackInitBootOutput = mutableListOf<String >()
153
165
if (Shell .cmd(" $magiskboot unpack $initBoot " ).to(unpackInitBootOutput, unpackInitBootOutput).exec().isSuccess)
154
166
{
155
167
val initBootUnpackOp = unpackInitBootOutput.joinToString(" \n " )
156
- _bootInfo .value.initBootFmt = extractKernelValues(initBootUnpackOp.trimIndent(), RAMDISK_FMT )
157
- _bootInfo .value.ramdiskLocation = " init_boot.img"
168
+ _slotInfo .value.ramdiskInfo.ramdiskFmt = extractKernelValues(initBootUnpackOp.trimIndent(), RAMDISK_FMT )
169
+ _slotInfo .value.ramdiskInfo .ramdiskLocation = " init_boot.img"
158
170
}
159
171
}
160
172
@@ -184,16 +196,16 @@ class SlotViewModel(
184
196
}
185
197
} else if (kernel.exists()) {
186
198
_sha1 = Shell .cmd(" $magiskboot sha1 $boot " ).exec().out .firstOrNull()
187
- if (_bootInfo .value.headerVersion.equals(" 4" ) && _bootInfo .value.ramdiskLocation.equals(null ))
199
+ if (_slotInfo .value.bootImgInfo. headerVersion.equals(" 4" ) && _slotInfo .value.ramdiskInfo .ramdiskLocation.equals(null ))
188
200
{
189
- _bootInfo .value.ramdiskLocation = " boot.img"
190
- _bootInfo .value.initBootFmt = " lz4_legacy"
201
+ _slotInfo .value.ramdiskInfo .ramdiskLocation = " boot.img"
202
+ _slotInfo .value.ramdiskInfo.ramdiskFmt = " lz4_legacy"
191
203
}
192
204
} else {
193
- if (_bootInfo .value.headerVersion.equals(" 4" ) && _bootInfo .value.ramdiskLocation.equals(null ))
205
+ if (_slotInfo .value.bootImgInfo. headerVersion.equals(" 4" ) && _slotInfo .value.ramdiskInfo .ramdiskLocation.equals(null ))
194
206
{
195
- _bootInfo .value.ramdiskLocation = " boot.img"
196
- _bootInfo .value.initBootFmt = " lz4_legacy"
207
+ _slotInfo .value.ramdiskInfo .ramdiskLocation = " boot.img"
208
+ _slotInfo .value.ramdiskInfo.ramdiskFmt = " lz4_legacy"
197
209
}
198
210
_error = " Unable to generate SHA1 hash. Invalid boot.img or magiskboot unpack failed!"
199
211
}
@@ -203,7 +215,7 @@ class SlotViewModel(
203
215
_backupPartitions [partitionName] = true
204
216
}
205
217
206
- _bootInfo .value.kernelVersion = null
218
+ _slotInfo .value.bootImgInfo .kernelVersion = null
207
219
inInit = false
208
220
}
209
221
@@ -323,7 +335,7 @@ class SlotViewModel(
323
335
if (kernel.exists()) {
324
336
val result = Shell .cmd(" strings kernel | grep -E -m1 'Linux version.*#' | cut -d\\ -f3-" ).exec().out
325
337
if (result.isNotEmpty()) {
326
- _bootInfo .value.kernelVersion = result[0 ].replace(""" \(.+\)""" .toRegex(), " " ).replace(""" \s+""" .toRegex(), " " )
338
+ _slotInfo .value.bootImgInfo .kernelVersion = result[0 ].replace(""" \(.+\)""" .toRegex(), " " ).replace(""" \s+""" .toRegex(), " " )
327
339
}
328
340
}
329
341
Shell .cmd(" $magiskboot cleanup" ).exec()
@@ -450,13 +462,13 @@ class SlotViewModel(
450
462
fun backup (context : Context ) {
451
463
launch {
452
464
_clearFlash ()
453
- val currentKernelVersion = if (_bootInfo .value.kernelVersion != null ) {
454
- _bootInfo .value.kernelVersion
465
+ val currentKernelVersion = if (_slotInfo .value.bootImgInfo .kernelVersion != null ) {
466
+ _slotInfo .value.bootImgInfo .kernelVersion
455
467
} else if (isActive) {
456
468
System .getProperty(" os.version" )!!
457
469
} else {
458
470
_getKernel (context)
459
- _bootInfo .value.kernelVersion
471
+ _slotInfo .value.bootImgInfo .kernelVersion
460
472
}
461
473
val now = LocalDateTime .now().format(DateTimeFormatter .ofPattern(" yyyy-MM-dd--HH-mm" ))
462
474
val backupDir = createBackupDir(context, now)
@@ -483,7 +495,7 @@ class SlotViewModel(
483
495
val now = LocalDateTime .now().format(DateTimeFormatter .ofPattern(" yyyy-MM-dd--HH-mm" ))
484
496
val backupDir = createBackupDir(context, now)
485
497
val jsonFile = backupDir.getChildFile(" backup.json" )
486
- val backup = Backup (now, " ak3" , _bootInfo .value.kernelVersion!! , null , flashFilename)
498
+ val backup = Backup (now, " ak3" , _slotInfo .value.bootImgInfo .kernelVersion!! , null , flashFilename)
487
499
val indentedJson = Json { prettyPrint = true }
488
500
jsonFile.outputStream().use { it.write(indentedJson.encodeToString(backup).toByteArray(Charsets .UTF_8 )) }
489
501
val destination = backupDir.getChildFile(flashFilename!! )
@@ -703,7 +715,7 @@ class SlotViewModel(
703
715
if (driver.exists()) {
704
716
addMessage(" Copied $flashFilename " )
705
717
_wasFlashSuccess .value = false
706
- val partitionName = bootInfo .ramdiskLocation?.removeSuffix(" .img" ) ? : " boot"
718
+ val partitionName = _slotInfo .value.ramdiskInfo .ramdiskLocation?.removeSuffix(" .img" ) ? : " boot"
707
719
val magiskboot = File (context.filesDir, " magiskboot" )
708
720
val ksuinit = File (context.filesDir, " ksuinit" )
709
721
if (partitionName == " boot" )
0 commit comments