From bba367376b8e2727bd9674ea7211cd1f29e1611d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Mi=C5=9B?= Date: Tue, 14 Nov 2023 15:30:30 +0100 Subject: [PATCH] Add Service state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ś --- .../speaktouch/service/SpeakTouchService.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/com/neo/speaktouch/service/SpeakTouchService.kt b/app/src/main/java/com/neo/speaktouch/service/SpeakTouchService.kt index d4fcd09f..5ea0336a 100644 --- a/app/src/main/java/com/neo/speaktouch/service/SpeakTouchService.kt +++ b/app/src/main/java/com/neo/speaktouch/service/SpeakTouchService.kt @@ -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() } @@ -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) { @@ -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 @@ -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 + } }