Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Direct Boot #105

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
android:theme="@style/Theme.SpeakTouch"
tools:targetApi="34"
android:icon="@null"
android:memtagMode="async">
android:memtagMode="async"
android:directBootAware="true">

<service
android:name=".service.SpeakTouchService"
Expand Down
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
}
}