Rabbit-R1/android (non root)/java/sources/androidx/media3/exoplayer/WakeLockManager.java
2024-05-21 17:08:36 -04:00

52 lines
1.6 KiB
Java

package androidx.media3.exoplayer;
import android.content.Context;
import android.os.PowerManager;
import androidx.media3.common.util.Log;
/* loaded from: classes2.dex */
final class WakeLockManager {
private static final String TAG = "WakeLockManager";
private static final String WAKE_LOCK_TAG = "ExoPlayer:WakeLockManager";
private boolean enabled;
private final PowerManager powerManager;
private boolean stayAwake;
private PowerManager.WakeLock wakeLock;
public WakeLockManager(Context context) {
this.powerManager = (PowerManager) context.getApplicationContext().getSystemService("power");
}
public void setEnabled(boolean z) {
if (z && this.wakeLock == null) {
PowerManager powerManager = this.powerManager;
if (powerManager == null) {
Log.w(TAG, "PowerManager is null, therefore not creating the WakeLock.");
return;
} else {
PowerManager.WakeLock newWakeLock = powerManager.newWakeLock(1, WAKE_LOCK_TAG);
this.wakeLock = newWakeLock;
newWakeLock.setReferenceCounted(false);
}
}
this.enabled = z;
updateWakeLock();
}
public void setStayAwake(boolean z) {
this.stayAwake = z;
updateWakeLock();
}
private void updateWakeLock() {
PowerManager.WakeLock wakeLock = this.wakeLock;
if (wakeLock == null) {
return;
}
if (this.enabled && this.stayAwake) {
wakeLock.acquire();
} else {
wakeLock.release();
}
}
}