From 87004879cc1d242314de07b5c83a9fd574901c0e Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 26 Jun 2024 20:27:51 -0700 Subject: Android: Add missing mutex on object create/read/destroy --- xbmc/platform/android/peripherals/PeripheralBusAndroid.cpp | 9 ++++++++- xbmc/platform/android/peripherals/PeripheralBusAndroid.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/xbmc/platform/android/peripherals/PeripheralBusAndroid.cpp b/xbmc/platform/android/peripherals/PeripheralBusAndroid.cpp index f8282eeb55..a785c9043b 100644 --- a/xbmc/platform/android/peripherals/PeripheralBusAndroid.cpp +++ b/xbmc/platform/android/peripherals/PeripheralBusAndroid.cpp @@ -112,6 +112,8 @@ bool CPeripheralBusAndroid::InitializeProperties(CPeripheral& peripheral) joystick.SetButtonCount(state.GetButtonCount()); joystick.SetAxisCount(state.GetAxisCount()); + std::unique_lock lock(m_critSectionStates); + // remember the joystick state m_joystickStates.insert(std::make_pair(deviceId, std::move(state))); @@ -134,6 +136,8 @@ bool CPeripheralBusAndroid::InitializeButtonMap(const CPeripheral& peripheral, return false; } + std::unique_lock lock(m_critSectionStates); + // get the joystick state auto it = m_joystickStates.find(deviceId); if (it == m_joystickStates.end()) @@ -325,7 +329,10 @@ void CPeripheralBusAndroid::OnInputDeviceRemoved(int deviceId) if (removed) { - m_joystickStates.erase(deviceId); + { + std::unique_lock lock(m_critSectionStates); + m_joystickStates.erase(deviceId); + } OnDeviceRemoved(deviceLocation); } diff --git a/xbmc/platform/android/peripherals/PeripheralBusAndroid.h b/xbmc/platform/android/peripherals/PeripheralBusAndroid.h index 5ee9480970..59bc261e54 100644 --- a/xbmc/platform/android/peripherals/PeripheralBusAndroid.h +++ b/xbmc/platform/android/peripherals/PeripheralBusAndroid.h @@ -66,7 +66,7 @@ private: mutable std::map m_joystickStates; PeripheralScanResults m_scanResults; - CCriticalSection m_critSectionStates; + mutable CCriticalSection m_critSectionStates; CCriticalSection m_critSectionResults; }; using PeripheralBusAndroidPtr = std::shared_ptr; -- cgit v1.2.3 From 04b710232ea16ec1ccf4f9a40b66bedf535ccef1 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Wed, 26 Jun 2024 22:38:45 -0700 Subject: Android: Prevent duplicate mapping of surjective keys --- xbmc/platform/android/peripherals/AndroidJoystickState.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/xbmc/platform/android/peripherals/AndroidJoystickState.cpp b/xbmc/platform/android/peripherals/AndroidJoystickState.cpp index 9e622d4d73..3b1099dd3b 100644 --- a/xbmc/platform/android/peripherals/AndroidJoystickState.cpp +++ b/xbmc/platform/android/peripherals/AndroidJoystickState.cpp @@ -469,6 +469,10 @@ bool CAndroidJoystickState::MapButton(JOYSTICK::IButtonMap& buttonMap, int butto if (controllerButton.empty()) return false; + // Check if feature is already mapped + if (buttonMap.GetFeatureType(controllerButton) != JOYSTICK::FEATURE_TYPE::UNKNOWN) + return false; + // Map the button CLog::Log(LOGDEBUG, "Automatically mapping {} to {}", controllerButton, buttonPrimitive.ToString()); -- cgit v1.2.3