bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

Android中Binder機制的介紹和使用

本篇內容介紹了“Android中Binder機制的介紹和使用”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

松溪ssl適用于網站、小程序/APP、API接口等需要進行數據傳輸應用場景,ssl證書未來市場廣闊!成為成都創新互聯公司的ssl證書銷售渠道,可以享受市場價格4-6折優惠!如果有意向歡迎電話聯系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

binder用于android進程間的通訊。客戶端程序和系統服務,客戶端進程之間,都是通過binder進行進程間通訊的。

1.客戶端程序和系統服務

客戶端和系統服務通訊的入口:cotext.getSystemService(String name)

android.app.ContextImpl:

 
  1.  

    @Override      

  2.  

    public Object getSystemService(String name) {      

  3.  

    return SystemServiceRegistry.getSystemService(this, name);      

  4.  

    }      

android.app.SystemServiceRegistry:

靜態代碼塊注冊系統服務:

 
  1.  

    static {      

  2.  

    registerService(Context.ACCESSIBILITY_SERVICE, AccessibilityManager.class,      

  3.  

    new CachedServiceFetcher<AccessibilityManager>() {      

  4.  

    @Override      

  5.  

    public AccessibilityManager createService(ContextImpl ctx) {      

  6.  

    return AccessibilityManager.getInstance(ctx);      

  7.  

    }});      

  8.  

     

  9.  

    registerService(Context.CAPTIONING_SERVICE, CaptioningManager.class,      

  10.  

    new CachedServiceFetcher<CaptioningManager>() {      

  11.  

    @Override      

  12.  

    public CaptioningManager createService(ContextImpl ctx) {      

  13.  

    return new CaptioningManager(ctx);      

  14.  

    }});      

  15.  

     

  16.  

    registerService(Context.ACCOUNT_SERVICE, AccountManager.class,      

  17.  

    new CachedServiceFetcher<AccountManager>() {      

  18.  

    @Override      

  19.  

    public AccountManager createService(ContextImpl ctx) {      

  20.  

    IBinder b = ServiceManager.getService(Context.ACCOUNT_SERVICE);      

  21.  

    IAccountManager service = IAccountManager.Stub.asInterface(b);      

  22.  

    return new AccountManager(ctx, service);      

  23.  

    }});      

  24.  

    ....      

ServiceManager、ServiceManagerNative:

serviceManager是管理系統服務的一個工具類。

 
  1.  

    sServiceManager = ServiceManagerNative      

  2.  

    .asInterface(Binder.allowBlocking(BinderInternal.getContextObject()));      

getService方法:利用ServiceManagerProxy類通過進程間通訊的方式,獲取其他服務在binder驅動中的binder對象mRemote。

xxx.Stub.asInterface(binder):

利用getService獲取到的binder對象實例化相應服務的Proxy對象,返回給客戶端,供客戶端使用。

返回系統服務:

 
  1.  

    /**      

  2.  

    * Gets a system service from a given context.      

  3.  

    */      

  4.  

    public static Object getSystemService(ContextImpl ctx, String name) {      

  5.  

    ServiceFetcher<?> fetcher = SYSTEM_SERVICE_FETCHERS.get(name);      

  6.  

    return fetcher != null ? fetcher.getService(ctx) : null;      

  7.  

    }      

2.客戶端之間

B應用進程調用A應用進程

B bindservice 向AmS請求啟動B應用的service。啟動service成功后會像AmS返回一個(binder驅動中的mRemote)binder,AmS會以該binder為參數調用ActivityThread類中的ApplicatonThread對象。接著會在ApplicationThread中回調conn接口。最后,B進程可以利用該binder調用A應用提供的功能。

“Android中Binder機制的介紹和使用”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯網站,小編將為大家輸出更多高質量的實用文章!

網站欄目:Android中Binder機制的介紹和使用
地址分享:http://vcdvsql.cn/article10/pdhedo.html

成都網站建設公司_創新互聯,為您提供定制網站App設計定制開發網站制作網站策劃網站營銷

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

外貿網站建設