Hard killing background processes on Android without root

"Hard"-killing background processes on Android without root

 

INTRODUCTION

Hibernate is a small Android utility for hibernating of background processes. Originally it uses public API method ActivityManager.killBackgroundProcesses to fulfil the task, which is a kind of "soft" killing, because the system does actually suspend and unload the killed process from memory and CPU, but may awake it at any time. Unfortunately some applications are designed in such a way, that they restart themselves just after the "soft" killing. As a result hibernation is ineffective (at least partially).

 

MAIN IDEA

As a workaround for the problem this helper has been invented and implemented. Its idea is to utilize "force-stop" command of Android activity manager. Normally, an end user invokes this command by pressing "Force stop" button in specific app properties dialog. This is a kind of "hard" killing, which provides most efficient method of hibernation.

The great challenge was to find a way to automate this interactive action on a stock (non-rooted) device. And it was done using shell scripting.

Please, note that this is just a helper - Hibernate app is still required to do the main part of the job - monitoring of background processes.

Google Play:

 

REQUIREMENTS

Android 3.0 or higher.

The solution requires a user to connect his/her device to PC, where Android Debug Bridge (ADB) must be present (specifically 'adb' executable with its libraries).

The helper setup package contains all necessary shell scripts to control the installation procedure via ADB.

If you have Android platform tools already installed on your PC, make sure they are included into PATH. Otherwise you should copy the helper scripts into the folder where ADB is located.

If you don't have Android platoform tools, you may download them here:

Before you proceed with installation, make sure you unlock developer settings on the device, and enable USB debugging in these settings. Please, find details in the official documenation:

All this routine is performed only once. The benefit of doing it is the new feature available otherwise only in rooted devices (which void a guarantee).

 

INSTALLATION

  1. Unzip the contents of the helper distribution kit in a folder from where ADB is accessible. All files have the prefix 'wuh', which is an acronym for com.Weborienteer.Utilits.Hibernate.
  2. Connect your device to PC via USB cable.

    If you connect your device to PC for the first time, Android will ask your confirmation to allow ADB connection on this step or later. You should allow the connection. Check on the option to remember authorization in order to skip such requests in future.

  3. Open command line console window in the folder with scripts.
  4. Run installation script suitable for your PC's operating system:

    > wuh_install.bat

    or

    > wuh_install.sh

  5. After the process is done (make sure there is no errors), you may close the command line window, unplug device from PC and power off PC.
  6. Open Hibernate settings on your Android device and enable "Force stop automation" checkbox in the Experimental section.

From now on and until you reboot your device, Hibernate will hibernate "insistent" background processes by forcing stop, if they refuse to sleep even after multiple calls of killBackgroundProcesses.

NB. Hibernation helper continues running until device reboot. After reboot you should repeat the installation procedure (steps 2 - 5).

 

DISCLAIMER

This is an experimental feature.

It may not work on all Android devices. If you encounter some problems, please, send a detailed report. Nevertheless there is no guarantee that every problem which may arise on a specific device can be solved.

Android is very restrictive and diversified platform.

 

TECHNICAL NOTES

The helper consists of the script file wuh_notify.sh which is installed on your device into /data/local/tmp and launched there as background process with the 'shell' user permissions. Then the script listens for notifications from Hibernate to stop specific packages. The 'shell' user has a bit more privileges than an ordinary human being using Android, but less than 'root'. That does the trick.

 

LINKS, SUPPORT, FEEDBACK

 

FINAL WARNING

Please use new feature with great caution! Carefully choose apps for hibernation. DO NOT ABUSE it by stopping core system apps, otherwise your system may hang or reboot.

 

DOWNLOAD

http://weborienteer.com/wuh.zip

15 comments:

  1. Installed the script on my SGH-I527M (stock 4.4.2 non-rooted) without any error. But the option for force-stop is still grayed out.

    ReplyDelete
    Replies
    1. I solved the issue. nohup is not available, so by removing it, service starts now.
      start /B adb.exe shell "sh /data/local/tmp/wuh_notify.sh > /dev/null 2>&1 &"

      Delete
    2. Thank you for your feedback. Yes, you're right nohup can be unavailable in some Android versions, but unfortunately without nohup the script may be killed by OS. Anyway, I'm glad if it works for you.

      Delete
  2. "Thanks" to Google, "notify" is not available anymore in Android 6+, so this method stopped working. It looks like Google watches all my attempts to fix their idiosyncrasies, and intentionally make situation even worse and worse.

    ReplyDelete
  3. Dear Stan
    Installed the helper script successfully on my Samsung Galaxy S4 i9506 OS 4.3 (non-rooted), but the option "Force Stop" automation is still greyed out. Read the comment from Reza above, but I'm unsure how / where to enter the command line to remove nohup in order to make it work. Can you help with instructions?

    Kind regards

    Fretho

    ReplyDelete
    Replies
    1. Open wuh_install.bat or wuh_install.sh file in a text editor on your PC (for the editor, it's important to preserve Linux format with single LF symbol for new line, I'm not sure if you're on Linux).

      Then just replace "nohup " mention with empty string (actually remove it). You can see example of the resulting string in the comment from Reza. Finally save the edited file and repeat installation.

      Delete
  4. Worked like a charm, thank you so much. For others having the same problem due to nohup not available, I used Notepad++ (minimalist package) to open the wuh_install.bat where I just erased nohup.

    Kind regards

    Fretho

    ReplyDelete
  5. Dear Stan

    Am now using Motorola Droid Ultra, 4.4.4 non-rooted. When scrolling down to the bottom in settings, the service mode shuts off and the experimental option of "Force stop" automation isn't available. Tried erasing nohup as I did with Samsung Galaxy S4, but unfortunately without any luck.
    Hope you can give some advice on how to activate Force stop automation.
    Your app is truly one of the most useful for those of us without a rooted device.

    Kind regards

    Fretho

    ReplyDelete
    Replies
    1. Hi, please be more specific. How the service mode is shutting off? When the service is not running, the experimental automation is disabled. Feel free to send details to my e-mail - it can become a long story.

      Delete
  6. Hi,
    Under settings: Even though service mode is set to 'On', when scrolling down to the bottom, service mode switches off as 'Experimental' comes into view, with all options being greyed out. This lasts until I scroll back up and enable service mode again, thus back where I started. Am aware that it may be a device specific issue, but still hoping for the issue to be resolved somehow.

    Kind regards

    Fretho

    ReplyDelete
    Replies
    1. Try to enable the service mode and press OK - this will apply the mode and run the service. Then make sure the shell script is running, and re-open settings again - Experimental things should be available now if all was done successfully. Again, if you have problems, please send details to my e-mail. If you have had another device (Samsung) on which the trick did work, and it doesn't work on a new device - try to find the difference.

      Delete
  7. Your download link http://weborienteer.com/wuh.zip is down. It returns a page saying...

    Application is not available
    The application is currently not serving requests at this endpoint. It may not have been started or is still starting.

    I also tried right clicking on it and saving it that way using multiple browsers like Chrome and Internet Explorer and it fails to download stating failure.

    Please help me get the wuh.zip file(s) so I can finish following your installation instructions to turn on Force Stop in your Hibernate app for my android 6.0.1 phone.

    ReplyDelete
    Replies
    1. Hi, yes, unfortunately OpenShift broke its free service some time ago, I have a post about it in my blog. I'll send the file to you by e-mail.

      Delete
    2. BTW, the blogger does not provide your e-mail, so contact me directly please.

      Delete