增加启动进程失败打点

Signed-off-by: zhangyuhang72 <zhangyuhang72@huawei.com>
Change-Id: I7863853c1d049c3bf94e59ce52f5fc6cc155f90b
This commit is contained in:
zhangyuhang72 2024-08-31 11:01:26 +08:00
parent 48fb5ba265
commit 7f48ffe37b
13 changed files with 504 additions and 18 deletions

View File

@ -312,6 +312,21 @@ PROCESS_EXIT:
PROCESS_NAME: {type: STRING, desc: process name}
EXTENSION_TYPE: {type: INT32, desc: process exit extension type}
PROCESS_START_FAILED:
__BASE: {type: FAULT, level: CRITICAL, tag: app, desc: process start failed, preserve: true}
STARTUP_TIME: {type: INT64, desc: process start failed time}
STARTUP_ABILITY_TYPE: {type: INT32, desc: process start ability type}
STARTUP_EXTENSION_TYPE: {type: INT32, desc: process start extension type}
CALLER_BUNDLE_NAME: {type: STRING, desc: caller bundle name}
CALLER_UID: {type: INT32, desc: caller uid}
CALLER_PROCESS_NAME: {type: STRING, desc: caller process name}
CALLER_PROCESS_ID: {type: INT32, desc: caller processId}
BUNDLE_NAME: {type: STRING, desc: bundle name}
PROCESS_NAME: {type: STRING, desc: process name}
PROCESS_TYPE: {type: INT32, desc: process type}
REASON: {type: INT32, desc: failed reason}
SUB_REASON: {type: INT32, desc: failed sub reason}
DRAWN_COMPLETED:
__BASE: {type: BEHAVIOR, level: MINOR, tag: app, desc: drawn completed event reporting}
APP_UID: {type: INT32, desc: app uid}

View File

@ -85,6 +85,7 @@ enum class ProcessType {
EXTENSION,
RENDER,
GPU,
CHILD,
};
enum class AppStartType {

View File

@ -18,10 +18,19 @@
#include "ability_info.h"
#include "app_running_record.h"
#include "child_process_record.h"
#include "event_report.h"
namespace OHOS {
namespace AppExecFwk {
enum class ProcessStartFailedReason {
UNKNOWN = 0,
APPSPAWN_FAILED = 1,
CREATE_START_MSG_FAILED = 2,
GET_SPAWN_CLIENT_FAILED = 3,
GENERATE_RENDER_UID_FAILED = 4,
CHECK_CHILD_FDS_FAILED = 5,
};
class AppMgrEventUtil {
public:
@ -31,6 +40,15 @@ public:
static bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &callerAppRecord,
const std::shared_ptr<AppRunningRecord> &appRecord, AAFwk::EventInfo &eventInfo);
static bool SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> callerAppRecord,
std::shared_ptr<AppRunningRecord> appRecord, AAFwk::EventInfo &eventInfo);
static bool SendChildProcessStartFailedEvent(std::shared_ptr<ChildProcessRecord> childRecord,
ProcessStartFailedReason reason, int32_t subReason);
static bool SendRenderProcessStartFailedEvent(std::shared_ptr<RenderRecord> renderRecord,
ProcessStartFailedReason reason, int32_t subReason);
static void SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid, int64_t restartTime);
@ -39,6 +57,9 @@ private:
static void UpdateStartupType(const std::shared_ptr<AbilityInfo> &abilityInfo, int32_t &abilityType,
int32_t &extensionType);
static void UpdateCallerInfo(AAFwk::EventInfo &eventInfo, std::shared_ptr<AppRunningRecord> callerAppRecord,
std::shared_ptr<AppRunningRecord> appRecord);
};
}
}

View File

@ -34,6 +34,7 @@
#include "app_foreground_state_observer_interface.h"
#include "app_malloc_info.h"
#include "app_mgr_constants.h"
#include "app_mgr_event.h"
#include "app_preloader.h"
#include "app_record_id.h"
#include "app_running_manager.h"
@ -1291,6 +1292,9 @@ private:
int StartRenderProcessImpl(const std::shared_ptr<RenderRecord> &renderRecord,
const std::shared_ptr<AppRunningRecord> appRecord, pid_t &renderPid, bool isGPU = false);
void SetRenderStartMsg(AppSpawnStartMsg &startMsg, std::shared_ptr<RenderRecord> renderRecord,
const int32_t renderUid, const bool isGPU);
void OnRenderRemoteDied(const wptr<IRemoteObject> &remote);
void AddWatchParameter();
@ -1349,6 +1353,9 @@ private:
bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &appRecord);
bool SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> appRecord, ProcessStartFailedReason reason,
int32_t subReason);
void SendAppStartupTypeEvent(const std::shared_ptr<AppRunningRecord> &appRecord,
const std::shared_ptr<AbilityInfo> &abilityInfo, const AppStartType startType);

