Skip to content

Commit 3ad1fe9

Browse files
committed
Enable Both slot Flash options
Enabling flashing AnyKernel Zips for both slots (useful during OTAs to maintain root)
1 parent 852b108 commit 3ad1fe9

File tree

8 files changed

+266
-50
lines changed

8 files changed

+266
-50
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ jobs:
5252
name: KernelFlasher
5353
path: KernelFlasher.apk
5454

55-
- name: Rename apk
56-
run: |
57-
ls -al
58-
DATE=$(date +'%y.%m.%d')
59-
echo "TAG=$DATE" >> $GITHUB_ENV
55+
# - name: Rename apk
56+
# run: |
57+
# ls -al
58+
# DATE=$(date +'%y.%m.%d')
59+
# echo "TAG=$DATE" >> $GITHUB_ENV
6060

6161
# - name: Upload release
6262
# uses: ncipollo/[email protected]
@@ -67,4 +67,4 @@ jobs:
6767
# tag: "v1.${{ github.run_number }}.0"
6868
# body: |
6969
# Note: QMod KernelFlasher, support ksu-lkm
70-
# artifacts: "*.apk"
70+
# artifacts: "*.apk"

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
.externalNativeBuild
1010
.cxx
1111
local.properties
12+
.secrets
13+
.env
14+
.github/workflows/build_local.yml
15+
KernelFlasher.apk

app/src/main/assets/flash_ak3.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ TMP=$F/tmp;
1313

1414
$F/busybox rm -rf $TMP 2>/dev/null;
1515
$F/busybox mkdir -p $TMP;
16+
## $F/busybox sed -i "/export ZIPFILE=\"\$3\";/a export STATE=\"\$4\";\nexport SLOT=\"\$5\";" $F/update-binary;
17+
## $F/busybox sed -i 's/\[ -e \/dev\/block\/$byname\/system \] || slot=\$(find_slot);/[ -e \/dev\/block\/$byname\/system ] || slot=$SLOT;/' $F/update-binary;
18+
## $F/busybox sed -i '/setup_env;/i sed -i "/is_slot_device=auto/i slot_select=$4" anykernel.sh' $F/update-binary;
19+
## $F/busybox sed -i '/setup_env;/i sed -i '\''s/is_slot_device=auto/is_slot_device=1/'\'' anykernel.sh' $F/update-binary;
1620

1721
# update-binary <RECOVERY_API_VERSION> <OUTFD> <ZIPFILE>
18-
AKHOME=$TMP/anykernel $F/busybox ash $F/update-binary 3 1 "$Z";
22+
AKHOME=$TMP/anykernel $F/busybox ash $F/update-binary 3 1 "$Z" "$S" "$P";
1923
RC=$?;
2024

2125
$F/busybox rm -rf $TMP;

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

Lines changed: 115 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,31 @@ class MainActivity : ComponentActivity() {
196196
val updatesViewModel = mainViewModel.updates
197197
val rebootViewModel = mainViewModel.reboot
198198
BackHandler(enabled = mainViewModel.isRefreshing, onBack = {})
199+
val slotContentA: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
200+
val slotSuffix = "_a"
201+
val slotViewModel = slotViewModelA
202+
if (slotViewModel!!.wasFlashSuccess != null && listOf("slot{slotSuffix}", "slot").any { navController.currentDestination!!.route.equals(it) }) {
203+
slotViewModel.clearFlash(this@MainActivity)
204+
}
205+
RefreshableScreen(mainViewModel, navController, swipeEnabled = true) {
206+
SlotContent(slotViewModel, slotSuffix, navController)
207+
}
208+
209+
}
210+
val slotContentB: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
211+
val slotSuffix = "_b"
212+
val slotViewModel = slotViewModelB
213+
if (slotViewModel!!.wasFlashSuccess != null && listOf("slot{slotSuffix}", "slot").any { navController.currentDestination!!.route.equals(it) }) {
214+
slotViewModel.clearFlash(this@MainActivity)
215+
}
216+
RefreshableScreen(mainViewModel, navController, swipeEnabled = true) {
217+
SlotContent(slotViewModel, slotSuffix, navController)
218+
}
219+
220+
}
199221
val slotContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
200-
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix") ?: ""
201-
val slotViewModel = if (slotSuffix == "_b") slotViewModelB else slotViewModelA
222+
val slotSuffix = ""
223+
val slotViewModel = slotViewModelA
202224
if (slotViewModel!!.wasFlashSuccess != null && listOf("slot{slotSuffix}", "slot").any { navController.currentDestination!!.route.equals(it) }) {
203225
slotViewModel.clearFlash(this@MainActivity)
204226
}
@@ -207,16 +229,54 @@ class MainActivity : ComponentActivity() {
207229
}
208230

