# WifiLockManager

# WifiLockManager

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/WifiLockManager.java+class:androidx.media3.common.util.WifiLockManager)

*** ** * ** ***

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

<br />

```
@UnstableApi
class WifiLockManager
```

<br />

*** ** * ** ***

Utility class to handle a[WifiLock](https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html)

The handling of wifi 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                                                                                                                                                                                                                                                           |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [WifiLockManager](https://developer.android.com/reference/kotlin/androidx/media3/common/util/WifiLockManager#WifiLockManager(android.content.Context,android.os.Looper,androidx.media3.common.util.Clock))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!, wifiLockLooper: `[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 wifi 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/WifiLockManager#setEnabled(boolean))`(enabled: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether to enable the usage of a[WifiLock](https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html).        |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [setStayAwake](https://developer.android.com/reference/kotlin/androidx/media3/common/util/WifiLockManager#setStayAwake(boolean))`(stayAwake: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Sets whether to acquire or release the[WifiLock](https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html). |

## Public constructors

### WifiLockManager

```
WifiLockManager(context: Context!, wifiLockLooper: Looper!, clock: Clock!)
```

Creates the wifi 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)                                          |
| `wifiLockLooper: `[Looper](https://developer.android.com/reference/android/os/Looper.html)`!`         | A background[Looper](https://developer.android.com/reference/android/os/Looper.html)to call wifi 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 usage of a[WifiLock](https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html).

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

Enabling[WifiLock](https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.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[WifiLock](https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html). |

### setStayAwake

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

Sets whether to acquire or release the[WifiLock](https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html).

The wifi lock will not be acquired unless handling has been enabled through[setEnabled](https://developer.android.com/reference/kotlin/androidx/media3/common/util/WifiLockManager#setEnabled(boolean)).  

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