Skip to content

Commit

Permalink
perf: 优化规则在某些场景下的查询
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jan 3, 2024
1 parent a3fea76 commit 4c1a2d1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ class GkdAbService : CompositionAbService({
var lastTriggerShizukuTime = 0L
var lastContentEventTime = 0L
val queryThread = Dispatchers.IO.limitedParallelism(1)
val actionThread = Dispatchers.IO.limitedParallelism(1)
val eventExecutor = Executors.newSingleThreadExecutor()
onDestroy {
queryThread.cancel()
actionThread.cancel()
}
var queryTaskJob: Job? = null
fun newQueryTask(eventNode: AccessibilityNodeInfo? = null) {
Expand Down Expand Up @@ -161,11 +163,17 @@ class GkdAbService : CompositionAbService({
}
continue
}
scope.launch(queryThread) {
scope.launch(actionThread) {
if (rule.status != RuleStatus.StatusOk) return@launch
val actionResult = rule.performAction(context, target)
if (actionResult.result) {
rule.trigger()
scope.launch(actionThread) {
delay(300)
if (queryTaskJob?.isActive != true) {
newQueryTask()
}
}
toastClickTip()
insertClickLog(rule)
LogUtils.d(
Expand All @@ -178,7 +186,7 @@ class GkdAbService : CompositionAbService({
}
val t = System.currentTimeMillis()
if (t - lastTriggerTime < 10_000 || t - appChangeTime < 5_000) {
scope.launch(queryThread) {
scope.launch(actionThread) {// 在任意规则触发10s内或APP切换5s内使用主动探测查询
delay(300)
if (queryTaskJob?.isActive != true) {
newQueryTask()
Expand Down

0 comments on commit 4c1a2d1

Please sign in to comment.