Shouldn't WifiLockManager check if a lock is already held?
- Dominant language
- Java
- Stars
- 21.9k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Hey there,
I wasn't sure what was the right issue type to use here, so I thought I'd ask here first.
I recently came upon a crash in firebase: `java.lang.UnsupportedOperationException: Exceeded maximum number of wifi locks`. After following the breadcrumbs, I found it came when calling `ExoPlayer.prepare()` which eventually leads to acquiring a wifi/wake lock, depending on player configurations set.
I took a look at the source code in Exoplayers `WifiLockManager` and noticed the `updateWifiLock()` method doesn't check if the wifi lock is held, before attempting to acquire one. Here is link to the source method: https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/WifiLockManager.java#L83
I believe what you want to do is something like below, to avoid obtaining multiple wifi locks.
```java
if (enabled && stayAwake) {
if (!wifiLock.isHeld) wifiLock.acquire();
} else {
wifiLock.release();
}
```
Contributor guide
Assessment
This issue has not been assessed yet.