Android is an operating system that is constantly evolving. New features are added on every release and bring improvements to various subsystems. However, it usually takes a couple of releases for a new feature to mature. Google is used to add preliminary support for a feature in a particular Android version and enhance or complete that feature in the next version, based mainly on real-world experiences. One good example is Doze mode, which first appeared in Android Marshmallow and got even better on Android Nougat. Here’s a handy tip to improve battery life on Android Nougat using BackgroundRestrictor app for Android.
The RUN_IN_BACKGROUND Permission
On Android Nougat, Google also introduced special permission, RUN_IN_BACKGROUND. It is meant to be permission used only by developers for testing purposes and this is why it is hidden from the user. Many Android hackers believe that this permission is the foundation for something bigger that will come in the future, most probably Android GO.
RUN_IN_BACKGROUND permission does one simple thing: It allows an App to continuously run services in the background or have broadcast receivers which execute code on special events, like connecting to the internet. For example, a messenger App might have a broadcast receiver that triggers syncing and fetching of messages when the user gets their device connected to the internet. While allowing Apps running code in the background helps in creating a better user experience, it consumes power and system resources. Many Apps (Facebook’s Messenger App is a great example) overuse this ability and end up destroying the user’s experience instead of enhancing it.
Fortunately for Nougat users, the Android hacker community has managed to expose the functionality mentioned above and also find a way to manipulate the RUN_IN_BACKGROUND permission. A special command given through an adb shell can remove this permission for any App. By depriving an App of this permission, it cannot do any operation unless the user actively uses it. The power of this permission becomes more evident while the device screen is on. At this time, Doze mode and other similar battery-saving mechanisms do not apply any restrictions to Apps.
RUN_IN_BACKGROUND permission does not only affect battery usage. If you disable it on Apps that work over the internet, you also will get lower internet bandwidth usage as a bonus. Furthermore, disallowing memory hogs like Messenger to run in the background might improve multitasking, especially on low-end devices.
How to manipulate RUN_IN_BACKGROUND permission
If you have your device connected to your PC, you can easily disable this permission for any App by giving the following command:
adb shell cmd appops set <package-name> RUN_IN_BACKGROUND ignore
replacing <package-name> with the App’s package name. For example, ‘com.android.calculator2’ for the calculator App.
To enable the permission, you can give the following command:
adb shell cmd appops set <package-name> RUN_IN_BACKGROUND allow
again replacing <package-name> as needed.
While the adb solution works quite well, there are several Apps available that allow manipulating this permission quickly and efficiently. A simple App made for this purpose is BackgroundRestrictor.
BackgroundRestrictor is as simple as it gets. Upon opening it, it displays a list with Apps that make use of the RUN_IN_BACKGROUND permission. You can disable or enable this permission for any App in the list by clicking the toggle button next to its name. It also includes a search function, for easily finding an App in case you have many installed. Its only drawback is that it requires root permission to work. If you do not have root support on your device, the only way to manipulate the RUN_IN_BACKGROUND permission is through adb.
BackgroundRestrictor is open source and free. You will not find it in the Play Store though. It is only available on F-Droid.