Skip to content

Commit 902e7e5

Browse files
committed
allow invalid inactive slot
detect non-ab devices
1 parent ea46c5e commit 902e7e5

File tree

7 files changed

+101
-53
lines changed

7 files changed

+101
-53
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class MainActivity : ComponentActivity() {
6666

6767
private var rootServiceConnected: Boolean = false
6868
private var viewModel: MainViewModel? = null
69+
private var isAb: Boolean? = null
6970
private lateinit var mainListener: MainListener
7071
var isAwaitingResult = false
7172

@@ -140,7 +141,7 @@ class MainActivity : ComponentActivity() {
140141
content.viewTreeObserver.addOnPreDrawListener(
141142
object : ViewTreeObserver.OnPreDrawListener {
142143
override fun onPreDraw(): Boolean {
143-
return if (viewModel?.isRefreshing == false || Shell.isAppGrantedRoot() == false) {
144+
return if (viewModel?.isRefreshing == false || isAb == false || Shell.isAppGrantedRoot() == false) {
144145
content.viewTreeObserver.removeOnPreDrawListener(this)
145146
true
146147
} else {
@@ -152,8 +153,17 @@ class MainActivity : ComponentActivity() {
152153

153154
Shell.getShell()
154155
if (Shell.isAppGrantedRoot()!!) {
155-
val intent = Intent(this, FilesystemService::class.java)
156-
RootService.bind(intent, AidlConnection())
156+
isAb = Shell.cmd("getprop ro.build.ab_update").exec().out[0] == "true"
157+
if (isAb!!) {
158+
val intent = Intent(this, FilesystemService::class.java)
159+
RootService.bind(intent, AidlConnection())
160+
} else {
161+
setContent {
162+
KernelFlasherTheme {
163+
ErrorScreen(stringResource(R.string.non_ab_unsupported))
164+
}
165+
}
166+
}
157167
} else {
158168
setContent {
159169
KernelFlasherTheme {

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

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
package com.github.capntrips.kernelflasher.ui.components
22

3-
import androidx.compose.foundation.clickable
43
import androidx.compose.foundation.layout.Row
54
import androidx.compose.foundation.layout.Spacer
65
import androidx.compose.foundation.layout.width
7-
import androidx.compose.foundation.text.selection.SelectionContainer
86
import androidx.compose.material3.MaterialTheme
97
import androidx.compose.material3.Text
108
import androidx.compose.runtime.Composable
119
import androidx.compose.runtime.MutableState
1210
import androidx.compose.runtime.getValue
13-
import androidx.compose.runtime.mutableStateOf
14-
import androidx.compose.runtime.remember
1511
import androidx.compose.runtime.setValue
1612
import androidx.compose.ui.Modifier
1713
import androidx.compose.ui.graphics.Color
1814
import androidx.compose.ui.layout.layout
1915
import androidx.compose.ui.text.TextStyle
20-
import androidx.compose.ui.text.style.TextOverflow
2116
import androidx.compose.ui.unit.dp
2217

2318
@Composable
@@ -54,24 +49,6 @@ fun DataRow(
5449
style = labelStyle
5550
)
5651
Spacer(Modifier.width(8.dp))
57-
SelectionContainer(Modifier.alignByBaseline()) {
58-
var clicked by remember { mutableStateOf(false)}
59-
val modifier = if (clickable) {
60-
Modifier
61-
.clickable { clicked = !clicked }
62-
.alignByBaseline()
63-
} else {
64-
Modifier
65-
.alignByBaseline()
66-
}
67-
Text(
68-
modifier = modifier,
69-
text = value,
70-
color = valueColor,
71-
style = valueStyle,
72-
maxLines = if (clicked) Int.MAX_VALUE else 1,
73-
overflow = if (clicked) TextOverflow.Visible else TextOverflow.Ellipsis
74-
)
75-
}
52+
DataValue(value, valueColor, valueStyle, clickable)
7653
}
7754
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.github.capntrips.kernelflasher.ui.components
2+
3+
import androidx.compose.foundation.clickable
4+
import androidx.compose.foundation.layout.RowScope
5+
import androidx.compose.foundation.text.selection.SelectionContainer
6+
import androidx.compose.material3.MaterialTheme
7+
import androidx.compose.material3.Text
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.getValue
10+
import androidx.compose.runtime.mutableStateOf
11+
import androidx.compose.runtime.remember
12+
import androidx.compose.runtime.setValue
13+
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.graphics.Color
15+
import androidx.compose.ui.text.TextStyle
16+
import androidx.compose.ui.text.style.TextOverflow
17+
18+
@Composable
19+
fun RowScope.DataValue(
20+
value: String,
21+
color: Color = Color.Unspecified,
22+
style: TextStyle = MaterialTheme.typography.titleSmall,
23+
clickable: Boolean = false,
24+
) {
25+
SelectionContainer(Modifier.alignByBaseline()) {
26+
var clicked by remember { mutableStateOf(false) }
27+
val modifier = if (clickable) {
28+
Modifier
29+
.clickable { clicked = !clicked }
30+
.alignByBaseline()
31+
} else {
32+
Modifier
33+
.alignByBaseline()
34+
}
35+
Text(
36+
modifier = modifier,
37+
text = value,
38+
color = color,
39+
style = style,
40+
maxLines = if (clicked) Int.MAX_VALUE else 1,
41+
overflow = if (clicked) TextOverflow.Visible else TextOverflow.Ellipsis
42+
)
43+
}
44+
}
Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.capntrips.kernelflasher.ui.components
22

33
import androidx.compose.animation.AnimatedVisibility
4+
import androidx.compose.foundation.layout.Row
45
import androidx.compose.material3.ExperimentalMaterial3Api
56
import androidx.compose.material3.MaterialTheme
67
import androidx.compose.runtime.Composable
@@ -25,7 +26,7 @@ fun SlotCard(
2526
DataCard (
2627
title = title,
2728
button = {
28-
if (!isSlotScreen) {
29+
if (!isSlotScreen && !viewModel.hasError) {
2930
AnimatedVisibility(!viewModel.isRefreshing) {
3031
ViewButton {
3132
navController.navigate("slot${viewModel.slotSuffix}")
@@ -35,33 +36,44 @@ fun SlotCard(
3536
}
3637
) {
3738
val cardWidth = remember { mutableIntStateOf(0) }
38-
DataRow(
39-
label = stringResource(R.string.boot_sha1),
40-
value = viewModel.sha1.substring(0, 8),
41-
valueStyle = MaterialTheme.typography.titleSmall.copy(
42-
fontFamily = FontFamily.Monospace,
43-
fontWeight = FontWeight.Medium
44-
),
45-
mutableMaxWidth = cardWidth
46-
)
47-
AnimatedVisibility(!viewModel.isRefreshing && viewModel.kernelVersion != null) {
39+
if (!viewModel.hasError) {
4840
DataRow(
49-
label = stringResource(R.string.kernel_version),
50-
value = if (viewModel.kernelVersion != null) viewModel.kernelVersion!! else "",
51-
mutableMaxWidth = cardWidth,
52-
clickable = true
41+
label = stringResource(R.string.boot_sha1),
42+
value = viewModel.sha1.substring(0, 8),
43+
valueStyle = MaterialTheme.typography.titleSmall.copy(
44+
fontFamily = FontFamily.Monospace,
45+
fontWeight = FontWeight.Medium
46+
),
47+
mutableMaxWidth = cardWidth
5348
)
54-
}
55-
if (showDlkm && viewModel.hasVendorDlkm) {
56-
var vendorDlkmValue = stringResource(R.string.not_found)
57-
if (viewModel.isVendorDlkmMapped) {
58-
vendorDlkmValue = if (viewModel.isVendorDlkmMounted) {
59-
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.mounted))
60-
} else {
61-
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.unmounted))
49+
AnimatedVisibility(!viewModel.isRefreshing && viewModel.kernelVersion != null) {
50+
DataRow(
51+
label = stringResource(R.string.kernel_version),
52+
value = if (viewModel.kernelVersion != null) viewModel.kernelVersion!! else "",
53+
mutableMaxWidth = cardWidth,
54+
clickable = true
55+
)
56+
}
57+
if (showDlkm && viewModel.hasVendorDlkm) {
58+
var vendorDlkmValue = stringResource(R.string.not_found)
59+
if (viewModel.isVendorDlkmMapped) {
60+
vendorDlkmValue = if (viewModel.isVendorDlkmMounted) {
61+
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.mounted))
62+
} else {
63+
String.format("%s, %s", stringResource(R.string.exists), stringResource(R.string.unmounted))
64+
}
6265
}
66+
DataRow(stringResource(R.string.vendor_dlkm), vendorDlkmValue, mutableMaxWidth = cardWidth)
67+
}
68+
} else {
69+
Row {
70+
DataValue(
71+
value = viewModel.error,
72+
color = MaterialTheme.colorScheme.error,
73+
style = MaterialTheme.typography.titleSmall,
74+
clickable = true
75+
)
6376
}
64-
DataRow(stringResource(R.string.vendor_dlkm), vendorDlkmValue, mutableMaxWidth = cardWidth)
6577
}
6678
}
6779
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ class MainViewModel(
6767
updates = UpdatesViewModel(context, fileSystemManager, navController, _isRefreshing)
6868
reboot = RebootViewModel(context, fileSystemManager, navController, _isRefreshing)
6969
slotA = SlotViewModel(context, fileSystemManager, navController, _isRefreshing, slotSuffix == "_a", "_a", bootA, initBootA, _backups)
70-
if (slotA.hasError) {
70+
if (slotA.hasError && slotSuffix == "_a") {
7171
_error = slotA.error
7272
}
7373
slotB = SlotViewModel(context, fileSystemManager, navController, _isRefreshing, slotSuffix == "_b", "_b", bootB, initBootB, _backups)
74-
if (slotB.hasError) {
74+
if (slotB.hasError && slotSuffix == "_b") {
7575
_error = slotB.error
7676
}
7777

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class SlotViewModel(
8888
}
8989

9090
fun refresh(context: Context) {
91+
if (!isActive) {
92+
inInit = true
93+
}
94+
9195
val magiskboot = File(context.filesDir, "magiskboot")
9296
Shell.cmd("$magiskboot unpack $boot").exec()
9397
if (initBoot != null) {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<string name="app_name">Kernel Flasher</string>
33
<string name="root_required">Root is required</string>
44
<string name="root_service_disconnected">Root service disconnected</string>
5+
<string name="non_ab_unsupported">Non-AB devices are not supported</string>
56
<string name="device">Device</string>
67
<string name="model">Model</string>
78
<string name="build_number">Build Number</string>

0 commit comments

Comments
 (0)