JobSchedulerInternal.java revision f0ce10155244b8e7361dc61640a2d0beac22471b
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    JobStorePersistStats getPersistStats();
68
69    /**
70     * Stats about the first load after boot and the most recent save.
71     * STOPSHIP Remove it and the relevant code once b/64536115 is fixed.
72     */
73    public class JobStorePersistStats {
74        public int countAllJobsLoaded = -1;
75        public int countSystemServerJobsLoaded = -1;
76        public int countSystemSyncManagerJobsLoaded = -1;
77
78        public int countAllJobsSaved = -1;
79        public int countSystemServerJobsSaved = -1;
80        public int countSystemSyncManagerJobsSaved = -1;
81
82        public JobStorePersistStats() {
83        }
84
85        public JobStorePersistStats(JobStorePersistStats source) {
86            countAllJobsLoaded = source.countAllJobsLoaded;
87            countSystemServerJobsLoaded = source.countSystemServerJobsLoaded;
88            countSystemSyncManagerJobsLoaded = source.countSystemSyncManagerJobsLoaded;
89
90            countAllJobsSaved = source.countAllJobsSaved;
91            countSystemServerJobsSaved = source.countSystemServerJobsSaved;
92            countSystemSyncManagerJobsSaved = source.countSystemSyncManagerJobsSaved;
93        }
94
95        @Override
96        public String toString() {
97            return "FirstLoad: "
98                    + countAllJobsLoaded + "/"
99                    + countSystemServerJobsLoaded + "/"
100                    + countSystemSyncManagerJobsLoaded
101                    + " LastSave: "
102                    + countAllJobsSaved + "/"
103                    + countSystemServerJobsSaved + "/"
104                    + countSystemSyncManagerJobsSaved;
105        }
106    }
107}
108