android.app.job.JobWorkItem Java Examples
The following examples show how to use
android.app.job.JobWorkItem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobIntentService.java From titan-hotfix with Apache License 2.0 | 6 votes |
/** * Dequeue some work. */ @Override public JobIntentService.GenericWorkItem dequeueWork() { JobWorkItem work; synchronized (mLock) { if (mParams == null) { return null; } work = mParams.dequeueWork(); } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new WrapperWorkItem(work); } else { return null; } }
Example #2
Source File: JobIntentService.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Dequeue some work. */ @Override public GenericWorkItem dequeueWork() { JobWorkItem work = null; synchronized (mLock) { if (mParams == null) { return null; } try { work = mParams.dequeueWork(); } catch (Throwable ignore) { } } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new JobServiceEngineImpl.WrapperWorkItem(work); } else { return null; } }
Example #3
Source File: JobIntentService.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Dequeue some work. */ @Override public GenericWorkItem dequeueWork() { JobWorkItem work = null; synchronized (mLock) { if (mParams == null) { return null; } try { work = mParams.dequeueWork(); } catch (Throwable ignore) { } } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new JobServiceEngineImpl.WrapperWorkItem(work); } else { return null; } }
Example #4
Source File: AlJobServiceEngineImpl.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Dequeue some work. */ @Override public JobIntentService.GenericWorkItem dequeueWork() { JobWorkItem work = null; synchronized (mLock) { if (mParams == null) { return null; } try { work = mParams.dequeueWork(); } catch (SecurityException se) { //ignore se.printStackTrace(); } } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new WrapperWorkItem(work); } else { return null; } }
Example #5
Source File: SafeJobServiceEngineImpl.java From android-job with Apache License 2.0 | 6 votes |
/** * Dequeue some work. */ @Override public JobIntentService.GenericWorkItem dequeueWork() { JobWorkItem work = null; synchronized (mLock) { if (mParams == null) { return null; } try { work = mParams.dequeueWork(); } catch (SecurityException se) { //ignore se.printStackTrace(); } } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new WrapperWorkItem(work); } else { return null; } }
Example #6
Source File: JobIntentService.java From mobile-messaging-sdk-android with Apache License 2.0 | 6 votes |
/** * Dequeue some work. */ @Override public JobIntentService.GenericWorkItem dequeueWork() { JobWorkItem work; synchronized (mLock) { if (mParams == null) { return null; } try { work = mParams.dequeueWork(); } catch (SecurityException e) { // Issue: https://issuetracker.google.com/issues/63622293 // Caller no longer running, last stopped +###ms because: last work dequeued Log.e(TAG, "Failed to run mParams.dequeueWork()!", e); return null; } } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new WrapperWorkItem(work); } else { return null; } }
Example #7
Source File: JobIntentService.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Dequeue some work. */ @Override public GenericWorkItem dequeueWork() { JobWorkItem work = null; synchronized (mLock) { if (mParams == null) { return null; } try { work = mParams.dequeueWork(); } catch (Throwable ignore) { } } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new JobServiceEngineImpl.WrapperWorkItem(work); } else { return null; } }
Example #8
Source File: JobIntentService.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Dequeue some work. */ @Override public GenericWorkItem dequeueWork() { JobWorkItem work = null; synchronized (mLock) { if (mParams == null) { return null; } try { work = mParams.dequeueWork(); } catch (Throwable ignore) { } } if (work != null) { work.getIntent().setExtrasClassLoader(mService.getClassLoader()); return new JobServiceEngineImpl.WrapperWorkItem(work); } else { return null; } }
Example #9
Source File: JobServiceContext.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
JobWorkItem doDequeueWork(JobCallback cb, int jobId) { final long ident = Binder.clearCallingIdentity(); try { synchronized (mLock) { assertCallerLocked(cb); if (mVerb == VERB_STOPPING || mVerb == VERB_FINISHED) { // This job is either all done, or on its way out. Either way, it // should not dispatch any more work. We will pick up any remaining // work the next time we start the job again. return null; } final JobWorkItem work = mRunningJob.dequeueWorkLocked(); if (work == null && !mRunningJob.hasExecutingWorkLocked()) { // This will finish the job. doCallbackLocked(false, "last work dequeued"); } return work; } } finally { Binder.restoreCallingIdentity(ident); } }
Example #10
Source File: JobSchedulerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public int enqueue(JobInfo job, JobWorkItem work) throws RemoteException { if (DEBUG) { Slog.d(TAG, "Enqueueing job: " + job.toString() + " work: " + work); } final int uid = Binder.getCallingUid(); final int userId = UserHandle.getUserId(uid); enforceValidJobRequest(uid, job); if (job.isPersisted()) { throw new IllegalArgumentException("Can't enqueue work for persisted jobs"); } if (work == null) { throw new NullPointerException("work is null"); } validateJobFlags(job, uid); long ident = Binder.clearCallingIdentity(); try { return JobSchedulerService.this.scheduleAsPackage(job, work, uid, null, userId, null); } finally { Binder.restoreCallingIdentity(ident); } }
Example #11
Source File: MyJobWorkService.java From service with Apache License 2.0 | 5 votes |
@Override protected Void doInBackground(Void... params) { boolean cancelled; JobWorkItem work; /** * Iterate over available work. Once dequeueWork() returns null, the * job's work queue is empty and the job has stopped, so we can let this * async task complete. */ while (!(cancelled=isCancelled()) && (work=mParams.dequeueWork()) != null) { String txt = work.getIntent().getStringExtra("Key1"); Log.i("JobWorkService", "Processing work: " + work + ", msg: " + txt); showNotification(txt); // Process work here... we'll pretend by sleeping. try { Thread.sleep(5000); } catch (InterruptedException e) { } hideNotification(); // Tell system we have finished processing the work. Log.i("JobWorkService", "Done with: " + work); mParams.completeWork(work); } if (cancelled) { Log.i("JobWorkService", "CANCELLED!"); } return null; }
Example #12
Source File: JobWorkService.java From android-sdk with Apache License 2.0 | 5 votes |
private void reschedule(JobWorkItem item) { ServiceScheduler.PendingIntentFactory pendingIntentFactory = new ServiceScheduler .PendingIntentFactory(getApplicationContext()); ServiceScheduler serviceScheduler = new ServiceScheduler(getApplicationContext(), pendingIntentFactory, LoggerFactory.getLogger(ServiceScheduler.class)); Intent intent = item.getIntent(); serviceScheduler.schedule(intent, intent.getLongExtra(INTENT_EXTRA_JWS_PERIODIC, -1)); }
Example #13
Source File: JobWorkService.java From android-sdk with Apache License 2.0 | 5 votes |
private void completeWork(JobParameters jobParameters, JobWorkItem jobWorkItem) { Intent intent = jobWorkItem.getIntent(); if (intent != null && intent.hasExtra(INTENT_EXTRA_JWS_PERIODIC)) { logger.info("Periodic work item completed "); jobParameters.completeWork(jobWorkItem); //reschedule(jobWorkItem); } else { logger.info("work item completed"); jobParameters.completeWork(jobWorkItem); } }
Example #14
Source File: ServiceScheduler.java From android-sdk with Apache License 2.0 | 5 votes |
/** * Start a service either through the context or enqueued to the JobService to be run in a minute. * For example, the BroadcastReceivers use this to handle all versions of the API. * * @param context - Application context * @param jobId - job id for the job to start if it is a job * @param intent - Intent you want to run. */ public static void startService(Context context, Integer jobId, Intent intent) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { JobInfo jobInfo = new JobInfo.Builder(jobId, new ComponentName(context, JobWorkService.class)) // schedule it to run any time between 1 - 5 minutes .setMinimumLatency(JobWorkService.ONE_MINUTE) .setOverrideDeadline(5 * JobWorkService.ONE_MINUTE) .build(); JobScheduler jobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); if (jobScheduler.getAllPendingJobs().stream().filter(job -> job.getId() == jobId && job.getExtras().equals(intent.getExtras())).count() > 0) { // already pending job. don't run again LoggerFactory.getLogger("ServiceScheduler").info("Job already pending"); return; } JobWorkItem jobWorkItem = new JobWorkItem(intent); try { jobScheduler.enqueue(jobInfo, jobWorkItem); } catch (Exception e) { LoggerFactory.getLogger("ServiceScheduler").error("Problem enqueuing work item ", e); } } else { context.startService(intent); } }
Example #15
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public JobWorkItem dequeueWorkLocked() { if (pendingWork != null && pendingWork.size() > 0) { JobWorkItem work = pendingWork.remove(0); if (work != null) { if (executingWork == null) { executingWork = new ArrayList<>(); } executingWork.add(work); work.bumpDeliveryCount(); } updateEstimatedNetworkBytesLocked(); return work; } return null; }
Example #16
Source File: JobIntentService.java From titan-hotfix with Apache License 2.0 | 5 votes |
@Override void enqueueWork(Intent work) { if (DEBUG) { Log.d(TAG, "Enqueueing work: " + work); } mJobScheduler.enqueue(mJobInfo, new JobWorkItem(work)); }
Example #17
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public void enqueueWorkLocked(IActivityManager am, JobWorkItem work) { if (pendingWork == null) { pendingWork = new ArrayList<>(); } work.setWorkId(nextPendingWorkId); nextPendingWorkId++; if (work.getIntent() != null && GrantedUriPermissions.checkGrantFlags(work.getIntent().getFlags())) { work.setGrants(GrantedUriPermissions.createFromIntent(am, work.getIntent(), sourceUid, sourcePackageName, sourceUserId, toShortString())); } pendingWork.add(work); updateEstimatedNetworkBytesLocked(); }
Example #18
Source File: JobSchedulerImpl.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public int enqueue(JobInfo job, JobWorkItem work) { try { return mBinder.enqueue(job, work); } catch (RemoteException e) { return JobScheduler.RESULT_FAILURE; } }
Example #19
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void dumpJobWorkItem(ProtoOutputStream proto, long fieldId, JobWorkItem work) { final long token = proto.start(fieldId); proto.write(JobStatusDumpProto.JobWorkItem.WORK_ID, work.getWorkId()); proto.write(JobStatusDumpProto.JobWorkItem.DELIVERY_COUNT, work.getDeliveryCount()); if (work.getIntent() != null) { work.getIntent().writeToProto(proto, JobStatusDumpProto.JobWorkItem.INTENT); } Object grants = work.getGrants(); if (grants != null) { ((GrantedUriPermissions) grants).dump(proto, JobStatusDumpProto.JobWorkItem.URI_GRANTS); } proto.end(token); }
Example #20
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void dumpJobWorkItem(PrintWriter pw, String prefix, JobWorkItem work, int index) { pw.print(prefix); pw.print(" #"); pw.print(index); pw.print(": #"); pw.print(work.getWorkId()); pw.print(" "); pw.print(work.getDeliveryCount()); pw.print("x "); pw.println(work.getIntent()); if (work.getGrants() != null) { pw.print(prefix); pw.println(" URI grants:"); ((GrantedUriPermissions)work.getGrants()).dump(pw, prefix + " "); } }
Example #21
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void ungrantWorkList(IActivityManager am, ArrayList<JobWorkItem> list) { if (list != null) { final int N = list.size(); for (int i = 0; i < N; i++) { ungrantWorkItem(am, list.get(i)); } } }
Example #22
Source File: JobStatus.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public boolean completeWorkLocked(IActivityManager am, int workId) { if (executingWork != null) { final int N = executingWork.size(); for (int i = 0; i < N; i++) { JobWorkItem work = executingWork.get(i); if (work.getWorkId() == workId) { executingWork.remove(i); ungrantWorkItem(am, work); return true; } } } return false; }
Example #23
Source File: JobIntentService.java From Telegram with GNU General Public License v2.0 | 4 votes |
WrapperWorkItem(JobWorkItem jobWork) { mJobWork = jobWork; }
Example #24
Source File: JobIntentService.java From mobile-messaging-sdk-android with Apache License 2.0 | 4 votes |
@Override void enqueueWork(Intent work) { if (DEBUG) Log.d(TAG, "Enqueueing work: " + work); mJobScheduler.enqueue(mJobInfo, new JobWorkItem(work)); }
Example #25
Source File: JobIntentService.java From titan-hotfix with Apache License 2.0 | 4 votes |
WrapperWorkItem(JobWorkItem jobWork) { mJobWork = jobWork; }
Example #26
Source File: JobIntentService.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override void enqueueWork(Intent work) { if (DEBUG) Log.d(TAG, "Enqueueing work: " + work); mJobScheduler.enqueue(mJobInfo, new JobWorkItem(work)); }
Example #27
Source File: JobIntentService.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
WrapperWorkItem(JobWorkItem jobWork) { mJobWork = jobWork; }
Example #28
Source File: JobServiceContext.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public JobWorkItem dequeueWork(int jobId) { return doDequeueWork(this, jobId); }
Example #29
Source File: JobIntentService.java From Telegram with GNU General Public License v2.0 | 4 votes |
@Override void enqueueWork(Intent work) { if (DEBUG) Log.d(TAG, "Enqueueing work: " + work); mJobScheduler.enqueue(mJobInfo, new JobWorkItem(work)); }
Example #30
Source File: AlJobServiceEngineImpl.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 4 votes |
WrapperWorkItem(JobWorkItem jobWork) { mJobWork = jobWork; }