Skip to content

Commit

Permalink
修复 kkevsekk1#392 root权限直接打开无障碍
Browse files Browse the repository at this point in the history
  • Loading branch information
wilinz committed Aug 13, 2022
1 parent 1eb5a14 commit 3d04d49
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions app/src/main/java/org/autojs/autojs/ui/main/drawer/DrawerPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ import com.stardust.view.accessibility.AccessibilityService
import io.github.g00fy2.quickie.QRResult
import io.github.g00fy2.quickie.ScanQRCode
import io.noties.markwon.Markwon
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import org.autojs.autojs.Pref
import org.autojs.autoxjs.R
import org.autojs.autojs.autojs.AutoJs
import org.autojs.autojs.devplugin.DevPlugin
import org.autojs.autojs.external.foreground.ForegroundService
Expand All @@ -63,6 +60,7 @@ import org.autojs.autojs.ui.compose.widget.MyIcon
import org.autojs.autojs.ui.compose.widget.MySwitch
import org.autojs.autojs.ui.floating.FloatyWindowManger
import org.autojs.autojs.ui.settings.SettingsActivity_
import org.autojs.autoxjs.R
import org.joda.time.DateTimeZone
import org.joda.time.Instant

Expand Down Expand Up @@ -116,7 +114,7 @@ fun DrawerPage() {
SwitchTimedTaskScheduler()
ProjectAddress(context)
DownloadLink(context)
FEEDBACK(context)
Feedback(context)
CheckForUpdate()
AppDetailsSettings(context)
}
Expand Down Expand Up @@ -144,7 +142,7 @@ private fun AppDetailsSettings(context: Context) {
}

@Composable
private fun FEEDBACK(context: Context) {
private fun Feedback(context: Context) {
TextButton(onClick = {
IntentUtil.browse(
context,
Expand Down Expand Up @@ -788,6 +786,7 @@ private fun StableModeSwitch() {
@Composable
private fun AccessibilityServiceSwitch() {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var showDialog by remember {
mutableStateOf(false)
}
Expand Down Expand Up @@ -819,7 +818,15 @@ private fun AccessibilityServiceSwitch() {
checked = isAccessibilityServiceEnabled,
onCheckedChange = {
if (!isAccessibilityServiceEnabled) {
showDialog = true
if (Pref.shouldEnableAccessibilityServiceByRoot()) {
scope.launch {
val enabled = withContext(Dispatchers.IO) {
AccessibilityServiceTool.enableAccessibilityServiceByRootAndWaitFor(2000)
}
if (enabled) isAccessibilityServiceEnabled = true
else showDialog = true
}
} else showDialog = true
} else {
isAccessibilityServiceEnabled = !AccessibilityService.disable()
}
Expand Down

0 comments on commit 3d04d49

Please sign in to comment.