Binder가 안드로이드에서 사용되는 방법은 2가지

  • IPC
  • RPC

 

Binder를 사용하는 모든 서비스는 안드로이드 부팅시 혹은 클라이언트가 서비스를 요청하기 전에 반드시 Service Manager에 등록해야 한다. 

ServiceManager는 Binder 노드 0을 차지한는 context manager로 동작하며, 이는 Binder 드라이버에 등록된다. 

 

Binder Server 

  • Service Manager에 등록 
  • 통신용 Thread Pool 동작 
  • Binder Client 접속 대기 

 

Binder Client 

  • 서비스를 받는 Binder 서버 번호를 service manager에 물어본다. 
  • 해당 node 번호를 사용하여 서비스를 요청 (Binder 서버 접속)

 

실행 순서 

  1. Binder 드라이버 초기화, init 프로세스에 의해 service manager가 binder에 등록되어 실행됨 
  2. Server 프로세스(Service A)가 ServiceManager를 이용하여 Binder 드라이버에 전달됨  (addService("A"))
  3. A는 등록된 이후에 onTransact()를 이용하여 클라이언트의 요청 처리 준비, 이에 접근하는 application 프로세스가 Service Manager를 이용하여 위에서 등록된 A의 인터페이스 handle을 할당 받는다 (getService("A"))
  4. ServiceManager와 Binder 인터페이스를 이용하여 application이 service A에 접근 가능 → application은 A로 transaction을 이용하여 IPC 및 RPC 호출을 수행 

 

IServiceManager.h : Binder 등록과 서버 Binder로의 접속에 관련된 class 

 

출처 : 안드로이드의 모든 것 분석과 포팅

+ Recent posts