Shreyas Basarge | cbf5ae9 | 2016-03-08 16:13:06 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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; |
| 18 | |
Christopher Tate | 435c2f4 | 2018-01-18 12:59:15 -0800 | [diff] [blame] | 19 | import android.annotation.UserIdInt; |
Shreyas Basarge | cbf5ae9 | 2016-03-08 16:13:06 +0000 | [diff] [blame] | 20 | import android.app.job.JobInfo; |
| 21 | |
| 22 | import java.util.List; |
| 23 | |
| 24 | /** |
| 25 | * JobScheduler local system service interface. |
| 26 | * {@hide} Only for use within the system server. |
| 27 | */ |
| 28 | public interface JobSchedulerInternal { |
| 29 | |
Christopher Tate | a732f01 | 2017-10-26 17:26:53 -0700 | [diff] [blame] | 30 | // Bookkeeping about app standby bucket scheduling |
| 31 | |
| 32 | /** |
| 33 | * The current bucket heartbeat ordinal |
| 34 | */ |
| 35 | long currentHeartbeat(); |
| 36 | |
| 37 | /** |
| 38 | * Heartbeat ordinal at which the given standby bucket's jobs next become runnable |
| 39 | */ |
| 40 | long nextHeartbeatForBucket(int bucket); |
| 41 | |
Shreyas Basarge | cbf5ae9 | 2016-03-08 16:13:06 +0000 | [diff] [blame] | 42 | /** |
Christopher Tate | 435c2f4 | 2018-01-18 12:59:15 -0800 | [diff] [blame] | 43 | * Heartbeat ordinal for the given app. This is typically the heartbeat at which |
| 44 | * the app last ran jobs, so that a newly-scheduled job in an app that hasn't run |
| 45 | * jobs in a long time is immediately runnable even if the app is bucketed into |
| 46 | * an infrequent time allocation. |
| 47 | */ |
| 48 | public long baseHeartbeatForApp(String packageName, @UserIdInt int userId, int appBucket); |
| 49 | |
| 50 | /** |
Christopher Tate | 325768c | 2018-03-07 16:07:56 -0800 | [diff] [blame] | 51 | * Tell the scheduler when a JobServiceContext starts running a job in an app |
| 52 | */ |
| 53 | void noteJobStart(String packageName, int userId); |
| 54 | |
| 55 | /** |
Shreyas Basarge | cbf5ae9 | 2016-03-08 16:13:06 +0000 | [diff] [blame] | 56 | * Returns a list of pending jobs scheduled by the system service. |
| 57 | */ |
| 58 | List<JobInfo> getSystemScheduledPendingJobs(); |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
Christopher Tate | 1d99c39 | 2017-12-07 16:54:04 -0800 | [diff] [blame] | 61 | * Cancel the jobs for a given uid (e.g. when app data is cleared) |
| 62 | */ |
| 63 | void cancelJobsForUid(int uid, String reason); |
| 64 | |
| 65 | /** |
Dianne Hackborn | f9bac16 | 2017-04-20 17:17:48 -0700 | [diff] [blame] | 66 | * These are for activity manager to communicate to use what is currently performing backups. |
| 67 | */ |
| 68 | void addBackingUpUid(int uid); |
| 69 | void removeBackingUpUid(int uid); |
| 70 | void clearAllBackingUpUids(); |
Makoto Onuki | dd4b14f | 2017-08-17 14:03:48 -0700 | [diff] [blame] | 71 | |
Christopher Tate | d117b29 | 2018-01-05 17:32:36 -0800 | [diff] [blame] | 72 | /** |
| 73 | * The user has started interacting with the app. Take any appropriate action. |
| 74 | */ |
| 75 | void reportAppUsage(String packageName, int userId); |
| 76 | |
| 77 | /** |
| 78 | * Report a snapshot of sync-related jobs back to the sync manager |
| 79 | */ |
Makoto Onuki | e7b0298 | 2017-08-24 14:23:36 -0700 | [diff] [blame] | 80 | JobStorePersistStats getPersistStats(); |
| 81 | |
Makoto Onuki | dd4b14f | 2017-08-17 14:03:48 -0700 | [diff] [blame] | 82 | /** |
Makoto Onuki | e7b0298 | 2017-08-24 14:23:36 -0700 | [diff] [blame] | 83 | * Stats about the first load after boot and the most recent save. |
Makoto Onuki | dd4b14f | 2017-08-17 14:03:48 -0700 | [diff] [blame] | 84 | */ |
Makoto Onuki | e7b0298 | 2017-08-24 14:23:36 -0700 | [diff] [blame] | 85 | public class JobStorePersistStats { |
| 86 | public int countAllJobsLoaded = -1; |
| 87 | public int countSystemServerJobsLoaded = -1; |
| 88 | public int countSystemSyncManagerJobsLoaded = -1; |
| 89 | |
| 90 | public int countAllJobsSaved = -1; |
| 91 | public int countSystemServerJobsSaved = -1; |
| 92 | public int countSystemSyncManagerJobsSaved = -1; |
| 93 | |
| 94 | public JobStorePersistStats() { |
| 95 | } |
| 96 | |
| 97 | public JobStorePersistStats(JobStorePersistStats source) { |
| 98 | countAllJobsLoaded = source.countAllJobsLoaded; |
| 99 | countSystemServerJobsLoaded = source.countSystemServerJobsLoaded; |
| 100 | countSystemSyncManagerJobsLoaded = source.countSystemSyncManagerJobsLoaded; |
| 101 | |
| 102 | countAllJobsSaved = source.countAllJobsSaved; |
| 103 | countSystemServerJobsSaved = source.countSystemServerJobsSaved; |
| 104 | countSystemSyncManagerJobsSaved = source.countSystemSyncManagerJobsSaved; |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public String toString() { |
| 109 | return "FirstLoad: " |
| 110 | + countAllJobsLoaded + "/" |
| 111 | + countSystemServerJobsLoaded + "/" |
| 112 | + countSystemSyncManagerJobsLoaded |
| 113 | + " LastSave: " |
| 114 | + countAllJobsSaved + "/" |
| 115 | + countSystemServerJobsSaved + "/" |
| 116 | + countSystemSyncManagerJobsSaved; |
| 117 | } |
| 118 | } |
Shreyas Basarge | cbf5ae9 | 2016-03-08 16:13:06 +0000 | [diff] [blame] | 119 | } |