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.annotation.Nullable; 21 import android.app.job.JobInfo; 22 import android.app.job.JobParameters; 23 import android.util.proto.ProtoOutputStream; 24 25 import java.util.List; 26 27 /** 28 * JobScheduler local system service interface. 29 * {@hide} Only for use within the system server. 30 */ 31 public interface JobSchedulerInternal { 32 33 /** 34 * Returns a list of jobs scheduled by the system service for itself. 35 */ getSystemScheduledOwnJobs(@ullable String namespace)36 List<JobInfo> getSystemScheduledOwnJobs(@Nullable String namespace); 37 38 /** 39 * Cancel the jobs for a given uid (e.g. when app data is cleared) 40 * 41 * @param includeProxiedJobs Include jobs scheduled for this UID by other apps 42 */ cancelJobsForUid(int uid, boolean includeProxiedJobs, @JobParameters.StopReason int reason, int debugReasonCode, String debugReason)43 void cancelJobsForUid(int uid, boolean includeProxiedJobs, 44 @JobParameters.StopReason int reason, int debugReasonCode, String debugReason); 45 46 /** 47 * These are for activity manager to communicate to use what is currently performing backups. 48 */ addBackingUpUid(int uid)49 void addBackingUpUid(int uid); removeBackingUpUid(int uid)50 void removeBackingUpUid(int uid); clearAllBackingUpUids()51 void clearAllBackingUpUids(); 52 53 /** Returns the package responsible for providing media from the cloud to the device. */ 54 @Nullable getCloudMediaProviderPackage(int userId)55 String getCloudMediaProviderPackage(int userId); 56 57 /** 58 * The user has started interacting with the app. Take any appropriate action. 59 */ reportAppUsage(String packageName, int userId)60 void reportAppUsage(String packageName, int userId); 61 62 /** @return {@code true} if the app is considered buggy from JobScheduler's perspective. */ isAppConsideredBuggy(int callingUserId, @NonNull String callingPackageName, int timeoutBlameUserId, @NonNull String timeoutBlamePackageName)63 boolean isAppConsideredBuggy(int callingUserId, @NonNull String callingPackageName, 64 int timeoutBlameUserId, @NonNull String timeoutBlamePackageName); 65 66 /** 67 * @return {@code true} if the given notification is associated with any user-initiated jobs. 68 */ isNotificationAssociatedWithAnyUserInitiatedJobs(int notificationId, int userId, @NonNull String packageName)69 boolean isNotificationAssociatedWithAnyUserInitiatedJobs(int notificationId, 70 int userId, @NonNull String packageName); 71 72 /** 73 * @return {@code true} if the given notification channel is associated with any user-initiated 74 * jobs. 75 */ isNotificationChannelAssociatedWithAnyUserInitiatedJobs( @onNull String notificationChannel, int userId, @NonNull String packageName)76 boolean isNotificationChannelAssociatedWithAnyUserInitiatedJobs( 77 @NonNull String notificationChannel, int userId, @NonNull String packageName); 78 79 /** 80 * Report a snapshot of sync-related jobs back to the sync manager 81 */ getPersistStats()82 JobStorePersistStats getPersistStats(); 83 84 /** 85 * Stats about the first load after boot and the most recent save. 86 */ 87 public class JobStorePersistStats { 88 public int countAllJobsLoaded = -1; 89 public int countSystemServerJobsLoaded = -1; 90 public int countSystemSyncManagerJobsLoaded = -1; 91 92 public int countAllJobsSaved = -1; 93 public int countSystemServerJobsSaved = -1; 94 public int countSystemSyncManagerJobsSaved = -1; 95 JobStorePersistStats()96 public JobStorePersistStats() { 97 } 98 JobStorePersistStats(JobStorePersistStats source)99 public JobStorePersistStats(JobStorePersistStats source) { 100 countAllJobsLoaded = source.countAllJobsLoaded; 101 countSystemServerJobsLoaded = source.countSystemServerJobsLoaded; 102 countSystemSyncManagerJobsLoaded = source.countSystemSyncManagerJobsLoaded; 103 104 countAllJobsSaved = source.countAllJobsSaved; 105 countSystemServerJobsSaved = source.countSystemServerJobsSaved; 106 countSystemSyncManagerJobsSaved = source.countSystemSyncManagerJobsSaved; 107 } 108 109 @Override toString()110 public String toString() { 111 return "FirstLoad: " 112 + countAllJobsLoaded + "/" 113 + countSystemServerJobsLoaded + "/" 114 + countSystemSyncManagerJobsLoaded 115 + " LastSave: " 116 + countAllJobsSaved + "/" 117 + countSystemServerJobsSaved + "/" 118 + countSystemSyncManagerJobsSaved; 119 } 120 121 /** 122 * Write the persist stats to the specified field. 123 */ dumpDebug(ProtoOutputStream proto, long fieldId)124 public void dumpDebug(ProtoOutputStream proto, long fieldId) { 125 final long token = proto.start(fieldId); 126 127 final long flToken = proto.start(JobStorePersistStatsProto.FIRST_LOAD); 128 proto.write(JobStorePersistStatsProto.Stats.NUM_TOTAL_JOBS, countAllJobsLoaded); 129 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SERVER_JOBS, 130 countSystemServerJobsLoaded); 131 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SYNC_MANAGER_JOBS, 132 countSystemSyncManagerJobsLoaded); 133 proto.end(flToken); 134 135 final long lsToken = proto.start(JobStorePersistStatsProto.LAST_SAVE); 136 proto.write(JobStorePersistStatsProto.Stats.NUM_TOTAL_JOBS, countAllJobsSaved); 137 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SERVER_JOBS, 138 countSystemServerJobsSaved); 139 proto.write(JobStorePersistStatsProto.Stats.NUM_SYSTEM_SYNC_MANAGER_JOBS, 140 countSystemSyncManagerJobsSaved); 141 proto.end(lsToken); 142 143 proto.end(token); 144 } 145 } 146 } 147