Avoid unnecessary getSystemService call on WifiLockManager and WakeLockManager if not enabled
This commit is contained in:
parent
be2d68c2b3
commit
2ee69cb1f9
@ -32,15 +32,13 @@ import androidx.media3.common.util.Log;
|
||||
|
||||
private static final String TAG = "WakeLockManager";
|
||||
private static final String WAKE_LOCK_TAG = "ExoPlayer:WakeLockManager";
|
||||
|
||||
@Nullable private final PowerManager powerManager;
|
||||
@Nullable private WakeLock wakeLock;
|
||||
private boolean enabled;
|
||||
private boolean stayAwake;
|
||||
private final Context applicationContext;
|
||||
|
||||
public WakeLockManager(Context context) {
|
||||
powerManager =
|
||||
(PowerManager) context.getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||
applicationContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,6 +54,8 @@ import androidx.media3.common.util.Log;
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (enabled) {
|
||||
if (wakeLock == null) {
|
||||
final PowerManager powerManager =
|
||||
(PowerManager) applicationContext.getSystemService(Context.POWER_SERVICE);
|
||||
if (powerManager == null) {
|
||||
Log.w(TAG, "PowerManager is null, therefore not creating the WakeLock.");
|
||||
return;
|
||||
|
@ -31,15 +31,13 @@ import androidx.media3.common.util.Log;
|
||||
|
||||
private static final String TAG = "WifiLockManager";
|
||||
private static final String WIFI_LOCK_TAG = "ExoPlayer:WifiLockManager";
|
||||
|
||||
@Nullable private final WifiManager wifiManager;
|
||||
@Nullable private WifiLock wifiLock;
|
||||
private boolean enabled;
|
||||
private boolean stayAwake;
|
||||
private Context applicationContext;
|
||||
|
||||
public WifiLockManager(Context context) {
|
||||
wifiManager =
|
||||
(WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
applicationContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,6 +52,9 @@ import androidx.media3.common.util.Log;
|
||||
*/
|
||||
public void setEnabled(boolean enabled) {
|
||||
if (enabled && wifiLock == null) {
|
||||
final WifiManager wifiManager =
|
||||
(WifiManager) applicationContext.getApplicationContext()
|
||||
.getSystemService(Context.WIFI_SERVICE);
|
||||
if (wifiManager == null) {
|
||||
Log.w(TAG, "WifiManager is null, therefore not creating the WifiLock.");
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user