Android 存储设备管理 -- IMountService (二)
来源:互联网 发布:淘宝静物摄影布光 编辑:程序博客网 时间:2024/06/05 17:07
这里我们主要是梳理下图中的架构,以IMountService为例。
在StorageManager的构造函数中,用到了IMountService
/** * Constructs a StorageManager object through which an application can * can communicate with the systems mount service. * * @param tgtLooper The {@android.os.Looper} which events will be received on. * * <p>Applications can get instance of this class by calling * {@link android.content.Context#getSystemService(java.lang.String)} with an argument * of {@link android.content.Context#STORAGE_SERVICE}. * * @hide */ public StorageManager(Looper tgtLooper) throws RemoteException { mMountService = IMountService.Stub.asInterface(ServiceManager.getService("mount")); if (mMountService == null) { Log.e(TAG, "Unable to connect to mount service! - is it running yet?"); return; } mTgtLooper = tgtLooper; mBinderListener = new MountServiceBinderListener(); mMountService.registerListener(mBinderListener); }我们看一下IMountService.java中asInterface()的定义
/** * Cast an IBinder object into an IMountService interface, generating a * proxy if needed. */ public static IMountService asInterface(IBinder obj) { if (obj == null) { return null; } IInterface iin = obj.queryLocalInterface(DESCRIPTOR); if (iin != null && iin instanceof IMountService) { return (IMountService) iin; } return new IMountService.Stub.Proxy(obj); }它new了一个Proxy,很明显StorageManager的构造函数中得到的只是一个Proxy,也就是代理。这个可以看一下声明
/** * WARNING! Update IMountService.h and IMountService.cpp if you change this * file. In particular, the ordering of the methods below must match the * _TRANSACTION enum in IMountService.cpp * * @hide - Applications should use android.os.storage.StorageManager to access * storage functions. */public interface IMountService extends IInterface { /** Local-side IPC implementation stub class. */ public static abstract class Stub extends Binder implements IMountService { private static class Proxy implements IMountService { private final IBinder mRemote; Proxy(IBinder remote) { mRemote = remote; } public IBinder asBinder() { return mRemote; } public String getInterfaceDescriptor() { return DESCRIPTOR; } /** * Registers an IMountServiceListener for receiving async * notifications. */ public void registerListener(IMountServiceListener listener) throws RemoteException { Parcel _data = Parcel.obtain(); Parcel _reply = Parcel.obtain(); try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeStrongBinder((listener != null ? listener.asBinder() : null)); mRemote.transact(Stub.TRANSACTION_registerListener, _data, _reply, 0); _reply.readException(); } finally { _reply.recycle(); _data.recycle(); } }
从中可以看出,Proxy包含于Stub中,而Stub包含于IMountService接口类中。
图中的Proxy和Stub都在IMountService.java中实现。
Proxy中有的函数,在Stub中也有对应的函数,这是因为它们都implements IMountService。
我们以registerListener()为例,从上面的代码可以看出其在Proxy中的定义,它调用了mRemote.transact(),其实它是跟Stub的onTransact()相对应,我们看看它的定义
/** Construct the stub at attach it to the interface. */ public Stub() { attachInterface(this, DESCRIPTOR); } public IBinder asBinder() { return this; } @Override public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException { switch (code) { case INTERFACE_TRANSACTION: { reply.writeString(DESCRIPTOR); return true; } case TRANSACTION_registerListener: { data.enforceInterface(DESCRIPTOR); IMountServiceListener listener; listener = IMountServiceListener.Stub.asInterface(data.readStrongBinder()); registerListener(listener); reply.writeNoException(); return true; }可以看到,在onTransact()中,也调到了registerListener(),但是Stub没有实现这个函数,这样就会调用它的实例中的实现。
而这个实例就是MountService。我们看一下MountService的声明
/** * MountService implements back-end services for platform storage * management. * @hide - Applications should use android.os.storage.StorageManager * to access the MountService. */class MountService extends IMountService.Stub implements INativeDaemonConnectorCallbacks, Watchdog.Monitor { private static final boolean LOCAL_LOGD = false; private static final boolean DEBUG_UNMOUNT = true; private static final boolean DEBUG_EVENTS = true; private static final boolean DEBUG_OBB = false;
可以看出,MountService继承自IMountService.Stub,它才是上图中真正的Service。它在SystemServer.java中被调用,并实例化。
而IMountService.Stub就是图中的Stub。它应该会在MountService启动时被实例化。
IMountService.Stub.Proxy是图中的Proxy,它在StorageManager.java中被实例化。
StorageManager就是图中的Client。
- Android 存储设备管理 -- IMountService (二)
- Android 存储设备管理 -- IMountService
- Android 存储设备管理 -- Vold
- Android 存储设备管理 -- MountService
- Android 存储设备管理 -- StorageManager
- Android 存储设备管理 -- 总结
- Android 存储设备管理 -- Vold处理内核消息
- Android StorageManager 存储设备管理
- Android存储设备管理
- Android 存储设备管理框架
- Android 锁屏(设备管理)
- Android 框架层为IMountService 增加新接口(Java层service)
- Android 设备管理
- Android设备管理
- 存储设备管理与分区
- (转载)【Android设备管理】利用D…
- Android 框架层为IMountService 增加新接口
- Linux存储在线管理(一)FC磁盘设备管理
- lsof 常用命令
- 随笔:把1,2,3…n*n 的数字按照顺时针螺旋的形式填入数字矩阵
- IOS之地图和定位应用开发
- DNS详细解释
- sysfs接口函数到建立_DEVICE_ATTR
- Android 存储设备管理 -- IMountService (二)
- 通过设置Ant中java和junit的dir属性来解决ant脚本只能在特定目录下正常运行
- insert语句
- Java 枚举7常见种用法
- myeclipse安装svn插件的多种方式
- mysql数据库读取速度和插入速度的调整记录
- ASP.NET基础控件
- 第一个hibernate工程
- oracle dblink详解