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.NonNull; 20 import android.app.job.JobInfo; 21 import android.util.proto.ProtoOutputStream; 22 23 import java.util.List; 24 25 /** 26 * JobScheduler local system service interface. 27 * {@hide} Only for use within the system server. 28 */ 29 public interface JobSchedulerInternal { 30 31 /** 32 * Returns a list of pending jobs scheduled by the system service. 33 */ getSystemScheduledPendingJobs()34 List<JobInfo> getSystemScheduledPendingJobs(); 35 36 /** 37 * Cancel the jobs for a given uid (e.g. when app data is cleared) 38 */ cancelJobsForUid(int uid, String reason)39 void cancelJobsForUid(int uid, String reason); 40 41 /** 42 * These are for activity manager to communicate to use what is currently performing backups. 43 */ addBackingUpUid(int uid)44 void addBackingUpUid(int uid); removeBackingUpUid(int uid)45 void removeBackingUpUid(int uid); clearAllBackingUpUids()46 void clearAllBackingUpUids(); 47 48 /** Returns the package responsible for backing up media on the device. */ 49 @NonNull getMediaBackupPackage()50 String getMediaBackupPackage(); 51 52 /** 53 * The user has started interacting with the app. Take any appropriate action. 54 */ reportAppUsage(String packageName, int userId)55 void reportAppUsage(String packageName, int userId); 56 57 /** 58 * Report a snapshot of sync-related jobs back to the sync manager 59 */ getPersistStats()60 JobStorePersistStats getPersistStats(); 61 62 /** 63 * Stats about the first load after boot and the most recent save. 64 */ 65 public class JobStorePersistStats { 66 public int countAllJobsLoaded = -1; 67 public int countSystemServerJobsLoaded = -1; 68 public int countSystemSyncManagerJobsLoaded = -1; 69 70 public int countAllJobsSaved = -1; 71 public int countSystemServerJobsSaved = -1; 72 public int countSystemSyncManagerJobsSaved = -1; 73 JobStorePersistStats()74 public JobStorePersistStats() { 75 } 76 JobStorePersistStats(JobStorePersistStats source)77 public JobStorePersistStats(JobStorePersistStats source) { 78 countAllJobsLoaded = source.countAllJobsLoaded; 79 countSystemServerJobsLoaded = source.countSystemServerJobsLoaded; 80 countSystemSyncManagerJobsLoaded = source.countSystemSyncManagerJobsLoaded; 81 82 countAllJobsSaved = source.countAllJobsSaved; 83 countSystemServerJobsSaved = source.countSystemServerJobsSaved; 84 countSystemSyncManagerJobsSaved = source.countSystemSyncManagerJobsSaved; 85 } 86 87 @Override toString()88 public String toString() { 89 return "FirstLoad: " 90 + countAllJobsLoaded + "/" 91 + countSystemServerJobsLoaded + "/" 92 + countSystemSyncManagerJobsLoaded 93 + " LastSave: " 94 + countAllJobsSaved + "/" 95 + countSystemServerJobsSaved + "/" 96 + countSystemSyncManagerJobsSaved; 97 } 98 99 /** 100 * Write the persist stats to the specified field. 101 */ dumpDebug(ProtoOutputStream proto, long fieldId)102 public void dumpDebug(ProtoOutputStream proto, long fieldId) { 103 final long token = proto.start(fieldId); 104 105 final long flToken = proto.start(JobStorePersistStatsProto.FIRST_LOAD); 106 proto.write(JobStorePersistStatsProto.Stats.NUM_TOTAL_JOBS, countAllJobsLoaded); 107 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SERVER_JOBS, 108 countSystemServerJobsLoaded); 109 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SYNC_MANAGER_JOBS, 110 countSystemSyncManagerJobsLoaded); 111 proto.end(flToken); 112 113 final long lsToken = proto.start(JobStorePersistStatsProto.LAST_SAVE); 114 proto.write(JobStorePersistStatsProto.Stats.NUM_TOTAL_JOBS, countAllJobsSaved); 115 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SERVER_JOBS, 116 countSystemServerJobsSaved); 117 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SYNC_MANAGER_JOBS, 118 countSystemSyncManagerJobsSaved); 119 proto.end(lsToken); 120 121 proto.end(token); 122 } 123 } 124 } 125