Home | History | Annotate | Download | only in app
      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.JobInfo;
     21 import android.app.job.JobScheduler;
     22 import android.app.job.IJobScheduler;
     23 import android.app.job.JobWorkItem;
     24 import android.content.Intent;
     25 import android.os.RemoteException;
     26 
     27 import java.util.List;
     28 
     29 
     30 /**
     31  * Concrete implementation of the JobScheduler interface
     32  * @hide
     33  */
     34 public class JobSchedulerImpl extends JobScheduler {
     35     IJobScheduler mBinder;
     36 
     37     /* package */ JobSchedulerImpl(IJobScheduler binder) {
     38         mBinder = binder;
     39     }
     40 
     41     @Override
     42     public int schedule(JobInfo job) {
     43         try {
     44             return mBinder.schedule(job);
     45         } catch (RemoteException e) {
     46             return JobScheduler.RESULT_FAILURE;
     47         }
     48     }
     49 
     50     @Override
     51     public int enqueue(JobInfo job, JobWorkItem work) {
     52         try {
     53             return mBinder.enqueue(job, work);
     54         } catch (RemoteException e) {
     55             return JobScheduler.RESULT_FAILURE;
     56         }
     57     }
     58 
     59     @Override
     60     public int scheduleAsPackage(JobInfo job, String packageName, int userId, String tag) {
     61         try {
     62             return mBinder.scheduleAsPackage(job, packageName, userId, tag);
     63         } catch (RemoteException e) {
     64             return JobScheduler.RESULT_FAILURE;
     65         }
     66     }
     67 
     68     @Override
     69     public void cancel(int jobId) {
     70         try {
     71             mBinder.cancel(jobId);
     72         } catch (RemoteException e) {}
     73 
     74     }
     75 
     76     @Override
     77     public void cancelAll() {
     78         try {
     79             mBinder.cancelAll();
     80         } catch (RemoteException e) {}
     81 
     82     }
     83 
     84     @Override
     85     public List<JobInfo> getAllPendingJobs() {
     86         try {
     87             return mBinder.getAllPendingJobs();
     88         } catch (RemoteException e) {
     89             return null;
     90         }
     91     }
     92 
     93     @Override
     94     public JobInfo getPendingJob(int jobId) {
     95         try {
     96             return mBinder.getPendingJob(jobId);
     97         } catch (RemoteException e) {
     98             return null;
     99         }
    100     }
    101 }
    102