blob: d3055e6fa252927111cf0286bab77e22ce803bbd [file] [log] [blame]
Matthew Williams6de79e22014-05-01 10:47:00 -07001/*
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 Tate7060b042014-06-09 19:50:00 -070017package com.android.server.job.controllers;
Matthew Williams6de79e22014-05-01 10:47:00 -070018
19import android.content.Context;
Kweku Adams85f2fbc2017-12-18 12:04:12 -080020import android.util.proto.ProtoOutputStream;
Matthew Williams6de79e22014-05-01 10:47:00 -070021
Matthew Williamsfa8e5082015-10-15 15:59:12 -070022import com.android.server.job.JobSchedulerService;
Christopher Tate7060b042014-06-09 19:50:00 -070023import com.android.server.job.StateChangedListener;
Matthew Williams6de79e22014-05-01 10:47:00 -070024
Matthew Williamseffacfa2014-06-05 20:56:40 -070025import java.io.PrintWriter;
26
Matthew Williams6de79e22014-05-01 10:47:00 -070027/**
Christopher Tate7060b042014-06-09 19:50:00 -070028 * Incorporates shared controller logic between the various controllers of the JobManager.
29 * These are solely responsible for tracking a list of jobs, and notifying the JM when these
Matthew Williams6de79e22014-05-01 10:47:00 -070030 * are ready to run, or whether they must be stopped.
31 */
32public abstract class StateController {
Matthew Williamsfa8e5082015-10-15 15:59:12 -070033 protected static final boolean DEBUG = JobSchedulerService.DEBUG;
Dianne Hackborn33d31c52016-02-16 10:30:33 -080034 protected final Context mContext;
35 protected final Object mLock;
36 protected final StateChangedListener mStateChangedListener;
Matthew Williams6de79e22014-05-01 10:47:00 -070037
Dianne Hackborn33d31c52016-02-16 10:30:33 -080038 public StateController(StateChangedListener stateChangedListener, Context context,
39 Object lock) {
Matthew Williams3d86fd22014-05-16 18:02:17 -070040 mStateChangedListener = stateChangedListener;
41 mContext = context;
Dianne Hackborn33d31c52016-02-16 10:30:33 -080042 mLock = lock;
Matthew Williams6de79e22014-05-01 10:47:00 -070043 }
44
45 /**
Christopher Tate7060b042014-06-09 19:50:00 -070046 * Implement the logic here to decide whether a job should be tracked by this controller.
Amith Yamasanib0ff3222015-03-04 09:56:14 -080047 * This logic is put here so the JobManager can be completely agnostic of Controller logic.
Matthew Williams6de79e22014-05-01 10:47:00 -070048 * Also called when updating a task, so implementing controllers have to be aware of
49 * preexisting tasks.
50 */
Dianne Hackbornb0001f62016-02-16 10:30:33 -080051 public abstract void maybeStartTrackingJobLocked(JobStatus jobStatus, JobStatus lastJob);
Dianne Hackborn1a30bd92016-01-11 11:05:00 -080052 /**
53 * Optionally implement logic here to prepare the job to be executed.
54 */
Dianne Hackbornb0001f62016-02-16 10:30:33 -080055 public void prepareForExecutionLocked(JobStatus jobStatus) {
Dianne Hackborn1a30bd92016-01-11 11:05:00 -080056 }
Matthew Williams6de79e22014-05-01 10:47:00 -070057 /**
58 * Remove task - this will happen if the task is cancelled, completed, etc.
59 */
Dianne Hackborn141f11c2016-04-05 15:46:12 -070060 public abstract void maybeStopTrackingJobLocked(JobStatus jobStatus, JobStatus incomingJob,
61 boolean forUpdate);
Dianne Hackborn1a30bd92016-01-11 11:05:00 -080062 /**
63 * Called when a new job is being created to reschedule an old failed job.
64 */
Dianne Hackborn7da13d72017-04-04 17:17:35 -070065 public void rescheduleForFailureLocked(JobStatus newJob, JobStatus failureToReschedule) {
Dianne Hackborn1a30bd92016-01-11 11:05:00 -080066 }
Matthew Williams6de79e22014-05-01 10:47:00 -070067
Dianne Hackbornef3aa6e2016-04-29 18:18:08 -070068 public abstract void dumpControllerStateLocked(PrintWriter pw, int filterUid);
Kweku Adams85f2fbc2017-12-18 12:04:12 -080069 public abstract void dumpControllerStateLocked(ProtoOutputStream proto, long fieldId,
70 int filterUid);
Matthew Williams6de79e22014-05-01 10:47:00 -070071}