安卓源碼閱讀心得總結

前言

閱讀安卓源碼心得總結

【知識點】SystemServer 與 SystemService、SystemServiceManager 的關係

    【SystemServer】:是系統所有服務起航的地方,一般自己添加的服務也需要添加在這裏啓動 
    
    【SystemService】:系統服務一般需要繼承實現的類 
    
    【SystemServiceManager】: 是在 SystemServer 中用來管理系統服務的類,他有一個 SystemService 鏈表
                    保存了系統服務。
                    

【應用舉例】:
     public final class SystemServer
    {
        ...
        ///////////////////////////////////////////////////////////////////////////////
        // 一、創建一個 SystemServiceManager 管理系統服務 
        mSystemServiceManager = new SystemServiceManager(mSystemContext);
        
        ...
        ////////////////////////////////////////////////////////////////////////////////
        // 二、啓動系統服務,並添加到 SystemServiceManager 中的 SystemService 鏈表中進行管理
        mActivityManagerService = mSystemServiceManager.startService(ActivityManagerService.Lifecycle.class).getService();
        mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);
        mSystemServiceManager.startService(BluetoothService.class);
        
        ...
        ////////////////////////////////////////////////////////////////////////////////
        // 三、真正啓動系統服務:調用系統服務覆寫的 onBootPhase 接口
        mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);
        ...
        
    }   

【非常好】xxxInteral 是在 xxxService 中實現的

【知識點】Andoird Context 類提供 app 大部分接口

【知識點】AudioPolicyService 的實現位於其父接口 AudioPolicyInterfaceImp.java 中

【知識點】Bpxx 和 Bnxx 實現位於 Ixx.cpp 中

【知識點】C++ 類實現在同名文件中

【知識點】Context 父類_子類實現爲 ContextImpl

【知識點】onFirstRef() sp 強指針第一次調用,老羅有講

【知識點】sensor 框架中有介紹 c++單實例類實現

【知識點】Server 服務器_ Service 服務

【知識點】xxxManager 是 Binder 客戶端,xxxService 是 Binder 服務端

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章