{"id":14550,"date":"2024-08-30T16:56:44","date_gmt":"2024-08-30T08:56:44","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14550"},"modified":"2024-09-03T17:31:56","modified_gmt":"2024-09-03T09:31:56","slug":"jni%e6%96%b9%e6%b3%95%e6%b3%a8%e5%86%8c%e5%8e%9f%e7%90%86%ef%bc%88%e4%bb%a5android_util_binder-cpp%e4%b8%ba%e4%be%8b%ef%bc%89","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14550","title":{"rendered":"\u7cfb\u7edf\u7c7bJNI\u65b9\u6cd5\u6ce8\u518c\u539f\u7406\uff08\u4ee5android_util_Binder.cpp\u4e3a\u4f8b\uff09"},"content":{"rendered":"<p>\u89c1<code>frameworks\/base\/core\/jni\/AndroidRuntime.cpp<\/code>\u7684startReg\u65b9\u6cd5<\/p>\n<pre><code class=\"language-cpp\">\/\/extern \u5173\u952e\u5b57\u7684\u4f5c\u7528\u662f\u544a\u8bc9\u7f16\u8bd1\u5668\u4e00\u4e2a\u53d8\u91cf\u6216\u51fd\u6570\u5df2\u7ecf\u5728\u5176\u4ed6\u5730\u65b9\u5b9a\u4e49\u8fc7\u4e86\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u3002\nextern int register_android_os_Binder(JNIEnv* env);\n\n1428 static const RegJNIRec gRegJNI[] = {\n         ...\n1450     REG_JNI(register_android_os_Binder),        \n         ...\n    }<\/code><\/pre>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_16 counter-hierarchy counter-decimal ez-toc-grey\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" style=\"display: none;\"><i class=\"ez-toc-glyphicon ez-toc-icon-toggle\"><\/i><\/a><\/span><\/div>\n<nav><ul class=\"ez-toc-list ez-toc-list-level-1\"><li class=\"ez-toc-page-1 ez-toc-heading-level-1\"><a class=\"ez-toc-link ez-toc-heading-1\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14550\/#register_android_os_Binder%E6%96%B9%E6%B3%95\" title=\"register_android_os_Binder\u65b9\u6cd5\">register_android_os_Binder\u65b9\u6cd5<\/a><ul class=\"ez-toc-list-level-2\"><li class=\"ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-2\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14550\/#%E2%86%92int_register_android_os_Binder\" title=\"\u2192int_register_android_os_Binder\">\u2192int_register_android_os_Binder<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-3\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14550\/#%E2%86%92int_register_android_os_BinderInternal\" title=\"\u2192int_register_android_os_BinderInternal\">\u2192int_register_android_os_BinderInternal<\/a><\/li><li class=\"ez-toc-page-1 ez-toc-heading-level-2\"><a class=\"ez-toc-link ez-toc-heading-4\" href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14550\/#%E2%86%92int_register_android_os_BinderProxy\" title=\"\u2192int_register_android_os_BinderProxy\">\u2192int_register_android_os_BinderProxy<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"register_android_os_Binder%E6%96%B9%E6%B3%95\"><\/span>register_android_os_Binder\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>register_android_os_Binder\u65b9\u6cd5\u5b9a\u4e49\u5728<code>frameworks\/base\/core\/jni\/android_util_Binder.cpp<\/code>\u7c7b\u4e2d<\/p>\n<pre><code class=\"language-cpp\">1466 int register_android_os_Binder(JNIEnv* env)\n1467 {\n1468     if (int_register_android_os_Binder(env) &lt; 0)\n1469         return -1;\n1470     if (int_register_android_os_BinderInternal(env) &lt; 0)\n1471         return -1;\n1472     if (int_register_android_os_BinderProxy(env) &lt; 0)\n1473         return -1;\n1474 \n1475     jclass clazz = FindClassOrDie(env, &quot;android\/util\/Log&quot;);\n1476     gLogOffsets.mClass = MakeGlobalRefOrDie(env, clazz);\n1477     gLogOffsets.mLogE = GetStaticMethodIDOrDie(env, clazz, &quot;e&quot;,\n1478             &quot;(Ljava\/lang\/String;Ljava\/lang\/String;Ljava\/lang\/Throwable;)I&quot;);\n1479 \n1480     clazz = FindClassOrDie(env, &quot;android\/os\/ParcelFileDescriptor&quot;);\n1481     gParcelFileDescriptorOffsets.mClass = MakeGlobalRefOrDie(env, clazz);\n1482     gParcelFileDescriptorOffsets.mConstructor = GetMethodIDOrDie(env, clazz, &quot;&lt;init&gt;&quot;,\n1483                                                                  &quot;(Ljava\/io\/FileDescriptor;)V&quot;);\n1484 \n1485     clazz = FindClassOrDie(env, &quot;android\/os\/StrictMode&quot;);\n1486     gStrictModeCallbackOffsets.mClass = MakeGlobalRefOrDie(env, clazz);\n1487     gStrictModeCallbackOffsets.mCallback = GetStaticMethodIDOrDie(env, clazz,\n1488             &quot;onBinderStrictModePolicyChange&quot;, &quot;(I)V&quot;);\n1489 \n1490     clazz = FindClassOrDie(env, &quot;java\/lang\/Thread&quot;);\n1491     gThreadDispatchOffsets.mClass = MakeGlobalRefOrDie(env, clazz);\n1492     gThreadDispatchOffsets.mDispatchUncaughtException = GetMethodIDOrDie(env, clazz,\n1493             &quot;dispatchUncaughtException&quot;, &quot;(Ljava\/lang\/Throwable;)V&quot;);\n1494     gThreadDispatchOffsets.mCurrentThread = GetStaticMethodIDOrDie(env, clazz, &quot;currentThread&quot;,\n1495             &quot;()Ljava\/lang\/Thread;&quot;);\n1496 \n1497     return 0;\n1498 }<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E2%86%92int_register_android_os_Binder\"><\/span>\u2192int_register_android_os_Binder<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-cpp\"> 961 static const JNINativeMethod gBinderMethods[] = {\n 962      \/* name, signature, funcPtr *\/\n 963     \/\/ @CriticalNative\n 964     { &quot;getCallingPid&quot;, &quot;()I&quot;, (void*)android_os_Binder_getCallingPid },\n 965     \/\/ @CriticalNative\n 966     { &quot;getCallingUid&quot;, &quot;()I&quot;, (void*)android_os_Binder_getCallingUid },\n 967     \/\/ @CriticalNative\n 968     { &quot;isHandlingTransaction&quot;, &quot;()Z&quot;, (void*)android_os_Binder_isHandlingTransaction },\n 969     \/\/ @CriticalNative\n 970     { &quot;clearCallingIdentity&quot;, &quot;()J&quot;, (void*)android_os_Binder_clearCallingIdentity },\n 971     { &quot;restoreCallingIdentity&quot;, &quot;(J)V&quot;, (void*)android_os_Binder_restoreCallingIdentity },\n 972     \/\/ @CriticalNative\n 973     { &quot;setThreadStrictModePolicy&quot;, &quot;(I)V&quot;, (void*)android_os_Binder_setThreadStrictModePolicy },\n 974     \/\/ @CriticalNative\n 975     { &quot;getThreadStrictModePolicy&quot;, &quot;()I&quot;, (void*)android_os_Binder_getThreadStrictModePolicy },\n 976     \/\/ @CriticalNative\n 977     { &quot;setCallingWorkSourceUid&quot;, &quot;(I)J&quot;, (void*)android_os_Binder_setCallingWorkSourceUid },\n 978     \/\/ @CriticalNative\n 979     { &quot;getCallingWorkSourceUid&quot;, &quot;()I&quot;, (void*)android_os_Binder_getCallingWorkSourceUid },\n 980     \/\/ @CriticalNative\n 981     { &quot;clearCallingWorkSource&quot;, &quot;()J&quot;, (void*)android_os_Binder_clearCallingWorkSource },\n 982     { &quot;restoreCallingWorkSource&quot;, &quot;(J)V&quot;, (void*)android_os_Binder_restoreCallingWorkSource },\n 983     { &quot;flushPendingCommands&quot;, &quot;()V&quot;, (void*)android_os_Binder_flushPendingCommands },\n 984     { &quot;getNativeBBinderHolder&quot;, &quot;()J&quot;, (void*)android_os_Binder_getNativeBBinderHolder },\n 985     { &quot;getNativeFinalizer&quot;, &quot;()J&quot;, (void*)android_os_Binder_getNativeFinalizer },\n 986     { &quot;blockUntilThreadAvailable&quot;, &quot;()V&quot;, (void*)android_os_Binder_blockUntilThreadAvailable }\n 987 };\n\n 989 const char* const kBinderPathName = &quot;android\/os\/Binder&quot;;\n 990 \n 991 static int int_register_android_os_Binder(JNIEnv* env)\n 992 {\n 993     jclass clazz = FindClassOrDie(env, kBinderPathName);\n 994 \n 995     gBinderOffsets.mClass = MakeGlobalRefOrDie(env, clazz);\n 996     gBinderOffsets.mExecTransact = GetMethodIDOrDie(env, clazz, &quot;execTransact&quot;, &quot;(IJJI)Z&quot;);\n 997     gBinderOffsets.mGetInterfaceDescriptor = GetMethodIDOrDie(env, clazz, &quot;getInterfaceDescriptor&quot;,\n 998         &quot;()Ljava\/lang\/String;&quot;);\n 999     gBinderOffsets.mObject = GetFieldIDOrDie(env, clazz, &quot;mObject&quot;, &quot;J&quot;);\n1000 \n1001     return RegisterMethodsOrDie(\n1002         env, kBinderPathName,\n1003         gBinderMethods, NELEM(gBinderMethods));\n1004 }<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E2%86%92int_register_android_os_BinderInternal\"><\/span>\u2192int_register_android_os_BinderInternal<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h2><span class=\"ez-toc-section\" id=\"%E2%86%92int_register_android_os_BinderProxy\"><\/span>\u2192int_register_android_os_BinderProxy<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<button class=\"simplefavorite-button\" data-postid=\"14550\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u89c1frameworks\/base\/core\/jni\/AndroidRuntime.cpp\u7684start [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1064],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14550"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14550"}],"version-history":[{"count":10,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14550\/revisions"}],"predecessor-version":[{"id":14619,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14550\/revisions\/14619"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14550"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}