IActivityManager ActivityManagerNative ActivityManagerService之间如何进行工作

本文解析了IActivityManager接口的调用流程,从app侧的proxy到ActivityManagerProxy,再到ActivityManagerService的具体实现,详细介绍了startActivityFromRecents等函数的内部处理过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

总结:IActivityManager调用函数最终会调用ActivityManagerService中的对应实现

IActivityManager 定义的接口。 app侧的proxy <—->ActivityManagerProxy
比如IActivityManager定义接口startActivityFromRecents

class ActivityManagerProxy implements IActivityManager
{
    public ActivityManagerProxy(IBinder remote)
    {
        mRemote = remote;
    }
    public IBinder asBinder()
    {
        return mRemote;
    }
mRemote.transact(START_ACTIVITY_FROM_RECENTS_TRANSACTION, data, reply, 0);

ActivityManagerNative的声明

public abstract class ActivityManagerNative extends Binder implements IActivityManager

onTransact中的处理

    case START_ACTIVITY_FROM_RECENTS_TRANSACTION:
        {
            data.enforceInterface(IActivityManager.descriptor);
            final int taskId = data.readInt();
            final Bundle options =
                    data.readInt() == 0 ? null : Bundle.CREATOR.createFromParcel(data);
            final int result = startActivityFromRecents(taskId, options);
            reply.writeNoException();
            reply.writeInt(result);
            return true;
        }

ActivityManagerService的声明

ActivityManagerService extends ActivityManagerNative 

真正的实现代码

    @Override
    public final int startActivityFromRecents(int taskId, Bundle bOptions) {
        if (checkCallingPermission(START_TASKS_FROM_RECENTS) != PackageManager.PERMISSION_GRANTED) {
            String msg = "Permission Denial: startActivityFromRecents called without " +
                    START_TASKS_FROM_RECENTS;
            Slog.w(TAG, msg);
            throw new SecurityException(msg);
        }
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (this) {
                return mStackSupervisor.startActivityFromRecentsInner(taskId, bOptions);
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

因此通过IActivityManager调用函数最终会调用ActivityManagerService中的对应实现

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值