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 package android.app;
18 
19 import android.app.job.IJobScheduler;
20 import android.app.job.JobInfo;
21 import android.app.job.JobScheduler;
22 import android.app.job.JobSnapshot;
23 import android.app.job.JobWorkItem;
24 import android.os.RemoteException;
25 
26 import java.util.List;
27 
28 
29 /**
30  * Concrete implementation of the JobScheduler interface
31  *
32  * Note android.app.job is the better package to put this class, but we can't move it there
33  * because that'd break robolectric. Grr.
34  *
35  * @hide
36  */
37 public class JobSchedulerImpl extends JobScheduler {
38     IJobScheduler mBinder;
39 
JobSchedulerImpl(IJobScheduler binder)40     public JobSchedulerImpl(IJobScheduler binder) {
41         mBinder = binder;
42     }
43 
44     @Override
schedule(JobInfo job)45     public int schedule(JobInfo job) {
46         try {
47             return mBinder.schedule(job);
48         } catch (RemoteException e) {
49             return JobScheduler.RESULT_FAILURE;
50         }
51     }
52 
53     @Override
enqueue(JobInfo job, JobWorkItem work)54     public int enqueue(JobInfo job, JobWorkItem work) {
55         try {
56             return mBinder.enqueue(job, work);
57         } catch (RemoteException e) {
58             return JobScheduler.RESULT_FAILURE;
59         }
60     }
61 
62     @Override
scheduleAsPackage(JobInfo job, String packageName, int userId, String tag)63     public int scheduleAsPackage(JobInfo job, String packageName, int userId, String tag) {
64         try {
65             return mBinder.scheduleAsPackage(job, packageName, userId, tag);
66         } catch (RemoteException e) {
67             return JobScheduler.RESULT_FAILURE;
68         }
69     }
70 
71     @Override
cancel(int jobId)72     public void cancel(int jobId) {
73         try {
74             mBinder.cancel(jobId);
75         } catch (RemoteException e) {}
76 
77     }
78 
79     @Override
cancelAll()80     public void cancelAll() {
81         try {
82             mBinder.cancelAll();
83         } catch (RemoteException e) {}
84 
85     }
86 
87     @Override
getAllPendingJobs()88     public List<JobInfo> getAllPendingJobs() {
89         try {
90             return mBinder.getAllPendingJobs().getList();
91         } catch (RemoteException e) {
92             return null;
93         }
94     }
95 
96     @Override
getPendingJob(int jobId)97     public JobInfo getPendingJob(int jobId) {
98         try {
99             return mBinder.getPendingJob(jobId);
100         } catch (RemoteException e) {
101             return null;
102         }
103     }
104 
105     @Override
getStartedJobs()106     public List<JobInfo> getStartedJobs() {
107         try {
108             return mBinder.getStartedJobs();
109         } catch (RemoteException e) {
110             return null;
111         }
112     }
113 
114     @Override
getAllJobSnapshots()115     public List<JobSnapshot> getAllJobSnapshots() {
116         try {
117             return mBinder.getAllJobSnapshots().getList();
118         } catch (RemoteException e) {
119             return null;
120         }
121     }
122 }
123