/*package*/ JobProxy getJobProxy(JobApi api) { return api.getProxy(mContext); }
/*package*/ Set<JobRequest> getAllJobRequests(@Nullable String tag, boolean includeStarted, boolean cleanUpTransient) { Set<JobRequest> requests = getJobStorage().getAllJobRequests(tag, includeStarted); if (cleanUpTransient) { Iterator<JobRequest> iterator = requests.iterator(); while (iterator.hasNext()) { JobRequest request = iterator.next(); if (request.isTransient() && !request.getJobApi().getProxy(mContext).isPlatformJobScheduled(request)) { getJobStorage().remove(request); iterator.remove(); } } } return requests; }
/*package*/ static void cleanUpOrphanedJob(Context context, int jobId) { /* * That's necessary if the database was deleted and jobs (especially the JobScheduler) are still around. * Then if a new job is being scheduled, it's possible that the new job has the ID of the old one. Here * we make sure, that no job is left in the system. */ for (JobApi jobApi : JobApi.values()) { if (jobApi.isSupported(context)) { try { jobApi.getProxy(context).cancel(jobId); } catch (Exception ignored) { // GCM API could crash if it's disabled, ignore crashes at this point and continue } } } }
/** * @param jobId The unique ID of the pending {@link JobRequest}. * @return The {@link JobRequest} if it's pending or {@code null} otherwise. */ public JobRequest getJobRequest(int jobId) { JobRequest request = getJobRequest(jobId, false); if (request != null && request.isTransient() && !request.getJobApi().getProxy(mContext).isPlatformJobScheduled(request)) { getJobStorage().remove(request); return null; } else { return request; } }
/*package*/ JobProxy getJobProxy(JobApi api) { return api.getProxy(mContext); }
/*package*/ Set<JobRequest> getAllJobRequests(@Nullable String tag, boolean includeStarted, boolean cleanUpTransient) { Set<JobRequest> requests = mJobStorage.getAllJobRequests(tag, includeStarted); if (cleanUpTransient) { Iterator<JobRequest> iterator = requests.iterator(); while (iterator.hasNext()) { JobRequest request = iterator.next(); if (request.isTransient() && !request.getJobApi().getProxy(mContext).isPlatformJobScheduled(request)) { mJobStorage.remove(request); iterator.remove(); } } } return requests; }
/*package*/ static void cleanUpOrphanedJob(Context context, int jobId) { /* * That's necessary if the database was deleted and jobs (especially the JobScheduler) are still around. * Then if a new job is being scheduled, it's possible that the new job has the ID of the old one. Here * we make sure, that no job is left in the system. */ for (JobApi jobApi : JobApi.values()) { if (jobApi.isSupported(context)) { try { jobApi.getProxy(context).cancel(jobId); } catch (Exception ignored) { // GCM API could crash if it's disabled, ignore crashes at this point and continue } } } }
/** * @param jobId The unique ID of the pending {@link JobRequest}. * @return The {@link JobRequest} if it's pending or {@code null} otherwise. */ public JobRequest getJobRequest(int jobId) { JobRequest request = getJobRequest(jobId, false); if (request != null && request.isTransient() && !request.getJobApi().getProxy(mContext).isPlatformJobScheduled(request)) { getJobStorage().remove(request); return null; } else { return request; } }