Spoofing Battery and Forcing Sleep

I wanted to do something with my Android phone using ADB commands, while keeping it plugged in to run the said commands. However, the thing I wanted to test was related to the idle (dozing or asleep) mode of Android devices. The workaround was to spoof the battery state to bypass Android’s charging restrictions.

Spoofing Battery Charging Status and Forcing Android Device to Sleep (Idle Mode)

  • Turn off the device screen using the physical power button.
  • Trick Android into thinking the device is running on battery power: adb shell dumpsys battery unplug
  • Force the device to step into deep Doze mode: adb shell dumpsys deviceidle force-idle
  • Verify the device is successfully spoofed and asleep: adb shell dumpsys deviceidle get deep (This should return IDLE).

Can also do:
adb shell dumpsys battery unplug && adb shell dumpsys deviceidle force-idle && adb shell dumpsys deviceidle get deep

Device Cleanup for Spoofed Battery and Forced Sleep (Crucial!)

  1. Once testing is done, you must tell the OS to start reading the actual battery state again, otherwise it won’t charge properly: adb shell dumpsys battery reset
  2. Bring the device out of idle: adb shell dumpsys deviceidle unforce

Can also do:
adb shell dumpsys battery reset && adb shell dumpsys deviceidle unforce && adb shell dumpsys deviceidle get deep

Related Posts:

Posts that may be related to "Spoofing Battery and Forcing Sleep":

Catzie

An odd human being who happens to have a variety of ever-changing interests, but right now they are programming, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert/drink flavors, obsessing about finding out how some things works, automation, anime, video games... Ran online dessert shops Cookies PH and Catzie's Cakery in her past life.

Leave a Reply

Your email address will not be published. Required fields are marked *