WMS中Binder案例
- 1、FWK层中AIDL形式
- 1.1 服务端实现Stub
- 1.2 客户端获取proxy
- 2、紧密相关SurfaceFlinger
android12-release
1、FWK层中AIDL形式
Android 接口定义语言 (AIDL)、Android 应用层 到 HAL 层
AIDL形式是Android中binder机制的具体实现。按照规范aidl/hidl文件自动生成相应代码文件:
客户端获取proxy:asInterface(android.os.IBinder obj)
服务端实现Stub:class Stub extends android.os.Binder
1.1 服务端实现Stub
WindowManagerService
继承IWindowManager.Stub
,SystemServer.java中服务初始化添加到ServiceManager中
frameworks/base/services/java/com/android/server/SystemServer.java
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
frameworks/base/core/java/android/view/IWindowManager.aidl
1.2 客户端获取proxy
- 应用端获取服务
getSystemService(Context.INPUT_SERVICE))
,这里通过中getWindowManagerService()
方法操作IWindowManager.Stub.asInterface(ServiceManager.getService("window"))
- 直接获取
IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE))
frameworks/base/core/java/android/app/SystemServiceRegistry.java
registerService(Context.WINDOW_SERVICE, WindowManager.class,new CachedServiceFetcher<WindowManager>() {@Overridepublic WindowManager createService(ContextImpl ctx) {return new WindowManagerImpl(ctx);}});
frameworks/base/core/java/android/view/WindowManagerGlobal.java
@UnsupportedAppUsage
public static IWindowManager getWindowManagerService() {synchronized (WindowManagerGlobal.class) {if (sWindowManagerService == null) {sWindowManagerService = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));try {if (sWindowManagerService != null) {ValueAnimator.setDurationScale(sWindowManagerService.getCurrentAnimatorScale());sUseBLASTAdapter = sWindowManagerService.useBLAST();}} catch (RemoteException e) {throw e.rethrowFromSystemServer();}}return sWindowManagerService;}
}
2、紧密相关SurfaceFlinger
SurfaceFlinger中Binder案例