From 29eab659b7662f86faa854f6da734f9eb12280e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Mi=C5=9B?= Date: Tue, 14 Nov 2023 15:17:41 +0100 Subject: [PATCH 1/2] Direct Boot: initial support. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SpeakTouch already turns on at `boot_locked` in this state. Signed-off-by: Patryk Miś --- app/src/main/AndroidManifest.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a5f00a75..31f49d47 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -20,7 +20,8 @@ android:theme="@style/Theme.SpeakTouch" tools:targetApi="34" android:icon="@null" - android:memtagMode="async"> + android:memtagMode="async" + android:directBootAware="true"> Date: Tue, 14 Nov 2023 15:30:30 +0100 Subject: [PATCH 2/2] 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 + } }