Mobile Development 8 min read

Guide to Reducing Android Device Power Consumption and Preventing Shutdown During Automated Testing

This guide explains how to lower Android device power usage and avoid unexpected shutdowns during large‑scale automated testing by controlling battery thresholds, adjusting screen brightness, terminating background apps, setting screen timeout, synchronizing time, and managing audio settings through ADB shell commands.

360 Tech Engineering
360 Tech Engineering
360 Tech Engineering
Guide to Reducing Android Device Power Consumption and Preventing Shutdown During Automated Testing

During daily automated testing many Android real devices are used, and devices often run out of battery and shut down, which greatly increases operational costs. This article describes two main strategies: reducing device power consumption and preventing power‑off shutdowns.

1. Control device battery levels to avoid shutdown – Define a low‑level threshold (20%) and a normal level (60%). Devices below the high threshold do not accept new tasks, and tasks are interrupted when the battery falls below the low threshold. When the battery rises above the normal level, the restrictions are lifted.

Battery information can be obtained with the shell command adb shell dumpsys battery , where the level field shows the current charge percentage.

~$ adb shell dumpsys battery
Current Battery Service state:
  AC powered: false
  USB powered: true
  Wireless powered: false
  Max charging current: 0
  Max charging voltage: 0
  Charge counter: 37000
  status: 5
  health: 2
  present: true
  level: 100
  scale: 100
  voltage: 4358
  temperature: 300
  technology: Li-poly

2. Reduce device power consumption and improve utilization

• Screen brightness : Set the brightness adjustment mode to manual (0) to prevent automatic changes, then adjust the brightness value (0‑255) with settings put system screen_brightness . Example commands:

# Set manual brightness mode
settings put system screen_brightness_mode 0
# Get current mode
settings get system screen_brightness_mode
# Get current brightness
settings get system screen_brightness
# Set brightness to 150
settings put system screen_brightness 150

• Close third‑party apps and lock screen after tasks : List installed third‑party packages with adb shell pm list packages -3 and force‑stop each app using adb shell am force-stop .

$ adb shell pm list packages -3
package:com.sankuai.meituan
package:com.tencent.mm
package:com.liuzh.deviceinfo
package:com.ct.client

adb shell am force-stop com.ct.client

3. Set phone state to reduce task failures

• Set screen off timeout to 30 seconds:

adb shell settings put system screen_off_timeout 30

• Enable automatic time synchronization:

adb shell settings put global auto_time 1

• Adjust system volume via reflection to obtain IAudioService and call its methods. The process includes retrieving the service, getting the current ringer mode, and setting the desired mode and stream volumes.

Method getServiceMethod = Class.forName("android.os.ServiceManager").getDeclaredMethod("getService", String.class);
IBinder binder = (IBinder) getServiceMethod.invoke(null, "audio");
Method asInterfaceMethod = Class.forName("android.media.IAudioService$Stub").getMethod("asInterface", IBinder.class);
IAudioService iAudioService = (IAudioService) asInterfaceMethod.invoke(null, binder);
int mode = iAudioService.getRingerModeExternal();
// Set to normal ringer mode
iAudioService.setRingerModeExternal(AudioManager.RINGER_MODE_NORMAL, "com.android.settings");
// Set stream volume
iAudioService.setStreamVolume(streamType, volume, 0, null);

Note: On some Huawei devices (e.g., version 9.1.0.226) setting the ringer mode may throw a SecurityException due to missing android.permission.STATUS_BAR_SERVICE permission.

For further reading, see the linked articles on real‑time big‑data computation, common authentication schemes, and bare‑metal server deployment.

Androidmobile testingpower managementBattery OptimizationDevice AutomationShell Commands
360 Tech Engineering
Written by

360 Tech Engineering

Official tech channel of 360, building the most professional technology aggregation platform for the brand.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.