Get instant current il milliampere from Android using adb - android

I need to calculate the power consumption of an Android smartphone using adb.
I know that there is Google Battery Historian, and I also know the command:
adb shell dumpsys batterystats
But I need something different: I want to launch an app (youtube for example) using adb for 10 minutes and, using adb (wireless) I want to collect the power consumption in milliamperes every second.
I know that there is a way to get the mA, but I cannot understand how.

Related

Android - Disable Forced DozeMode or AppStandByMode

I have an application that uses a ForegroundService to send location updates to a server. Basically a tracker.
This ForegroundService has a Handler that periodically (using postDelayed) executes a block of code to send the location.
This works perfectly fine, when the app is in the foreground and even in the background, but I started to notice a delay when the phone is locked, with the screen off for about 15minutes. I mean, 15 minutes of no user activity and no charger plugged.
This is happening on a Android Q (v10) device. I'm assuming this would also happen on any device running Oreo onwards.
Let's make it clear... My app send the location every 30sec, but when entering what I suppose is the DozeMode or AppStandByMode, it continues sending the location, but every 2 minutes (more or less). If I turn the screen on, or plug-in the charger it inmediately come back to the 30sec pace. That's what makes me thing about the DozeMode or AppStandByMode. Moreover, if I leave the phone untouched, but with the charger plugged in, then this never happens.
As said, I'm pretty sure the DozeMode or AppStandByMode is kicking in, and I know I can whitelist my app to prevent that. But before going further I would like to reproduce this without the need to wait those 15minutes every time I want to test the behavior of my app.
So I "googled" how I can force this and here's what I've found:
For DozeMode (see source)
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step deep
And continue to execute the last command until reaching IDLE state.
For AppStandByeMode (see source)
adb shell dumpsys battery unplug
adb shell am set-inactive packageName true
And query the state with this other command:
adb shell am get-inactive packageName
which I confirm it returns Idle=true
I also even do as this other blog suggest, issuing:
adb shell dumpsys deviceidle force-idle
I though I was not getting in this mode, but now it seems I am and I can not get out of it... See the update
UPDATE
At first I thought I was not entering the DozeMode... Now I can confirm I'm in, but it always triggers inmediately. (no more waiting those 15min)
Whenever I lock the phone and screen goes off, it automatically enters the doze mode and begin spacing the location updates. I plug the charger and then again sends them at 30sec.
I've try:
adb shell dumpsys deviceidle unforce
adb shell dumpsys deviceidle disable
adb shell dumpsys battery reset
and still the same.
Also:
power-down and power back up the phone
uninstall the app
change battery optimization to NOT OPTIMZE inside the app settings
Did I miss a step?
Except for Doze mode, Android 9 extended the concept of AppStandby with App Standby Buckets.
Along with network restrictions, an app that is in a low priority bucket will be affected in the frequency of running Jobs, triggering Alarms, and receiving FCM messages.
You can get your app's current bucket using this command:
adb shell am get-standby-bucket your.package.name
You can set the bucket and see how your app behaves using this command:
adb shell am set-standby-bucket your.package.name <never/rare>
I wrote an article that summarizes all changes regarding background process limitations over the years: https://rotemmatityahu.medium.com/workmanager-does-it-always-manage-to-work-fd8518655052

How to exit recovery mode loop on an android phone used for development?

so i was messing with second screen app for changing resolution while mirroring
and i installed adb and added:
adb shell pm grant com.farmerbb.secondscreen.free android.permission.WRITE_SECURE_SETTINGS
and as soon as i started second screen my phone went into recovery mode and stuck in a loop where i have three options:
1-connect with mi assistant (which the software doesn't recognize my phone)
2-wipe Data but considering the fact that i haven't backup phone and i have some important data it's just impossible for me
3-is the reboot option which gets interesting cause when my phone is in this mode my device is shown in adb devices
List of devices attached
68100cf8 device
and seems like i have full access (i'm not sure)
so My Question is: is it possible to recover my data with adb or is there any other way?
in recovery mode, the adb also can be used, you can pull data from data partition if it mounted.

Battery usage info for longer than a day

I want to get battery usage data from my OnePlus 5 over a longer period (months), to keep track of how much I use my phone.
I've been playing around with adb and the batterystats dump, like so:
adb shell dumpsys batterystats > batterystats.txt
,but this data only seems to cover the data since the last charge.
Is battery usage data even stored for a longer period on your phone? Or is it reset every time you charge it? If it is stored somewhere, how would I access it?
$ adb version
Android Debug Bridge version 1.0.39
Revision 3db08f2c6889-android
From the android documentation dumpsys service. As indicated I executed the following command adb shell dumpsys batterystats -h to get the available arguments
From my experimentations, battery logs records do not last more than few days (in my case 10 days on my motorola Moto x 2nd gen). You may have to plug and log the phone more often than each month
As printed by the -h argument you can use enable no-auto-reset by doing adb shell dumpsys batterystats enable no-auto-reset
no-auto-reset: don't automatically reset stats when unplugged
but you have to do it after each boot as indicated by the command
Option state is not saved across boots.

All ADB devices offline when starting adb at boot

I'm testing an application which records user travels for later review. One part of testing involves testing application behavior when under user specified battery level.
It must stop recording to save battery. I have built a system with a raspberry pi that when you flip a switch, adb commands are sent to all connected devices to mock battery status.
My issue is when I tried to have adb as startup or as a service it, adb list all device offline thus the device doesn't work. My script will work as long you start manually the adb server.
More info:
It is the cold season here so we use a car to record travels. We can't have a screen on the device to comply with local regulations that is why, I require the adb to start at boot or during account automatic login.
Can anyone help me on this issue?

How long does an App need to be idle for App Standby to kick in (Android Marshmallow)

I've looked all over the internet to find specifics about App Standby mode in Android Marshmallow, but I've not found any specific data for when it happens, other than some listed conditions that might cause it to happen. I also see a nebulous "If the device is idle for long periods of time, the system allows idle apps network access around once a day" without any specifics about how long this window would be.
Doze mode seems pretty well researched (This gist was particularly helpful and consistent with my findings), but I haven't been able to see App Standby in action. I created a test app that sends data to a server every 5 minutes via an Alarm and ran it for a week, and it continued to hit the server every 5 minutes unless the phone went into Doze mode and only hit the server in maintenance periods, then go back to every 5 minutes when the phone was awoken, so it did not appear that Android ever put it in "App Standby" state even though I didn't directly interact with the app.
Is there any specific data on how App Standby works?
You can force the device to enter this mode using the code below:
adb shell dumpsys deviceidle enable
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step
adb shell dumpsys deviceidle force-idle

Categories

Resources