diff --git a/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt b/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt index 57d632b..b33cf6a 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt @@ -35,14 +35,17 @@ class A11yContext( private var parentCache = LruCache(MAX_CACHE_SIZE) var rootCache: AccessibilityNodeInfo? = null - private fun clearNodeCache() { + private fun clearNodeCache(t: Long = System.currentTimeMillis()) { if (META.debuggable) { val sizeList = listOf(childCache.size(), parentCache.size(), indexCache.size()) if (sizeList.any { it > 0 }) { Log.d("cache", "clear cache -> $sizeList") } } - rootCache = null + lastClearTime = t + if (rootCache?.packageName != topActivityFlow.value.appId) { + rootCache = null + } try { childCache.evictAll() parentCache.evictAll() @@ -61,14 +64,12 @@ class A11yContext( private fun clearNodeCacheIfTimeout() { if (appChangeTime != lastAppChangeTime) { lastAppChangeTime = appChangeTime - lastClearTime = System.currentTimeMillis() clearNodeCache() return } val t = System.currentTimeMillis() if (t - lastClearTime > 30_000L) { - lastClearTime = t - clearNodeCache() + clearNodeCache(t) } } @@ -83,7 +84,7 @@ class A11yContext( if (interruptInnerKey == interruptKey) return interruptInnerKey = interruptKey val rule = currentRule ?: return - if (!activityRuleFlow.value.currentRules.contains(rule)) return + if (!activityRuleFlow.value.currentRules.any { it === rule }) return if (rule.isPriority()) return if (META.debuggable) { Log.d("guardInterrupt", "中断 rule=${rule.statusText()}")