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