Package org.robolectric.shadows
Class ShadowPowerManager
- java.lang.Object
-
- org.robolectric.shadows.ShadowPowerManager
-
@Implements(value=android.os.PowerManager.class, looseSignatures=true) public class ShadowPowerManager extends Object
Shadow of PowerManager
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classShadowPowerManager.ShadowWakeLock
-
Constructor Summary
Constructors Constructor Description ShadowPowerManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddThermalStatusListener(Object listener)This function adds a listener for thermal status change.protected intgetCurrentThermalStatus()This function returns the current thermal status of the device.static PowerManager.WakeLockgetLatestWakeLock()Retrieves the most recent wakelock registered by the applicationprotected intgetLocationPowerSaveMode()Returns how location features should behave when battery saver is on.com.google.common.collect.ImmutableList<String>getRebootReasons()Returns the list of reasons for each reboot, in chronological order.intgetTimesRebooted()Returns the number of timesreboot(String)was called.protected booleanisAmbientDisplayAvailable()Returns true by default, or the value specified viasetAmbientDisplayAvailable(boolean).protected booleanisAmbientDisplaySuppressed()Returns true ifsuppressAmbientDisplay(String, boolean)has been called with any token.protected booleanisDeviceIdleMode()protected booleanisIgnoringBatteryOptimizations(String packageName)protected booleanisInteractive()protected booleanisLightDeviceIdleMode()protected booleanisPowerSaveMode()protected booleanisRebootingUserspaceSupported()Returns last value specified insetIsRebootingUserspaceSupported(boolean)orfalseby default.protected booleanisScreenOn()protected booleanisWakeLockLevelSupported(int level)protected PowerManager.WakeLocknewWakeLock(int flags, String tag)protected voidreboot(String reason)protected voidremoveThermalStatusListener(Object listener)This function removes a listener for thermal status change.static voidreset()Discards the most recentPowerManager.WakeLocksvoidsetAmbientDisplayAvailable(boolean available)Sets the value returned byisAmbientDisplayAvailable().voidsetCurrentThermalStatus(int thermalStatus)Sets the value returned bygetCurrentThermalStatus().voidsetIgnoringBatteryOptimizations(String packageName, boolean value)voidsetIsDeviceIdleMode(boolean isDeviceIdleMode)Sets the value returned byisDeviceIdleMode().voidsetIsInteractive(boolean interactive)voidsetIsLightDeviceIdleMode(boolean lightDeviceIdleMode)Sets the value returned byisLightDeviceIdleMode().voidsetIsPowerSaveMode(boolean powerSaveMode)voidsetIsRebootingUserspaceSupported(boolean supported)Sets the value returned byisRebootingUserspaceSupported().voidsetIsScreenOn(boolean screenOn)voidsetIsWakeLockLevelSupported(int level, boolean supported)voidsetLocationPowerSaveMode(int locationMode)Sets the value returned bygetLocationPowerSaveMode()when battery saver is on.protected voidsuppressAmbientDisplay(String token, boolean suppress)If true, suppress the device's ambient display.
-
-
-
Method Detail
-
newWakeLock
@Implementation protected PowerManager.WakeLock newWakeLock(int flags, String tag)
-
isScreenOn
@Implementation protected boolean isScreenOn()
-
setIsScreenOn
public void setIsScreenOn(boolean screenOn)
-
isInteractive
@Implementation(minSdk=21) protected boolean isInteractive()
-
setIsInteractive
public void setIsInteractive(boolean interactive)
-
isPowerSaveMode
@Implementation(minSdk=21) protected boolean isPowerSaveMode()
-
setIsPowerSaveMode
public void setIsPowerSaveMode(boolean powerSaveMode)
-
isWakeLockLevelSupported
@Implementation(minSdk=21) protected boolean isWakeLockLevelSupported(int level)
-
setIsWakeLockLevelSupported
public void setIsWakeLockLevelSupported(int level, boolean supported)
-
isDeviceIdleMode
@Implementation(minSdk=23) protected boolean isDeviceIdleMode()
- Returns:
- false by default, or the value specified via
setIsDeviceIdleMode(boolean)
-
setIsDeviceIdleMode
public void setIsDeviceIdleMode(boolean isDeviceIdleMode)
Sets the value returned byisDeviceIdleMode().
-
isLightDeviceIdleMode
@Implementation(minSdk=24) protected boolean isLightDeviceIdleMode()
- Returns:
- false by default, or the value specified via
setIsLightDeviceIdleMode(boolean)
-
setIsLightDeviceIdleMode
public void setIsLightDeviceIdleMode(boolean lightDeviceIdleMode)
Sets the value returned byisLightDeviceIdleMode().
-
getLocationPowerSaveMode
@Implementation(minSdk=28) protected int 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
@Implementation(minSdk=29) protected int getCurrentThermalStatus()
This function returns the current thermal status of the device.
-
addThermalStatusListener
@Implementation(minSdk=29) protected void addThermalStatusListener(Object listener)
This function adds a listener for thermal status change.
-
removeThermalStatusListener
@Implementation(minSdk=29) protected void removeThermalStatusListener(Object listener)
This function removes a listener for thermal status change.
-
setCurrentThermalStatus
public void setCurrentThermalStatus(int thermalStatus)
Sets the value returned bygetCurrentThermalStatus().
-
reset
@Resetter public static void reset()
Discards the most recentPowerManager.WakeLocks
-
getLatestWakeLock
public static PowerManager.WakeLock getLatestWakeLock()
Retrieves the most recent wakelock registered by the application- Returns:
- Most recent wake lock.
-
isIgnoringBatteryOptimizations
@Implementation(minSdk=23) protected boolean isIgnoringBatteryOptimizations(String packageName)
-
setIgnoringBatteryOptimizations
public void setIgnoringBatteryOptimizations(String packageName, boolean value)
-
reboot
@Implementation protected void reboot(String reason)
-
getTimesRebooted
public int getTimesRebooted()
Returns the number of timesreboot(String)was called.
-
getRebootReasons
public com.google.common.collect.ImmutableList<String> getRebootReasons()
Returns the list of reasons for each reboot, in chronological order.
-
setAmbientDisplayAvailable
public void setAmbientDisplayAvailable(boolean available)
Sets the value returned byisAmbientDisplayAvailable().
-
setIsRebootingUserspaceSupported
public void setIsRebootingUserspaceSupported(boolean supported)
Sets the value returned byisRebootingUserspaceSupported().
-
isAmbientDisplayAvailable
@Implementation(minSdk=30) protected boolean isAmbientDisplayAvailable()
Returns true by default, or the value specified viasetAmbientDisplayAvailable(boolean).
-
suppressAmbientDisplay
@Implementation(minSdk=30) protected void suppressAmbientDisplay(String token, boolean suppress)
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
@Implementation(minSdk=30) protected boolean isAmbientDisplaySuppressed()
Returns true ifsuppressAmbientDisplay(String, boolean)has been called with any token.
-
isRebootingUserspaceSupported
@Implementation(minSdk=30) protected boolean isRebootingUserspaceSupported()
Returns last value specified insetIsRebootingUserspaceSupported(boolean)orfalseby default.
-
-