Od 27 marca 2025 r. zalecamy używanie android-latest-release zamiast aosp-main do kompilowania i wspołtworzenia AOSP. Więcej informacji znajdziesz w artykule o zmianach w AOSP.
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Binder to system komunikacji międzyprocesowej, który umożliwia komunikację między dwoma procesami na urządzeniu z Androidem. Binder umożliwia wykonywanie wywołań funkcji w innym procesie, co jest całkowicie niewidoczne dla wywołującego.
W terminologii bindera proces wywołania jest uważany za klienta, a jego punkt końcowy jest nazywany proxy bindera lub proxy. Z kolei wywoływany proces to serwer, a jego punkt końcowy to węzeł bindera lub węzeł.
Każdy węzeł może udostępniać i implementować własny interfejs. Za pomocą serwera proxy klient może wykonywać metody w interfejsie węzła tak, jakby wywołanie było lokalnym wywołaniem funkcji. Poniższy przykład pokazuje wywołanie metody:
int result = someNodeInterface.foo(a, b); // someNodeInterface is a proxy object
Załóżmy, że klient wywołujący foo() działa w procesie A, a serwer implementujący foo() działa w procesie B. Na rysunku 1 pokazano, jak to wywołanie jest wykonywane:
Rysunek 1. Wykonywanie wywołania Binder.
Aby wykonać metodę w innym procesie, jak pokazano na rysunku 1, wykonaj te czynności:
Kod klienta w procesie A wywołuje kod proxy w procesie A. Kod serwera proxy w procesie A tworzy transakcję zawierającą te elementy:
Identyfikator węzła.
Identyfikator metody foo() na węźle.
Bufor zawierający kopię argumentów a i b
Transakcja jest przesyłana do sterownika jądra bindera.
Sterownik jądra Binder stwierdza, że proces B hostuje węzeł.
Jądro kopiuje całą transakcję do przestrzeni adresowej procesu B.
Jądro znajduje wątek w procesie B, który ma obsłużyć transakcję, i przekazuje mu ją.
Wątek rozpakowuje transakcję, znajduje węzeł i wysyła transakcję do obiektu węzła.
Obiekt węzła pobiera identyfikator funkcji z transakcji, rozpakowuje a i b z bufora transakcji i zapisuje a i b w zmiennych lokalnych.
Obiekt węzła wywołuje funkcję foo(a, b) w kodzie serwera w procesie B.
Wynik wywołania jest zwracany w transakcji odpowiedzi, która jest przekazywana do sterownika jądra, a następnie z powrotem do wywołującego serwera proxy w procesie A.
Serwer proxy zwraca ten wynik do elementu wywołującego w procesie A.
Przypadki użycia Binder
Binder może być używany w różnych scenariuszach, w których musi dochodzić do komunikacji między oprogramowaniem w różnych procesach. Na przykład:
Aplikacja aparatu używa mechanizmu Binder do komunikacji z serwerem aparatu w innym procesie. Serwer aparatu używa następnie mechanizmu Binder do komunikacji z warstwą HAL aparatu w innym procesie.
Aplikacja używa mechanizmu Binder do komunikacji z serwerem systemowym w innym procesie. Serwer systemowy używa mechanizmu Binder do komunikacji z warstwami HAL w innych procesach.
Aplikacja w jednym procesie używa mechanizmu Binder do komunikowania się z inną aplikacją w innym procesie.
Demon systemowy odpowiedzialny za instalowanie, aktualizowanie i usuwanie aplikacji (installd) używa mechanizmu Binder do komunikacji z demonem środowiska wykonawczego Androida („artd”) w celu kompilowania aplikacji.
AIDL i binder
Użyj języka definiowania interfejsu Androida (AIDL), aby zdefiniować interfejsy programowania, które używają mechanizmu Binder do komunikacji międzyprocesowej. Więcej informacji znajdziesz w omówieniu AIDL.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-05 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-08-05 UTC."],[],[],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."]]