mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2025-02-06 15:06:28 +00:00
Issue:#I6UDXQ
Signed-off-by: zhoushicheng <zhoushicheng2@huawei.com> Change-Id: Id54d0766e90b3120d07544bfd6a4c75421f1f07c
This commit is contained in:
parent
4f6eedb5b7
commit
db80f6f411
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -317,11 +317,22 @@ void Ability::OnActive()
|
||||
return;
|
||||
}
|
||||
lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_ACTIVE);
|
||||
if (abilityInfo_ == nullptr) {
|
||||
HILOG_ERROR("Ability::OnActive error. abilityInfo_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
AAFwk::EventInfo eventInfo;
|
||||
eventInfo.bundleName = abilityInfo_->bundleName;
|
||||
eventInfo.moduleName = abilityInfo_->moduleName;
|
||||
eventInfo.abilityName = abilityInfo_->name;
|
||||
eventInfo.abilityType = static_cast<int32_t>(abilityInfo_->type);
|
||||
eventInfo.bundleType = static_cast<int32_t>(abilityInfo_->applicationInfo.bundleType);
|
||||
if (setWant_ != nullptr) {
|
||||
eventInfo.callerBundleName = setWant_->GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME);
|
||||
HILOG_INFO("callerBundleName is %{public}s", eventInfo.callerBundleName.c_str());
|
||||
} else {
|
||||
HILOG_ERROR("setWant_ is nullptr, can not get callerBundleName.");
|
||||
}
|
||||
AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::ABILITY_ONACTIVE,
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
HILOG_DEBUG("%{public}s end.", __func__);
|
||||
@ -345,10 +356,15 @@ void Ability::OnInactive()
|
||||
return;
|
||||
}
|
||||
lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_INACTIVE);
|
||||
if (abilityInfo_ == nullptr) {
|
||||
HILOG_ERROR("Ability::OnInactive error. abilityInfo_ == nullptr.");
|
||||
return;
|
||||
}
|
||||
AAFwk::EventInfo eventInfo;
|
||||
eventInfo.bundleName = abilityInfo_->bundleName;
|
||||
eventInfo.moduleName = abilityInfo_->moduleName;
|
||||
eventInfo.abilityName = abilityInfo_->name;
|
||||
eventInfo.bundleType = static_cast<int32_t>(abilityInfo_->applicationInfo.bundleType);
|
||||
AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::ABILITY_ONINACTIVE,
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
HILOG_DEBUG("%{public}s end", __func__);
|
||||
@ -1515,6 +1531,12 @@ void Ability::OnForeground(const Want &want)
|
||||
eventInfo.bundleName = want.GetElement().GetBundleName();
|
||||
eventInfo.moduleName = want.GetElement().GetModuleName();
|
||||
eventInfo.abilityName = want.GetElement().GetAbilityName();
|
||||
eventInfo.callerBundleName = want.GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME);
|
||||
if (abilityInfo_ != nullptr) {
|
||||
eventInfo.bundleType = static_cast<int32_t>(abilityInfo_->applicationInfo.bundleType);
|
||||
} else {
|
||||
HILOG_ERROR("abilityInfo_ is nullptr, can not get bundleType.");
|
||||
}
|
||||
AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::ABILITY_ONFOREGROUND,
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
@ -1569,6 +1591,7 @@ void Ability::OnBackground()
|
||||
eventInfo.bundleName = abilityInfo_->bundleName;
|
||||
eventInfo.moduleName = abilityInfo_->moduleName;
|
||||
eventInfo.abilityName = abilityInfo_->name;
|
||||
eventInfo.bundleType = static_cast<int32_t>(abilityInfo_->applicationInfo.bundleType);
|
||||
AAFwk::EventReport::SendAbilityEvent(AAFwk::EventName::ABILITY_ONBACKGROUND,
|
||||
HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
|
@ -129,12 +129,15 @@ ABILITY_ONFOREGROUND:
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
MODULE_NAME: {type: STRING, desc: module name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
BUNDLE_TYPE: {type: INT32, desc: type of componment, atomic service or normal app}
|
||||
CALLER_BUNDLENAME: {type: STRING, desc: caller bundle name}
|
||||
|
||||
ABILITY_ONBACKGROUND:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: ability, desc: ability onBackground}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
MODULE_NAME: {type: STRING, desc: module name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
BUNDLE_TYPE: {type: INT32, desc: type of componment, atomic service or normal app}
|
||||
|
||||
ABILITY_ONACTIVE:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: ability onActive}
|
||||
@ -142,12 +145,15 @@ ABILITY_ONACTIVE:
|
||||
MODULE_NAME: {type: STRING, desc: module name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
ABILITY_TYPE: {type: INT32, desc: ability type}
|
||||
BUNDLE_TYPE: {type: INT32, desc: type of componment, atomic service or normal app}
|
||||
CALLER_BUNDLENAME: {type: STRING, desc: caller bundle name}
|
||||
|
||||
ABILITY_ONINACTIVE:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, desc: ability onInactive}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
MODULE_NAME: {type: STRING, desc: module name}
|
||||
ABILITY_NAME: {type: STRING, desc: ability name}
|
||||
BUNDLE_TYPE: {type: INT32, desc: type of componment, atomic service or normal app}
|
||||
|
||||
# serviceExtensionAbility behavior event
|
||||
|
||||
@ -202,6 +208,8 @@ APP_FOREGROUND:
|
||||
VERSION_NAME: {type: STRING, desc: version name}
|
||||
PROCESS_NAME: {type: STRING, desc: process name}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
BUNDLE_TYPE: {type: INT32, desc: type of componment, atomic service or normal app}
|
||||
CALLER_BUNDLENAME: {type: STRING, desc: caller bundle name}
|
||||
|
||||
APP_BACKGROUND:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: PowerStats, desc: background app}
|
||||
@ -210,6 +218,7 @@ APP_BACKGROUND:
|
||||
VERSION_NAME: {type: STRING, desc: version name}
|
||||
PROCESS_NAME: {type: STRING, desc: process name}
|
||||
BUNDLE_NAME: {type: STRING, desc: bundle name}
|
||||
BUNDLE_TYPE: {type: INT32, desc: type of componment, atomic service or normal app}
|
||||
|
||||
APP_TERMINATE:
|
||||
__BASE: {type: BEHAVIOR, level: MINOR, tag: app, desc: terminate app}
|
||||
|
@ -421,6 +421,14 @@ void AppMgrServiceInner::ApplicationForegrounded(const int32_t recordId)
|
||||
eventInfo.versionName = applicationInfo->versionName;
|
||||
eventInfo.versionCode = applicationInfo->versionCode;
|
||||
eventInfo.processName = appRecord->GetProcessName();
|
||||
eventInfo.bundleType = static_cast<int32_t>(applicationInfo->bundleType);
|
||||
int32_t callerPid = appRecord->GetCallerPid() == -1 ? IPCSkeleton::GetCallingPid() : appRecord->GetCallerPid();
|
||||
auto callerRecord = GetAppRunningRecordByPid(callerPid);
|
||||
if (callerRecord != nullptr) {
|
||||
eventInfo.callerBundleName = callerRecord->GetBundleName();
|
||||
} else {
|
||||
HILOG_ERROR("callerRecord is nullptr, can not get callerBundleName.");
|
||||
}
|
||||
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_FOREGROUND, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
|
||||
@ -451,6 +459,7 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId)
|
||||
eventInfo.versionName = applicationInfo->versionName;
|
||||
eventInfo.versionCode = applicationInfo->versionCode;
|
||||
eventInfo.processName = appRecord->GetProcessName();
|
||||
eventInfo.bundleType = static_cast<int32_t>(applicationInfo->bundleType);
|
||||
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::APP_BACKGROUND, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
}
|
||||
|
||||
@ -1737,21 +1746,21 @@ bool AppMgrServiceInner::SendProcessStartEvent(const std::shared_ptr<AppRunningR
|
||||
auto token = appRecord->GetCallerTokenId() == -1 ?
|
||||
static_cast<int>(IPCSkeleton::GetCallingTokenID()) : appRecord->GetCallerTokenId();
|
||||
Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(token, nativeTokenInfo);
|
||||
eventInfo.bundleName = "";
|
||||
eventInfo.processName = nativeTokenInfo.processName;
|
||||
eventInfo.callerBundleName = "";
|
||||
eventInfo.callerProcessName = nativeTokenInfo.processName;
|
||||
} else {
|
||||
if (callerAppRecord->GetBundleName().empty()) {
|
||||
eventInfo.bundleName = callerAppRecord->GetName();
|
||||
eventInfo.callerBundleName = callerAppRecord->GetName();
|
||||
} else {
|
||||
eventInfo.bundleName = callerAppRecord->GetBundleName();
|
||||
eventInfo.callerBundleName = callerAppRecord->GetBundleName();
|
||||
}
|
||||
eventInfo.processName = callerAppRecord->GetProcessName();
|
||||
eventInfo.callerProcessName = callerAppRecord->GetProcessName();
|
||||
}
|
||||
AAFwk::EventReport::SendAppEvent(AAFwk::EventName::PROCESS_START, HiSysEventType::BEHAVIOR, eventInfo);
|
||||
HILOG_INFO("%{public}s. time : %{public}" PRId64 ", abilityType : %{public}d, bundle : %{public}s,\
|
||||
uid : %{public}d, process : %{public}s",
|
||||
__func__, eventInfo.time, eventInfo.abilityType, eventInfo.bundleName.c_str(), eventInfo.callerUid,
|
||||
eventInfo.processName.c_str());
|
||||
__func__, eventInfo.time, eventInfo.abilityType, eventInfo.callerBundleName.c_str(), eventInfo.callerUid,
|
||||
eventInfo.callerProcessName.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -38,10 +38,13 @@ struct EventInfo {
|
||||
std::string moduleName;
|
||||
std::string abilityName;
|
||||
std::string processName;
|
||||
std::string callerProcessName;
|
||||
std::string callerBundleName;
|
||||
int32_t abilityType = -1;
|
||||
int64_t time = 0;
|
||||
int32_t callerUid = -1;
|
||||
int32_t exitResult = -1;
|
||||
int32_t bundleType = -1;
|
||||
};
|
||||
|
||||
enum class EventName {
|
||||
|
@ -44,6 +44,7 @@ const std::string EVENT_KEY_CALLER_PROCESS_NAME = "CALLER_PROCESS_NAME";
|
||||
const std::string EVENT_KEY_EXIT_TIME = "EXIT_TIME";
|
||||
const std::string EVENT_KEY_EXIT_RESULT = "EXIT_RESULT";
|
||||
const std::string EVENT_KEY_EXIT_PID = "EXIT_PID";
|
||||
const std::string EVENT_KEY_BUNDLE_TYPE = "BUNDLE_TYPE";
|
||||
const std::map<EventName, std::string> eventNameToStrMap_ = {
|
||||
std::map<EventName, std::string>::value_type(EventName::START_ABILITY_ERROR, "START_ABILITY_ERROR"),
|
||||
std::map<EventName, std::string>::value_type(EventName::TERMINATE_ABILITY_ERROR, "TERMINATE_ABILITY_ERROR"),
|
||||
@ -102,9 +103,9 @@ void EventReport::SendAppEvent(const EventName &eventName, HiSysEventType type,
|
||||
type,
|
||||
EVENT_KEY_STARTUP_TIME, eventInfo.time,
|
||||
EVENT_KEY_STARTUP_ABILITY_TYPE, eventInfo.abilityType,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName,
|
||||
EVENT_KEY_CALLER_UID, eventInfo.callerUid,
|
||||
EVENT_KEY_CALLER_PROCESS_NAME, eventInfo.processName);
|
||||
EVENT_KEY_CALLER_PROCESS_NAME, eventInfo.callerProcessName);
|
||||
} else {
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
@ -113,9 +114,9 @@ void EventReport::SendAppEvent(const EventName &eventName, HiSysEventType type,
|
||||
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.bundleName,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName,
|
||||
EVENT_KEY_CALLER_UID, eventInfo.callerUid,
|
||||
EVENT_KEY_CALLER_PROCESS_NAME, eventInfo.processName);
|
||||
EVENT_KEY_CALLER_PROCESS_NAME, eventInfo.callerProcessName);
|
||||
}
|
||||
break;
|
||||
case EventName::PROCESS_EXIT:
|
||||
@ -127,6 +128,29 @@ void EventReport::SendAppEvent(const EventName &eventName, HiSysEventType type,
|
||||
EVENT_KEY_EXIT_RESULT, eventInfo.exitResult,
|
||||
EVENT_KEY_EXIT_PID, eventInfo.pid);
|
||||
break;
|
||||
case EventName::APP_FOREGROUND:
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
name,
|
||||
type,
|
||||
EVENT_KEY_APP_PID, eventInfo.pid,
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_VERSION_NAME, eventInfo.versionName,
|
||||
EVENT_KEY_VERSION_CODE, eventInfo.versionCode,
|
||||
EVENT_KEY_PROCESS_NAME, eventInfo.processName,
|
||||
EVENT_KEY_BUNDLE_TYPE, eventInfo.bundleType,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName);
|
||||
case EventName::APP_BACKGROUND:
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
name,
|
||||
type,
|
||||
EVENT_KEY_APP_PID, eventInfo.pid,
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_VERSION_NAME, eventInfo.versionName,
|
||||
EVENT_KEY_VERSION_CODE, eventInfo.versionCode,
|
||||
EVENT_KEY_PROCESS_NAME, eventInfo.processName,
|
||||
EVENT_KEY_BUNDLE_TYPE, eventInfo.bundleType);
|
||||
default:
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
@ -182,6 +206,16 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty
|
||||
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName);
|
||||
break;
|
||||
case EventName::ABILITY_ONFOREGROUND:
|
||||
HiSysEventWrite(
|
||||
HiSysEvent::Domain::AAFWK,
|
||||
name,
|
||||
type,
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_MODULE_NAME, eventInfo.moduleName,
|
||||
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName,
|
||||
EVENT_KEY_BUNDLE_TYPE, eventInfo.bundleType,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName);
|
||||
break;
|
||||
case EventName::ABILITY_ONBACKGROUND:
|
||||
case EventName::ABILITY_ONINACTIVE:
|
||||
HiSysEventWrite(
|
||||
@ -190,7 +224,8 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty
|
||||
type,
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_MODULE_NAME, eventInfo.moduleName,
|
||||
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName);
|
||||
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName,
|
||||
EVENT_KEY_BUNDLE_TYPE, eventInfo.bundleType);
|
||||
break;
|
||||
case EventName::ABILITY_ONACTIVE:
|
||||
HiSysEventWrite(
|
||||
@ -200,7 +235,9 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty
|
||||
EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName,
|
||||
EVENT_KEY_MODULE_NAME, eventInfo.moduleName,
|
||||
EVENT_KEY_ABILITY_NAME, eventInfo.abilityName,
|
||||
EVENT_KEY_ABILITY_TYPE, eventInfo.abilityType);
|
||||
EVENT_KEY_ABILITY_TYPE, eventInfo.abilityType,
|
||||
EVENT_KEY_BUNDLE_TYPE, eventInfo.bundleType,
|
||||
EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user