1 /* 2 * Copyright (C) 2021 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.usage.cts; 18 19 import android.app.job.JobInfo; 20 import android.app.job.JobParameters; 21 import android.app.job.JobScheduler; 22 import android.app.job.JobService; 23 import android.content.ComponentName; 24 import android.content.Context; 25 26 import java.util.function.Supplier; 27 28 public final class TestJob extends JobService { 29 30 public static final int TEST_JOB_ID = 1; 31 public static final String NOTIFICATION_CHANNEL_ID = TestJob.class.getSimpleName(); 32 private static boolean sJobStarted; 33 public static Supplier<Boolean> hasJobStarted = () -> sJobStarted; 34 35 @Override onStartJob(JobParameters params)36 public boolean onStartJob(JobParameters params) { 37 sJobStarted = true; 38 return false; 39 } 40 41 @Override onStopJob(JobParameters params)42 public boolean onStopJob(JobParameters params) { 43 return false; 44 } 45 schedule(Context context)46 public static void schedule(Context context) { 47 sJobStarted = false; 48 JobScheduler jobScheduler = context.getSystemService(JobScheduler.class); 49 ComponentName componentName = new ComponentName(context, TestJob.class); 50 51 JobInfo jobInfo = new JobInfo.Builder(TEST_JOB_ID, componentName).build(); 52 jobScheduler.schedule(jobInfo); 53 } 54 } 55