实现功能:
记录是谁启动了Activity以及启动Activity的信息。
代码API-28
ActivityStarter.java:
private int startActivityMayWait(IApplicationThread caller, int callingUid,
String callingPackage, Intent intent, String resolvedType,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
IBinder resultTo, String resultWho, int requestCode, int startFlags,
ProfilerInfo profilerInfo, WaitResult outResult,
Configuration globalConfig, SafeActivityOptions options, boolean ignoreTargetSecurity,
int userId, TaskRecord inTask, String reason,
boolean allowPendingRemoteAnimationRegistryLookup) {
.................
mSupervisor.getActivityMetricsLogger().notifyActivityLaunched(res, outRecord[0]);
属性取值
callingPackage-发起者
outRecord[0].info 启动的Activity的信息
注意点:
判断res的取值 0-99为成功启动 其他值则数据不在记录范围
return res;
A应用启动B B返回A后回调监听:
ActiveServices.java
private final boolean scheduleServiceRestartLocked(ServiceRecord r, boolean allowCancel) {
.......................
mAm.mHandler.removeCallbacks(r.restarter);
mAm.mHandler.postAtTime(r.restarter, r.nextRestartTime);
r.nextRestartTime = SystemClock.uptimeMillis() + r.restartDelay;
Slog.w(TAG, "Scheduling restart of crashed service "
+ r.shortName + " in " + r.restartDelay + "ms");
EventLog.writeEvent(EventLogTags.AM_SCHEDULE_SERVICE_RESTART,
r.userId, r.shortName, r.restartDelay);
//添加代码监听
取参:
r.name
r.packageName
r.shortName
return canceled;
}
这两个数据组合起来可以监听应用的 但是Launcher部分的不在这个位置,需要再看看。