package com.xhly.manageapp.service

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import com.xhly.corelib.Const
import com.xhly.corelib.eventbus.UIEvent
import com.xhly.corelib.utils.LogShow

class ManageAccessibilityService : AccessibilityService() {
    override fun onAccessibilityEvent(event: AccessibilityEvent?) {
        event?.let {
            if (AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED == it.eventType) {
                LogShow(it.packageName.toString() + "|||" + it.className.toString())
               /* if (it.className.toString().equals("com.example.mytestxf.MainActivity")) {
                    performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK)
                }*/
                if (!it.packageName.toString().isNullOrBlank()) {
                    val uiEvent = UIEvent(Const.LOGAPPSTART)
                    uiEvent.setMessage(it.packageName.toString())
                    uiEvent.post()
                }
            }
        }
    }

    override fun onInterrupt() {

    }

    override fun onDestroy() {
        super.onDestroy()
        LogShow("我被销毁")
    }
}