在Android中運行的應用程序都是通過以下三種方式來層層深入:
1.App->Runtime Service->Lib
2.App->Runtime Service->Native Service->Lib
3.App->Runtime Service->Native Daemon->Lib
App->Runtime Service->Lib方式:
1.application層由Binder IPC調用application framework 層中Runtime Service
2.Runtime Service通過JNI調用Libray層中的Native Service Binding
3.Native Service Binding通過動態加載的方式來調用HAL Library層的東西
4.HAL Library再調用Linux內核層的Kernel Driver。
App->Runtime Service->Native Service->Lib:
此方式一般被Android原生服務所采用。
1.application層由Binder IPC調用application framework 層中Runtime Service
2.Runtime Service通過JNI調用Libray層中的Native Service Binding
3.Native Service Binding通過Binder IPC機制來調用Native Service
4.Native Service通過動態加載的方式來調用HAL Library層的東西
5.HAL Library再調用Linux內核層的Kernel Driver。
于第一種方式相比,只多了一個通過IPC機制調用原生服務并進行動態加載的過程。
App->Runtime Service->Native Daemon->Lib:
此方式一般用于守護進程的連接。
1.application層由Binder IPC調用application framework 層中Runtime Service
2.Runtime Service通過JNI調用Libray層中的Native Service Binding
3.Native Service Binding通過Socket機制調用Native Deamon 進程
4.Native Deamon 進程通過動態加載的方式來調用HAL Library層的東西
5.HAL Library再調用Linux內核層的Kernel Driver。
這種方式比原生服務的調用簡單,它直接通過JNI綁定原生服務,通過sockets調用守護進程進行動態加載。
注釋:內容來自《Android技術內幕》