I made a simple shell (actually windows batch) script that automates a task on android phone. It can be ran on any computer. I thought that if I convert the batch to linux sh
script, I could issue the commands without adb shell
before them.
So this (.exe
added for clarity):
adb.exe shell sleep 1
becomes this:
sleep 1
Well it works with sleep
in particular, but not with sendevent
. I made a script to press and release focus button:
#!/bin/sh
# Simply send two key events to see if it works (spoiler: it doesn't)
sendevent /dev/input/event0 1 212 1
sendevent /dev/input/event0 0 0 0
sleep 1
sendevent /dev/input/event0 1 212 0
sendevent /dev/input/event0 0 0 0
But I cannot execute the sendevent
commands:
That's ridiculous. Obviously my phone is capable of executing the commands from external source, so why the hell not from itself? Am I going to need a computer to work with the shell?
What can I do to issue adb commands to my own phone? (I am not using rooted device. Android developers made it too much painful to achieve.)
event0
device file. This has nothing to do with whether or not you can execute a command. This is special to that single command and can be solved by requesting appropriate permissions (root permissions in that case). – GiantTree May 26 '16 at 23:00su
) or by flashing a custom kernel compiled for permissive mode (most of which root your device or need root for management anyway). There might be another way around your issue, if so, please open a new question stating what you want to achieve. – GiantTree May 27 '16 at 00:14adb
client, so you can't connect back to yourself. I get what you try to achieve. My idea was, that what you try to achieve with arbitrary commands, might be possible without using those input commands. Remember thatadbd
(the ADB daemon on the device) runs with system permissions but does not carry them on to child processes, that's why you can run commands fromadb
but not from within a shell script. – GiantTree May 27 '16 at 01:08adb
on the phone and make it connect to itself, you will not be able to access that event0 device. This is because the file is owned by root and is readable and writable only by user root and group input. Any other user can do absolutely nothing, and there is no way to circumvent the issue, but root your device. – Grimoire May 27 '16 at 09:19adbd
from PC and from the phone itself? It's still the same process, isn't it? Please can you explain it more or give me some links? – Tomáš Zato May 27 '16 at 09:36sendevent
command from your computer viaadb
? – Grimoire May 27 '16 at 09:39adb
daemon service. – Tomáš Zato May 27 '16 at 09:43adbd
to listen aresetprop service.adb.tcp.port 5555
, followed by astop adbd
andstart adbd
. Only then you'll be able toadb connect localhost:5555
and finally get your device connected to itself. – Grimoire May 27 '16 at 09:57