• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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 package android.jobscheduler.cts;
17 
18 import android.annotation.TargetApi;
19 import android.app.job.JobScheduler;
20 import android.content.ComponentName;
21 import android.content.Context;
22 import android.content.Intent;
23 import android.jobscheduler.MockJobService;
24 import android.test.AndroidTestCase;
25 
26 /**
27  * Common functionality from which the other test case classes derive.
28  */
29 @TargetApi(21)
30 public abstract class ConstraintTest extends AndroidTestCase {
31     /** Force the scheduler to consider the device to be on stable charging. */
32     private static final Intent EXPEDITE_STABLE_CHARGING =
33             new Intent("com.android.server.task.controllers.BatteryController.ACTION_CHARGING_STABLE");
34 
35     /** Environment that notifies of JobScheduler callbacks. */
36     static MockJobService.TestEnvironment kTestEnvironment =
37             MockJobService.TestEnvironment.getTestEnvironment();
38     /** Handle for the service which receives the execution callbacks from the JobScheduler. */
39     static ComponentName kJobServiceComponent;
40     JobScheduler mJobScheduler;
41 
42     @Override
setUp()43     public void setUp() throws Exception {
44         kTestEnvironment.setUp();
45         kJobServiceComponent = new ComponentName(getContext(), MockJobService.class);
46         mJobScheduler = (JobScheduler) getContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
47         mJobScheduler.cancelAll();
48     }
49 
50     /**
51      * The scheduler will usually only flush its queue of unexpired jobs when the device is
52      * considered to be on stable power - that is, plugged in for a period of 2 minutes.
53      * Rather than wait for this to happen, we cheat and send this broadcast instead.
54      */
sendExpediteStableChargingBroadcast()55     protected void sendExpediteStableChargingBroadcast() {
56         getContext().sendBroadcast(EXPEDITE_STABLE_CHARGING);
57     }
58 }
59