Added in API level 1

PowerManager


class PowerManager
kotlin.Any
   ↳ android.os.PowerManager

This class lets you query and request control of aspects of the device's power state.

Summary

Nested classes
abstract

Listener passed to android.

abstract

Listener passed to android.

A wake lock is a mechanism to indicate that your application needs to have the device stay on.

abstract

A listener interface to get notified when the wakelock is enabled/disabled.

Constants
static Int

Wake lock flag: Turn the screen on when the wake lock is acquired.

static String

Intent that is broadcast when the state of isDeviceIdleMode() changes.

static String

Intent that is broadcast when the state of isDeviceLightIdleMode() changes.

static String

Intent that is broadcast when Low Power Standby is enabled or disabled.

static String

Intent that is broadcast when Low Power Standby policy is changed.

static String

Intent that is broadcast when the state of isPowerSaveMode() changes.

static String

Signals that wake-on-lan/wake-on-wlan is allowed in Low Power Standby.

static Int

Wake lock level: Ensures that the screen and keyboard backlight are on at full brightness.

static Int

All location providers should be disabled when battery saver is on and the device is non-interactive.

static Int

In this mode, all the location providers will be kept available, but location fixes should only be provided to foreground apps.

static Int

In this mode, the GPS based location provider should be disabled when battery saver is on and the device is non-interactive.

static Int

Either the location providers shouldn't be affected by battery saver, or battery saver is off.

static Int

In this mode, location will not be turned off, but LocationManager will throttle all requests to providers when the device is non-interactive.

static Int

Exempts apps with ongoing calls.

static Int

Exempts apps on the temporary powersave allowlist.

static Int

Exempts active Voice Interaction Sessions in Low Power Standby.

static Int

Wake lock flag: When this wake lock is released, poke the user activity timer so the screen stays on for a little longer.

static Int

Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off.

static Int

Wake lock level: Turns the screen off when the proximity sensor activates.

static Int

Flag for android.

static Int

Wake lock level: Ensures that the screen is on at full brightness; the keyboard backlight will be allowed to go off.

static Int

Wake lock level: Ensures that the screen is on (but may be dimmed); the keyboard backlight will be allowed to go off.

static Int

Thermal status code: Platform has done everything to reduce power.

static Int

Thermal status code: Key components in platform are shutting down due to thermal condition.

static Int

Thermal status code: Light throttling where UX is not impacted.

static Int

Thermal status code: Moderate throttling where UX is not largely impacted.

static Int

Thermal status code: Not under throttling.

static Int

Thermal status code: Severe throttling where UX is largely impacted.

static Int

Thermal status code: Need shutdown immediately.

Public methods
Unit

This function adds a listener for thermal headroom change, listener callback will be enqueued tasks on the main thread

Unit

This function adds a listener for thermal headroom change.

Unit

This function adds a listener for thermal status change, listener callback will be enqueued tasks on the main thread

Unit

This function adds a listener for thermal status change.

Duration?

Returns the current battery life remaining estimate.

Int

This function returns the current thermal status of the device.

Int

Returns how location features should behave when battery saver is on.

Float
getThermalHeadroom(forecastSeconds: Int)

Provides an estimate of how much thermal headroom the device currently has before hitting severe throttling.

MutableMap<Int!, Float!>

Gets the thermal headroom thresholds for all available thermal throttling status above THERMAL_STATUS_NONE.

Boolean

Returns true if Low Power Standby is disabled (so Low Power Standby does not restrict apps), or apps may be automatically exempt from Low Power Standby restrictions for the given reason.

Boolean

Returns true if Low Power Standby is disabled (so Low Power Standby does not restrict apps), or apps are allowed to use a given feature during Low Power Standby.

Boolean

Returns whether the current battery life remaining estimate is personalized based on device usage history or not.

Boolean

Returns true if the device is currently in idle mode.

Boolean

Returns true if the device is currently in light idle mode.

Boolean

Returns true if the calling package is exempt from Low Power Standby restrictions or Low Power Standby is disabled (so Low Power Standby does not restrict apps), false otherwise.

Boolean

Return whether the given application package name is on the device's power allowlist.

Boolean

Returns true if the device is in an interactive state.

Boolean

