1 /* 2 * Copyright (C) 2017 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.jobscheduler.cts.jobtestapp; 18 19 import android.app.job.JobParameters; 20 import android.app.job.JobService; 21 import android.content.Intent; 22 import android.util.Log; 23 24 public class TestJobService extends JobService { 25 private static final String TAG = TestJobService.class.getSimpleName(); 26 private static final String PACKAGE_NAME = "android.jobscheduler.cts.jobtestapp"; 27 public static final String ACTION_JOB_STARTED = PACKAGE_NAME + ".action.JOB_STARTED"; 28 public static final String ACTION_JOB_STOPPED = PACKAGE_NAME + ".action.JOB_STOPPED"; 29 public static final String JOB_PARAMS_EXTRA_KEY = PACKAGE_NAME + ".extra.JOB_PARAMETERS"; 30 31 @Override 32 public boolean onStartJob(JobParameters params) { 33 Log.i(TAG, "Test job executing: " + params.getJobId()); 34 final Intent reportJobStartIntent = new Intent(ACTION_JOB_STARTED); 35 reportJobStartIntent.putExtra(JOB_PARAMS_EXTRA_KEY, params); 36 sendBroadcast(reportJobStartIntent); 37 return true; 38 } 39 40 @Override 41 public boolean onStopJob(JobParameters params) { 42 Log.i(TAG, "Test job stopped executing: " + params.getJobId()); 43 final Intent reportJobStopIntent = new Intent(ACTION_JOB_STOPPED); 44 reportJobStopIntent.putExtra(JOB_PARAMS_EXTRA_KEY, params); 45 sendBroadcast(reportJobStopIntent); 46 return true; 47 } 48 } 49