JobSchedulerInternal.java revision 55c84552cc0cab34f13084c219a0f4c4487e512b
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
17package com.android.server.job;
18
19import android.annotation.UserIdInt;
20import android.app.job.JobInfo;
21
22import java.util.List;
23
24/**
25 * JobScheduler local system service interface.
26 * {@hide} Only for use within the system server.
27 */
28public interface JobSchedulerInternal {
29
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
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     */
48    public long baseHeartbeatForApp(String packageName, @UserIdInt int userId, int appBucket);
49
50    /**
51     * Returns a list of pending jobs scheduled by the system service.
52     */
53    List<JobInfo> getSystemScheduledPendingJobs();
54
55    /**
56     * Cancel the jobs for a given uid (e.g. when app data is cleared)
57     */
58    void cancelJobsForUid(int uid, String reason);
59
60    /**
61     * These are for activity manager to communicate to use what is currently performing backups.
62     */
63    void addBackingUpUid(int uid);
64    void removeBackingUpUid(int uid);
65    void clearAllBackingUpUids();
66
67    /**
68     * The user has started interacting with the app.  Take any appropriate action.
69     */
70    void reportAppUsage(String packageName, int userId);
71
72    /**
73     * Report a snapshot of sync-related jobs back to the sync manager
74     */
75    JobStorePersistStats getPersistStats();
76
77    /**
78     * Stats about the first load after boot and the most recent save.
79     */
80    public class JobStorePersistStats {
81        public int countAllJobsLoaded = -1;
82        public int countSystemServerJobsLoaded = -1;
83        public int countSystemSyncManagerJobsLoaded = -1;
84
85        public int countAllJobsSaved = -1;
86        public int countSystemServerJobsSaved = -1;
87        public int countSystemSyncManagerJobsSaved = -1;
88
89        public JobStorePersistStats() {
90        }
91
92        public JobStorePersistStats(JobStorePersistStats source) {
93            countAllJobsLoaded = source.countAllJobsLoaded;
94            countSystemServerJobsLoaded = source.countSystemServerJobsLoaded;
95            countSystemSyncManagerJobsLoaded = source.countSystemSyncManagerJobsLoaded;
96
97            countAllJobsSaved = source.countAllJobsSaved;
98            countSystemServerJobsSaved = source.countSystemServerJobsSaved;
99            countSystemSyncManagerJobsSaved = source.countSystemSyncManagerJobsSaved;
100        }
101
102        @Override
103        public String toString() {
104            return "FirstLoad: "
105                    + countAllJobsLoaded + "/"
106                    + countSystemServerJobsLoaded + "/"
107                    + countSystemSyncManagerJobsLoaded
108                    + " LastSave: "
109                    + countAllJobsSaved + "/"
110                    + countSystemServerJobsSaved + "/"
111                    + countSystemSyncManagerJobsSaved;
112        }
113    }
114}
115