When I excuted a commend, such as am start -W -n com.xxx.xxx/.xxActivity
I can see the content.
Starting: Intent { cmp=com.xxx.xxx/.xxActivity }
Status: ok
Activity: com.xxx.xxx/.xxActivity
ThisTime: 52
TotalTime: 71
Complete
But when I excuted a commend with su ,such as su -c "am start -W -n com.xxx.xxx/.xxActivity"
there is nothing to output, how can I get the output with su?
The standard Android su works as expected if run properly:
$ su 0 am start -W -n com.android.settings/.Settings
Starting: Intent { cmp=com.android.settings/.Settings }
Warning: Activity not started, its current task has been brought to the front
Status: ok
Activity: com.android.settings/.Settings
ThisTime: 0
TotalTime: 0
Complete
Here's an excerpt from the su.c code:
/*
* SU can be given a specific command to exec. UID _must_ be
* specified for this (ie argc => 3).
*
* Usage:
* su 1000
* su 1000 ls -l
* or
* su [uid[,gid[,group1]...] [cmd]]
* E.g.
* su 1000,shell,net_bw_acct,net_bw_stats id
* will return
* uid=1000(system) gid=2000(shell) groups=3006(net_bw_stats),3007(net_bw_acct)
*/
Related
im trying to create bash script to install split APKs manually with adb shell
that requires to get session id using the command bellow
command
SESSION='pm install-create -S 42211368'
this will output something like : Success: created install session [547376362]
547376362 will be the session ID
I want to pass 547376362 into SESSION Variable
sh < pm install-write -S 24628703 ${SESSION} 0 /sdcard/YTAPKM/base.apk
so result shall be "sh < pm install-write -S 24628703 547376362 0 /sdcard/YTAPKM/base.apk"
grep is sufficient for this.
SESSION=$(pm install-create -S 42211368 | grep -oE '[0-9]+')
sh < pm install-write -S 24628703 ${SESSION} 0 /sdcard/YTAPKM/base.apk
To explain what's happening a bit:
grep -E uses "extended" regular expressions (easier to work with)
grep -o outputs only the matching part, the integer in this case
SESSION=$(some_cmd) stores the stdout from some_cmd to the variable SESSION, and allows for pipes and such too
I want to debug android's so file. I use start an Activity: am start [-D] [-W] to start activitey.
the applicationg package name is com.dualboot.apps.springzen . the main activity is com.dualboot.apps.springzen.Main$Activity . i use command
'adb shell am start com.dualboot.apps.springzen/com.dualboot.springzen.Main$Actinity'
it's not exist
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.dualboot.apps.springzen/com.dualboot.springzen.Main }
Error type 3
Error: Activity class {com.dualboot.apps.springzen/com.dualboot.springzen.Main} does not exist.
how to start this activity
Since you are calling a component you need to include the component -n option tag.
Use this:
adb shell am start -n com.dualboot.apps.springzen/.MainActivity
if you actually have the $ in your class name (I doubt it) which usually refers to an inner class then you need to use:
adb shell am start -n com.dualboot.apps.springzen/.Main\$Activity
When bash (or other shell) fails to guess the correct column count on your terminal, it gets inconvenient to edit long lines.
For usual Linux systems, there is script termsize that automatically fixes the terminal size. But typical Android does not have Python, so termsize can't work.
How do I fix the terminal width in adb shell?
This snippet can assist you for setting up column count:
echo "\033[18t"; { sleep 1; echo -n "COLUMNS="; } & grep -m 1 -o '[0-9]*t' | { sleep 2; grep -m 1 -o '[0-9]*'; }
Usage:
Open adb shell;
Insert the snippet into command line;
Execute it (press Enter) and immediately press Enter again.
Wait for 2 seconds: it should print COLUMNS= after 1 second and the columns count after another 1 second;
Copy COLUMNS=NNN into console and press Enter yet again.
Example session:
$ adb shell
9]*t' | { sleep 2; grep -m 1 -o '[0-9]*'; } <
[1] 17212
^[[8;38;149t
COLUMNS=149
[1] + Done { sleep 1 ; echo -n "COLUMNS=" ; }
shell#hwH60:/ $ COLUMNS=149
shell#hwH60:/ $
When using 'adb pull ...' the output is sent to stderr regardless of success. Is there any reason for this? For an example, pulling a file that is there and pulling a file that doesn't exist:
When I run:
adb pull /data/data/good_file.txt /tmp`
I get the following:
stdout:
stderr: 0 KB/s (13 bytes in 0.078s)
(i.e. no stdout)
Then when when I run:
adb pull /data/data/bad_file.txt /tmp
I get the following:
stdout:
stderr: remote object '/data/bad_file.txt' does not exist
The program below was used to generate the above results:
from subprocess import Popen
cmd = "adb pull /data/data/good_file.txt /tmp"
p = Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print cmd
print "stdout: " + out
print "stderr: " + err
I have the same issue with: adb install -r /foo/bar.apk and sound like adb always send his result to stderr, just add 2>&1 at end and it solves the problem.
cmd = "adb pull /data/data/good_file.txt /tmp 2>&1"
The 2>&1 just redirects Channel 2 (Standard Error) and Channel 1
(Standard Output) to the same place which in this context is Channel 1
(Standard Output), and thence your log file.
I am trying to get the output of a WLAN driver control interface via adb shell on a motorola droid 2. The command is called wlan_cu. To run the command,I am using:
% wlan_cu -itiwlan0 -s /data/jay/stat.sh
Connection established with supplicant .../Connection> Bssid_list,
Connect, Disassociate, Status, Full_bssid_list, wPs/
Status : DISCONNECT MAC : f8.7b.7a.7b.b7.9b SSID : <empty>
BSSID : 00.00.00.00.00.00
Channel : <empty>
Driver/, Connection/, Management/, Show/, Privacy/, scAn/, roaminG/, qOs/, poWer/, eVents/, Bt coexsistance/, Report/, dEbug/, biT/, aboUt, Quit
[1] Segmentation fault wlan_cu -itiwlan0 -s /data/jay/stat.sh
The -s option is to read wlan_cu commands from a script.
% cat /data/jay/stat.sh
c s
/
q
If I try to redirect the output i.e.
% wlan_cu -itiwlan0 -s /data/jay/stat.sh &> out.txt
out.txt is created, but empty and the output still goes to screen. Anyone have an idea? been stuck on this for quite a while.
you can try to redirect both stdout and stderr to the out.txt. Try this,
# wlan_cu -itiwlan0 -s /data/jay/stat.sh > out.txt 2>&1