از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
مروری بر AIDL
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
زبان تعریف رابط اندروید (AIDL) ابزاری است که به کاربران اجازه میدهد IPC را انتزاعی کنند. با توجه به یک رابط (مشخص شده در یک فایل .aidl
)، سیستمهای ساخت مختلف از باینری aidl
برای ساخت پیوندهای C++ یا جاوا استفاده میکنند تا این رابط بدون در نظر گرفتن زمان اجرا یا بیتی در آنجا، در سراسر فرآیندها قابل استفاده باشد.
AIDL را می توان بین هر فرآیندی در اندروید استفاده کرد: بین اجزای پلتفرم یا بین برنامه ها. با این حال، هرگز به عنوان یک API برای برنامه ها استفاده نمی شود. برای مثال، AIDL ممکن است برای پیادهسازی API SDK در پلتفرم استفاده شود، اما سطح API SDK هرگز مستقیماً حاوی APIهای AIDL نیست. برای مستندات مربوط به نحوه استفاده مستقیم از AIDL بین برنامهها، به مستندات مربوطه توسعه دهندگان Android مراجعه کنید. هنگامی که AIDL بین اجزای پلتفرم که به طور جداگانه به روز می شوند، مانند APEX (شروع در Android 10) یا HAL (شروع در Android 11) استفاده می شود، باید از سیستم نسخه سازی معروف به Stable AIDL استفاده شود.
مثال
در اینجا یک مثال رابط AIDL آمده است:
package my.package;
import my.package.Baz; // defined elsewhere
interface IFoo {
void doFoo(Baz baz);
}
یک فرآیند سرور یک رابط را ثبت میکند و تماسهایی را به آن ارائه میکند، و یک فرآیند مشتری با آن واسطها تماس برقرار میکند. در بسیاری از موارد، یک فرآیند هم به عنوان یک کلاینت و هم به عنوان سرور عمل می کند زیرا ممکن است به چندین رابط ارجاع دهد. برای جزئیات بیشتر در مورد زبان AIDL، به زبان AIDL مراجعه کنید. برای جزئیات بیشتر در مورد زمانهای اجرا مختلف موجود برای استفاده از این رابطها، به Backends AIDL مراجعه کنید. این نوع اعلانها دقیقاً مانند یک اعلان کلاس در یک زبان خاص هستند، اما در سراسر فرآیندها کار میکنند.
چگونه کار می کند
AIDL از درایور هسته بایندر برای برقراری تماس استفاده می کند. هنگامی که تماس برقرار می کنید، یک شناسه متد و همه اشیاء در یک بافر بسته بندی می شوند و در یک فرآیند راه دور کپی می شوند، جایی که یک رشته بایندر برای خواندن داده ها منتظر می ماند. هنگامی که یک رشته بایندر دادهها را برای یک تراکنش دریافت میکند، رشته یک شیء خرد بومی را در فرآیند محلی جستجو میکند و این کلاس دادهها را باز میکند و با یک شی رابط محلی تماس برقرار میکند. این شیء رابط محلی همان چیزی است که یک فرآیند سرور ایجاد و ثبت می کند. هنگامی که تماسها در همان فرآیند و باطن یکسان انجام میشوند، هیچ شیء پروکسی وجود ندارد، و بنابراین تماسها مستقیم و بدون بستهبندی یا باز کردن بستهبندی میشوند. برای اطلاعات بیشتر، به نمای کلی Binder مراجعه کنید.
با خدمات موجود در دستگاه تعامل داشته باشید
اندروید با چند دستور ارائه می شود که امکان تعامل با سرویس های دستگاه را فراهم می کند. امتحان کنید:
adb shell dumpsys --help # listing and dumping services
adb shell service --help # sending commands to services for testing
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-30 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-30 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# AIDL overview\n\nThe Android Interface Definition Language (AIDL) is a tool that lets users\nabstract away IPC. Given an interface (specified in a `.aidl`\nfile), various build systems use the `aidl` binary to construct C++ or Java\nbindings so that this interface can be used across processes, regardless of the\nruntime or bitness there.\n\nAIDL can be used between any process in Android: between platform components\nor between apps. However, it is never used as an API for apps. AIDL may be used\nto implement an SDK API in the platform, for example, but the SDK API surface\nnever contains AIDL APIs directly. For documentation about how to use AIDL\nbetween apps directly, see corresponding\n[Android developers\ndocumentation](https://developer.android.com/guide/components/aidl).\nWhen AIDL is used between platform components that are updated separately, such\nas APEXes (starting in Android 10) or HALs (starting in\nAndroid 11), the versioning system known as\n[Stable AIDL](/docs/core/architecture/aidl/stable-aidl) must be used.\n\nExample\n-------\n\nHere is an example AIDL interface: \n\n package my.package;\n\n import my.package.Baz; // defined elsewhere\n\n interface IFoo {\n void doFoo(Baz baz);\n }\n\nA *server* process registers an interface and serves calls to it, and a *client*\nprocess makes calls to those interfaces. In many cases, a process acts as both a\nclient and a server since it may be referencing multiple interfaces. For more\ndetails about the AIDL language, see\n[AIDL language](/docs/core/architecture/aidl/aidl-language). For more details\nabout the various runtimes available to use these interfaces, see\n[AIDL backends](/docs/core/architecture/aidl/aidl-backends). These type\ndeclarations are exactly like a class declaration in a given language, but they\nwork across processes.\n\nHow it works\n------------\n\nAIDL uses the binder kernel driver to make calls. When you make a call, a\nmethod identifier and all of the objects are packed onto a buffer and copied to\na remote process where a binder thread waits to read the data. Once a binder\nthread receives data for a transaction, the thread looks up a native stub object\nin the local process, and this class unpacks the data and makes a call on a\nlocal interface object. This local interface object is the one a server process\ncreates and registers. When calls are made in the same process and the same\nbackend, no proxy objects exist, and so calls are direct without any\npacking or unpacking. For further information, see the\n[Binder overview](/docs/core/architecture/ipc/binder-overview).\n\nInteract with services on the device\n------------------------------------\n\nAndroid comes with a few commands to allow interacting with services on the\ndevice. Try: \n\n adb shell dumpsys --help # listing and dumping services\n adb shell service --help # sending commands to services for testing"]]