209231
}
232+
val slotFlashContentA: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
233+
val slotSuffix = "_a"
234+
val slotViewModel = slotViewModelA
235+
RefreshableScreen(mainViewModel, navController) {
236+
SlotFlashContent(slotViewModel!!, slotSuffix, navController)
237+
}
238+
}
239+
val slotFlashContentB: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
240+
val slotSuffix = "_b"
241+
val slotViewModel = slotViewModelB
242+
RefreshableScreen(mainViewModel, navController) {
243+
SlotFlashContent(slotViewModel!!, slotSuffix, navController)
244+
}
245+
}
210246
val slotFlashContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
211-
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix") ?: ""
212-
val slotViewModel = if (slotSuffix == "_b") slotViewModelB else slotViewModelA
247+
val slotSuffix = ""
248+
val slotViewModel = slotViewModelA
213249
RefreshableScreen(mainViewModel, navController) {
214250
SlotFlashContent(slotViewModel!!, slotSuffix, navController)
215251
}
216252
}
253+
val slotBackupsContentA: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
254+
val slotSuffix = "_a"
255+
val slotViewModel = slotViewModelA
256+
if (backStackEntry.arguments?.getString("backupId") != null) {
257+
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
258+
} else {
259+
backupsViewModel.clearCurrent()
260+
}
261+
RefreshableScreen(mainViewModel, navController) {
262+
SlotBackupsContent(slotViewModel!!, backupsViewModel, slotSuffix, navController)
263+
}
264+
}
265+
val slotBackupsContentB: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
266+
val slotSuffix = "_b"
267+
val slotViewModel = slotViewModelB
268+
if (backStackEntry.arguments?.getString("backupId") != null) {
269+
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
270+
} else {
271+
backupsViewModel.clearCurrent()
272+
}
273+
RefreshableScreen(mainViewModel, navController) {
274+
SlotBackupsContent(slotViewModel!!, backupsViewModel, slotSuffix, navController)
275+
}
276+
}
217277
val slotBackupsContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
218-
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix") ?: ""
219-
val slotViewModel = if (slotSuffix == "_b") slotViewModelB else slotViewModelA
278+
val slotSuffix = ""
279+
val slotViewModel = slotViewModelA
220280
if (backStackEntry.arguments?.getString("backupId") != null) {
221281
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
222282
} else {
@@ -226,9 +286,31 @@ class MainActivity : ComponentActivity() {
226286
SlotBackupsContent(slotViewModel!!, backupsViewModel, slotSuffix, navController)
227287
}
228288
}
289+
val slotBackupFlashContentA: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
290+
val slotSuffix = "_a"
291+
val slotViewModel = slotViewModelA
292+
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
293+
if (backupsViewModel.backups.containsKey(backupsViewModel.currentBackup)) {
294+
RefreshableScreen(mainViewModel, navController) {
295+
SlotFlashContent(slotViewModel!!, slotSuffix, navController)
296+
}
297+
}
298+
299+
}
300+
val slotBackupFlashContentB: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
301+
val slotSuffix = "_b"
302+
val slotViewModel = slotViewModelB
303+
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
304+
if (backupsViewModel.backups.containsKey(backupsViewModel.currentBackup)) {
305+
RefreshableScreen(mainViewModel, navController) {
306+
SlotFlashContent(slotViewModel!!, slotSuffix, navController)
307+
}
308+
}
309+
310+
}
229311
val slotBackupFlashContent: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit = { backStackEntry ->
230-
val slotSuffix = backStackEntry.arguments?.getString("slotSuffix") ?: ""
231-
val slotViewModel = if (slotSuffix == "_b") slotViewModelB else slotViewModelA
312+
val slotSuffix = ""
313+
val slotViewModel = slotViewModelA
232314
backupsViewModel.currentBackup = backStackEntry.arguments?.getString("backupId")
233315
if (backupsViewModel.backups.containsKey(backupsViewModel.currentBackup)) {
234316
RefreshableScreen(mainViewModel, navController) {
@@ -244,18 +326,31 @@ class MainActivity : ComponentActivity() {
244326
}
245327
}
246328
if (mainViewModel.isAb) {
247-
composable("slot{slotSuffix}", content = slotContent)
248-
composable("slot{slotSuffix}/flash", content = slotFlashContent)
249-
composable("slot{slotSuffix}/flash/ak3", content = slotFlashContent)
250-
composable("slot{slotSuffix}/flash/image", content = slotFlashContent)
251-
composable("slot{slotSuffix}/flash/image/flash", content = slotFlashContent)
252-
composable("slot{slotSuffix}/backup", content = slotFlashContent)
253-
composable("slot{slotSuffix}/backup/backup", content = slotFlashContent)
254-
composable("slot{slotSuffix}/backups", content = slotBackupsContent)
255-
composable("slot{slotSuffix}/backups/{backupId}", content = slotBackupsContent)
256-
composable("slot{slotSuffix}/backups/{backupId}/restore", content = slotBackupsContent)
257-
composable("slot{slotSuffix}/backups/{backupId}/restore/restore", content = slotBackupsContent)
258-
composable("slot{slotSuffix}/backups/{backupId}/flash/ak3", content = slotBackupFlashContent)
329+
composable("slot_a", content = slotContentA)
330+
composable("slot_a/flash", content = slotFlashContentA)
331+
composable("slot_a/flash/ak3", content = slotFlashContentA)
332+
composable("slot_a/flash/image", content = slotFlashContentA)
333+
composable("slot_a/flash/image/flash", content = slotFlashContentA)
334+
composable("slot_a/backup", content = slotFlashContentA)
335+
composable("slot_a/backup/backup", content = slotFlashContentA)
336+
composable("slot_a/backups", content = slotBackupsContentA)
337+
composable("slot_a/backups/{backupId}", content = slotBackupsContentA)
338+
composable("slot_a/backups/{backupId}/restore", content = slotBackupsContentA)
339+
composable("slot_a/backups/{backupId}/restore/restore", content = slotBackupsContentA)
340+
composable("slot_a/backups/{backupId}/flash/ak3", content = slotBackupFlashContentA)
341+
342+
composable("slot_b", content = slotContentB)
343+
composable("slot_b/flash", content = slotFlashContentB)
344+
composable("slot_b/flash/ak3", content = slotFlashContentB)
345+
composable("slot_b/flash/image", content = slotFlashContentB)
346+
composable("slot_b/flash/image/flash", content = slotFlashContentB)
347+
composable("slot_b/backup", content = slotFlashContentB)
348+
composable("slot_b/backup/backup", content = slotFlashContentB)
349+
composable("slot_b/backups", content = slotBackupsContentB)
350+
composable("slot_b/backups/{backupId}", content = slotBackupsContentB)
351+
composable("slot_b/backups/{backupId}/restore", content = slotBackupsContentB)
352+
composable("slot_b/backups/{backupId}/restore/restore", content = slotBackupsContentB)
353+
composable("slot_b/backups/{backupId}/flash/ak3", content = slotBackupFlashContentB)
259354
} else {
260355
composable("slot", content = slotContent)
261356
composable("slot/flash", content = slotFlashContent)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.capntrips.kernelflasher.ui.components
2+
3+
import androidx.compose.foundation.layout.PaddingValues
4+
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.foundation.shape.RoundedCornerShape
6+
import androidx.compose.material3.ButtonDefaults
7+
import androidx.compose.material3.Text
8+
import androidx.compose.material3.TextButton
9+
import androidx.compose.material3.MaterialTheme
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.res.stringResource
13+
import androidx.compose.ui.unit.LayoutDirection
14+
import androidx.compose.ui.unit.dp
15+
import com.github.capntrips.kernelflasher.R
16+
17+
@Composable
18+
fun DialogButton(
19+
buttonText: String,
20+
onClick: () -> Unit
21+
) {
22+
TextButton(
23+
modifier = Modifier.padding(0.dp),
24+
shape = RoundedCornerShape(4.0.dp),
25+
contentPadding = PaddingValues(
26+
horizontal = ButtonDefaults.ContentPadding.calculateLeftPadding(LayoutDirection.Ltr) - (6.667).dp,
27+
vertical = ButtonDefaults.ContentPadding.calculateTopPadding()
28+
),
29+
onClick = onClick
30+
) {
31+
Text(buttonText,
32+
maxLines = 1,
33+
color = MaterialTheme.colorScheme.primary
34+
)
35+
}
36+
}

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ fun ColumnScope.SlotContent(
4040
AnimatedVisibility(!viewModel.isRefreshing) {
4141
Column {
4242
Spacer(Modifier.height(5.dp))
43-
if (viewModel.isActive) {
44-
OutlinedButton(
45-
modifier = Modifier
46-
.fillMaxWidth(),
47-
shape = RoundedCornerShape(4.dp),
48-
onClick = {
49-
navController.navigate("slot$slotSuffix/flash")
50-
}
51-
) {
52-
Text(stringResource(R.string.flash))
43+
OutlinedButton(
44+
modifier = Modifier
45+
.fillMaxWidth(),
46+
shape = RoundedCornerShape(4.dp),
47+
onClick = {
48+
navController.navigate("slot$slotSuffix/flash")
5349
}
50+
) {
51+
Text(stringResource(R.string.flash))
5452
}
5553
OutlinedButton(
5654
modifier = Modifier
@@ -63,17 +61,15 @@ fun ColumnScope.SlotContent(
6361
) {
6462
Text(stringResource(R.string.backup))
6563
}
66-
if (viewModel.isActive) {
67-
OutlinedButton(
68-
modifier = Modifier
69-
.fillMaxWidth(),
70-
shape = RoundedCornerShape(4.dp),
71-
onClick = {
72-
navController.navigate("slot$slotSuffix/backups")
73-
}
74-
) {
75-
Text(stringResource(R.string.restore))
64+
OutlinedButton(
65+
modifier = Modifier
66+
.fillMaxWidth(),
67+
shape = RoundedCornerShape(4.dp),
68+
onClick = {
69+
navController.navigate("slot$slotSuffix/backups")
7670
}
71+
) {
72+
Text(stringResource(R.string.restore))
7773
}
7874
OutlinedButton(
7975
modifier = Modifier

0 commit comments

Comments
 (0)