Returns true if Low Power Standby is enabled.

Boolean

Returns true if the device is currently in power save mode.

Boolean

Returns true if this device supports rebooting userspace.

Boolean

Returns true if the device is in an interactive state.

Boolean

This function checks if the device has implemented Sustained Performance Mode.

Boolean

Returns true if the specified wake lock level is supported.

PowerManager.WakeLock!
newWakeLock(levelAndFlags: Int, tag: String!)

Creates a new wake lock with the specified level and flags.

Unit
reboot(reason: String?)

Reboot the device.

Unit

This function removes a listener for Thermal headroom change

Unit

This function removes a listener for thermal status change

Constants

ACQUIRE_CAUSES_WAKEUP

Added in API level 1
Deprecated in API level 33
static val ACQUIRE_CAUSES_WAKEUP: Int

Deprecated: Most applications should use android.R.attr#turnScreenOn or android.app.Activity#setTurnScreenOn(boolean) instead, as this prevents the previous foreground app from being resumed first when the screen turns on.

Wake lock flag: Turn the screen on when the wake lock is acquired.

This flag will require android.Manifest.permission#TURN_SCREEN_ON in future releases.

Normally wake locks don't actually wake the device, they just cause the screen to remain on once it's already on. This flag will cause the device to wake up when the wake lock is acquired.

Android TV playback devices attempt to turn on the HDMI-connected TV via HDMI-CEC on any wake-up, including wake-ups triggered by wake locks.

Cannot be used with PARTIAL_WAKE_LOCK.

Value: 268435456

ACTION_DEVICE_IDLE_MODE_CHANGED

Added in API level 23
static val ACTION_DEVICE_IDLE_MODE_CHANGED: String

Intent that is broadcast when the state of isDeviceIdleMode() changes. This broadcast is only sent to registered receivers.

Value: "android.os.action.DEVICE_IDLE_MODE_CHANGED"

ACTION_DEVICE_LIGHT_IDLE_MODE_CHANGED

Added in API level 33
static val ACTION_DEVICE_LIGHT_IDLE_MODE_CHANGED: String

Intent that is broadcast when the state of isDeviceLightIdleMode() changes. This broadcast is only sent to registered receivers.

Value: "android.os.action.LIGHT_DEVICE_IDLE_MODE_CHANGED"

ACTION_LOW_POWER_STANDBY_ENABLED_CHANGED

Added in API level 33
static val ACTION_LOW_POWER_STANDBY_ENABLED_CHANGED: String

Intent that is broadcast when Low Power Standby is enabled or disabled. This broadcast is only sent to registered receivers and receivers holding android.permission.MANAGE_LOW_POWER_STANDBY.

Value: "android.os.action.LOW_POWER_STANDBY_ENABLED_CHANGED"

ACTION_LOW_POWER_STANDBY_POLICY_CHANGED

Added in API level 34
static val ACTION_LOW_POWER_STANDBY_POLICY_CHANGED: String

Intent that is broadcast when Low Power Standby policy is changed. This broadcast is only sent to registered receivers and receivers holding android.permission.MANAGE_LOW_POWER_STANDBY.

Value: "android.os.action.LOW_POWER_STANDBY_POLICY_CHANGED"

ACTION_POWER_SAVE_MODE_CHANGED

Added in API level 21
static val ACTION_POWER_SAVE_MODE_CHANGED: String

Intent that is broadcast when the state of isPowerSaveMode() changes. This broadcast is only sent to registered receivers.

Value: "android.os.action.POWER_SAVE_MODE_CHANGED"

FEATURE_WAKE_ON_LAN_IN_LOW_POWER_STANDBY

Added in API level 34
static val FEATURE_WAKE_ON_LAN_IN_LOW_POWER_STANDBY: String

Signals that wake-on-lan/wake-on-wlan is allowed in Low Power Standby.

If Low Power Standby is enabled (isLowPowerStandbyEnabled()), wake-on-lan/wake-on-wlan may not be available while in standby. Use isAllowedInLowPowerStandby(String) to determine whether the device allows this feature to be used during Low Power Standby with the currently active Low Power Standby policy.

Value: "com.android.lowpowerstandby.WAKE_ON_LAN"

FULL_WAKE_LOCK

