diff --git a/BUILD.gn b/BUILD.gn index a3d0ad1d64f4f333981938fc590ff16aca1fc696..3d0405c7eeede51350305cef9d5265101e2df41c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -255,6 +255,7 @@ ohos_shared_library("usagestatservice") { "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", + "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_single", "relational_store:native_rdb", @@ -340,6 +341,7 @@ ohos_static_library("usagestatservice_static") { "ffrt:libffrt", "hicollie:libhicollie", "hilog:libhilog", + "hisysevent:libhisysevent", "init:libbegetutil", "ipc:ipc_single", "relational_store:native_rdb", diff --git a/bundle.json b/bundle.json index 0b6e8d31b9aad6288f3a3baa9379e4bd9ce32431..e30298b10033d0fbe53eff3a94863933d47ef15b 100644 --- a/bundle.json +++ b/bundle.json @@ -47,7 +47,8 @@ "time_service", "init", "jsoncpp", - "ffrt" + "ffrt", + "hisysevent" ], "third_party": [] }, diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 6ec93c247545a5e49eda5e89e2202615a1a79d23..35f26779dc3cf26ce78b738267f90ec3c222c495 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -26,6 +26,7 @@ #include "bundle_active_util.h" #include "ffrt_inner.h" #include "bundle_constants.h" +#include "hisysevent.h" namespace OHOS { @@ -34,6 +35,7 @@ namespace DeviceUsageStats { const int32_t DEFAULT_OS_ACCOUNT_ID = 0; // 0 is the default id when there is no os_account part #endif // OS_ACCOUNT_PART_ENABLED constexpr int32_t BUNDLE_UNINSTALL_DELAY_TIME = 5 * 1000 * 1000; +static constexpr char RSS[] = "RSS"; BundleActiveReportHandlerObject::BundleActiveReportHandlerObject() { @@ -843,6 +845,14 @@ void BundleActiveCore::OnAppGroupChanged(const AppGroupCallbackInfo& callbackInf bundleGroupHandler_->PostTask([bundleActiveCore, callbackInfo, tokenInfo]() { bundleActiveCore->NotifOberserverGroupChanged(callbackInfo, tokenInfo); }); + HiSysEventWrite(RSS, + "UPDATE_GROUP_SCENE", HiviewDFX::HiSysEvent::EventType::STATISTIC, + "UPDATE_GROUP_BUNDLENAME", callbackInfo.GetBundleName(), + "UPDATE_GROUP_USERID", callbackInfo.GetUserId(), + "UPDATE_GROUP_REASON", callbackInfo.GetChangeReason(), + "UPDATE_GROUP_TIME", GetSystemTimeMs(), + "UPDATE_GROUP_OLD_GROUP", callbackInfo.GetOldGroup(), + "UPDATE_GROUP_NEW_GROUP", callbackInfo.GetNewGroup()); } void BundleActiveCore::NotifOberserverGroupChanged(const AppGroupCallbackInfo& callbackInfo, diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 0dbf59e996db5e7f8827c89d52cf38ef978118da..7ec4d8171c2523058e4a2e46e10c63324788a74d 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -36,6 +36,8 @@ #include "bundle_active_usage_database.h" #include "bundle_active_bundle_mgr_helper.h" #include "bundle_active_account_helper.h" +#include "hisysevent.h" +#include "bundle_active_core.h" namespace OHOS { namespace DeviceUsageStats { @@ -45,6 +47,8 @@ namespace { const int32_t MAX_FILES_EVERY_INTERVAL_TYPE[SORTED_TABLE_ARRAY_NUMBER] = {30, 30, 12, 10}; const int32_t MAIN_APP_INDEX = 0; const int32_t FILE_VERSION_LINE_NUM = 50; + const int64_t MAX_END_TIME = 20000000000000; + static constexpr char RSS[] = "RSS"; } BundleActiveUsageDatabase::BundleActiveUsageDatabase() { @@ -1366,6 +1370,31 @@ void BundleActiveUsageDatabase::UpdateEventData(int32_t databaseType, BundleActi void BundleActiveUsageDatabase::UpdateBundleUsageData(int32_t databaseType, BundleActivePeriodStats &stats) { + if (databaseType == 0) { + int32_t bundleStatsSize = 0; + vector bundleActivePackageStats = + QueryDatabaseUsageStats(databaseType, 0, MAX_END_TIME, stats.userId_, ""); + for (int32_t i = 0; i < bundleActivePackageStats.size(); i++) { + std::map>::iterator iter = + stats.bundleStats_.find(bundleActivePackageStats[i].bundleName_ + to_string( + bundleActivePackageStats[i].uid_)); + if (iter != stats.bundleStats_.end() && + iter->second->lastTimeUsed_ == bundleActivePackageStats[i].lastTimeUsed_) { + bundleStatsSize++; + } + } + std::shared_ptr bundleActiveCore = std::make_shared(); + if (bundleActiveCore == nullptr) { + BUNDLE_ACTIVE_LOGE("UpdateBundleUsageData bundleActiveCore is nullptr"); + return; + } + HiSysEventWrite(RSS, + "UPDATE_BUNDLE_USAGE_SCENE", HiviewDFX::HiSysEvent::EventType::STATISTIC, + "UPDATE_BUNDLE_USAGE_EVENT_SIZE", stats.events_.Size(), + "UPDATE_BUNDLE_USAGE_STATS_SIZE", stats.bundleStats_.size() - bundleStatsSize, + "UPDATE_BUNDLE_USAGE_USERID", stats.userId_, + "UPDATE_BUNDLE_USAGE_TIME", bundleActiveCore->GetSystemTimeMs()); + } lock_guard lock(databaseMutex_); if (databaseType < 0 || databaseType >= EVENT_DATABASE_INDEX) { BUNDLE_ACTIVE_LOGE("databaseType is invalid : %{public}d", databaseType);