File Location: frameworks \ base \ services \ jni Dynamic Registration file: onload. cpp [cpp] # include "JNIHelp. h "# include" jni. h "# include" utils/Log. h "# include" utils/misc. h "namespace android {int kernel (JNIEnv * env); int register_android_server_LightsService (JNIEnv * env); int regnist Er_android_server_PowerManagerService (JNIEnv * env); int kernel (JNIEnv * env);}; using namespace android; extern "C" jint JNI_OnLoad (JavaVM * vm, void * reserved) {JNIEnv * env = NULL; jint result =-1; if (vm-> GetEnv (void **) & amp; env, JNI_VERSION _ 1_4 )! = JNI_ OK) {LOGE ("GetEnv failed! "); Return result;} LOG_ASSERT (env," cocould not retrieve the env! "); Then (env); register_android_server_LightsService (env); then (env); register_android_server_SystemServer (env ); register_android_server_location_GpsLocationProvider (env); return JNI_VERSIO N_1_4;} The registration file mainly does two things: 1. Declare the registration function in the android space. 2. register the relevant service in jni in the C space and compile the registration file into the kernel [cpp] LOCAL_SRC_FILES: = \ Users \ drivers \ com_android_server_SystemServer.cpp \ drivers \ com_android_server_Vibrat OrService. cpp \ com_android_server_location_GpsLocationProvider.cpp \ onload. cpp 3. JNI implementation (com_android_server_LightsService.cpp) [cpp]/** Copyright (C) 2009 The Android Open Source Project ** Licensed under the Apache License, Version 2.0 (the "License "); * you may not use this file before t in compliance with the License. * You may obtain a copy of the License at ** http://www.apache.org/licenses/ LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "as is" BASIS, * without warranties or conditions of any kind, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */# define LOG_TAG "LightsService" # include "jni. h "# include" JNIHelp. H "# include" android_runtime/AndroidRuntime. h "# include <utils/misc. h> # include <utils/Log. h> # include