1 /* 2 * Copyright (C) 2024 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 com.android.server.utils; 18 19 import com.android.tools.r8.keepanno.annotations.KeepItemKind; 20 import com.android.tools.r8.keepanno.annotations.MethodAccessFlags; 21 import com.android.tools.r8.keepanno.annotations.UsedByNative; 22 23 /** 24 * Utility class for lazily registering native methods for a given class. 25 * 26 * <p><strong>Note: </strong>Most native methods are registered eagerly via the 27 * native {@code JNI_OnLoad} hook when system server loads its primary native 28 * lib. However, some classes within system server may be stripped if unused. 29 * This class offers a way to selectively register their native methods. Such 30 * register calls should typically be done from that class's {@code static {}} 31 * init block. 32 */ 33 @UsedByNative( 34 description = "Referenced from JNI in jni/com_android_server_utils_LazyJniRegistrar.cpp", 35 kind = KeepItemKind.CLASS_AND_MEMBERS, 36 methodAccess = {MethodAccessFlags.NATIVE}) 37 public final class LazyJniRegistrar { 38 39 // Note: {@link SystemServer#run} loads the native "android_servers" lib, so no need to do so 40 // explicitly here. Classes that use this registration must not be initialized before this. 41 42 /** Registers native methods for ConsumerIrService. */ registerConsumerIrService()43 public static native void registerConsumerIrService(); 44 45 /** Registers native methods for GameManagerService. */ registerGameManagerService()46 public static native void registerGameManagerService(); 47 48 /** Registers native methods for VrManagerService. */ registerVrManagerService()49 public static native void registerVrManagerService(); 50 } 51