Skip to content

Commit

Permalink
Add Service state
Browse files Browse the repository at this point in the history
This feature will be not only useful for debugging, but also to make sure
the  Services is running before we try to set TTS which supports Direct Boot.

Signed-off-by: Patryk Miś <[email protected]>
  • Loading branch information
PatrykMis committed Nov 16, 2023
1 parent 441eedc commit 7642f10
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/com/neo/speaktouch/service/SpeakTouchService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ import javax.inject.Inject
@AndroidEntryPoint
class SpeakTouchService : AccessibilityService() {

enum class ServiceState {
NULL,
LOADING,
ENABLED,
SHUTTING_DOWN,
DISABLED
}

private var serviceState: ServiceState = ServiceState.NULL

@Inject
lateinit var interceptors: Interceptors

override fun onCreate() {
super.onCreate()

setServiceState(ServiceState.LOADING)
Controllers.install()
}

Expand All @@ -48,6 +59,7 @@ class SpeakTouchService : AccessibilityService() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
addFlags(AccessibilityServiceInfo.FLAG_REQUEST_2_FINGER_PASSTHROUGH)
}
setServiceState(ServiceState.ENABLED)
}

override fun onAccessibilityEvent(event: AccessibilityEvent) {
Expand All @@ -59,9 +71,11 @@ class SpeakTouchService : AccessibilityService() {
override fun onDestroy() {
super.onDestroy()

setServiceState(ServiceState.SHUTTING_DOWN)
interceptors.event.forEach(EventInterceptor::finish)

Controllers.uninstall()
setServiceState(ServiceState.DISABLED)
}

override fun onInterrupt() = Unit
Expand All @@ -70,4 +84,12 @@ class SpeakTouchService : AccessibilityService() {
override fun onGesture(gestureId: Int): Boolean {
return interceptors.gesture.handle(gestureId)
}

fun getServiceState(): ServiceState {
return serviceState
}

private fun setServiceState(newState: ServiceState) {
serviceState = newState
}
}

0 comments on commit 7642f10

Please sign in to comment.