Rabbit-R1/android (non root)/java/sources/androidx/media3/exoplayer/WifiLockManager.java

53 lines
1.6 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.exoplayer;
import android.content.Context;
import android.net.wifi.WifiManager;
import androidx.media3.common.util.Log;
/* loaded from: classes2.dex */
final class WifiLockManager {
private static final String TAG = "WifiLockManager";
private static final String WIFI_LOCK_TAG = "ExoPlayer:WifiLockManager";
private boolean enabled;
private boolean stayAwake;
private WifiManager.WifiLock wifiLock;
private final WifiManager wifiManager;
public WifiLockManager(Context context) {
this.wifiManager = (WifiManager) context.getApplicationContext().getSystemService("wifi");
}
public void setEnabled(boolean z) {
if (z && this.wifiLock == null) {
WifiManager wifiManager = this.wifiManager;
if (wifiManager == null) {
Log.w(TAG, "WifiManager is null, therefore not creating the WifiLock.");
return;
} else {
WifiManager.WifiLock createWifiLock = wifiManager.createWifiLock(3, WIFI_LOCK_TAG);
this.wifiLock = createWifiLock;
createWifiLock.setReferenceCounted(false);
}
}
this.enabled = z;
updateWifiLock();
}
public void setStayAwake(boolean z) {
this.stayAwake = z;
updateWifiLock();
}
private void updateWifiLock() {
WifiManager.WifiLock wifiLock = this.wifiLock;
if (wifiLock == null) {
return;
}
if (this.enabled && this.stayAwake) {
wifiLock.acquire();
} else {
wifiLock.release();
}
}
}