{"id":14428,"date":"2024-08-22T16:26:53","date_gmt":"2024-08-22T08:26:53","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14428"},"modified":"2024-08-26T14:01:33","modified_gmt":"2024-08-26T06:01:33","slug":"android_util_binder-cpp","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=14428","title":{"rendered":"android_util_Binder.cpp"},"content":{"rendered":"<p>\u6e90\u7801\u4f4d\u7f6e\uff1a<code>frameworks\/base\/core\/jni\/android_util_Binder.cpp<\/code><\/p>\n<h1>\u65b9\u6cd5<\/h1>\n<ul>\n<li>android_os_BinderInternal_getContextObject\n<pre><code class=\"language-cpp\">1033 static jobject android_os_BinderInternal_getContextObject(JNIEnv* env, jobject clazz)\n1034 {\n1035     sp&lt;IBinder&gt; b = ProcessState::self()-&gt;getContextObject(NULL);\n1036     return javaObjectForIBinder(env, b);\n1037 }<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>ProcessState\u7c7b\u89c1\uff1a<a href=\"http:\/\/xinyiworld.top\/wordpress_it\/?p=14446\">http:\/\/xinyiworld.top\/wordpress_it\/?p=14446<\/a><\/p>\n<ul>\n<li>javaObjectForIBinder<\/li>\n<\/ul>\n<pre><code class=\"language-cpp\">662 \/\/ If the argument is a JavaBBinder, return the Java object that was used to create it.\n 663 \/\/ Otherwise return a BinderProxy for the IBinder. If a previous call was passed the\n 664 \/\/ same IBinder, and the original BinderProxy is still alive, return the same BinderProxy.\n 665 jobject javaObjectForIBinder(JNIEnv* env, const sp&lt;IBinder&gt;&amp; val)\n 666 {   \n 667     if (val == NULL) return NULL;\n 668     \n 669     if (val-&gt;checkSubclass(&amp;gBinderOffsets)) {\n 670         \/\/ It&#039;s a JavaBBinder created by ibinderForJavaObject. Already has Java object.\n 671         jobject object = static_cast&lt;JavaBBinder*&gt;(val.get())-&gt;object();\n 672         LOGDEATH(&quot;objectForBinder %p: it&#039;s our own %p!\\n&quot;, val.get(), object);\n 673         return object;\n 674     }\n 675     \n 676     BinderProxyNativeData* nativeData = new BinderProxyNativeData();\n 677     nativeData-&gt;mOrgue = new DeathRecipientList;\n 678     nativeData-&gt;mObject = val;\n 679 \n 680     jobject object = env-&gt;CallStaticObjectMethod(gBinderProxyOffsets.mClass,\n 681             gBinderProxyOffsets.mGetInstance, (jlong) nativeData, (jlong) val.get());\n 682     if (env-&gt;ExceptionCheck()) {\n 683         \/\/ In the exception case, getInstance still took ownership of nativeData.\n 684         return NULL;\n 685     }\n 686     BinderProxyNativeData* actualNativeData = getBPNativeData(env, object);\n 687     if (actualNativeData == nativeData) {\n 688         \/\/ Created a new Proxy\n 689         uint32_t numProxies = gNumProxies.fetch_add(1, std::memory_order_relaxed);\n 690         uint32_t numLastWarned = gProxiesWarned.load(std::memory_order_relaxed);\n 691         if (numProxies &gt;= numLastWarned + PROXY_WARN_INTERVAL) {\n 692             \/\/ Multiple threads can get here, make sure only one of them gets to\n 693             \/\/ update the warn counter.\n 694             if (gProxiesWarned.compare_exchange_strong(numLastWarned,\n 695                         numLastWarned + PROXY_WARN_INTERVAL, std::memory_order_relaxed)) {\n 696                 ALOGW(&quot;Unexpectedly many live BinderProxies: %d\\n&quot;, numProxies);\n 697             }\n 698         }\n 699     } else {\n 700         delete nativeData;\n 701     }\n 702 \n 703     return object;\n 704 }<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"14428\" 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>\u6e90\u7801\u4f4d\u7f6e\uff1aframeworks\/base\/core\/jni\/android_util_Binder. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1102],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14428"}],"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=14428"}],"version-history":[{"count":4,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14428\/revisions"}],"predecessor-version":[{"id":14469,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/14428\/revisions\/14469"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14428"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}