Added in API level 1
Deprecated in API level 17
static val FULL_WAKE_LOCK: Int

Deprecated: Most applications should use android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON instead of this type of wake lock, as it will be correctly managed by the platform as the user moves between applications and doesn't require a special permission.

Wake lock level: Ensures that the screen and keyboard backlight are on at full brightness.

If the user presses the power button, then the FULL_WAKE_LOCK will be implicitly released by the system, causing both the screen and the CPU to be turned off. Contrast with PARTIAL_WAKE_LOCK.

Value: 26

LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF

Added in API level 28
static val LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF: Int

All location providers should be disabled when battery saver is on and the device is non-interactive.

Value: 2

LOCATION_MODE_FOREGROUND_ONLY

Added in API level 28
static val LOCATION_MODE_FOREGROUND_ONLY: Int

In this mode, all the location providers will be kept available, but location fixes should only be provided to foreground apps.

Value: 3

LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF

Added in API level 28
static val LOCATION_MODE_GPS_DISABLED_WHEN_SCREEN_OFF: Int

In this mode, the GPS based location provider should be disabled when battery saver is on and the device is non-interactive.

Value: 1

LOCATION_MODE_NO_CHANGE

Added in API level 28
static val LOCATION_MODE_NO_CHANGE: Int

Either the location providers shouldn't be affected by battery saver, or battery saver is off.

Value: 0

LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF

Added in API level 29
static val LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF: Int

In this mode, location will not be turned off, but LocationManager will throttle all requests to providers when the device is non-interactive.

Value: 4

LOW_POWER_STANDBY_ALLOWED_REASON_ONGOING_CALL

Added in API level 34
static val LOW_POWER_STANDBY_ALLOWED_REASON_ONGOING_CALL: Int

Exempts apps with ongoing calls.

This includes apps with foreground services of type "phoneCall".

Value: 4

LOW_POWER_STANDBY_ALLOWED_REASON_TEMP_POWER_SAVE_ALLOWLIST

Added in API level 34
static val LOW_POWER_STANDBY_ALLOWED_REASON_TEMP_POWER_SAVE_ALLOWLIST: Int

Exempts apps on the temporary powersave allowlist.

Value: 2

LOW_POWER_STANDBY_ALLOWED_REASON_VOICE_INTERACTION

Added in API level 34
static val LOW_POWER_STANDBY_ALLOWED_REASON_VOICE_INTERACTION: Int

Exempts active Voice Interaction Sessions in Low Power Standby.

Value: 1

ON_AFTER_RELEASE

Added in API level 1
static val ON_AFTER_RELEASE: Int

Wake lock flag: When this wake lock is released, poke the user activity timer so the screen stays on for a little longer.

This will not turn the screen on if it is not already on.

Cannot be used with PARTIAL_WAKE_LOCK.

Value: 536870912

PARTIAL_WAKE_LOCK

Added in API level 1
static val PARTIAL_WAKE_LOCK: Int

Wake lock level: Ensures that the CPU is running; the screen and keyboard backlight will be allowed to go off.

If the user presses the power button, then the screen will be turned off but the CPU will be kept on until all partial wake locks have been released.

Value: 1

PROXIMITY_SCREEN_OFF_WAKE_LOCK

Added in API level 21
static val PROXIMITY_SCREEN_OFF_WAKE_LOCK: Int

Wake lock level: Turns the screen off when the proximity sensor activates.

If the proximity sensor detects that an object is nearby, the screen turns off immediately. Shortly after the object moves away, the screen turns on again.

A proximity wake lock does not prevent the device from falling asleep unlike FULL_WAKE_LOCK, SCREEN_BRIGHT_WAKE_LOCK and SCREEN_DIM_WAKE_LOCK. If there is no user activity and no other wake locks are held, then the device will fall asleep (and lock) as usual. However, the device will not fall asleep while the screen has been turned off by the proximity sensor because it effectively counts as ongoing user activity.

Since not all devices have proximity sensors, use isWakeLockLevelSupported to determine whether this wake lock level is supported.

Cannot be used with ACQUIRE_CAUSES_WAKEUP.

Value: 32

RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY

Added in API level 21
static val RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY: Int

Flag for android.os.PowerManager.