JNI encapsulation of HAL

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.