diff --git a/app/src/main/java/com/limelight/Game.java b/app/src/main/java/com/limelight/Game.java index 5d214508a..d2613a9e9 100644 --- a/app/src/main/java/com/limelight/Game.java +++ b/app/src/main/java/com/limelight/Game.java @@ -92,6 +92,8 @@ public class Game extends Activity implements SurfaceHolder.Callback, OnGenericMotionListener, OnTouchListener, NvConnectionListener, EvdevListener, OnSystemUiVisibilityChangeListener, GameGestures, StreamView.InputCallbacks, PerfOverlayListener, UsbDriverService.UsbDriverStateListener, View.OnKeyListener { + + public static Game instance = null; private int lastButtonState = 0; // Only 2 touches are supported @@ -121,6 +123,9 @@ public class Game extends Activity implements SurfaceHolder.Callback, private boolean displayedFailureDialog = false; private boolean connecting = false; private boolean connected = false; + public boolean isConnected() { + return connected; + } private boolean autoEnterPip = false; private boolean surfaceCreated = false; private boolean attemptedConnection = false; @@ -185,6 +190,8 @@ public void onServiceDisconnected(ComponentName componentName) { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + instance = this; + UiHelper.setLocale(this); // We don't want a title bar @@ -1072,6 +1079,8 @@ protected void onPause() { protected void onStop() { super.onStop(); + instance = null; + SpinnerDialog.closeDialogs(this); Dialog.closeDialogs(); diff --git a/app/src/main/java/com/limelight/KeyboardAccessibilityService.java b/app/src/main/java/com/limelight/KeyboardAccessibilityService.java new file mode 100644 index 000000000..e438485e9 --- /dev/null +++ b/app/src/main/java/com/limelight/KeyboardAccessibilityService.java @@ -0,0 +1,47 @@ +package com.limelight; + +import android.accessibilityservice.AccessibilityService; +import android.view.KeyEvent; +import android.view.accessibility.AccessibilityEvent; + +import java.util.Arrays; +import java.util.List; + +public class KeyboardAccessibilityService extends AccessibilityService { + + private final static List BLACKLISTED_KEYS = Arrays.asList(KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_VOLUME_DOWN, KeyEvent.KEYCODE_POWER); + + @Override + public boolean onKeyEvent(KeyEvent event) { + int action = event.getAction(); + int keyCode = event.getKeyCode(); + + if (Game.instance != null && Game.instance.isConnected() && !BLACKLISTED_KEYS.contains(keyCode)) { + // Preventing default will disable shortcut actions like alt+tab and etc. + if (action == KeyEvent.ACTION_DOWN) { + Game.instance.handleKeyDown(event); + return true; + } else if (action == KeyEvent.ACTION_UP) { + Game.instance.handleKeyUp(event); + return true; + } + } + + return super.onKeyEvent(event); + } + + @Override + public void onServiceConnected() { + LimeLog.info("Keyboard service is connected"); + } + + @Override + public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) { + + } + + @Override + public void onInterrupt() { + + } +} \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 82cf3222e..9be4246b1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -298,4 +298,7 @@ None (both sticks move the mouse) Right analog stick Left analog stick + + Moonlight Physical Keyboard Service + These permissions are only used to detect when buttons are pressed so they can be sent to PC without triggering default action on your device.\n\nMoonlight does NOT observe the text you type and does NOT collect your passwords, credit card numbers or any other information. diff --git a/app/src/main/res/xml/keyboard_accessibility_service.xml b/app/src/main/res/xml/keyboard_accessibility_service.xml new file mode 100644 index 000000000..1d7ee8e64 --- /dev/null +++ b/app/src/main/res/xml/keyboard_accessibility_service.xml @@ -0,0 +1,10 @@ + + \ No newline at end of file diff --git a/app/src/nonRoot/AndroidManifest.xml b/app/src/nonRoot/AndroidManifest.xml index 815895ec8..223d8ea68 100644 --- a/app/src/nonRoot/AndroidManifest.xml +++ b/app/src/nonRoot/AndroidManifest.xml @@ -3,5 +3,19 @@ - + + + + + + + +