3

I like using battery saver on my Android phone as it greatly extends the battery. However, there is one app that I use that I would like to exempt from two of the things that batter saver disables - vibration and location services.

I'm ok with the battery usage for these on this one app only but want to restrict all other apps from using the battery.

How can I accomplish this?

4
+50

Vibration and GPS are considered as system services, not apps. Thus, it cannot be exempted on the usual setting when Battery Saver is enabled. However, since Android 8.0 Oreo, it is possible to tweak some settings for Battery Saver.

This is related to the BATTERY_SAVER_CONSTANTS global settings that can be modified through ADB.

/**
         * Battery Saver specific settings
         * This is encoded as a key=value list, separated by commas. Ex:
         *
         * "vibration_disabled=true,adjust_brightness_factor=0.5"
         *
         * The following keys are supported:
         *
         * <pre>
         * advertise_is_enabled              (boolean)
         * datasaver_disabled                (boolean)
         * enable_night_mode                 (boolean)
         * launch_boost_disabled             (boolean)
         * vibration_disabled                (boolean)
         * animation_disabled                (boolean)
         * soundtrigger_disabled             (boolean)
         * fullbackup_deferred               (boolean)
         * keyvaluebackup_deferred           (boolean)
         * firewall_disabled                 (boolean)
         * gps_mode                          (int)
         * adjust_brightness_disabled        (boolean)
         * adjust_brightness_factor          (float)
         * force_all_apps_standby            (boolean)
         * force_background_check            (boolean)
         * optional_sensors_disabled         (boolean)
         * aod_disabled                      (boolean)
         * quick_doze_enabled                (boolean)
         * </pre>
         * @hide
         * @see com.android.server.power.batterysaver.BatterySaverPolicy
         */
        @UnsupportedAppUsage
        @TestApi
        public static final String BATTERY_SAVER_CONSTANTS = "battery_saver_constants";

For the possible integer values of gps_mode:

/**
     * Either the location providers shouldn't be affected by battery saver,
     * or battery saver is off.
     */
    public static final int LOCATION_MODE_NO_CHANGE = 0;

    /**
     * In this mode, the GPS based location provider should be disabled when battery saver is on and
     * the device is non-interactive.
     */
    public static final int LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF = 1;

    /**
     * All location providers should be disabled when battery saver is on and
     * the device is non-interactive.
     */
    public static final int LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF = 2;

    /**
     * In this mode, all the location providers will be kept available, but location fixes
     * should only be provided to foreground apps.
     */
    public static final int LOCATION_MODE_FOREGROUND_ONLY = 3;

    /**
     * In this mode, location will not be turned off, but LocationManager will throttle all
     * requests to providers when the device is non-interactive.
     */
    public static final int LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF = 4;

As stated on XDA Developers, How to Customize Battery Saver Mode in Android 8.0 Oreo:

  1. Install ADB and USB drivers if necessary.
  2. Connect the Android device to the PC with USB and wait until the device is detected
  3. Open a command prompt and type adb devices to make sure the ADB detects it.
  4. Type adb shell
  5. Decide which values wanted to be changed. Inputting multiple keys are supported with comma separation. For this specific question: vibration_disabled=false,gps_mode=0
  6. Type settings put global battery_saver_constants <new_value>. Note that the change is permanent, so to undo, the user needs to manually input the opposite values instead.

On rooted devices, it is also possible to run the settings command directly from the device using terminal apps like Termux.

  • This is very helpful, thanks! I think for my use, gps_mode=3 would work well, as my app runs a service which is foregrounded for GPS events only when I tell it to run, while other apps that run in the background will get denied and not use extra battery. – Michael Apr 27 '20 at 20:43
  • I have tested this out and it works perfectly. I appreciate this this awesome answer and am going to wait to accept until I can give you some bounty points for it. :-) – Michael Apr 27 '20 at 21:09
  • After running with this for over a day, I noticed that my app had stopped producing screen off vibration when in battery saver mode. I then checked GPS and it would no longer lock or report positions in the same. But I reconnected USB and reran the adb command and now it's working again. Perhaps it's less permanent than you thought? I didn't install anything such as updates in the interim. – Michael Apr 30 '20 at 1:58
  • @Michael Unfortunately, I don't have an Android 8.0 or higher to test... and in theory, the setting should preserve permanently. However, I can't expect much since each vendor may behave differently and something might overwrite the value. Perhaps a new question regarding "preserving settings value" or "identifying the app/process that modifies the settings value" could be a good candidate... (though, the comment thread on How to make changes done through adb settings put persist through device reboots? might hint a more complex issue... – Andrew T. Apr 30 '20 at 2:09
  • I don't even remember rebooting the device! Ah well, it's useful although if I'm going to have to periodically reset it I'm going to try to automate it somewhat. :-) – Michael Apr 30 '20 at 19:09
1

Assuming you have a Pixel 3XL and using the system level battery saving,

From: https://dontkillmyapp.com/google

Pie and pre-Pie

If you see background processing issues, overall it is a good idea to make your app not battery optimized to ensure it gets the freedom it needs to perform in the background.

For that:

  • Go to Settings > Apps > Your app > Advanced > Battery > Battery optimization
  • Change view to All apps
  • Search for your app
  • Choose Not optimized

From the comments:

my app is already not optimized, but vibration doesn't work nor does GPS with the screen off when power saver is on.

So as stated in: https://support.google.com/pixelphone/answer/6187458?hl=en

What happens when Power Saver is on:

  • Apps only refresh their content, like email or news, when you look at the app.
  • Location services stop when your screen is off.
  • Apps stop doing things in the background, unless you turn off battery optimization.
  • Your phone stops listening for "Ok Google.” Instead, you need to squeeze your phone or tap the Assistant icon Assistant.
  • Dark theme turns on.
  • Your phone and notifications may be delayed.

So your app not receiving GPS/location services is covered by Power Saver behavior, as to why vibration isn't working I can't say without knowing why vibration is occurring unless its related to any of the above items like location or a background process.

  • my app is already not optimized, but vibration doesn't work nor does GPS with the screen off when power saver is on. – Michael Apr 27 '20 at 3:12
  • @Michael See update to answer. – Morrison Chang Apr 27 '20 at 3:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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