总结: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中的对应实现