اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release
بدلاً من aosp-main
لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
"قائمة الرسائل السريعة" باستخدام لغة تعريف واجهة نظام Android (AIDL)
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
اعتبارًا من Android 12، يمكن استخدام Fast Message Queue
مع واجهات AIDL باستخدام الخلفية في NDK. يتيح ذلك للعمليات
التواصل بدون تكاليف إضافية والقيود المفروضة على معاملات الربط بعد
بعض الإعدادات القصيرة. يتيح استخدام Stable AIDL التواصل بين عمليات النظام و
المورّد.
أنواع الحمولات المسموح بها
يجب أن تتضمّن الرسائل المُرسَلة بين العمليات في قائمة انتظار رسائل الذاكرة المشتركة تنسيق الذاكرة نفسه على مستوى حدود العمليات، ولا يمكن أن تحتوي على مؤشرات. سيؤدي محاولة إنشاء
AidlMessageQueue
بنوع غير متوافق إلى حدوث خطأ في الترجمة.
أنواع الطوابير المتوافقة
تتوفّر أنواع الطوابير نفسها من HIDL، والتي يُشار إليها غالبًا باسم "النكهات"، مع AIDL. وتُستخدَم هذه الوسائط كوسائط نماذج ل
القوائم والأوصاف.
أنواع HIDL |
أنواع لغة تعريف واجهة نظام Android |
android::hardware::kSynchronizedReadWrite |
android.hardware.common.fmq.SynchronizedReadWrite |
android::hardware::kUnsynchronizedWrite |
android.hardware.common.fmq.UnsynchronizedWrite |
كيفية الاستخدام
حدِّد واجهة AIDL التي ستُرسل MQDescriptor
إلى العملية الأخرى.
يمكن استخدام MQDescriptor
في أي مكان يمكن فيه استخدام قطعة أرض.
وسيطات النموذج المطلوبة لدالة MQDescriptor
هي نوع الحمولة ونكهة "الصفّ".
import android.hardware.common.fmq.MQDescriptor
import android.hardware.common.fmq.SynchronizedReadWrite
void getQueue(out MQDescriptor<int, SynchronizedReadWrite> mqDesc);
إنّ عملية إعداد كل جانب من صف الرسائل متطابقة تقريبًا مع
العملية باستخدام HIDL، مع استخدام أنواع AIDL فقط.
#include <fmq/AidlMessageQueue.h>
...
using ::android::AidlMessageQueue;
using ::aidl::android::hardware::common::fmq::MQDescriptor;
using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
...
ndk::ScopedAStatus MyInterface::getQueue(MQDescriptor<int32_t, SynchronizedReadWrite>* mqDesc) {
*mqDesc = mFmqSynchronized->dupeDesc();
return ndk::ScopedAStatus::ok();
}
...
// Create the first side of the queue before servicing getQueue() in this example
mFmqSynchronized =
new AidlMessageQueue<int32_t, SynchronizedReadWrite>(kNumElementsInQueue);
ستنشئ عملية الاستقبال الجانب الآخر من "قائمة الانتظار" باستخدام الوصف الذي تم استلامه من واجهة AIDL.
MQDescriptor<int32_t, SynchronizedReadWrite> desc;
auto ret = service->getQueue(true, &desc);
if (!ret.isOk()) {
...
}
// By default the constructor will reset the read and write pointers of the queue.
// Add a second `false` argument to avoid resetting the pointers.
mQueue = new (std::nothrow) AidlMessageQueue<int32_t, SynchronizedReadWrite>(desc);
if (!mQueue->isValid()) {
...
}
يُرجى العِلم أنّ استخدام AidlMessageQueue
بعد الإعداد هو نفسه استخدام HIDL MessageQueue
.
جميع واجهات برمجة التطبيقات الموضّحة في مقالة استخدام MessageQueue
تتوفّر بالكامل مع AidlMessageQueue
باستثناء واحد:
يتم استبدال const MQDescriptor<T, flavor>* getDesc()
بـ MQDescriptor<T, U> dupeDesc()
الذي يعرض MQDescriptor
AIDL.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Fast Message Queue with AIDL\n\nAs of Android 12, [Fast Message Queue](/docs/core/architecture/hidl/fmq) can be\nused with AIDL interfaces using the NDK backend. This allows processes to\ncommunicate without the overhead and restrictions of binder transactions after\nsome short setup. Using [Stable AIDL](/docs/core/architecture/aidl/stable-aidl) allows communication between system and\nvendor processes.\n\nSupported payload types\n-----------------------\n\n- [@FixedSize](/docs/core/architecture/aidl/aidl-annotations#fixedsize) AIDL `parcelable` types\n- AIDL `enum` types\n- [AIDL integral types](/docs/core/architecture/aidl/aidl-backends#types)\n\nThe messages sent between processes in the shared memory message queue must have the same\nmemory layout across process boundaries and cannot contain pointers. Attempting to create an\n`AidlMessageQueue` with a type that isn't supported will cause a compilation error.\n\nSupported queue types\n---------------------\n\nThe same [queue types](/docs/core/architecture/hidl/fmq#flavors) from HIDL, often\ncalled flavors, are supported with AIDL. These are used as template arguments for\nthe queues and descriptors.\n\n| HIDL Types | AIDL Types |\n|---------------------------------------------|-----------------------------------------------------|\n| `android::hardware::kSynchronizedReadWrite` | `android.hardware.common.fmq.SynchronizedReadWrite` |\n| `android::hardware::kUnsynchronizedWrite` | `android.hardware.common.fmq.UnsynchronizedWrite` |\n\nHow to use\n----------\n\nDefine the AIDL interface that will pass the `MQDescriptor` to the other process.\n`MQDescriptor` can be used anywhere a parcelable can be.\n\nThe required template arguments for `MQDescriptor` are payload type and queue flavor. \n\n import android.hardware.common.fmq.MQDescriptor\n import android.hardware.common.fmq.SynchronizedReadWrite\n\n void getQueue(out MQDescriptor\u003cint, SynchronizedReadWrite\u003e mqDesc);\n\nThe process of setting up each side of the message queue is nearly identical to\nthe [process using HIDL](/docs/core/architecture/hidl/fmq#setup), just using the AIDL types. \n\n #include \u003cfmq/AidlMessageQueue.h\u003e\n ...\n using ::android::AidlMessageQueue;\n using ::aidl::android::hardware::common::fmq::MQDescriptor;\n using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;\n ...\n ndk::ScopedAStatus MyInterface::getQueue(MQDescriptor\u003cint32_t, SynchronizedReadWrite\u003e* mqDesc) {\n *mqDesc = mFmqSynchronized-\u003edupeDesc();\n return ndk::ScopedAStatus::ok();\n }\n ...\n // Create the first side of the queue before servicing getQueue() in this example\n mFmqSynchronized =\n new AidlMessageQueue\u003cint32_t, SynchronizedReadWrite\u003e(kNumElementsInQueue);\n\nThe receiving process will create the other side of the queue with the descriptor received from the AIDL interface. \n\n MQDescriptor\u003cint32_t, SynchronizedReadWrite\u003e desc;\n auto ret = service-\u003egetQueue(true, &desc);\n if (!ret.isOk()) {\n ...\n }\n // By default the constructor will reset the read and write pointers of the queue.\n // Add a second `false` argument to avoid resetting the pointers.\n mQueue = new (std::nothrow) AidlMessageQueue\u003cint32_t, SynchronizedReadWrite\u003e(desc);\n if (!mQueue-\u003eisValid()) {\n ...\n }\n\nUsing the `AidlMessageQueue` after setup is the same as the HIDL `MessageQueue`.\nAll of the APIs described at [Using the MessageQueue](/docs/core/architecture/hidl/fmq#using)\nare fully supported with `AidlMessageQueue` with one exception:\n\n`const MQDescriptor\u003cT, flavor\u003e* getDesc()` is replaced by `MQDescriptor\u003cT, U\u003e dupeDesc()`\nwhich returns the AIDL `MQDescriptor`."]]