BatterySaverMode
public
class
BatterySaverMode
extends Object
| java.lang.Object | |
| ↳ | com.google.wear.modes.BatterySaverMode |
Battery Saver Mode on Wear attempts to reduce battery consumption. It may disable ambient mode, tilt to wake, etc.
This class provides an object to interact with the configured and active levels of bedtime mode.
The supported levels of battery saver mode are:
An instance of this class can be obtained by ModeManager.getBatterySaverMode() API.
Summary
Constants | |
|---|---|
int |
BATTERY_SAVER_LEVEL_NORMAL
This battery saver mode level indicates normal battery saver mode is enabled. |
int |
BATTERY_SAVER_LEVEL_OFF
This battery saver mode level indicates battery saver mode is off. |
Public methods | |
|---|---|
void
|
addActiveLevelListener(Executor executor, Consumer<Integer> listener)
Adds a listener to listen for the changes in the active level of battery saver mode. |
int
|
getActiveLevel()
Gets the active level of battery saver mode. |
int
|
getConfiguredLevel()
Gets the configured level of battery saver mode. |
long
|
getOverriddenReasons()
This method allows checking for the reason behind the state of battery saver mode being overridden. |
boolean
|
isOverridden()
Determine if the state of battery saver mode is overridden or not. |
void
|
removeActiveLevelListener(Consumer<Integer> listener)
This removes the previously added listener. |
void
|
setConfiguredLevel(int level)
Sets the configured level of battery saver mode which can be fetched via |
Inherited methods | |
|---|---|
Constants
BATTERY_SAVER_LEVEL_NORMAL
public static final int BATTERY_SAVER_LEVEL_NORMAL
This battery saver mode level indicates normal battery saver mode is enabled.
Constant Value: 1 (0x00000001)
BATTERY_SAVER_LEVEL_OFF
public static final int BATTERY_SAVER_LEVEL_OFF
This battery saver mode level indicates battery saver mode is off.
Constant Value: 0 (0x00000000)
Public methods
addActiveLevelListener
public void addActiveLevelListener (Executor executor,
Consumer<Integer> listener)Adds a listener to listen for the changes in the active level of battery saver mode. The listener will be triggered asynchronously with an initial level on registration and then again when the level changes.
Due to potential race conditions between calls, use of this method should not be mixed
with getActiveLevel() method and the level the listener is triggered with should be
treated as the latest active level.
Note: This should be balanced with removeActiveLevelListener(Consumer) to prevent
memory leaks.
Requires com.google.wear.services.Permissions.READ_BATTERY_SAVER
| Parameters | |
|---|---|
executor |
Executor: The listener will be triggered on this Executor |
listener |
Consumer: The listener to add |
getActiveLevel
public int getActiveLevel ()
Gets the active level of battery saver mode.
This is the active level of battery saver mode in effect as reflected on the device. It is
determined by the current operating context of the system. Due to potential race conditions
due to change between calls, use of this method should not be mixed with addActiveLevelListener(Executor,Consumer).
Requires com.google.wear.services.Permissions.READ_BATTERY_SAVER
| Returns | |
|---|---|
int |
the active level of battery saver mode. This could be one of BATTERY_SAVER_LEVEL_OFF or BATTERY_SAVER_LEVEL_NORMAL.
Value is one of the following: |
getConfiguredLevel
public int getConfiguredLevel ()
Gets the configured level of battery saver mode.
This reflects the default configured level of battery saver mode and is set via setConfiguredLevel(int).
Note: If the state of battery saver mode is overridden (isOverridden()), this may
differ from the active level. See isOverridden() for details.
Requires com.google.wear.services.Permissions.READ_BATTERY_SAVER
| Returns | |
|---|---|
int |
the configured level of battery saver mode. This could be one of BATTERY_SAVER_LEVEL_OFF or BATTERY_SAVER_LEVEL_NORMAL.
Value is one of the following: |
getOverriddenReasons
public long getOverriddenReasons ()
This method allows checking for the reason behind the state of battery saver mode being
overridden. See isOverridden() for details.
This method returns a flag (defined in ModeManager) comprising reason(s)
indicating the factors playing a role in overriding the state of battery saver mode. Each flag has
a permission associated with it, and this method only returns the flags the caller already
has the permission for. Please check the respective flag for its permission requirement.
Note: The returned level might also contain ModeManager.FLAG_OVERRIDDEN_BY_UNKNOWN_REASON indicating an unknown cause behind the state
of battery saver mode being overridden.
Requires com.google.wear.services.Permissions.READ_BATTERY_SAVER
| Returns | |
|---|---|
long |
the combination of flags defined in ModeManager specifying the cause behind
the state of battery saver mode being overridden. Returned level of OL implies that
the state of battery saver mode is not overridden.
Value is either 0 or a combination of the following:
|
isOverridden
public boolean isOverridden ()
Determine if the state of battery saver mode is overridden or not.
Battery saver has a configured level which is the default level for its state. The active level as reflected on the device, on the other hand, is determined by the current operating context of the system and depends on either of the following:
- Either the configured level of battery saver mode
- Or the configured values of all other modes
The state of battery saver mode can be defined as overridden if its configured level does not
play a role in determining its active level. This does not necessarily mean that the
configured level will be different from the active level but rather means that if the
configured level is updated, the active level will not be updated till the override is
lifted.
Requires com.google.wear.services.Permissions.READ_BATTERY_SAVER
| Returns | |
|---|---|
boolean |
true if the state of battery saver mode is overridden, i.e. updating configured level does not update the active level |
removeActiveLevelListener
public void removeActiveLevelListener (Consumer<Integer> listener)
This removes the previously added listener.
| Parameters | |
|---|---|
listener |
Consumer: The listener to remove |
setConfiguredLevel
public void setConfiguredLevel (int level)
Sets the configured level of battery saver mode which can be fetched via getConfiguredLevel(). In case an override is not in place, this will also update its active
level as reflected on the device which can be fetched via getActiveLevel(). However,
in case the state of battery saver mode is overridden, its active level as on the device will be
updated to reflect this configured level once the override is uplifted.
Requires com.google.wear.services.Permissions.WRITE_BATTERY_SAVER
| Parameters | |
|---|---|
level |
int: The level of battery saver mode to state. This could be one of BATTERY_SAVER_LEVEL_OFF or BATTERY_SAVER_LEVEL_NORMAL.
Value is one of the following: |