android adb - how to set emulator to ac power - android

In an effort to test doze and standby mode im trying to change the battery level and also the set to ac etc using adb and a api 23 emulator.
But when i run the following bash command:
adb shell dumpsys battery set level [95]
i get the following error:
Bad value: [95]
also when i run :
adb shell dumpsys battery set [ac]
i get the following error:
Dump current battery state, or:
set [ac|usb|wireless|status|level|invalid] <value>
unplug
reset
i am assuming meaning it could not find the ac command. How can i change the emulator to ac and also update the battery level ?
update: there is a command adb shell dumpsys battery unplug
to unplug the emulator so should there not be a command to plug it in for AC power ?

there is a command adb shell dumpsys battery unplug to unplug the
emulator so should there not be a command to plug it in for AC power ?
Yes, the command is:
adb shell dumpsys battery set ac 1
To change the level of the battery you can use this command:
adb shell dumpsys battery set level 42

If you'd like to test Doze, I recommend trying the commands directly from the Developer Site here.
The commands to cycle through Doze modes are as follows:
$ adb shell dumpsys battery unplug
$ adb shell dumpsys deviceidle step
$ adb shell dumpsys deviceidle -h
And for testing App Standby:
To force your app into App Standby mode:
$ adb shell dumpsys battery unplug
$ adb shell am set-inactive <packageName> true
To simulate waking your app:
$ adb shell am set-inactive <packageName> false
$ adb shell am get-inactive <packageName>

Related

When turn on doze mode on an emulator it doesn't work

When I turn on doze mode on an android emulator using adb shell it just freeze. I cannot reboot it and emulator restarting doesn't help.
I use the following commands for turn doze mode on:
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step deep
And the following to turn it off:
adb shell input keyevent KEYCODE_WAKEUP
adb shell dumpsys battery reset

Adb Shell dumpheap for native not working

I need to take the native dump of the android process.
The cmd I am using is:
adb shell am dumpheap -n <pid> /data/local/tmp/dump.txt
The device is S8, Oreo OS.
Everytime I run this cmd, the 'dump.txt' is generated with the following content:
Native heap dump not available. To enable, run these commands
(requires root):$ adb shell setprop libc.debug.malloc 1 $ adb shell
stop $ adb shell start
Though I am doing it says and the phone is also rooted but it still gives the same content.
I am stuck. Any help would be appreciated.

adb shell "watch" command to monitor

I am trying to monitor some commands in my adb shell and I could go watch adb shell <command> but the extra time to have to connect up to the shell is killing me.
Does the Android adb shell have its own version of watch so I can monitor some commands
while true; do <command>; sleep 2; done

Unplugging the device via ADB: "can't find service"

I have to test how my app behaves in doze mode. According to the documentation, I first must make the device think it's unplugged by entering the following command in the terminal:
$ adb shell dumpsys battery unplug
However, nothing happens and it logs:
Can't find service: battery
What should I do?
There is no battery service as the log points out (this may be device specific).
Enter the following command to find existing battery related services:
$ adb shell service list | grep battery
it will result in something like this
$ adb shell service list | grep battery
88 batterymanager: [android.app.IBatteryService]
107 batterystats: [com.android.internal.app.IBatteryStats]
114 batteryproperties: [android.os.IBatteryPropertiesRegistrar]
It makes sense that to manage the battery, you should use the batterymanager.
$ adb shell dumpsys batterymanager
outputs (in case the usb charged is plugged)
Current Battery Service state:
(UPDATES STOPPED -- use 'reset' to restart)
AC powered: false
USB powered: true
then, when you type
$ adb shell dumpsys batterymanager unplug
and run the previous command again, it outputs
Current Battery Service state:
(UPDATES STOPPED -- use 'reset' to restart)
AC powered: false
USB powered: false
Which validates that you should use the batterymanager service instead of battery.

Nexus 5 won't go into doze mode using ADB

I have a Nexus 5 that won't go into Doze/IDLE mode using ADB commands from Windows. It's adb connected using USB cable and it is working for all other ADB commands. The screen is off.
C:\>adb shell dumpsys deviceidle force-idle
Unable to go idle; stopped at ACTIVE
C:\>adb shell dumpsys deviceidle enable
C:\>adb shell dumpsys battery unplug
C:\>adb shell dumpsys deviceidle step
Stepped to: ACTIVE
C:\>adb shell dumpsys deviceidle step
Stepped to: ACTIVE
C:\>adb shell dumpsys deviceidle step
Stepped to: ACTIVE
C:\>adb shell dumpsys deviceidle enable
C:\>adb shell dumpsys deviceidle force-idle
Unable to go idle; stopped at ACTIVE
First you need run this command:
> adb shell dumpsys battery unplug
Then turn off the screen (this step is crucial), otherwise the device remains in ACTIVE state.
After that run this command until the device state changes to IDLE:
> adb shell dumpsys deviceidle step
Stepped to: IDLE_PENDING
> adb shell dumpsys deviceidle step
Stepped to: SENSING
> adb shell dumpsys deviceidle step
Stepped to: LOCATING
> adb shell dumpsys deviceidle step
Stepped to: IDLE
There may be a condition which prevents the phone from going into IDLE, such as a scheduled alarm clock. Make sure there are no alarm clock apps set to go off in less than an hour of you trying to force the phone into IDLE.

Categories

Resources