1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 // in android.app so ContextImpl has package access 18 package android.app; 19 20 import android.app.job.IJobScheduler; 21 import android.app.job.JobInfo; 22 import android.app.job.JobScheduler; 23 import android.app.job.JobSnapshot; 24 import android.app.job.JobWorkItem; 25 import android.os.RemoteException; 26 27 import java.util.List; 28 29 /** 30 * Concrete implementation of the JobScheduler interface 31 * @hide 32 */ 33 public class JobSchedulerImpl extends JobScheduler { 34 IJobScheduler mBinder; 35 JobSchedulerImpl(IJobScheduler binder)36 /* package */ JobSchedulerImpl(IJobScheduler binder) { 37 mBinder = binder; 38 } 39 40 @Override schedule(JobInfo job)41 public int schedule(JobInfo job) { 42 try { 43 return mBinder.schedule(job); 44 } catch (RemoteException e) { 45 return JobScheduler.RESULT_FAILURE; 46 } 47 } 48 49 @Override enqueue(JobInfo job, JobWorkItem work)50 public int enqueue(JobInfo job, JobWorkItem work) { 51 try { 52 return mBinder.enqueue(job, work); 53 } catch (RemoteException e) { 54 return JobScheduler.RESULT_FAILURE; 55 } 56 } 57 58 @Override scheduleAsPackage(JobInfo job, String packageName, int userId, String tag)59 public int scheduleAsPackage(JobInfo job, String packageName, int userId, String tag) { 60 try { 61 return mBinder.scheduleAsPackage(job, packageName, userId, tag); 62 } catch (RemoteException e) { 63 return JobScheduler.RESULT_FAILURE; 64 } 65 } 66 67 @Override cancel(int jobId)68 public void cancel(int jobId) { 69 try { 70 mBinder.cancel(jobId); 71 } catch (RemoteException e) {} 72 73 } 74 75 @Override cancelAll()76 public void cancelAll() { 77 try { 78 mBinder.cancelAll(); 79 } catch (RemoteException e) {} 80 81 } 82 83 @Override getAllPendingJobs()84 public List<JobInfo> getAllPendingJobs() { 85 try { 86 return mBinder.getAllPendingJobs().getList(); 87 } catch (RemoteException e) { 88 return null; 89 } 90 } 91 92 @Override getPendingJob(int jobId)93 public JobInfo getPendingJob(int jobId) { 94 try { 95 return mBinder.getPendingJob(jobId); 96 } catch (RemoteException e) { 97 return null; 98 } 99 } 100 101 @Override getStartedJobs()102 public List<JobInfo> getStartedJobs() { 103 try { 104 return mBinder.getStartedJobs(); 105 } catch (RemoteException e) { 106 return null; 107 } 108 } 109 110 @Override getAllJobSnapshots()111 public List<JobSnapshot> getAllJobSnapshots() { 112 try { 113 return mBinder.getAllJobSnapshots().getList(); 114 } catch (RemoteException e) { 115 return null; 116 } 117 } 118 } 119