2025 年 3 月 27 日より、AOSP のビルドとコントリビューションには aosp-main
ではなく android-latest-release
を使用することをおすすめします。詳細については、AOSP の変更をご覧ください。
AIDL の概要
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Android インターフェース定義言語(AIDL)は、IPC を考慮しなくても済むようになるツールです。インターフェースが(.aidl
ファイルで)指定されると、さまざまなビルドシステムで aidl
バイナリによって C++ または Java のバインディングが作成されます。指定されたインターフェースは、ランタイムやビット数にかかわらず複数のプロセスで使用できるようになります。
AIDL は、Android の任意のプロセス間(プラットフォーム コンポーネント間またはアプリ間)で使用できます。ただし、アプリ用 API として使用されることはありません。たとえば、SDK API をプラットフォームに実装するために AIDL を使用できますが、SDK API サーフェスに AIDL API が直接含まれることはありません。アプリ間で AIDL を直接使用する方法については、対応する Android デベロッパー向けドキュメントをご覧ください。APEX(Android 10 以降)や HAL(Android 11 以降)など、個別に更新されるプラットフォーム コンポーネント間で AIDL を使用する場合は、安定版 AIDL というバージョニング システムを使用する必要があります。
例
以下に、AIDL インターフェースの例を示します。
package my.package;
import my.package.Baz; // defined elsewhere
interface IFoo {
void doFoo(Baz baz);
}
サーバー プロセスはインターフェースを登録して呼び出しを配信し、クライアント プロセスはそれらのインターフェースを呼び出します。多くの場合、プロセスは複数のインターフェースを参照する可能性があるため、クライアントとサーバーの両方として機能します。AIDL 言語について詳しくは、AIDL 言語をご覧ください。これらのインターフェースを使用できるさまざまなランタイムについて詳しくは、AIDL バックエンドをご覧ください。こうした型宣言は特定の言語のクラス宣言とほとんど同じですが、複数のプロセスで機能する点が異なります。
仕組み
AIDL は binder カーネル ドライバを使用して呼び出しを行います。呼び出しを行うと、1 つのメソッド識別子とすべてのオブジェクトがバッファにパッキングされ、リモート プロセスにコピーされて、binder スレッドがデータの読み取りを待機します。トランザクションのデータを受け取ると、binder スレッドはローカル プロセス内のネイティブのスタブ オブジェクトを検索します。そのクラスがデータを解凍し、ローカル インターフェース オブジェクトを呼び出します。このローカル インターフェース オブジェクトは、サーバー プロセスが作成して登録するオブジェクトです。同じプロセスと同じバックエンドで呼び出しが行われる場合は、プロキシ オブジェクトが存在しないため、呼び出しはパッキングも解凍もされずに直接行われます。
デバイス上のサービスとのインタラクション
Android には、デバイス上のサービスとのインタラクションを可能にするコマンドがいくつか用意されています。次を試します。
adb shell dumpsys --help # listing and dumping services
adb shell service --help # sending commands to services for testing
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2025-03-26 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-03-26 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"]]