/** * Global switch to enable or disable printing log messages to Logcat. * * @param enabled Whether or not to print all log messages. The default value is {@code true}. */ public static void setLogcatEnabled(boolean enabled) { JobCat.setLogcatEnabled(enabled); }
/** * @param context Any context. * @return Whether the package has the WAKE_LOCK permission. */ public static boolean hasWakeLockPermission(Context context) { return hasPermission(context, Manifest.permission.WAKE_LOCK, 0); }
/** * @return Whether logging is enabled for this library. The default value is {@code true}. */ public static boolean isLogcatEnabled() { return JobCat.isLogcatEnabled(); }
protected void plantOneOffFlexSupport(JobRequest request, AlarmManager alarmManager, PendingIntent pendingIntent) { long triggerAtMs = JobConfig.getClock().currentTimeMillis() + Common.getAverageDelayMsSupportFlex(request); alarmManager.set(AlarmManager.RTC, triggerAtMs, pendingIntent); mCat.d("Scheduled repeating alarm (flex support), %s, interval %s, flex %s", request, JobUtil.timeToString(request.getIntervalMs()), JobUtil.timeToString(request.getFlexMs())); }
private void logScheduled(JobRequest request) { mCat.d("Scheduled alarm, %s, delay %s (from now), exact %b, reschedule count %d", request, JobUtil.timeToString(Common.getAverageDelayMs(request)), request.isExact(), Common.getRescheduleCount(request)); }
private static boolean hasPermission(Context context, String permission, int repeatCount) { try { return PackageManager.PERMISSION_GRANTED == context.getPackageManager() .checkPermission(permission, context.getPackageName()); } catch (Exception e) { CAT.e(e); // crash https://gist.github.com/vRallev/6affe17c93e993681bfd // give it another chance with the application context return repeatCount < 1 && hasPermission(context.getApplicationContext(), permission, repeatCount + 1); } } }
/** * @return Whether the battery not low requirement is met. That's true either if it's not a requirement * or if the battery actually isn't low. The battery is low, if less than 15% are left and the device isn't * charging. */ protected boolean isRequirementBatteryNotLowMet() { return !(getParams().getRequest().requiresBatteryNotLow() && Device.getBatteryStatus(getContext()).isBatteryLow()); }
/** * @return {@code false} if the {@link Job} requires the device to be charging and it isn't charging. * Otherwise always returns {@code true}. */ protected boolean isRequirementChargingMet() { return !(getParams().getRequest().requiresCharging() && !Device.getBatteryStatus(getContext()).isCharging()); }
protected JobProxy14(Context context, String logTag) { mContext = context; mCat = new JobCat(logTag); }
@Override public void plantPeriodicFlexSupport(JobRequest request) { mCat.w("plantPeriodicFlexSupport called although flex is supported"); super.plantPeriodicFlexSupport(request); }
/** * Add a global logger for the job library, which will be notified about each log statement. * * @param logger Your desired logger. * @return {@code true} if the logger was added. Returns {@code false} if the logger was * already added. */ public static synchronized boolean addLogger(@NonNull JobLogger logger) { return JobCat.addLogger(logger); }
/** * Remove a global logger. * * @param logger Your desired logger. * @see #addLogger(JobLogger) */ public static synchronized void removeLogger(@NonNull JobLogger logger) { JobCat.removeLogger(logger); }
/** * Overrides the executor service for all parallel execution. This could be helpful for Espresso * tests. * * @param executorService The new executor service. */ public static void setExecutorService(@NonNull ExecutorService executorService) { JobConfig.executorService = JobPreconditions.checkNotNull(executorService); }
/** * Adds an offset to the job IDs. Job IDs are generated and usually start with 1. This offset shifts the * very first job ID. * * @param jobIdOffset The offset for the very first job ID. */ public static void setJobIdOffset(int jobIdOffset) { JobPreconditions.checkArgumentNonnegative(jobIdOffset, "offset can't be negative"); if (jobIdOffset > JobIdsInternal.RESERVED_JOB_ID_RANGE_START - 500) { throw new IllegalArgumentException("offset is too close to Integer.MAX_VALUE"); } JobConfig.jobIdOffset = jobIdOffset; }
@Override protected void plantOneOffInexact(JobRequest request, AlarmManager alarmManager, PendingIntent pendingIntent) { long currentTime = System.currentTimeMillis(); long startMs = currentTime + Common.getStartMs(request); long lengthMs = Common.getEndMs(request) - Common.getStartMs(request); alarmManager.setWindow(AlarmManager.RTC, startMs, lengthMs, pendingIntent); mCat.d("Schedule alarm, %s, start %s, end %s", request, JobUtil.timeToString(Common.getStartMs(request)), JobUtil.timeToString(Common.getEndMs(request))); }
@After public void resetValue() { JobCat.setLogcatEnabled(true); mResetValueCalled = true; }
protected JobProxy21(Context context, String logTag) { mContext = context; mCat = new JobCat(logTag); }
@Override public void plantPeriodicFlexSupport(JobRequest request) { CAT.w("plantPeriodicFlexSupport called although flex is supported"); plantPeriodic(request); }
/** * @param context Any context. * @return Whether the package has the RECEIVE_BOOT_COMPLETED permission. */ public static boolean hasBootPermission(Context context) { return hasPermission(context, Manifest.permission.RECEIVE_BOOT_COMPLETED, 0); }
@Override public void plantPeriodic(JobRequest request) { PendingIntent pendingIntent = getPendingIntent(request, true); AlarmManager alarmManager = getAlarmManager(); if (alarmManager != null) { alarmManager.setRepeating(getType(true), getTriggerAtMillis(request), request.getIntervalMs(), pendingIntent); } mCat.d("Scheduled repeating alarm, %s, interval %s", request, JobUtil.timeToString(request.getIntervalMs())); }