您的位置:首页 > 其它

IActivityManager ActivityManagerNative ActivityManagerService之间如何进行工作

2016-12-21 15:59 543 查看
总结: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中的对应实现
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ActivityMa
相关文章推荐