diff --git a/app/src/main/kotlin/li/songe/gkd/composition/CanOnAccessibilityEvent.kt b/app/src/main/kotlin/li/songe/gkd/composition/CanOnAccessibilityEvent.kt index 4b0beed..bf3b4a2 100644 --- a/app/src/main/kotlin/li/songe/gkd/composition/CanOnAccessibilityEvent.kt +++ b/app/src/main/kotlin/li/songe/gkd/composition/CanOnAccessibilityEvent.kt @@ -3,5 +3,5 @@ package li.songe.gkd.composition import android.view.accessibility.AccessibilityEvent interface CanOnAccessibilityEvent { - fun onAccessibilityEvent(f: (AccessibilityEvent?) -> Unit):Boolean + fun onAccessibilityEvent(f: (AccessibilityEvent) -> Unit): Boolean } \ No newline at end of file diff --git a/app/src/main/kotlin/li/songe/gkd/composition/CompositionAbService.kt b/app/src/main/kotlin/li/songe/gkd/composition/CompositionAbService.kt index f376ad5..fadf6aa 100644 --- a/app/src/main/kotlin/li/songe/gkd/composition/CompositionAbService.kt +++ b/app/src/main/kotlin/li/songe/gkd/composition/CompositionAbService.kt @@ -28,15 +28,15 @@ open class CompositionAbService( destroyHooks.forEach { f -> f() } } - private val onAccessibilityEventHooks by lazy { linkedSetOf<(AccessibilityEvent?) -> Unit>() } + private val onAccessibilityEventHooks by lazy { linkedSetOf<(AccessibilityEvent) -> Unit>() } private val interestedEvents = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED or AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED - override fun onAccessibilityEvent(f: (AccessibilityEvent?) -> Unit) = + override fun onAccessibilityEvent(f: (AccessibilityEvent) -> Unit) = onAccessibilityEventHooks.add(f) override fun onAccessibilityEvent(event: AccessibilityEvent?) { - if (event?.eventType?.and(interestedEvents) != 0) { + if (event != null && event.eventType.and(interestedEvents) != 0) { onAccessibilityEventHooks.forEach { f -> f(event) } } } diff --git a/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt b/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt index dfef0b6..ddd9bc3 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt @@ -155,9 +155,6 @@ class GkdAbService : CompositionAbService({ val skipAppIds = listOf("com.android.systemui") onAccessibilityEvent { event -> - if (event == null || event.packageName == null) return@onAccessibilityEvent - if (!(event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED)) return@onAccessibilityEvent - if (event.eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && skipAppIds.contains(event.packageName.toString()) ) { @@ -279,7 +276,7 @@ class GkdAbService : CompositionAbService({ var lastUpdateSubsTime = 0L onAccessibilityEvent { - if (it?.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {// 筛选降低判断频率 + if (it.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {// 筛选降低判断频率 // 借助 无障碍事件 触发自动检测更新 val i = storeFlow.value.updateSubsInterval val t = System.currentTimeMillis() @@ -394,7 +391,6 @@ class GkdAbService : CompositionAbService({ onAccessibilityEvent { e -> if (!storeFlow.value.captureScreenshot) return@onAccessibilityEvent - e ?: return@onAccessibilityEvent val appId = e.packageName ?: return@onAccessibilityEvent val appCls = e.className ?: return@onAccessibilityEvent if (appId.contentEquals("com.miui.screenshot") &&