!1292 【SR000H04KJ】【DFX打点】HiSysEvent系统事件

Merge pull request !1292 from dujingcheng/hisysevent
This commit is contained in:
openharmony_ci 2022-04-25 02:06:59 +00:00 committed by Gitee
commit 0a150cb169
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
31 changed files with 1060 additions and 4 deletions

View File

@ -31,6 +31,7 @@ declare_args() {
device_manager_enable = true
global_resmgr_enable = true
hicollie_enable = true
hisysevent_enable = true
if (defined(global_parts_info) &&
!defined(global_parts_info.aafwk_ability_runtime)) {
@ -71,6 +72,11 @@ declare_args() {
bundle_framework_free_install = false
}
if (defined(global_parts_info) &&
!defined(global_parts_info.hiviewdfx_hisysevent_native)) {
hisysevent_enable = false
}
print("bundle_framework_graphics = " + "$bundle_framework_graphics")
print("bundle_framework_free_install = " + "$bundle_framework_free_install")
print("ability_runtime_enable = " + "$ability_runtime_enable")
@ -80,4 +86,5 @@ declare_args() {
print("global_resmgr_enable = " + "$global_resmgr_enable")
print("hicollie_enable = " + "$hicollie_enable")
print("support_jsapi = " + "$support_jsapi")
print("hisysevent_enable = " + "$hisysevent_enable")
}

View File

@ -17,6 +17,9 @@
"bundle_framework_graphics",
"bundle_framework_free_install"
],
"hisysevent_config": [
"//foundation/appexecfwk/standard/hisysevent.yaml"
],
"adapted_system_type": [
"standard"
],
@ -34,6 +37,7 @@
"device_manager_base",
"distributeddatamgr",
"eventhandler",
"hisysevent_native",
"hiviewdfx_hilog_native",
"init",
"ipc",

117
hisysevent.yaml Normal file
View File

@ -0,0 +1,117 @@
# Copyright (c) 2022-2022 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
domain: APPEXECFWK
################################################################################
# FAULT EVENT #
################################################################################
BUNDLE_INSTALL_EXCEPTION:
__BASE: {type: FAULT, level: MINOR, desc: used to fault happened when bundle install}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: normal prebundle or freeInstall}
SCENE: {type: STRING, desc: boot reboot or createUser}
ERROR_CODE: {type: INT32, desc: error code}
BUNDLE_UNINSTALL_EXCEPTION:
__BASE: {type: FAULT, level: MINOR, desc: used to fault happened when bundle uninstall}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: normal prebundle or freeInstall}
ERROR_CODE: {type: INT32, desc: error code}
BUNDLE_UPDATE_EXCEPTION:
__BASE: {type: FAULT, level: MINOR, desc: used to fault happened when bundle update}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: normal prebundle or freeInstall}
ERROR_CODE: {type: INT32, desc: error code}
PRE_BUNDLE_RECOVER_EXCEPTION:
__BASE: {type: FAULT, level: MINOR, desc: used to fault happened when prebundle recover}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: only prebundle}
ERROR_CODE: {type: INT32, desc: error code}
BUNDLE_STATE_CHANGE_EXCEPTION:
__BASE: {type: FAULT, level: MINOR, desc: used to fault happened when state change}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
ABILITY_NAME: {type: STRING, desc: abilityName}
TYPE: {type: STRING, desc: application or ability}
BUNDLE_CLEAN_CACHE_EXCEPTION:
__BASE: {type: FAULT, level: MINOR, desc: used to fault happened when clean cache or clean data}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
CLEAN_TYPE: {type: STRING, desc: clean cache or clean data}
################################################################################
# BEHAVIOR EVENT #
################################################################################
BOOT_SCAN_START:
__BASE: {type: BEHAVIOR, level: MINOR, desc: boot scan start}
TIME: {type: INT64, desc: time stamp}
BOOT_SCAN_END:
__BASE: {type: BEHAVIOR, level: MINOR, desc: boot scan end}
TIME: {type: INT64, desc: time stamp}
BUNDLE_INSTALL:
__BASE: {type: BEHAVIOR, level: MINOR, desc: bundle install}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: normal prebundle or freeInstall}
SCENE: {type: STRING, desc: boot reboot or createUser}
BUNDLE_UNINSTALL:
__BASE: {type: BEHAVIOR, level: MINOR, desc: bundle uninstall}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: normal prebundle or freeInstall}
BUNDLE_UPDATE:
__BASE: {type: BEHAVIOR, level: MINOR, desc: bundle update}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: normal prebundle or freeInstall}
PRE_BUNDLE_RECOVER:
__BASE: {type: BEHAVIOR, level: MINOR, desc: prebundle recover}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
VERSION: {type: UINT32, desc: versionCode}
INSTALL_TYPE: {type: STRING, desc: only prebundle}
BUNDLE_COMPONENT_STATE_CHANGE:
__BASE: {type: BEHAVIOR, level: MINOR, desc: bundle or component disable or enable}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
ABILITY_NAME: {type: STRING, desc: abilityName}
TYPE: {type: STRING, desc: application or ability}
STATE: {type: STRING, desc: isEnable}
BUNDLE_CLEAN_CACHE:
__BASE: {type: BEHAVIOR, level: MINOR, desc: bundle clean cache}
USERID: {type: INT32, desc: userId}
BUNDLE_NAME: {type: STRING, desc: bundleName}
CLEAN_TYPE: {type: STRING, desc: clean cache or clean data}

View File

@ -241,6 +241,12 @@ ohos_shared_library("libbms") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
if (use_pre_bundle_profile) {
defines += [ "USE_PRE_BUNDLE_PROFILE" ]
}

View File

