1 /* 2 * Copyright (C) 2021 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.safetycenter; 18 19 import static android.os.Build.VERSION_CODES.TIRAMISU; 20 21 import android.annotation.SystemApi; 22 import android.app.SystemServiceRegistry; 23 import android.content.Context; 24 25 import androidx.annotation.RequiresApi; 26 27 /** 28 * Class holding initialization code for the safety center in the permission module. 29 * 30 * @hide 31 */ 32 @RequiresApi(TIRAMISU) 33 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 34 public final class SafetyCenterFrameworkInitializer { 35 SafetyCenterFrameworkInitializer()36 private SafetyCenterFrameworkInitializer() {} 37 38 /** 39 * Called by {@link SystemServiceRegistry}'s static initializer and registers {@link 40 * SafetyCenterManager} to {@link Context}, so that {@link Context#getSystemService} can return 41 * it. 42 * 43 * <p>If this is called from other places, it throws a {@link IllegalStateException}. 44 */ registerServiceWrappers()45 public static void registerServiceWrappers() { 46 SystemServiceRegistry.registerContextAwareService( 47 Context.SAFETY_CENTER_SERVICE, 48 SafetyCenterManager.class, 49 (context, serviceBinder) -> 50 new SafetyCenterManager( 51 context, ISafetyCenterManager.Stub.asInterface(serviceBinder))); 52 } 53 } 54