Skip to content

Commit

Permalink
optimize require wake lock
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfeng committed Mar 17, 2023
1 parent 0e72089 commit d78a510
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions player/src/main/java/snow/player/SnowPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,31 +693,15 @@ private void requireWakeLock() {
return;
}

if (isWakeLockHeld() && isWifiLockHeld()) {
return;
}

PowerManager.WakeLock oldWakeLock = mWakeLock;
WifiManager.WifiLock oldWifiLock = mWifiLock;

mWakeLock = createWakeLock();
mWifiLock = createWifiLock();

if (mWakeLock != null && !mWakeLock.isHeld()) {
if (!isWakeLockHeld()) {
mWakeLock = createWakeLock();
mWakeLock.acquire();
}

if (mWifiLock != null && !mWifiLock.isHeld()) {
if (!isWifiLockHeld()) {
mWifiLock = createWifiLock();
mWifiLock.acquire();
}

if (oldWakeLock != null && oldWakeLock.isHeld()) {
oldWakeLock.release();
}

if (oldWifiLock != null && oldWifiLock.isHeld()) {
oldWifiLock.release();
}
}

private boolean wakeLockPermissionDenied() {
Expand Down

0 comments on commit d78a510

Please sign in to comment.