public abstract class PowerManager extends EventManager
Applications should use the getInstance()
method to get the single
instance of this object, and should call the class methods to make queries
for power state information.
Modifier and Type | Field and Description |
---|---|
protected static PowerManager |
instance
A reference to the single instance of the PowerManager object.
|
Modifier | Constructor and Description |
---|---|
protected |
PowerManager()
Prevent other class from instantiating.
|
Modifier and Type | Method and Description |
---|---|
int |
getBatteryLevel()
Used for retrieving the current level (percent of battery charge remaining)
of the main battery or batteries.
|
int |
getEstimatedTimeRemaining()
Used for getting an estimate of how much time remains before battery
power ceases.
|
static PowerManager |
getInstance()
Returns a reference to the single instance of the PowerManger object.
|
abstract int |
getPowerState()
Gets the current system power state.
|
boolean |
isUsingExternalPower()
Used for checking if an external power source is being used.
|
abstract void |
setPowerState(int state,
boolean urgency)
Puts the system in the state specified in the parameter
state . |
addEventListener, addEventListener, addEventListener, addEventListener, addEventListener, getCurrent, getSystemEvents, post, registerApplication, registerApplication, registerApplication, registerApplication, registerApplication, removeEventListener, unregisterApplication
protected static PowerManager instance
public static PowerManager getInstance()
null
if power
management is not implemented on this platform.public abstract int getPowerState()
PowerStateEvent.POWER_STATE_OFF
,
PowerStateEvent.POWER_STATE_SUSPEND
,
PowerStateEvent.POWER_STATE_SLEEP
,
PowerStateEvent.POWER_STATE_REGULATED_LOW_POWER
,
PowerStateEvent.POWER_STATE_REGULATED_HIGH_POWER
, or
PowerStateEvent.POWER_STATE_FULL_POWER
.public abstract void setPowerState(int state, boolean urgency) throws PowerManagerException, java.lang.SecurityException
state
.
Applications suites that want to call this method with the urgency
parameter set to false
have to require the
PowerStatePermission
with name "set".
Applications suites that want to call this method with the urgency
parameter set to true
have to require the
PowerStatePermission
with name "setUrgent". Implementations are
recommended to grant this permissions only to pre-installed system
applications though.
state
- the state that the system is going to transit to, MUST be one
of PowerStateEvent.POWER_STATE_OFF
,
PowerStateEvent.POWER_STATE_SUSPEND
,
PowerStateEvent.POWER_STATE_SLEEP
,
PowerStateEvent.POWER_STATE_REGULATED_LOW_POWER
,
PowerStateEvent.POWER_STATE_REGULATED_HIGH_POWER
, or
PowerStateEvent.POWER_STATE_FULL_POWER
.urgency
- If urgency
is set to true
, force
the system to change state regardless of any objections which
may be posted by applications to reject the state change.
In circumstances like a low power emergency shutdown,
urgency
should be set to true
.PowerManagerException
- A PowerManagerException
MUST
be thrown with error code STATE_TRANSITION_FAILURE
if an error is encountered during the state change process. A
PowerManagerException
MUST be thrown with error code
ILLEGAL_STATE_TRANSITION_REQUEST
if an unrecognized
state
value is passed to the method or when there
is an invalid state transition request.java.lang.SecurityException
- A SecurityException
MUST
be thrown if the caller does not have the valid permission to
initiate the call.public int getBatteryLevel()
EventManager.getCurrent
(PowerStateEvent.BATTERY_LEVEL
)
.0
-100
), or -1
if battery
capacity information is not available, or Integer.MAX_VALUE
if battery capacity information is not available and an
external power source is currently being used.public int getEstimatedTimeRemaining()
-1
if no estimate is available, or Integer.MAX_VALUE
if an external power source is currently applied.public boolean isUsingExternalPower()
true
if an external power source is being
used (implying infinite power remaining). Returns false if
running from internal batteries, in which case the battery level
and estimated seconds remaining should be monitored.Copyright (c) 2013, Oracle and/or its affiliates. All Rights Reserved. Use of this specification is subject to license terms.