59 lines
2.1 KiB
Java
59 lines
2.1 KiB
Java
|
package o;
|
||
|
|
||
|
import android.content.BroadcastReceiver;
|
||
|
import android.content.ComponentName;
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.os.PowerManager;
|
||
|
import android.util.SparseArray;
|
||
|
|
||
|
@Deprecated
|
||
|
/* loaded from: classes.dex */
|
||
|
public abstract class xsS extends BroadcastReceiver {
|
||
|
private static final String EXTRA_WAKE_LOCK_ID = "androidx.contentpager.content.wakelockid";
|
||
|
private static final SparseArray<PowerManager.WakeLock> sActiveWakeLocks = new SparseArray<>();
|
||
|
private static int mNextId = 1;
|
||
|
|
||
|
public static ComponentName startWakefulService(Context context, Intent intent) {
|
||
|
SparseArray<PowerManager.WakeLock> sparseArray = sActiveWakeLocks;
|
||
|
synchronized (sparseArray) {
|
||
|
int i = mNextId;
|
||
|
int i2 = i + 1;
|
||
|
mNextId = i2;
|
||
|
if (i2 <= 0) {
|
||
|
mNextId = 1;
|
||
|
}
|
||
|
intent.putExtra(EXTRA_WAKE_LOCK_ID, i);
|
||
|
ComponentName startService = context.startService(intent);
|
||
|
if (startService == null) {
|
||
|
return null;
|
||
|
}
|
||
|
PowerManager powerManager = (PowerManager) context.getSystemService("power");
|
||
|
StringBuilder sb = new StringBuilder("androidx.core:wake:");
|
||
|
sb.append(startService.flattenToShortString());
|
||
|
PowerManager.WakeLock newWakeLock = powerManager.newWakeLock(1, sb.toString());
|
||
|
newWakeLock.setReferenceCounted(false);
|
||
|
newWakeLock.acquire(60000L);
|
||
|
sparseArray.put(i, newWakeLock);
|
||
|
return startService;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static boolean completeWakefulIntent(Intent intent) {
|
||
|
int intExtra = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0);
|
||
|
if (intExtra == 0) {
|
||
|
return false;
|
||
|
}
|
||
|
SparseArray<PowerManager.WakeLock> sparseArray = sActiveWakeLocks;
|
||
|
synchronized (sparseArray) {
|
||
|
PowerManager.WakeLock wakeLock = sparseArray.get(intExtra);
|
||
|
if (wakeLock == null) {
|
||
|
return true;
|
||
|
}
|
||
|
wakeLock.release();
|
||
|
sparseArray.remove(intExtra);
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|