Skip to content

Commit

Permalink
manager: hides navbar on action screen, disable back gesture and save…
Browse files Browse the repository at this point in the history
… logs until action is completed

Fix irresponsive behaviour of runModuleAction() in ui.util.KsuCli to avoid app crash or hang during transition (tiann#2321)
  • Loading branch information
rifsxd authored and armv7a committed Jan 2, 2025
1 parent 7f3c229 commit 3d884f6
Show file tree
Hide file tree
Showing 5 changed files with 366 additions and 23 deletions.
305 changes: 305 additions & 0 deletions 2321.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
From 2525643f6de02c48d00153a938ff3b1f1f95f10a Mon Sep 17 00:00:00 2001
From: Rifat Azad <[email protected]>
Date: Thu, 26 Dec 2024 23:37:52 +0600
Subject: [PATCH 1/5] manager: hides navbar on action screen, disable back
gesture and save logs until action is completed - This is to avoid this issue
#2315 of irresponsive behaviour of runModuleAction() in ui.util.KsuCli which
executes shell commands, in that process if a transition is made to a
different Destination i.e HomeScreen it will get stuck until the action is
completed or app crashes.

---
.../me/weishu/kernelsu/ui/MainActivity.kt | 16 ++++-
.../kernelsu/ui/screen/ExecuteModuleAction.kt | 66 ++++++++++++-------
2 files changed, 59 insertions(+), 23 deletions(-)

diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt
index 5737c524a940..171d4d7e9b5c 100644
--- a/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt
+++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt
@@ -34,8 +34,10 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
+import androidx.navigation.compose.currentBackStackEntryAsState
import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationStyle
+import com.ramcosta.composedestinations.generated.destinations.ExecuteModuleActionScreenDestination
import com.ramcosta.composedestinations.generated.NavGraphs
import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState
import com.ramcosta.composedestinations.utils.rememberDestinationsNavigator
@@ -46,6 +48,7 @@ import me.weishu.kernelsu.ui.theme.KernelSUTheme
import me.weishu.kernelsu.ui.util.LocalSnackbarHost
import me.weishu.kernelsu.ui.util.rootAvailable
import me.weishu.kernelsu.ui.util.install
+import me.weishu.kernelsu.ui.util.*

class MainActivity : ComponentActivity() {

@@ -66,8 +69,19 @@ class MainActivity : ComponentActivity() {
KernelSUTheme {
val navController = rememberNavController()
val snackBarHostState = remember { SnackbarHostState() }
+ val currentDestination = navController.currentBackStackEntryAsState()?.value?.destination
+
+ val showBottomBar = when (currentDestination?.route) {
+ ExecuteModuleActionScreenDestination.route -> false // Hide for ExecuteModuleActionScreen
+ else -> true
+ }
+
Scaffold(
- bottomBar = { BottomBar(navController) },
+ bottomBar = {
+ if (showBottomBar) {
+ BottomBar(navController)
+ }
+ },
contentWindowInsets = WindowInsets(0, 0, 0, 0)
) { innerPadding ->
CompositionLocalProvider(
diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
index 93b06a0ca514..cde274f9fba8 100644
--- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
+++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
@@ -1,15 +1,22 @@
package me.weishu.kernelsu.ui.screen

import android.os.Environment
+import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
+import androidx.compose.foundation.layout.WindowInsets
+import androidx.compose.foundation.layout.WindowInsetsSides
+import androidx.compose.foundation.layout.defaultMinSize
+import androidx.compose.foundation.layout.safeDrawing
+import androidx.compose.foundation.layout.only
import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Save
import androidx.compose.material3.ExperimentalMaterial3Api
+import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@@ -49,12 +56,17 @@ import java.util.Locale
@Destination<RootGraph>
fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String) {
var text by rememberSaveable { mutableStateOf("") }
- var tempText : String
+ var tempText: String
val logContent = rememberSaveable { StringBuilder() }
val snackBarHost = LocalSnackbarHost.current
val scope = rememberCoroutineScope()
val scrollState = rememberScrollState()
var actionResult: Boolean
+ var isActionRunning by rememberSaveable { mutableStateOf(true) }
+
+ BackHandler(enabled = isActionRunning) {
+ // Disable back button if action is running
+ }

LaunchedEffect(Unit) {
if (text.isNotEmpty()) {
@@ -79,29 +91,41 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String
actionResult = it
}
}
- if (actionResult) navigator.popBackStack()
+ isActionRunning = false
}

Scaffold(
topBar = {
TopBar(
- onBack = {
- navigator.popBackStack()
- },
+ isActionRunning = isActionRunning,
onSave = {
- scope.launch {
- val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault())
- val date = format.format(Date())
- val file = File(
- Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
- "KernelSU_module_action_log_${date}.log"
- )
- file.writeText(logContent.toString())
- snackBarHost.showSnackbar("Log saved to ${file.absolutePath}")
+ if (!isActionRunning) {
+ scope.launch {
+ val format = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault())
+ val date = format.format(Date())
+ val file = File(
+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
+ "KernelSU_Next_module_action_log_${date}.log"
+ )
+ file.writeText(logContent.toString())
+ snackBarHost.showSnackbar("Log saved to ${file.absolutePath}")
+ }
}
}
)
},
+ floatingActionButton = {
+ if (!isActionRunning) {
+ ExtendedFloatingActionButton(
+ text = { Text(text = stringResource(R.string.close)) },
+ icon = { Icon(Icons.Filled.Close, contentDescription = null) },
+ onClick = {
+ navigator.popBackStack()
+ }
+ )
+ }
+ },
+ contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
snackbarHost = { SnackbarHost(snackBarHost) }
) { innerPadding ->
KeyEventBlocker {
@@ -129,16 +153,14 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String

@OptIn(ExperimentalMaterial3Api::class)
@Composable
-private fun TopBar(onBack: () -> Unit = {}, onSave: () -> Unit = {}) {
+private fun TopBar(isActionRunning: Boolean, onSave: () -> Unit = {}) {
TopAppBar(
title = { Text(stringResource(R.string.action)) },
- navigationIcon = {
- IconButton(
- onClick = onBack
- ) { Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = null) }
- },
actions = {
- IconButton(onClick = onSave) {
+ IconButton(
+ onClick = onSave,
+ enabled = !isActionRunning
+ ) {
Icon(
imageVector = Icons.Filled.Save,
contentDescription = stringResource(id = R.string.save_log),

From db6476430ac7fe04c37ff0e180293e79bc2fed4c Mon Sep 17 00:00:00 2001
From: Rifat Azad <[email protected]>
Date: Thu, 26 Dec 2024 23:54:12 +0600
Subject: [PATCH 2/5] manager: added close string for action screen

---
manager/app/src/main/res/values/strings.xml | 1 +
1 file changed, 1 insertion(+)

diff --git a/manager/app/src/main/res/values/strings.xml b/manager/app/src/main/res/values/strings.xml
index 8a891e30492d..cda6b6dc627a 100644
--- a/manager/app/src/main/res/values/strings.xml
+++ b/manager/app/src/main/res/values/strings.xml
@@ -111,6 +111,7 @@
<string name="grant_root_failed">Failed to grant root!</string>
<string name="action">Action</string>
<string name="open">Open</string>
+ <string name="close">Close</string>
<string name="enable_web_debugging">Enable WebView debugging</string>
<string name="enable_web_debugging_summary">Can be used to debug WebUI, please enable only when needed.</string>
<string name="direct_install">Direct install (Recommended)</string>

From f31a90f3b754adba8b7b38abcc78dec77d249fea Mon Sep 17 00:00:00 2001
From: Rifat Azad <[email protected]>
Date: Sun, 29 Dec 2024 13:07:52 +0600
Subject: [PATCH 3/5] manager: floating button dynamic padding depending on
android navigation bar

---
.../java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
index cde274f9fba8..591d6c771810 100644
--- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
+++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
@@ -4,6 +4,7 @@ import android.os.Environment
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
@@ -121,7 +122,9 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String
icon = { Icon(Icons.Filled.Close, contentDescription = null) },
onClick = {
navigator.popBackStack()
- }
+ },
+ modifier = Modifier
+ .navigationBarsPadding()
)
}
},

From dea8abd3469a5ede1dc46a7f5ca394bc24be3cab Mon Sep 17 00:00:00 2001
From: rifsxd <[email protected]>
Date: Sun, 29 Dec 2024 21:19:52 +0600
Subject: [PATCH 4/5] manager: let the system to handle the safedrawing

---
.../java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
index 591d6c771810..5f670e99d50e 100644
--- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
+++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
@@ -106,7 +106,7 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String
val date = format.format(Date())
val file = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
- "KernelSU_Next_module_action_log_${date}.log"
+ "KernelSU_module_action_log_${date}.log"
)
file.writeText(logContent.toString())
snackBarHost.showSnackbar("Log saved to ${file.absolutePath}")
@@ -128,7 +128,7 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String
)
}
},
- contentWindowInsets = WindowInsets.safeDrawing.only(WindowInsetsSides.Top + WindowInsetsSides.Horizontal),
+ contentWindowInsets = WindowInsets.safeDrawing,
snackbarHost = { SnackbarHost(snackBarHost) }
) { innerPadding ->
KeyEventBlocker {

From 8a694789c6c07f840d9583d55b6648b415248a0c Mon Sep 17 00:00:00 2001
From: rifsxd <[email protected]>
Date: Mon, 30 Dec 2024 11:19:55 +0600
Subject: [PATCH 5/5] manager: removed nvigationBarPadding since Scaffold has
already added the navigation bar insets

---
.../java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
index 5f670e99d50e..be31d34697e7 100644
--- a/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
+++ b/manager/app/src/main/java/me/weishu/kernelsu/ui/screen/ExecuteModuleAction.kt
@@ -4,7 +4,6 @@ import android.os.Environment
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
@@ -122,9 +121,7 @@ fun ExecuteModuleActionScreen(navigator: DestinationsNavigator, moduleId: String
icon = { Icon(Icons.Filled.Close, contentDescription = null) },
onClick = {
navigator.popBackStack()
- },
- modifier = Modifier
- .navigationBarsPadding()
+ }
)
}
},
16 changes: 15 additions & 1 deletion manager/app/src/main/java/me/weishu/kernelsu/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import androidx.navigation.compose.currentBackStackEntryAsState
import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.animations.NavHostAnimatedDestinationStyle
import com.ramcosta.composedestinations.generated.destinations.ExecuteModuleActionScreenDestination
import com.ramcosta.composedestinations.generated.NavGraphs
import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState
import com.ramcosta.composedestinations.utils.rememberDestinationsNavigator
Expand All @@ -46,6 +48,7 @@ import me.weishu.kernelsu.ui.theme.KernelSUTheme
import me.weishu.kernelsu.ui.util.LocalSnackbarHost
import me.weishu.kernelsu.ui.util.rootAvailable
import me.weishu.kernelsu.ui.util.install
import me.weishu.kernelsu.ui.util.*

class MainActivity : ComponentActivity() {

Expand All @@ -66,8 +69,19 @@ class MainActivity : ComponentActivity() {
KernelSUTheme {
val navController = rememberNavController()
val snackBarHostState = remember { SnackbarHostState() }
val currentDestination = navController.currentBackStackEntryAsState()?.value?.destination

val showBottomBar = when (currentDestination?.route) {
ExecuteModuleActionScreenDestination.route -> false // Hide for ExecuteModuleActionScreen
else -> true
}

Scaffold(
bottomBar = { BottomBar(navController) },
bottomBar = {
if (showBottomBar) {
BottomBar(navController)
}
},
contentWindowInsets = WindowInsets(0, 0, 0, 0)
) { innerPadding ->
CompositionLocalProvider(
Expand Down
Loading

0 comments on commit 3d884f6

Please sign in to comment.