From bf95c1d6812241bd2ce159379469db120ff6fffd Mon Sep 17 00:00:00 2001 From: "zhoushicheng2@huawei.com" Date: Thu, 26 May 2022 16:25:04 +0800 Subject: [PATCH] zhoushicheng2@huawei.com Signed-off-by: zhoushicheng2@huawei.com Change-Id: Ifebac8e6fa927acbc5b9db6ee84d761039047240 --- hisysevent.yaml | 4 +- .../include/ability_manager_service.h | 1 - .../src/ability_manager_service.cpp | 104 +++++------------- services/appmgr/src/app_mgr_service_inner.cpp | 30 ++--- services/common/BUILD.gn | 5 +- services/common/include/event_report.h | 15 ++- services/common/src/event_report.cpp | 11 +- 7 files changed, 55 insertions(+), 115 deletions(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index 5b533a36..0b7e8511 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -117,7 +117,7 @@ TERMINATE_ABILITY: # serviceExtensionAbility behavior event -START_SERVICE_EXTENSION: +START_SERVICE: __BASE: {type: BEHAVIOR, level: MINOR, tag: ability, desc: start serviceExtensionAbility} USER_ID: {type: INT32, desc: userId} BUNDLE_NAME: {type: STRING, desc: bundle name} @@ -125,7 +125,7 @@ START_SERVICE_EXTENSION: ABILITY_NAME: {type: STRING, desc: ability name} EXTENSION_TYPE: {type: STRING, desc: extension type} -STOP_SERVICE_EXTENSION: +STOP_SERVICE: __BASE: {type: BEHAVIOR, level: MINOR, tag: ability, desc: stop serviceExtensionAbility} USER_ID: {type: INT32, desc: userId} BUNDLE_NAME: {type: STRING, desc: bundle name} diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 3687b618..6d6755f8 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1016,7 +1016,6 @@ private: const sptr &callerToken, int32_t userId); int CheckOptExtensionAbility(const Want &want, AbilityRequest &abilityRequest, int32_t validUserId, AppExecFwk::ExtensionAbilityType extensionType); - std::string GetExtensionType(AppExecFwk::ExtensionAbilityType extensionType); constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000; constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 498c2709..3f8333bf 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -632,7 +632,7 @@ int AbilityManagerService::StartAbility(const Want &want, const StartOptions &st abilityRequest.want.SetParam(Want::PARAM_RESV_WINDOW_MODE, startOptions.GetWindowMode()); auto missionListManager = GetListManagerByUserId(oriValidUserId); if (missionListManager == nullptr) { - HILOG_ERROR("missionListManager is Null. userId=%{public}d", validUserId); + HILOG_ERROR("missionListManager is Null. userId=%{public}d", oriValidUserId); eventInfo.errCode = ERR_INVALID_VALUE; AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); @@ -690,13 +690,13 @@ int AbilityManagerService::StartExtensionAbility(const Want &want, const sptrStartAbility(abilityRequest); if (eventInfo.errCode != ERR_OK) { - AAFWK::EventReport::SendAbilityEvent(AAFWK::START_EXTENSION_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); } return eventInfo.errCode; @@ -768,13 +768,13 @@ int AbilityManagerService::StopExtensionAbility(const Want &want, const sptrStopServiceAbility(abilityRequest); - AAFWK::EventReport::SendAbilityEvent(AAFWK::STOP_EXTENSION_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::STOP_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); return eventInfo.errCode; @@ -898,19 +898,13 @@ void AbilityManagerService::GrantUriPermission(const Want &want, int32_t validUs int AbilityManagerService::TerminateAbility(const sptr &token, int resultCode, const Want *resultWant) { AAFWK::EventInfo eventInfo; - auto abilityRecord = Token::GetAbilityRecordByToken(token); - eventInfo.userId = abilityRecord->GetApplicationInfo().uid / BASE_USER_RANGE; - eventInfo.bundleName = resultWant->GetElement().GetBundleName(); - eventInfo.moduleName = resultWant->GetElement().GetModuleName(); - eventInfo.abilityName = resultWant->GetElement().GetAbilityName(); - eventInfo.errCode = TerminateAbilityWithFlag(token, resultCode, resultWant, true); AAFWK::EventReport::SendAbilityEvent(AAFWK::TERMINATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); if (eventInfo.errCode != ERR_OK) { AAFWK::EventReport::SendAbilityEvent(AAFWK::TERMINATE_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); } - return eventInfo.errCode; + return TerminateAbilityWithFlag(token, resultCode, resultWant, true); } int AbilityManagerService::CloseAbility(const sptr &token, int resultCode, const Want *resultWant) @@ -1171,7 +1165,7 @@ int AbilityManagerService::ConnectAbility( if (VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); eventInfo.errCode = CHECK_PERMISSION_FAILED; - AAFWK::EventReport::SendAbilityEvent(AAFWK::CONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); return CHECK_PERMISSION_FAILED; } @@ -1180,7 +1174,7 @@ int AbilityManagerService::ConnectAbility( if (!GetLocalDeviceId(localDeviceId)) { HILOG_ERROR("%{public}s: Get Local DeviceId failed", __func__); eventInfo.errCode = ERR_INVALID_VALUE; - AAFWK::EventReport::SendAbilityEvent(AAFWK::CONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); return ERR_INVALID_VALUE; } @@ -1188,7 +1182,7 @@ int AbilityManagerService::ConnectAbility( int result = manager->IsConnectFreeInstall(want, validUserId, callerToken, localDeviceId); if (result != ERR_OK) { eventInfo.errCode = result; - AAFWK::EventReport::SendAbilityEvent(AAFWK::CONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); return result; } @@ -1205,7 +1199,7 @@ int AbilityManagerService::ConnectAbility( if (!queryResult || extensionInfo.name.empty() || extensionInfo.bundleName.empty()) { HILOG_ERROR("Invalid extension ability info."); eventInfo.errCode = ERR_INVALID_VALUE; - AAFWK::EventReport::SendAbilityEvent(AAFWK::CONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); return ERR_INVALID_VALUE; } @@ -1215,7 +1209,7 @@ int AbilityManagerService::ConnectAbility( if (CheckIfOperateRemote(abilityWant)) { HILOG_INFO("AbilityManagerService::ConnectAbility. try to ConnectRemoteAbility"); eventInfo.errCode = ConnectRemoteAbility(abilityWant, connect->AsObject()); - AAFWK::EventReport::SendAbilityEvent(AAFWK::CONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); return eventInfo.errCode; } @@ -1223,13 +1217,13 @@ int AbilityManagerService::ConnectAbility( if (callerToken != nullptr && callerToken->GetObjectDescriptor() != u"ohos.aafwk.AbilityToken") { HILOG_INFO("%{public}s invalid Token.", __func__); eventInfo.errCode = ConnectLocalAbility(abilityWant, validUserId, connect, nullptr); - AAFWK::EventReport::SendAbilityEvent(AAFWK::CONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); return eventInfo.errCode; } eventInfo.errCode = ConnectLocalAbility(abilityWant, validUserId, connect, callerToken); if (eventInfo.errCode != ERR_OK) { - AAFWK::EventReport::SendAbilityEvent(AAFWK::CONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); } return eventInfo.errCode; @@ -1248,7 +1242,7 @@ int AbilityManagerService::DisconnectAbility(const sptr &con eventInfo.errCode = DisconnectLocalAbility(connect); eventInfo.errCode |= DisconnectRemoteAbility(connect->AsObject()); if (eventInfo.errCode != ERR_OK) { - AAFWK::EventReport::SendAbilityEvent(AAFWK::DISCONNECT_SERVICE_ERROR, + AAFWK::EventReport::SendExtensionEvent(AAFWK::DISCONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); } return eventInfo.errCode; @@ -4719,50 +4713,6 @@ int AbilityManagerService::DumpAbilityInfoDone(std::vector &infos, return ERR_OK; } -std::string AbilityManagerService::GetExtensionType(AppExecFwk::ExtensionAbilityType extensionType) -{ - std::string extensionTypeStr; - switch (extensionType) { - case AppExecFwk::ExtensionAbilityType::FORM: - extensionTypeStr = "FOMR"; - break; - case AppExecFwk::ExtensionAbilityType::WORK_SCHEDULER: - extensionTypeStr = "WORK_SCHEDULER"; - break; - case AppExecFwk::ExtensionAbilityType::INPUTMETHOD: - extensionTypeStr = "INPUTMETHOD"; - break; - case AppExecFwk::ExtensionAbilityType::SERVICE: - extensionTypeStr = "SERVICE"; - break; - case AppExecFwk::ExtensionAbilityType::ACCESSIBILITY: - extensionTypeStr = "ACCESSIBILITY"; - break; - case AppExecFwk::ExtensionAbilityType::DATASHARE: - extensionTypeStr = "DATASHARE"; - break; - case AppExecFwk::ExtensionAbilityType::FILESHARE: - extensionTypeStr = "FILESHARE"; - break; - case AppExecFwk::ExtensionAbilityType::STATICSUBSCRIBER: - extensionTypeStr = "STATICSUBSCRIBER"; - break; - case AppExecFwk::ExtensionAbilityType::WALLPAPER: - extensionTypeStr = "WALLPAPER"; - break; - case AppExecFwk::ExtensionAbilityType::BACKUP: - extensionTypeStr = "BACKUP"; - break; - case AppExecFwk::ExtensionAbilityType::WINDOW: - extensionTypeStr = "WINDOW"; - break; - default: - extensionTypeStr = "UNSPECIFIED"; - break; - } - return extensionTypeStr; -} - #ifdef SUPPORT_GRAPHICS int AbilityManagerService::SetMissionLabel(const sptr &token, const std::string &label) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 28d367dd..607966d8 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -273,13 +273,11 @@ void AppMgrServiceInner::AttachApplication(const pid_t pid, const sptrRegisterAppDeathRecipient(); AAFWK::EventInfo eventInfo; auto applicationInfo = appRecord->GetApplicationInfo(); - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.abilityName = appRecord->GetAbilityInfo()->name; eventInfo.bundleName = applicationInfo->name; eventInfo.versionName = applicationInfo->versionName; eventInfo.versionCode = applicationInfo->versionCode; - eventInfo.timeStamp = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) - .count(); + eventInfo.processName = applicationInfo->process; AAFWK::EventReport::SendAppEvent(AAFWK::APP_ATTACH, HiSysEventType::BEHAVIOR, eventInfo); } @@ -318,13 +316,11 @@ void AppMgrServiceInner::LaunchApplication(const std::shared_ptrLaunchPendingAbilities(); AAFWK::EventInfo eventInfo; auto applicationInfo = appRecord->GetApplicationInfo(); - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.abilityName = appRecord->GetAbilityInfo()->name; eventInfo.bundleName = applicationInfo->name; eventInfo.versionName = applicationInfo->versionName; eventInfo.versionCode = applicationInfo->versionCode; - eventInfo.timeStamp = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) - .count(); + eventInfo.processName = applicationInfo->process; AAFWK::EventReport::SendAppEvent(AAFWK::APP_LAUNCH, HiSysEventType::BEHAVIOR, eventInfo); } @@ -362,13 +358,11 @@ void AppMgrServiceInner::ApplicationForegrounded(const int32_t recordId) HILOG_INFO("application is foregrounded"); AAFWK::EventInfo eventInfo; auto applicationInfo = appRecord->GetApplicationInfo(); - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.abilityName = appRecord->GetAbilityInfo()->name; eventInfo.bundleName = applicationInfo->name; eventInfo.versionName = applicationInfo->versionName; eventInfo.versionCode = applicationInfo->versionCode; - eventInfo.timeStamp = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) - .count(); + eventInfo.processName = applicationInfo->process; AAFWK::EventReport::SendAppEvent(AAFWK::APP_FOREGROUND, HiSysEventType::BEHAVIOR, eventInfo); } @@ -393,13 +387,11 @@ void AppMgrServiceInner::ApplicationBackgrounded(const int32_t recordId) HILOG_INFO("application is backgrounded"); AAFWK::EventInfo eventInfo; auto applicationInfo = appRecord->GetApplicationInfo(); - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.abilityName = appRecord->GetAbilityInfo()->name; eventInfo.bundleName = applicationInfo->name; eventInfo.versionName = applicationInfo->versionName; eventInfo.versionCode = applicationInfo->versionCode; - eventInfo.timeStamp = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) - .count(); + eventInfo.processName = applicationInfo->process; AAFWK::EventReport::SendAppEvent(AAFWK::APP_BACKGROUND, HiSysEventType::BEHAVIOR, eventInfo); } @@ -433,13 +425,11 @@ void AppMgrServiceInner::ApplicationTerminated(const int32_t recordId) RemoveAppFromRecentListById(recordId); AAFWK::EventInfo eventInfo; auto applicationInfo = appRecord->GetApplicationInfo(); - eventInfo.pid = appRecord->GetPriorityObject()->GetPid(); + eventInfo.abilityName = appRecord->GetAbilityInfo()->name; eventInfo.bundleName = applicationInfo->name; eventInfo.versionName = applicationInfo->versionName; eventInfo.versionCode = applicationInfo->versionCode; - eventInfo.timeStamp = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()) - .count(); + eventInfo.processName = applicationInfo->process; AAFWK::EventReport::SendAppEvent(AAFWK::APP_TERMINATE, HiSysEventType::BEHAVIOR, eventInfo); DelayedSingleton::GetInstance()->OnProcessDied(appRecord); diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index f2625c90..fe87c9d2 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -35,7 +35,10 @@ ohos_source_set("abilitymgr_common") { config("perm_verification_config") { visibility = [ ":*" ] - include_dirs = [ "include" ] + include_dirs = [ + "include", + "${bundlefwk_inner_api_path}/appexecfwk_base/include", + ] cflags = [] if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] diff --git a/services/common/include/event_report.h b/services/common/include/event_report.h index 0fd3933f..48d61cdf 100644 --- a/services/common/include/event_report.h +++ b/services/common/include/event_report.h @@ -21,6 +21,7 @@ #include "errors.h" #include "hisysevent.h" +#include "extension_ability_info.h" using HiSysEventType = OHOS::HiviewDFX::HiSysEvent::EventType; using HiSysEvent = OHOS::HiviewDFX::HiSysEvent; @@ -42,8 +43,8 @@ const std::string CLOSE_ABILITY = "CLOSE_ABILITY"; const std::string DO_FOREGROUND_ABILITY = "DO_FOREGROUND_ABILITY"; const std::string DO_BACKGROUND_ABILITY = "DO_BACKGROUND_ABILITY"; // serviceExtensionAbility behavior event -const std::string START_SERVICE_EXTENSION = "START_SERVICE_EXTENSION"; -const std::string STOP_SERVICE_EXTENSION = "STOP_SERVICE_EXTENSION"; +const std::string START_SERVICE = "START_SERVICE"; +const std::string STOP_SERVICE = "STOP_SERVICE"; const std::string CONNECT_SERVICE = "CONNECT_SERVICE"; const std::string DISCONNECT_SERVICE = "DISCONNECT_SERVICE"; // form behavior event @@ -66,9 +67,7 @@ const std::string APP_TERMINATE = "APP_TERMINATE"; } struct EventInfo { - int32_t pid = -1; int32_t userId = -1; - int64_t timeStamp = 0; int64_t formId = -1; uint32_t versionCode = 0; uint32_t sceneFlag = -1; @@ -76,16 +75,15 @@ struct EventInfo { std::string bundleName; std::string moduleName; std::string abilityName; - std::string extensionType; + std::string processName; + AppExecFwk::ExtensionAbilityType extensionType; // olny used in fault event ErrCode errCode = ERR_OK; void Reset() { - pid =-1; userId = -1; - timeStamp = 0; formId =-1; versionCode = 0; sceneFlag = -1; @@ -93,7 +91,8 @@ struct EventInfo { bundleName.clear(); moduleName.clear(); abilityName.clear(); - extensionType.clear(); + processName.clear(); + extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED; errCode = ERR_OK; } }; diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index 7e5ac6b9..a51e971e 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -14,7 +14,6 @@ */ #include "event_report.h" -#include "hisysevent.h" #include "hilog_wrapper.h" #include @@ -27,7 +26,6 @@ const std::string TYPE = "TYPE"; const std::string EVENT_KEY_PID = "PID"; const std::string EVENT_KEY_USERID = "USERID"; const std::string EVENT_KEY_FORM_ID = "FORM_ID"; -const std::string EVENT_KEY_TIME_STAMP = "TIME_STAMP"; const std::string EVENT_KEY_ERROR_CODE = "ERROR_CODE"; const std::string EVENT_KEY_SCENE_FLAG = "SCENE_FLAG"; const std::string EVENT_KEY_BUNDLE_NAME = "BUNDLE_NAME"; @@ -35,6 +33,7 @@ const std::string EVENT_KEY_MODULE_NAME = "MODULE_NAME"; const std::string EVENT_KEY_ABILITY_NAME = "ABILITY_NAME"; const std::string EVENT_KEY_VERSION_NAME = "VERSION_NAME"; const std::string EVENT_KEY_VERSION_CODE = "VERSION_CODE"; +const std::string EVENT_KEY_PROCESS_NAME = "PROCESS_NAME"; const std::string EVENT_KEY_EXTENSION_TYPE = "EXTENSION_TYPE"; } @@ -48,8 +47,8 @@ void EventReport::SendAppEvent(const std::string &eventName, HiSysEventType type EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName, EVENT_KEY_VERSION_NAME, eventInfo.versionName, EVENT_KEY_VERSION_CODE, eventInfo.versionCode, - EVENT_KEY_PID, eventInfo.pid, - EVENT_KEY_TIME_STAMP, eventInfo.timeStamp); + EVENT_KEY_ABILITY_NAME, eventInfo.abilityName, + EVENT_KEY_PROCESS_NAME, eventInfo.processName); } void EventReport::SendAbilityEvent(const std::string &eventName, HiSysEventType type, @@ -96,7 +95,7 @@ void EventReport::SendExtensionEvent(const std::string &eventName, HiSysEventTyp HiSysEvent::Domain::AAFWK, eventName, type); - } else if (eventName ==CONNECT_SERVICE) { + } else if (eventName == CONNECT_SERVICE) { HiSysEvent::Write( HiSysEvent::Domain::AAFWK, eventName, @@ -105,7 +104,7 @@ void EventReport::SendExtensionEvent(const std::string &eventName, HiSysEventTyp EVENT_KEY_BUNDLE_NAME, eventInfo.bundleName, EVENT_KEY_MODULE_NAME, eventInfo.moduleName, EVENT_KEY_ABILITY_NAME, eventInfo.abilityName); - } else if (eventName == START_SERVICE_EXTENSION || eventName == STOP_SERVICE_EXTENSION) { + } else if (eventName == START_SERVICE || eventName == STOP_SERVICE) { HiSysEvent::Write( HiSysEvent::Domain::AAFWK, eventName,