11package io.github.sds100.keymapper.inputmethod.latin
22
3-
43import android.content.BroadcastReceiver
54import android.content.ComponentName
65import android.content.Context
@@ -28,7 +27,6 @@ class KeyEventRelayServiceWrapperImpl(
2827 private val id : String ,
2928 private val callback : IKeyEventRelayServiceCallback ,
3029) : KeyEventRelayServiceWrapper {
31-
3230 companion object {
3331 /* *
3432 * This is used to listen to when the key event relay service is restarted in Key Mapper.
@@ -66,23 +64,28 @@ class KeyEventRelayServiceWrapperImpl(
6664 }
6765 }
6866
69- private val broadcastReceiver: BroadcastReceiver = object : BroadcastReceiver () {
70- override fun onReceive (context : Context ? , intent : Intent ? ) {
71- context ? : return
72- intent ? : return
67+ private val broadcastReceiver: BroadcastReceiver =
68+ object : BroadcastReceiver () {
69+ override fun onReceive (
70+ context : Context ? ,
71+ intent : Intent ? ,
72+ ) {
73+ context ? : return
74+ intent ? : return
7375
74- when (intent.action) {
75- ACTION_REBIND_RELAY_SERVICE -> {
76- bind()
76+ when (intent.action) {
77+ ACTION_REBIND_RELAY_SERVICE -> {
78+ bind()
79+ }
7780 }
7881 }
7982 }
80- }
8183
8284 fun onCreate () {
83- val intentFilter = IntentFilter ().apply {
84- addAction(ACTION_REBIND_RELAY_SERVICE )
85- }
85+ val intentFilter =
86+ IntentFilter ().apply {
87+ addAction(ACTION_REBIND_RELAY_SERVICE )
88+ }
8689
8790 ContextCompat .registerReceiver(ctx, broadcastReceiver, intentFilter, ContextCompat .RECEIVER_EXPORTED )
8891 bind()
@@ -128,15 +131,17 @@ class KeyEventRelayServiceWrapperImpl(
128131 }
129132
130133 private fun bind () {
131- Log .d(LatinIME .TAG , " Bind $servicePackageName " )
132134 try {
133135 val relayServiceIntent = Intent ()
134136 val component =
135137 ComponentName (servicePackageName, " io.github.sds100.keymapper.api.KeyEventRelayService" )
136138 relayServiceIntent.setComponent(component)
137139 val isSuccess = ctx.bindService(relayServiceIntent, serviceConnection, 0 )
138140
139- if (! isSuccess) {
141+ if (isSuccess) {
142+ Log .d(LatinIME .TAG , " Bind $servicePackageName " )
143+ } else {
144+ Log .d(LatinIME .TAG , " Bind unsuccessful $servicePackageName " )
140145 ctx.unbindService(serviceConnection)
141146 }
142147 } catch (e: SecurityException ) {
@@ -163,10 +168,18 @@ class KeyEventRelayServiceWrapperImpl(
163168 // while there is no registered connection.
164169 }
165170 }
166-
167171}
168172
169173interface KeyEventRelayServiceWrapper {
170- fun sendKeyEvent (event : KeyEvent , targetPackageName : String , callbackId : String ): Boolean
171- fun sendMotionEvent (event : MotionEvent , targetPackageName : String , callbackId : String ): Boolean
174+ fun sendKeyEvent (
175+ event : KeyEvent ,
176+ targetPackageName : String ,
177+ callbackId : String ,
178+ ): Boolean
179+
180+ fun sendMotionEvent (
181+ event : MotionEvent ,
182+ targetPackageName : String ,
183+ callbackId : String ,
184+ ): Boolean
172185}
0 commit comments