Package org.robolectric.shadows
Class ShadowPowerManager
java.lang.Object
org.robolectric.shadows.ShadowPowerManager
Shadow of PowerManager
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Shadow ofPowerManager.LowPowerStandbyPortsLock
to allow testing state.static class
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAllowedInLowPowerStandby
(String feature) protected void
addThermalStatusListener
(Object listener) This function adds a listener for thermal status change.static void
Clears most recent recorded wakelock.boolean
Gets the value set bysetAdaptivePowerSaveEnabled(boolean)
.protected Duration
Returns the current battery life remaining estimate.protected int
This function returns the current thermal status of the device.static PowerManager.WakeLock
Retrieves the most recent wakelock registered by the applicationprotected int
Returns how location features should behave when battery saver is on.Returns the list of reasons for each reboot, in chronological order.com.google.common.collect.ImmutableSet<Object>
This function gets listeners for thermal status change.int
Returns the number of timesreboot(String)
was called.protected boolean
isAllowedInLowPowerStandby
(String feature) protected boolean
Returns true by default, or the value specified viasetAmbientDisplayAvailable(boolean)
.protected boolean
Returns true ifsuppressAmbientDisplay(String, boolean)
has been called with any token.protected boolean
Returns whether the current battery life remaining estimate is personalized based on device usage history or not.protected boolean
protected boolean
protected boolean
protected boolean
isIgnoringBatteryOptimizations
(String packageName) protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
Returns last value specified insetIsRebootingUserspaceSupported(boolean)
orfalse
by default.protected boolean
protected boolean
isWakeLockLevelSupported
(int level) protected Object
protected PowerManager.WakeLock
newWakeLock
(int flags, String tag) protected void
protected void
removeThermalStatusListener
(Object listener) This function removes a listener for thermal status change.static void
reset()
Discards the most recentPowerManager.WakeLock
sprotected boolean
setAdaptivePowerSaveEnabled
(boolean enabled) Sets whether Adaptive Power Saver is enabled.void
setAmbientDisplayAvailable
(boolean available) Sets the value returned byisAmbientDisplayAvailable()
.protected void
setBatteryDischargePrediction
(Duration timeRemaining, boolean isPersonalized) Differs from real implementation as device charging state is not checked.void
setCurrentThermalStatus
(int thermalStatus) Sets the value returned bygetCurrentThermalStatus()
.void
setExemptFromLowPowerStandby
(boolean exemptFromLowPowerStandby) void
setIgnoringBatteryOptimizations
(String packageName, boolean value) void
setIsDeviceIdleMode
(boolean isDeviceIdleMode) Sets the value returned byisDeviceIdleMode()
.void
setIsDeviceLightIdleMode
(boolean lightDeviceIdleMode) Sets the value returned byisDeviceLightIdleMode()
.void
setIsInteractive
(boolean interactive) Deprecated.void
setIsLightDeviceIdleMode
(boolean lightDeviceIdleMode) Sets the value returned byisLightDeviceIdleMode()
.void
setIsPowerSaveMode
(boolean powerSaveMode) void
setIsRebootingUserspaceSupported
(boolean supported) Sets the value returned byisRebootingUserspaceSupported()
.void
setIsScreenOn
(boolean screenOn) Deprecated.UseturnScreenOn(boolean)
instead.void
setIsWakeLockLevelSupported
(int level, boolean supported) void
setLocationPowerSaveMode
(int locationMode) Sets the value returned bygetLocationPowerSaveMode()
when battery saver is on.void
setLowPowerStandbyEnabled
(boolean lowPowerStandbyEnabled) void
setLowPowerStandbySupported
(boolean lowPowerStandbySupported) protected void
suppressAmbientDisplay
(String token, boolean suppress) If true, suppress the device's ambient display.void
turnScreenOn
(boolean screenOn) Emulates turning the screen on/off if the screen is not already on/off.
-
Constructor Details
-
ShadowPowerManager
public ShadowPowerManager()
-
-
Method Details
-
newWakeLock
-
isScreenOn
-
setIsScreenOn
Deprecated.UseturnScreenOn(boolean)
instead. -
isInteractive
-
setIsInteractive
Deprecated.PreferturnScreenOn(boolean)
instead. -
turnScreenOn
public void turnScreenOn(boolean screenOn) Emulates turning the screen on/off if the screen is not already on/off. -
isPowerSaveMode
-
setIsPowerSaveMode
public void setIsPowerSaveMode(boolean powerSaveMode) -
isWakeLockLevelSupported
-
setIsWakeLockLevelSupported
public void setIsWakeLockLevelSupported(int level, boolean supported) -
isDeviceIdleMode
- Returns:
- false by default, or the value specified via
setIsDeviceIdleMode(boolean)
-
setIsDeviceIdleMode
public void setIsDeviceIdleMode(boolean isDeviceIdleMode) Sets the value returned byisDeviceIdleMode()
. -
isLightDeviceIdleMode
- Returns:
- false by default, or the value specified via
setIsLightDeviceIdleMode(boolean)
-
setIsLightDeviceIdleMode
public void setIsLightDeviceIdleMode(boolean lightDeviceIdleMode) Sets the value returned byisLightDeviceIdleMode()
. -
isDeviceLightIdleMode
-
setIsDeviceLightIdleMode
public void setIsDeviceLightIdleMode(boolean lightDeviceIdleMode) Sets the value returned byisDeviceLightIdleMode()
. -
getLocationPowerSaveMode
Returns how location features should behave when battery saver is on. When battery saver is off, this will always return#LOCATION_MODE_NO_CHANGE
. -
setLocationPowerSaveMode
public void setLocationPowerSaveMode(int locationMode) Sets the value returned bygetLocationPowerSaveMode()
when battery saver is on. -
getCurrentThermalStatus
This function returns the current thermal status of the device. -
addThermalStatusListener
This function adds a listener for thermal status change. -
getThermalStatusListeners
This function gets listeners for thermal status change. -
removeThermalStatusListener
This function removes a listener for thermal status change. -
setCurrentThermalStatus
public void setCurrentThermalStatus(int thermalStatus) Sets the value returned bygetCurrentThermalStatus()
. -
reset
Discards the most recentPowerManager.WakeLock
s -
getLatestWakeLock
Retrieves the most recent wakelock registered by the application- Returns:
- Most recent wake lock.
-
clearWakeLocks
public static void clearWakeLocks()Clears most recent recorded wakelock. -
isIgnoringBatteryOptimizations
-
setIgnoringBatteryOptimizations
-
setBatteryDischargePrediction
@Implementation(minSdk=31) protected void setBatteryDischargePrediction(Duration timeRemaining, boolean isPersonalized) Differs from real implementation as device charging state is not checked.- Parameters:
timeRemaining
- The time remaining as aDuration
.isPersonalized
- true if personalized based on device usage history, false otherwise.
-
getBatteryDischargePrediction
Returns the current battery life remaining estimate.Differs from real implementation as the time that
setBatteryDischargePrediction(java.time.Duration, boolean)
was called is not taken into account.- Returns:
- The estimated battery life remaining as a
Duration
. Will benull
if the prediction has not been set.
-
isBatteryDischargePredictionPersonalized
Returns whether the current battery life remaining estimate is personalized based on device usage history or not. This value does not take a device's powered or charging state into account.- Returns:
- A boolean indicating if the current discharge estimate is personalized based on historical device usage or not.
-
reboot
-
getTimesRebooted
public int getTimesRebooted()Returns the number of timesreboot(String)
was called. -
getRebootReasons
Returns the list of reasons for each reboot, in chronological order. May containnull
. -
setAmbientDisplayAvailable
public void setAmbientDisplayAvailable(boolean available) Sets the value returned byisAmbientDisplayAvailable()
. -
setIsRebootingUserspaceSupported
public void setIsRebootingUserspaceSupported(boolean supported) Sets the value returned byisRebootingUserspaceSupported()
. -
isAmbientDisplayAvailable
Returns true by default, or the value specified viasetAmbientDisplayAvailable(boolean)
. -
suppressAmbientDisplay
If true, suppress the device's ambient display. Ambient display is defined as anything visible on the display whenPowerManager.isInteractive()
is false.- Parameters:
token
- An identifier for the ambient display suppression.suppress
- Iftrue
, suppresses the ambient display. Otherwise, unsuppresses the ambient display for the given token.
-
isAmbientDisplaySuppressed
Returns true ifsuppressAmbientDisplay(String, boolean)
has been called with any token. -
isRebootingUserspaceSupported
Returns last value specified insetIsRebootingUserspaceSupported(boolean)
orfalse
by default. -
setAdaptivePowerSaveEnabled
Sets whether Adaptive Power Saver is enabled.This has no effect, other than the value of
getAdaptivePowerSaveEnabled()
is changed, which can be used to ensure this method is called correctly.- Returns:
- true if the value has changed.
-
getAdaptivePowerSaveEnabled
public boolean getAdaptivePowerSaveEnabled()Gets the value set bysetAdaptivePowerSaveEnabled(boolean)
. -
isLowPowerStandbySupported
-
setLowPowerStandbySupported
public void setLowPowerStandbySupported(boolean lowPowerStandbySupported) -
isLowPowerStandbyEnabled
-
setLowPowerStandbyEnabled
-
isAllowedInLowPowerStandby
-
addAllowedInLowPowerStandby
-
isExemptFromLowPowerStandby
-
setExemptFromLowPowerStandby
public void setExemptFromLowPowerStandby(boolean exemptFromLowPowerStandby) -
newLowPowerStandbyPortsLock
@Implementation(minSdk=34) protected Object newLowPowerStandbyPortsLock(List<PowerManager.LowPowerStandbyPortDescription> ports)
-
turnScreenOn(boolean)
instead.