private JobCallable(Job job) { mJob = job; Context context = mJob.getContext(); mWakeLock = WakeLockUtil.acquireWakeLock(context, "JobExecutor", WAKE_LOCK_TIMEOUT); }
@SuppressWarnings("SameParameterValue") @Nullable static PowerManager.WakeLock acquireWakeLock(@NonNull Context context, @NonNull String tag, long timeoutMillis) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag); wakeLock.setReferenceCounted(false); return acquireWakeLock(context, wakeLock, timeoutMillis) ? wakeLock : null; }
PowerManager.WakeLock wakeLock = acquireWakeLock(context, tag, TimeUnit.MINUTES.toMillis(3)); if (wakeLock != null) { ACTIVE_WAKE_LOCKS.put(id, wakeLock);
@Override public Job.Result call() throws Exception { try { // just in case something was blocking and the wake lock is no longer acquired WakeLockUtil.acquireWakeLock(mJob.getContext(), mWakeLock, WAKE_LOCK_TIMEOUT); return runJob(); } finally { markJobAsFinished(mJob); if (mWakeLock == null || !mWakeLock.isHeld()) { CAT.w("Wake lock was not held after job %s was done. The job took too long to complete. This could have unintended side effects on your app.", mJob); } WakeLockUtil.releaseWakeLock(mWakeLock); } }
@SuppressWarnings("SameParameterValue") @Nullable static PowerManager.WakeLock acquireWakeLock(@NonNull Context context, @NonNull String tag, long timeoutMillis) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, tag); wakeLock.setReferenceCounted(false); return acquireWakeLock(context, wakeLock, timeoutMillis) ? wakeLock : null; }
private JobCallable(Job job) { mJob = job; Context context = mJob.getContext(); mWakeLock = WakeLockUtil.acquireWakeLock(context, "JobExecutor", WAKE_LOCK_TIMEOUT); }
PowerManager.WakeLock wakeLock = acquireWakeLock(context, tag, TimeUnit.MINUTES.toMillis(3)); if (wakeLock != null) { ACTIVE_WAKE_LOCKS.put(id, wakeLock);
@Override public Job.Result call() throws Exception { try { // just in case something was blocking and the wake lock is no longer acquired WakeLockUtil.acquireWakeLock(mJob.getContext(), mWakeLock, WAKE_LOCK_TIMEOUT); return runJob(); } finally { markJobAsFinished(mJob); if (mWakeLock == null || !mWakeLock.isHeld()) { CAT.w("Wake lock was not held after job %s was done. The job took too long to complete. This could have unintended side effects on your app.", mJob); } WakeLockUtil.releaseWakeLock(mWakeLock); } }