Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like apps to be updated automatically when my phone is plugged in (charging) and on wifi. I can easily allow auto-update only when wifi is on with the appropriate option in the Play Store settings, but not prevent auto-updates from occuring if the phone is running on battery.

This is causing an unecessary battery drain when I am using my phone on wifi at home. Given that auto-updating apps is more a daemon job than a time critical task, I cannot believe it is not a standard power saving strategy.

Do you know any apps or system workaround (including if the device is rooted) to achieve this?

share|improve this question

Note:

Following solution:

  • is tested on Android 4.2.1, COS12 (Android 5.0.2) and CM12.1 (Android 5.1.1) - all of them running Play Store v6.0.51
  • requires a rooted Android
  • here is a short demo of the solution

While browsing the manifest of Play Store, I took an educated guess that only the following service is likely the initiator of auto-update of apps over Wi-Fi.

com.google.android.finsky.autoupdate.ReschedulerUsingAlarmManager$CheckWifiAndAutoUpdate

I played with that service under few conditions on different devices and found it useful for the goal in question. It goes without saying that the auto-update setting of apps should be set to "Auto-update apps over Wi-Fi only" in Play Store.

Here is what you can do: Install an app which can execute series of actions when power source and Wi-Fi are connected and later on, disconnected. I used Tasker (trial version; userguide) as the automation app.

We would be needing two tasks: an entry task and an exit task. See my answer here for related help.

  • Enter task: (Actions):

    1. Code → Run Shell

      • Command:

        pm enable com.android.vending/com.google.android.finsky.autoupdate.ReschedulerUsingAlarmManager\$CheckWifiAndAutoUpdate;
        am force-stop com.android.vending;
        am startservice com.android.vending/com.google.android.finsky.autoupdate.ReschedulerUsingAlarmManager\$CheckWifiAndAutoUpdate
        
      • tick Use Root
    2. You may optionally add one or more actions to notify yourself that the update procedure has begun. I used Alert → Flash to notify myself via a toast.
  • Exit task: (Actions):

    This task requires Busybox's applets installed. See How do I install missing command line tools onto an Android device? for related help.

    1. Net → Test Net

      • Type: Mobile Data Enabled
      • Store Result In: %Mdata
    2. Code → Run Shell

      • Command:

        svc data disable;
        svc wifi disable;
        am force-stop com.android.vending;
        am force-stop com.android.providers.downloads;
        down_path=$(content query --uri content://downloads/my_downloads --projection _data --where "notificationpackage='com.android.vending'");
        [[ "$down_path" != "No result found." ]] && echo $down_path | sed 's/.*=//g' | xargs rm -f || echo continue;
        content delete --uri content://downloads/my_downloads --where "notificationpackage='com.android.vending'"
        pm disable com.android.vending/com.google.android.finsky.autoupdate.ReschedulerUsingAlarmManager\$CheckWifiAndAutoUpdate;
        svc wifi enable;
        [[ "%Mdata" == "yes" ]] && svc data enable || echo doing nothing;
        
      • tick Use Root
    3. Again, to notify yourself, use any action of your choice.

What does those tasks do?

When the conditions for both the contexts are met, the enter task is run. The commands in that task does these things in sequential order:

  • enable the aforesaid Play Store's service
  • force-stop Play Store
  • start the said Play Store's service

And that's all for the auto-update to begin.

After remaining activated, whenever the profile deactivates (simply because a condition for a context doesn't meet anymore) the exit task would run. That exit task executes following steps in sequential order:

  • store the state (enabled/disabled) of mobile data in a variable Mdata
  • the job of those commands is to:

    • disable mobile data
    • disable Wi-Fi
    • force-stop Play Store
    • force-stop Download Manager

    I noticed that if an update (download in progress) for an app is interrupted due to unavailability of Wi-Fi, the progress bar (notification) is dismissed, the status of the progress gets stored in a row in the table downloads of database downloads.db. (That database is located under the data directory of Download Manager.) That row also contains the location of the partially downloaded file.

    In order to make sure that auto-update doesn't occur on the next successful connection to Wi-Fi and making sure that it never does so when the profile is not running the enter task, following is what rest of the commands do:

    • extract the location of the partially downloaded file from the value in the column _data corresponding to a row identified by com.android.vending as notificationpackage. We aim to delete that file. This is a small sacrifice to make.
    • if there is indeed a file path under _data, then use it to delete the file pointed by it.
    • delete that row, otherwise, it will be read by Download Manager when network connectivity changes (reconnected to a Wi-Fi) and auto-update would begin again.
    • disable the aforesaid Play Store service so that auto-update never begins on it own
    • enable Wi-Fi
    • enable mobile data, if it were enabled prior to running this task.

1At the time of creating the first revision of this answer the current Play Store version is definitely not 6.0.5 but above. However, none of my devices have received any further Play Store update so far.

share|improve this answer

The closest I've come is combining two settings. I do this on two devices, one running Android 4.4.4 (KitKat) and another running Android 5.0.2 (Lollipop).

  • System Settings → Wi-Fi → Advanced → Keep Wi-Fi on during sleep → Only when plugged in
  • Play Store → Settings → Auto-update apps → Auto-update apps over Wi-Fi only

It seems to pick up updates at least a little more often when it's plugged in. It's not perfect, but it's not a bad half-solution, and it doesn't require Tasker or rooting.

share|improve this answer

This can be achieved using Tasker (Paid App). In Tasker, the Profile can defined having the following conditions. It have little learning curve, but this App can replace almost many apps.

Below is the sample profile,

When Battery > X% And Wifi is ON and Charging is enabled

Enable Auto Sync On

This is just the sample one, you can specify the condition based on your requirement. Since this is a seperate topic, i would encourage you to google tasker in xda forums.

share|improve this answer
2  
Wouldn't this enable/disable all auto syncing for all data? Having to manually refresh every other service just so the Play Store doesn't auto update seems less than ideal. – Mr. Buster Sep 10 '13 at 16:53

There is a ticket open now on Google Code, so hopefully this feature will be added in a future release.

https://code.google.com/p/android-developer-preview/issues/detail?id=1511

share|improve this answer
    
The issue appears to be closed with no solution being there or in the final product. – Firelord Feb 14 at 23:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.