החל מ-27 במרץ 2025, מומלץ להשתמש ב-android-latest-release
במקום ב-aosp-main
כדי ליצור תרומות ל-AOSP. מידע נוסף זמין במאמר שינויים ב-AOSP.
סקירה כללית על AIDL
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
שפת ההגדרה לבניית ממשק Android (AIDL) היא כלי שמאפשר למשתמשים להסתיר את פרטי ה-IPC. בהינתן ממשק (שצוין בקובץ .aidl
), מערכות בנייה שונות משתמשות בקובץ הבינארי aidl
כדי ליצור קישורי C++ או Java, כך שאפשר להשתמש בממשק הזה בתהליכים שונים, ללא קשר לזמן הריצה או לרוחב הסיביות.
אפשר להשתמש ב-AIDL בין כל תהליך ב-Android: בין רכיבי פלטפורמה או בין אפליקציות. עם זאת, הוא אף פעם לא משמש כממשק API לאפליקציות. לדוגמה, אפשר להשתמש ב-AIDL כדי להטמיע SDK API בפלטפורמה, אבל ממשק ה-SDK API אף פעם לא מכיל AIDL APIs ישירות. למידע על שימוש ב-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);
}
תהליך השרת רושם ממשק ומשרת קריאות אליו, ותהליך הלקוח מבצע קריאות לממשקים האלה. במקרים רבים, תהליך מסוים פועל גם כלקוח וגם כשרת, כי הוא עשוי להפנות לכמה ממשקי API. לפרטים נוספים על שפת AIDL, אפשר לעיין במאמר שפת AIDL. לפרטים נוספים על סביבות הריצה השונות שזמינות לשימוש בממשקים האלה, אפשר לעיין במאמר בנושא בק-אנד של AIDL. הצהרות מהסוג הזה דומות בדיוק להצהרת מחלקה בשפה נתונה, אבל הן פועלות בין תהליכים.
איך זה עובד
AIDL משתמש במנהל התקן של ליבת ה-binder כדי לבצע קריאות. כשמבצעים שיחה, מזהה השיטה וכל האובייקטים נארזים לתוך מאגר זמני ומועתקים לתהליך מרוחק שבו השרשור של ה-binder ממתין לקריאת הנתונים. אחרי ששרשור של Binder מקבל נתונים של טרנזקציה, השרשור מחפש אובייקט stub מקורי בתהליך המקומי. המחלקה הזו פורקת את הנתונים ומבצעת קריאה באובייקט של ממשק מקומי. אובייקט הממשק המקומי הזה הוא זה שתהליך השרת יוצר ורושם. כשמתבצעות קריאות באותו תהליך ובאותו קצה עורפי, לא קיימים אובייקטים של שרת proxy, ולכן הקריאות הן ישירות ללא אריזה או פריקה. מידע נוסף זמין במאמר סקירה כללית על Binder.
אינטראקציה עם שירותים במכשיר
מערכת Android כוללת כמה פקודות שמאפשרות אינטראקציה עם שירותים במכשיר. כדאי לבצע את הפעולות הבאות:
adb shell dumpsys --help # listing and dumping services
adb shell service --help # sending commands to services for testing
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-30 (שעון UTC).
[[["התוכן קל להבנה","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 (שעון UTC)."],[],[],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"]]