WakeLockManager


@UnstableApi
public final class WakeLockManager


Utility class to handle a WakeLock.

The handling of wake locks requires the WAKE_LOCK permission.

The class must be used from a single thread. This can be the main thread as all blocking operations are internally handled on the background Looper thread provided in the constructor.

Summary

Public constructors

WakeLockManager(Context context, Looper wakeLockLooper, Clock clock)

Creates the wake lock manager.

Public methods

void
setEnabled(boolean enabled)

Sets whether to enable the acquiring and releasing of the WakeLock.

void
setStayAwake(boolean stayAwake)

Sets whether to acquire or release the WakeLock.

Public constructors

WakeLockManager

public WakeLockManager(Context context, Looper wakeLockLooper, Clock clock)

Creates the wake lock manager.

Parameters
Context context

A Context

Looper wakeLockLooper

A background Looper to call wake lock system calls on.

Clock clock

The Clock to schedule handler messages.

Public methods

setEnabled

public void setEnabled(boolean enabled)

Sets whether to enable the acquiring and releasing of the WakeLock.

By default, wake lock handling is not enabled. Enabling this will acquire the wake lock if necessary. Disabling this will release the wake lock if it is held.

Enabling WakeLock requires the WAKE_LOCK.

Parameters
boolean enabled

True if the player should handle a WakeLock, false otherwise.

setStayAwake

public void setStayAwake(boolean stayAwake)

Sets whether to acquire or release the WakeLock.

Please note this method requires wake lock handling to be enabled through setEnabled(boolean enable) to actually have an impact on the WakeLock.

Parameters
boolean stayAwake

True if the player should acquire the WakeLock. False if the player should release.