Question

Answers for this question should be ideally non-rooted.

I am looking at re-writing one of the adb tools, sendevent.c I have found this file online and am confident that i could adapt it for my purposes.

I presume i could push my new file to the device, but what i am not sure about is what directories i can place this file so that it can execute, from my research i have found a few directories but get permission errors when trying to push to them.

There is another question that was asked that related allot to what i want to do. but how to add the new tool was not explained for reference it is here.


edit

Or if anyone knows a way of replicating a complex drag without sacrificing accuracy, on a non-rooted device?

My original idea was to remove every other set of co-ordinate events which works, but is not as accurate and timings need allot of fine-tuning.


compiling note

for anyone else interested in how to do this.

I have just compiled and ran a hello world test, the instructions i found were on this question:

here is a copy of the answer if the link becomes invalid (my test modified the test-libstdc++ sample as it is more lightweight):

Last tested with NDK r8e on Linux and Nexus 4 with adb from SDK Platform-Tools Rev 18 on Windows 7 (latest as of 2013-07-25) without root access.

  1. Go to $NDK_ROOT (The topmost folder of NDK zip when unzipped).
  2. Copy $NDK_ROOT/samples/hello-jni directory as $NDK_ROOT/sources/hello-world.
  3. Go to $NDK_ROOT/sources/hello-world.
  4. Edit AndroidManifest.xml to give the application an appropriate name (This is optional).
  5. Go to $NDK_ROOT/sources/hello-world/jni. This is where the source code is.
  6. Edit hello-jni.c, remove all the code, and put in your hello world code. Mine is:

    include

    int main( int argc, char* argv[]) { printf("Hello, World!"); return 0; }
  7. Edit Android.mk and change the line include $(BUILD_SHARED_LIBRARY) to include $(BUILD_EXECUTABLE). You can also change the LOCAL_MODULE line to the name you want for your executable(default is hello-jni)
  8. Go back to $NDK_ROOT/sources/hello-world
  9. Run ../../ndk-build to create the executable.
  10. Copy it from $NDK_ROOT/sources/hello-jni/libs/armeabi/hello-jni to /data/local/tmp on the Android device and change it's permissions to 755 (rwxr-xr-x). If you changed the LOCAL_MODULE line in $NDK_ROOT/sources/hello-world/jni/Android.mk, the executable name will be the new value of LOCAL_MODULE instead of hello-jni. (All this is done via adb from the Android SDK.)
  11. Execute the binary with full path as /data/local/tmp/hello-jni, or whatever you named it to.

And you're done( and free to start on the documentation in $NDK_ROOT/docs to get a better idea of what to do).

Was it helpful?

Solution

The way I solved it in the question you referenced was by using adb push local_path remote_path and the remote directory I used is /data/local/tmp/ which requires no root permissions. To push a thing you just need to compile it locally and send push it. You can then run in on the device using adb shell absolute_path_to_script

To recap. If you want to make a custom script from a android/adb C source, you need to:

  • compile it (lets say you get my_script)
  • don't forget to make it an executable with chmod a+x my_script
  • push it to the device adb push my_script /data/local/tmp/my_script
  • run it form the device adb shell /data/local/tmp/my_script

Now to answer your other question about dragging, I ended up making my own custom sendevent script that takes a local file (from the android device), reads events line by line and sends them to the driver.

Here's the script http://pastebin.com/LWWiNA6U

It takes 3 arguments,

  • the file_input,
  • the file_output - this is specific to every device, you need to check and see where do you need to write the raw binary data to emulate touch events. For the devices I used: /dev/input/event5 (for the HTC One M7) and /dev/input/event2 (for the Galaxy Note 8)
  • and the sleep_time - delay between every touch event being sent to the driver

Hope it helps

EDIT: Oh and btw, this is example input. It's standard converted from getevent as far as I remember

0003 0039 4a
0003 0035 1cc
0003 0036 3a2
0000 0000 00000000

0003 0035 250
0003 0036 426
0000 0000 00000000

0003 0035 250
0003 0036 4aa
0000 0000 00000000

0003 0035 149
0003 0036 3a2
0000 0000 00000000

0003 0035 c5
0003 0036 3a2
0000 0000 00000000

0003 0039 ffffffff
0000 0000 00000000
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top