Skip to content

Commit

Permalink
perf: match event
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Sep 30, 2024
1 parent 876c047 commit 737172b
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 196 deletions.
3 changes: 2 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import li.songe.gkd.util.openApp
import li.songe.gkd.util.openUri
import li.songe.gkd.util.storeFlow
import kotlin.reflect.KClass
import kotlin.reflect.jvm.jvmName

class MainActivity : ComponentActivity() {
val mainVm by viewModels<MainViewModel>()
Expand Down Expand Up @@ -153,7 +154,7 @@ private fun updateServiceRunning() {
}

fun checkRunning(cls: KClass<*>): Boolean {
return list.any { it.service.className == cls.java.name }
return list.any { it.service.className == cls.jvmName }
}
ManageService.isRunning.value = checkRunning(ManageService::class)
A11yService.isRunning.value = checkRunning(A11yService::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.service.quicksettings.TileService
import com.blankj.utilcode.util.LogUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import li.songe.gkd.appScope
import li.songe.gkd.debug.SnapshotExt.captureSnapshot
import li.songe.gkd.service.A11yService
Expand Down Expand Up @@ -46,7 +47,7 @@ class SnapshotTileService : TileService() {
}
} else if (latestAppId != oldAppId) {
LogUtils.d("SnapshotTileService::eventExecutor.execute")
A11yService.eventExecutor.execute {
appScope.launch(A11yService.eventThread) {
val topActivity = safeGetTopActivity() ?: TopActivity(appId = latestAppId)
updateTopActivity(topActivity)
getAndUpdateCurrentRules()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/service/A11yEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ data class A11yEvent(
val className: String,
)

fun A11yEvent.sameAs(other: A11yEvent): Boolean {
if (other === this) return true
return type == other.type && appId == other.appId && className == other.className
}

fun AccessibilityEvent.toA11yEvent(): A11yEvent? {
return A11yEvent(
type = eventType,
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/kotlin/li/songe/gkd/service/A11yExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import li.songe.selector.getCharSequenceInvoke
import li.songe.selector.getIntInvoke
import li.songe.selector.initDefaultTypeInfo


// 某些应用耗时 554ms
val AccessibilityService.safeActiveWindow: AccessibilityNodeInfo?
get() = try {
// java.lang.SecurityException: Call from user 0 as user -2 without permission INTERACT_ACROSS_USERS or INTERACT_ACROSS_USERS_FULL not allowed.
Expand All @@ -38,6 +38,10 @@ val AccessibilityService.safeActiveWindow: AccessibilityNodeInfo?
null
}

val AccessibilityService.activeWindowAppId: String?
get() = safeActiveWindow?.packageName?.toString()

// 在某些应用耗时 300ms
val AccessibilityEvent.safeSource: AccessibilityNodeInfo?
get() = if (className == null) {
null // https://github.com/gkd-kit/gkd/issues/426 event.clear 已被系统调用
Expand Down
Loading

0 comments on commit 737172b

Please sign in to comment.