public final class PowerManager.RunningLock extends Object
PowerManager#createRunningLock(String, RunningLockType) can be called to obtain a RunningLock.
lock(long) can be called to set the lock duration, during which the system will not hibernate. After
the lock duration times out,
the lock is automatically released and the system hibernates if no other RunningLock is set.
The following is an example of how to use RunningLock.
@Step1: Obtain the PowerManager object, create a global RunningLock object for it, and set the
RunningLockType.
If the RunningLock object is damaged, the lock duration will become invalid.
@Step2: Set a lock duration greater than 0 in milliseconds
PowerManager powerManager = new PowerManager();
PowerManager.RunningLock runningLock =
powerManager.createRunningLock("test", PowerManager.RunningLockType.BACKGROUND);
runningLock.lock(5000);
public void lock(long timeOutMs)
timeOutMs - Indicates the lock duration (ms). After the lock duration times out, the lock
is automatically released and the system hibernates if no other RunningLock is set.public void unLock()
public boolean isUsed()
true if the lock is held or in use; returns false if the lock has been
released.