日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 存储设备管理 -- StorageManager

發布時間:2024/3/12 Android 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 存储设备管理 -- StorageManager 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


上圖關系為:

  • ? ? StorageManager為Client,MountService是Server,通過AIDL進行進程間通信。
  • ? ? MountService是一個Android Service,由systemserver啟動。
  • ? ? Volume Daemon(Vold)是一個Native Service,有Init.c讀取init.rc后啟動。
  • ? ? MountService和Vold之間通過Socket通信。
  • ? ? NativeDaemonConnector幫助MountService取得Vold的socket,建立通信。
  • ? ? Vold通過NetLink讀取Kernel的uevent.
  • ? ? NetLinkManager幫助Vold建立與kernel間的通信

在android中,各種××××Manager為AP提供支持,管理系統的運行。××××Manager充當一個Client,××××ManagerService充當Server為××××Manager提供支持。簡單,經典的C/S架構。這里的各種××××ManagerService 就是指Android Service,都在Java Framework空間,且都在systemserver進程中。Native Service通過socket或者直接JNI,Android Service提供支持。Native Service在Native Framework(C/C++空間)中。以上有所元素全部在android用戶空間中。

對于StorageManager和MountService之間的具體架構,可以查看Android 存儲設備管理 -- IMountService (二)

我們這里主要是講解一下StorageManager的使用。這個可以參考http://developer.android.com/reference/android/os/storage/StorageManager.html

從中可以看出?Opaque Binary Blobs (OBBs)是很重要的一部分。這是Android 2.3添加的新功能,API level至少為9.

另外就是怎么就是獲得StorageManager的實例

import android.os.storage.StorageManager; public class PhoneStatusBarPolicy {private static final String TAG = "PhoneStatusBarPolicy";private StorageManager mStorageManager;public PhoneStatusBarPolicy(Context context) {mContext = context;// storagemStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);mStorageManager.registerListener( new com.android.systemui.usb.StorageNotification(context));

以上代碼摘自:framework/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java

我們看這里注冊了一個StorageEventListener,其實在整個Android里面一共定義了三個,其他兩個分別在:

frameworks/base/packages/SystemUI/src/com/android/systemui/usb/UsbStorageActivity.java

frameworks/base/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java

為什么需要用到getSystemService才能得到StorageManager的實例呢?

這個就需要研究一下frameworks/base/core/java/android/app/ContextImpl.java

/*** Common implementation of Context API, which provides the base* context object for Activity and other application components.*/ class ContextImpl extends Context {private final static String TAG = "ApplicationContext";static {registerService(STORAGE_SERVICE, new ServiceFetcher() {public Object createService(ContextImpl ctx) {try {return new StorageManager(ctx.mMainThread.getHandler().getLooper());} catch (RemoteException rex) {Log.e(TAG, "Failed to create StorageManager", rex);return null; }}});

參考:android usb流程(轉載加整理) ?

總結

以上是生活随笔為你收集整理的Android 存储设备管理 -- StorageManager的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。