[英]Involvement of binder driver in Intents (a form of IPC)
我打算對android應用程序進行開箱即用的分析。 也就是說,我將在Android QEMU模擬器中運行該應用程序,並執行虛擬機自檢(VMI)來監視該應用程序的行為。 為此,我已經對QEMU仿真器進行了檢測,以監視該應用程序的Linux系統調用和Binder IPC。
但是,我不確定在監視底層操作時是否能夠監視使用意圖進行的進程間通信。 意圖是否與綁定程序驅動程序對話或意圖是否在Java API級別上運行。
幾乎所有內容都使用活頁夾驅動程序。 startActivity
最終將我們引向了這里:
public ActivityResult execStartActivity(
Context who, IBinder contextThread, IBinder token, Activity target,
Intent intent, int requestCode) {
IApplicationThread whoThread = (IApplicationThread) contextThread;
if (mActivityMonitors != null) {
synchronized (mSync) {
final int N = mActivityMonitors.size();
for (int i=0; i<N; i++) {
final ActivityMonitor am = mActivityMonitors.get(i);
if (am.match(who, null, intent)) {
am.mHits++;
if (am.isBlocking()) {
return requestCode >= 0 ? am.getResult() : null;
}
break;
}
}
}
}
try {
int result = ActivityManagerNative.getDefault()
.startActivity(whoThread, intent,
intent.resolveTypeIfNeeded(who.getContentResolver()),
null, 0, token, target != null ? target.mEmbeddedID : null,
requestCode, false, false);
checkStartActivityResult(result, intent);
} catch (RemoteException e) {
}
return null;
}
如您所見,Java層將兩個綁定程序參數傳遞給實際開始活動的本機代碼。 本機代碼將使用這些參數使用綁定程序驅動程序進行IPC。
是的,Intent必須經過綁定程序,例如,startActivity,startService,sendBroadcast。
例如, https: //android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/ContextImpl.java中的sendBroadcast,它調用broadcastIntent()
@Override
public void sendBroadcast(Intent intent) {
warnIfCallingFromSystemProcess();
String resolvedType = intent.resolveTypeIfNeeded(getContentResolver());
try {
intent.prepareToLeaveProcess(this);
ActivityManager.getService().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, null,
Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false, false,
getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
在ActivityManagerNative.Java的broadcastIntent()中,它調用mRemote.transact()來打擾活頁夾。
public int broadcastIntent(IApplicationThread caller,
Intent intent, String resolvedType, IIntentReceiver resultTo,
int resultCode, String resultData, Bundle map,
String requiredPermission, boolean serialized,
boolean sticky, int userId) throws RemoteException
{
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeStrongBinder(caller != null ? caller.asBinder() : null);
intent.writeToParcel(data, 0);
data.writeString(resolvedType);
data.writeStrongBinder(resultTo != null ? resultTo.asBinder() : null);
data.writeInt(resultCode);
data.writeString(resultData);
data.writeBundle(map);
data.writeString(requiredPermission);
data.writeInt(serialized ? 1 : 0);
data.writeInt(sticky ? 1 : 0);
data.writeInt(userId);
mRemote.transact(BROADCAST_INTENT_TRANSACTION, data, reply, 0);
reply.readException();
int res = reply.readInt();
reply.recycle();
data.recycle();
return res;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.