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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 模拟登陆广西科技大学正方教务系统
- 下一篇: pytorch MSELoss参数详解