16de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams/* 26de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * Copyright (C) 2014 The Android Open Source Project 36de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * 46de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * Licensed under the Apache License, Version 2.0 (the "License"); 56de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * you may not use this file except in compliance with the License. 66de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * You may obtain a copy of the License at 76de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * 86de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * http://www.apache.org/licenses/LICENSE-2.0 96de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * 106de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * Unless required by applicable law or agreed to in writing, software 116de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * distributed under the License is distributed on an "AS IS" BASIS, 126de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * See the License for the specific language governing permissions and 146de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * limitations under the License 156de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams */ 166de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 177060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tatepackage com.android.server.job.controllers; 186de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 196de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williamsimport android.content.Context; 206de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 217060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tateimport com.android.server.job.JobSchedulerService; 227060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tateimport com.android.server.job.StateChangedListener; 236de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 24effacfa75bd9c2ebc889a7bc4f002c07f82f4c31Matthew Williamsimport java.io.PrintWriter; 25effacfa75bd9c2ebc889a7bc4f002c07f82f4c31Matthew Williams 266de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams/** 277060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * Incorporates shared controller logic between the various controllers of the JobManager. 287060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * These are solely responsible for tracking a list of jobs, and notifying the JM when these 296de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * are ready to run, or whether they must be stopped. 306de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams */ 316de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williamspublic abstract class StateController { 32326f230ceba67a9b72d2606f7c503bef6f938dddGeorgi Nikolov protected static final boolean DEBUG = false; 336de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams protected Context mContext; 346de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams protected StateChangedListener mStateChangedListener; 356de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 363d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams public StateController(StateChangedListener stateChangedListener, Context context) { 373d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams mStateChangedListener = stateChangedListener; 383d86fd2bb9db6067c49634bc4c6cdb4d5235ad36Matthew Williams mContext = context; 396de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams } 406de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 416de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams /** 427060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * Implement the logic here to decide whether a job should be tracked by this controller. 437060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate * This logic is put here so the JobManger can be completely agnostic of Controller logic. 446de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * Also called when updating a task, so implementing controllers have to be aware of 456de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * preexisting tasks. 466de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams */ 477060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public abstract void maybeStartTrackingJob(JobStatus jobStatus); 486de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams /** 496de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams * Remove task - this will happen if the task is cancelled, completed, etc. 506de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams */ 517060b04f6d92351b67222e636ab378a0273bf3e7Christopher Tate public abstract void maybeStopTrackingJob(JobStatus jobStatus); 526de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams 53effacfa75bd9c2ebc889a7bc4f002c07f82f4c31Matthew Williams public abstract void dumpControllerState(PrintWriter pw); 54effacfa75bd9c2ebc889a7bc4f002c07f82f4c31Matthew Williams 556de79e2b17fa0796ea4d39fd9555b563c484248dMatthew Williams} 56