Use the newly public InputDevice.isExternal() function on Android Q

This commit is contained in:
Cameron Gutman 2019-06-05 20:23:22 -07:00
parent 6fb3a8e57d
commit b7810d6eb6

View File

@ -335,6 +335,11 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
} }
private static boolean isExternal(InputDevice dev) { private static boolean isExternal(InputDevice dev) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// Landroid/view/InputDevice;->isExternal()Z is officially public on Android Q
return dev.isExternal();
}
else {
try { try {
// Landroid/view/InputDevice;->isExternal()Z is on the light graylist in Android P // Landroid/view/InputDevice;->isExternal()Z is on the light graylist in Android P
return (Boolean)dev.getClass().getMethod("isExternal").invoke(dev); return (Boolean)dev.getClass().getMethod("isExternal").invoke(dev);
@ -347,6 +352,7 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
} catch (ClassCastException e) { } catch (ClassCastException e) {
e.printStackTrace(); e.printStackTrace();
} }
}
// Answer true if we don't know // Answer true if we don't know
return true; return true;