@ -32,6 +32,7 @@ bundle_install_sources = [
"${services_path}/bundlemgr/src/bundle_permission_mgr.cpp",
"${services_path}/bundlemgr/src/bundle_util.cpp",
"${services_path}/bundlemgr/src/bundle_verify_mgr.cpp",
"${services_path}/bundlemgr/src/event_report.cpp",
"${services_path}/bundlemgr/src/inner_bundle_info.cpp",
"${services_path}/bundlemgr/src/inner_bundle_user_info.cpp",
"${services_path}/bundlemgr/src/installd_client.cpp",

View File

@ -26,6 +26,7 @@
#include "bundle_data_mgr.h"
#include "bundle_pack_info.h"
#include "bundle_verify_mgr.h"
#include "event_report.h"
#include "inner_bundle_info.h"
#include "install_param.h"
@ -138,6 +139,15 @@ protected:
* @brief Reset install properties.
*/
void ResetInstallProperties();
/**
* @brief Reset install properties.
* @param isBootScene Indicates the event occurs in the boot phase.
*/
void MarkPreBundleSyeEventBootTag(bool isBootScene)
{
sysEventInfo_.preBundleScene =
isBootScene ? InstallScene::BOOT : InstallScene::REBOOT;
}
private:
/**
@ -465,6 +475,8 @@ private:
void OnSingletonChange();
ErrCode UninstallAllSandboxApps(const std::string &bundleName);
ErrCode CheckAppLabel(const InnerBundleInfo &oldInfo, const InnerBundleInfo &newInfo) const;
void SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType,
const InstallParam &installParam, InstallScene preBundleScene, ErrCode errCode);
InstallerState state_ = InstallerState::INSTALL_START;
std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; // this pointer will get when public functions called
@ -487,6 +499,8 @@ private:
int32_t userId_ = Constants::INVALID_USERID;
bool hasInstalledInUser_ = false;
SingletonState singletonState_ = SingletonState::DEFAULT;
// used to record system event infos
EventInfo sysEventInfo_;
DISALLOW_COPY_AND_MOVE(BaseBundleInstaller);

View File

@ -0,0 +1,151 @@
/*
* Copyright (c) 2022-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H
#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H
#include <string>
#include "appexecfwk_errors.h"
#include "bundle_constants.h"
namespace OHOS {
namespace AppExecFwk {
enum class BMSEventType {
UNKNOW = 0,
/***********FAULT EVENT**************/
BUNDLE_INSTALL_EXCEPTION,
BUNDLE_UNINSTALL_EXCEPTION,
BUNDLE_UPDATE_EXCEPTION,
PRE_BUNDLE_RECOVER_EXCEPTION,
BUNDLE_STATE_CHANGE_EXCEPTION,
BUNDLE_CLEAN_CACHE_EXCEPTION,
/***********BEHAVIOR EVENT***********/
BOOT_SCAN_START,
BOOT_SCAN_END,
BUNDLE_INSTALL,
BUNDLE_UNINSTALL,
BUNDLE_UPDATE,
PRE_BUNDLE_RECOVER,
BUNDLE_COMPONENT_STATE_CHANGE,
BUNDLE_CLEAN_CACHE,
};
enum class BundleEventType {
UNKNOW = 0,
INSTALL,
UNINSTALL,
UPDATE,
RECOVER,
};
enum class InstallScene {
NORMAL = 0,
BOOT,
REBOOT,
CREATE_USER,
REMOVE_USER,
};
enum HiSysEventType {
FAULT = 1, // system fault event
STATISTIC = 2, // system statistic event
SECURITY = 3, // system security event
BEHAVIOR = 4 // system behavior event
};
struct EventInfo {
int32_t userId = Constants::INVALID_USERID;
std::string bundleName;
std::string moduleName;
std::string abilityName;
int64_t timeStamp = 0;
uint32_t versionCode = 0;
// olny used for preBundle
bool isPreInstallApp = false;
InstallScene preBundleScene = InstallScene::NORMAL;
// olny used for clean cache
bool isCleanCache = true;
// olny used for component diable or enable
bool isEnable = false;
// olny used for free install
bool isFreeInstallMode = false;
// olny used in fault event
ErrCode errCode = ERR_OK;
void Reset()
{
userId = Constants::INVALID_USERID;
bundleName.clear();
moduleName.clear();
abilityName.clear();
versionCode = 0;
timeStamp = 0;
preBundleScene = InstallScene::NORMAL;
isCleanCache = false;
isPreInstallApp = false;
isFreeInstallMode = false;
isEnable = false;
errCode = ERR_OK;
}
};
class EventReport {
public:
/**
* @brief Send bundle system events.
* @param bundleEventType Indicates the bundle eventType.
* @param eventInfo Indicates the eventInfo.
*/
static void SendBundleSystemEvent(BundleEventType bundleEventType, const EventInfo& eventInfo);
/**
* @brief Send scan system events.
* @param bMSEventType Indicates the bMSEventType.
*/
static void SendScanSysEvent(BMSEventType bMSEventType);
/**
* @brief Send component diable or enable system events.
* @param bundleName Indicates the bundleName.
* @param abilityName Indicates the abilityName.
* @param userId Indicates the userId.
* @param isEnable Indicates the isEnable.
* @param exception Indicates the exception.
*/
static void SendComponentStateSysEvent(const std::string &bundleName,
const std::string &abilityName, int32_t userId, bool isEnable, bool exception);
/**
* @brief Send clean cache system events.
* @param bundleName Indicates the bundleName.
* @param userId Indicates the userId.
* @param isCleanCache Indicates the isCleanCache.
* @param exception Indicates the exception.
*/
static void SendCleanCacheSysEvent(
const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception);
/**
* @brief Send system events.
* @param eventType Indicates the bms eventInfo.
* @param eventInfo Indicates the eventInfo.
*/
static void SendSystemEvent(BMSEventType eventType, const EventInfo& eventInfo);
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2022-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_EVENT_REPORT_H
#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_EVENT_REPORT_H
#include <unordered_map>
#include "event_report.h"
namespace OHOS {
namespace AppExecFwk {
class InnerEventReport {
public:
/**
* @brief Send system events.
* @param eventType Indicates the bms eventInfo.
* @param eventInfo Indicates the eventInfo.
*/
static void SendSystemEvent(BMSEventType eventType, const EventInfo& eventInfo);
private:
// fault event
static void InnerSendBundleInstallExceptionEvent(const EventInfo& eventInfo);
static void InnerSendBundleUninstallExceptionEvent(const EventInfo& eventInfo);
static void InnerSendBundleUpdateExceptionEvent(const EventInfo& eventInfo);
static void InnerSendPreBundleRecoverExceptionEvent(const EventInfo& eventInfo);
static void InnerSendBundleComponentChangeExceptionEvent(const EventInfo& eventInfo);
static void InnerSendBundleCleanCacheExceptionEvent(const EventInfo& eventInfo);
// behavior event
static void InnerSendBootScanStartEvent(const EventInfo& eventInfo);
static void InnerSendBootScanEndEvent(const EventInfo& eventInfo);
static void InnerSendBundleInstallEvent(const EventInfo& eventInfo);
static void InnerSendBundleUninstallEvent(const EventInfo& eventInfo);
static void InnerSendBundleUpdateEvent(const EventInfo& eventInfo);
static void InnerSendPreBundleRecoverEvent(const EventInfo& eventInfo);
static void InnerSendBundleComponentChangeEvent(const EventInfo& eventInfo);
static void InnerSendBundleCleanCacheEvent(const EventInfo& eventInfo);
template<typename... Types>
static void InnerEventWrite(const std::string &eventName,
HiSysEventType type, Types... keyValues);
static std::unordered_map<BMSEventType, void (*)(const EventInfo& eventInfo)> bmsSysEventMap_;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_INNER_EVENT_REPORT_H

View File

@ -84,6 +84,7 @@ bool RecentlyUnuseBundleAgingHandler::UnInstallBundle(const std::string &bundleN
sptr<AgingUninstallReceiveImpl> userReceiverImpl(new (std::nothrow) AgingUninstallReceiveImpl());
InstallParam installParam;
installParam.userId = AccountHelper::GetCurrentActiveUserId();
installParam.installFlag = InstallFlag::FREE_INSTALL;
bundleInstaller->Uninstall(bundleName, installParam, userReceiverImpl);
return true;
}

View File

@ -78,10 +78,17 @@ ErrCode BaseBundleInstaller::InstallBundle(
isAppExist_ ? NotifyType::UPDATE : NotifyType::INSTALL,
uid);
}
if (result == ERR_OK) {
DistributedDataStorage::GetInstance()->SaveStorageDistributeInfo(bundleName_, userId_);
}
SendBundleSystemEvent(
bundleName_,
(isAppExist_ ? BundleEventType::UPDATE : BundleEventType::INSTALL),
installParam,
sysEventInfo_.preBundleScene,
result);
PerfProfile::GetInstance().SetBundleInstallEndTime(GetTickCount());
APP_LOGD("finish to process bundle install");
return result;
@ -104,6 +111,12 @@ ErrCode BaseBundleInstaller::InstallBundleByBundleName(
DistributedDataStorage::GetInstance()->SaveStorageDistributeInfo(bundleName, userId_);
}
SendBundleSystemEvent(
bundleName,
BundleEventType::INSTALL,
installParam,
InstallScene::CREATE_USER,
result);
PerfProfile::GetInstance().SetBundleInstallEndTime(GetTickCount());
APP_LOGD("finish to process %{public}s bundle install", bundleName.c_str());
return result;
@ -126,6 +139,14 @@ ErrCode BaseBundleInstaller::Recover(
DistributedDataStorage::GetInstance()->SaveStorageDistributeInfo(bundleName, userId_);
}
auto recoverInstallParam = installParam;
recoverInstallParam.isPreInstallApp = true;
SendBundleSystemEvent(
bundleName,
BundleEventType::RECOVER,
recoverInstallParam,
sysEventInfo_.preBundleScene,
result);
PerfProfile::GetInstance().SetBundleInstallEndTime(GetTickCount());
APP_LOGD("finish to process %{public}s bundle recover", bundleName.c_str());
return result;
@ -145,10 +166,17 @@ ErrCode BaseBundleInstaller::UninstallBundle(const std::string &bundleName, cons
dataMgr_->NotifyBundleStatus(
bundleName, Constants::EMPTY_STRING, Constants::EMPTY_STRING, result, NotifyType::UNINSTALL_BUNDLE, uid);
}
if (result == ERR_OK) {
DistributedDataStorage::GetInstance()->DeleteStorageDistributeInfo(bundleName, userId_);
}
SendBundleSystemEvent(
bundleName,
BundleEventType::UNINSTALL,
installParam,
sysEventInfo_.preBundleScene,
result);
PerfProfile::GetInstance().SetBundleUninstallEndTime(GetTickCount());
APP_LOGD("finish to process %{public}s bundle uninstall", bundleName.c_str());
return result;
@ -170,9 +198,6 @@ ErrCode BaseBundleInstaller::UninstallBundle(
bundleName, modulePackage, Constants::EMPTY_STRING, result, NotifyType::UNINSTALL_MODULE, uid);
}
PerfProfile::GetInstance().SetBundleUninstallEndTime(GetTickCount());
APP_LOGD("finish to process %{public}s module in %{public}s uninstall", modulePackage.c_str(), bundleName.c_str());
if (result == ERR_OK) {
InnerBundleInfo innerBundleInfo;
if (!dataMgr_->GetInnerBundleInfo(bundleName, innerBundleInfo)) {
@ -182,6 +207,15 @@ ErrCode BaseBundleInstaller::UninstallBundle(
dataMgr_->EnableBundle(bundleName);
}
}
SendBundleSystemEvent(
bundleName,
BundleEventType::UNINSTALL,
installParam,
sysEventInfo_.preBundleScene,
result);
PerfProfile::GetInstance().SetBundleUninstallEndTime(GetTickCount());
APP_LOGD("finish to process %{public}s module in %{public}s uninstall", modulePackage.c_str(), bundleName.c_str());
return result;
}
@ -617,6 +651,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall(
return ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_BUNDLE;
}
versionCode_ = oldInfo.GetVersionCode();
ScopeGuard enableGuard([&] { dataMgr_->EnableBundle(bundleName); });
InnerBundleUserInfo curInnerBundleUserInfo;
if (!oldInfo.GetInnerBundleUserInfo(userId_, curInnerBundleUserInfo)) {
@ -710,6 +745,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall(
return ERR_APPEXECFWK_UNINSTALL_MISSING_INSTALLED_BUNDLE;
}
versionCode_ = oldInfo.GetVersionCode();
ScopeGuard enableGuard([&] { dataMgr_->EnableBundle(bundleName); });
InnerBundleUserInfo curInnerBundleUserInfo;
if (!oldInfo.GetInnerBundleUserInfo(userId_, curInnerBundleUserInfo)) {
@ -838,6 +874,7 @@ ErrCode BaseBundleInstaller::InnerProcessInstallByPreInstallInfo(
bool isAppExist = dataMgr_->GetInnerBundleInfo(bundleName, oldInfo);
if (isAppExist) {
dataMgr_->EnableBundle(bundleName);
versionCode_ = oldInfo.GetVersionCode();
if (oldInfo.HasInnerBundleUserInfo(userId_)) {
APP_LOGE("App is exist in user(%{public}d).", userId_);
return ERR_APPEXECFWK_INSTALL_ALREADY_EXIST;
@ -1977,6 +2014,7 @@ void BaseBundleInstaller::ResetInstallProperties()
installedModules_.clear();
state_ = InstallerState::INSTALL_START;
singletonState_ = SingletonState::DEFAULT;
sysEventInfo_.Reset();
}
void BaseBundleInstaller::OnSingletonChange()
@ -2016,5 +2054,18 @@ void BaseBundleInstaller::OnSingletonChange()
}
}
}
void BaseBundleInstaller::SendBundleSystemEvent(const std::string &bundleName, BundleEventType bundleEventType,
const InstallParam &installParam, InstallScene preBundleScene, ErrCode errCode)
{
sysEventInfo_.bundleName = bundleName;
sysEventInfo_.isPreInstallApp = installParam.isPreInstallApp;
sysEventInfo_.errCode = errCode;
sysEventInfo_.isFreeInstallMode = (installParam.installFlag == InstallFlag::FREE_INSTALL);
sysEventInfo_.userId = userId_;
sysEventInfo_.versionCode = versionCode_;
sysEventInfo_.preBundleScene = preBundleScene;
EventReport::SendBundleSystemEvent(bundleEventType, sysEventInfo_);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -534,34 +534,47 @@ bool BundleMgrHostImpl::CleanBundleCacheFiles(
if (userId == Constants::UNSPECIFIED_USERID) {
userId = BundleUtil::GetUserIdByCallingUid();
}
APP_LOGD("start CleanBundleCacheFiles, bundleName : %{public}s, userId : %{public}d", bundleName.c_str(), userId);
if (userId < 0) {
APP_LOGE("userId is invalid");
EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true);
return false;
}
if (bundleName.empty() || !cleanCacheCallback) {
APP_LOGE("the cleanCacheCallback is nullptr or bundleName empty");
EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true);
return false;
}
if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERNISSION_REMOVECACHEFILE)) {
APP_LOGE("ohos.permission.REMOVE_CACHE_FILES permission denied");
EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true);
return false;
}
ApplicationInfo applicationInfo;
auto dataMgr = GetDataMgrFromService();
if (dataMgr == nullptr) {
APP_LOGE("DataMgr is nullptr");
EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true);
return false;
}
if (!dataMgr->GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO,
userId, applicationInfo)) {
APP_LOGE("can not get application info of %{public}s", bundleName.c_str());
EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true);
return false;
}
if (applicationInfo.isSystemApp && !applicationInfo.userDataClearable) {
APP_LOGE("can not clean cacheFiles of %{public}s due to userDataClearable is false", bundleName.c_str());
EventReport::SendCleanCacheSysEvent(bundleName, userId, true, true);
return false;
}
CleanBundleCacheTask(bundleName, cleanCacheCallback, userId);
return true;
}
@ -576,7 +589,8 @@ void BundleMgrHostImpl::CleanBundleCacheTask(const std::string &bundleName,
Constants::FILE_SEPARATOR_CHAR + std::to_string(userId) + Constants::BASE + bundleName;
rootDir.emplace_back(dataDir);
}
auto cleanCache = [rootDir, cleanCacheCallback]() {
auto cleanCache = [bundleName, userId, rootDir, cleanCacheCallback]() {
std::vector<std::string> caches;
for (const auto &st : rootDir) {
std::vector<std::string> cache;
@ -587,6 +601,7 @@ void BundleMgrHostImpl::CleanBundleCacheTask(const std::string &bundleName,
caches.emplace_back(item);
}
}
bool error = false;
if (!caches.empty()) {
for (const auto& cache : caches) {
@ -596,6 +611,8 @@ void BundleMgrHostImpl::CleanBundleCacheTask(const std::string &bundleName,
}
}
}
EventReport::SendCleanCacheSysEvent(bundleName, userId, true, error);
APP_LOGD("CleanBundleCacheFiles with error %{public}d", error);
cleanCacheCallback->OnCleanCacheFinished(error);
};
@ -607,35 +624,50 @@ bool BundleMgrHostImpl::CleanBundleDataFiles(const std::string &bundleName, cons
APP_LOGD("start CleanBundleDataFiles, bundleName : %{public}s, userId : %{public}d", bundleName.c_str(), userId);
if (bundleName.empty() || userId < 0) {
APP_LOGE("the bundleName empty or invalid userid");
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, true);
return false;
}
ApplicationInfo applicationInfo;
if (!GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, applicationInfo)) {
APP_LOGE("can not get application info of %{public}s", bundleName.c_str());
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, true);
return false;
}
if (applicationInfo.isSystemApp && !applicationInfo.userDataClearable) {
APP_LOGE("can not clean dataFiles of %{public}s due to userDataClearable is false", bundleName.c_str());
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, true);
return false;
}
InnerBundleUserInfo innerBundleUserInfo;
if (!GetBundleUserInfo(bundleName, userId, innerBundleUserInfo)) {
APP_LOGE("%{public}s, userId:%{public}d, GetBundleUserInfo failed", bundleName.c_str(), userId);
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, true);
return false;
}
if (BundlePermissionMgr::ClearUserGrantedPermissionState(applicationInfo.accessTokenId)) {
APP_LOGE("%{public}s, ClearUserGrantedPermissionState failed", bundleName.c_str());
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, true);
return false;
}
if (InstalldClient::GetInstance()->RemoveBundleDataDir(bundleName, userId) != ERR_OK) {
APP_LOGE("%{public}s, RemoveBundleDataDir failed", bundleName.c_str());
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, true);
return false;
}
if (InstalldClient::GetInstance()->CreateBundleDataDir(bundleName, userId, innerBundleUserInfo.uid,
innerBundleUserInfo.uid, GetAppPrivilegeLevel(bundleName))) {
APP_LOGE("%{public}s, CreateBundleDataDir failed", bundleName.c_str());
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, true);
return false;
}
EventReport::SendCleanCacheSysEvent(bundleName, userId, false, false);
return true;
}
@ -934,20 +966,24 @@ bool BundleMgrHostImpl::SetApplicationEnabled(const std::string &bundleName, boo
APP_LOGD("SetApplicationEnabled begin");
if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_CHANGE_ABILITY_ENABLED_STATE)) {
APP_LOGE("verify permission failed");
EventReport::SendComponentStateSysEvent(bundleName, "", userId, isEnable, true);
return false;
}
APP_LOGD("verify permission success, bgein to SetApplicationEnabled");
auto dataMgr = GetDataMgrFromService();
if (dataMgr == nullptr) {
APP_LOGE("DataMgr is nullptr");
EventReport::SendComponentStateSysEvent(bundleName, "", userId, isEnable, true);
return false;
}
if (!dataMgr->SetApplicationEnabled(bundleName, isEnable, userId)) {
APP_LOGE("Set application(%{public}s) enabled value faile.", bundleName.c_str());
EventReport::SendComponentStateSysEvent(bundleName, "", userId, isEnable, true);
return false;
}
EventReport::SendComponentStateSysEvent(bundleName, "", userId, isEnable, false);
InnerBundleUserInfo innerBundleUserInfo;
if (!GetBundleUserInfo(bundleName, userId, innerBundleUserInfo)) {
APP_LOGE("Get calling userInfo in bundle(%{public}s) failed", bundleName.c_str());
@ -980,20 +1016,29 @@ bool BundleMgrHostImpl::SetAbilityEnabled(const AbilityInfo &abilityInfo, bool i
APP_LOGD("start SetAbilityEnabled");
if (!BundlePermissionMgr::VerifyCallingPermission(Constants::PERMISSION_CHANGE_ABILITY_ENABLED_STATE)) {
APP_LOGE("verify permission failed");
EventReport::SendComponentStateSysEvent(
abilityInfo.bundleName, abilityInfo.name, userId, isEnabled, true);
return false;
}
APP_LOGD("verify permission success, bgein to SetAbilityEnabled");
auto dataMgr = GetDataMgrFromService();
if (dataMgr == nullptr) {
APP_LOGE("DataMgr is nullptr");
EventReport::SendComponentStateSysEvent(
abilityInfo.bundleName, abilityInfo.name, userId, isEnabled, true);
return false;
}
if (!dataMgr->SetAbilityEnabled(abilityInfo, isEnabled, userId)) {
APP_LOGE("Set ability(%{public}s) enabled value failed.", abilityInfo.bundleName.c_str());
EventReport::SendComponentStateSysEvent(
abilityInfo.bundleName, abilityInfo.name, userId, isEnabled, true);
return false;
}
EventReport::SendComponentStateSysEvent(
abilityInfo.bundleName, abilityInfo.name, userId, isEnabled, false);
InnerBundleUserInfo innerBundleUserInfo;
if (!GetBundleUserInfo(abilityInfo.bundleName, userId, innerBundleUserInfo)) {
APP_LOGE("Get calling userInfo in bundle(%{public}s) failed", abilityInfo.bundleName.c_str());

View File

@ -24,6 +24,7 @@
#ifdef CONFIG_POLOCY_ENABLE
#include "config_policy_utils.h"
#endif
#include "event_report.h"
#include "perf_profile.h"
#include "system_bundle_installer.h"
@ -82,12 +83,14 @@ void BMSEventHandler::ProcessEvent(const InnerEvent::Pointer &event)
void BMSEventHandler::OnBootStartScanning(int32_t userId)
{
EventReport::SendScanSysEvent(BMSEventType::BOOT_SCAN_START);
#ifdef USE_PRE_BUNDLE_PROFILE
ProcessBootBundleInstallFromPreBundleProFile(userId);
#else
ProcessBootBundleInstallFromScan(userId);
#endif
PerfProfile::GetInstance().Dump();
EventReport::SendScanSysEvent(BMSEventType::BOOT_SCAN_END);
}
void BMSEventHandler::ProcessBootBundleInstallFromScan(int32_t userId)
@ -266,7 +269,9 @@ void BMSEventHandler::SetAllInstallFlag() const
void BMSEventHandler::OnRebootStartScanning(int32_t userId)
{
EventReport::SendScanSysEvent(BMSEventType::BOOT_SCAN_START);
ProcessRebootBundle(userId);
EventReport::SendScanSysEvent(BMSEventType::BOOT_SCAN_END);
}
void BMSEventHandler::ProcessRebootBundle(int32_t userId)

View File

@ -142,6 +142,7 @@ void BundleUserMgrHostImpl::RemoveUser(int32_t userId)
InstallParam installParam;
installParam.userId = userId;
installParam.forceExecuted = true;
installParam.isPreInstallApp = true;
installParam.installFlag = InstallFlag::NORMAL;
sptr<UserReceiverImpl> userReceiverImpl(new UserReceiverImpl());
userReceiverImpl->SetBundlePromise(bundlePromise);

View File

@ -0,0 +1,117 @@
/*
* Copyright (c) 2022-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "event_report.h"
#include <unordered_map>
#include "app_log_wrapper.h"
#include "bundle_util.h"
#ifdef HISYSEVENT_ENABLE
#include "inner_event_report.h"
#endif
namespace OHOS {
namespace AppExecFwk {
namespace {
const std::unordered_map<BundleEventType, BMSEventType> BUNDLE_EXCEPTION_SYS_EVENT_MAP = {
{ BundleEventType::INSTALL, BMSEventType::BUNDLE_INSTALL_EXCEPTION },
{ BundleEventType::UNINSTALL, BMSEventType::BUNDLE_UNINSTALL_EXCEPTION },
{ BundleEventType::UPDATE, BMSEventType::BUNDLE_UPDATE_EXCEPTION },
{ BundleEventType::RECOVER, BMSEventType::PRE_BUNDLE_RECOVER_EXCEPTION },
};
const std::unordered_map<BundleEventType, BMSEventType> BUNDLE_SYS_EVENT_MAP = {
{ BundleEventType::INSTALL, BMSEventType::BUNDLE_INSTALL },
{ BundleEventType::UNINSTALL, BMSEventType::BUNDLE_UNINSTALL },
{ BundleEventType::UPDATE, BMSEventType::BUNDLE_UPDATE },
{ BundleEventType::RECOVER, BMSEventType::PRE_BUNDLE_RECOVER },
};
}
void EventReport::SendBundleSystemEvent(BundleEventType bundleEventType, const EventInfo& eventInfo)
{
BMSEventType bmsEventType = BMSEventType::UNKNOW;
std::unordered_map<BundleEventType, BMSEventType>::const_iterator iter;
if (eventInfo.errCode != ERR_OK) {
iter = BUNDLE_EXCEPTION_SYS_EVENT_MAP.find(bundleEventType);
if (iter != BUNDLE_EXCEPTION_SYS_EVENT_MAP.end()) {
bmsEventType = iter->second;
}
SendSystemEvent(bmsEventType, eventInfo);
return;
}
iter = BUNDLE_SYS_EVENT_MAP.find(bundleEventType);
if (iter != BUNDLE_SYS_EVENT_MAP.end()) {
bmsEventType = iter->second;
}
SendSystemEvent(bmsEventType, eventInfo);
}
void EventReport::SendScanSysEvent(BMSEventType bMSEventType)
{
EventInfo eventInfo;
eventInfo.timeStamp = BundleUtil::GetCurrentTime();
EventReport::SendSystemEvent(bMSEventType, eventInfo);
}
void EventReport::SendComponentStateSysEvent(const std::string &bundleName,
const std::string &abilityName, int32_t userId, bool isEnable, bool exception)
{
EventInfo eventInfo;
eventInfo.bundleName = bundleName;
eventInfo.abilityName = abilityName;
eventInfo.userId = userId;
eventInfo.isEnable = isEnable;
BMSEventType bmsEventType;
if (exception) {
bmsEventType = BMSEventType::BUNDLE_STATE_CHANGE_EXCEPTION;
} else {
bmsEventType = BMSEventType::BUNDLE_COMPONENT_STATE_CHANGE;
}
EventReport::SendSystemEvent(bmsEventType, eventInfo);
}
void EventReport::SendCleanCacheSysEvent(
const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception)
{
EventInfo eventInfo;
eventInfo.bundleName = bundleName;
eventInfo.userId = userId;
eventInfo.isCleanCache = isCleanCache;
BMSEventType bmsEventType;
if (exception) {
bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE_EXCEPTION;
} else {
bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE;
}
EventReport::SendSystemEvent(bmsEventType, eventInfo);
}
void EventReport::SendSystemEvent(BMSEventType bmsEventType, const EventInfo& eventInfo)
{
#ifdef HISYSEVENT_ENABLE
InnerEventReport::SendSystemEvent(bmsEventType, eventInfo);
#else
APP_LOGD("Hisysevent is disabled");
#endif
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -28,6 +28,7 @@
namespace OHOS {
namespace AppExecFwk {
namespace {
const std::u16string ATOMIC_SERVICE_STATUS_CALLBACK_TOKEN = u"ohos.aafwk.IAtomicServiceStatusCallback";
const std::string serviceCenterBundleName = "com.ohos.hag.famanager";
const std::string serviceCenterAbilityName = "com.ohos.hag.famanager.HapInstallServiceAbility";
@ -46,6 +47,20 @@ constexpr uint32_t BIT_SIX = 32;
constexpr uint32_t BIT_SEVEN = 64;
constexpr uint32_t OUT_TIME = 30000;
void SendSysEvent(int32_t resultCode, const AAFwk::Want &want, int32_t userId)
{
EventInfo sysEventInfo;
ElementName element = want.GetElement();
sysEventInfo.bundleName = element.GetBundleName();
sysEventInfo.moduleName = want.GetStringParam("moduleName");
sysEventInfo.abilityName = element.GetAbilityName();
sysEventInfo.isFreeInstallMode = true;
sysEventInfo.userId = userId;
sysEventInfo.errCode = resultCode;
EventReport::SendSystemEvent(BMSEventType::BUNDLE_INSTALL_EXCEPTION, sysEventInfo);
}
}
BundleConnectAbilityMgr::BundleConnectAbilityMgr()
{
runner_ = EventRunner::Create(true);
@ -76,6 +91,7 @@ bool BundleConnectAbilityMgr::SilentInstallSafely(const TargetAbilityInfo &targe
if (handler_ == nullptr) {
SendCallBack(FreeInstallErrorCode::UNDEFINED_ERROR, want,
userId, targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::UNDEFINED_ERROR, want, userId);
APP_LOGE("handler is null");
return false;
}
@ -94,6 +110,7 @@ bool BundleConnectAbilityMgr::UpgradeCheckSafely(const TargetAbilityInfo &target
if (handler_ == nullptr) {
SendCallBack(FreeInstallErrorCode::UNDEFINED_ERROR, want,
userId, targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::UNDEFINED_ERROR, want, userId);
APP_LOGE("handler is null");
return false;
}
@ -112,6 +129,7 @@ bool BundleConnectAbilityMgr::UpgradeInstallSafely(const TargetAbilityInfo &targ
if (handler_ == nullptr) {
SendCallBack(FreeInstallErrorCode::UNDEFINED_ERROR, want,
userId, targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::UNDEFINED_ERROR, want, userId);
APP_LOGE("handler is null");
return false;
}
@ -135,6 +153,7 @@ bool BundleConnectAbilityMgr::CheckReusableConnection(int32_t flag,
APP_LOGE("Fail to connect ServiceCenter");
SendCallBack(FreeInstallErrorCode::CONNECT_ERROR, want,
userId, targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::CONNECT_ERROR, want, userId);
return false;
} else {
SendRequest(flag, targetAbilityInfo, want, userId);
@ -334,6 +353,7 @@ void BundleConnectAbilityMgr::SendRequest(
APP_LOGE("%{public}s failed to WriteParcelable targetAbilityInfo", __func__);
SendCallBack(FreeInstallErrorCode::UNDEFINED_ERROR, want, userId,
targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::UNDEFINED_ERROR, want, userId);
return;
}
sptr<ServiceCenterStatusCallback> serviceCenterCallback =
@ -346,6 +366,7 @@ void BundleConnectAbilityMgr::SendRequest(
APP_LOGE("%{public}s failed to WriteRemoteObject callbcak", __func__);
SendCallBack(FreeInstallErrorCode::UNDEFINED_ERROR, want, userId,
targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::UNDEFINED_ERROR, want, userId);
return;
}
APP_LOGI("ServiceCenterRemoteObject->SendRequest");
@ -354,6 +375,7 @@ void BundleConnectAbilityMgr::SendRequest(
APP_LOGE("%{public}s failed to get remote object", __func__);
SendCallBack(
FreeInstallErrorCode::CONNECT_ERROR, want, userId, targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::CONNECT_ERROR, want, userId);
return;
}
int32_t result = serviceCenterRemoteObject_->SendRequest(flag, data, reply, option);
@ -362,6 +384,7 @@ void BundleConnectAbilityMgr::SendRequest(
APP_LOGE("Failed to sendRequest, result = %{public}d", result);
SendCallBack(
FreeInstallErrorCode::CONNECT_ERROR, want, userId, targetAbilityInfo.targetInfo.transactId);
SendSysEvent(FreeInstallErrorCode::CONNECT_ERROR, want, userId);
return;
}
OutTimeMonitor(targetAbilityInfo.targetInfo.transactId);

View File

@ -0,0 +1,343 @@
/*
* Copyright (c) 2022-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "inner_event_report.h"
#include "app_log_wrapper.h"
#include "hisysevent.h"
namespace OHOS {
namespace AppExecFwk {
namespace {
// event type
const std::string BUNDLE_INSTALL_EXCEPTION = "BUNDLE_INSTALL_EXCEPTION";
const std::string BUNDLE_UNINSTALL_EXCEPTION = "BUNDLE_UNINSTALL_EXCEPTION";
const std::string BUNDLE_UPDATE_EXCEPTION = "BUNDLE_UPDATE_EXCEPTION";
const std::string PRE_BUNDLE_RECOVER_EXCEPTION = "PRE_BUNDLE_RECOVER_EXCEPTION";
const std::string BUNDLE_STATE_CHANGE_EXCEPTION = "BUNDLE_STATE_CHANGE_EXCEPTION";
const std::string BUNDLE_CLEAN_CACHE_EXCEPTION = "BUNDLE_CLEAN_CACHE_EXCEPTION";
const std::string BOOT_SCAN_START = "BOOT_SCAN_START";
const std::string BOOT_SCAN_END = "BOOT_SCAN_END";
const std::string BUNDLE_INSTALL = "BUNDLE_INSTALL";
const std::string BUNDLE_UNINSTALL = "BUNDLE_UNINSTALL";
const std::string BUNDLE_UPDATE = "BUNDLE_UPDATE";
const std::string PRE_BUNDLE_RECOVER = "PRE_BUNDLE_RECOVER";
const std::string BUNDLE_COMPONENT_STATE_CHANGE = "BUNDLE_COMPONENT_STATE_CHANGE";
const std::string BUNDLE_CLEAN_CACHE = "BUNDLE_CLEAN_CACHE";
// event params
const std::string EVENT_PARAM_USERID = "USERID";
const std::string EVENT_PARAM_UID = "UID";
const std::string EVENT_PARAM_BUNDLE_NAME = "BUNDLE_NAME";
const std::string EVENT_PARAM_ERROR_CODE = "ERROR_CODE";
const std::string EVENT_PARAM_ABILITY_NAME = "ABILITY_NAME";
const std::string EVENT_PARAM_TIME = "TIME";
const std::string EVENT_PARAM_VERSION = "VERSION";
const std::string EVENT_PARAM_SCENE = "SCENE";
const std::string EVENT_PARAM_CLEAN_TYPE = "CLEAN_TYPE";
const std::string EVENT_PARAM_INSTALL_TYPE = "INSTALL_TYPE";
const std::string EVENT_PARAM_STATE = "STATE";
const std::string FREE_INSTALL_TYPE = "FreeInstall";
const std::string PRE_BUNDLE_INSTALL_TYPE = "PreBundleInstall";
const std::string NORMAL_INSTALL_TYPE = "normalInstall";
const std::string NORMAL_SCENE = "Normal";
const std::string BOOT_SCENE = "Boot";
const std::string REBOOT_SCENE = "Reboot";
const std::string CREATE_USER_SCENE = "CreateUser";
const std::string REMOVE_USER_SCENE = "CreateUser";
const std::string CLEAN_CACHE = "cleanCache";
const std::string CLEAN_DATA = "cleanData";
const std::string ENABLE = "enable";
const std::string DISABLE = "disable";
const std::string APPLICATION = "application";
const std::string ABILITY = "ability";
const std::string TYPE = "TYPE";
const std::unordered_map<InstallScene, std::string> INSTALL_SCENE_STR_MAP = {
{ InstallScene::NORMAL, NORMAL_SCENE },
{ InstallScene::BOOT, BOOT_SCENE },
{ InstallScene::REBOOT, REBOOT_SCENE },
{ InstallScene::CREATE_USER, CREATE_USER_SCENE },
{ InstallScene::REMOVE_USER, REMOVE_USER_SCENE },
};
std::string GetInstallType(const EventInfo& eventInfo)
{
std::string installType = NORMAL_INSTALL_TYPE;
if (eventInfo.isFreeInstallMode) {
installType = FREE_INSTALL_TYPE;
} else if (eventInfo.isPreInstallApp) {
installType = PRE_BUNDLE_INSTALL_TYPE;
}
return installType;
}
std::string GetInstallScene(const EventInfo& eventInfo)
{
std::string installScene = NORMAL_SCENE;
auto iter = INSTALL_SCENE_STR_MAP.find(eventInfo.preBundleScene);
if (iter != INSTALL_SCENE_STR_MAP.end()) {
installScene = iter->second;
}
return installScene;
}
}
std::unordered_map<BMSEventType, void (*)(const EventInfo& eventInfo)>
InnerEventReport::bmsSysEventMap_ = {
{ BMSEventType::BUNDLE_INSTALL_EXCEPTION,
[](const EventInfo& eventInfo) {
InnerSendBundleInstallExceptionEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_UNINSTALL_EXCEPTION,
[](const EventInfo& eventInfo) {
InnerSendBundleUninstallExceptionEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_UPDATE_EXCEPTION,
[](const EventInfo& eventInfo) {
InnerSendBundleUpdateExceptionEvent(eventInfo);
} },
{ BMSEventType::PRE_BUNDLE_RECOVER_EXCEPTION,
[](const EventInfo& eventInfo) {
InnerSendPreBundleRecoverExceptionEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_STATE_CHANGE_EXCEPTION,
[](const EventInfo& eventInfo) {
InnerSendBundleComponentChangeExceptionEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_CLEAN_CACHE_EXCEPTION,
[](const EventInfo& eventInfo) {
InnerSendBundleCleanCacheExceptionEvent(eventInfo);
} },
{ BMSEventType::BOOT_SCAN_START,
[](const EventInfo& eventInfo) {
InnerSendBootScanStartEvent(eventInfo);
} },
{ BMSEventType::BOOT_SCAN_END,
[](const EventInfo& eventInfo) {
InnerSendBootScanEndEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_INSTALL,
[](const EventInfo& eventInfo) {
InnerSendBundleInstallEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_UNINSTALL,
[](const EventInfo& eventInfo) {
InnerSendBundleUninstallEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_UPDATE,
[](const EventInfo& eventInfo) {
InnerSendBundleUpdateEvent(eventInfo);
} },
{ BMSEventType::PRE_BUNDLE_RECOVER,
[](const EventInfo& eventInfo) {
InnerSendPreBundleRecoverEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_COMPONENT_STATE_CHANGE,
[](const EventInfo& eventInfo) {
InnerSendBundleComponentChangeEvent(eventInfo);
} },
{ BMSEventType::BUNDLE_CLEAN_CACHE,
[](const EventInfo& eventInfo) {
InnerSendBundleCleanCacheEvent(eventInfo);
} },
};
void InnerEventReport::SendSystemEvent(BMSEventType bmsEventType, const EventInfo& eventInfo)
{
auto iter = bmsSysEventMap_.find(bmsEventType);
if (iter == bmsSysEventMap_.end()) {
return;
}
iter->second(eventInfo);
}
void InnerEventReport::InnerSendBundleInstallExceptionEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BUNDLE_INSTALL_EXCEPTION,
HiSysEventType::FAULT,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
EVENT_PARAM_SCENE, GetInstallScene(eventInfo),
EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
}
void InnerEventReport::InnerSendBundleUninstallExceptionEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BUNDLE_UNINSTALL_EXCEPTION,
HiSysEventType::FAULT,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
}
void InnerEventReport::InnerSendBundleUpdateExceptionEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BUNDLE_UPDATE_EXCEPTION,
HiSysEventType::FAULT,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
}
void InnerEventReport::InnerSendPreBundleRecoverExceptionEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
PRE_BUNDLE_RECOVER_EXCEPTION,
HiSysEventType::FAULT,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, PRE_BUNDLE_INSTALL_TYPE,
EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
}
void InnerEventReport::InnerSendBundleComponentChangeExceptionEvent(const EventInfo& eventInfo)
{
std::string type = eventInfo.abilityName.empty() ? APPLICATION : ABILITY;
InnerEventWrite(
BUNDLE_STATE_CHANGE_EXCEPTION,
HiSysEventType::FAULT,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_ABILITY_NAME, eventInfo.abilityName,
TYPE, type);
}
void InnerEventReport::InnerSendBundleCleanCacheExceptionEvent(const EventInfo& eventInfo)
{
std::string cleanType = eventInfo.isCleanCache ? CLEAN_CACHE : CLEAN_DATA;
InnerEventWrite(
BUNDLE_CLEAN_CACHE_EXCEPTION,
HiSysEventType::FAULT,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_CLEAN_TYPE, cleanType);
}
void InnerEventReport::InnerSendBootScanStartEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BOOT_SCAN_START,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_TIME, eventInfo.timeStamp);
}
void InnerEventReport::InnerSendBootScanEndEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BOOT_SCAN_END,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_TIME, eventInfo.timeStamp);
}
void InnerEventReport::InnerSendBundleInstallEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BUNDLE_INSTALL,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
EVENT_PARAM_SCENE, GetInstallScene(eventInfo));
}
void InnerEventReport::InnerSendBundleUninstallEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BUNDLE_UNINSTALL,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo));
}
void InnerEventReport::InnerSendBundleUpdateEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BUNDLE_UPDATE,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo));
}
void InnerEventReport::InnerSendPreBundleRecoverEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
PRE_BUNDLE_RECOVER,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_VERSION, eventInfo.versionCode,
EVENT_PARAM_INSTALL_TYPE, PRE_BUNDLE_INSTALL_TYPE);
}
void InnerEventReport::InnerSendBundleComponentChangeEvent(const EventInfo& eventInfo)
{
std::string type = eventInfo.abilityName.empty() ? APPLICATION : ABILITY;
std::string state = eventInfo.isEnable ? ENABLE : DISABLE;
InnerEventWrite(
BUNDLE_COMPONENT_STATE_CHANGE,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_ABILITY_NAME, eventInfo.abilityName,
TYPE, type,
EVENT_PARAM_STATE, state);
}
void InnerEventReport::InnerSendBundleCleanCacheEvent(const EventInfo& eventInfo)
{
std::string cleanType = eventInfo.isCleanCache ? CLEAN_CACHE : CLEAN_DATA;
InnerEventWrite(
BUNDLE_CLEAN_CACHE,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_USERID, eventInfo.userId,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_CLEAN_TYPE, cleanType);
}
template<typename... Types>
void InnerEventReport::InnerEventWrite(
const std::string &eventName,
HiSysEventType type,
Types... keyValues)
{
OHOS::HiviewDFX::HiSysEvent::Write(
OHOS::HiviewDFX::HiSysEvent::Domain::APPEXECFWK,
eventName,
static_cast<OHOS::HiviewDFX::HiSysEvent::EventType>(type),
keyValues...);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -42,6 +42,8 @@ bool SystemBundleInstaller::InstallSystemBundle(
|| appType == Constants::AppType::THIRD_SYSTEM_APP) {
installParam.needSavePreInstallInfo = true;
}
MarkPreBundleSyeEventBootTag(true);
ErrCode result = InstallBundle(filePath, installParam, appType);
if (result != ERR_OK) {
APP_LOGE("install system bundle fail, error: %{public}d", result);
@ -58,6 +60,7 @@ bool SystemBundleInstaller::OTAInstallSystemBundle(
APP_LOGE("Get dataMgr shared_ptr nullptr");
return false;
}
InstallParam installParam;
installParam.isPreInstallApp = true;
installParam.noSkipsKill = false;
@ -67,14 +70,18 @@ bool SystemBundleInstaller::OTAInstallSystemBundle(
|| appType == Constants::AppType::THIRD_SYSTEM_APP) {
installParam.needSavePreInstallInfo = true;
}
for (auto allUserId : dataMgr->GetAllUser()) {
installParam.userId = allUserId;
MarkPreBundleSyeEventBootTag(false);
ErrCode result = InstallBundle(filePaths, installParam, appType);
if (result != ERR_OK) {
APP_LOGW("install system bundle fail, error: %{public}d", result);
}
ResetInstallProperties();
}
return true;
}
@ -85,16 +92,20 @@ bool SystemBundleInstaller::UninstallSystemBundle(const std::string &bundleName)
APP_LOGE("Get dataMgr shared_ptr nullptr");
return false;
}
InstallParam installParam;
for (auto userId : dataMgr->GetAllUser()) {
installParam.userId = userId;
installParam.needSavePreInstallInfo = true;
installParam.isPreInstallApp = true;
installParam.noSkipsKill = false;
installParam.needSendEvent = false;
MarkPreBundleSyeEventBootTag(false);
ErrCode result = UninstallBundle(bundleName, installParam);
if (result != ERR_OK) {
APP_LOGW("uninstall system bundle fail, error: %{public}d", result);
}
ResetInstallProperties();
}
return true;
@ -112,14 +123,18 @@ bool SystemBundleInstaller::UninstallSystemBundle(const std::string &bundleName,
for (auto userId : dataMgr->GetAllUser()) {
installParam.userId = userId;
installParam.needSavePreInstallInfo = true;
installParam.isPreInstallApp = true;
installParam.noSkipsKill = false;
installParam.needSendEvent = false;
MarkPreBundleSyeEventBootTag(false);
ErrCode result = UninstallBundle(bundleName, modulePackage, installParam);
if (result != ERR_OK) {
APP_LOGW("uninstall system bundle fail, error: %{public}d", result);
}
ResetInstallProperties();
}
return true;
}
} // namespace AppExecFwk

View File

@ -129,6 +129,12 @@ ohos_unittest("BmsBundleAccessTokenIdTest") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}

View File

@ -100,6 +100,12 @@ ohos_unittest("BmsBundleCloneTest") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
if (bundle_framework_free_install) {
sources += aging
sources += free_install

View File

@ -131,6 +131,12 @@ ohos_unittest("BmsBundleInstallerTest") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}
@ -252,6 +258,12 @@ ohos_unittest("BmsMultipleBundleInstallerTest") {
defines += [ "DEVICE_MANAGER_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}

View File

@ -133,6 +133,13 @@ ohos_unittest("BmsBundleKitServiceTest") {
external_deps += [ "hicollie_native:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}

View File

@ -136,6 +136,12 @@ ohos_unittest("BmsBundlePermissionGrantTest") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}

View File

@ -134,6 +134,12 @@ ohos_unittest("BmsBundleUninstallerTest") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}

View File

@ -138,6 +138,12 @@ ohos_unittest("BmsBundleUpdaterTest") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}

View File

@ -125,6 +125,12 @@ ohos_unittest("BmsDataMgrTest") {
external_deps += [ "hicollie_native:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
}
group("unittest") {

View File

@ -83,6 +83,13 @@ ohos_unittest("BmsDistributedDataStorageTest") {
external_deps += [ "hicollie_native:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/bundlemgrservice/ohos_test.xml"
}

View File

@ -118,6 +118,12 @@ ohos_unittest("BmsServiceBundleScanTest") {
external_deps += [ "hicollie_native:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
}
group("unittest") {

View File

@ -118,6 +118,12 @@ ohos_unittest("BmsServiceStartupTest") {
external_deps += [ "hicollie_native:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
}
group("unittest") {

View File

@ -111,6 +111,13 @@ ohos_moduletest("BmsBundleInstallerModuleTest") {
external_deps += [ "hicollie_native:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/mstbundlemgrservice/ohos_test.xml"
}

View File

@ -106,6 +106,13 @@ ohos_moduletest("BmsBundleUninstallerModuleTest") {
external_deps += [ "hicollie_native:libhicollie" ]
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/mstbundlemgrservice/ohos_test.xml"
}

View File

@ -91,6 +91,12 @@ ohos_moduletest("BmsServiceStartModuleTest") {
defines += [ "HICOLLIE_ENABLE" ]
}
if (hisysevent_enable) {
sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ]
external_deps += [ "hisysevent_native:libhisysevent" ]
defines += [ "HISYSEVENT_ENABLE" ]
}
resource_config_file =
"${appexecfwk_path}/test/resource/mstbundlemgrservice/ohos_test.xml"
}