google / google/ExoPlayer

Shouldn't WifiLockManager check if a lock is already held?

Open
#10,427 2 comments 0 reactions 1 assignee Claimed by @marcbaechinger View on GitHub
needs triage question
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.