Question is straight forward and simple. Is it possible to get the dumpsys information after certain point or certain user action. Not from the scratch.
There is no such thing.
Logs belong to the logcat facility. dumpsys is mostly for reporting the current state and some more advanced things. It is true that few of the Android service developers included some limited logging excerpts into their dumpsys output but virtually none of them implemented a way to clear those logs.
I realise this is a bit late but...
As per the documentation:
Connect your mobile device to your computer.
Open a terminal and type the following commands to reset the adb server:
adb kill-server
adb devices
This will list any connected devices (If you don't see any devices listed, make sure your phone is connected, and USB Debugging is turned on, and then kill and restart adb again).
Next you will need to reset battery data gathering. The device is always collecting batterystats and other debugging information in the background. Resetting erases old battery collection data. If you do not reset, the output will be huge.
In terminal use command:
adb shell dumpsys batterystats --reset
Disconnect your device from your computer so that you are only drawing current from the device's battery.
Play with your app and perform actions for which you would like data; for example, disconnect from WiFi and send data to the cloud.
Reconnect your phone and make sure it is recognized:
adb devices
Dump all battery data (This can take a while):
adb shell dumpsys batterystats > [path/]batterystats.txt
The batterystats.txt file is created in the directory you specify using the optional path argument. If you leave out [path/], the file is created in your home directory.
You can find the home directory in Android Studio by going to:
Tools > SDK Manager > Android SDK Location.
Navigate to that filepath then open the subdirectory 'platform-tools' and look for batterystats.txt.
Related
I'm using scrcpy to mirror the phone screen to computer, which uses adb.
I've followed the steps and it works:
# connect via USB
adb devices
adb tcpip 5555
# now unplug USB, and the following will work over WiFi
adb connect 192.168.1.14:5555
scrcpy
But when you reboot the phone or computer, doing adb connect 192.168.1.14:5555 and scrcpy doesn't work anymore (NB: the phone IP hasn't changed, it's fixed).
Reading the answers from Run/install/debug Android applications over Wi-Fi?, I see 3 options:
plug the USB cable each time before doing a wireless connection, but this is annoying, and somehow reduces the interest of wireless...
Use "ADB over network" (main answer's screenshot), but as noted by many people in comments: "i do not have the "ADB over network" option in debugging option"; so this option doesn't work for me
other techniques that need root (not possible for me)
Question: how to pair the phone and computer with a USB cable only once, and then be able to use adb between them without having to use a USB connection first, after each reboot?
Note: I don't use Android Studio, but only scrcpy.
It's not possible without root the phone. If your phone has rooted. You can use this app. https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb&hl=en. With this app you can easily debugs android apps with only wifi. Don't want USB cable even only first time.
Based on all the information I have the next conclusion. Just for reference, how a low-level setup with changing add routes works inside, described here. It comes up, there is a pretty straight thing inside changing navigation with adb tcpip <port>.
The first thing we need to do, it's setup system property with tcp port with name setprop service.adb.tcp.port (and values with a port number) By default, there is not such property.
And then just restart adb with few commands. stop adbd and start adbd on a device in order to debug bridge listen new port. What is the trick here, that you don't have access to this service and stop/start it without root. But it could be easily done, via Developer setting with stop/start debugging.
This few simple action hidden inside adb tcpip <port>. And the problem, that you cannot change system properties (point 1). That is why all application requires root access, it's just to change the single option. That is why, we need to connect with USB to debug bridge, which can change properties with his sepolicy.
So answering your question. I don't understand either, what is the problem or enabling this small setup in Developer options. But right now, it's possible to do so on some Roms, or devices with root access.
How to measure app power consumption when I connect my device with my pc?
I've read about batterystats from Android Studio. And I've followed the instructions and get a batterystats dumpsys. However, I can't not let my device consistently plugged on usb port because the result of dumpsys will have a missing part called "Estimated power use". Which is the most important part of the whole test because the app power consumption it contained.
I've tried using StopCharge app to interrupt phone charging. But the prerequisite is that the device need to get ROOT.
Other options like power tutor is outdated. Information out from the application can't quite fit my request(Android 6.0 or upper).
Is it possible to get the power consumption measurement of an application when it's charging or is my mind out of the roof?
Thank you in advance!
p.s the following is a sample of the method of Android Studio batterystats
Estimated power use (mAh)
Capacity: 2930, Computed drain: 43.9, actual drain: 58.6-87.9
Screen: 35.6
Unaccounted: 14.7 ( )
Uid u0a2618: 2.91 ( cpu=2.17 wake=0.657 wifi=0.00656 sensor=0.0732 )
I think when you plug, the battery stats are not very accurate.
There's two ways i usually do:
Connect the adb by wi-fi and run batterystats
In Android Studio go to preferences->Plugins and search for Wi-fi, this way you connect the device on USB, go to plugin and he do the wifi connection
Or if you don't wanna a new plugin
Run adb tcpip 5555 and adb connect 192.168.0.101:5555 if you already have usb access (More info.)
-
Use the Google Battery Historian:
In this link, download the project following the guidelines
In your adb, run adb shell dumpsys batterystats --reset to clear all the history
Use your App for some time
Go back on ADB an generate the log: adb bugreport > bugreport.txt
Then Upload the file to the Battery Historian site that you will host by following the instructions, and you are done.
Image of the Battery Historian:
Problem description:
Each time wen I connect USB cable between PC and my mobile phone the battery automatically is charged. I want to use ADB protocol but I don't want to charge my battery during ADB connection. Is it possible to to turn off this charging? And ofcourse how can I do this?
Environment:
Mobile phone with Android os 4 and higher
I need only mention that my referential device working on android 5 so there is no /sys/class/power_supply/battery/force_usb_charging file
BEWARE: adb shell dumpsys battery unplug only MOCKS the battery status. I checked with a current indicator on my usb cable and this does not change the amount of flowing current at all so the battery is still charging.
It only changes what applications think about the state, so for example google play would not start updating if you have configured that it can only update when charging...
Changing the value of a file like /sys/devices/battery.XX/power_supply/battery/hv_charger_set to 0 does really work but its a different file for every device. For example, for my yotaphone 2 with a snapdragon 805 there is a file: /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
So you could make a script that you can use in tasker(if you have root):
echo $1 > /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
if you write that to an executable file /data/setcharging.sh then you could call the script like /data/setcharging.sh 0 to disable or
/data/setcharging.sh 1 to enable.
This works, I checked with my current metering usb cable, but it does not show that it works in the battery status icon. So you could use a combination of this and adb shell dumpsys battery unplug / reset to make it look better, but the problem is that then apps like tasker don't know whether you have ac power or not, so you can not put triggers for that when you've set it to unplugged...
One more thing, I also tested what it does in recovery (twrp) and during boot. And it turns out that during boot and in recovery, the charging just works. So its not like your device will end up dead if you forget to turn on charging again. You can always charge it in recovery mode and then boot up and change the value again (or change it while in recovery if your recovery gives access to adb).
Lastly, there are apps on the play store that are made exactly for this, but I would recommend getting such a current indicating usb-cable and checking if they really do what they say and are not just mocking.
You can make the system think it is not loading th battery using
adb shell dumpsys battery unplug
Refer to this good article :
https://stanfy.com/blog/android-shell-part-1-mocking-battery-status/
Try this for rooted device:
To enable battery Charging:
adb shell dumpsys battery set ac 1
adb shell dumpsys battery set usb 1
adb shell dumpsys battery set wireless 1
To disable battery Charging:
adb shell dumpsys battery set ac 0
adb shell dumpsys battery set usb 0
adb shell dumpsys battery set wireless 0
Probably it can be done via (root privileges):
/sys/devices/battery.XX/power_supply/battery/hv_charger_set
0 - Disable USB Charging
1 - Enable USB Charging
if android os version is more than 6 use unplug and reset to revert back.
adb shell dumpsys battery unplug
adb shell dumpsys battery reset
Copied from perfetto.dev
On rooted phones the power management IC driver allows to disconnect the USB charging while keeping the USB data link active. This feature is SoC-specific, is undocumented and not exposed through any HAL. For instance on a Pixel 2 this can be achieved running, as root: echo 1 > /sys/devices/soc/800f000.qcom,spmi/spmi-0/spmi0-02/800f000.qcom,spmi:qcom,pmi8998#2:qcom,qpnp-smb2/power_supply/battery/input_suspend. Note that in most devices the kernel USB driver holds a wakelock to keep the USB data link active, so the device will never fully suspend even when turning the screen off.
I am trying to detect if the adb server is running on the Android device for part of an anti-cheating implementation for my free game.
Specifically, I want to stop use of adb shell input tap x,y, since the game is a competitive multiplayer puzzle game.
Things I have tried:
Using battery info I can detect if USB is plugged in. Well, that is also a legit use.
Using Settings.Secure or Settings.Global, I can query ADB_ENABLED, but that always returns 1 if adb is enabled. It DOES NOT take into account adb connected or not!
Querying all system services, but I cannot see anything that looks like an adb service.
At this point, I am out of ideas. Hopefully someone else knows how to do this?
You can check for running adbd process or query init.svc.adbd system property:
$ ps adbd
USER PID PPID VSIZE RSS WCHAN PC NAME
root 14947 1 4596 208 ffffffff 00019358 S /sbin/adbd
$ getprop init.svc.adbd
running
In Android the adb driver is implemented as a function of universal usb driver. You can check the (comma separated) list of currently enabled usb functions to see if it includes "adb":
$ cat /sys/devices/virtual/android_usb/android0/functions
mtp,adb
But you would not be able stop cheating while your app is running completely on the user controlled device.
I want to use my phones as a remote camera system that charges via a solar panel however I was wondering whether there is any way to turn the phone on automatically or remotely.
Thats to say, if the phone runs out of battery and turns off, is there anyway to turn it back on automatically or remotely?
If the phone is rooted, here is what you can do.
(Optional) Rename /system/bin/playlpm:
adb shell remount
adb shell mv /system/bin/playlpm /system/bin/playlpm-original
Then create a playlpm file locally and put the following:
#!/system/bin/sh
/system/bin/reboot
And push it to the target:
adb push playlpm /system/bin
Then give it a proper permission:
adb shell chmod 0755 /system/bin/playlpm
adb shell chown root.shell /system/bin/playlpm
Now, whenever phone is connected to a power supply, it is going to (re)boot automatically. That's, if its battery has drained it will boot up when a power will be available from solar panel.
Also see:
Auto Power on Android when the charger is Connected
Programmatically auto-power on the phone
Is there a way to auto-power on the phone
[root] NoMoarPowah!