Skip to content

Commit

Permalink
init on onServiceConnected
Browse files Browse the repository at this point in the history
  • Loading branch information
Krosxx committed Mar 2, 2023
1 parent 1089fdf commit 4fe450b
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import cn.vove7.andro_accessibility_api.utils.whileWaitTime
import cn.vove7.andro_accessibility_api.viewnode.ViewNode
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.lang.Thread.sleep
import kotlin.math.min

/**
Expand All @@ -23,21 +22,20 @@ import kotlin.math.min
*/
@Suppress("MemberVisibilityCanBePrivate")
abstract class AccessibilityApi : AccessibilityService(), BaseServiceApi {
//implement of BaseServiceApi
// implement of BaseServiceApi
override val _baseService: AccessibilityService get() = this

abstract val enableListenAppScope: Boolean

var currentScope: AppScope? = null
private set

//activity or dialog
// activity or dialog
var currentPage: String? = null
private set
get() = currentScope?.packageName

override fun onCreate() {
super.onCreate()
override fun onServiceConnected() {
if (this::class.java == BASE_SERVICE_CLS) {
baseService = this
}
Expand All @@ -61,7 +59,7 @@ abstract class AccessibilityApi : AccessibilityService(), BaseServiceApi {
*/
val activeWinNode: ViewNode? get() = ViewNode.activeWinNode()

//适应 多窗口 分屏
// 适应 多窗口 分屏
val rootNodeOfAllWindows get() = ViewNode.getRoot()

override fun getRootInActiveWindow(): AccessibilityNodeInfo? {
Expand Down Expand Up @@ -119,7 +117,7 @@ abstract class AccessibilityApi : AccessibilityService(), BaseServiceApi {
event ?: return

if (event.eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
//界面切换
// 界面切换
val classNameStr = event.className
val pkg = event.packageName as String?
if (!classNameStr.isNullOrBlank() && pkg != null) {
Expand Down Expand Up @@ -155,7 +153,7 @@ abstract class AccessibilityApi : AccessibilityService(), BaseServiceApi {

private fun isEnableGestureService() = ::GESTURE_SERVICE_CLS.isInitialized

//无障碍基础服务
// 无障碍基础服务
@SuppressLint("StaticFieldLeak")
var baseService: AccessibilityApi? = null

Expand All @@ -165,7 +163,7 @@ abstract class AccessibilityApi : AccessibilityService(), BaseServiceApi {
baseService!!
}

//无障碍高级服务 执行手势等操作
// 无障碍高级服务 执行手势等操作
/**
* GestureService base on AccessibilityApi
*/
Expand All @@ -185,6 +183,9 @@ abstract class AccessibilityApi : AccessibilityService(), BaseServiceApi {
val isBaseServiceEnable: Boolean
get() = (baseService != null)

val isServiceEnable: Boolean
get() = isBaseServiceEnable

val isGestureServiceEnable: Boolean get() = gestureService != null

/**
Expand All @@ -210,15 +211,15 @@ abstract class AccessibilityApi : AccessibilityService(), BaseServiceApi {
} ?: throw NeedAccessibilityException(cls.name)
}

//声明 需要基础无障碍权限
// 声明 需要基础无障碍权限
fun requireBaseAccessibility(autoJump: Boolean = false) {
if (!isBaseServiceEnable) {
if (autoJump) jumpAccessibilityServiceSettings(BASE_SERVICE_CLS)
throw NeedAccessibilityException(BASE_SERVICE_CLS.name)
}
}

//声明 需要手势无障碍权限
// 声明 需要手势无障碍权限
fun requireGestureAccessibility(autoJump: Boolean = false) {
if (!isGestureServiceEnable) {
if (autoJump) jumpAccessibilityServiceSettings(GESTURE_SERVICE_CLS)
Expand Down

0 comments on commit 4fe450b

Please sign in to comment.