Skip to content

Commit

Permalink
#1376 cleanup and fix merge conflicts in KeyEventRelayService
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Dec 27, 2024
1 parent c6f6325 commit 08501e0
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ class KeyEventRelayService : Service() {

private val binderInterface: IKeyEventRelayService = object : IKeyEventRelayService.Stub() {
override fun sendKeyEvent(event: KeyEvent?, targetPackageName: String?): Boolean {
synchronized(callbackLock) {
Timber.d("KeyEventRelayService: onKeyEvent ${event?.keyCode}")

val client = clients[targetPackageName]
Timber.d("KeyEventRelayService: onKeyEvent ${event?.keyCode}")

if (client == null) {
synchronized(callbackLock) {
if (!clients.containsKey(targetPackageName)) {
return false
} else {
try {
// Get the process ID of the app that called this service.
val sourcePackageName = getCallerPackageName() ?: return false
}

if (!permittedPackages.contains(sourcePackageName)) {
Timber.d("An unrecognized package $sourcePackageName tried to send a key event.")
val client = clients[targetPackageName]!!

return false
}
try {
// Get the process ID of the app that called this service.
val sourcePackageName = getCallerPackageName() ?: return false

if (!permittedPackages.contains(sourcePackageName)) {
Timber.d("An unrecognized package $sourcePackageName tried to send a key event.")

return client.callback.onKeyEvent(event, targetPackageName)
} catch (e: DeadObjectException) {
// If the application is no longer connected then delete the callback.
clients.remove(targetPackageName)
return false
}

return client.callback.onKeyEvent(event, targetPackageName)
} catch (e: DeadObjectException) {
// If the application is no longer connected then delete the callback.
clients.remove(targetPackageName)
return false
}
}
}
Expand Down Expand Up @@ -127,13 +127,13 @@ class KeyEventRelayService : Service() {
}

private inner class ClientConnection(
private val sourcePackageName: String,
private val clientPackageName: String,
val callback: IKeyEventRelayServiceCallback
) : DeathRecipient {
override fun binderDied() {
Timber.d("Client binder died: $sourcePackageName")
Timber.d("Client binder died: $clientPackageName")
synchronized(callbackLock) {
clients.remove(sourcePackageName)
clients.remove(clientPackageName)
}
}
}
Expand Down

0 comments on commit 08501e0

Please sign in to comment.