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