mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
app: fix touch handling in SuRequest dialog
- Remove android:windowIsFloating so SuRequestActivity is a full-screen translucent activity rather than a floating window that dismisses on touches outside during asynchronous initialization. - Set setFinishOnTouchOutside(false) to prevent unwanted dismissals. - Decouple the 1-second grant button delay from the countdown timer so interacting with the timeout slider immediately does not leave the grant button permanently disabled. - Ensure an immediate DENY response is sent if the activity or view model is destroyed before responding. Assisted-by: Gemini 3.8 Flash
This commit is contained in:
@@ -54,6 +54,7 @@ class SuRequestActivity : ComponentActivity(), UntrackedActivity {
|
||||
}
|
||||
setTheme(R.style.Floating)
|
||||
super.onCreate(savedInstanceState)
|
||||
setFinishOnTouchOutside(false)
|
||||
|
||||
onBackPressedDispatcher.addCallback(this) { viewModel.denyPressed() }
|
||||
viewModel.finishActivity = { finish() }
|
||||
@@ -99,6 +100,11 @@ class SuRequestActivity : ComponentActivity(), UntrackedActivity {
|
||||
super.finishAndRemoveTask()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
viewModel.activityDestroyed()
|
||||
}
|
||||
|
||||
private object EmptyAccessibilityDelegate : View.AccessibilityDelegate() {
|
||||
override fun sendAccessibilityEvent(host: View, eventType: Int) {}
|
||||
override fun performAccessibilityAction(host: View, action: Int, args: Bundle?) = true
|
||||
|
||||
@@ -15,11 +15,14 @@ import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.ALLOW
|
||||
import com.topjohnwu.magisk.core.model.su.SuPolicy.Companion.DENY
|
||||
import com.topjohnwu.magisk.core.su.SuRequestHandler
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.concurrent.TimeUnit.SECONDS
|
||||
|
||||
class SuRequestViewModel(
|
||||
@@ -51,6 +54,7 @@ class SuRequestViewModel(
|
||||
private val millis = SECONDS.toMillis(Config.suDefaultTimeout.toLong())
|
||||
private var timer = SuTimer(millis, 1000)
|
||||
private var initialized = false
|
||||
private var responded = false
|
||||
|
||||
fun setSelectedItemPosition(position: Int) {
|
||||
_uiState.update { it.copy(selectedItemPosition = position) }
|
||||
@@ -112,23 +116,49 @@ class SuRequestViewModel(
|
||||
isSharedUid = isSharedUid,
|
||||
selectedItemPosition = selectedPos,
|
||||
useTapjackProtection = Config.suTapjack,
|
||||
grantEnabled = false,
|
||||
)
|
||||
}
|
||||
viewModelScope.launch {
|
||||
delay(1000)
|
||||
_uiState.update { it.copy(grantEnabled = true) }
|
||||
}
|
||||
timer.start()
|
||||
initialized = true
|
||||
}
|
||||
|
||||
fun activityDestroyed() {
|
||||
if (initialized && !responded) {
|
||||
respond(DENY)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
timer.cancel()
|
||||
if (initialized && !responded) {
|
||||
responded = true
|
||||
val pos = _uiState.value.selectedItemPosition
|
||||
runBlocking(Dispatchers.IO) {
|
||||
handler.respond(DENY, Config.Value.TIMEOUT_LIST[pos])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun respond(action: Int) {
|
||||
if (!initialized) return
|
||||
if (!initialized || responded) return
|
||||
responded = true
|
||||
timer.cancel()
|
||||
|
||||
val pos = _uiState.value.selectedItemPosition
|
||||
val pkg = _uiState.value.packageName
|
||||
timeoutPrefs.edit { putInt(pkg, pos) }
|
||||
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
handler.respond(action, Config.Value.TIMEOUT_LIST[pos])
|
||||
finishActivity()
|
||||
withContext(Dispatchers.Main) {
|
||||
finishActivity()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,14 +168,13 @@ class SuRequestViewModel(
|
||||
}
|
||||
|
||||
private inner class SuTimer(
|
||||
private val millis: Long,
|
||||
millis: Long,
|
||||
interval: Long
|
||||
) : CountDownTimer(millis, interval) {
|
||||
|
||||
override fun onTick(remains: Long) {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
grantEnabled = it.grantEnabled || remains <= millis - 1000,
|
||||
denyCountdown = (remains / 1000).toInt() + 1
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
</style>
|
||||
|
||||
<style name="Floating" parent="android:Theme.DeviceDefault.NoActionBar">
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user