framework学习笔记

framework学习笔记10. 应用查找AMS

2020-12-16  本文已影响0人  加个标志位

一. 笔记5 ~ 笔记9内容:

  1. 虚拟地址与物理地址;
  2. IPC通信方式:管道,套接字,内存共享,信号,binder驱动;
  3. binder驱动:binder_open(), binder_mmap(), binder_ioctl;
  4. 通信过程:
    服务进程启动后进入等待;
    客户端发起调用;
    服务进程被唤醒;
    客户端进入等待;
    服务进程响应调用并执行;
    服务处理返回;
    客户端被唤醒;

二. 应用向AMS发起请求过程分析:
Instrumentation类中execStartActivity()方法:

public ActivityResult execStartActivity(
            Context who, IBinder contextThread, IBinder token, Activity target,
            Intent intent, int requestCode, Bundle options) {
        IApplicationThread whoThread = (IApplicationThread) contextThread;
        if (mActivityMonitors != null) {
           // ...
        }
        try {
            intent.migrateExtraStreamToClipData();
            intent.prepareToLeaveProcess();
            int result = ActivityManagerNative.getDefault()
                .startActivity(whoThread, who.getBasePackageName(), intent,
                        intent.resolveTypeIfNeeded(who.getContentResolver()),
                        token, target != null ? target.mEmbeddedID : null,
                        requestCode, 0, null, options);
            checkStartActivityResult(result, intent);
        } catch (RemoteException e) {
        }
        return null;
    }

2.1 ActivityManagerNative.getDefault():向ServiceManager进程查询返回 AMS的Binder对象的handle值,最终返回的是BpBinder(handle);


查找AMS.png
上一篇下一篇

猜你喜欢

热点阅读