• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.ondevicepersonalization;
18 
19 import static android.app.ondevicepersonalization.OnDevicePersonalizationSystemServiceManager.ON_DEVICE_PERSONALIZATION_SYSTEM_SERVICE;
20 import static android.ondevicepersonalization.OnDevicePersonalizationManager.ON_DEVICE_PERSONALIZATION_SERVICE;
21 import static android.ondevicepersonalization.OnDevicePersonalizationPrivacyStatusManager.ON_DEVICE_PERSONALIZATION_PRIVACY_STATUS_SERVICE;
22 
23 import android.annotation.SystemApi;
24 import android.app.SystemServiceRegistry;
25 import android.app.ondevicepersonalization.OnDevicePersonalizationSystemServiceManager;
26 import android.content.Context;
27 
28 import com.android.modules.utils.build.SdkLevel;
29 
30 /**
31  * Class holding initialization code for the OnDevicePersonalization module.
32  *
33  * @hide
34  */
35 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
36 public class OnDevicePersonalizationFrameworkInitializer {
OnDevicePersonalizationFrameworkInitializer()37     private OnDevicePersonalizationFrameworkInitializer() {
38     }
39 
40     /**
41      * Called by {@link SystemServiceRegistry}'s static initializer and registers all
42      * OnDevicePersonalization services to {@link Context}, so that
43      * {@link Context#getSystemService} can return them.
44      *
45      * @throws IllegalStateException if this is called from anywhere besides
46      *     {@link SystemServiceRegistry}
47      */
registerServiceWrappers()48     public static void registerServiceWrappers() {
49         SystemServiceRegistry.registerContextAwareService(
50                 ON_DEVICE_PERSONALIZATION_SERVICE, OnDevicePersonalizationManager.class,
51                 (c) -> new OnDevicePersonalizationManager(c));
52         SystemServiceRegistry.registerContextAwareService(
53                 ON_DEVICE_PERSONALIZATION_PRIVACY_STATUS_SERVICE,
54                 OnDevicePersonalizationPrivacyStatusManager.class,
55                 (c) -> new OnDevicePersonalizationPrivacyStatusManager(c));
56 
57         if (SdkLevel.isAtLeastU()) {
58             SystemServiceRegistry.registerStaticService(
59                     ON_DEVICE_PERSONALIZATION_SYSTEM_SERVICE,
60                     OnDevicePersonalizationSystemServiceManager.class,
61                     (s) -> new OnDevicePersonalizationSystemServiceManager(s));
62         }
63     }
64 }
65