private JobCallable(Job job) { mJob = job; Context context = mJob.getContext(); mWakeLock = WakeLockUtil.acquireWakeLock(context, "JobExecutor", WAKE_LOCK_TIMEOUT); }
public static boolean completeWakefulIntent(Intent intent) { return WakeLockUtil.completeWakefulIntent(intent); } }
/** * Finish the execution from a previous {@link #startWakefulService}. Any wake lock * that was being held will now be released. * * @param intent The Intent as originally generated by {@link #startWakefulService}. * @return Returns true if the intent is associated with a wake lock that is * now released; returns false if there was no wake lock specified for it. */ public static boolean completeWakefulIntent(Intent intent) { if (intent == null) { return false; } final int id = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0); if (id == 0) { return false; } synchronized (ACTIVE_WAKE_LOCKS) { releaseWakeLock(ACTIVE_WAKE_LOCKS.get(id)); ACTIVE_WAKE_LOCKS.remove(id); return true; } } }
@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); } }
public static ComponentName startWakefulService(Context context, Intent intent) { return WakeLockUtil.startWakefulService(context, intent); }
@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); } }
public static ComponentName startWakefulService(Context context, Intent intent) { return WakeLockUtil.startWakefulService(context, intent); }
@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; }
public static boolean completeWakefulIntent(Intent intent) { return WakeLockUtil.completeWakefulIntent(intent); } }
/** * Finish the execution from a previous {@link #startWakefulService}. Any wake lock * that was being held will now be released. * * @param intent The Intent as originally generated by {@link #startWakefulService}. * @return Returns true if the intent is associated with a wake lock that is * now released; returns false if there was no wake lock specified for it. */ public static boolean completeWakefulIntent(Intent intent) { if (intent == null) { return false; } final int id = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0); if (id == 0) { return false; } synchronized (ACTIVE_WAKE_LOCKS) { releaseWakeLock(ACTIVE_WAKE_LOCKS.get(id)); ACTIVE_WAKE_LOCKS.remove(id); return true; } } }
PowerManager.WakeLock wakeLock = acquireWakeLock(context, tag, TimeUnit.MINUTES.toMillis(3)); if (wakeLock != null) { ACTIVE_WAKE_LOCKS.put(id, wakeLock);
@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);