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