اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release بدلاً من aosp-main لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
Binder هو نظام للتواصل بين العمليات يتيح لعمليتين على جهاز يعمل بنظام التشغيل Android التواصل مع بعضهما. يوفر Binder وسيلة لتنفيذ طلبات استدعاء الدوال في عملية أخرى تكون غير مرئية تمامًا للمستدعي.
في مصطلحات Binder، تُعدّ عملية الاتصال العميل ويُطلق على نقطة النهاية اسم وكيل Binder أو وكيل. في المقابل، يُطلق على العملية التي يتم استدعاؤها اسم الخادم، ويُطلق على نقطة النهاية اسم عقدة الرابط أو العقدة.
يمكن لكل عقدة عرض واجهة خاصة بها وتنفيذها. باستخدام وكيل، يمكن للعميل تنفيذ طرق على واجهة عقدة كما لو كان الاستدعاء عبارة عن استدعاء دالة محلية. يوضّح المثال التالي طريقة استدعاء:
int result = someNodeInterface.foo(a, b); // someNodeInterface is a proxy object
لنفترض أنّ العميل الذي يستدعي foo() يعمل في العملية (أ) وأنّ الخادم الذي ينفّذ foo() يعمل في العملية (ب). يوضح الشكل 1 كيفية تنفيذ هذا الاستدعاء:
الشكل 1. تنفيذ طلب Binder
لتنفيذ طريقة في عملية أخرى، كما هو موضّح في الشكل 1، يحدث ما يلي:
يستدعي رمز العميل في العملية (أ) رمز الوكيل في العملية (أ). ينشئ رمز الوكيل في العملية (أ) معاملة تحتوي على العناصر التالية:
معرّف العقدة
معرّف لطريقة foo() على العقدة
مخزن مؤقت يحتوي على نسخة من الوسيطتين a وb
يتم إرسال المعاملة إلى برنامج تشغيل نواة Binder.
يحدّد برنامج تشغيل نواة Binder أنّ العملية B تستضيف العقدة.
ينسخ النواة العملية بأكملها إلى مساحة عنوان العملية B.
يبحث النواة عن سلسلة محادثات في العملية B للتعامل مع المعاملة، ثم يمرّر المعاملة إليها.
يفكّ السلسلة حزمة المعاملة، ويعثر على العقدة، ويرسل المعاملة إلى عنصر العقدة.
يحصل عنصر العقدة على معرّف الدالة من المعاملة، ويفك حزمة a وb من مخزن المعاملات المؤقت، ويخزّن a وb في متغيرات محلية.
يستدعي عنصر العقدة foo(a, b) في رمز الخادم في العملية B.
يتم عرض نتيجة المكالمة في معاملة ردّ يتم تمريرها إلى برنامج تشغيل النواة ثم إلى الوكيل الذي أجرى المكالمة في العملية (أ).
يعرض الخادم الوكيل هذه النتيجة على المتصل في العملية (أ).
حالات استخدام Binder
يمكن استخدام Binder في مجموعة متنوعة من السيناريوهات التي يجب فيها إجراء اتصال بين البرامج في عمليات مختلفة. مثلاً:
يستخدم تطبيق الكاميرا Binder للتواصل مع خادم الكاميرا في عملية أخرى. يستخدم خادم الكاميرا بعد ذلك binder للتواصل مع طبقة HAL الخاصة بالكاميرا في عملية أخرى.
يستخدم التطبيق binder للتواصل مع خادم النظام في عملية أخرى. يستخدم خادم النظام binder للتواصل مع طبقات HAL في عمليات أخرى.
يستخدم تطبيق في إحدى العمليات Binder للتواصل مع تطبيق آخر في عملية أخرى.
يستخدم برنامج النظام الخفي المسؤول عن تثبيت التطبيقات وتحديثها وإزالتها (installd) برنامج binder للتواصل مع برنامج Android الخفي (artd) من أجل تجميع التطبيقات.
لغة تعريف واجهة نظام Android (AIDL) وBinder
استخدِم لغة تعريف واجهة Android (AIDL) لتحديد واجهات البرمجة التي تستخدم binder للتواصل بين العمليات (IPC). لمزيد من المعلومات، اطّلِع على نظرة عامة حول AIDL.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-08-05 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-05 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Binder overview\n\n*Binder* is a system for interprocess\ncommunication that lets two processes on an Android-powered device\ncommunicate. Binder provides a means to execute function calls in another\nprocess that is completely transparent to the caller.\n\nIn binder terms, the calling process is considered the *client* and its\nendpoint is called the *binder proxy* or *proxy* . Conversely,\nthe process being called is the *server* and its endpoint is called the\n*binder node* or *node*.\n\nEach node can expose and implement its own interface. And, using a proxy, the\nclient can execute methods on a node interface as though invocation was a\nlocal function call. The following example shows a method being invoked: \n\n int result = someNodeInterface.foo(a, b); // someNodeInterface is a proxy object\n\nAssume that the client calling `foo()` is running in process A and the server\nimplementing `foo()` is running in process B. Figure 1 shows how this call is\nexecuted:\n\n**Figure 1.** Binder call execution.\n\nTo execute a method in another process, as shown in figure 1,\nthe following occurs:\n\n1. The client code in process A invokes the proxy code in process A. The proxy code in process A creates a transaction containing the following items:\n - An identifier for the node\n - An identifier for the `foo()` method on the node\n - A buffer containing a copy of the arguments `a` and `b`\n2. The transaction is submitted to the binder kernel driver.\n3. The binder kernel driver determines that process B hosts the node.\n4. The kernel copies the entire transaction into process B's address space.\n5. The kernel finds a thread in process B to handle the transaction and passes the transaction to it.\n6. The thread unpacks the transaction, finds the node, and sends the transaction to the node object.\n7. The node object obtains the function identifier from the transaction, unpacks `a` and `b` from the transaction buffer, and stores `a` and `b` in local variables.\n8. The node object calls `foo(a, b)` on the server code in process B.\n9. The result of the call is returned in a reply transaction, which is passed to the kernel driver and then back to the calling proxy in process A.\n10. The proxy returns that result to the caller in process A.\n\nBinder use cases\n----------------\n\nBinder can be used in a variety of scenarios where communication between\nsoftware in different processes must occur. For example:\n\n- A camera app uses binder to communicate with the camera server in\n another process. The camera server then uses binder to communicate with the\n camera HAL in another process.\n\n- An app uses binder to communicate with a system server in another process. The\n system server uses binder to talk to HALs in other processes.\n\n- An app in one process uses binder to communicate with a different app in\n another process.\n\n- The system daemon responsible for installing, updating, and removing\n apps (`installd`) uses binder to communicate with the Android\n runtime daemon ('artd') to compile apps.\n\nAIDL and binder\n---------------\n\nUse the Android Interface Design Language (AIDL) to define programming\ninterfaces that use binder for IPC. For further information, see the\n[AIDL overview](/docs/core/architecture/aidl).\n| **Note:** HIDL is deprecated; only AIDL is recommended for new implementations."]]