Drive for better visionIServiceManagerMarch, 2012                      Himax Media                      Solutions         ...
Class Hierarchy                                                   RefBase         IInterface                              ...
Meta Interface: 描述字串             descriptor: 定義描述字串              "android.os.IServiceManager"                   這個字串會被 B...
Meta Interface: asInterface(sp<IBinder> obj)             功能                   由 Binder 指標找出對應的 Interface             實作...
sp<IServiceManager> defaultServiceManager()             功能                   傳回 Service Manager 物件指標             實作    ...
sp<IBinder> BpServiceManager::addService(name,     sp<IBinder>& service)             功能                   由服務對應的 IBinder...
sp<IBinder> BpServiceManager::checkService(name)              功能                   取得服務對應的 IBinder              實作     ...
sp<IBinder> BpServiceManager::getService(name)             功能                   取得服務對應的 IBinder             實作         ...
部分的 service name             activity                                    iphonesubinfo             meminfo             ...
Vector<String16> BpServiceManager::listServices()             功能                   取得服務名稱的列表             實作            ...
Drive for better vision
Upcoming SlideShare
Loading in …5
×

11 i service_manager

661 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
661
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • 1. 所有 interface 相關的 class ,都由大寫 I 開頭, IInterface 是這些 class 的祖先 2. 繼承 interface 的稱為 meta interface ,是所有 service 的祖先,要創造新的 service 之前,要先創造 meta interface 3. 真正的 service 會提供 Bn 及 Bp 兩種介面,分別繼承 Bn-interface 及 Bp-interface ,兩者都繼承 meta interface
  • 11 i service_manager

    1. 1. Drive for better visionIServiceManagerMarch, 2012 Himax Media Solutions 承景科技股份有限公司
    2. 2. Class Hierarchy RefBase IInterface IBinder BpRefBase meta interface IServiceManager BBinder BpBinder BnInterface BpInterface Bn-interface Bp-interface BnServiceManager BpServiceManagerHimax Media Solutions Proprietary & Confidential 2
    3. 3. Meta Interface: 描述字串  descriptor: 定義描述字串 "android.os.IServiceManager"  這個字串會被 BnServiceManager 、 BpServiceManager 所繼承  String16& getInterfaceDescriptor()  傳回 meta interface 的描述字串 "android.os.IServiceManager" IServiceManager BnInterface BpInterface BnServiceManager BpServiceManagerHimax Media Solutions Proprietary & Confidential 3
    4. 4. Meta Interface: asInterface(sp<IBinder> obj)  功能  由 Binder 指標找出對應的 Interface  實作  因為參數 obj 要求 IBinder ,所以只有兩種可能: BpBinder 或 BnServiceManager  如果傳進來是 BpBinder ,會產生一個新的 BpServiceManager , 並轉換為 IServiceManager  如果傳進來是 BnServiceManager ,就轉換為 IServiceManager 傳 回Himax Media Solutions Proprietary & Confidential 4
    5. 5. sp<IServiceManager> defaultServiceManager()  功能  傳回 Service Manager 物件指標  實作  同時間只能存在一個 ServiceManager 實體 (singleton 模式 )  使用 ProcessState 產生與 handle 0 溝通的 BpBinder  使用 IServiceManager::asInterface(new BpBinder(0)) 由 BpBinder 指標取得對應的介面  產生新的 BpServiceManager 物件並傳回,此物件的 remote() 為 BpBinder 0 /dev/binder BpBinder remote BpServiceManagerHimax Media Solutions Proprietary & Confidential 5
    6. 6. sp<IBinder> BpServiceManager::addService(name, sp<IBinder>& service)  功能  由服務對應的 IBinder 及名稱,新增一個服務  實作  呼叫 BpBinder.transact(...) ,送出  ADD_SERVICE_TRANSACTION  "android.os.IServiceManager"  服務名稱 "phone"  服務 Binder ADD_SERVICE_TRANSACTION "android.os.IServiceManager","phone",service "phone", service BpServiceManager BpBinder remote service manager /dev/binderHimax Media Solutions Proprietary & Confidential 6
    7. 7. sp<IBinder> BpServiceManager::checkService(name)  功能  取得服務對應的 IBinder  實作  呼叫 BpBinder.transact(...) ,送出兩個字串  CHECK_SERVICE_TRANSACTION  "android.os.IServiceManager"  服務名稱 "phone"  BnServiceManager 會回應 sp<IBinder> ,如果服務不存在或忙碌 中,則會指向 NULL sp<IBinder> CHECK_SERVICE_TRANSACTION "android.os.IServiceManager","phone" "phone", service BpServiceManager BpBinder remote service manager /dev/binderHimax Media Solutions Proprietary & Confidential 7
    8. 8. sp<IBinder> BpServiceManager::getService(name)  功能  取得服務對應的 IBinder  實作  呼叫 checkService(name)  因為忙碌時也可能傳回 NULL ,所以要連續檢查 5 次Himax Media Solutions Proprietary & Confidential 8
    9. 9. 部分的 service name  activity  iphonesubinfo  meminfo  sip  gfxinfo  entropy  cpuinfo  telephony.registry  permission  battery  batteryinfo  vibrator  drm.drmManager  mount  simphonebook  samplingprofiler  isms  diskstats  hardware  media.player  package  iphonesubinfoHimax Media Solutions Proprietary & Confidential 9
    10. 10. Vector<String16> BpServiceManager::listServices()  功能  取得服務名稱的列表  實作  呼叫 BpBinder.transact(...) ,送出  LIST_SERVICES_TRANSACTION  "android.os.IServiceManager"  每次會回應一個服務名稱Himax Media Solutions Proprietary & Confidential 10
    11. 11. Drive for better vision

    ×