The adb command dumpsys along with argument “battery” provides the current state of the battery in our android device and this command “adb shell dumpsys battery” can also be used simulate the different scenarios during the testing of the device.
$ adb shell dumpsys battery
Above command when run on our mobile provided below important information about battery.
Current Battery Service state:
AC powered: false
USB powered: true
Wireless powered: false
Max charging current: 0
Max charging voltage: 0
Charge counter: 4236000
status: 2
health: 2
present: true
level: 70
scale: 100
voltage: 4034
temperature: 311
technology: Li-ion
batteryMiscEvent: 65536
batteryCurrentEvent: 0
mSecPlugTypeSummary: 2
LED Charging: true
LED Low Battery: true
current now: 430
charge counter: 4236000
Adaptive Fast Charging Settings: true
Super Fast Charging Settings: false
FEATURE_WIRELESS_FAST_CHARGER_CONTROL: true
mWasUsedWirelessFastChargerPreviously: false
mWirelessFastChargingSettingsEnable: true
LLB CAL: 20230417
LLB MAN:
LLB CURRENT: YEAR2023M7D23
LLB DIFF: 14
mSavedBatteryBeginningDate: 0
SEC_FEATURE_BATTERY_FULL_CAPACITY: true
mFullCapacityEnable: false
FEATURE_HICCUP_CONTROL: true
FEATURE_SUPPORTED_DAILY_BOARD: false
SEC_FEATURE_BATTERY_LIFE_EXTENDER: false
SEC_FEATURE_USE_WIRELESS_POWER_SHARING: false
BatteryInfoBackUp
mSavedBatteryAsoc: 97
mSavedBatteryMaxTemp: 900
mSavedBatteryMaxCurrent: 3417
mSavedBatteryUsage: 6215
FEATURE_SAVE_BATTERY_CYCLE: true
SEC_FEATURE_PREVENT_SWELLING: false
Using “dumpsys battery” command to simulate during testing
Simulate Changing of battery level
$ adb shell dumpsys battery set level 50
Above command will set the battery level to 50% irrespective of what is the actual battery level i.e. it simulates the battery percentage to the value you want to test. This is useful during UI testing.
Once we set the battery level using above command, we can reset the value to actual charged percentage using below command,
$ adb shell dumpsys battery reset
Simulate Battery Unplugging / Removal
$ adb shell dumpsys battery unplug
Simulate Android device being removed from USB Charging
$ adb shell dumpsys battery set usb 0
Test how the device behaves under low power conditions
$ adb shell settings put global low_power
Once you have finished your testing, you can undo your manual device settings with this command:
$ adb shell dumpsys battery reset