• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 import android.annotation.UserIdInt;
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 
30     // Bookkeeping about app standby bucket scheduling
31 
32     /**
33      * The current bucket heartbeat ordinal
34      */
currentHeartbeat()35     long currentHeartbeat();
36 
37     /**
38      * Heartbeat ordinal at which the given standby bucket's jobs next become runnable
39      */
nextHeartbeatForBucket(int bucket)40     long nextHeartbeatForBucket(int bucket);
41 
42     /**
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      */
baseHeartbeatForApp(String packageName, @UserIdInt int userId, int appBucket)48     public long baseHeartbeatForApp(String packageName, @UserIdInt int userId, int appBucket);
49 
50     /**
51      * Tell the scheduler when a JobServiceContext starts running a job in an app
52      */
noteJobStart(String packageName, int userId)53     void noteJobStart(String packageName, int userId);
54 
55     /**
56      * Returns a list of pending jobs scheduled by the system service.
57      */
getSystemScheduledPendingJobs()58     List<JobInfo> getSystemScheduledPendingJobs();
59 
60     /**
61      * Cancel the jobs for a given uid (e.g. when app data is cleared)
62      */
cancelJobsForUid(int uid, String reason)63     void cancelJobsForUid(int uid, String reason);
64 
65     /**
66      * These are for activity manager to communicate to use what is currently performing backups.
67      */
addBackingUpUid(int uid)68     void addBackingUpUid(int uid);
removeBackingUpUid(int uid)69     void removeBackingUpUid(int uid);
clearAllBackingUpUids()70     void clearAllBackingUpUids();
71 
72     /**
73      * The user has started interacting with the app.  Take any appropriate action.
74      */
reportAppUsage(String packageName, int userId)75     void reportAppUsage(String packageName, int userId);
76 
77     /**
78      * Report a snapshot of sync-related jobs back to the sync manager
79      */
getPersistStats()80     JobStorePersistStats getPersistStats();
81 
82     /**
83      * Stats about the first load after boot and the most recent save.
84      */
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 
JobStorePersistStats()94         public JobStorePersistStats() {
95         }
96 
JobStorePersistStats(JobStorePersistStats source)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
toString()108         public String toString() {
109             return "FirstLoad: "
110                     + countAllJobsLoaded + "/"
111                     + countSystemServerJobsLoaded + "/"
112                     + countSystemSyncManagerJobsLoaded
113                     + " LastSave: "
114                     + countAllJobsSaved + "/"
115                     + countSystemServerJobsSaved + "/"
116                     + countSystemSyncManagerJobsSaved;
117         }
118     }
119 }
120