Have you ever went to sleep at night with a completely charged phone, just to wake up with a low battery? Don't worry, it has happened to all of us. Even with Doze mode and all Google's efforts to improve battery life on Android, idle battery life isn't exactly ideal. Especially if you have lots of apps installed. The culprit is most probably a misbehaving wakelock from an app like Facebook, Messenger, Snapchat, you name it. Luckily, you can easily stop these wakelocks using simple shell commands. And you don't even need root for that! Today, we'll show you how you can stop wakelocks from any Android app without using root. This can be done on every Android phone, as long as you got ADB.


Stop Wakelocks from Any Android App

Video tutorial from our YouTube channel in case you prefer a visual aid

Before starting with anything, you're going to need to set up ADB on both your phone and your computer. If you haven't done it yet, please refer to this tutorial in order to set yourself up.

Unless you're completely sure of what's draining down your battery, we're going to use a small tool called "Better Battery Stats" in order to find the culprit. The developer is active on our forums, so you can find the app here. However, if you would like to support the developer, you can also download it from the Google Play Store, where it's a paid application. It provides many other statistics such as CPU states, app wake-ups, and network info.

BetterBatteryStats Developer: Sven Knispel
Price: 1.99
4
Download

It requires root on devices with Android KitKat and up, however, there's an ADB command workaround that exists for unrooted devices. Connect your device to your computer, either through USB debugging or WiFi debugging. Make sure it's connected by using the command:

        adb devices
    

Then, we're going to start the Android shell using the following command:

        adb shell
    

Afterwards, we're going to grant the just-installed BetterBatteryStats the BATTERY_STATS permission with:

        pm grant com.asksven.betterbatterystats_xdaedition android.permission.BATTERY_STATS
    

Done! Now BBS will work on your unrooted device.

Note: if you purchased Better Battery Stats from the Google Play Store, then change "com.asksven.betterbatterystats_xdaedition" to just "com.asksven.betterbatterystats" in the above ADB command.

Finding the Culprit

You have many applications on your phone, so there is no easy way of telling for sure what's eating up your battery. That's why we're using Better Battery Stats to find the responsible wakelock. After setting up the app, charge up your phone then unplug it and leave it alone with the screen off for at least 30 minutes. This should give the app plenty of time to register everything. Once inside the app, select Partial Wakelocks, and see what application is causing the most damage.

Stopping the Wakelock

Now that we know what's eating up your battery, we can put a stop to it. In our case, it's Snapchat. Whatever your culprit is, be sure to find the package name of the application using Package Name Viewer from the Play Store, because we'll need it for our ADB command below.

Package Name Viewer 2.0 Developer: csIng
Price: Free
4.4
Download

As you obviously disconnected your phone to use Better Battery Stats, plug it back to your computer to use ADB again. Once again, check if it's properly connected with

        adb devices
    

And enter the shell using:

        adb shell
    

Now, using your target app's package name, send the following command:

        cmd appops set com.android.application WAKE_LOCK ignore
    

Of course, you're going to switch up "com.android.application" with your application's package name. In my case:

        cmd appops set com.snapchat.android WAKE_LOCK ignore
    

If you've done all steps correctly, all wakelocks requests by the app will be ignored by the Android system. Congratulations!


Explanation

A wakelock, in layman's terms, is just a way for an app to keep the CPU/screen/other things awake when the phone is idle in order to perform a specific background task. Some apps do legitimately need wakelocks in order to function properly, but the problem comes when some applications hold wakelocks repeatedly, hold them for a long time without dropping them, or do excessive/unnecessary network and CPU tasks taking advantage of these wakelocks.

Case in point: apps like Snapchat, Facebook, Messenger or other social media apps include misbehaving wakelocks. This tutorial is simply a way to stop these wakelocks from happening again without uninstalling the app. If, however, you notice that the app stops functioning correctly after using this ADB command, you can change things back to the way they were by re-running the command and changing "ignore" to "allow", or by simply uninstalling then re-installing the app again.