How native function is called in…
来源:互联网 发布:php explode() 编辑:程序博客网 时间:2024/04/30 17:48
How native function is called in Android platform ( unfinishedversion)
android.os.Power.java -------- native file ---->.../jni/android_os_Power.c 3.1) a global register function array static const RegJNIRec gRegJNI[] = { ... register_android_os_Power, } 3.2) Register native function process int AndroidRuntime::startReg(JNIEnv* env) or Java_com_android_internal_util_WithFramework_registerNatives(...) or Java_LoadClass_registerNatives(....) ---> register_jni_procs(gRegJNI, NELEM(gRegJNI),env) ---> foreach(member of gRegJNI) call register_XXX_XXX_XXX..XXX() //so here register_android_os_power() will becalled ---> AndroidRuntime::registerNativeMethods(env, class_namelike "android/os/Power", method table like method_table,size) ---> jniRegisterNativeMethods(env, className,gMethods, numMethods) -->pEnv->RegisterNatives(env, clazz, gMethods,numMethods) ; --> foreach(method) calldvmRegisterJNIMethod(ClassObject* clazz, const char*methodName, constchar* signature, void* fnPtr) --> calldvmSetNativeFunc(method, dvmCallSynchronizedJNIMethod, fnPtr); //for sycn method or call dvmSetNativeFunc(method, dvmCallJNIMethod,fnPtr); --> ((Method*)method)->insns = insns; // set actual codespace to be executed for a native function void dvmPlatformInvoke(void* pEnv,ClassObject* clazz, int argInfo, int argc,
const u4*argv, const char* shorty, void* func, JValue*pReturn) dvmCallMethod() /dvmInvokeMethod ---> if(dvmIsNativeMethod(method)) {
(*method->nativeFunc)(self->curFrame,&retval, method, self);
}
1. Power.java--> find corresponding native cfile
2. in android_os_Power.c, you canfind:
static JNINativeMethod method_table[]=// Native functiontable {
{"acquireWakeLock", "(ILjava/lang/String;)V", (void*)acquireWakeLock},
{"releaseWakeLock", "(Ljava/lang/String;)V", (void*)releaseWakeLock},
{"setLastUserActivityTimeo ut", "(J)I",(void*)setLastUserActivityTimeo ut },
{"setScreenState", "(Z)I", (void*)setScreenState },
{"shutdown", "()V", (void*)android_os_Power_shutdown },
{ "reboot","(Ljava/lang/String;)V", (void*)android_os_Power_reboot },
};int register_android_os_Power(JNIEnv *env)// function to register mapping tablefrom name to function
{
returnAndroidRuntime::registerNativeMethods(
env, "android/os/Power",
method_table, NELEM(method_table));
}
3. in /framework/base/core/jni , a file named:AndroidRuntime.cpp
4.calling a native method ( JNI method)
0 0
- How native function is called in…
- How to create patch file in Linu…
- How to write/use DLL in Linux sy…
- How to get Time Separator in Jav…
- resource is out of sync with t…
- Google+ is Blocked in China
- function module …
-  
- how to do with a slow oracle dat…
- How to get a good idea to perfor…
- How GNU Radio Core Works -- An A…
- How to Disable and Turn Off UAC …
- How to pass a hash to a subrouti…
- How do I get default date and ti…
- How to sign a Driver by Windows …
- How to got the Mac address from …
- How to move LOB Data to Another …
- javascript Function
- FW:Android 的属性系统(翻译)
- Android的底层库libutils介绍
- 覆灭和新生
- Chrome32发布,包含页面提示、新Win8界面,更好的恶意软件拦截,和监护人功能
- Android应用及应用管理简介
- How native function is called in…
- Android Building System 分析
- 武林大会与狗熊打架
- 吃素的困境
- 一句话评论明星(2)
- 采用scp命令在Linux系统之间copy文…
- tar
- Android事件处理
- Unix/Linux 脚本中 "set -e" 的作…