Skip to content

Commit

Permalink
Merge pull request #4 from cubesky/master
Browse files Browse the repository at this point in the history
fix: 修复 MaaTouch 在 Android 14 上触控崩溃的问题
  • Loading branch information
aa889788 authored Mar 1, 2024
2 parents 7a0777c + 658195f commit 774aa24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public final class InputManager {
public static final int INJECT_MODE_WAIT_FOR_RESULT = 1;
public static final int INJECT_MODE_WAIT_FOR_FINISH = 2;

private final android.hardware.input.InputManager manager;
private final Object manager;
private Method injectInputEventMethod = null;

public InputManager(android.hardware.input.InputManager manager) {
public InputManager(Object manager) {
this.manager = manager;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shxyke.MaaTouch.wrappers;

import android.annotation.SuppressLint;
import android.os.Build;
import android.os.IBinder;
import android.os.IInterface;

Expand Down Expand Up @@ -46,10 +47,15 @@ public DisplayManager getDisplayManager() {
public InputManager getInputManager() {
if (inputManager == null) {
try {
Method getInstanceMethod = android.hardware.input.InputManager.class.getDeclaredMethod("getInstance");
android.hardware.input.InputManager im = (android.hardware.input.InputManager) getInstanceMethod.invoke(null);
Method getInstanceMethod;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
getInstanceMethod = Class.forName("android.hardware.input.InputManagerGlobal").getMethod("getInstance");
} else {
getInstanceMethod = android.hardware.input.InputManager.class.getDeclaredMethod("getInstance");
}
Object im = getInstanceMethod.invoke(null);
inputManager = new InputManager(im);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
throw new AssertionError(e);
}
Expand Down

0 comments on commit 774aa24

Please sign in to comment.