Rename keycode injection method

Make it explicit that it injects both "press" and "release" events.
This commit is contained in:
Romain Vimont 2021-04-30 23:05:15 +02:00
parent 9a7d351d67
commit 233f8e6cc4
2 changed files with 7 additions and 7 deletions

View file

@ -55,7 +55,7 @@ public class Controller {
public void control() throws IOException {
// on start, power on the device
if (!Device.isScreenOn()) {
device.injectKeycode(KeyEvent.KEYCODE_POWER);
device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER);
// dirty hack
// After POWER is injected, the device is powered on asynchronously.
@ -273,7 +273,7 @@ public class Controller {
if (keepPowerModeOff) {
schedulePowerModeOff();
}
return device.injectKeycode(KeyEvent.KEYCODE_POWER);
return device.pressReleaseKeycode(KeyEvent.KEYCODE_POWER);
}
private boolean setClipboard(String text, boolean paste) {
@ -284,7 +284,7 @@ public class Controller {
// On Android >= 7, also press the PASTE key if requested
if (paste && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && device.supportsInputEvents()) {
device.injectKeycode(KeyEvent.KEYCODE_PASTE);
device.pressReleaseKeycode(KeyEvent.KEYCODE_PASTE);
}
return ok;

View file

@ -191,12 +191,12 @@ public final class Device {
return injectKeyEvent(action, keyCode, repeat, metaState, displayId);
}
public static boolean injectKeycode(int keyCode, int displayId) {
public static boolean pressReleaseKeycode(int keyCode, int displayId) {
return injectKeyEvent(KeyEvent.ACTION_DOWN, keyCode, 0, 0, displayId) && injectKeyEvent(KeyEvent.ACTION_UP, keyCode, 0, 0, displayId);
}
public boolean injectKeycode(int keyCode) {
return injectKeycode(keyCode, displayId);
public boolean pressReleaseKeycode(int keyCode) {
return pressReleaseKeycode(keyCode, displayId);
}
public static boolean isScreenOn() {
@ -272,7 +272,7 @@ public final class Device {
if (!isScreenOn()) {
return true;
}
return injectKeycode(KeyEvent.KEYCODE_POWER, displayId);
return pressReleaseKeycode(KeyEvent.KEYCODE_POWER, displayId);
}
/**