blob: 021ba9df0b8ff034276061150983216df19003e3 [file] [log] [blame]
Aurimas Liutikasdc3f8852024-07-11 10:07:48 -07001/*
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
17package android.ondevicepersonalization;
18
19import static android.adservices.ondevicepersonalization.OnDevicePersonalizationConfigManager.ON_DEVICE_PERSONALIZATION_CONFIG_SERVICE;
20import static android.adservices.ondevicepersonalization.OnDevicePersonalizationManager.ON_DEVICE_PERSONALIZATION_SERVICE;
21import static android.adservices.ondevicepersonalization.OnDevicePersonalizationSystemEventManager.ON_DEVICE_PERSONALIZATION_SYSTEM_EVENT_SERVICE;
22import static android.federatedcompute.FederatedComputeManager.FEDERATED_COMPUTE_SERVICE;
23import static android.ondevicepersonalization.OnDevicePersonalizationSystemServiceManager.ON_DEVICE_PERSONALIZATION_SYSTEM_SERVICE;
24
25import android.adservices.ondevicepersonalization.OnDevicePersonalizationConfigManager;
26import android.adservices.ondevicepersonalization.OnDevicePersonalizationManager;
27import android.adservices.ondevicepersonalization.OnDevicePersonalizationSystemEventManager;
28import android.annotation.SystemApi;
29import android.app.SystemServiceRegistry;
30import android.content.Context;
31import android.federatedcompute.FederatedComputeManager;
32
33import com.android.modules.utils.build.SdkLevel;
34
35/**
36 * Class holding initialization code for the OnDevicePersonalization module.
37 *
38 * @hide
39 */
40@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
41public class OnDevicePersonalizationFrameworkInitializer {
42 private OnDevicePersonalizationFrameworkInitializer() {
43 }
44
45 /**
46 * Called by {@link SystemServiceRegistry}'s static initializer and registers all
47 * OnDevicePersonalization services to {@link Context}, so that
48 * {@link Context#getSystemService} can return them.
49 *
50 * @throws IllegalStateException if this is called from anywhere besides
51 * {@link SystemServiceRegistry}
52 */
53 public static void registerServiceWrappers() {
54 SystemServiceRegistry.registerContextAwareService(
55 ON_DEVICE_PERSONALIZATION_SERVICE, OnDevicePersonalizationManager.class,
56 (c) -> new OnDevicePersonalizationManager(c));
57 SystemServiceRegistry.registerContextAwareService(
58 ON_DEVICE_PERSONALIZATION_CONFIG_SERVICE,
59 OnDevicePersonalizationConfigManager.class,
60 (c) -> new OnDevicePersonalizationConfigManager(c));
61 SystemServiceRegistry.registerContextAwareService(
62 FEDERATED_COMPUTE_SERVICE, FederatedComputeManager.class,
63 (c) -> new FederatedComputeManager(c));
64 SystemServiceRegistry.registerContextAwareService(
65 ON_DEVICE_PERSONALIZATION_SYSTEM_EVENT_SERVICE,
66 OnDevicePersonalizationSystemEventManager.class,
67 (c) -> new OnDevicePersonalizationSystemEventManager(c));
68 if (SdkLevel.isAtLeastU()) {
69 SystemServiceRegistry.registerStaticService(
70 ON_DEVICE_PERSONALIZATION_SYSTEM_SERVICE,
71 OnDevicePersonalizationSystemServiceManager.class,
72 (s) -> new OnDevicePersonalizationSystemServiceManager(s));
73 }
74 }
75}