經常使用命令:service list
但是你有沒有執行過service --h,察看過其他的Option
Usage: service [-h|-?]
service list
service check SERVICE
service call SERVICE CODE [i32 INT | s16 STR] ...
Options:
i32: Write the integer INT into the send parcel.
s16: Write the UTF-16 string STR into the send parcel.
看看他的源碼的具體位置:
android\frameworks\native\cmds\service
結構也非常簡單。首先概略御覽源碼:
本質上是通過Native 層的servicemanager接口實現具體功能。
對於service call這條命令的實現,我從來沒用過,新比較好奇。所以探究了一下源碼的實現:
解析所有傳入的argv,打包數據:
很好,可以通過service call命令來檢驗binder服務是否正確。那麼有個神奇的問題,可以和java端的binder直接通訊嗎?
嘗試一下確認一下:我們以mountservice爲例:
1.service list |grep mount
2.
爲什麼是call 30?
其中含義自行理解。重點關注Parcel這個值,java層binder調用,結果通過Parcel回傳到Native層。言外之意,java層的binder可以和native層的binder直接通訊。
舉例:
service call audio 4 i32 3 i32 15 i32 1 s16 com.skyworthdigital.settings;service call audio 4 i32 3 i32 8 i32 1 s16 com.skyworthdigital.settings;service call audio 4 i32 3 i32 17 i32 1 s16 com.skyworthdigital.settings;