mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-15 19:22:26 +08:00
fix: setGeneratedTime failed (#759)
Some checks failed
Build-Apk / build (push) Has been cancelled
Some checks failed
Build-Apk / build (push) Has been cancelled
This commit is contained in:
parent
db3be41dff
commit
03cdf98f09
|
@ -126,7 +126,6 @@ class A11yService : AccessibilityService(), OnCreate, OnA11yConnected, OnA11yEve
|
||||||
val cache = A11yContext(true)
|
val cache = A11yContext(true)
|
||||||
|
|
||||||
val targetNode = serviceVal.safeActiveWindow?.let {
|
val targetNode = serviceVal.safeActiveWindow?.let {
|
||||||
cache.rootCache = it
|
|
||||||
cache.querySelector(
|
cache.querySelector(
|
||||||
it,
|
it,
|
||||||
selector,
|
selector,
|
||||||
|
@ -275,7 +274,11 @@ private fun A11yService.useMatchRule() {
|
||||||
if (byForced && !rule.checkForced()) continue
|
if (byForced && !rule.checkForced()) continue
|
||||||
lastNode?.let { n ->
|
lastNode?.let { n ->
|
||||||
val refreshOk = (!lastNodeUsed) || (try {
|
val refreshOk = (!lastNodeUsed) || (try {
|
||||||
n.refresh()
|
val e = n.refresh()
|
||||||
|
if (e) {
|
||||||
|
n.setGeneratedTime()
|
||||||
|
}
|
||||||
|
e
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
false
|
false
|
||||||
})
|
})
|
||||||
|
|
|
@ -17,19 +17,21 @@ import li.songe.selector.UnknownMemberMethodException
|
||||||
import li.songe.selector.UnknownMemberMethodParamsException
|
import li.songe.selector.UnknownMemberMethodParamsException
|
||||||
import li.songe.selector.initDefaultTypeInfo
|
import li.songe.selector.initDefaultTypeInfo
|
||||||
|
|
||||||
|
// 在主线程调用任意获取新节点或刷新节点的API会阻塞界面导致卡顿
|
||||||
|
|
||||||
// 某些应用耗时 554ms
|
// 某些应用耗时 554ms
|
||||||
val AccessibilityService.safeActiveWindow: AccessibilityNodeInfo?
|
val AccessibilityService.safeActiveWindow: AccessibilityNodeInfo?
|
||||||
get() = try {
|
get() = try {
|
||||||
// java.lang.SecurityException: Call from user 0 as user -2 without permission INTERACT_ACROSS_USERS or INTERACT_ACROSS_USERS_FULL not allowed.
|
// java.lang.SecurityException: Call from user 0 as user -2 without permission INTERACT_ACROSS_USERS or INTERACT_ACROSS_USERS_FULL not allowed.
|
||||||
rootInActiveWindow.apply {
|
rootInActiveWindow?.apply {
|
||||||
a11yContext.rootCache = this
|
// https://github.com/gkd-kit/gkd/issues/759
|
||||||
}?.apply {
|
|
||||||
setGeneratedTime()
|
setGeneratedTime()
|
||||||
}
|
}
|
||||||
// 在主线程调用会阻塞界面导致卡顿
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
null
|
null
|
||||||
|
}.apply {
|
||||||
|
a11yContext.rootCache = this
|
||||||
}
|
}
|
||||||
|
|
||||||
val AccessibilityService.safeActiveWindowAppId: String?
|
val AccessibilityService.safeActiveWindowAppId: String?
|
||||||
|
@ -76,8 +78,8 @@ fun AccessibilityNodeInfo.setGeneratedTime() {
|
||||||
fun AccessibilityNodeInfo.isExpired(expiryMillis: Long): Boolean {
|
fun AccessibilityNodeInfo.isExpired(expiryMillis: Long): Boolean {
|
||||||
val generatedTime = extras.getLong(A11Y_NODE_TIME_KEY, -1)
|
val generatedTime = extras.getLong(A11Y_NODE_TIME_KEY, -1)
|
||||||
if (generatedTime == -1L) {
|
if (generatedTime == -1L) {
|
||||||
setGeneratedTime()
|
// https://github.com/gkd-kit/gkd/issues/759
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
return (System.currentTimeMillis() - generatedTime) > expiryMillis
|
return (System.currentTimeMillis() - generatedTime) > expiryMillis
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user