API glitch may explain fast-draining phone batteries

Almost a quarter of apps that contain Android’s explicit power control APIs, or wakelocks, may have major battery-draining bugs.

Purdue University researchers say that this new class of smartphone software glitches, which they term no-sleep energy bugs, can entirely drain batteries while the phones aren’t in use.

“These energy bugs are a silent battery killer,” says professor of electrical and computer engineering Y Charlie Hu. “A fully charged phone battery can be drained in as little as five hours.”

Because conserving battery power is so important, the industry has adopted an aggressive sleep policy that means smartphones are always in a sleep mode, by default.

“When there are no active user interactions such as screen touches, every component, including the central processor, stays off unless an app instructs the operating system to keep it on,” says Hu.

However, various background operations need to be performed while the phone is idle, for example, a mailer needing to automatically update email by checking with the remote server.

To stop the phone going to sleep at such times, manufacturers make APIs available to app developers that instruct the phone to stay awake long enough.

“App developers have to explicitly juggle different power control APIs that are exported from the operating systems of the smartphones,” says Hu.

“Unfortunately, programmers are only human. They make mistakes when using these APIs, which leads to software bugs that mishandle power control, preventing the phone from engaging the sleep mode. As a result, the phone stays awake and drains the battery.”

What’s surprising is the scale of the problem. When the researchers studied 187 Android applications containing the wakelock APIs, 42 were found to contain errors.

“We’ve had anecdotal evidence concerning these no-sleep energy bugs, but there has not been any systematic study of them until now,” says professor Samuel Midkiff.

 

The bugs are invisible to users.

“You don’t see any difference,” says Hu. “You put it in your pocket and you think everything is fine. You take it out, and your battery is dead.”

While the researchers concentrated on Android phones, the same types of bugs appear to affect other brands too, says Hu.