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

Android: Two fixes on the joystick codepath #25179

Draft
wants to merge 2 commits into
base: master
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
19 changes: 19 additions & 0 deletions xbmc/platform/android/peripherals/AndroidJoystickState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,25 @@ bool CAndroidJoystickState::ProcessEvent(const AInputEvent* event)

bool result = SetButtonValue(keycode, buttonState);

if (!result)
{
// Try shoehorning keys into buttons
switch (keycode)
{
case AKEYCODE_MENU:
result = SetButtonValue(AKEYCODE_BUTTON_START, buttonState);
break;
case AKEYCODE_BACK:
result = SetButtonValue(AKEYCODE_BUTTON_SELECT, buttonState);
break;
case AKEYCODE_HOME:
result = SetButtonValue(AKEYCODE_BUTTON_MODE, buttonState);
break;
default:
break;
}
}

return result;
}

Expand Down
55 changes: 53 additions & 2 deletions xbmc/platform/android/peripherals/PeripheralBusAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,59 @@ bool CPeripheralBusAndroid::ConvertToPeripheralScanResult(
if (!inputDevice.supportsSource(CJNIViewInputDevice::SOURCE_JOYSTICK) &&
!inputDevice.supportsSource(CJNIViewInputDevice::SOURCE_GAMEPAD))
{
CLog::Log(LOGDEBUG, "CPeripheralBusAndroid: ignoring non-joystick device");
return false;
// Observed an anomylous PS4 controller with only SOURCE_MOUSE
if (!inputDevice.supportsSource(CJNIViewInputDevice::SOURCE_MOUSE))
{
CLog::Log(LOGDEBUG, "CPeripheralBusAndroid: ignoring non-joystick device");
return false;
}

// Make sure the anomylous controller has buttons
// clang-format off
std::vector<int> buttons{
AKEYCODE_BUTTON_A,
AKEYCODE_BUTTON_B,
AKEYCODE_BUTTON_C,
AKEYCODE_BUTTON_X,
AKEYCODE_BUTTON_Y,
AKEYCODE_BUTTON_Z,
AKEYCODE_BUTTON_L1,
AKEYCODE_BUTTON_R1,
AKEYCODE_BUTTON_L2,
AKEYCODE_BUTTON_R2,
AKEYCODE_BUTTON_THUMBL,
AKEYCODE_BUTTON_THUMBR,
AKEYCODE_BUTTON_START,
AKEYCODE_BUTTON_SELECT,
AKEYCODE_BUTTON_MODE,
AKEYCODE_BUTTON_1,
AKEYCODE_BUTTON_2,
AKEYCODE_BUTTON_3,
AKEYCODE_BUTTON_4,
AKEYCODE_BUTTON_5,
AKEYCODE_BUTTON_6,
AKEYCODE_BUTTON_7,
AKEYCODE_BUTTON_8,
AKEYCODE_BUTTON_9,
AKEYCODE_BUTTON_10,
AKEYCODE_BUTTON_11,
AKEYCODE_BUTTON_12,
AKEYCODE_BUTTON_13,
AKEYCODE_BUTTON_14,
AKEYCODE_BUTTON_15,
AKEYCODE_BUTTON_16,
};
// clang-format on

auto result = inputDevice.hasKeys(buttons);

if (std::find(result.begin(), result.end(), true) == result.end())
{
CLog::Log(LOGDEBUG, "CPeripheralBusAndroid: ignoring non-joystick device with mouse source");
return false;
}

CLog::Log(LOGDEBUG, "CPeripheralBusAndroid: adding non-joystick device with mouse source");
}

peripheralScanResult.m_type = PERIPHERAL_JOYSTICK;
Expand Down