Class ShadowPowerManager

    • Constructor Detail

      • ShadowPowerManager

        public ShadowPowerManager()
    • Method Detail

      • turnScreenOn

        public void turnScreenOn​(boolean screenOn)
        Emulates turning the screen on/off if the screen is not already on/off.
      • setIsPowerSaveMode

        public void setIsPowerSaveMode​(boolean powerSaveMode)
      • isWakeLockLevelSupported

        @Implementation(minSdk=21)
        protected boolean isWakeLockLevelSupported​(int level)
      • setIsWakeLockLevelSupported

        public void setIsWakeLockLevelSupported​(int level,
                                                boolean supported)
      • setIsDeviceIdleMode

        public void setIsDeviceIdleMode​(boolean isDeviceIdleMode)
        Sets the value returned by isDeviceIdleMode().
      • setIsLightDeviceIdleMode

        public void setIsLightDeviceIdleMode​(boolean lightDeviceIdleMode)
        Sets the value returned by isLightDeviceIdleMode().
      • 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.
      • 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.
      • 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.
      • getTimesRebooted

        public int getTimesRebooted()
        Returns the number of times reboot(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 by isAmbientDisplayAvailable().
      • setIsRebootingUserspaceSupported

        public void setIsRebootingUserspaceSupported​(boolean supported)
        Sets the value returned by isRebootingUserspaceSupported().
      • 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.
      • 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.