Chinaunix首页 | 论坛 | 博客
  • 博客访问: 656664
  • 博文数量: 171
  • 博客积分: 2246
  • 博客等级: 大尉
  • 技术积分: 1574
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-31 11:45
文章分类

全部博文(171)

文章存档

2018年(3)

2017年(4)

2015年(1)

2014年(20)

2013年(57)

2012年(86)

分类: 嵌入式

2012-08-14 14:48:40

FROM:http://blog.csdn.net/a379039233/article/details/6097651
1.Power.java--> find corresponding native cfile(查找对应的具体用C实现的C文件)
      android.os.Power.java:native file ---->.../jni/android_os_Power.cpp
2. in android_os_Power.c, you canfind:

点击(此处)折叠或打开

  1. static JNINativeMethod method_table[]= // Native functiontable
  2. {
  3.     {"acquireWakeLock", "(ILjava/lang/String;)V", (void*)acquireWakeLock},
  4.     {"releaseWakeLock", "(Ljava/lang/String;)V", (void*)releaseWakeLock},
  5.     {"setLastUserActivityTimeout", "(J)I",(void*)setLastUserActivityTimeout },
  6.     {"setScreenState", "(Z)I", (void*)setScreenState },
  7.     {"shutdown", "()V", (void*)android_os_Power_shutdown },
  8.     { "reboot","(Ljava/lang/String;)V", (void*)android_os_Power_reboot },
  9. };
  10.  
  11. int register_android_os_Power(JNIEnv *env)//function to register mapping tablefrom name 
  12.   //to function
  13. {
  14.     returnAndroidRuntime::registerNativeMethods(
  15.        env, "android/os/Power",
  16.        method_table, NELEM(method_table));
  17. }
3. in /framework/base/core/jni , a file named:AndroidRuntime.cpp
   1) a global register function array

点击(此处)折叠或打开

  1. static const RegJNIRec gRegJNI[] =
  2.            {
  3.                     // ...
  4.                      register_android_os_Power,
  5.           }
   2) Register native function process

点击(此处)折叠或打开

  1. int AndroidRuntime::startReg(JNIEnv* env)
  2. or
  3. Java_com_android_internal_util_WithFramework_registerNatives(...)
  4. or
  5. Java_LoadClass_registerNatives(....)
  6.     ---> register_jni_procs(gRegJNI, NELEM(gRegJNI),env)
  7.     ---> foreach(member of gRegJNI) call register_XXX_XXX_XXX..XXX() 
  8.     //so here register_android_os_power() will becalled
  9.     ---> AndroidRuntime::registerNativeMethods(env, 
  10.                            /*class_namelike */"android/os/Power", 
  11.                          /*method table like*/method_table,
  12.                                               size)
  13.     ---> jniRegisterNativeMethods(env, className,gMethods, numMethods)
  14.     ---pEnv->RegisterNatives(env, clazz, gMethods,numMethods);
  15.     ---> foreach(method) call dvmRegisterJNIMethod(ClassObject* clazz, 
  16.                                                   const char*methodName,
  17.                                                   constchar* signature, void* fnPtr)
  18.     ---> call dvmSetNativeFunc(method, dvmCallSynchronizedJNIMethod, fnPtr); 
  19.                                                    //for sycn method
  20.     or
  21.     call dvmSetNativeFunc(method, dvmCallJNIMethod,fnPtr);
  22.     ---> ((Method*)method)->insns = insns;
  23.     // set actual codespace to be executed for a native function
4.calling a native method ( JNI method)

点击(此处)折叠或打开

  1. void dvmPlatformInvoke(void* pEnv,ClassObject* clazz, int argInfo, int argc,
  2.     const u4*argv, const char* shorty, void* func, JValue*pReturn)
  3.    dvmCallMethod() /dvmInvokeMethod
  4.    ------->
  5.    if(dvmIsNativeMethod(method))
  6.    {
  7.       (*method->nativeFunc)(self->curFrame,&retval, method, self);
  8.    }

阅读(2931) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~