0

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:

image description

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.)

16
  • 1
    Whatever you use to execute that shell script does not have the appropriate permissions to open the 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
    Commented May 26, 2016 at 23:00
  • @GiantTree Well it cannot be resolved the way you propose, because my device is not rooted. Does bold text display properly on your device? Solution I'm looking for is somehow connecting to the adb service on my device to send those commands there, since as you correctly say my used doesn't have access to the required resources. Commented May 26, 2016 at 23:05
  • I saw that you don't have a rooted device. This does not mean that those permissions are not required on your device. Ideally a permissive kernel would suffice, because on my device, that exact file you posted runs perfectly without any errors.
    – GiantTree
    Commented May 26, 2016 at 23:09
  • I don't understand now. Are you saying the permission can be obtained without having rooted device? Commented May 27, 2016 at 0:11
  • Sorry, I try to explain: There are 2 modes a kernel can be in: enforcing (locked down, high security) and permissive (somewhat open, medium security). Most/all devices ship with enforcing-only kernels. To get the needed permissions you need to either root your device and run the commands in a root context (after su) 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
    Commented May 27, 2016 at 0:14

2 Answers 2

1

Adb is a two-part system, the "ADB" command that runs on your computer, and a daemon that runs on the device to receive the commands you send to it.

To run it on the device you need a version of ADB that is compiled to run on the device. There are several of these on the play store (Search "Adb Shell") on Google Play, such as Adb Shell.

There is also an "ADBLib" by Cameron Guzman on GitHub that can be compiled into an Android App and allow run Adb Shell commands from there.

0

on a rooted phone you can do this by download linux deploy termius and any adb over wifi app on the play store all you have to do is set up linux deploy on Debian with root as the user name and ssh access. connect to it with termius run sudo apt-get install adb when that finishes turn on the adb over wifi app go back to termius adn type adb devices it should come up with emulator-5554 device during this prosess it may ask you to athenticate the rsa key just say yes ass well as tick the box that says always then you can run your adb commands

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .