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