View File

@ -21,6 +21,7 @@
#include <sys/types.h>
#include "app_death_recipient.h"
#include "app_mgr_constants.h"
#include "child_scheduler_interface.h"
#include "child_process_info.h"
#include "child_process_request.h"
@ -63,6 +64,7 @@ public:
void ClearMainProcessCallback();
void SetEntryParams(const std::string &entryParams);
std::string GetEntryParams() const;
ProcessType GetProcessType() const;
private:
void MakeProcessName(const std::shared_ptr<AppRunningRecord> hostRecord);
@ -80,6 +82,7 @@ private:
sptr<IRemoteObject> mainProcessCb_ = nullptr;
bool isStartWithDebug_;
std::string entryParams_;
ProcessType processType_ = ProcessType::CHILD;
};
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -127,6 +127,132 @@ bool AppMgrEventUtil::SendProcessStartEvent(const std::shared_ptr<AppRunningReco
return true;
}
bool AppMgrEventUtil::SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> callerAppRecord,
std::shared_ptr<AppRunningRecord> appRecord, AAFwk::EventInfo &eventInfo)
{
if (!appRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord is null");
return false;
}
time_t currentTime = time(nullptr);
if (currentTime <= 0) {
TAG_LOGE(AAFwkTag::APPMGR, "currentTime <= 0");
return false;
}
eventInfo.time = currentTime;
eventInfo.callerUid = appRecord->GetCallerUid() == -1 ? IPCSkeleton::GetCallingUid() : appRecord->GetCallerUid();
if (!appRecord->GetAbilities().empty()) {
auto abilityRecord = appRecord->GetAbilities().begin()->second;
if (!abilityRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "abilityRecord null");
return false;
}
auto abilityinfo = abilityRecord->GetAbilityInfo();
UpdateStartupType(abilityinfo, eventInfo.abilityType, eventInfo.extensionType);
} else {
TAG_LOGI(AAFwkTag::APPMGR, "Abilities nullptr!");
}
UpdateCallerInfo(eventInfo, callerAppRecord, appRecord);
if (!appRecord->GetBundleName().empty()) {
eventInfo.bundleName = appRecord->GetBundleName();
}
eventInfo.processName = appRecord->GetProcessName();
eventInfo.processType = static_cast<int32_t>(appRecord->GetProcessType());
if (!appRecord->GetPriorityObject()) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord's priorityObject is null");
} else {
eventInfo.pid = appRecord->GetPriorityObject()->GetPid();
}
AAFwk::EventReport::SendProcessStartFailedEvent(AAFwk::EventName::PROCESS_START_FAILED, eventInfo);
return true;
}
void AppMgrEventUtil::UpdateCallerInfo(AAFwk::EventInfo &eventInfo, std::shared_ptr<AppRunningRecord> callerAppRecord,
std::shared_ptr<AppRunningRecord> appRecord)
{
if (!callerAppRecord) {
Security::AccessToken::NativeTokenInfo nativeTokenInfo = {};
auto token = appRecord->GetCallerTokenId() == -1 ?
static_cast<int32_t>(IPCSkeleton::GetCallingTokenID()) : appRecord->GetCallerTokenId();
Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(token, nativeTokenInfo);
eventInfo.callerBundleName = "";
eventInfo.callerProcessName = nativeTokenInfo.processName;
eventInfo.callerPid = IPCSkeleton::GetCallingPid();
} else {
if (callerAppRecord->GetBundleName().empty()) {
eventInfo.callerBundleName = callerAppRecord->GetName();
} else {
eventInfo.callerBundleName = callerAppRecord->GetBundleName();
}
eventInfo.callerProcessName = callerAppRecord->GetProcessName();
eventInfo.callerPid = GetCallerPid(callerAppRecord);
}
}
bool AppMgrEventUtil::SendChildProcessStartFailedEvent(std::shared_ptr<ChildProcessRecord> childRecord,
ProcessStartFailedReason reason, int32_t subReason)
{
if (!childRecord) {
TAG_LOGW(AAFwkTag::APPMGR, "appRecord is null");
return false;
}
auto hostRecord = childRecord->GetHostRecord();
if (!hostRecord) {
TAG_LOGW(AAFwkTag::APPMGR, "hostRecord is null");
return false;
}
AAFwk::EventInfo eventInfo;
time_t currentTime = time(nullptr);
if (currentTime <= 0) {
TAG_LOGE(AAFwkTag::APPMGR, "currentTime <= 0");
return false;
}
eventInfo.time = currentTime;
eventInfo.callerUid = hostRecord->GetUid();
eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPriorityObject()->GetPid() : -1;
eventInfo.callerBundleName = hostRecord->GetBundleName();
eventInfo.callerProcessName = hostRecord->GetProcessName();
eventInfo.bundleName = hostRecord->GetBundleName();
eventInfo.processName = childRecord->GetProcessName();
eventInfo.processType = static_cast<int32_t>(childRecord->GetProcessType());
eventInfo.reason = static_cast<int32_t>(reason);
eventInfo.subReason = subReason;
AAFwk::EventReport::SendProcessStartFailedEvent(AAFwk::EventName::PROCESS_START_FAILED, eventInfo);
return true;
}
bool AppMgrEventUtil::SendRenderProcessStartFailedEvent(std::shared_ptr<RenderRecord> renderRecord,
ProcessStartFailedReason reason, int32_t subReason)
{
if (!renderRecord) {
TAG_LOGW(AAFwkTag::APPMGR, "appRecord is null");
return false;
}
auto hostRecord = renderRecord->GetHostRecord();
if (!hostRecord) {
TAG_LOGW(AAFwkTag::APPMGR, "hostRecord is null");
return false;
}
AAFwk::EventInfo eventInfo;
time_t currentTime = time(nullptr);
if (currentTime <= 0) {
TAG_LOGE(AAFwkTag::APPMGR, "currentTime <= 0");
return false;
}
eventInfo.time = currentTime;
eventInfo.callerUid = hostRecord->GetUid();
eventInfo.callerPid = hostRecord->GetPriorityObject() != nullptr ? hostRecord->GetPriorityObject()->GetPid() : -1;
eventInfo.callerBundleName = hostRecord->GetBundleName();
eventInfo.callerProcessName = hostRecord->GetProcessName();
eventInfo.bundleName = hostRecord->GetBundleName();
eventInfo.processName = renderRecord->GetProcessName();
eventInfo.processType = static_cast<int32_t>(renderRecord->GetProcessType());
eventInfo.reason = static_cast<int32_t>(reason);
eventInfo.subReason = subReason;
AAFwk::EventReport::SendProcessStartFailedEvent(AAFwk::EventName::PROCESS_START_FAILED, eventInfo);
return true;
}
void AppMgrEventUtil::SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid, int64_t restartTime)
{
// eventInfo come from SendProcessStartEvent

View File

@ -238,6 +238,7 @@ constexpr int32_t NETSYS_SOCKET_GROUPID = 1097;
constexpr int32_t DEFAULT_INVAL_VALUE = -1;
constexpr int32_t NO_ABILITY_RECORD_ID = -1;
constexpr int32_t EXIT_REASON_UNKNOWN = 0;
constexpr int32_t PROCESS_START_FAILED_SUB_REASON_UNKNOWN = 0;
constexpr int32_t MAX_SPECIFIED_PROCESS_NAME_LENGTH = 255;
constexpr int32_t LEAK_WAIT = 900000;
@ -2943,10 +2944,14 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
TAG_LOGE(AAFwkTag::APPMGR, "appRecord is null");
return;
}
bool isCJApp = IsCjApplication(bundleInfo);
if (!remoteClientManager_ || !remoteClientManager_->GetSpawnClient()) {
TAG_LOGE(AAFwkTag::APPMGR, "appSpawnClient is null");
appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId());
if (!isCJApp) {
SendProcessStartFailedEvent(appRecord, ProcessStartFailedReason::GET_SPAWN_CLIENT_FAILED,
PROCESS_START_FAILED_SUB_REASON_UNKNOWN);
}
return;
}
@ -2954,14 +2959,17 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
auto appInfo = appRecord->GetApplicationInfo();
auto bundleType = appInfo ? appInfo->bundleType : BundleType::APP;
startMsg.maxChildProcess = maxChildProcess;
if (CreateStartMsg(processName, startFlags, uid, bundleInfo, bundleIndex, bundleType, startMsg, want, moduleName,
abilityName, strictMode) != ERR_OK) {
auto ret = CreateStartMsg(processName, startFlags, uid, bundleInfo, bundleIndex, bundleType, startMsg, want,
moduleName, abilityName, strictMode);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "CreateStartMsg failed.");
appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId());
if (!isCJApp) {
SendProcessStartFailedEvent(appRecord, ProcessStartFailedReason::CREATE_START_MSG_FAILED, ret);
}
return;
};
bool isCJApp = IsCjApplication(bundleInfo);
SetProcessJITState(appRecord);
PerfProfile::GetInstance().SetAppForkStartTime(GetTickCount());
pid_t pid = 0;
@ -2981,6 +2989,10 @@ void AppMgrServiceInner::StartProcess(const std::string &appName, const std::str
if (FAILED(errCode)) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to spawn new app process, errCode %{public}08x", errCode);
appRunningManager_->RemoveAppRunningRecordById(appRecord->GetRecordId());
if (!isCJApp) {
SendProcessStartFailedEvent(appRecord, ProcessStartFailedReason::APPSPAWN_FAILED,
static_cast<int32_t>(errCode));
}
return;
}
@ -3135,6 +3147,24 @@ void AppMgrServiceInner::SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, in
}
}
bool AppMgrServiceInner::SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> appRecord,
ProcessStartFailedReason reason, int32_t subReason)
{
if (!appRecord) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord is nullptr");
return false;
}
TAG_LOGD(AAFwkTag::APPMGR, "processName:%{public}s, reason:%{public}d, subReason:%{public}d",
appRecord->GetProcessName().c_str(), reason, subReason);
AAFwk::EventInfo eventInfo;
eventInfo.reason = static_cast<int32_t>(reason);
eventInfo.subReason = subReason;
auto callerPid = appRecord->GetCallerPid() == -1 ? IPCSkeleton::GetCallingPid() : appRecord->GetCallerPid();
auto callerAppRecord = GetAppRunningRecordByPid(callerPid);
AppMgrEventUtil::SendProcessStartFailedEvent(callerAppRecord, appRecord, eventInfo);
return true;
}
void AppMgrServiceInner::SendAppStartupTypeEvent(const std::shared_ptr<AppRunningRecord> &appRecord,
const std::shared_ptr<AbilityInfo> &abilityInfo, const AppStartType startType)
{
@ -4763,33 +4793,27 @@ int AppMgrServiceInner::StartRenderProcessImpl(const std::shared_ptr<RenderRecor
auto nwebSpawnClient = remoteClientManager_->GetNWebSpawnClient();
if (!nwebSpawnClient) {
TAG_LOGE(AAFwkTag::APPMGR, "nwebSpawnClient is null");
AppMgrEventUtil::SendRenderProcessStartFailedEvent(renderRecord,
ProcessStartFailedReason::GET_SPAWN_CLIENT_FAILED, ERR_INVALID_VALUE);
return ERR_INVALID_VALUE;
}
int32_t renderUid = Constants::INVALID_UID;
if (!GenerateRenderUid(renderUid)) {
TAG_LOGE(AAFwkTag::APPMGR, "Generate renderUid failed");
AppMgrEventUtil::SendRenderProcessStartFailedEvent(renderRecord,
ProcessStartFailedReason::GENERATE_RENDER_UID_FAILED, ERR_INVALID_OPERATION);
return ERR_INVALID_OPERATION;
}
AppSpawnStartMsg startMsg = appRecord->GetStartMsg();
startMsg.renderParam = renderRecord->GetRenderParam();
startMsg.uid = renderUid;
startMsg.gid = renderUid;
if (isGPU) {
startMsg.procName += GPU_PROCESS_NAME;
startMsg.processType = GPU_PROCESS_TYPE;
} else {
startMsg.procName += RENDER_PROCESS_NAME;
startMsg.processType = RENDER_PROCESS_TYPE;
}
startMsg.code = 0; // 0: DEFAULT
SetRenderStartMsg(startMsg, renderRecord, renderUid, isGPU);
pid_t pid = 0;
ErrCode errCode = nwebSpawnClient->StartProcess(startMsg, pid);
if (FAILED(errCode)) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to spawn new render process, errCode %{public}08x", errCode);
std::lock_guard<ffrt::mutex> lock(renderUidSetLock_);
renderUidSet_.erase(renderUid);
AppMgrEventUtil::SendRenderProcessStartFailedEvent(renderRecord,
ProcessStartFailedReason::APPSPAWN_FAILED, static_cast<int32_t>(errCode));
return ERR_INVALID_VALUE;
}
renderPid = pid;
@ -4807,6 +4831,22 @@ int AppMgrServiceInner::StartRenderProcessImpl(const std::shared_ptr<RenderRecor
return 0;
}
void AppMgrServiceInner::SetRenderStartMsg(AppSpawnStartMsg &startMsg, std::shared_ptr<RenderRecord> renderRecord,
const int32_t renderUid, const bool isGPU)
{
startMsg.renderParam = renderRecord->GetRenderParam();
startMsg.uid = renderUid;
startMsg.gid = renderUid;
if (isGPU) {
startMsg.procName += GPU_PROCESS_NAME;
startMsg.processType = GPU_PROCESS_TYPE;
} else {
startMsg.procName += RENDER_PROCESS_NAME;
startMsg.processType = RENDER_PROCESS_TYPE;
}
startMsg.code = 0; // 0: DEFAULT
}
int AppMgrServiceInner::GetRenderProcessTerminationStatus(pid_t renderPid, int &status)
{
auto callingPid = IPCSkeleton::GetCallingPid();
@ -6317,9 +6357,13 @@ int32_t AppMgrServiceInner::StartChildProcessImpl(const std::shared_ptr<ChildPro
auto spawnClient = remoteClientManager_->GetSpawnClient();
if (!spawnClient) {
TAG_LOGE(AAFwkTag::APPMGR, "spawnClient is null");
AppMgrEventUtil::SendChildProcessStartFailedEvent(childProcessRecord,
ProcessStartFailedReason::GET_SPAWN_CLIENT_FAILED, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT);
return ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT;
}
if (!args.CheckFdsSize() || !args.CheckFdsKeyLength()) {
AppMgrEventUtil::SendChildProcessStartFailedEvent(childProcessRecord,
ProcessStartFailedReason::CHECK_CHILD_FDS_FAILED, ERR_INVALID_VALUE);
return ERR_INVALID_VALUE;
}
@ -6333,6 +6377,8 @@ int32_t AppMgrServiceInner::StartChildProcessImpl(const std::shared_ptr<ChildPro
ErrCode errCode = spawnClient->StartProcess(startMsg, pid);
if (FAILED(errCode)) {
TAG_LOGE(AAFwkTag::APPMGR, "failed to spawn new child process, errCode %{public}08x", errCode);
AppMgrEventUtil::SendChildProcessStartFailedEvent(childProcessRecord,
ProcessStartFailedReason::APPSPAWN_FAILED, static_cast<int32_t>(errCode));
return ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT;
}

View File

@ -102,6 +102,11 @@ std::string ChildProcessRecord::GetSrcEntry() const
return srcEntry_;
}
ProcessType ChildProcessRecord::GetProcessType() const
{
return processType_;
}
std::shared_ptr<AppRunningRecord> ChildProcessRecord::GetHostRecord() const
{
return hostRecord_.lock();

View File

@ -53,6 +53,8 @@ struct EventInfo {
int32_t processType = -1;
int32_t callerPid = -1;
int64_t duration = 0;
int32_t reason = -1;
int32_t subReason = -1;
};
enum class EventName {
@ -89,6 +91,7 @@ enum class EventName {
PROCESS_EXIT,
DRAWN_COMPLETED,
APP_STARTUP_TYPE,
PROCESS_START_FAILED,
// key behavior event
GRANT_URI_PERMISSION,
@ -116,6 +119,7 @@ public:
static void SendAppForegroundEvent(const EventName &eventName, const EventInfo &eventInfo);
static void SendAppBackgroundEvent(const EventName &eventName, const EventInfo &eventInfo);
static void SendProcessStartEvent(const EventName &eventName, const EventInfo &eventInfo);
static void SendProcessStartFailedEvent(const EventName &eventName, const EventInfo &eventInfo);
static void SendProcessExitEvent(const EventName &eventName, const EventInfo &eventInfo);
static void SendStartServiceEvent(const EventName &eventName, const EventInfo &eventInfo);
static void SendStopServiceEvent(const EventName &eventName, const EventInfo &eventInfo);

View File

@ -54,7 +54,11 @@ constexpr const char *EVENT_KEY_APP_UID = "APP_UID";
constexpr const char *EVENT_KEY_PROCESS_TYPE = "PROCESS_TYPE";
constexpr const char *EVENT_KEY_TIME = "TIME";
constexpr const char *EVENT_KEY_PID = "PID";
constexpr const char *EVENT_KEY_REASON = "REASON";
constexpr const char *EVENT_KEY_SUB_REASON = "SUB_REASON";
constexpr const char *INVALID_EVENT_NAME = "INVALIDEVENTNAME";
constexpr const int32_t DEFAULT_EXTENSION_TYPE = -1;
}
void EventReport::SendAppEvent(const EventName &eventName, HiSysEventType type, const EventInfo &eventInfo)
@ -472,6 +476,51 @@ void EventReport::SendProcessStartEvent(const EventName &eventName, const EventI
}
}
void EventReport::SendProcessStartFailedEvent(const EventName &eventName, const EventInfo &eventInfo)
{
std::string name = ConvertEventName(eventName);
if (name == INVALID_EVENT_NAME) {
TAG_LOGE(AAFwkTag::DEFAULT, "invalid eventName");
return;
}
TAG_LOGD(AAFwkTag::DEFAULT, "eventName:%{public}s,processName:%{public}s,reason:%{public}d,subReason:%{public}d",
name.c_str(), eventInfo.processName.c_str(), eventInfo.reason, eventInfo.subReason);
if (eventInfo.extensionType == DEFAULT_EXTENSION_TYPE) {
HiSysEventWrite(
HiSysEvent::Domain::AAFWK,
name,
HiSysEventType::FAULT,
EVENT_KEY_STARTUP_TIME, eventInfo.time,
EVENT_KEY_STARTUP_ABILITY_TYPE, eventInfo.abilityType,
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName,
EVENT_KEY_CALLER_UID, eventInfo.callerUid,
EVENT_KEY_CALLER_PROCESS_NAME, eventInfo.callerProcessName,
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
EVENT_KEY_PROCESS_NAME, eventInfo.processName,
EVENT_KEY_CALLER_PROCESS_ID, eventInfo.callerPid,
EVENT_KEY_PROCESS_TYPE, eventInfo.processType,
EVENT_KEY_REASON, eventInfo.reason,
EVENT_KEY_SUB_REASON, eventInfo.subReason);
} else {
HiSysEventWrite(
HiSysEvent::Domain::AAFWK,
name,
HiSysEventType::FAULT,
EVENT_KEY_STARTUP_TIME, eventInfo.time,
EVENT_KEY_STARTUP_ABILITY_TYPE, eventInfo.abilityType,
EVENT_KEY_STARTUP_EXTENSION_TYPE, eventInfo.extensionType,
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName,
EVENT_KEY_CALLER_UID, eventInfo.callerUid,
EVENT_KEY_CALLER_PROCESS_NAME, eventInfo.callerProcessName,
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
EVENT_KEY_PROCESS_NAME, eventInfo.processName,
EVENT_KEY_CALLER_PROCESS_ID, eventInfo.callerPid,
EVENT_KEY_PROCESS_TYPE, eventInfo.processType,
EVENT_KEY_REASON, eventInfo.reason,
EVENT_KEY_SUB_REASON, eventInfo.subReason);
}
}
void EventReport::SendProcessExitEvent(const EventName &eventName, const EventInfo &eventInfo)
{
std::string name = ConvertEventName(eventName);
@ -591,7 +640,7 @@ std::string EventReport::ConvertEventName(const EventName &eventName)
// app behavior event
"APP_ATTACH", "APP_LAUNCH", "APP_FOREGROUND", "APP_BACKGROUND", "APP_TERMINATE",
"PROCESS_START", "PROCESS_EXIT", "DRAWN_COMPLETED", "APP_STARTUP_TYPE",
"PROCESS_START", "PROCESS_EXIT", "DRAWN_COMPLETED", "APP_STARTUP_TYPE", "PROCESS_START_FAILED",
// key behavior event
"GRANT_URI_PERMISSION", "FA_SHOW_ON_LOCK", "START_PRIVATE_ABILITY",

View File

@ -193,5 +193,110 @@ HWTEST_F(AppMgrEventTest, SendProcessStartEvent_0300, TestSize.Level1)
bool ret = AppMgrEventUtil::SendProcessStartEvent(callerAppRecord, appRecord, eventInfo);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: SendProcessStartFailedEvent_0100
* @tc.desc: Send process start failed event
* @tc.type: FUNC
*/
HWTEST_F(AppMgrEventTest, SendProcessStartFailedEvent_0100, TestSize.Level1)
{
std::shared_ptr<AppRunningRecord> callerAppRecord = nullptr;
std::shared_ptr<AppRunningRecord> appRecord = nullptr;
AAFwk::EventInfo eventInfo;
bool ret = AppMgrEventUtil::SendProcessStartFailedEvent(callerAppRecord, appRecord, eventInfo);
EXPECT_EQ(ret, false);
}
/**
* @tc.name: SendProcessStartFailedEvent_0200
* @tc.desc: Send process start failed event
* @tc.type: FUNC
*/
HWTEST_F(AppMgrEventTest, SendProcessStartFailedEvent_0200, TestSize.Level1)
{
auto appInfo = std::make_shared<ApplicationInfo>();
EXPECT_NE(appInfo, nullptr);
appInfo->bundleName = "testBundleName";
appInfo->name = "testBundleName";
int32_t recordId = 1;
std::string processName = "testProcess";
auto appRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
appRecord->SetCallerUid(-1);
appRecord->priorityObject_->SetPid(1001);
EXPECT_NE(appRecord, nullptr);
std::shared_ptr<AppRunningRecord> callerAppRecord = nullptr;
AAFwk::EventInfo eventInfo;
bool ret = AppMgrEventUtil::SendProcessStartFailedEvent(callerAppRecord, appRecord, eventInfo);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: SendProcessStartFailedEvent_0300
* @tc.desc: Send process start failed event
* @tc.type: FUNC
*/
HWTEST_F(AppMgrEventTest, SendProcessStartFailedEvent_0300, TestSize.Level1)
{
auto appInfo = std::make_shared<ApplicationInfo>();
EXPECT_NE(appInfo, nullptr);
appInfo->bundleName = "testBundleName";
appInfo->name = "testBundleName";
int32_t recordId = 1;
std::string processName = "testProcess";
auto appRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
EXPECT_NE(appRecord, nullptr);
appRecord->SetCallerUid(-1);
auto callerAppInfo = std::make_shared<ApplicationInfo>();
EXPECT_NE(callerAppInfo, nullptr);
callerAppInfo->bundleName = "testCallerBundleName";
callerAppInfo->name = "testCallerBundleName";
std::string callerProcessName = "testCallerProcess";
int32_t callerRecordId = 2;
auto callerAppRecord = std::make_shared<AppRunningRecord>(callerAppInfo, callerRecordId, callerProcessName);
EXPECT_NE(callerAppRecord, nullptr);
AAFwk::EventInfo eventInfo;
bool ret = AppMgrEventUtil::SendProcessStartFailedEvent(callerAppRecord, appRecord, eventInfo);
EXPECT_EQ(ret, true);
}
/**
* @tc.name: SendRenderProcessStartFailedEvent_0100
* @tc.desc: Send render process start failed event
* @tc.type: FUNC
*/
HWTEST_F(AppMgrEventTest, SendRenderProcessStartFailedEvent_0100, TestSize.Level1)
{
auto appInfo = std::make_shared<ApplicationInfo>();
EXPECT_NE(appInfo, nullptr);
appInfo->bundleName = "testBundleName";
appInfo->name = "testBundleName";
std::string processName = "testProcess";
int32_t recordId = 1;
pid_t hostPid = 1001;
auto hostRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
hostRecord->priorityObject_->SetPid(hostPid);
hostRecord->SetUid(100);
EXPECT_NE(hostRecord, nullptr);
std::string renderParam = "test_render_param";
int32_t ipcFd = 1;
int32_t sharedFd = 1;
int32_t crashFd = 1;
std::shared_ptr<RenderRecord> renderRecord =
RenderRecord::CreateRenderRecord(hostPid, renderParam, ipcFd, sharedFd, crashFd, hostRecord);
bool ret = AppMgrEventUtil::SendRenderProcessStartFailedEvent(renderRecord,
ProcessStartFailedReason::APPSPAWN_FAILED, 123);
EXPECT_EQ(ret, true);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -22,6 +22,7 @@
#include "remote_client_manager.h"
#undef private
#include "app_scheduler.h"
#include "app_mgr_event.h"
#include "event_handler.h"
#include "hilog_tag_wrapper.h"
#include "ipc_skeleton.h"
@ -345,6 +346,89 @@ HWTEST_F(AppMgrServiceInnerTest, SendProcessStartEvent_008, TestSize.Level1)
TAG_LOGI(AAFwkTag::TEST, "SendProcessStartEvent_008 end");
}
/**
* @tc.name: SendProcessStartFailedEvent_001
* @tc.desc: Verify that the SendProcessStartFailedEvent interface calls abnormal parameter
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerTest, SendProcessStartFailedEvent_001, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "SendProcessStartFailedEvent_001 start");
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
appMgrServiceInner->Init();
EXPECT_NE(appMgrServiceInner, nullptr);
EXPECT_FALSE(appMgrServiceInner->SendProcessStartFailedEvent(nullptr,
ProcessStartFailedReason::APPSPAWN_FAILED, 0));
TAG_LOGI(AAFwkTag::TEST, "SendProcessStartFailedEvent_001 end");
}
/**
* @tc.name: SendProcessStartFailedEvent_002
* @tc.desc: Verify that the SendProcessStartFailedEvent interface calls abnormal parameter
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerTest, SendProcessStartFailedEvent_002, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "SendProcessStartFailedEvent_002 start");
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
appMgrServiceInner->Init();
EXPECT_NE(appMgrServiceInner, nullptr);
BundleInfo bundleInfo;
std::string processName = "test_processName";
std::shared_ptr<AppRunningRecord> appRecord =
appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
EXPECT_TRUE(
appMgrServiceInner->SendProcessStartFailedEvent(appRecord, ProcessStartFailedReason::APPSPAWN_FAILED, 0));
TAG_LOGI(AAFwkTag::TEST, "SendProcessStartFailedEvent_002 end");
}
/**
* @tc.name: SendProcessStartFailedEvent_003
* @tc.desc: Verify that the SendProcessStartFailedEvent interface calls like a application called
* @tc.type: FUNC
*/
HWTEST_F(AppMgrServiceInnerTest, SendProcessStartFailedEvent_003, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "SendProcessStartFailedEvent_003 start");
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
appMgrServiceInner->Init();
EXPECT_NE(appMgrServiceInner, nullptr);
BundleInfo bundleInfo;
std::string processName = "test_processName";
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
applicationInfo_->bundleName = "testBundleName";
std::shared_ptr<AppRunningRecord> appRecord =
appMgrServiceInner->appRunningManager_->CreateAppRunningRecord(applicationInfo_, processName, bundleInfo);
EXPECT_NE(appRecord, nullptr);
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
std::shared_ptr<ModuleRunningRecord> moduleRunningRecord = std::make_shared<ModuleRunningRecord>(appInfo, nullptr);
auto abilityRecordEmpty = std::make_shared<AbilityRunningRecord>(nullptr, token, 0);
moduleRunningRecord->abilities_[token] = abilityRecordEmpty;
std::vector<std::shared_ptr<ModuleRunningRecord>> moduleRecordList = { moduleRunningRecord };
appRecord->hapModules_["moduleRecordList"] = moduleRecordList;
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
auto abilityRecord = std::make_shared<AbilityRunningRecord>(abilityInfo, token, 0);
moduleRunningRecord->abilities_[token] = abilityRecord;
appRecord->SetCallerTokenId(IPCSkeleton::GetCallingTokenID());
appRecord->SetCallerUid(IPCSkeleton::GetCallingUid());
auto &recordMap = appMgrServiceInner->appRunningManager_->appRunningRecordMap_;
auto iter = recordMap.find(IPCSkeleton::GetCallingPid());
if (iter == recordMap.end()) {
recordMap.insert({IPCSkeleton::GetCallingPid(), appRecord});
} else {
recordMap.erase(iter);
recordMap.insert({IPCSkeleton::GetCallingPid(), appRecord});
}
appRecord->GetPriorityObject()->pid_ = IPCSkeleton::GetCallingPid();
appRecord->SetCallerPid(IPCSkeleton::GetCallingPid());
EXPECT_TRUE(appMgrServiceInner->SendProcessStartFailedEvent(appRecord, ProcessStartFailedReason::APPSPAWN_FAILED,
1));
TAG_LOGI(AAFwkTag::TEST, "SendProcessStartFailedEvent_003 end");
}
/**
* @tc.name: SendProcessExitEvent_001
* @tc.desc: Verify that the SendProcessExitEvent interface calls normally

View File

@ -80,6 +80,7 @@ HWTEST_F(EventReportTest, ConvertEventName_0100, TestSize.Level0)
EXPECT_EQ(EventReport::ConvertEventName(EventName::PROCESS_EXIT), "PROCESS_EXIT");
EXPECT_EQ(EventReport::ConvertEventName(EventName::DRAWN_COMPLETED), "DRAWN_COMPLETED");
EXPECT_EQ(EventReport::ConvertEventName(EventName::APP_STARTUP_TYPE), "APP_STARTUP_TYPE");
EXPECT_EQ(EventReport::ConvertEventName(EventName::PROCESS_START_FAILED), "PROCESS_START_FAILED");
// key behavior event
EXPECT_EQ(EventReport::ConvertEventName(EventName::GRANT_URI_PERMISSION), "GRANT_URI_PERMISSION");
EXPECT_EQ(EventReport::ConvertEventName(EventName::FA_SHOW_ON_LOCK), "FA_SHOW_ON_LOCK");
@ -574,6 +575,25 @@ HWTEST_F(EventReportTest, SendProcessStartEvent_0100, TestSize.Level0)
EventReport::SendProcessStartEvent(eventName, eventInfo);
}
/**
* @tc.name: SendProcessStartFailedEvent_0100
* @tc.desc: Check SendProcessStartFailedEvent Test
* @tc.type: FUNC
* @tc.require: issueI99FZY
*/
HWTEST_F(EventReportTest, SendProcessStartFailedEvent_0100, TestSize.Level0)
{
EventName eventName = static_cast<EventName>(-1);
EXPECT_EQ(EventReport::ConvertEventName(eventName), "INVALIDEVENTNAME");
EventInfo eventInfo;
EventReport::SendProcessStartFailedEvent(eventName, eventInfo);
eventName = EventName::PROCESS_START_FAILED;
EventReport::SendProcessStartFailedEvent(eventName, eventInfo);
eventInfo.extensionType = 0;
EventReport::SendProcessStartFailedEvent(eventName, eventInfo);
EXPECT_EQ(EventReport::ConvertEventName(eventName), "PROCESS_START_FAILED");
}
/**
* @tc.name: SendProcessExitEvent_0100
* @tc.desc: Check SendProcessExitEvent Test