# WakeLockManager

# WakeLockManager

Artifact:[androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/WakeLockManager.java+class:androidx.media3.common.util.WakeLockManager)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/util/WakeLockManager "View this page in Java")

<br />

```
@UnstableApi
class WakeLockManager
```

<br />

*** ** * ** ***

Utility class to handle a[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html).

The handling of wake locks requires the[WAKE_LOCK](https://developer.android.com/reference/android/Manifest.permission.html#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](https://developer.android.com/reference/android/os/Looper.html)thread provided in the constructor.

## Summary

|                                                                                                                                                                                                                                                          ### Public constructors                                                                                                                                                                                                                                                           |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [WakeLockManager](https://developer.android.com/reference/kotlin/androidx/media3/common/util/WakeLockManager#WakeLockManager(android.content.Context,android.os.Looper,androidx.media3.common.util.Clock))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, wakeLockLooper: `[Looper](https://developer.android.com/reference/android/os/Looper.html)`!, clock: `[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock)`!)` Creates the wake lock manager. |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [setEnabled](https://developer.android.com/reference/kotlin/androidx/media3/common/util/WakeLockManager#setEnabled(boolean))`(enabled: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether to enable the acquiring and releasing of the[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html). |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [setStayAwake](https://developer.android.com/reference/kotlin/androidx/media3/common/util/WakeLockManager#setStayAwake(boolean))`(stayAwake: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether to acquire or release the[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html).              |

## Public constructors

### WakeLockManager

```
WakeLockManager(context: Context!, wakeLockLooper: Looper!, clock: Clock!)
```

Creates the wake lock manager.  

|                                              Parameters                                               |
|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!`         | A[Context](https://developer.android.com/reference/android/content/Context.html)                                          |
| `wakeLockLooper: `[Looper](https://developer.android.com/reference/android/os/Looper.html)`!`         | A background[Looper](https://developer.android.com/reference/android/os/Looper.html)to call wake lock system calls on.    |
| `clock: `[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock)`!` | The[Clock](https://developer.android.com/reference/kotlin/androidx/media3/common/util/Clock)to schedule handler messages. |

## Public functions

### setEnabled

```
fun setEnabled(enabled: Boolean): Unit
```

Sets whether to enable the acquiring and releasing of the[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html).

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](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html)requires the[WAKE_LOCK](https://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK()).  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `enabled: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if the player should handle a[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html), false otherwise. |

### setStayAwake

```
fun setStayAwake(stayAwake: Boolean): Unit
```

Sets whether to acquire or release the[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html).

Please note this method requires wake lock handling to be enabled through setEnabled(boolean enable) to actually have an impact on the[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html).  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `stayAwake: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if the player should acquire the[WakeLock](https://developer.android.com/reference/android/os/PowerManager.WakeLock.html). False if the player should release. |