Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 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 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 17 | package com.android.server.job.controllers; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
| 20 | |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 21 | import com.android.server.job.StateChangedListener; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 22 | |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 23 | import java.io.PrintWriter; |
| 24 | |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 25 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 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 |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 28 | * are ready to run, or whether they must be stopped. |
| 29 | */ |
| 30 | public abstract class StateController { |
Georgi Nikolov | 326f230 | 2014-10-08 11:50:50 -0700 | [diff] [blame] | 31 | protected static final boolean DEBUG = false; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 32 | protected Context mContext; |
| 33 | protected StateChangedListener mStateChangedListener; |
| 34 | |
Matthew Williams | 3d86fd2 | 2014-05-16 18:02:17 -0700 | [diff] [blame] | 35 | public StateController(StateChangedListener stateChangedListener, Context context) { |
| 36 | mStateChangedListener = stateChangedListener; |
| 37 | mContext = context; |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /** |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 41 | * Implement the logic here to decide whether a job should be tracked by this controller. |
| 42 | * This logic is put here so the JobManger can be completely agnostic of Controller logic. |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 43 | * Also called when updating a task, so implementing controllers have to be aware of |
| 44 | * preexisting tasks. |
| 45 | */ |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 46 | public abstract void maybeStartTrackingJob(JobStatus jobStatus); |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Remove task - this will happen if the task is cancelled, completed, etc. |
| 49 | */ |
Christopher Tate | 7060b04 | 2014-06-09 19:50:00 -0700 | [diff] [blame] | 50 | public abstract void maybeStopTrackingJob(JobStatus jobStatus); |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 51 | |
Matthew Williams | effacfa | 2014-06-05 20:56:40 -0700 | [diff] [blame] | 52 | public abstract void dumpControllerState(PrintWriter pw); |
| 53 | |
Matthew Williams | 6de79e2 | 2014-05-01 10:47:00 -0700 | [diff] [blame] | 54 | } |