I have some old shell scripts that needs to be executed on an android device but the command to fetch the total cpu, memory and swap usage is top. More specific it is:
top -m 1 -d 1.0 -n $duration
Now I have been looking to find a replacement for this and I found out that I can use dumpsys. The problem what I have is that I want to give a timeout like this:
dumpsys -t 20 cpuinfo
I checked this site: https://developer.android.com/studio/command-line/dumpsys.html but didn't find out why this doesn't work. Even when I try the help I get the same error
dumpsys --help
Can't find the service: --help
Does someone know what is going on? My current android version is 6.0.1 if this is important.
Thanks in advance!
It is true that dumpsys --help does not work. I think there is a mistake in their document. However, below works:
# adb shell dumpsys input
# adb shell dumpsys -l
Add permission on your manifest "android.permission.DUMP".or
There's another (hacky) way to access dumpsys without rooting your device - through adb shell.
This will require allowing USB debugging, and finding the port of the adb service.
Enable USB debugging on your device. This option is found under Settings -> Developer Options.
Connect your device to a PC, and run the following command from the PC's shell/command line: adb tcpip 12345. Then, from your devices shell, issue the command adb connect localhost:12345 from your application. You can now disconnect the device from USB. Alternatively, you can scan the ports on your device one by one without USB connection, using adb connect localhost: and find the port adb service is listening to.
Authorize USB debugging from the pop up confirmation dialog, if prompted. Check the "always" checkbox to do not require this step again.
Now, when you have access to the adb service, use adb shell dumpsys ... from your application code to get whatever service dump you need.
Related
I am trying to find device RAM (512 MB or 1GB) using adb shell commands.
Following commands giving more details about the free,used & total memory. But how to find the device overall RAM?
adb shell "cat /proc/meminfo"
adb shell dumpsys meminfo
adb shell procrank
So it looks to me that MemTotal is probably the field you are looking for:
MemTotal — Total amount of physical RAM, in kilobytes.
While it is not the strictly Android, another Linux flavour CentOS provides the following page regarding /proc/meminfo. It seems that Red Hat, and other variants also describe it similarily.
Is there something that is making you suspect that this is not the physical RAM? On my device the value reported for MemTotal matches what I expect.
People who post answers often forget that Windows users don't have access to grep, cat, etc. Add shell to the beginning of your pipe.
.\adb.exe -s whichever-device shell "cat /proc/meminfo | grep MemTotal"
This is assuming you're connected to multiple devices. If you're only connected to one, you can remove -s whichever-device (usually the ip if you're connected by wifi or the device number from the device list if connected by wire.).
I have an LG watch which I can connect directly to my developer machine using USB and therefore can use the following command to take screenshots:
adb shell screencap -p /sdcard/screenshot.png
However my Moto 360 watch doesn't have a usb connection and thus I have to connect it using bluetooth going via its paired handset. This means there are always two devices connected to adb. Thus its not possible to use the adb shell command as adb doesn't know which device to apply it to. Some adb commands can have the device specied, but it doesn't look like this is possible with adb shell.
Using the Take wearables screenshot menu option in the Android Wear app isn't doing anything - it says "Screenshot request sent" but then nothing after that.
So how can I grab a screenshot of the watch? (I want to take a screenshot when there is an incoming phone call)
Enable bluetooth debugging on your wearable and setup a debugging session (described here: Debugging over Bluetooth).
You have to run any adb command in the following format:
adb -s localhost:4444 <command>
A simple
adb -s localhost:4444 shell screencap -p /sdcard/screenshot.png
adb -s localhost:4444 pull -p /sdcard/screenshot.png
should do the trick ;)
When I use ADB, my phone is recognized. However, once I enter the shell, the phone mysteriously disappears. This is weird especially because the shell lists "root#nozomi", as "nozomi" is the phone's code name.
And because it is not recognized, I can't, for example, push files:
The adb command is available both on your phone and your host/development machine. However, it is not much useful on your phone from the shell.
adb shell opens a unix command shell on your phone. Commands you enter here are executed on your phone.
When you execute adb devices in the adb shell, you ask your phone if it has any other phones connected to it via the android debugging interface. And clearly your phone tells you, that this is not the case.
Same thing holds for adb push you are asking your phone to push a file to another phone via adb. Since none are connected, you get the error message.
Try exiting the adb shell again and execute commands on the host machine instead.
Trying to configure ADB so that I can debug it via wifi, I have checked on Google but not getting proper resolution.
Tell me what to enter in port address, device ip.
Moreover setprop service.adb.tcp.port command is running when i give space between set and prop, bit confuse...
Seeking for help
I got the following article, and wanted help in the same context.
disconnect device from usb then tell it to listen on 4455
adb tcpip 4455
restarting in TCP mode port: 4455
connect to the device using a specified ip:port. my device is using wifi
adb connect 192.168.1.103:4455
connected to 192.168.1.103:4455
now do normal adb commands over tcp
adb shell
when your done, you can put it back in USB mode
adb usb
restarting in USB mode
Help me
These are commands for the shell of the android device, not for the host system.
Type adb shell to get the device's shell and then enter them. If you get back to the windows shell prompt you are in the wrong place.
However those commands may not be effective on a secured device anyway.
setprop is an Android command and is meant to be used in a terminal after su on the device (you can do adb shell setprop ... but when you adb shell stop adbd you'll loose your device connection). The easier way if already connected via USB is adb tcpip 8600 and then adb connect IP_OF_PHONE:8600 -- but this will only work if adb shell will get you a root prompt (starts with # and not $). Be aware that anyone on your wifi network can access your device!
I'm developing an application (using Eclipse + Android SDk/NDK) which uses the micro-usb port on an android phone to connect to peripherals. I am trying to connect to the ADB daemon on the phone via WiFi (tcp port 5555) so I can debug my application in Eclipse. However, I just can't get this to work.
Nothing I try actually results in the ADB daemon on the phone switching to TCPIP mode (as far as I can tell by looking at the output of getprop). The issue seems to be that I can't set the relevant service.adb.tcp.port property on the phone. The development phone I am using is an LG GT540 running CyanogenMod 7.0.0 (Android v2.3.3). Development machine is iMac running OS X Lion.
Here is some relevant information on what I have tried/confirmed/discovered:
The phone is rooted (ru.secure = 0)
Connecting to ADB via USB works fine
The adb service on the Mac is running as root (adb root)
adb shell gives me a shell with super-user access (# prompt, su, ability to edit system files etc)
adb tcpip 5555 does not complain or throw errors when run from a terminal window on the mac but does not set the service.adb.tcp.port property on the phone
setprop service.adb.tcp.port 5555 entered at the # prompt of a terminal window on the phone does not complain or throw errors but does not set the service.adb.tcp.port property
setprop persist.service.adb.enable 0 works from both Mac and phone shells (confirmed by checking ADB daemon stops and getprop returns 0 for the enable property)
setprop persist.service.adb.enable 1 works fine from both Mac and phone shells (confirmed by checking ADB daemon starts and getprop returns 1 for enable property)
The only properties on the phone relating to ADB on the phone are persist.service.adb.enable and init.svc.adbd (if ADB is running)(confirmed by getprop | grep adb on the phone)
Apps on the market that purport to 'automatically' configure ADB for Wifi (such as WiFi ADB) do not work either (tcp.port property is not set and ADB over TCP does not work)
Am I looking too hard here and missing something obvious? There are many posts and articles on the Internet relating to problems getting ADB to work over TCP but they all relate to phone rooting issues.
Is anyone able to shed some light on why I can't seem to set this particular property or suggest any other issue that may be preventing the ADB daemon from running in TCPIP mode?
You need to stop and then restart adbd on the phone for the tcp port property to take effect.
setprop service.adb.tcp.port 5555
stop adbd
start adbd
With any device (rooted or not) it really ought to be as simple as:
Connect to USB
Run adb tcpip <port>
You will see restarting in TCP mode port: <port> spit out the terminal if it worked. If you see nothing, it didn't.
The property is set for you by the daemon. Tutorials telling you to set the propery and reboot adbd are focused on code that needs to execute on-device (i.e. if you are writing an ADB over WiFi app).
However, you mentioned you are using Cyanogenmod. Doesn't CM have an "ADB over Network" setting in Developer Options (I swear it was there in CM7)? I know that their chosen port is 5555. You may be running into conflicts with that feature trying to do it manually. Probably best to use what's built into the system if it's there.
1 line to add on start of application.
setprop service.adb.tcp.port 5555 && stop adbd && start adbd
This resets adb on start!