@@ -66,7 +66,6 @@ class MainActivity : ComponentActivity() {
6666
6767 private var rootServiceConnected: Boolean = false
6868 private var viewModel: MainViewModel ? = null
69- private var isAb: Boolean? = null
7069 private lateinit var mainListener: MainListener
7170 var isAwaitingResult = false
7271
@@ -141,7 +140,7 @@ class MainActivity : ComponentActivity() {
141140 content.viewTreeObserver.addOnPreDrawListener(
142141 object : ViewTreeObserver .OnPreDrawListener {
143142 override fun onPreDraw (): Boolean {
144- return if (viewModel?.isRefreshing == false || isAb == false || Shell .isAppGrantedRoot() == false ) {
143+ return if (viewModel?.isRefreshing == false || Shell .isAppGrantedRoot() == false ) {
145144 content.viewTreeObserver.removeOnPreDrawListener(this )
146145 true
147146 } else {
@@ -153,17 +152,8 @@ class MainActivity : ComponentActivity() {
153152
154153 Shell .getShell()
155154 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 ())
167157 } else {
168158 setContent {
169159 KernelFlasherTheme {
@@ -206,60 +196,79 @@ class MainActivity : ComponentActivity() {
206196 val updatesViewModel = mainViewModel.updates
207197 val rebootViewModel = mainViewModel.reboot
208198 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+ }
209210 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
212213 RefreshableScreen (mainViewModel, navController) {
213- SlotFlashContent (slotViewModel, slotSuffix, navController)
214+ SlotFlashContent (slotViewModel!! , slotSuffix, navController)
214215 }
215216 }
216217 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
219220 if (backStackEntry.arguments?.getString(" backupId" ) != null ) {
220221 backupsViewModel.currentBackup = backStackEntry.arguments?.getString(" backupId" )
221222 } else {
222223 backupsViewModel.clearCurrent()
223224 }
224225 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+ }
226237 }
238+
227239 }
228240 NavHost (navController = navController, startDestination = " main" ) {
229241 composable(" main" ) {
230242 RefreshableScreen (mainViewModel, navController, swipeEnabled = true ) {
231243 MainContent (mainViewModel, navController)
232244 }
233245 }
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)
263272 }
264273 composable(" backups" ) {
265274 backupsViewModel.clearCurrent()
0 commit comments