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
  • Constructor Details

    • ShadowPowerManager

      public ShadowPowerManager()
  • Method Details

    • newWakeLock

      @Implementation protected PowerManager.WakeLock newWakeLock(int flags, String tag)
    • isScreenOn

      @Implementation protected boolean isScreenOn()
    • setIsScreenOn

      @Deprecated public void setIsScreenOn(boolean screenOn)
      Deprecated.
    • isInteractive

      @Implementation(minSdk=21) protected boolean isInteractive()
    • setIsInteractive

      @Deprecated public void setIsInteractive(boolean interactive)
      Deprecated.
      Prefer turnScreenOn(boolean) instead.
    • turnScreenOn

      public void turnScreenOn(boolean screenOn)
      Emulates turning the screen on/off if the screen is not already on/off.
    • 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 by isDeviceIdleMode().
    • 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 by isLightDeviceIdleMode().
    • isDeviceLightIdleMode

      @Implementation(minSdk=33) protected boolean isDeviceLightIdleMode()
    • setIsDeviceLightIdleMode

      public void setIsDeviceLightIdleMode(boolean lightDeviceIdleMode)
      Sets the value returned by isDeviceLightIdleMode().
    • 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 by getLocationPowerSaveMode() 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.
    • getThermalStatusListeners

      public com.google.common.collect.ImmutableSet<Object> getThermalStatusListeners()
      This function gets listeners 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 by getCurrentThermalStatus().
    • reset

      @Resetter public static void reset()
      Discards the most recent PowerManager.WakeLocks
    • getLatestWakeLock

      public static PowerManager.WakeLock 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

      @Implementation(minSdk=23) protected boolean isIgnoringBatteryOptimizations(String packageName)
    • setIgnoringBatteryOptimizations

      public void setIgnoringBatteryOptimizations(String packageName, boolean value)
    • 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 a Duration.
      isPersonalized - true if personalized based on device usage history, false otherwise.
    • getBatteryDischargePrediction

      @Implementation(minSdk=31) protected Duration 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 be null if the prediction has not been set.
    • isBatteryDischargePredictionPersonalized

      @Implementation(minSdk=31) protected boolean 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

      @Implementation protected void reboot(String reason)
    • getTimesRebooted

      public int getTimesRebooted()
      Returns the number of times reboot(String) was called.
    • getRebootReasons

      public List<String> getRebootReasons()
      Returns the list of reasons for each reboot, in chronological order. May contain null.
    • setAmbientDisplayAvailable

      public void setAmbientDisplayAvailable(boolean available)
      Sets the value returned by isAmbientDisplayAvailable().
    • setIsRebootingUserspaceSupported

      public void setIsRebootingUserspaceSupported(boolean supported)
      Sets the value returned by isRebootingUserspaceSupported().
    • isAmbientDisplayAvailable

      @Implementation(minSdk=30) protected boolean isAmbientDisplayAvailable()
      Returns true by default, or the value specified via setAmbientDisplayAvailable(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 when PowerManager.isInteractive() is false.
      Parameters:
      token - An identifier for the ambient display suppression.
      suppress - If true, suppresses the ambient display. Otherwise, unsuppresses the ambient display for the given token.
    • isAmbientDisplaySuppressed

      @Implementation(minSdk=30) protected boolean isAmbientDisplaySuppressed()
      Returns true if suppressAmbientDisplay(String, boolean) has been called with any token.
    • isRebootingUserspaceSupported

      @Implementation(minSdk=30) protected boolean isRebootingUserspaceSupported()
      Returns last value specified in setIsRebootingUserspaceSupported(boolean) or false by default.
    • setAdaptivePowerSaveEnabled

      @Implementation(minSdk=29) protected boolean setAdaptivePowerSaveEnabled(boolean enabled)
      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()
    • isLowPowerStandbySupported

      @Implementation(minSdk=33) protected boolean isLowPowerStandbySupported()
    • setLowPowerStandbySupported

      public void setLowPowerStandbySupported(boolean lowPowerStandbySupported)
    • isLowPowerStandbyEnabled

      @Implementation(minSdk=33) protected boolean isLowPowerStandbyEnabled()
    • setLowPowerStandbyEnabled

      @Implementation(minSdk=33) protected void setLowPowerStandbyEnabled(boolean lowPowerStandbyEnabled)
    • isAllowedInLowPowerStandby

      @Implementation(minSdk=34) protected boolean isAllowedInLowPowerStandby(String feature)
    • addAllowedInLowPowerStandby

      public void addAllowedInLowPowerStandby(String feature)
    • isExemptFromLowPowerStandby

      @Implementation(minSdk=34) protected boolean isExemptFromLowPowerStandby()
    • setExemptFromLowPowerStandby

      public void setExemptFromLowPowerStandby(boolean exemptFromLowPowerStandby)
    • newLowPowerStandbyPortsLock

      @Implementation(minSdk=34) protected Object newLowPowerStandbyPortsLock(List<PowerManager.LowPowerStandbyPortDescription> ports)