# 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)

*** ** * ** ***


```
@UnstableApi
public final class WifiLockManager
```

<br />

*** ** * ** ***

Utility class to handle a `https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html`

The handling of wifi locks requires the `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 `https://developer.android.com/reference/android/os/Looper.html` thread provided in the constructor.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/common/util/WifiLockManager#WifiLockManager(android.content.Context,android.os.Looper,androidx.media3.common.util.Clock)(https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/android/os/Looper.html wifiLockLooper, https://developer.android.com/reference/androidx/media3/common/util/Clock clock)` Creates the wifi lock manager. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/WifiLockManager#setEnabled(boolean)(boolean enabled)` Sets whether to enable the usage of a `https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/common/util/WifiLockManager#setStayAwake(boolean)(boolean stayAwake)` Sets whether to acquire or release the `https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html`. |

## Public constructors

### WifiLockManager

```
public WifiLockManager(Context context, Looper wifiLockLooper, Clock clock)
```

Creates the wifi lock manager.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | A `https://developer.android.com/reference/android/content/Context.html` |
| `https://developer.android.com/reference/android/os/Looper.html wifiLockLooper` | A background `https://developer.android.com/reference/android/os/Looper.html` to call wifi lock system calls on. |
| `https://developer.android.com/reference/androidx/media3/common/util/Clock clock` | The `https://developer.android.com/reference/androidx/media3/common/util/Clock` to schedule handler messages. |

## Public methods

### setEnabled

```
public void setEnabled(boolean enabled)
```

Sets whether to enable the usage of a `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 `https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html` requires the `https://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK`.

| Parameters |
|---|---|
| `boolean enabled` | True if the player should handle a `https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html`. |

### setStayAwake

```
public void setStayAwake(boolean stayAwake)
```

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

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

| Parameters |
|---|---|
| `boolean stayAwake` | True if the player should acquire the `https://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html`. False if it should release. |