@@ -66,7 +66,6 @@ class MainActivity : ComponentActivity() {
66
66
67
67
private var rootServiceConnected: Boolean = false
68
68
private var viewModel: MainViewModel ? = null
69
- private var isAb: Boolean? = null
70
69
private lateinit var mainListener: MainListener
71
70
var isAwaitingResult = false
72
71
@@ -141,7 +140,7 @@ class MainActivity : ComponentActivity() {
141
140
content.viewTreeObserver.addOnPreDrawListener(
142
141
object : ViewTreeObserver .OnPreDrawListener {
143
142
override fun onPreDraw (): Boolean {
144
- return if (viewModel?.isRefreshing == false || isAb == false || Shell .isAppGrantedRoot() == false ) {
143
+ return if (viewModel?.isRefreshing == false || Shell .isAppGrantedRoot() == false ) {
145
144
content.viewTreeObserver.removeOnPreDrawListener(this )
146
145
true
147
146
} else {
@@ -153,17 +152,8 @@ class MainActivity : ComponentActivity() {
153
152
154
153
Shell .getShell()
155
154
if (Shell .isAppGrantedRoot()!! ) {
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
- }
155
+ val intent = Intent (this , FilesystemService ::class .java)
156
+ RootService .bind(intent, AidlConnection ())
167
157
} else {
168
158
setContent {
169
159
KernelFlasherTheme {
@@ -206,60 +196,79 @@ class MainActivity : ComponentActivity() {
206
196
val updatesViewModel = mainViewModel.updates
207
197
val rebootViewModel = mainViewModel.reboot
208
198
BackHandler (enabled = mainViewModel.isRefreshing, onBack = {})
199
+ val slotContent: @Composable AnimatedVisibilityScope .(NavBackStackEntry ) -> Unit = { backStackEntry ->
200
+ val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" ) ? : " "
201
+ val slotViewModel = if (slotSuffix == " _b" ) slotViewModelB else 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
+ }
209
210
val slotFlashContent: @Composable AnimatedVisibilityScope .(NavBackStackEntry ) -> Unit = { backStackEntry ->
210
- val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" )!!
211
- val slotViewModel = if (slotSuffix == " _a " ) slotViewModelA else slotViewModelB
211
+ val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" ) ? : " "
212
+ val slotViewModel = if (slotSuffix == " _b " ) slotViewModelB else slotViewModelA
212
213
RefreshableScreen (mainViewModel, navController) {
213
- SlotFlashContent (slotViewModel, slotSuffix, navController)
214
+ SlotFlashContent (slotViewModel!! , slotSuffix, navController)
214
215
}
215
216
}
216
217
val slotBackupsContent: @Composable AnimatedVisibilityScope .(NavBackStackEntry ) -> Unit = { backStackEntry ->
217
- val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" )!!
218
- val slotViewModel = if (slotSuffix == " _a " ) slotViewModelA else slotViewModelB
218
+ val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" ) ? : " "
219
+ val slotViewModel = if (slotSuffix == " _b " ) slotViewModelB else slotViewModelA
219
220
if (backStackEntry.arguments?.getString(" backupId" ) != null ) {
220
221
backupsViewModel.currentBackup = backStackEntry.arguments?.getString(" backupId" )
221
222
} else {
222
223
backupsViewModel.clearCurrent()
223
224
}
224
225
RefreshableScreen (mainViewModel, navController) {
225
- SlotBackupsContent (slotViewModel, backupsViewModel, slotSuffix, navController)
226
+ SlotBackupsContent (slotViewModel!! , backupsViewModel, slotSuffix, navController)
227
+ }
228
+ }
229
+ val slotBackupFlashContent: @Composable AnimatedVisibilityScope .(NavBackStackEntry ) -> Unit = { backStackEntry ->
230
+ val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" ) ? : " "
231
+ val slotViewModel = if (slotSuffix == " _b" ) slotViewModelB else slotViewModelA
232
+ backupsViewModel.currentBackup = backStackEntry.arguments?.getString(" backupId" )
233
+ if (backupsViewModel.backups.containsKey(backupsViewModel.currentBackup)) {
234
+ RefreshableScreen (mainViewModel, navController) {
235
+ SlotFlashContent (slotViewModel!! , slotSuffix, navController)
236
+ }
226
237
}
238
+
227
239
}
228
240
NavHost (navController = navController, startDestination = " main" ) {
229
241
composable(" main" ) {
230
242
RefreshableScreen (mainViewModel, navController, swipeEnabled = true ) {
231
243
MainContent (mainViewModel, navController)
232
244
}
233
245
}
234
- composable(" slot{slotSuffix}" ) { backStackEntry ->
235
- val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" )!!
236
- val slotViewModel = if (slotSuffix == " _a" ) slotViewModelA else slotViewModelB
237
- if (slotViewModel.wasFlashSuccess != null && navController.currentDestination!! .route.equals(" slot{slotSuffix}" )) {
238
- slotViewModel.clearFlash(this @MainActivity)
239
- }
240
- RefreshableScreen (mainViewModel, navController, swipeEnabled = true ) {
241
- SlotContent (slotViewModel, slotSuffix, navController)
242
- }
243
- }
244
- composable(" slot{slotSuffix}/flash" , content = slotFlashContent)
245
- composable(" slot{slotSuffix}/flash/ak3" , content = slotFlashContent)
246
- composable(" slot{slotSuffix}/flash/image" , content = slotFlashContent)
247
- composable(" slot{slotSuffix}/flash/image/flash" , content = slotFlashContent)
248
- composable(" slot{slotSuffix}/backup" , content = slotFlashContent)
249
- composable(" slot{slotSuffix}/backup/backup" , content = slotFlashContent)
250
- composable(" slot{slotSuffix}/backups" , content = slotBackupsContent)
251
- composable(" slot{slotSuffix}/backups/{backupId}" , content = slotBackupsContent)
252
- composable(" slot{slotSuffix}/backups/{backupId}/restore" , content = slotBackupsContent)
253
- composable(" slot{slotSuffix}/backups/{backupId}/restore/restore" , content = slotBackupsContent)
254
- composable(" slot{slotSuffix}/backups/{backupId}/flash/ak3" ) { backStackEntry ->
255
- val slotSuffix = backStackEntry.arguments?.getString(" slotSuffix" )!!
256
- val slotViewModel = if (slotSuffix == " _a" ) slotViewModelA else slotViewModelB
257
- backupsViewModel.currentBackup = backStackEntry.arguments?.getString(" backupId" )
258
- if (backupsViewModel.backups.containsKey(backupsViewModel.currentBackup)) {
259
- RefreshableScreen (mainViewModel, navController) {
260
- SlotFlashContent (slotViewModel, slotSuffix, navController)
261
- }
262
- }
246
+ 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)
259
+ } else {
260
+ composable(" slot" , content = slotContent)
261
+ composable(" slot/flash" , content = slotFlashContent)
262
+ composable(" slot/flash/ak3" , content = slotFlashContent)
263
+ composable(" slot/flash/image" , content = slotFlashContent)
264
+ composable(" slot/flash/image/flash" , content = slotFlashContent)
265
+ composable(" slot/backup" , content = slotFlashContent)
266
+ composable(" slot/backup/backup" , content = slotFlashContent)
267
+ composable(" slot/backups" , content = slotBackupsContent)
268
+ composable(" slot/backups/{backupId}" , content = slotBackupsContent)
269
+ composable(" slot/backups/{backupId}/restore" , content = slotBackupsContent)
270
+ composable(" slot/backups/{backupId}/restore/restore" , content = slotBackupsContent)
271
+ composable(" slot/backups/{backupId}/flash/ak3" , content = slotBackupFlashContent)
263
272
}
264
273
composable(" backups" ) {
265
274
backupsViewModel.clearCurrent()
0 commit comments