1 /*
2  * Copyright (C) 2019 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 android.app.job;
18 
19 import android.annotation.SystemApi;
20 import android.app.JobSchedulerImpl;
21 import android.app.SystemServiceRegistry;
22 import android.app.tare.EconomyManager;
23 import android.app.tare.IEconomyManager;
24 import android.content.Context;
25 import android.os.DeviceIdleManager;
26 import android.os.IDeviceIdleController;
27 import android.os.PowerExemptionManager;
28 import android.os.PowerWhitelistManager;
29 
30 /**
31  * Class holding initialization code for the job scheduler module.
32  *
33  * @hide
34  */
35 @SystemApi
36 public class JobSchedulerFrameworkInitializer {
JobSchedulerFrameworkInitializer()37     private JobSchedulerFrameworkInitializer() {
38     }
39 
40     /**
41      * Called by {@link SystemServiceRegistry}'s static initializer and registers
42      * {@link JobScheduler} and other services to {@link Context}, so
43      * {@link Context#getSystemService} can return them.
44      *
45      * <p>If this is called from other places, it throws a {@link IllegalStateException).
46      */
registerServiceWrappers()47     public static void registerServiceWrappers() {
48         SystemServiceRegistry.registerContextAwareService(
49                 Context.JOB_SCHEDULER_SERVICE, JobScheduler.class,
50                 (context, b) -> new JobSchedulerImpl(context, IJobScheduler.Stub.asInterface(b)));
51         SystemServiceRegistry.registerContextAwareService(
52                 Context.DEVICE_IDLE_CONTROLLER, DeviceIdleManager.class,
53                 (context, b) -> new DeviceIdleManager(
54                         context, IDeviceIdleController.Stub.asInterface(b)));
55         SystemServiceRegistry.registerContextAwareService(
56                 Context.POWER_WHITELIST_MANAGER, PowerWhitelistManager.class,
57                 PowerWhitelistManager::new);
58         SystemServiceRegistry.registerContextAwareService(
59                 Context.POWER_EXEMPTION_SERVICE, PowerExemptionManager.class,
60                 PowerExemptionManager::new);
61         SystemServiceRegistry.registerStaticService(
62                 Context.RESOURCE_ECONOMY_SERVICE, EconomyManager.class,
63                 (b) -> new EconomyManager(IEconomyManager.Stub.asInterface(b)));
64     }
65 }
66