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 package com.android.server.job.controllers; 18 19 import android.content.Context; 20 21 import com.android.server.job.StateChangedListener; 22 23 import java.io.PrintWriter; 24 25 /** 26 * Incorporates shared controller logic between the various controllers of the JobManager. 27 * These are solely responsible for tracking a list of jobs, and notifying the JM when these 28 * are ready to run, or whether they must be stopped. 29 */ 30 public abstract class StateController { 31 protected static final boolean DEBUG = false; 32 protected Context mContext; 33 protected StateChangedListener mStateChangedListener; 34 protected boolean mDeviceIdleMode; 35 36 public StateController(StateChangedListener stateChangedListener, Context context) { 37 mStateChangedListener = stateChangedListener; 38 mContext = context; 39 } 40 41 public void deviceIdleModeChanged(boolean enabled) { 42 mDeviceIdleMode = enabled; 43 } 44 45 /** 46 * Implement the logic here to decide whether a job should be tracked by this controller. 47 * This logic is put here so the JobManager can be completely agnostic of Controller logic. 48 * Also called when updating a task, so implementing controllers have to be aware of 49 * preexisting tasks. 50 */ 51 public abstract void maybeStartTrackingJob(JobStatus jobStatus); 52 /** 53 * Remove task - this will happen if the task is cancelled, completed, etc. 54 */ 55 public abstract void maybeStopTrackingJob(JobStatus jobStatus); 56 57 public abstract void dumpControllerState(PrintWriter pw); 58 } 59