DIY-Actions: Execute Command, Execute Root Command

Post your questions and help other users.

Moderator: Martin

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

DIY-Actions: Execute Command, Execute Root Command

Post by Martin » 11 Apr 2013 09:49

Hi,

Many interesting features available on Android can be accessed on the command line respectively by using the actions Execute Command and Execute Root Command.
The goal of this post is to collect interesting commands that extend the capabilities of Automagic (it is not the goal to create a complete Android command line reference).

Feel free to add more commands and variations of already listed commands by replying to this post. Optionally also include a link to a published flow that shows how the feature can be used.

Thanks!
Martin



:!: Not all commands work on all devices/Android versions.


Action Execute Command


Command: ps
Report a snapshot of the current processes running on the device. Use variable stdout to access the output.

Command: am bug-report
Developer options and USB debugging must be enabled. Create a bug report using all kind of system data including a screenshot and allows the data to be sent by mail after a few seconds. Device vibrates when the bug report is created and ready to be sent. This method might be useful to create a screenshot without root. The screenshot is stored in /mnt/sdcard/Pictures/Screenshot/Screnshot_<timestamp>.png




Action Execute Root Command :!: use at your own risk and have a backup ready :!:


Command: screencap -p /mnt/sdcard/test.png
Create a screenshot and store in the specified file.


Command: input text <text>
Enters the specified text into the currently focused text field or component.


Command: input keyevent <keyevent>
Newer Android devices (Android 4+) can use the name of the key event, older Android devices have to use the numeric value of the key event.
Simulates the specified keyevent. Keyevent values are available here: API doc KeyEvent and here: Simulating keypress events on Android

Simulate DPAD:
input keyevent DPAD_UP resp. input keyevent 19
input keyevent DPAD_DOWN resp. input keyevent 20
input keyevent DPAD_LEFT resp. input keyevent 21
input keyevent DPAD_RIGHT resp. input keyevent 22
input keyevent DPAD_CENTER resp. input keyevent 23

Press the Power button to turn off the display: input keyevent POWER resp. input keyevent 26
Press the menu key to pass the slide to unlock keyguard: input keyevent MENU resp. input keyevent 82
Enter a pin/pass in the keyguard and press enter: input text 1234, input keyevent ENTER resp. input keyevent 66

Command: reboot
Reboot the device. Be careful, seems a little bit too fast for a regular shutdown.


Command: reboot -p
Shutdown the device. Be careful, seems a little bit too fast for a regular shutdown.


Command: pm disable <package name>
Disable an app/package and also stops services and processes of the specified package.


Command: pm enable <package name>
Enable a disabled app/package again.


Command: am force-stop <package name>
Force-stop an app/package. Might be an alternative way to kill an app.


Command: service call activity 42 s16 com.android.systemui
Remove/Stop the statusbar/buttonbar (back, home, recents) to gain screen real estate.


Command: am startservice -n com.android.systemui/.SystemUIService
Show/Restart the statusbar/buttonbar (back, home, recents). You might need to reset your wallpaper.

syndromtr
Posts: 31
Joined: 01 Feb 2013 13:28

Re: DIY-Actions: Execute Command, Execute Root Command

Post by syndromtr » 14 Apr 2013 18:26

Execute Root command example:
dumpsys is a very detailed command which gives info about service infos:
first, try this in console:

dumpsys | grep DUMP

you'll get services list that you can diagnose.. examples:

dumpsys battery : to get voltage and temperature
dumpsys appwidget : (better use this command like this at first = dumpsys appwidget > /mnt/sdcard/1.txt) and you can examine 1.txt
all available widgets, and which commands are executed on those widgets..

dumpsys statusbar : read the status bar and status bar notifications !

pilusona
Posts: 39
Joined: 02 Dec 2012 03:47
Location: India

Re: DIY-Actions: Execute Command, Execute Root Command

Post by pilusona » 25 Jun 2013 04:48

Hi,
For older versions of Android (I have checked with 2.3.6), keyevent with event name as text is not working, like

input keyevent DPAD_DOWN

instead you should pass numeric values, like

input keyevent 20

You can find the list of numeric values associted with the corresponding texts here:

http://thecodeartist.blogspot.in/2011/0 ... evice.html
Samsung Galaxy Note 8
Android 9.
Non-rooted

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: DIY-Actions: Execute Command, Execute Root Command

Post by Martin » 26 Jun 2013 19:17

Hi pilusona,

Thanks for the note, updated the post.

Regards,
Martin

renatuzz
Posts: 3
Joined: 09 Aug 2013 06:25

Re: DIY-Actions: Execute Command, Execute Root Command

Post by renatuzz » 09 Aug 2013 06:33

Hi,
is there any way to switch the logging off? I use a password in the command string and i don't want to see it in the log.
Thanks Rene

renatuzz
Posts: 3
Joined: 09 Aug 2013 06:25

Re: DIY-Actions: Execute Command, Execute Root Command

Post by renatuzz » 09 Aug 2013 14:11

I've found a workaround: At the end of my flow i kill(9) the Automagic process itself by an action.
Not nice but the log is cleared in the app.

Rene

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: DIY-Actions: Execute Command, Execute Root Command

Post by Martin » 09 Aug 2013 15:11

Hi,

No sorry, the logging can not be turned off.
You could also move the command to a shell script and execute the script from within Automagic.

Regards,
Martin

renatuzz
Posts: 3
Joined: 09 Aug 2013 06:25

Re: DIY-Actions: Execute Command, Execute Root Command

Post by renatuzz » 09 Aug 2013 18:55

Thanks for your hint. But i ask for the password by an input action in AM and have to send it to the shell. And this will be always logged by the command action, isn't it.

P.S.: The disadvantage of killing AM in the workaround is that no global variables are stored at the end of the flow.

Regards
Rene

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: DIY-Actions: Execute Command, Execute Root Command

Post by Martin » 10 Aug 2013 10:00

Yes, it's probably not possible to suppress the log in this case.
I will add an entry to my todo-list to create a new action to clear the log in a future release.

Regards
Martin

govoni
Posts: 5
Joined: 02 Sep 2013 00:36

Re: DIY-Actions: Execute Command, Execute Root Command

Post by govoni » 02 Sep 2013 15:52

I'm trying to create a flow when the smartphone is shaked it will take a screenshot.

execute root command

screencap -p /mnt/sdcard/screencap.png

after I trying to rename this file to

mv /mnt/sdcard/screencap.png /mnt/sdcard/screencap_{date_hour}.png

if I don't use the variable, it works, but with the variable doesn't work....

Someone can help me?

I just try to get the trigger time from the clipboard, but no success.

Post Reply