From 592b031cece7b01eecaed8c5d691f5c9b91109d1 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 09:42:24 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=82=B9=E5=87=BB/=E5=88=A0=E9=99=A4=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8Cquery=E6=8E=A5=E5=8F=A3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=B1=82=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- BUILD.gn | 6 +- .../innerkits/include/bundle_active_client.h | 7 +- .../innerkits/include/bundle_active_proxy.h | 8 +- .../innerkits/src/bundle_active_client.cpp | 15 +- .../innerkits/src/bundle_active_proxy.cpp | 46 +++++-- services/common/include/bundle_active_core.h | 1 + .../common/include/bundle_active_service.h | 15 +- .../include/bundle_active_usage_database.h | 6 + .../common/include/ibundle_active_service.h | 12 +- ...bundle_active_continuous_task_observer.cpp | 1 + services/common/src/bundle_active_core.cpp | 20 +++ services/common/src/bundle_active_service.cpp | 112 +++++++++++++-- services/common/src/bundle_active_stub.cpp | 28 +++- .../src/bundle_active_usage_database.cpp | 20 +++ .../include/bundle_active_event.h | 9 +- .../include/bundle_active_form_record.h | 54 ++++++++ .../include/bundle_active_module_record.h | 62 +++++++++ .../include/bundle_active_package_stats.h | 2 +- .../include/bundle_active_user_service.h | 5 + .../packageusage/src/bundle_active_event.cpp | 13 +- .../src/bundle_active_form_record.cpp | 88 ++++++++++++ .../src/bundle_active_module_record.cpp | 130 ++++++++++++++++++ .../src/bundle_active_package_stats.cpp | 2 +- .../src/bundle_active_user_service.cpp | 55 +++++++- 24 files changed, 663 insertions(+), 54 deletions(-) create mode 100644 services/packageusage/include/bundle_active_form_record.h create mode 100644 services/packageusage/include/bundle_active_module_record.h create mode 100644 services/packageusage/src/bundle_active_form_record.cpp create mode 100644 services/packageusage/src/bundle_active_module_record.cpp diff --git a/BUILD.gn b/BUILD.gn index 87a5834..e91e458 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -35,7 +35,9 @@ ohos_shared_library("usagestatsinner") { "services/packageusage/src/bundle_active_event.cpp", "services/packageusage/src/bundle_active_package_stats.cpp", ] - public_configs = [ ":usagestatsinner_public_config" ] + public_configs = [ + ":usagestatsinner_public_config" + ] public_deps = [ ":usagestatservice" ] external_deps = [ "hiviewdfx_hilog_native:libhilog", @@ -110,6 +112,8 @@ ohos_shared_library("usagestatservice") { "services/packageusage/src/bundle_active_event_list.cpp", "services/packageusage/src/bundle_active_event_stats.cpp", "services/packageusage/src/bundle_active_event_tracker.cpp", + "services/packageusage/src/bundle_active_form_record.cpp", + "services/packageusage/src/bundle_active_module_record.cpp", "services/packageusage/src/bundle_active_package_stats.cpp", "services/packageusage/src/bundle_active_period_stats.cpp", "services/packageusage/src/bundle_active_report_handler.cpp", diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 5bf1e97..ff62dcb 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -19,13 +19,15 @@ #include "ibundle_active_service.h" #include "bundle_active_package_stats.h" #include "bundle_active_event.h" +#include "bundle_active_package_stats.h" +#include "bundle_active_module_record.h" namespace OHOS { namespace DeviceUsageStats { class BundleActiveClient { public: - int ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, - const std::string& continuousTask, const int userId, const int eventId); + int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, + const int64_t formId, const int32_t formDimension, const int userId, const int eventId); bool IsBundleIdle(const std::string& bundleName); std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode); @@ -35,6 +37,7 @@ public: const int64_t endTime); std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime); int QueryPackageGroup(); + int QueryFormStatistics(int32_t maxNum, std::vector& results); static BundleActiveClient& GetInstance(); BundleActiveClient() {} ~BundleActiveClient() {} diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index e5fe92e..a58a874 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -18,13 +18,16 @@ #include "ibundle_active_service.h" #include "bundle_active_event.h" +#include "bundle_active_package_stats.h" +#include "bundle_active_package_stats.h" +#include "bundle_active_module_record.h" namespace OHOS { namespace DeviceUsageStats { class BundleActiveProxy : public IRemoteProxy { public: - int ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, - const std::string& continuousTask, const int userId, const int eventId) override; + int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, + const int64_t formId, const int32_t formDimension, const int userId, const int eventId) override; bool IsBundleIdle(const std::string& bundleName) override; std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; @@ -35,6 +38,7 @@ public: const int64_t endTime) override; std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) override; int QueryPackageGroup() override; + int QueryFormStatistics(int32_t maxNum, std::vector& results) override; explicit BundleActiveProxy(const sptr& impl) : IRemoteProxy(impl) {} virtual ~BundleActiveProxy() {} diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 4ac0b1b..8cf3c17 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -14,7 +14,6 @@ */ #include "bundle_active_client.h" -#include "bundle_active_package_stats.h" namespace OHOS { namespace DeviceUsageStats { @@ -46,14 +45,14 @@ bool BundleActiveClient::GetBundleActiveProxy() return true; } -int BundleActiveClient::ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, - const std::string& continuousTask, const int userId, const int eventId) +int BundleActiveClient::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, + const int64_t formId, const int32_t formDimension, const int userId, const int eventId) { BUNDLE_ACTIVE_LOGI("BundleActiveClient::ReportEvent called"); if (!GetBundleActiveProxy()) { return -1; } - return bundleActiveProxy_->ReportEvent(bundleName, abilityName, abilityId, continuousTask, userId, eventId); + return bundleActiveProxy_->ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, formDimension, userId, eventId); } bool BundleActiveClient::IsBundleIdle(const std::string& bundleName) @@ -115,6 +114,14 @@ int BundleActiveClient::QueryPackageGroup() } return bundleActiveProxy_->QueryPackageGroup(); } + +int BundleActiveClient::QueryFormStatistics(int32_t maxNum, std::vector& results) +{ + if (!GetBundleActiveProxy()) { + return -1; + } + return bundleActiveProxy_->QueryFormStatistics(maxNum, results); +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index ffcab9c..5ecce91 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -14,13 +14,11 @@ */ #include "bundle_active_proxy.h" -#include "bundle_active_package_stats.h" -#include "bundle_active_package_stats.h" namespace OHOS { namespace DeviceUsageStats { -int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, - const std::string& continuousTask, const int userId, const int eventId) +int BundleActiveProxy::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, + const int64_t formId, const int32_t formDimension, const int userId, const int eventId) { MessageParcel data; MessageParcel reply; @@ -29,12 +27,14 @@ int BundleActiveProxy::ReportEvent(std::string& bundleName, std::string& ability return -1; } data.WriteString(bundleName); - data.WriteString(abilityName); - data.WriteString(abilityId); - data.WriteString(continuousTask); + data.WriteString(moduleName); + data.WriteString(modulePackage); + data.WriteString(formName); + data.WriteInt64(formId); + data.WriteInt32(formDimension); data.WriteInt32(userId); data.WriteInt32(eventId); - Remote() -> SendRequest(REPORT_EVENT, data, reply, option); + Remote() -> SendRequest(REPORT_FORM_EVENT, data, reply, option); int32_t result = reply.ReadInt32(); return result; @@ -74,7 +74,7 @@ std::vector BundleActiveProxy::QueryPackageStats(const int32_t size = reply.ReadInt32(); std::shared_ptr tmp; for (int i = 0; i < size; i++) { - tmp = tmp->Unmarshalling(reply); + tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; } @@ -108,7 +108,7 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi int32_t size = reply.ReadInt32(); std::shared_ptr tmp; for (int i = 0; i < size; i++) { - tmp = tmp->Unmarshalling(reply); + tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; } @@ -152,7 +152,7 @@ std::vector BundleActiveProxy::QueryCurrentPackageStat int32_t size = reply.ReadInt32(); std::shared_ptr tmp; for (int i = 0; i < size; i++) { - tmp = tmp->Unmarshalling(reply); + tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; } @@ -183,7 +183,7 @@ std::vector BundleActiveProxy::QueryCurrentEvents(const int64 int32_t size = reply.ReadInt32(); std::shared_ptr tmp; for (int i = 0; i < size; i++) { - tmp = tmp->Unmarshalling(reply); + tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; } @@ -210,6 +210,28 @@ int BundleActiveProxy::QueryPackageGroup() BUNDLE_ACTIVE_LOGI("QueryPackageGroup result is %{public}d", packageGroup); return packageGroup; } + +int BundleActiveProxy::QueryFormStatistics(int32_t maxNum, std::vector& results) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return -1; + } + data.WriteInt32(maxNum); + Remote() -> SendRequest(QUERY_FORM_STATS, data, reply, option); + int32_t size = reply.ReadInt32(); + std::shared_ptr tmp; + for (int i = 0; i < size; i++) { + tmp = tmp->UnMarshalling(reply); + if (tmp == nullptr) { + continue; + } + results.emplace_back(*tmp); + } + return 0; +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index e2037b1..2e1a870 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -109,6 +109,7 @@ public: int IsBundleIdle(const std::string& bundleName, const int userId); // query the app group for calling app. int QueryPackageGroup(const int userId, const std::string bundleName); + int QueryFormStatistics(int32_t maxNum, std::vector& results, int userId); // get the wall time and check if the wall time is changed. int64_t CheckTimeChangeAndGetWallTime(int userId = 0); // convert event timestamp from boot based time to wall time. diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index ff28fc2..885da39 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -33,11 +33,15 @@ class BundleActiveService : public SystemAbility, public BundleActiveStub { DECLARE_SYSTEM_ABILITY(BundleActiveService); public: using IBundleMgr = OHOS::AppExecFwk::IBundleMgr; - using ApplicationInfo = OHOS::AppExecFwk::ApplicationInfo; using BundleInfo = OHOS::AppExecFwk::BundleInfo; using BundleFlag = OHOS::AppExecFwk::BundleFlag; - int ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, - const std::string& continuousTask, const int userId, const int eventId) override; + using HapModuleInfo = OHOS::AppExecFwk::HapModuleInfo; + using AbilityInfo = OHOS::AppExecFwk::AbilityInfo; + using ApplicationInfo = OHOS::AppExecFwk::ApplicationInfo; + using ApplicationFlag = OHOS::AppExecFwk::ApplicationFlag; + using AbilityType = OHOS::AppExecFwk::AbilityType; + int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, + const int64_t formId, const int32_t formDimension, const int userId, const int eventId) override; bool IsBundleIdle(const std::string& bundleName) override; std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; @@ -48,6 +52,7 @@ public: const int64_t endTime) override; std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) override; int QueryPackageGroup() override; + int QueryFormStatistics(int32_t maxNum, std::vector& results) override; BundleActiveService(int32_t systemAbilityId, int runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) {} ~BundleActiveService() {} @@ -75,6 +80,10 @@ private: bool SubscribeAppState(); bool SubscribeContinuousTask(); OHOS::sptr GetAppManagerInstance(); + void GetAndSetModuleRecordInfos(BundleInfo& bundleInfo, HapModuleInfo& hapModuleInfo, + ApplicationInfo& appInfo, AbilityInfo& abilityInfo, BundleActiveModuleRecord& moduleRecord); + void SerModuleProperties(const BundleInfo& bundleInfo, const HapModuleInfo& hapModuleInfo, + const ApplicationInfo& appInfo, const AbilityInfo& abilityInfo, BundleActiveModuleRecord& moduleRecord); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index d858749..4772fdf 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -31,6 +31,7 @@ #include "bundle_active_period_stats.h" #include "bundle_active_calendar.h" #include "bundle_active_package_history.h" +#include "bundle_active_module_record.h" namespace OHOS { namespace DeviceUsageStats { @@ -57,6 +58,11 @@ public: GetBundleHistoryData(int userId); void OnPackageUninstalled(const int userId, const std::string& bundleName); void ChangeToDebug(); + void UpdateModuleData(int userId, std::map> moduleRecords_); + void RemoveFormData(const int userId, const std::string formName, + const int32_t formDimension, const int64_t formId); + void GetFormDataWhenInit(const int32_t userId, std::map>& moduleRecords); private: void CheckDatabaseVersion(); diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h index 401584e..cebb7c6 100644 --- a/services/common/include/ibundle_active_service.h +++ b/services/common/include/ibundle_active_service.h @@ -40,10 +40,12 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActivePackageStats; class BundleActiveEvent; +class BundleActiveModuleRecord; + class IBundleActiveService : public IRemoteBroker { public: - virtual int ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, - const std::string& continuousTask, const int userId, const int eventId) = 0; + virtual int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, + const int64_t formId, const int32_t formDimension, const int userId, const int eventId) = 0; virtual bool IsBundleIdle(const std::string& bundleName) = 0; virtual std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) = 0; @@ -54,17 +56,19 @@ public: virtual std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) = 0; virtual int QueryPackageGroup() = 0; virtual void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) = 0; + virtual int QueryFormStatistics(int32_t maxNum, std::vector& results) = 0; public: enum { - REPORT_EVENT = 1, + REPORT_FORM_EVENT = 1, IS_BUNDLE_IDLE = 2, QUERY_USAGE_STATS = 3, QUERY_EVENTS = 4, QUERY_CURRENT_USAGE_STATS = 5, QUERY_CURRENT_EVENTS = 6, QUERY_BUNDLE_GROUP = 7, - SET_BUNDLE_GROUP = 8 + SET_BUNDLE_GROUP = 8, + QUERY_FORM_STATS = 9 }; public: DECLARE_INTERFACE_DESCRIPTOR(u"Resourceschedule.IBundleActiveService"); diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index 5492ace..1298b46 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -83,6 +83,7 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( if (GetBundleMgr()) { bundleMgr_->GetBundleNameForUid(uid, bundleName); } else { + BUNDLE_ACTIVE_LOGE("Get bundle mgr failed!"); return; } OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 01f0293..6f67c08 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -442,6 +442,11 @@ int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) BUNDLE_ACTIVE_LOGE("get user data service failed!"); return -1; } + if (event.eventId_ == BundleActiveEvent::FORM_IS_CLICKED || + event.eventId_ == BundleActiveEvent::FORM_IS_REMOVED) { + service->ReportFormClickedOrRemoved(event); + return 0; + } service->ReportEvent(event); bundleGroupController_->ReportEvent(event, bootBasedTimeStamp, userId); return 0; @@ -520,6 +525,21 @@ std::vector BundleActiveCore::QueryEvents(const int userId, c return result; } +int BundleActiveCore::QueryFormStatistics(int32_t maxNum, std::vector& results, int userId) +{ + std::lock_guard lock(mutex_); + int64_t timeNow = CheckTimeChangeAndGetWallTime(userId); + if (timeNow == -1) { + return -1; + } + std::shared_ptr service = GetUserDataAndInitializeIfNeeded(userId, timeNow, debugCore_); + if (service == nullptr) { + return -1; + } + int errCode = service->QueryFormStatistics(maxNum, results); + return errCode; +} + void BundleActiveCore::SetBundleGroup(const std::string& bundleName, const int newGroup, const int userId) { int newReason = GROUP_CONTROL_REASON_FORCED; diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 8b73dc0..3575896 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -30,6 +30,8 @@ static const int PERIOD_BEST_JS = 0; static const int PERIOD_YEARLY_JS = 4; static const int PERIOD_BEST_SERVICE = 4; static const int DELAY_TIME = 2000; +static const int ROOT_UID = 0; +static const int SYSTEM_UID = 1000; REGISTER_SYSTEM_ABILITY_BY_ID(BundleActiveService, DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, true); const std::string NEEDED_PERMISSION = "ohos.permission.BUNDLE_ACTIVE_INFO"; @@ -201,22 +203,34 @@ void BundleActiveService::OnStop() } -int BundleActiveService::ReportEvent(std::string& bundleName, std::string& abilityName, std::string abilityId, - const std::string& continuousTask, const int userId, const int eventId) +int BundleActiveService::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, + const int64_t formId, const int32_t formDimension, const int userId, const int eventId) { - BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); - tmpHandlerObject.event_.bundleName_ = bundleName; - tmpHandlerObject.event_.abilityName_ = abilityName; - tmpHandlerObject.event_.abilityId_ = abilityId; - tmpHandlerObject.event_.eventId_ = eventId; - tmpHandlerObject.event_.continuousTaskAbilityName_ = continuousTask; - sptr timer = MiscServices::TimeServiceClient::GetInstance(); - tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); - std::shared_ptr handlerobjToPtr = - std::make_shared(tmpHandlerObject); - auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REPORT_EVENT, handlerobjToPtr); - reportHandler_->SendEvent(event); - return 0; + int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + if (!GetBundleMgrProxy()) { + BUNDLE_ACTIVE_LOGE("Get bundle manager proxy failed!"); + return -1; + } + bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(callingUid); + if ((callingUid == ROOT_UID || callingUid == SYSTEM_UID) || bundleIsSystemApp) { + BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); + tmpHandlerObject.event_.bundleName_ = bundleName; + tmpHandlerObject.event_.moduleName_ = moduleName; + tmpHandlerObject.event_.modulePackage_ = modulePackage; + tmpHandlerObject.event_.formName_ = formName; + tmpHandlerObject.event_.formId_ = formId; + tmpHandlerObject.event_.formDimension_ = formDimension; + tmpHandlerObject.event_.eventId_ = eventId; + sptr timer = MiscServices::TimeServiceClient::GetInstance(); + tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); + std::shared_ptr handlerobjToPtr = + std::make_shared(tmpHandlerObject); + auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REPORT_EVENT, handlerobjToPtr); + reportHandler_->SendEvent(event); + return 0; + } else { + return -1; + } } bool BundleActiveService::IsBundleIdle(const std::string& bundleName) @@ -430,6 +444,74 @@ bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int uid, return true; } } + +int BundleActiveService::QueryFormStatistics(int32_t maxNum, std::vector& results) +{ + int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + BUNDLE_ACTIVE_LOGI("QueryFormStatistics UID is %{public}d", callingUid); + // get userid + int userId = -1; + OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); + int32_t errCode = 0; + if (ret == ERR_OK && userId != -1) { + BUNDLE_ACTIVE_LOGI("QueryEvents userid is %{public}d", userId); + bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId, errCode); + if (isSystemAppAndHasPermission == true) { + errCode = bundleActiveCore_->QueryFormStatistics(maxNum, results, userId); + } + } + return errCode; +} + +void BundleActiveService::GetAndSetModuleRecordInfos(BundleInfo& bundleInfo, HapModuleInfo& hapModuleInfo, + ApplicationInfo& appInfo, AbilityInfo& abilityInfo, BundleActiveModuleRecord& moduleRecord) +{ + if (!GetBundleMgrProxy()) { + return; + } + if (!sptrBundleMgr_->GetApplicationInfo(moduleRecord.bundleName_, ApplicationFlag::GET_BASIC_APPLICATION_INFO, + moduleRecord.userId_, appInfo)) { + BUNDLE_ACTIVE_LOGE("GetApplicationInfo failed!"); + return; + } + if (!sptrBundleMgr_->GetBundleInfo(moduleRecord.bundleName_, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, + moduleRecord.userId_)) { + BUNDLE_ACTIVE_LOGE("GetBundleInfo failed!"); + return; + } + AbilityInfo mockAbilityInfo; + mockAbilityInfo.bundleName = moduleRecord.bundleName_; + mockAbilityInfo.package = moduleRecord.modulePackage_; + if (!sptrBundleMgr_->GetHapModuleInfo(mockAbilityInfo, hapModuleInfo)) { + BUNDLE_ACTIVE_LOGE("GetHapModuleInfo failed!"); + return; + } + std::string mainAbility = hapModuleInfo.mainAbility; + if (!hapModuleInfo.abilityInfos.empty()) { + for (auto oneAbilityInfo : hapModuleInfo.abilityInfos) { + if (oneAbilityInfo.type != AbilityType::PAGE) { + continue; + } + if (mainAbility.empty() || mainAbility.compare(abilityInfo.name) == 0) { + SerModuleProperties(bundleInfo, hapModuleInfo, appInfo, oneAbilityInfo, moduleRecord); + break; + } + } + } +} + +void BundleActiveService::SerModuleProperties(const BundleInfo& bundleInfo, const HapModuleInfo& hapModuleInfo, + const ApplicationInfo& appInfo, const AbilityInfo& abilityInfo, BundleActiveModuleRecord& moduleRecord) +{ + moduleRecord.deviceId_ = appInfo.deviceId; + moduleRecord.abilityName_ = abilityInfo.name; + moduleRecord.appLabelId_ = appInfo.labelId; + // hapModuleInfo.labelId 待徐浩添加 + moduleRecord.abilityName_ = abilityInfo.labelId; + moduleRecord.descriptionId_ = abilityInfo.descriptionId; + moduleRecord.abilityIconId_ = abilityInfo.iconId; + moduleRecord.installFreeSupported_ = hapModuleInfo.installationFree; +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index d221187..3d6f663 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -16,6 +16,7 @@ #include "bundle_active_stub.h" #include "bundle_active_package_stats.h" #include "bundle_active_event.h" +#include "bundle_active_module_record.h" namespace OHOS { namespace DeviceUsageStats { @@ -26,14 +27,16 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me return -1; } switch (code) { - case REPORT_EVENT: { + case REPORT_FORM_EVENT: { std::string bundleName = data.ReadString(); - std::string ablityName = data.ReadString(); - std::string abilityId = data.ReadString(); - std::string continuousTaskName = data.ReadString(); + std::string moduleName = data.ReadString(); + std::string modulePackage = data.ReadString(); + std::string formName = data.ReadString(); + int64_t formId = data.ReadInt64(); + int32_t formDimension = data.ReadInt32(); int userId = data.ReadInt32(); int eventId = data.ReadInt32(); - int result = ReportEvent(bundleName, ablityName, abilityId, continuousTaskName, userId, eventId); + int result = ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, formDimension, userId, eventId); return reply.WriteInt32(result); } case IS_BUNDLE_IDLE: { @@ -130,6 +133,21 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me result = QueryPackageGroup(); return reply.WriteInt32(result); } + case QUERY_FORM_STATS: { + std::vector results; + int size = 0; + int32_t maxNum = data.ReadInt32(); + QueryFormStatistics(maxNum, results); + size = static_cast(results.size()); + reply.WriteInt32(size); + for (int i = 0; i < size; i++) { + bool tmp = results[i].Marshalling(reply); + if (tmp == false) { + return 1; + } + } + return size == 0; + } default: return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 729b7ff..01ac344 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -66,6 +66,7 @@ void BundleActiveUsageDatabase::ChangeToDebug() calendar_->ChangeToDebug(); debugDatabase_ = true; } + void BundleActiveUsageDatabase::InitUsageGroupInfo(int32_t databaseType) { lock_guard lock(databaseMutex_); @@ -1201,6 +1202,7 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t void BundleActiveUsageDatabase::OnPackageUninstalled(const int userId, const string& bundleName) { + // 加入应用删除后删除卡片 lock_guard lock(databaseMutex_); for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { if (sortedTableArray_.at(i).empty()) { @@ -1255,6 +1257,24 @@ int64_t BundleActiveUsageDatabase::GetSystemTimeMs() } return static_cast(tarDate); } + +void BundleActiveUsageDatabase::UpdateModuleData(int userId, std::map> moduleRecords_) +{ + // mock +} + +void BundleActiveUsageDatabase::RemoveFormData(const int userId, const std::string formName, + const int32_t formDimension, const int64_t formId) +{ + // mock +} + +void BundleActiveUsageDatabase::GetFormDataWhenInit(const int32_t userId, std::map>& moduleRecords) +{ + // key: std::string combineInfo = bundlename + " " + modulePackage + " " + moduleName + // mock +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index dc26307..00cd140 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -40,11 +40,18 @@ public: static const int KEYGUARD_SHOWN = 15; static const int KEYGUARD_HIDDEN = 16; static const int NOTIFICATION_SEEN = 17; + static const int FORM_IS_CLICKED = 18; + static const int FORM_IS_REMOVED = 19; inline static const std::string DEVICE_EVENT_PACKAGE_NAME = "openharmony"; std::string bundleName_; std::string continuousTaskAbilityName_; std::string abilityName_; std::string abilityId_; + std::string moduleName_; + std::string modulePackage_; + std::string formName_; + int32_t formDimension_; + int64_t formId_; int64_t timeStamp_; int eventId_; @@ -58,7 +65,7 @@ public: int64_t GetTimeStamp(); int GetEventId(); virtual bool Marshalling(Parcel &parcel) const override; - std::shared_ptr Unmarshalling(Parcel &parcel); + std::shared_ptr UnMarshalling(Parcel &parcel); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/include/bundle_active_form_record.h b/services/packageusage/include/bundle_active_form_record.h new file mode 100644 index 0000000..5c482c9 --- /dev/null +++ b/services/packageusage/include/bundle_active_form_record.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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 BUNDLE_ACTIVE_FORM_RECORD_H +#define BUNDLE_ACTIVE_FORM_RECORD_H + +#include + +#include "ibundle_active_service.h" + +namespace OHOS { +namespace DeviceUsageStats { +class BundleActiveFormRecord : public Parcelable { +public: + std::string formName_; + int32_t formDimension_; + int64_t formId_; + int64_t formLastUsedTime_; + int32_t count_; + int32_t userId_; + void UpdateFormRecord(const int64_t timeStamp); + BundleActiveFormRecord(const BundleActiveFormRecord& orig); + virtual bool Marshalling(Parcel &parcel) const override; + std::shared_ptr UnMarshalling(Parcel &parcel); + BundleActiveFormRecord(); + BundleActiveFormRecord(const std::string formName, const int32_t formDimension, const int64_t formId, + const int64_t timeStamp, const int32_t userId); + ~BundleActiveFormRecord() {} + bool operator==(const BundleActiveFormRecord& formRecord) const + { + return (this->formId_ == formRecord.formId_); + } + bool operator==(const int64_t formId) const + { + return (this->formId_ == formId); + } + static bool cmp(const BundleActiveFormRecord& formRecordA, const BundleActiveFormRecord& formRecordB); +}; +} // namespace DeviceUsageStats +} // namespace OHOS +#endif // BUNDLE_ACTIVE_FORM_RECORD_H + diff --git a/services/packageusage/include/bundle_active_module_record.h b/services/packageusage/include/bundle_active_module_record.h new file mode 100644 index 0000000..c154587 --- /dev/null +++ b/services/packageusage/include/bundle_active_module_record.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 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 BUNDLE_ACTIVE_MODULE_RECORD_H +#define BUNDLE_ACTIVE_MODULE_RECORD_H + +#include +#include +#include + +#include "bundle_active_form_record.h" +#include "ibundle_active_service.h" + +namespace OHOS { +namespace DeviceUsageStats { +class BundleActiveModuleRecord : public Parcelable { +public: + void AddOrUpdateOneFormRecord(const std::string formName, const int32_t formDimension, + const int64_t formId, const int64_t timeStamp); + void RemoveOneFormRecord(const std::string formName, const int32_t formDimension, + const int64_t formId); + void UpdateModuleRecord(int64_t timeStamp); + BundleActiveModuleRecord(); + virtual bool Marshalling(Parcel &parcel) const override; + std::shared_ptr UnMarshalling(Parcel &parcel); + ~BundleActiveModuleRecord() {} + static bool cmp(const BundleActiveModuleRecord& moduleRecordA, const BundleActiveModuleRecord& moduleRecordB); +public: + std::string deviceId_; + std::string bundleName_; + std::string moduleName_; + std::string modulePackage_; + std::string abilityName_; + uint32_t appLabelId_; + uint32_t labelId_; + uint32_t descriptionId_; + uint32_t abilityLableId_; + uint32_t abilityDescriptionId_; + uint32_t abilityIconId_; + uint32_t launchedCount_; + int64_t lastModuleUsedTime_; + int32_t userId_; + bool removed_; + bool installFreeSupported_; + bool isNewAdded_; + std::vector formRecords_; // key:formid, value:formhistory +}; +} // namespace DeviceUsageStats +} // namespace OHOS +#endif // BUNDLE_ACTIVE_MODULE_RECORD_H \ No newline at end of file diff --git a/services/packageusage/include/bundle_active_package_stats.h b/services/packageusage/include/bundle_active_package_stats.h index 6e648a8..26af6d2 100644 --- a/services/packageusage/include/bundle_active_package_stats.h +++ b/services/packageusage/include/bundle_active_package_stats.h @@ -55,7 +55,7 @@ public: void IncrementServiceTimeUsed(const int64_t timeStamp); void IncrementBundleLaunchedCount(); virtual bool Marshalling(Parcel &parcel) const override; - std::shared_ptr Unmarshalling(Parcel &parcel); + std::shared_ptr UnMarshalling(Parcel &parcel); void printdata(); private: diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h index dffb022..8c44d35 100644 --- a/services/packageusage/include/bundle_active_user_service.h +++ b/services/packageusage/include/bundle_active_user_service.h @@ -26,6 +26,7 @@ #include "bundle_active_stats_combiner.h" #include "bundle_active_usage_database.h" #include "bundle_active_constant.h" +#include "bundle_active_module_record.h" namespace OHOS { namespace DeviceUsageStats { @@ -56,6 +57,7 @@ public: ~BundleActiveUserService() {} void ReportForShutdown(const BundleActiveEvent& event); void ReportEvent(const BundleActiveEvent& event); + void ReportFormClickedOrRemoved(const BundleActiveEvent& event); void RestoreStats(bool forced); void RenewStatsInMemory(const int64_t timeStamp); void RenewTableTime(int64_t oldTime, int64_t newTime); @@ -67,12 +69,14 @@ public: const int64_t endTime, const int userId, const std::string& bundleName); std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, const int userId, const std::string& bundleName); + int QueryFormStatistics(int32_t maxNum, std::vector& results); void LoadActiveStats(const int64_t timeStamp, const bool& force, const bool& timeChanged); private: static const int64_t ONE_SECOND_MILLISECONDS = 1000; BundleActiveUsageDatabase database_; std::vector> currentStats_; + std::map> moduleRecords_; bool statsChanged_; bool debugUserService_; std::string lastBackgroundBundle_; @@ -80,6 +84,7 @@ private: std::vector periodLength_ = {0, 0, 0, 0}; void NotifyStatsChanged(); void NotifyNewUpdate(); + std::shared_ptr GetOrCreateModuleRecord(const BundleActiveEvent& event); void PrintInMemPackageStats(const int idx); void PrintInMemEventStats(); }; diff --git a/services/packageusage/src/bundle_active_event.cpp b/services/packageusage/src/bundle_active_event.cpp index e07abd4..c7b764f 100644 --- a/services/packageusage/src/bundle_active_event.cpp +++ b/services/packageusage/src/bundle_active_event.cpp @@ -23,6 +23,11 @@ BundleActiveEvent::BundleActiveEvent() continuousTaskAbilityName_ = ""; abilityName_ = ""; abilityId_ = ""; + moduleName_ = ""; + modulePackage_ = ""; + formName_ = ""; + formId_ = 0; + formDimension_ = 0; timeStamp_ = 0; eventId_ = 0; } @@ -30,8 +35,14 @@ BundleActiveEvent::BundleActiveEvent() BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) { bundleName_ = orig.bundleName_; + continuousTaskAbilityName_ = orig.continuousTaskAbilityName_; abilityName_ = orig.abilityName_; abilityId_ = orig.abilityId_; + moduleName_ = orig.moduleName_; + modulePackage_ = orig.modulePackage_; + formName_ = orig.formName_; + formId_ = orig.formId_; + formDimension_ = orig.formDimension_; timeStamp_ = orig.timeStamp_; eventId_ = orig.eventId_; } @@ -80,7 +91,7 @@ bool BundleActiveEvent::Marshalling(Parcel &parcel) const return false; } -std::shared_ptr BundleActiveEvent::Unmarshalling(Parcel &parcel) +std::shared_ptr BundleActiveEvent::UnMarshalling(Parcel &parcel) { std::shared_ptr result = std::make_shared(); result->bundleName_ = parcel.ReadString(); diff --git a/services/packageusage/src/bundle_active_form_record.cpp b/services/packageusage/src/bundle_active_form_record.cpp new file mode 100644 index 0000000..c1e220e --- /dev/null +++ b/services/packageusage/src/bundle_active_form_record.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (c) 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 "bundle_active_form_record.h" + +namespace OHOS { +namespace DeviceUsageStats { +BundleActiveFormRecord::BundleActiveFormRecord() +{ + formName_ = ""; + formDimension_ = 0; + formId_ = 0; + formLastUsedTime_ = -1; + count_ = 0; + userId_ = -1; +} + +BundleActiveFormRecord::BundleActiveFormRecord(const std::string formName, const int32_t formDimension, + const int64_t formId, const int64_t timeStamp, const int32_t userId) +{ + formName_ = formName; + formDimension_ = formDimension; + formId_ = formId; + formLastUsedTime_ = timeStamp; + count_ = 1; + userId_ = userId; +} + +BundleActiveFormRecord::BundleActiveFormRecord(const BundleActiveFormRecord& orig) { + formName_ = orig.formName_; + formDimension_ = orig.formDimension_; + formId_ = orig.formId_; + formLastUsedTime_ = orig.formLastUsedTime_; + count_ = orig.count_; + userId_ = orig.userId_; +} + +void BundleActiveFormRecord::UpdateFormRecord(const int64_t timeStamp) +{ + if (formLastUsedTime_ < timeStamp) { + formLastUsedTime_ = timeStamp; + count_++; + } +} + +bool BundleActiveFormRecord::Marshalling(Parcel &parcel) const +{ + if (parcel.WriteString(formName_) && + parcel.WriteInt32(formDimension_) && + parcel.WriteInt64(formId_) && + parcel.WriteInt64(formLastUsedTime_) && + parcel.WriteInt32(count_)) { + return true; + } + return false; +} + +std::shared_ptr BundleActiveFormRecord::UnMarshalling(Parcel &parcel) +{ + std::shared_ptr result = std::make_shared(); + result->formName_ = parcel.ReadString(); + result->formDimension_ = parcel.ReadInt32(); + result->formId_ = parcel.ReadInt64(); + result->formLastUsedTime_ = parcel.ReadInt64(); + result->count_ = parcel.ReadInt32(); + return result; +} + +bool BundleActiveFormRecord::cmp(const BundleActiveFormRecord& formRecordA, + const BundleActiveFormRecord& formRecordB) +{ + return formRecordA.count_ > formRecordB.count_; +} +} // namespace DeviceUsageStats +} // namespace OHOS + diff --git a/services/packageusage/src/bundle_active_module_record.cpp b/services/packageusage/src/bundle_active_module_record.cpp new file mode 100644 index 0000000..87000f5 --- /dev/null +++ b/services/packageusage/src/bundle_active_module_record.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 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 "bundle_active_module_record.h" + +namespace OHOS { +namespace DeviceUsageStats { +void BundleActiveModuleRecord::AddOrUpdateOneFormRecord(const std::string formName, const int32_t formDimension, + const int64_t formId, const int64_t timeStamp) +{ + BundleActiveFormRecord newFormRecord(formName, formDimension, formId, timeStamp, userId_); + for (auto& formRecord : formRecords_) { + if (formRecord == newFormRecord) { + formRecord.UpdateFormRecord(timeStamp); + return; + } + } + formRecords_.emplace_back(newFormRecord); +} + +void BundleActiveModuleRecord::RemoveOneFormRecord(const std::string formName, const int32_t formDimension, + const int64_t formId) +{ + for (auto it = formRecords_.begin(); it != formRecords_.end(); it++) { + if (*it == formId) { + formRecords_.erase(it); + return; + } + } +} + +void BundleActiveModuleRecord::UpdateModuleRecord(int64_t timeStamp) +{ + if (lastModuleUsedTime_ < timeStamp) { + lastModuleUsedTime_ = timeStamp; + launchedCount_++; + } +} + +BundleActiveModuleRecord::BundleActiveModuleRecord() +{ + deviceId_ = ""; + bundleName_ = ""; // in database + moduleName_ = ""; // in database + modulePackage_ = ""; // in database + abilityName_ = ""; + appLabelId_ = 0; + labelId_ = 0; + descriptionId_ = 0; + abilityLableId_ = 0; + abilityDescriptionId_ = 0; + abilityIconId_ = 0; + launchedCount_ = 0; + lastModuleUsedTime_ = 0; + removed_ = false; + installFreeSupported_ = false; + isNewAdded_ = false; + userId_ = -1; +} + +bool BundleActiveModuleRecord::Marshalling(Parcel &parcel) const +{ + if (parcel.WriteString(deviceId_) && + parcel.WriteString(bundleName_) && + parcel.WriteString(moduleName_) && + parcel.WriteString(modulePackage_) && + parcel.WriteString(abilityName_) && + parcel.WriteUint32(appLabelId_) && + parcel.WriteUint32(descriptionId_) && + parcel.WriteUint32(abilityLableId_) && + parcel.WriteUint32(abilityDescriptionId_) && + parcel.WriteUint32(abilityIconId_) && + parcel.WriteUint32(launchedCount_) && + parcel.WriteInt64(lastModuleUsedTime_) && + parcel.WriteUint32(formRecords_.size()) + ) { + for (auto formRecord : formRecords_) { + formRecord.Marshalling(parcel); + } + return true; + } + return false; +} + +std::shared_ptr BundleActiveModuleRecord::UnMarshalling(Parcel &parcel) +{ + std::shared_ptr result = std::make_shared(); + result->deviceId_ = parcel.ReadString(); + result->bundleName_ = parcel.ReadString(); + result->moduleName_ = parcel.ReadString(); + result->modulePackage_ = parcel.ReadString(); + result->abilityName_ = parcel.ReadString(); + result->appLabelId_ = parcel.ReadUint32(); + result->descriptionId_ = parcel.ReadUint32(); + result->abilityLableId_ = parcel.ReadUint32(); + result->abilityDescriptionId_ = parcel.ReadUint32(); + result->abilityIconId_ = parcel.ReadUint32(); + result->launchedCount_ = parcel.ReadUint32(); + result->lastModuleUsedTime_ = parcel.ReadInt64(); + uint32_t size = parcel.ReadUint32(); + std::shared_ptr tmp = std::make_shared(); + for (uint32_t i = 0; i < size; i++) { + tmp = tmp->UnMarshalling(parcel); + if (!tmp) { + continue; + } + result->formRecords_.emplace_back(*tmp); + } + return result; +} + +bool BundleActiveModuleRecord::cmp(const BundleActiveModuleRecord& moduleRecordA, const BundleActiveModuleRecord& moduleRecordB) +{ + return moduleRecordA.lastModuleUsedTime_ > moduleRecordB.lastModuleUsedTime_; +} +} // namespace DeviceUsageStats +} // namespace OHOS + diff --git a/services/packageusage/src/bundle_active_package_stats.cpp b/services/packageusage/src/bundle_active_package_stats.cpp index aa09095..f43e081 100644 --- a/services/packageusage/src/bundle_active_package_stats.cpp +++ b/services/packageusage/src/bundle_active_package_stats.cpp @@ -253,7 +253,7 @@ bool BundleActivePackageStats::Marshalling(Parcel &parcel) const return false; } -std::shared_ptr BundleActivePackageStats::Unmarshalling(Parcel &parcel) +std::shared_ptr BundleActivePackageStats::UnMarshalling(Parcel &parcel) { std::shared_ptr result = std::make_shared(); result->bundleName_ = parcel.ReadString(); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index cf60fae..a1abc73 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -23,6 +23,7 @@ void BundleActiveUserService::Init(const int64_t timeStamp) database_.InitDatabaseTableInfo(timeStamp); BUNDLE_ACTIVE_LOGI("Init called"); LoadActiveStats(timeStamp, false, false); + database_.GetFormDataWhenInit(userId_, moduleRecords_); std::shared_ptr currentDailyStats = currentStats_[BundleActivePeriodStats::PERIOD_DAILY]; if (currentDailyStats != nullptr) { BundleActiveEvent startupEvent(BundleActiveEvent::STARTUP, timeStamp - ONE_SECOND_MILLISECONDS); @@ -172,6 +173,7 @@ void BundleActiveUserService::RestoreStats(bool forced) database_.UpdateUsageData(i, *(currentStats_[i])); } } + database_.UpdateModuleData(userId_, moduleRecords_); currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); statsChanged_ = false; BUNDLE_ACTIVE_LOGI("change statsChanged_ to %{public}d user is %{public}d", statsChanged_, userId_); @@ -185,9 +187,9 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo if (debugUserService_ == true) { tmpCalendar.ChangeToDebug(); } - tmpCalendar.SetMilliseconds(timeStamp); - tmpCalendar.TruncateTo(BundleActivePeriodStats::PERIOD_DAILY); for (uint32_t intervalType = 0; intervalType < periodLength_.size(); intervalType++) { + tmpCalendar.SetMilliseconds(timeStamp); + tmpCalendar.TruncateTo(static_cast(intervalType)); if (!force && currentStats_[intervalType] != nullptr && currentStats_[intervalType]->beginTime_ == tmpCalendar.GetMilliseconds()) { continue; @@ -375,6 +377,24 @@ std::vector BundleActiveUserService::QueryEvents(const int64_ return result; } +int BundleActiveUserService::QueryFormStatistics(int32_t maxNum, std::vector& results) +{ + for(auto oneModuleRecord = moduleRecords_.begin(); oneModuleRecord != moduleRecords_.end(); oneModuleRecord++) { + if (!oneModuleRecord->second) { + continue; + } + results.emplace_back(*(oneModuleRecord->second)); + } + std::sort(results.begin(), results.end(), BundleActiveModuleRecord::cmp); + if (static_cast(results.size()) < maxNum) { + results.resize(maxNum); + } + for (auto result : results) { + std::sort(result.formRecords_.begin(), result.formRecords_.end(), BundleActiveFormRecord::cmp); + } + return 0; +} + void BundleActiveUserService::PrintInMemPackageStats(const int idx) { BUNDLE_ACTIVE_LOGI("PrintInMemPackageStats called"); @@ -406,6 +426,37 @@ void BundleActiveUserService::PrintInMemEventStats() abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, timestamp); } } + +void BundleActiveUserService::ReportFormClickedOrRemoved(const BundleActiveEvent& event) +{ + auto moduleRecord = GetOrCreateModuleRecord(event); + if (event.eventId_ == BundleActiveEvent::FORM_IS_CLICKED && moduleRecord) { + if (!moduleRecord) { + return; + } + moduleRecord->UpdateModuleRecord(event.timeStamp_); + moduleRecord->AddOrUpdateOneFormRecord(event.formName_, event.formDimension_, event.formId_, event.timeStamp_); + NotifyStatsChanged(); + } else if (event.eventId_ == BundleActiveEvent::FORM_IS_REMOVED && moduleRecord) { + moduleRecord->RemoveOneFormRecord(event.formName_, event.formDimension_, event.formId_); + database_.RemoveFormData(userId_, event.formName_, event.formDimension_, event.formId_); + NotifyStatsChanged(); + } +} + +std::shared_ptr BundleActiveUserService::GetOrCreateModuleRecord(const BundleActiveEvent& event) +{ + std::string combinedInfo = event.bundleName_ + " " + event.moduleName_ + " " + event.modulePackage_; + auto it = moduleRecords_.find(combinedInfo); + if (it == moduleRecords_.end()) { + auto moduleRecordInserted = std::make_shared(); + moduleRecordInserted->bundleName_ = event.bundleName_; + moduleRecordInserted->moduleName_ = event.moduleName_; + moduleRecordInserted->modulePackage_ = event.modulePackage_; + moduleRecords_[combinedInfo] = moduleRecordInserted; + } + return moduleRecords_[combinedInfo]; +} } // namespace DeviceUsageStats } // namespace OHOS -- Gitee From 6af0c1f4997c3d1e4ebf2b89ec35b6bf2cc3af53 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 09:43:11 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=82=B9=E5=87=BB/=E5=88=A0=E9=99=A4=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8Cquery=E6=8E=A5=E5=8F=A3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=B1=82=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index e91e458..d2b3f4c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -35,9 +35,7 @@ ohos_shared_library("usagestatsinner") { "services/packageusage/src/bundle_active_event.cpp", "services/packageusage/src/bundle_active_package_stats.cpp", ] - public_configs = [ - ":usagestatsinner_public_config" - ] + public_configs = [ ":usagestatsinner_public_config" ] public_deps = [ ":usagestatservice" ] external_deps = [ "hiviewdfx_hilog_native:libhilog", -- Gitee From bce9317c90a1f3c78b07225f64e24ca1cecf879b Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 09:53:22 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=82=B9=E5=87=BB/=E5=88=A0=E9=99=A4=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8Cquery=E6=8E=A5=E5=8F=A3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=B1=82=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/include/bundle_active_client.h | 5 +++-- interfaces/innerkits/include/bundle_active_proxy.h | 5 +++-- interfaces/innerkits/src/bundle_active_client.cpp | 5 +++-- interfaces/innerkits/src/bundle_active_proxy.cpp | 5 +++-- services/common/include/bundle_active_service.h | 5 +++-- services/common/include/ibundle_active_service.h | 5 +++-- services/common/src/bundle_active_service.cpp | 5 +++-- services/common/src/bundle_active_usage_database.cpp | 3 ++- services/packageusage/src/bundle_active_form_record.cpp | 3 ++- services/packageusage/src/bundle_active_module_record.cpp | 3 ++- services/packageusage/src/bundle_active_user_service.cpp | 5 +++-- 11 files changed, 30 insertions(+), 19 deletions(-) diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index ff62dcb..46a7b61 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -26,8 +26,9 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActiveClient { public: - int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, - const int64_t formId, const int32_t formDimension, const int userId, const int eventId); + int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, + const std::string modulePackage, const std::string& formName, const int64_t formId, + const int32_t formDimension, const int userId, const int eventId); bool IsBundleIdle(const std::string& bundleName); std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode); diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index a58a874..f1b5397 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -26,8 +26,9 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActiveProxy : public IRemoteProxy { public: - int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, - const int64_t formId, const int32_t formDimension, const int userId, const int eventId) override; + int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, + const std::string modulePackage, const std::string& formName, const int64_t formId, + const int32_t formDimension, const int userId, const int eventId) override; bool IsBundleIdle(const std::string& bundleName) override; std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 8cf3c17..adac7af 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -45,8 +45,9 @@ bool BundleActiveClient::GetBundleActiveProxy() return true; } -int BundleActiveClient::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, - const int64_t formId, const int32_t formDimension, const int userId, const int eventId) +int BundleActiveClient::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, + const std::string modulePackage, const std::string& formName, const int64_t formId, + const int32_t formDimension, const int userId, const int eventId) { BUNDLE_ACTIVE_LOGI("BundleActiveClient::ReportEvent called"); if (!GetBundleActiveProxy()) { diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 5ecce91..ef99bd7 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -17,8 +17,9 @@ namespace OHOS { namespace DeviceUsageStats { -int BundleActiveProxy::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, - const int64_t formId, const int32_t formDimension, const int userId, const int eventId) +int BundleActiveProxy::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, + const std::string modulePackage, const std::string& formName, const int64_t formId, + const int32_t formDimension, const int userId, const int eventId) { MessageParcel data; MessageParcel reply; diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index 885da39..bd9f309 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -40,8 +40,9 @@ public: using ApplicationInfo = OHOS::AppExecFwk::ApplicationInfo; using ApplicationFlag = OHOS::AppExecFwk::ApplicationFlag; using AbilityType = OHOS::AppExecFwk::AbilityType; - int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, - const int64_t formId, const int32_t formDimension, const int userId, const int eventId) override; + int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, + const std::string modulePackage, const std::string& formName, const int64_t formId, + const int32_t formDimension, const int userId, const int eventId) override; bool IsBundleIdle(const std::string& bundleName) override; std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h index cebb7c6..dea9f7d 100644 --- a/services/common/include/ibundle_active_service.h +++ b/services/common/include/ibundle_active_service.h @@ -44,8 +44,9 @@ class BundleActiveModuleRecord; class IBundleActiveService : public IRemoteBroker { public: - virtual int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, - const int64_t formId, const int32_t formDimension, const int userId, const int eventId) = 0; + virtual int ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, + const std::string modulePackage, const std::string& formName, const int64_t formId, + const int32_t formDimension, const int userId, const int eventId) = 0; virtual bool IsBundleIdle(const std::string& bundleName) = 0; virtual std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) = 0; diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 3575896..ab97ae1 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -203,8 +203,9 @@ void BundleActiveService::OnStop() } -int BundleActiveService::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, const std::string modulePackage, const std::string& formName, - const int64_t formId, const int32_t formDimension, const int userId, const int eventId) +int BundleActiveService::ReportFormClickedOrRemoved(const std::string& bundleName, const std::string& moduleName, + const std::string modulePackage, const std::string& formName, const int64_t formId, + const int32_t formDimension, const int userId, const int eventId) { int callingUid = OHOS::IPCSkeleton::GetCallingUid(); if (!GetBundleMgrProxy()) { diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 01ac344..e8d0ac2 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1258,7 +1258,8 @@ int64_t BundleActiveUsageDatabase::GetSystemTimeMs() return static_cast(tarDate); } -void BundleActiveUsageDatabase::UpdateModuleData(int userId, std::map> moduleRecords_) +void BundleActiveUsageDatabase::UpdateModuleData(int userId, + std::map> moduleRecords_) { // mock } diff --git a/services/packageusage/src/bundle_active_form_record.cpp b/services/packageusage/src/bundle_active_form_record.cpp index c1e220e..0f7de8b 100644 --- a/services/packageusage/src/bundle_active_form_record.cpp +++ b/services/packageusage/src/bundle_active_form_record.cpp @@ -38,7 +38,8 @@ BundleActiveFormRecord::BundleActiveFormRecord(const std::string formName, const userId_ = userId; } -BundleActiveFormRecord::BundleActiveFormRecord(const BundleActiveFormRecord& orig) { +BundleActiveFormRecord::BundleActiveFormRecord(const BundleActiveFormRecord& orig) +{ formName_ = orig.formName_; formDimension_ = orig.formDimension_; formId_ = orig.formId_; diff --git a/services/packageusage/src/bundle_active_module_record.cpp b/services/packageusage/src/bundle_active_module_record.cpp index 87000f5..e99ce0e 100644 --- a/services/packageusage/src/bundle_active_module_record.cpp +++ b/services/packageusage/src/bundle_active_module_record.cpp @@ -121,7 +121,8 @@ std::shared_ptr BundleActiveModuleRecord::UnMarshallin return result; } -bool BundleActiveModuleRecord::cmp(const BundleActiveModuleRecord& moduleRecordA, const BundleActiveModuleRecord& moduleRecordB) +bool BundleActiveModuleRecord::cmp(const BundleActiveModuleRecord& moduleRecordA, + const BundleActiveModuleRecord& moduleRecordB) { return moduleRecordA.lastModuleUsedTime_ > moduleRecordB.lastModuleUsedTime_; } diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index a1abc73..8dc24c9 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -379,7 +379,7 @@ std::vector BundleActiveUserService::QueryEvents(const int64_ int BundleActiveUserService::QueryFormStatistics(int32_t maxNum, std::vector& results) { - for(auto oneModuleRecord = moduleRecords_.begin(); oneModuleRecord != moduleRecords_.end(); oneModuleRecord++) { + for (auto oneModuleRecord = moduleRecords_.begin(); oneModuleRecord != moduleRecords_.end(); oneModuleRecord++) { if (!oneModuleRecord->second) { continue; } @@ -444,7 +444,8 @@ void BundleActiveUserService::ReportFormClickedOrRemoved(const BundleActiveEvent } } -std::shared_ptr BundleActiveUserService::GetOrCreateModuleRecord(const BundleActiveEvent& event) +std::shared_ptr BundleActiveUserService::GetOrCreateModuleRecord( + const BundleActiveEvent& event) { std::string combinedInfo = event.bundleName_ + " " + event.moduleName_ + " " + event.modulePackage_; auto it = moduleRecords_.find(combinedInfo); -- Gitee From d86300d326a76c2c262bda3c166df77f31e5d805 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 10:00:22 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E7=82=B9=E5=87=BB/=E5=88=A0=E9=99=A4=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8Cquery=E6=8E=A5=E5=8F=A3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=B1=82=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/src/bundle_active_client.cpp | 3 ++- services/common/src/bundle_active_stub.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index adac7af..7a8562b 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -53,7 +53,8 @@ int BundleActiveClient::ReportFormClickedOrRemoved(const std::string& bundleName if (!GetBundleActiveProxy()) { return -1; } - return bundleActiveProxy_->ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, formDimension, userId, eventId); + return bundleActiveProxy_->ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, + formDimension, userId, eventId); } bool BundleActiveClient::IsBundleIdle(const std::string& bundleName) diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index 3d6f663..f69fd2e 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -36,7 +36,8 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me int32_t formDimension = data.ReadInt32(); int userId = data.ReadInt32(); int eventId = data.ReadInt32(); - int result = ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, formDimension, userId, eventId); + int result = ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, + formDimension, userId, eventId); return reply.WriteInt32(result); } case IS_BUNDLE_IDLE: { -- Gitee From ff3e5b238f2ef30a4aa984079163f0d9d7f34550 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 10:49:02 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E9=80=82=E9=85=8D=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- test/unittest/device_usage_statistics_test.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index bade742..f279ced 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -31,6 +31,11 @@ using namespace testing::ext; namespace OHOS { namespace DeviceUsageStats { static std::string DEFAULT_BUNDLENAME = "com.ohos.camera"; +static std::string DEFAULT_MODULENAME = "defaultmodulename"; +static std::string DEFAULT_MODULE = "defaultmodule"; +static std::string DEFAULT_FORM_NAME = "defaultformname"; +static int32_t DEFAULT_DIMENSION = 4; +static int64_t DEFAULT_FORMID = 1; static std::string DEFAULT_ABILITYID = "1234"; static std::string DEFAULT_ABILITYNAME = "testability"; static int DEFAULT_USERID = 0; @@ -85,12 +90,10 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_GetServiceObject_0 */ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_ReportEvent_001, Function | MediumTest | Level0) { - BundleActiveClient::GetInstance().ReportEvent(DEFAULT_BUNDLENAME, DEFAULT_ABILITYNAME, DEFAULT_ABILITYID, "", - DEFAULT_USERID, 2); - BundleActiveClient::GetInstance().ReportEvent(DEFAULT_BUNDLENAME, DEFAULT_ABILITYNAME, DEFAULT_ABILITYID, "", - DEFAULT_USERID, 3); - BundleActiveClient::GetInstance().ReportEvent(DEFAULT_BUNDLENAME, DEFAULT_ABILITYNAME, DEFAULT_ABILITYID, "", - DEFAULT_USERID, 4); + BundleActiveClient::GetInstance().ReportFormClickedOrRemoved(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, + DEFAULT_MODULE, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, DEFAULT_USERID, BundleActiveEvent::FORM_IS_CLICKED); + BundleActiveClient::GetInstance().ReportFormClickedOrRemoved(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, + DEFAULT_MODULE, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, DEFAULT_USERID, BundleActiveEvent::FORM_IS_REMOVED); } /* -- Gitee From 90fec7785d0b156395230a7cb5e3a0ac4c64fc9a Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 11:19:39 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E9=80=82=E9=85=8D=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- test/unittest/device_usage_statistics_test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index f279ced..943170a 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -91,9 +91,11 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_GetServiceObject_0 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_ReportEvent_001, Function | MediumTest | Level0) { BundleActiveClient::GetInstance().ReportFormClickedOrRemoved(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, - DEFAULT_MODULE, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, DEFAULT_USERID, BundleActiveEvent::FORM_IS_CLICKED); + DEFAULT_MODULE, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, DEFAULT_USERID, + BundleActiveEvent::FORM_IS_CLICKED); BundleActiveClient::GetInstance().ReportFormClickedOrRemoved(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, - DEFAULT_MODULE, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, DEFAULT_USERID, BundleActiveEvent::FORM_IS_REMOVED); + DEFAULT_MODULE, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, DEFAULT_USERID, + BundleActiveEvent::FORM_IS_REMOVED); } /* -- Gitee From 4a73f097a7418d851373f3da30fd554158ce9341 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 11:27:03 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9updatemodule=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_usage_database.h | 3 ++- services/common/src/bundle_active_usage_database.cpp | 4 ++-- services/packageusage/src/bundle_active_user_service.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index 4772fdf..64545d6 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -58,7 +58,8 @@ public: GetBundleHistoryData(int userId); void OnPackageUninstalled(const int userId, const std::string& bundleName); void ChangeToDebug(); - void UpdateModuleData(int userId, std::map> moduleRecords_); + void UpdateModuleData(const int userId, + std::map> moduleRecords_, const int64_t timeStamp); void RemoveFormData(const int userId, const std::string formName, const int32_t formDimension, const int64_t formId); void GetFormDataWhenInit(const int32_t userId, std::map(tarDate); } -void BundleActiveUsageDatabase::UpdateModuleData(int userId, - std::map> moduleRecords_) +void BundleActiveUsageDatabase::UpdateModuleData(const int userId, + std::map> moduleRecords_, const int64_t timeStamp); { // mock } diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 8dc24c9..0195a1d 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -173,7 +173,7 @@ void BundleActiveUserService::RestoreStats(bool forced) database_.UpdateUsageData(i, *(currentStats_[i])); } } - database_.UpdateModuleData(userId_, moduleRecords_); + database_.UpdateModuleData(userId_, moduleRecords_, currentStats_[BundleActivePeriodStats::PERIOD_DAILY]); currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); statsChanged_ = false; BUNDLE_ACTIVE_LOGI("change statsChanged_ to %{public}d user is %{public}d", statsChanged_, userId_); -- Gitee From c3820735b23ccfea4ec2c8dac02d41e7430c7f61 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 11:47:53 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9updatemodule=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packageusage/src/bundle_active_user_service.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 0195a1d..61dd24d 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -173,7 +173,8 @@ void BundleActiveUserService::RestoreStats(bool forced) database_.UpdateUsageData(i, *(currentStats_[i])); } } - database_.UpdateModuleData(userId_, moduleRecords_, currentStats_[BundleActivePeriodStats::PERIOD_DAILY]); + database_.UpdateModuleData(userId_, moduleRecords_, + currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->beginTime_); currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); statsChanged_ = false; BUNDLE_ACTIVE_LOGI("change statsChanged_ to %{public}d user is %{public}d", statsChanged_, userId_); -- Gitee From c412b46aaeb1dcdb0f5d1d0faece92f1a9a4c5c7 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 11:49:37 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9updatemodule=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packageusage/src/bundle_active_user_service.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 61dd24d..c6d10a6 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -430,6 +430,7 @@ void BundleActiveUserService::PrintInMemEventStats() void BundleActiveUserService::ReportFormClickedOrRemoved(const BundleActiveEvent& event) { + BUNDLE_ACTIVE_LOGI("ReportFormClickedOrRemoved called"); auto moduleRecord = GetOrCreateModuleRecord(event); if (event.eventId_ == BundleActiveEvent::FORM_IS_CLICKED && moduleRecord) { if (!moduleRecord) { -- Gitee From 64e5f0983d0498ca85700e7525121c1507cc9701 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Sat, 26 Mar 2022 11:56:13 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9updatemodule=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_usage_database.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 02a9a46..5455de5 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1259,7 +1259,7 @@ int64_t BundleActiveUsageDatabase::GetSystemTimeMs() } void BundleActiveUsageDatabase::UpdateModuleData(const int userId, - std::map> moduleRecords_, const int64_t timeStamp); + std::map> moduleRecords_, const int64_t timeStamp) { // mock } -- Gitee