Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal server for inputs only #493

Closed
toddsierens opened this issue Apr 9, 2019 · 3 comments
Closed

Minimal server for inputs only #493

toddsierens opened this issue Apr 9, 2019 · 3 comments

Comments

@toddsierens
Copy link
Contributor

Hello,

I think this product is amazing and I'm quite impressed that it works this well. I've been fiddling with low-level inputs using the shell sendevent, but as others have pointed out, this is very slow due to needing to create a java runtime environment for each command.

I find myself unable to disentangle the codebase for scrcpy to make a simple adb implementation of injecting InputEvents to the android device.

Could you help me get started with what steps I need to do.

I imagine that I will need to set up a server-client socket and send events from client to server to instruct on input events to inject. But even where to start, what packages to import, how to use the hidden API for the interface etc.

Any help is appreciated.

@rom1v
Copy link
Collaborator

rom1v commented Apr 11, 2019

Could you help me get started with what steps I need to do.

I guess you already read this comment: #231 (comment)

The client just serializes an event (in some format) and send it to the server. The server receives the event and injects it to the device.

@GoldDust69
Copy link

Hello,

I think this product is amazing and I'm quite impressed that it works this well. I've been fiddling with low-level inputs using the shell sendevent, but as others have pointed out, this is very slow due to needing to create a java runtime environment for each command.

I find myself unable to disentangle the codebase for scrcpy to make a simple adb implementation of injecting InputEvents to the android device.

Could you help me get started with what steps I need to do.

I imagine that I will need to set up a server-client socket and send events from client to server to instruct on input events to inject. But even where to start, what packages to import, how to use the hidden API for the interface etc.

Any help is appreciated.

I'd be interested to hear if you made any progress with this please as I too am looking to do something similar.

@toddsierens
Copy link
Contributor Author

A small amount, I have a very simple code snippet for event injections, but I want to take a device screenshot and am stumbling how to do this from an app_process with no android context.

Here is the code snippet that is simple enough for myself to understand :p

public class InjectEvent {
    private static InputManager im;
    private static final String GET_INSTANCE = "getInstance";
    private static final String INJECT_INPUT_EVENT = "injectInputEvent";
    private static Method injectInputEventMethod;

    static{
        try {
            im = (InputManager) InputManager.class.getDeclaredMethod(GET_INSTANCE, new Class[0])
                    .invoke(null, new Object[0]);
            injectInputEventMethod = InputManager.class.getMethod(
                    INJECT_INPUT_EVENT, new Class[]{InputEvent.class, int.class});
        } catch(Exception e){System.out.println("Failed to create wrapper");}
    }
    public static void injectInputEvent (InputEvent event, int sync)
            throws IllegalAccessException, InvocationTargetException{
        injectInputEventMethod.invoke(im, new Object[]{event, sync});
    }
}

What the static block does is get an instance of InputManager using reflection, and it gets the inject event method using reflection, and the injectInputEvent method invokes the method.

All of this was inspired/deduced or straight up copied from scrcpy. Just stripped of every piece of the puzzle that might not be necessary for input injections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants