Sergey Nikolaienkov | 2ad8af1 | 2019-08-26 13:13:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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.restrictions; |
| 18 | |
| 19 | import android.app.job.JobInfo; |
| 20 | import android.util.proto.ProtoOutputStream; |
| 21 | |
| 22 | import com.android.internal.util.IndentingPrintWriter; |
| 23 | import com.android.server.job.JobSchedulerService; |
| 24 | import com.android.server.job.controllers.JobStatus; |
| 25 | |
| 26 | /** |
| 27 | * Used by {@link JobSchedulerService} to impose additional restrictions regarding whether jobs |
| 28 | * should be scheduled or not based on the state of the system/device. |
| 29 | * Every restriction is associated with exactly one reason (from {@link |
| 30 | * android.app.job.JobParameters#JOB_STOP_REASON_CODES}), which could be retrieved using {@link |
| 31 | * #getReason()}. |
| 32 | * Note, that this is not taken into account for the jobs that have priority |
| 33 | * {@link JobInfo#PRIORITY_FOREGROUND_APP} or higher. |
| 34 | */ |
| 35 | public abstract class JobRestriction { |
| 36 | |
| 37 | final JobSchedulerService mService; |
| 38 | private final int mReason; |
| 39 | |
| 40 | JobRestriction(JobSchedulerService service, int reason) { |
| 41 | mService = service; |
| 42 | mReason = reason; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Called when the system boot phase has reached |
| 47 | * {@link com.android.server.SystemService#PHASE_SYSTEM_SERVICES_READY}. |
| 48 | */ |
| 49 | public void onSystemServicesReady() { |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Called by {@link JobSchedulerService} to check if it may proceed with scheduling the job (in |
| 54 | * case all constraints are satisfied and all other {@link JobRestriction}s are fine with it) |
| 55 | * |
| 56 | * @param job to be checked |
| 57 | * @return false if the {@link JobSchedulerService} should not schedule this job at the moment, |
| 58 | * true - otherwise |
| 59 | */ |
| 60 | public abstract boolean isJobRestricted(JobStatus job); |
| 61 | |
| 62 | /** Dump any internal constants the Restriction may have. */ |
| 63 | public abstract void dumpConstants(IndentingPrintWriter pw); |
| 64 | |
| 65 | /** Dump any internal constants the Restriction may have. */ |
| 66 | public abstract void dumpConstants(ProtoOutputStream proto); |
| 67 | |
| 68 | /** @return reason code for the Restriction. */ |
| 69 | public final int getReason() { |
| 70 | return mReason; |
| 71 | } |
| 72 | } |