android 进程间通信---Service Manager(2)
2015-09-20 09:47
525 查看
关于servicemanager的设计:
IBuildService.java
关键是这个class,stub继承自binder,而且实现了IbuildService的接口。
在看service
所以,service是实现了Stub的内容,进而可以实现这个方法。
而service的onbind就是返回这个stub
通过bindservice,会把这个Ibinder对象返回给client端。
/* * This file is auto-generated. DO NOT MODIFY. * Original file: D:\\AndroidDev\\github\\Example\\Examples\\ImageSearch\\src\\com\\htc\\globalsearch\\imagesearch\\service\\aidl\\IBuildService.aidl */ package com.htc.globalsearch.imagesearch.service.aidl; public interface IBuildService extends android.os.IInterface { /** Local-side IPC implementation stub class. */ public static abstract class Stub extends android.os.Binder implements com.htc.globalsearch.imagesearch.service.aidl.IBuildService { private static final java.lang.String DESCRIPTOR = "com.htc.globalsearch.imagesearch.service.aidl.IBuildService"; /** Construct the stub at attach it to the interface. */ public Stub() { this.attachInterface(this, DESCRIPTOR); } /** * Cast an IBinder object into an com.htc.globalsearch.imagesearch.service.aidl.IBuildService interface, * generating a proxy if needed. */ public static com.htc.globalsearch.imagesearch.service.aidl.IBuildService asInterface(android.os.IBinder obj) { if ((obj==null)) { return null; } android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR); if (((iin!=null)&&(iin instanceof com.htc.globalsearch.imagesearch.service.aidl.IBuildService))) { return ((com.htc.globalsearch.imagesearch.service.aidl.IBuildService)iin); } return new com.htc.globalsearch.imagesearch.service.aidl.IBuildService.Stub.Proxy(obj); } @Override public android.os.IBinder asBinder() { return this; } @Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException { switch (code) { case INTERFACE_TRANSACTION: { reply.writeString(DESCRIPTOR); return true; } case TRANSACTION_getServiceStatus: { data.enforceInterface(DESCRIPTOR); int _result = this.getServiceStatus(); reply.writeNoException(); reply.writeInt(_result); return true; } case TRANSACTION_findPerson: { data.enforceInterface(DESCRIPTOR); java.lang.String _arg0; _arg0 = data.readString(); int _arg1; _arg1 = data.readInt(); int _result = this.findPerson(_arg0, _arg1); reply.writeNoException(); reply.writeInt(_result); return true; } case TRANSACTION_registerCallback: { data.enforceInterface(DESCRIPTOR); com.htc.globalsearch.imagesearch.service.aidl.ICallBack _arg0; _arg0 = com.htc.globalsearch.imagesearch.service.aidl.ICallBack.Stub.asInterface(data.readStrongBinder()); this.registerCallback(_arg0); reply.writeNoException(); return true; } case TRANSACTION_unregisterCallback: { data.enforceInterface(DESCRIPTOR); com.htc.globalsearch.imagesearch.service.aidl.ICallBack _arg0; _arg0 = com.htc.globalsearch.imagesearch.service.aidl.ICallBack.Stub.asInterface(data.readStrongBinder()); this.unregisterCallback(_arg0); reply.writeNoException(); return true; } } return super.onTransact(code, data, reply, flags); } private static class Proxy implements com.htc.globalsearch.imagesearch.service.aidl.IBuildService { private android.os.IBinder mRemote; Proxy(android.os.IBinder remote) { mRemote = remote; } @Override public android.os.IBinder asBinder() { return mRemote; } public java.lang.String getInterfaceDescriptor() { return DESCRIPTOR; } @Override public int getServiceStatus() throws android.os.RemoteException { android.os.Parcel _data = android.os.Parcel.obtain(); android.os.Parcel _reply = android.os.Parcel.obtain(); int _result; try { _data.writeInterfaceToken(DESCRIPTOR); mRemote.transact(Stub.TRANSACTION_getServiceStatus, _data, _reply, 0); _reply.readException(); _result = _reply.readInt(); } finally { _reply.recycle(); _data.recycle(); } return _result; } @Override public int findPerson(java.lang.String path, int filter) throws android.os.RemoteException { android.os.Parcel _data = android.os.Parcel.obtain(); android.os.Parcel _reply = android.os.Parcel.obtain(); int _result; try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeString(path); _data.writeInt(filter); mRemote.transact(Stub.TRANSACTION_findPerson, _data, _reply, 0); _reply.readException(); _result = _reply.readInt(); } finally { _reply.recycle(); _data.recycle(); } return _result; } @Override public void registerCallback(com.htc.globalsearch.imagesearch.service.aidl.ICallBack cb) throws android.os.RemoteException { android.os.Parcel _data = android.os.Parcel.obtain(); android.os.Parcel _reply = android.os.Parcel.obtain(); try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeStrongBinder((((cb!=null))?(cb.asBinder()):(null))); mRemote.transact(Stub.TRANSACTION_registerCallback, _data, _reply, 0); _reply.readException(); } finally { _reply.recycle(); _data.recycle(); } } @Override public void unregisterCallback(com.htc.globalsearch.imagesearch.service.aidl.ICallBack cb) throws android.os.RemoteException { android.os.Parcel _data = android.os.Parcel.obtain(); android.os.Parcel _reply = android.os.Parcel.obtain(); try { _data.writeInterfaceToken(DESCRIPTOR); _data.writeStrongBinder((((cb!=null))?(cb.asBinder()):(null))); mRemote.transact(Stub.TRANSACTION_unregisterCallback, _data, _reply, 0); _reply.readException(); } finally { _reply.recycle(); _data.recycle(); } } } static final int TRANSACTION_getServiceStatus = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0); static final int TRANSACTION_findPerson = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1); static final int TRANSACTION_registerCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2); static final int TRANSACTION_unregisterCallback = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3); } public int getServiceStatus() throws android.os.RemoteException; public int findPerson(java.lang.String path, int filter) throws android.os.RemoteException; public void registerCallback(com.htc.globalsearch.imagesearch.service.aidl.ICallBack cb) throws android.os.RemoteException; public void unregisterCallback(com.htc.globalsearch.imagesearch.service.aidl.ICallBack cb) throws android.os.RemoteException; }
IBuildService.java
public static abstract class Stub extends android.os.Binder implements com.htc.globalsearch.imagesearch.service.aidl.IBuildService
关键是这个class,stub继承自binder,而且实现了IbuildService的接口。
在看service
private class ImageSearchBuildServiceImpl extends IBuildService.Stub{
所以,service是实现了Stub的内容,进而可以实现这个方法。
而service的onbind就是返回这个stub
@Override public IBinder onBind(Intent intent) { mCurrentCookie = intent.getLongExtra("cookie",-1); Log.i(TAG, "[onBind] mCurrentCookie:"+mCurrentCookie); iServiceImpl = new ImageSearchBuildServiceImpl(mImageSearchOperator); return iServiceImpl; }
通过bindservice,会把这个Ibinder对象返回给client端。
相关文章推荐
- android多媒体——6步学会MediaRecorder录音
- Android 之AsyncTask 学习
- android多媒体——4步学会SoundPool
- Android的消息处理机制——Looper,Handler,Message
- Android Studio-emulator: ERROR: Unable to load VM from snapshot.
- Android事件分发完全解析(下)
- 获得android keystore的SHA1值
- Android事件分发完全解析(上)
- Android 简单的智能机器人聊天软件
- Android ListView的中的数据更新时遇到的一些问题的总结
- Android自定义View之图形图像(模仿360的刷新球自定义一个SeekBar)
- Android 组件和进程的一些关系
- Android自定义控件
- 贝塞尔曲线练习之弹性的圆
- Android Context MODE的四种模式解析(转)
- android多点触控统一的原理(使用 event.getAction()&MotionEvent.ACTION_MASK的原因)
- Android笔记(三十四) Android中线程之间的通信(六)Handle中的post()方法详解
- [置顶] Android Studio中实战Jni开发
- android关于用.xml布局文件中对View添加OnClick事件无法响应的事情
- Android--Animotion动画详解-逐帧动画,补间动画,属性动画。