feat: 移除 null 事件

This commit is contained in:
lisonge 2023-12-26 21:35:47 +08:00
parent 2749ac21a5
commit 24a0b3622d
3 changed files with 5 additions and 9 deletions

View File

@ -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
}

View File

@ -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) }
}
}

View File

@ -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") &&