Loading api/current.txt +5 −0 Original line number Diff line number Diff line Loading @@ -32121,6 +32121,7 @@ package android.os { } public final class PowerManager { method public int getLocationPowerSaveMode(); method public boolean isDeviceIdleMode(); method public boolean isIgnoringBatteryOptimizations(java.lang.String); method public boolean isInteractive(); Loading @@ -32134,6 +32135,10 @@ package android.os { field public static final java.lang.String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED"; field public static final java.lang.String ACTION_POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED"; field public static final deprecated int FULL_WAKE_LOCK = 26; // 0x1a field public static final int LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF = 2; // 0x2 field public static final int LOCATION_MODE_FOREGROUND_ONLY = 3; // 0x3 field public static final int LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF = 1; // 0x1 field public static final int LOCATION_MODE_NO_CHANGE = 0; // 0x0 field public static final int ON_AFTER_RELEASE = 536870912; // 0x20000000 field public static final int PARTIAL_WAKE_LOCK = 1; // 0x1 field public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = 32; // 0x20 core/java/android/os/PowerManager.java +54 −0 Original line number Diff line number Diff line Loading @@ -565,6 +565,42 @@ public final class PowerManager { int OPTIONAL_SENSORS = 13; } /** * 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; /** * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"LOCATION_MODE_"}, value = { LOCATION_MODE_NO_CHANGE, LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF, LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF, LOCATION_MODE_FOREGROUND_ONLY, }) public @interface LocationPowerSaveMode {} final Context mContext; final IPowerManager mService; final Handler mHandler; Loading Loading @@ -1142,6 +1178,24 @@ public final class PowerManager { } } /** * Returns how location features should behave when battery saver is on. When battery saver * is off, this will always return {@link #LOCATION_MODE_NO_CHANGE}. * * <p>This API is normally only useful for components that provide location features. * * @see #isPowerSaveMode() * @see #ACTION_POWER_SAVE_MODE_CHANGED */ @LocationPowerSaveMode public int getLocationPowerSaveMode() { final PowerSaveState powerSaveState = getPowerSaveState(ServiceType.GPS); if (!powerSaveState.globalBatterySaverEnabled) { return LOCATION_MODE_NO_CHANGE; } return powerSaveState.gpsMode; } /** * Returns true if the device is currently in idle mode. This happens when a device * has been sitting unused and unmoving for a sufficiently long period of time, so that Loading services/core/java/com/android/server/location/GnssLocationProvider.java +1 −3 Original line number Diff line number Diff line Loading @@ -84,8 +84,6 @@ import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification; import com.android.internal.location.ProviderProperties; import com.android.internal.location.ProviderRequest; import com.android.server.power.BatterySaverPolicy; import libcore.io.IoUtils; import java.io.File; Loading Loading @@ -579,7 +577,7 @@ public class GnssLocationProvider implements LocationProviderInterface { final PowerSaveState result = mPowerManager.getPowerSaveState(ServiceType.GPS); switch (result.gpsMode) { case BatterySaverPolicy.GPS_MODE_DISABLED_WHEN_SCREEN_OFF: case PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF: // If we are in battery saver mode and the screen is off, disable GPS. disableGps |= result.batterySaverEnabled && !mPowerManager.isInteractive(); break; Loading services/core/java/com/android/server/power/BatterySaverPolicy.java +2 −16 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; import android.os.PowerManager; import android.os.PowerManager.ServiceType; import android.os.PowerSaveState; import android.provider.Settings; Loading Loading @@ -49,21 +50,6 @@ public class BatterySaverPolicy extends ContentObserver { public static final boolean DEBUG = false; // DO NOT SUBMIT WITH TRUE. /** Value of batterySaverGpsMode such that GPS isn't affected by battery saver mode. */ public static final int GPS_MODE_NO_CHANGE = 0; /** * Value of batterySaverGpsMode such that GPS is disabled when battery saver mode * is enabled and the screen is off. */ public static final int GPS_MODE_DISABLED_WHEN_SCREEN_OFF = 1; /** * Value of batterySaverGpsMode such that location should be disabled altogether * when battery saver mode is enabled and the screen is off. */ public static final int GPS_MODE_ALL_DISABLED_WHEN_SCREEN_OFF = 2; // Secure setting for GPS behavior when battery saver mode is on. public static final String SECURE_KEY_GPS_MODE = "batterySaverGpsMode"; Loading Loading @@ -354,7 +340,7 @@ public class BatterySaverPolicy extends ContentObserver { // Get default value from Settings.Secure final int defaultGpsMode = Settings.Secure.getInt(mContentResolver, SECURE_KEY_GPS_MODE, GPS_MODE_ALL_DISABLED_WHEN_SCREEN_OFF); PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF); mGpsMode = parser.getInt(KEY_GPS_MODE, defaultGpsMode); // Non-device-specific parameters. Loading services/core/java/com/android/server/power/batterysaver/BatterySaverLocationPlugin.java +2 −2 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.power.batterysaver; import android.content.Context; import android.os.PowerManager; import android.provider.Settings; import android.provider.Settings.Global; import android.util.Slog; import com.android.server.power.BatterySaverPolicy; import com.android.server.power.batterysaver.BatterySaverController.Plugin; public class BatterySaverLocationPlugin implements Plugin { Loading Loading @@ -53,7 +53,7 @@ public class BatterySaverLocationPlugin implements Plugin { private void updateLocationState(BatterySaverController caller) { final boolean kill = (caller.getBatterySaverPolicy().getGpsMode() == BatterySaverPolicy.GPS_MODE_ALL_DISABLED_WHEN_SCREEN_OFF) && == PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF) && caller.isEnabled() && !caller.isInteractive(); if (DEBUG) { Loading Loading
api/current.txt +5 −0 Original line number Diff line number Diff line Loading @@ -32121,6 +32121,7 @@ package android.os { } public final class PowerManager { method public int getLocationPowerSaveMode(); method public boolean isDeviceIdleMode(); method public boolean isIgnoringBatteryOptimizations(java.lang.String); method public boolean isInteractive(); Loading @@ -32134,6 +32135,10 @@ package android.os { field public static final java.lang.String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED"; field public static final java.lang.String ACTION_POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED"; field public static final deprecated int FULL_WAKE_LOCK = 26; // 0x1a field public static final int LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF = 2; // 0x2 field public static final int LOCATION_MODE_FOREGROUND_ONLY = 3; // 0x3 field public static final int LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF = 1; // 0x1 field public static final int LOCATION_MODE_NO_CHANGE = 0; // 0x0 field public static final int ON_AFTER_RELEASE = 536870912; // 0x20000000 field public static final int PARTIAL_WAKE_LOCK = 1; // 0x1 field public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = 32; // 0x20
core/java/android/os/PowerManager.java +54 −0 Original line number Diff line number Diff line Loading @@ -565,6 +565,42 @@ public final class PowerManager { int OPTIONAL_SENSORS = 13; } /** * 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; /** * @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"LOCATION_MODE_"}, value = { LOCATION_MODE_NO_CHANGE, LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF, LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF, LOCATION_MODE_FOREGROUND_ONLY, }) public @interface LocationPowerSaveMode {} final Context mContext; final IPowerManager mService; final Handler mHandler; Loading Loading @@ -1142,6 +1178,24 @@ public final class PowerManager { } } /** * Returns how location features should behave when battery saver is on. When battery saver * is off, this will always return {@link #LOCATION_MODE_NO_CHANGE}. * * <p>This API is normally only useful for components that provide location features. * * @see #isPowerSaveMode() * @see #ACTION_POWER_SAVE_MODE_CHANGED */ @LocationPowerSaveMode public int getLocationPowerSaveMode() { final PowerSaveState powerSaveState = getPowerSaveState(ServiceType.GPS); if (!powerSaveState.globalBatterySaverEnabled) { return LOCATION_MODE_NO_CHANGE; } return powerSaveState.gpsMode; } /** * Returns true if the device is currently in idle mode. This happens when a device * has been sitting unused and unmoving for a sufficiently long period of time, so that Loading
services/core/java/com/android/server/location/GnssLocationProvider.java +1 −3 Original line number Diff line number Diff line Loading @@ -84,8 +84,6 @@ import com.android.internal.location.GpsNetInitiatedHandler.GpsNiNotification; import com.android.internal.location.ProviderProperties; import com.android.internal.location.ProviderRequest; import com.android.server.power.BatterySaverPolicy; import libcore.io.IoUtils; import java.io.File; Loading Loading @@ -579,7 +577,7 @@ public class GnssLocationProvider implements LocationProviderInterface { final PowerSaveState result = mPowerManager.getPowerSaveState(ServiceType.GPS); switch (result.gpsMode) { case BatterySaverPolicy.GPS_MODE_DISABLED_WHEN_SCREEN_OFF: case PowerManager.LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF: // If we are in battery saver mode and the screen is off, disable GPS. disableGps |= result.batterySaverEnabled && !mPowerManager.isInteractive(); break; Loading
services/core/java/com/android/server/power/BatterySaverPolicy.java +2 −16 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.Context; import android.database.ContentObserver; import android.net.Uri; import android.os.Handler; import android.os.PowerManager; import android.os.PowerManager.ServiceType; import android.os.PowerSaveState; import android.provider.Settings; Loading Loading @@ -49,21 +50,6 @@ public class BatterySaverPolicy extends ContentObserver { public static final boolean DEBUG = false; // DO NOT SUBMIT WITH TRUE. /** Value of batterySaverGpsMode such that GPS isn't affected by battery saver mode. */ public static final int GPS_MODE_NO_CHANGE = 0; /** * Value of batterySaverGpsMode such that GPS is disabled when battery saver mode * is enabled and the screen is off. */ public static final int GPS_MODE_DISABLED_WHEN_SCREEN_OFF = 1; /** * Value of batterySaverGpsMode such that location should be disabled altogether * when battery saver mode is enabled and the screen is off. */ public static final int GPS_MODE_ALL_DISABLED_WHEN_SCREEN_OFF = 2; // Secure setting for GPS behavior when battery saver mode is on. public static final String SECURE_KEY_GPS_MODE = "batterySaverGpsMode"; Loading Loading @@ -354,7 +340,7 @@ public class BatterySaverPolicy extends ContentObserver { // Get default value from Settings.Secure final int defaultGpsMode = Settings.Secure.getInt(mContentResolver, SECURE_KEY_GPS_MODE, GPS_MODE_ALL_DISABLED_WHEN_SCREEN_OFF); PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF); mGpsMode = parser.getInt(KEY_GPS_MODE, defaultGpsMode); // Non-device-specific parameters. Loading
services/core/java/com/android/server/power/batterysaver/BatterySaverLocationPlugin.java +2 −2 Original line number Diff line number Diff line Loading @@ -16,11 +16,11 @@ package com.android.server.power.batterysaver; import android.content.Context; import android.os.PowerManager; import android.provider.Settings; import android.provider.Settings.Global; import android.util.Slog; import com.android.server.power.BatterySaverPolicy; import com.android.server.power.batterysaver.BatterySaverController.Plugin; public class BatterySaverLocationPlugin implements Plugin { Loading Loading @@ -53,7 +53,7 @@ public class BatterySaverLocationPlugin implements Plugin { private void updateLocationState(BatterySaverController caller) { final boolean kill = (caller.getBatterySaverPolicy().getGpsMode() == BatterySaverPolicy.GPS_MODE_ALL_DISABLED_WHEN_SCREEN_OFF) && == PowerManager.LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF) && caller.isEnabled() && !caller.isInteractive(); if (DEBUG) { Loading