1 /* 2 * Copyright (C) 2017 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.cts; 18 19 import android.app.job.StopReasonEnum; 20 import android.net.NetworkCapabilitiesProto; 21 import android.net.NetworkRequestProto; 22 import com.android.server.job.ConstantsProto; 23 import com.android.server.job.ConstraintEnum; 24 import com.android.server.job.DataSetProto; 25 import com.android.server.job.JobPackageHistoryProto; 26 import com.android.server.job.JobPackageTrackerDumpProto; 27 import com.android.server.job.JobSchedulerServiceDumpProto; 28 import com.android.server.job.JobStatusDumpProto; 29 import com.android.server.job.JobStatusShortInfoProto; 30 import com.android.server.job.StateControllerProto; 31 32 /** Test to check that the jobscheduler service properly outputs its dump state. */ 33 public class JobSchedulerIncidentTest extends ProtoDumpTestCase { 34 public void testJobSchedulerServiceDump() throws Exception { 35 final JobSchedulerServiceDumpProto dump = 36 getDump(JobSchedulerServiceDumpProto.parser(), "dumpsys jobscheduler --proto"); 37 38 verifyJobSchedulerServiceDumpProto(dump, PRIVACY_NONE); 39 } 40 41 static void verifyJobSchedulerServiceDumpProto(JobSchedulerServiceDumpProto dump, final int filterLevel) throws Exception { 42 testConstantsProto(dump.getSettings()); 43 44 for (int u : dump.getStartedUsersList()) { 45 assertTrue(0 <= u); 46 } 47 48 for (JobSchedulerServiceDumpProto.RegisteredJob rj : dump.getRegisteredJobsList()) { 49 testJobStatusShortInfoProto(rj.getInfo(), filterLevel); 50 testJobStatusDumpProto(rj.getDump()); 51 } 52 53 for (StateControllerProto c : dump.getControllersList()) { 54 testStateControllerProto(c, filterLevel); 55 } 56 57 for (JobSchedulerServiceDumpProto.PriorityOverride po : dump.getPriorityOverridesList()) { 58 assertTrue(0 <= po.getUid()); 59 } 60 61 for (int buu : dump.getBackingUpUidsList()) { 62 assertTrue(0 <= buu); 63 } 64 65 testJobPackageHistoryProto(dump.getHistory(), filterLevel); 66 67 testJobPackageTrackerDumpProto(dump.getPackageTracker()); 68 69 for (JobSchedulerServiceDumpProto.PendingJob pj : dump.getPendingJobsList()) { 70 testJobStatusShortInfoProto(pj.getInfo(), filterLevel); 71 testJobStatusDumpProto(pj.getDump()); 72 assertTrue(0 <= pj.getEnqueuedDurationMs()); 73 } 74 75 for (JobSchedulerServiceDumpProto.ActiveJob aj : dump.getActiveJobsList()) { 76 JobSchedulerServiceDumpProto.ActiveJob.InactiveJob ajIj = aj.getInactive(); 77 assertTrue(0 <= ajIj.getTimeSinceStoppedMs()); 78 79 JobSchedulerServiceDumpProto.ActiveJob.RunningJob ajRj = aj.getRunning(); 80 testJobStatusShortInfoProto(ajRj.getInfo(), filterLevel); 81 assertTrue(0 <= ajRj.getRunningDurationMs()); 82 assertTrue(0 <= ajRj.getTimeUntilTimeoutMs()); 83 testJobStatusDumpProto(ajRj.getDump()); 84 assertTrue(0 <= ajRj.getTimeSinceMadeActiveMs()); 85 assertTrue(0 <= ajRj.getPendingDurationMs()); 86 } 87 88 assertTrue(0 <= dump.getMaxActiveJobs()); 89 } 90 91 private static void testConstantsProto(ConstantsProto c) throws Exception { 92 assertNotNull(c); 93 94 assertTrue(0 <= c.getMinIdleCount()); 95 assertTrue(0 <= c.getMinChargingCount()); 96 assertTrue(0 <= c.getMinBatteryNotLowCount()); 97 assertTrue(0 <= c.getMinStorageNotLowCount()); 98 assertTrue(0 <= c.getMinConnectivityCount()); 99 assertTrue(0 <= c.getMinContentCount()); 100 assertTrue(0 <= c.getMinReadyJobsCount()); 101 assertTrue(0 <= c.getHeavyUseFactor()); 102 assertTrue(0 <= c.getModerateUseFactor()); 103 assertTrue(0 <= c.getFgJobCount()); 104 assertTrue(0 <= c.getBgNormalJobCount()); 105 assertTrue(0 <= c.getBgModerateJobCount()); 106 assertTrue(0 <= c.getBgLowJobCount()); 107 assertTrue(0 <= c.getBgCriticalJobCount()); 108 assertTrue(0 <= c.getMaxStandardRescheduleCount()); 109 assertTrue(0 <= c.getMaxWorkRescheduleCount()); 110 assertTrue(0 <= c.getMinLinearBackoffTimeMs()); 111 assertTrue(0 <= c.getMinExpBackoffTimeMs()); 112 assertTrue(0 <= c.getStandbyHeartbeatTimeMs()); 113 for (int sb : c.getStandbyBeatsList()) { 114 assertTrue(0 <= sb); 115 } 116 } 117 118 private static void testDataSetProto(DataSetProto ds) throws Exception { 119 assertNotNull(ds); 120 121 assertTrue(0 <= ds.getStartClockTimeMs()); 122 assertTrue(0 <= ds.getElapsedTimeMs()); 123 assertTrue(0 <= ds.getPeriodMs()); 124 125 for (DataSetProto.PackageEntryProto pe : ds.getPackageEntriesList()) { 126 assertTrue(0 <= pe.getUid()); 127 128 assertTrue(0 <= pe.getPendingState().getDurationMs()); 129 assertTrue(0 <= pe.getPendingState().getCount()); 130 assertTrue(0 <= pe.getActiveState().getDurationMs()); 131 assertTrue(0 <= pe.getActiveState().getCount()); 132 assertTrue(0 <= pe.getActiveTopState().getDurationMs()); 133 assertTrue(0 <= pe.getActiveTopState().getCount()); 134 135 for (DataSetProto.PackageEntryProto.StopReasonCount src : pe.getStopReasonsList()) { 136 assertTrue(StopReasonEnum.getDescriptor().getValues() 137 .contains(src.getReason().getValueDescriptor())); 138 assertTrue(0 <= src.getCount()); 139 } 140 } 141 assertTrue(0 <= ds.getMaxConcurrency()); 142 assertTrue(0 <= ds.getMaxForegroundConcurrency()); 143 } 144 145 private static void testJobPackageHistoryProto(JobPackageHistoryProto jph, int filterLevel) throws Exception { 146 assertNotNull(jph); 147 148 for (JobPackageHistoryProto.HistoryEvent he : jph.getHistoryEventList()) { 149 assertTrue(JobPackageHistoryProto.Event.getDescriptor().getValues() 150 .contains(he.getEvent().getValueDescriptor())); 151 assertTrue(0 <= he.getTimeSinceEventMs()); // Should be positive. 152 assertTrue(0 <= he.getUid()); 153 assertTrue(StopReasonEnum.getDescriptor().getValues() 154 .contains(he.getStopReason().getValueDescriptor())); 155 } 156 } 157 158 private static void testJobPackageTrackerDumpProto(JobPackageTrackerDumpProto jptd) throws Exception { 159 assertNotNull(jptd); 160 161 for (DataSetProto ds : jptd.getHistoricalStatsList()) { 162 testDataSetProto(ds); 163 } 164 testDataSetProto(jptd.getCurrentStats()); 165 } 166 167 private static void testJobStatusShortInfoProto(JobStatusShortInfoProto jssi, final int filterLevel) throws Exception { 168 assertNotNull(jssi); 169 170 assertTrue(0 <= jssi.getCallingUid()); 171 } 172 173 private static void testJobStatusDumpProto(JobStatusDumpProto jsd) throws Exception { 174 assertNotNull(jsd); 175 176 assertTrue(0 <= jsd.getCallingUid()); 177 assertTrue(0 <= jsd.getSourceUid()); 178 assertTrue(0 <= jsd.getSourceUserId()); 179 180 JobStatusDumpProto.JobInfo ji = jsd.getJobInfo(); 181 if (ji.getIsPeriodic()) { 182 assertTrue(0 <= ji.getPeriodIntervalMs()); 183 assertTrue(0 <= ji.getPeriodFlexMs()); 184 } 185 assertTrue(0 <= ji.getTriggerContentUpdateDelayMs()); 186 assertTrue(0 <= ji.getTriggerContentMaxDelayMs()); 187 testNetworkRequestProto(ji.getRequiredNetwork()); 188 // JobInfo.NETWORK_BYTES_UNKNOWN (= -1) is a valid value. 189 assertTrue(-1 <= ji.getTotalNetworkBytes()); 190 assertTrue(0 <= ji.getMinLatencyMs()); 191 assertTrue(0 <= ji.getMaxExecutionDelayMs()); 192 JobStatusDumpProto.JobInfo.Backoff bp = ji.getBackoffPolicy(); 193 assertTrue(JobStatusDumpProto.JobInfo.Backoff.Policy.getDescriptor().getValues() 194 .contains(bp.getPolicy().getValueDescriptor())); 195 assertTrue(0 <= bp.getInitialBackoffMs()); 196 197 for (ConstraintEnum c : jsd.getRequiredConstraintsList()) { 198 assertTrue(ConstraintEnum.getDescriptor().getValues() 199 .contains(c.getValueDescriptor())); 200 } 201 for (ConstraintEnum c : jsd.getSatisfiedConstraintsList()) { 202 assertTrue(ConstraintEnum.getDescriptor().getValues() 203 .contains(c.getValueDescriptor())); 204 } 205 for (ConstraintEnum c : jsd.getUnsatisfiedConstraintsList()) { 206 assertTrue(ConstraintEnum.getDescriptor().getValues() 207 .contains(c.getValueDescriptor())); 208 } 209 210 for (JobStatusDumpProto.TrackingController tc : jsd.getTrackingControllersList()) { 211 assertTrue(JobStatusDumpProto.TrackingController.getDescriptor().getValues() 212 .contains(tc.getValueDescriptor())); 213 } 214 215 for (JobStatusDumpProto.JobWorkItem jwi : jsd.getPendingWorkList()) { 216 assertTrue(0 <= jwi.getDeliveryCount()); 217 } 218 for (JobStatusDumpProto.JobWorkItem jwi : jsd.getExecutingWorkList()) { 219 assertTrue(0 <= jwi.getDeliveryCount()); 220 } 221 222 assertTrue(JobStatusDumpProto.Bucket.getDescriptor().getValues() 223 .contains(jsd.getStandbyBucket().getValueDescriptor())); 224 225 assertTrue(0 <= jsd.getEnqueueDurationMs()); 226 227 assertTrue(0 <= jsd.getNumFailures()); 228 229 assertTrue(0 <= jsd.getLastSuccessfulRunTime()); 230 assertTrue(0 <= jsd.getLastFailedRunTime()); 231 } 232 233 private static void testNetworkRequestProto(NetworkRequestProto nr) throws Exception { 234 assertNotNull(nr); 235 236 assertTrue(NetworkRequestProto.Type.getDescriptor().getValues() 237 .contains(nr.getType().getValueDescriptor())); 238 testNetworkCapabilitesProto(nr.getNetworkCapabilities()); 239 } 240 241 private static void testNetworkCapabilitesProto(NetworkCapabilitiesProto nc) throws Exception { 242 assertNotNull(nc); 243 244 for (NetworkCapabilitiesProto.Transport t : nc.getTransportsList()) { 245 assertTrue(NetworkCapabilitiesProto.Transport.getDescriptor().getValues() 246 .contains(t.getValueDescriptor())); 247 } 248 for (NetworkCapabilitiesProto.NetCapability c : nc.getCapabilitiesList()) { 249 assertTrue(NetworkCapabilitiesProto.NetCapability.getDescriptor().getValues() 250 .contains(c.getValueDescriptor())); 251 } 252 253 assertTrue(0 <= nc.getLinkUpBandwidthKbps()); 254 assertTrue(0 <= nc.getLinkDownBandwidthKbps()); 255 } 256 257 private static void testStateControllerProto(StateControllerProto sc, int filterLevel) throws Exception { 258 assertNotNull(sc); 259 260 StateControllerProto.BackgroundJobsController bjc = sc.getBackground(); 261 for (StateControllerProto.BackgroundJobsController.TrackedJob tj : bjc.getTrackedJobsList()) { 262 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 263 assertTrue(0 <= tj.getSourceUid()); 264 } 265 StateControllerProto.BatteryController bc = sc.getBattery(); 266 for (StateControllerProto.BatteryController.TrackedJob tj : bc.getTrackedJobsList()) { 267 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 268 assertTrue(0 <= tj.getSourceUid()); 269 } 270 StateControllerProto.ConnectivityController cc = sc.getConnectivity(); 271 for (StateControllerProto.ConnectivityController.TrackedJob tj : cc.getTrackedJobsList()) { 272 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 273 assertTrue(0 <= tj.getSourceUid()); 274 testNetworkRequestProto(tj.getRequiredNetwork()); 275 } 276 StateControllerProto.ContentObserverController coc = sc.getContentObserver(); 277 for (StateControllerProto.ContentObserverController.TrackedJob tj : coc.getTrackedJobsList()) { 278 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 279 assertTrue(0 <= tj.getSourceUid()); 280 } 281 for (StateControllerProto.ContentObserverController.Observer o : coc.getObserversList()) { 282 assertTrue(0 <= o.getUserId()); 283 284 for (StateControllerProto.ContentObserverController.Observer.TriggerContentData tcd : o.getTriggersList()) { 285 if (filterLevel == PRIVACY_AUTO) { 286 assertTrue(tcd.getUri().isEmpty()); 287 } 288 for (StateControllerProto.ContentObserverController.Observer.TriggerContentData.JobInstance ji : tcd.getJobsList()) { 289 testJobStatusShortInfoProto(ji.getInfo(), filterLevel); 290 291 assertTrue(0 <= ji.getSourceUid()); 292 assertTrue(0 <= ji.getTriggerContentUpdateDelayMs()); 293 assertTrue(0 <= ji.getTriggerContentMaxDelayMs()); 294 295 if (filterLevel == PRIVACY_AUTO) { 296 for (String ca : ji.getChangedAuthoritiesList()) { 297 assertTrue(ca.isEmpty()); 298 } 299 for (String ca : ji.getChangedUrisList()) { 300 assertTrue(ca.isEmpty()); 301 } 302 } 303 } 304 } 305 } 306 StateControllerProto.DeviceIdleJobsController dijc = sc.getDeviceIdle(); 307 for (StateControllerProto.DeviceIdleJobsController.TrackedJob tj : dijc.getTrackedJobsList()) { 308 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 309 assertTrue(0 <= tj.getSourceUid()); 310 } 311 StateControllerProto.IdleController ic = sc.getIdle(); 312 for (StateControllerProto.IdleController.TrackedJob tj : ic.getTrackedJobsList()) { 313 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 314 assertTrue(0 <= tj.getSourceUid()); 315 } 316 StateControllerProto.StorageController scr = sc.getStorage(); 317 for (StateControllerProto.StorageController.TrackedJob tj : scr.getTrackedJobsList()) { 318 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 319 assertTrue(0 <= tj.getSourceUid()); 320 } 321 StateControllerProto.TimeController tc = sc.getTime(); 322 assertTrue(0 <= tc.getNowElapsedRealtime()); 323 for (StateControllerProto.TimeController.TrackedJob tj : tc.getTrackedJobsList()) { 324 testJobStatusShortInfoProto(tj.getInfo(), filterLevel); 325 assertTrue(0 <= tj.getSourceUid()); 326 } 327 } 328 } 329