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