SDL: Fixed deadlock introduced by 7222c04fbf2b904e815f5ac9c8623ef8030fd261 (85d86)

From 85d86dd72c0339f46b4c017055e3ae8d5da42af0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 17 May 2026 12:17:26 -0700
Subject: [PATCH] Fixed deadlock introduced by
 7222c04fbf2b904e815f5ac9c8623ef8030fd261

It turns out this change causes a deadlock:
The main UI thread calls synchronized handleMotionEvent() which then calls SDL_LockJoysticks()
The main app thread calls SDL_LockJoysticks() and then synchronized pollInputDevices()

(cherry picked from commit 8c89a076a7b8c70ef2ec9af8c8169c4d6775d68e)
---
 .../main/java/org/libsdl/app/SDLControllerManager.java    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
index 2a0296eb0c03f..bce15e9de228a 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
@@ -346,7 +346,7 @@ synchronized void pollInputDevices() {
         }
     }
 
-    protected SDLJoystick getJoystick(int device_id) {
+    synchronized protected SDLJoystick getJoystick(int device_id) {
         for (SDLJoystick joystick : mJoysticks) {
             if (joystick.device_id == device_id) {
                 return joystick;
@@ -360,7 +360,7 @@ protected SDLJoystick getJoystick(int device_id) {
      * @param event the event to be handled.
      * @return if given event was processed.
      */
-    synchronized boolean handleMotionEvent(MotionEvent event) {
+    boolean handleMotionEvent(MotionEvent event) {
         int actionPointerIndex = event.getActionIndex();
         int action = event.getActionMasked();
         if (action == MotionEvent.ACTION_MOVE) {
@@ -530,7 +530,7 @@ int getButtonMask(InputDevice joystickDevice) {
         return button_mask;
     }
 
-    synchronized void setLED(int device_id, int red, int green, int blue) {
+    void setLED(int device_id, int red, int green, int blue) {
         if (Build.VERSION.SDK_INT < 31 /* Android 12.0 (S) */) {
             return;
         }
@@ -548,7 +548,7 @@ synchronized void setLED(int device_id, int red, int green, int blue) {
         joystick.lightsSession.requestLights(lightsRequest.build());
     }
 
-    synchronized void setSensorsEnabled(int device_id, boolean enabled) {
+    void setSensorsEnabled(int device_id, boolean enabled) {
         if (Build.VERSION.SDK_INT < 31 /* Android 12.0 (S) */) {
             return;
         }