-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComponentAccessibilityService.kt
More file actions
57 lines (47 loc) · 1.7 KB
/
Copy pathComponentAccessibilityService.kt
File metadata and controls
57 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package androidx.lifecycle.accessibilityservice
import android.accessibilityservice.AccessibilityService
import android.content.Intent
import androidx.annotation.CallSuper
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ServiceLifecycleDispatcher
import androidx.savedstate.SavedStateRegistryController
import androidx.savedstate.SavedStateRegistryOwner
abstract class ComponentAccessibilityService : AccessibilityService(),
LifecycleOwner,
SavedStateRegistryOwner {
@Suppress("LeakingThis")
private val lifecycleDispatcher = ServiceLifecycleDispatcher(this)
@Suppress("LeakingThis")
private val savedStateRegistryController = SavedStateRegistryController.create(this)
override val savedStateRegistry = savedStateRegistryController.savedStateRegistry
override fun getLifecycle(): Lifecycle = lifecycleDispatcher.lifecycle
// region main lifecycle
@CallSuper
override fun onCreate() {
savedStateRegistryController.performRestore(null)
lifecycleDispatcher.onServicePreSuperOnCreate()
super.onCreate()
}
@CallSuper
override fun onServiceConnected() {
lifecycleDispatcher.onServicePreSuperOnBind()
super.onServiceConnected()
onSetOverlay()
}
open fun onSetOverlay() {
// noop
}
@CallSuper
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
override fun onStart(intent: Intent?, startId: Int) {
lifecycleDispatcher.onServicePreSuperOnStart()
super.onStart(intent, startId)
}
@CallSuper
override fun onDestroy() {
lifecycleDispatcher.onServicePreSuperOnDestroy()
super.onDestroy()
}
// endregion
}