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