From dfcd19e014b0882cc6597a107b4313522fc96818 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 29 Mar 2022 12:00:31 +0800 Subject: [PATCH 1/4] =?UTF-8?q?review=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8Cjs=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E5=86=85=E6=BA=90=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- frameworks/src/bundle_state_common.cpp | 97 ++++++++++++++++- frameworks/src/bundle_state_init.cpp | 3 +- frameworks/src/bundle_state_query.cpp | 92 ++++++++++++++++ .../innerkits/include/bundle_active_client.h | 57 +++++++++- .../innerkits/include/bundle_active_proxy.h | 53 ++++++++- .../innerkits/src/bundle_active_client.cpp | 7 +- .../innerkits/src/bundle_active_proxy.cpp | 17 +-- .../napi/include/bundle_state_common.h | 3 + .../napi/include/bundle_state_data.h | 14 +++ .../napi/include/bundle_state_inner_errors.h | 1 + .../napi/include/bundle_state_query.h | 1 + services/common/include/bundle_active_core.h | 4 +- .../common/include/bundle_active_service.h | 58 ++++++++-- services/common/include/bundle_active_stub.h | 11 ++ .../include/bundle_active_usage_database.h | 4 +- .../common/include/ibundle_active_service.h | 49 ++++++++- .../src/bundle_active_app_state_obsever.cpp | 6 +- ...bundle_active_continuous_task_observer.cpp | 12 +-- services/common/src/bundle_active_core.cpp | 11 +- services/common/src/bundle_active_service.cpp | 47 +++----- services/common/src/bundle_active_stub.cpp | 17 ++- .../src/bundle_active_usage_database.cpp | 4 +- .../include/bundle_active_user_history.h | 2 +- .../src/bundle_active_user_history.cpp | 4 +- .../include/bundle_active_event.h | 50 ++++++++- .../include/bundle_active_event_list.h | 26 +++++ .../include/bundle_active_event_stats.h | 35 ++++++ .../include/bundle_active_form_record.h | 51 ++++++++- .../include/bundle_active_module_record.h | 5 +- .../include/bundle_active_package_stats.h | 101 +++++++++++------- .../include/bundle_active_period_stats.h | 46 +++++++- .../include/bundle_active_user_service.h | 3 +- .../packageusage/src/bundle_active_event.cpp | 90 +++++++++++++--- .../src/bundle_active_package_stats.cpp | 45 -------- .../src/bundle_active_period_stats.cpp | 10 -- .../src/bundle_active_user_service.cpp | 28 ++++- .../unittest/device_usage_statistics_test.cpp | 12 +-- 37 files changed, 841 insertions(+), 235 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index ef198cf..fc3896f 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -138,6 +138,100 @@ void BundleStateCommon::GetBundleStateInfoForResult(napi_env env, } } +void BundleStateCommon::GetModuleRecordForResult(napi_env env, + const std::vector &moduleRecords, napi_value result) +{ + int32_t index = 0; + for (const auto &item : moduleRecords) { + napi_value moduleObject = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &moduleObject)); + napi_value bundleName = nullptr; + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, item.bundleName_.c_str(), NAPI_AUTO_LENGTH, &bundleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "bundleName", bundleName)); + + napi_value appLabelId = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.appLabelId_, &appLabelId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "appLabelId", appLabelId)); + + napi_value moduleName = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, item.moduleName_.c_str(), NAPI_AUTO_LENGTH, + &moduleName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "name", moduleName)); + + napi_value labelId = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.labelId_, &labelId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "labelId", labelId)); + + napi_value descriptionId = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.descriptionId_, &descriptionId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "descriptionId", descriptionId)); + + napi_value abilityName = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, item.abilityName_.c_str(), NAPI_AUTO_LENGTH, + &abilityName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityName", abilityName)); + + napi_value abilityLableId = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.abilityLableId_, &abilityLableId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityLableId", abilityLableId)); + + napi_value abilityDescriptionId = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.abilityDescriptionId_, &abilityDescriptionId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityDescriptionId", + abilityDescriptionId)); + + napi_value abilityIconId = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.abilityIconId_, &abilityIconId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityIconId", abilityIconId)); + + napi_value launchedCount = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.launchedCount_, &launchedCount)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "launchedCount", launchedCount)); + + napi_value lastModuleUsedTime = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.lastModuleUsedTime_, &lastModuleUsedTime)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "lastLaunchTime", lastModuleUsedTime)); + + napi_value removed = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.removed_, &removed)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "isRemoved", removed)); + + napi_value formRecords = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &formRecords)); + int32_t formIdx = 0; + for (const auto& oneFormRecord : item.formRecords_) { + napi_value formObject = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &formObject)); + napi_value formName = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneFormRecord.formName_.c_str(), NAPI_AUTO_LENGTH, + &formName)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, formObject, "formName", formName)); + + napi_value formDimension = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, oneFormRecord.formDimension_, &formDimension)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, formObject, "formDimension", formDimension)); + + napi_value formId = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, oneFormRecord.formId_, &formId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, formObject, "formId", formId)); + + napi_value formLastUsedTime = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, oneFormRecord.formLastUsedTime_, &formLastUsedTime)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, formObject, "formLastUsedTime", formLastUsedTime)); + + napi_value count = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, oneFormRecord.count_, &count)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, formObject, "formTouchedCount", count)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, formRecords, formIdx, formObject)); + formIdx++; + } + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "formRecords", formRecords)); + NAPI_CALL_RETURN_VOID(env, napi_set_element(env, result, index, moduleObject)); + index++; + } +} + void BundleStateCommon::SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, const napi_value &result, const int &errorCode) { @@ -150,9 +244,6 @@ void BundleStateCommon::SetPromiseInfo(const napi_env &env, const napi_deferred napi_value BundleStateCommon::GetErrorValue(napi_env env, int errCode) { - if (errCode == ERR_OK) { - return NapiGetNull(env); - } napi_value result = nullptr; napi_value eCode = nullptr; NAPI_CALL(env, napi_create_int32(env, errCode, &eCode)); diff --git a/frameworks/src/bundle_state_init.cpp b/frameworks/src/bundle_state_init.cpp index 3e7955d..074b173 100644 --- a/frameworks/src/bundle_state_init.cpp +++ b/frameworks/src/bundle_state_init.cpp @@ -39,7 +39,8 @@ static napi_value BundleStateInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("queryCurrentBundleActiveStates", QueryCurrentBundleActiveStates), DECLARE_NAPI_FUNCTION("queryBundleActiveStates", QueryBundleActiveStates), DECLARE_NAPI_FUNCTION("queryBundleStateInfoByInterval", QueryBundleStateInfoByInterval), - DECLARE_NAPI_FUNCTION("queryBundleStateInfos", QueryBundleStateInfos) + DECLARE_NAPI_FUNCTION("queryBundleStateInfos", QueryBundleStateInfos), + DECLARE_NAPI_FUNCTION("getModuleUsageRecords", GetModuleUsageRecords) }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 35ae3d8..41e3c96 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -33,9 +33,101 @@ const u_int32_t APP_USAGE_MIN_PARAMS_BY_INTERVAL = 3; const u_int32_t APP_USAGE_PARAMS_BY_INTERVAL = 4; const u_int32_t APP_USAGE_MIN_PARAMS = 2; const u_int32_t APP_USAGE_PARAMS = 3; +const u_int32_t MODULE_RECORDS_MIN_PARAMS = 1; +const u_int32_t MODULE_RECORDS_PARAMS = 2; const u_int32_t SECOND_ARG = 2; const u_int32_t THIRD_ARG = 3; +napi_value ParseModuleRecordsParameters(const napi_env &env, const napi_callback_info &info, + ModuleRecordParamsInfo ¶ms) +{ + size_t argc = MODULE_RECORDS_PARAMS; + napi_value argv[MODULE_RECORDS_PARAMS] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); + NAPI_ASSERT(env, argc == MODULE_RECORDS_MIN_PARAMS || argc == MODULE_RECORDS_PARAMS, + "Invalid number of parameters"); + + // argv[0] : maxNum + if (BundleStateCommon::GetInt32NumberValue(env, argv[0], params.maxNum) == nullptr) { + BUNDLE_ACTIVE_LOGE("ParseModuleRecordsParameters failed, beginTime type is invalid."); + params.errorCode = ERR_MODULE_STATS_MAXNUM_INVALID; + } + + // argv[1] : callback + if (argc == MODULE_RECORDS_PARAMS) { + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_function, + "ParseModuleRecordsParameters invalid parameter type, function expected."); + napi_create_reference(env, argv[1], 1, ¶ms.callback); + } + return BundleStateCommon::NapiGetNull(env); +} + +napi_value GetModuleUsageRecords(napi_env env, napi_callback_info info) +{ + ModuleRecordParamsInfo params; + ParseModuleRecordsParameters(env, info, params); + if (params.errorCode != ERR_OK) { + return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + } + napi_value promise = nullptr; + AsyncCallbackInfoModuleRecord *asyncCallbackInfo = + new (std::nothrow) AsyncCallbackInfoModuleRecord; + if (!asyncCallbackInfo) { + params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; + return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + } + if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoModuleRecord), 0, + sizeof(AsyncCallbackInfoModuleRecord)) != EOK) { + params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; + return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + } + asyncCallbackInfo->env = env; + asyncCallbackInfo->asyncWork = nullptr; + asyncCallbackInfo->maxNum = params.maxNum; + BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "GetModuleUsageRecords", NAPI_AUTO_LENGTH, &resourceName); + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + AsyncCallbackInfoModuleRecord *asyncCallbackInfo = (AsyncCallbackInfoModuleRecord *)data; + if (asyncCallbackInfo != nullptr) { + asyncCallbackInfo->info.errorCode = + BundleActiveClient::GetInstance().QueryFormStatistics(asyncCallbackInfo->maxNum, asyncCallbackInfo->moduleRecords); + } else { + BUNDLE_ACTIVE_LOGE("QueryBundleStateInfoByInterval, asyncCallbackInfo == nullptr"); + } + }, + [](napi_env env, napi_status status, void *data) { + AsyncCallbackInfoModuleRecord *asyncCallbackInfo = (AsyncCallbackInfoModuleRecord *)data; + if (asyncCallbackInfo != nullptr) { + napi_value result = nullptr; + napi_create_array(env, &result); + BundleStateCommon::GetModuleRecordForResult(env, asyncCallbackInfo->moduleRecords, result); + BundleStateCommon::GetCallbackPromiseResult(env, asyncCallbackInfo->info, result); + + if (asyncCallbackInfo->info.callback != nullptr) { + napi_delete_reference(env, asyncCallbackInfo->info.callback); + } + + napi_delete_async_work(env, asyncCallbackInfo->asyncWork); + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; + } + }, + (void *)asyncCallbackInfo, + &asyncCallbackInfo->asyncWork); + NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); + if (asyncCallbackInfo->info.isCallback) { + return BundleStateCommon::NapiGetNull(env); + } else { + return promise; + } +} + napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_info &info, IsIdleStateParamsInfo ¶ms) { diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 46a7b61..5fa5b7e 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -26,21 +26,72 @@ 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); + /* + * function: ReportEvent, used to report event. + * parameters: event, userId + * return: errorcode. + */ + int ReportEvent(BundleActiveEvent event, const int userId); + /* + * function: IsBundleIdle, used to check whether specific bundle is idle. + * parameters: bundleName + * return: if bundle is idle, return true. if bundle is not idle, return false. + */ bool IsBundleIdle(const std::string& bundleName); + /* + * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of bundle usage statistics. + */ std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode); + /* + * function: QueryEvents, query all events in specific time span for calling user. + * parameters: beginTime, endTime, errCode + * return: vector of events. + */ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode); + /* + * function: SetBundleGroup, set specific bundle of specific user to a priority group. + * parameters: bundleName, newGroup, userId + */ void SetBundleGroup(std::string bundleName, const int newGroup, const int userId); + /* + * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of calling bundle usage statistics. + */ std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime); + /* + * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. + * parameters: beginTime, endTime, errCode + * return: vector of calling bundle events. + */ std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime); + /* + * function: QueryPackageGroup, query bundle priority group calling bundle. + * return: the priority group of calling bundle. + */ int QueryPackageGroup(); + /* + * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. + * parameters: maxNum + * return: errorcode. + */ int QueryFormStatistics(int32_t maxNum, std::vector& results); + /* + * function: GetInstance, get instance of client. + * return: object of BundleActiveClient. + */ static BundleActiveClient& GetInstance(); + /* + * function: BundleActiveClient, default constructor. + */ BundleActiveClient() {} + /* + * function: ~BundleActiveClient, default destructor. + */ ~BundleActiveClient() {} private: diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index f1b5397..2c55c43 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -26,22 +26,69 @@ 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; + /* + * function: ReportEvent, used to report event. + * parameters: event, userId + * return: errorcode. + */ + int ReportEvent(BundleActiveEvent& event, const int userId) override; + /* + * function: IsBundleIdle, used to check whether specific bundle is idle. + * parameters: bundleName + * return: if bundle is idle, return true. if bundle is not idle, return false. + */ bool IsBundleIdle(const std::string& bundleName) override; + /* + * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of bundle usage statistics. + */ std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; + /* + * function: QueryEvents, query all events in specific time span for calling user. + * parameters: beginTime, endTime, errCode + * return: vector of events. + */ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; + /* + * function: SetBundleGroup, set specific bundle of specific user to a priority group. + * parameters: bundleName, newGroup, userId + */ void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override; + /* + * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of calling bundle usage statistics. + */ std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime) override; + /* + * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. + * parameters: beginTime, endTime, errCode + * return: vector of calling bundle events. + */ std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) override; + /* + * function: QueryPackageGroup, query bundle priority group calling bundle. + * return: the priority group of calling bundle. + */ int QueryPackageGroup() override; + /* + * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. + * parameters: maxNum + * return: errorcode. + */ int QueryFormStatistics(int32_t maxNum, std::vector& results) override; + /* + * function: BundleActiveProxy, default constructor. + */ explicit BundleActiveProxy(const sptr& impl) : IRemoteProxy(impl) {} + /* + * function: ~BundleActiveProxy, default destructor. + */ virtual ~BundleActiveProxy() {} private: diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 7a8562b..97a98eb 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -45,16 +45,13 @@ 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::ReportEvent(BundleActiveEvent event, const int userId) { BUNDLE_ACTIVE_LOGI("BundleActiveClient::ReportEvent called"); if (!GetBundleActiveProxy()) { return -1; } - return bundleActiveProxy_->ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, - formDimension, userId, eventId); + return bundleActiveProxy_->ReportEvent(event, userId); } bool BundleActiveClient::IsBundleIdle(const std::string& bundleName) diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index ef99bd7..440e8e6 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -17,9 +17,7 @@ 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::ReportEvent(BundleActiveEvent& event, const int userId) { MessageParcel data; MessageParcel reply; @@ -27,15 +25,9 @@ int BundleActiveProxy::ReportFormClickedOrRemoved(const std::string& bundleName, if (!data.WriteInterfaceToken(GetDescriptor())) { return -1; } - data.WriteString(bundleName); - data.WriteString(moduleName); - data.WriteString(modulePackage); - data.WriteString(formName); - data.WriteInt64(formId); - data.WriteInt32(formDimension); data.WriteInt32(userId); - data.WriteInt32(eventId); - Remote() -> SendRequest(REPORT_FORM_EVENT, data, reply, option); + event.Marshalling(data); + Remote() -> SendRequest(REPORT_EVENT, data, reply, option); int32_t result = reply.ReadInt32(); return result; @@ -116,8 +108,7 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi result.push_back(*tmp); } for (uint32_t i = 0; i < result.size(); i++) { - BUNDLE_ACTIVE_LOGI("QueryEvents event id is %{public}d, bundle name is %{public}s, " - "time stamp is %{public}lld", result[i].eventId_, result[i].bundleName_.c_str(), result[i].timeStamp_); + result[i].PrintEvent(); } return result; } diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index 481f3b8..1153a02 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -53,6 +53,9 @@ public: static void GetBundleStateInfoForResult(napi_env env, const std::shared_ptr> &packageStats, napi_value result); + static void GetModuleRecordForResult(napi_env env, + const std::vector &moduleRecords, napi_value result); + static void SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, const napi_value &result, const int &errorCode); diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h index 428c4ed..a7c6358 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h @@ -93,6 +93,14 @@ struct AsyncCallbackInfoAppUsage { CallbackPromiseInfo info; }; +struct AsyncCallbackInfoModuleRecord { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + int32_t maxNum; + std::vector moduleRecords; + CallbackPromiseInfo info; +}; + struct IsIdleStateParamsInfo { std::string bundleName; napi_ref callback = nullptr; @@ -125,6 +133,12 @@ struct AppUsageParamsInfo { napi_ref callback = nullptr; int errorCode = 0; }; + +struct ModuleRecordParamsInfo { + int32_t maxNum; + napi_ref callback = nullptr; + int errorCode = 0; +}; } // namespace DeviceUsageStats } // namespace OHOS #endif // FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_DATA_H diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h index e4de782..5e5669a 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h @@ -49,6 +49,7 @@ enum : int { ERR_USAGE_STATS_TIME_INTERVAL, ERR_USAGE_STATS_INTERVAL_TYPE, ERR_USAGE_STATS_INTERVAL_NUMBER, + ERR_MODULE_STATS_MAXNUM_INVALID, }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_query.h b/interfaces/kits/bundlestats/napi/include/bundle_state_query.h index f893d7c..60a0071 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_query.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_query.h @@ -27,6 +27,7 @@ namespace DeviceUsageStats { napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info); napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info); napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info); + napi_value GetModuleUsageRecords(napi_env env, napi_callback_info info); } // namespace DeviceUsageStats } // namespace OHOS #endif // FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_QUERY_H diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 2e1a870..9fd2de2 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -119,13 +119,15 @@ public: const int64_t timeStamp, const bool debug); // when received a USER_REMOVED commen event, call it to remove data. void OnUserRemoved(const int userId); + // when user switched, restore old userdata. void OnUserSwitched(const int userId); // force set app group. void SetBundleGroup(const std::string& bundleName, const int newGroup, const int userId); - // get all user in device + // get all user in device. void GetAllActiveUser(std::vector& activatedOsAccountIds); // when service stop, call it to unregister commen event and shutdown call back. void UnRegisterSubscriber(); + // get system time in MS. int64_t GetSystemTimeMs(); int currentUsedUser_; diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index bd9f309..be95c8b 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -40,22 +40,69 @@ 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; + /* + * function: ReportEvent, used to report event. + * parameters: event, userId + * return: errorcode. + */ + int ReportEvent(BundleActiveEvent& event, const int userId) override; + /* + * function: IsBundleIdle, used to check whether specific bundle is idle. + * parameters: bundleName + * return: if bundle is idle, return true. if bundle is not idle, return false. + */ bool IsBundleIdle(const std::string& bundleName) override; + /* + * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of bundle usage statistics. + */ std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; + /* + * function: QueryEvents, query all events in specific time span for calling user. + * parameters: beginTime, endTime, errCode + * return: vector of events. + */ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) override; + /* + * function: SetBundleGroup, set specific bundle of specific user to a priority group. + * parameters: bundleName, newGroup, userId + */ void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) override; + /* + * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of calling bundle usage statistics. + */ std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime) override; + /* + * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. + * parameters: beginTime, endTime, errCode + * return: vector of calling bundle events. + */ std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) override; + /* + * function: QueryPackageGroup, query bundle priority group calling bundle. + * return: the priority group of calling bundle. + */ int QueryPackageGroup() override; + /* + * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. + * parameters: maxNum + * return: errorcode. + */ int QueryFormStatistics(int32_t maxNum, std::vector& results) override; + /* + * function: BundleActiveService, default constructor. + */ BundleActiveService(int32_t systemAbilityId, int runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) {} + /* + * function: ~BundleActiveService, default destructor. + */ ~BundleActiveService() {} protected: @@ -81,9 +128,8 @@ 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, + void QueryModuleRecordInfos(BundleActiveModuleRecord& moduleRecord); + void SerModuleProperties(const HapModuleInfo& hapModuleInfo, const ApplicationInfo& appInfo, const AbilityInfo& abilityInfo, BundleActiveModuleRecord& moduleRecord); }; } // namespace DeviceUsageStats diff --git a/services/common/include/bundle_active_stub.h b/services/common/include/bundle_active_stub.h index 51164a1..106ca68 100644 --- a/services/common/include/bundle_active_stub.h +++ b/services/common/include/bundle_active_stub.h @@ -22,9 +22,20 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActiveStub : public IRemoteStub { public: + /* + * function: OnRemoteRequest, handle message from proxy. + * parameters: code, data, reply, option + * return: errorcode. + */ int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) override; + /* + * function: BundleActiveStub, default constructor. + */ BundleActiveStub() {} + /* + * function: ~BundleActiveStub, default constructor. + */ ~BundleActiveStub() {} }; } // namespace DeviceUsageStats diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index 64545d6..5281d34 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -59,10 +59,10 @@ public: void OnPackageUninstalled(const int userId, const std::string& bundleName); void ChangeToDebug(); void UpdateModuleData(const int userId, - std::map> moduleRecords_, const int64_t timeStamp); + 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>& moduleRecords); private: diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h index dea9f7d..9b0b9ed 100644 --- a/services/common/include/ibundle_active_service.h +++ b/services/common/include/ibundle_active_service.h @@ -44,24 +44,65 @@ 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; + /* + * function: ReportEvent, used to report event. + * parameters: event, userId + * return: errorcode. + */ + virtual int ReportEvent(BundleActiveEvent& event, const int userId) = 0; + /* + * function: IsBundleIdle, used to check whether specific bundle is idle. + * parameters: bundleName + * return: if bundle is idle, return true. if bundle is not idle, return false. + */ virtual bool IsBundleIdle(const std::string& bundleName) = 0; + /* + * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of bundle usage statistics. + */ virtual std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime, int32_t& errCode) = 0; + /* + * function: QueryEvents, query all events in specific time span for calling user. + * parameters: beginTime, endTime, errCode + * return: vector of events. + */ virtual std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode) = 0; + /* + * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. + * parameters: intervalType, beginTime, endTime, errCode + * return: vector of calling bundle usage statistics. + */ virtual std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, const int64_t endTime) = 0; + /* + * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. + * parameters: beginTime, endTime, errCode + * return: vector of calling bundle events. + */ virtual std::vector QueryCurrentEvents(const int64_t beginTime, const int64_t endTime) = 0; + /* + * function: QueryPackageGroup, query bundle priority group calling bundle. + * return: the priority group of calling bundle. + */ virtual int QueryPackageGroup() = 0; + /* + * function: SetBundleGroup, set specific bundle of specific user to a priority group. + * parameters: bundleName, newGroup, userId + */ virtual void SetBundleGroup(const std::string& bundleName, int newGroup, int userId) = 0; + /* + * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. + * parameters: maxNum + * return: errorcode. + */ virtual int QueryFormStatistics(int32_t maxNum, std::vector& results) = 0; public: enum { - REPORT_FORM_EVENT = 1, + REPORT_EVENT = 1, IS_BUNDLE_IDLE = 2, QUERY_USAGE_STATS = 3, QUERY_EVENTS = 4, diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp index 5f3a951..58ff1a6 100644 --- a/services/common/src/bundle_active_app_state_obsever.cpp +++ b/services/common/src/bundle_active_app_state_obsever.cpp @@ -45,10 +45,8 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData stream << abilityStateData.token.GetRefPtr(); std::string abilityId = stream.str(); BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); - tmpHandlerObject.event_.bundleName_ = abilityStateData.bundleName; - tmpHandlerObject.event_.abilityName_ = abilityStateData.abilityName; - tmpHandlerObject.event_.abilityId_ = abilityStateData.abilityName; - tmpHandlerObject.event_.continuousTaskAbilityName_ = ""; + BundleActiveEvent event(abilityStateData.bundleName, abilityStateData.abilityName, abilityStateData.abilityName); + tmpHandlerObject.event_ = event; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); switch (abilityStateData.abilityState) { diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index 1298b46..d8e6e3b 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -76,8 +76,7 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( { int uid = continuousTaskCallbackInfo->GetCreatorUid(); int pid = continuousTaskCallbackInfo->GetCreatorPid(); - std::string abiliytName = continuousTaskCallbackInfo->GetAbilityName(); - std::string abilityId = ""; + std::string continuousTaskAbilityName_ = continuousTaskCallbackInfo->GetAbilityName(); int userId = -1; std::string bundleName = ""; if (GetBundleMgr()) { @@ -89,10 +88,7 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (ret == ERR_OK && userId != -1 && !bundleName.empty()) { BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); - tmpHandlerObject.event_.bundleName_ = bundleName; - tmpHandlerObject.event_.abilityName_ = ""; - tmpHandlerObject.event_.abilityId_ = abilityId; - tmpHandlerObject.event_.continuousTaskAbilityName_ = abiliytName; + BundleActiveEvent event(bundleName, continuousTaskAbilityName_); sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); if (isStart) { @@ -101,10 +97,10 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( tmpHandlerObject.event_.eventId_ = BundleActiveEvent::LONG_TIME_TASK_ENDED; } BUNDLE_ACTIVE_LOGI("OnContinuousTaskStart id is %{public}d, bundle name is %{public}s, " - "ability name is %{public}s, ability id is %{public}s, event id is %{public}d," + "ability name is %{public}s, event id is %{public}d," "uid is %{public}d, pid is %{public}d", tmpHandlerObject.userId_, tmpHandlerObject.event_.bundleName_.c_str(), - tmpHandlerObject.event_.abilityName_.c_str(), abilityId.c_str(), tmpHandlerObject.event_.eventId_, + tmpHandlerObject.event_.continuousTaskAbilityName_.c_str(), tmpHandlerObject.event_.eventId_, uid, pid); if (reportHandler_ != nullptr) { BUNDLE_ACTIVE_LOGI("BundleActiveAppStateObserver::OnAbilityStateChanged handler not null, SEND"); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 6f67c08..49a3efa 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -38,12 +38,7 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const int userI BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig) { - event_.bundleName_ = orig.event_.bundleName_; - event_.abilityName_ = orig.event_.abilityName_; - event_.abilityId_ = orig.event_.abilityId_; - event_.timeStamp_ = orig.event_.timeStamp_; - event_.eventId_ = orig.event_.eventId_; - event_.continuousTaskAbilityName_ = orig.event_.continuousTaskAbilityName_; + event_ = orig.event_; userId_ = orig.userId_; bundleName_ = orig.bundleName_; } @@ -430,7 +425,7 @@ int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) return 0; } - BUNDLE_ACTIVE_LOGI("report event called bundle name %{public}s time %{public}lld userId %{public}d, " + BUNDLE_ACTIVE_LOGI("report event called, bundle name %{public}s time %{public}lld userId %{public}d, " "eventid %{public}d, in lock range", event.bundleName_.c_str(), event.timeStamp_, userId, event.eventId_); int64_t timeNow = CheckTimeChangeAndGetWallTime(userId); if (timeNow == -1) { @@ -444,7 +439,7 @@ int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) } if (event.eventId_ == BundleActiveEvent::FORM_IS_CLICKED || event.eventId_ == BundleActiveEvent::FORM_IS_REMOVED) { - service->ReportFormClickedOrRemoved(event); + service->ReportFormEvent(event); return 0; } service->ReportEvent(event); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index ab97ae1..29b8154 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -30,8 +30,6 @@ 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"; @@ -203,25 +201,12 @@ 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::ReportEvent(BundleActiveEvent& event, const int userId) { - 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) { + AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + if ((AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE)) { 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; + tmpHandlerObject.event_ = event; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); std::shared_ptr handlerobjToPtr = @@ -230,6 +215,7 @@ int BundleActiveService::ReportFormClickedOrRemoved(const std::string& bundleNam reportHandler_->SendEvent(event); return 0; } else { + BUNDLE_ACTIVE_LOGE("token does not belong to native process, return"); return -1; } } @@ -459,32 +445,31 @@ int BundleActiveService::QueryFormStatistics(int32_t maxNum, std::vectorQueryFormStatistics(maxNum, results, userId); + for (auto& oneResult : results) { + QueryModuleRecordInfos(oneResult); + } } } return errCode; } -void BundleActiveService::GetAndSetModuleRecordInfos(BundleInfo& bundleInfo, HapModuleInfo& hapModuleInfo, - ApplicationInfo& appInfo, AbilityInfo& abilityInfo, BundleActiveModuleRecord& moduleRecord) +void BundleActiveService::QueryModuleRecordInfos(BundleActiveModuleRecord& moduleRecord) { if (!GetBundleMgrProxy()) { return; } + ApplicationInfo appInfo; 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!"); + BUNDLE_ACTIVE_LOGW("GetApplicationInfo failed!"); return; } AbilityInfo mockAbilityInfo; mockAbilityInfo.bundleName = moduleRecord.bundleName_; mockAbilityInfo.package = moduleRecord.modulePackage_; + HapModuleInfo hapModuleInfo; if (!sptrBundleMgr_->GetHapModuleInfo(mockAbilityInfo, hapModuleInfo)) { - BUNDLE_ACTIVE_LOGE("GetHapModuleInfo failed!"); + BUNDLE_ACTIVE_LOGW("GetHapModuleInfo failed!"); return; } std::string mainAbility = hapModuleInfo.mainAbility; @@ -493,15 +478,15 @@ void BundleActiveService::GetAndSetModuleRecordInfos(BundleInfo& bundleInfo, Hap if (oneAbilityInfo.type != AbilityType::PAGE) { continue; } - if (mainAbility.empty() || mainAbility.compare(abilityInfo.name) == 0) { - SerModuleProperties(bundleInfo, hapModuleInfo, appInfo, oneAbilityInfo, moduleRecord); + if (mainAbility.empty() || mainAbility.compare(oneAbilityInfo.name) == 0) { + SerModuleProperties(hapModuleInfo, appInfo, oneAbilityInfo, moduleRecord); break; } } } } -void BundleActiveService::SerModuleProperties(const BundleInfo& bundleInfo, const HapModuleInfo& hapModuleInfo, +void BundleActiveService::SerModuleProperties(const HapModuleInfo& hapModuleInfo, const ApplicationInfo& appInfo, const AbilityInfo& abilityInfo, BundleActiveModuleRecord& moduleRecord) { moduleRecord.deviceId_ = appInfo.deviceId; diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index f69fd2e..fb9fc83 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -27,17 +27,14 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me return -1; } switch (code) { - case REPORT_FORM_EVENT: { - std::string bundleName = 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(); + case REPORT_EVENT: { int userId = data.ReadInt32(); - int eventId = data.ReadInt32(); - int result = ReportFormClickedOrRemoved(bundleName, moduleName, modulePackage, formName, formId, - formDimension, userId, eventId); + std::shared_ptr tmpEvent; + tmpEvent = tmpEvent->UnMarshalling(data); + if (!tmpEvent) { + return -1; + } + int result = ReportEvent(*tmpEvent, userId); return reply.WriteInt32(result); } case IS_BUNDLE_IDLE: { diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 5455de5..058aad1 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 } @@ -1270,7 +1270,7 @@ void BundleActiveUsageDatabase::RemoveFormData(const int userId, const std::stri // mock } -void BundleActiveUsageDatabase::GetFormDataWhenInit(const int32_t userId, std::map>& moduleRecords) { // key: std::string combineInfo = bundlename + " " + modulePackage + " " + moduleName diff --git a/services/packagegroup/include/bundle_active_user_history.h b/services/packagegroup/include/bundle_active_user_history.h index 4b9e3c3..0aef910 100644 --- a/services/packagegroup/include/bundle_active_user_history.h +++ b/services/packagegroup/include/bundle_active_user_history.h @@ -55,7 +55,7 @@ public: const std::vector screenTimeLeve, const std::vector bootFromTimeLevel); void WriteDeviceDuration(); void WriteBundleUsage(const int userId); - void printdata(int userId); + void PrintData(int userId); void UpdateBootBasedAndScreenTime(const bool& isScreenOn, const int64_t bootBasedTimeStamp, const bool& isShutdown = false); private: diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index b06c8bc..6a6309a 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -229,10 +229,10 @@ void BundleActiveUserHistory::UpdateBootBasedAndScreenTime(const bool& isScreenO database_.PutDurationData(bootBasedDuration_, ScreenOnDuration_); } -void BundleActiveUserHistory::printdata(int userId) +void BundleActiveUserHistory::PrintData(int userId) { auto oneUserHistory = GetUserHistory(userId, false); - BUNDLE_ACTIVE_LOGI("printdata screen is %{public}d", isScreenOn_); + BUNDLE_ACTIVE_LOGI("PrintData screen is %{public}d", isScreenOn_); if (oneUserHistory == nullptr) { return; } diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index 00cd140..b435416 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -31,6 +31,7 @@ public: static const int SYSTEM_INTERACTIVE = 7; static const int USER_INTERACTIVE = 8; // internal events + static const int DEFAULT_EVENT_ID = 0; static const int END_OF_THE_DAY = 9; static const int SHUTDOWN = 10; static const int STARTUP = 11; @@ -56,15 +57,54 @@ public: int eventId_; public: + /* + * function: BundleActiveEvent, default constructor. + */ BundleActiveEvent(); + /* + * function: BundleActiveEvent, copy constructor. + * parameters: orig + */ BundleActiveEvent(const BundleActiveEvent& orig); + /* + * function: BundleActiveEvent, constructor using event Id, time stamp. + * parameters: eventId, timeStamp + */ BundleActiveEvent(int eventId, int64_t timeStamp); - std::string GetBundleName(); - std::string GetAbilityName(); - std::string GetAbilityId(); - int64_t GetTimeStamp(); - int GetEventId(); + /* + * function: BundleActiveEvent, constructor of continuous task event. + * parameters: bundleName, continuousTaskAbilityName + */ + BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName); + /* + * function: BundleActiveEvent, constructor of app ability event. + * parameters: bundleName, abilityName, abilityId + */ + BundleActiveEvent(const std::string bundleName, const std::string abilityName, const std::string abilityId); + /* + * function: BundleActiveEvent, constructor of form event. + * parameters: bundleName, moduleName, modulePackage, formName, formDimension, formId, eventId + */ + BundleActiveEvent(const std::string bundleName, const std::string moduleName, const std::string modulePackage, + const std::string formName, const int32_t formDimension, const int64_t formId, const int eventId); + void PrintEvent() const; + /* + * function: operator=, override operator =. + * parameters: orig + * return: a BundleActiveEvent object same as orig. + */ + BundleActiveEvent& operator=(const BundleActiveEvent& orig); + /* + * function: Marshalling, mashalling event object to parcel. + * parameters: parcel + * return: result of mashalling, true means successful, flase means failed. + */ virtual bool Marshalling(Parcel &parcel) const override; + /* + * function: UnMarshalling, Unmashalling event object from parcel. + * parameters: parcel + * return: point to a BundleActiveEvent. + */ std::shared_ptr UnMarshalling(Parcel &parcel); }; } // namespace DeviceUsageStats diff --git a/services/packageusage/include/bundle_active_event_list.h b/services/packageusage/include/bundle_active_event_list.h index 4a0a02d..32d3d6c 100644 --- a/services/packageusage/include/bundle_active_event_list.h +++ b/services/packageusage/include/bundle_active_event_list.h @@ -23,12 +23,38 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActiveEventList { public: + /* + * function: BundleActiveEventList, default constructor. + */ BundleActiveEventList(); + /* + * function: ~BundleActiveEventList, default destructor. + */ ~BundleActiveEventList() {} + /* + * function: Size, get size of member events_. + * return: size of member events_ + */ int Size(); + /* + * function: Clear, clear all event in member events_. + */ void Clear(); + /* + * function: Insert, insert a event to member events_. + * parameter: event + */ void Insert(BundleActiveEvent event); + /* + * function: FindBestIndex, find best index to insert event. + * parameters: timeStamp + * return: the index of inserting. + */ int FindBestIndex(const int64_t timeStamp); + /* + * function: Merge, merge two BundleActiveEventList. + * parameters: right + */ void Merge(const BundleActiveEventList& right); std::vector events_; }; diff --git a/services/packageusage/include/bundle_active_event_stats.h b/services/packageusage/include/bundle_active_event_stats.h index b15af31..13bc807 100644 --- a/services/packageusage/include/bundle_active_event_stats.h +++ b/services/packageusage/include/bundle_active_event_stats.h @@ -28,14 +28,49 @@ public: int64_t lastEventTime_; int64_t totalTime_; int count_; + /* + * function: BundleActiveEventStats, default constructor. + */ BundleActiveEventStats(); + /* + * function: BundleActiveEventStats, copy constructor. + * parameters: orig + */ BundleActiveEventStats(const BundleActiveEventStats& orig); + /* + * function: GetEventId, get eventId. + * return: member eventId_. + */ int GetEventId(); + /* + * function: GetFirstTimeStamp, get first time stamp. + * return: member beginTimeStamp_. + */ int GetFirstTimeStamp(); + /* + * function: GetLastTimeStamp, get last time stamp. + * return: member endTimeStamp_. + */ int GetLastTimeStamp(); + /* + * function: GetLastEventTime, get last event time. + * return: member lastEventTime_. + */ int GetLastEventTime(); + /* + * function: GetTotalTime, get total time. + * return: member totalTime_. + */ int GetTotalTime(); + /* + * function: GetCount, get count. + * return: member count_. + */ int GetCount(); + /* + * function: add, add statistics from another BundleActvieEventStats object. + * parameters: right + */ void add(const BundleActiveEventStats& right); }; } // namespace DeviceUsageStats diff --git a/services/packageusage/include/bundle_active_form_record.h b/services/packageusage/include/bundle_active_form_record.h index 5c482c9..cca2158 100644 --- a/services/packageusage/include/bundle_active_form_record.h +++ b/services/packageusage/include/bundle_active_form_record.h @@ -30,23 +30,68 @@ public: int64_t formLastUsedTime_; int32_t count_; int32_t userId_; - void UpdateFormRecord(const int64_t timeStamp); + +public: + /* + * function: BundleActiveFormRecord, copy constructor. + * parameters: orig + */ BundleActiveFormRecord(const BundleActiveFormRecord& orig); - virtual bool Marshalling(Parcel &parcel) const override; - std::shared_ptr UnMarshalling(Parcel &parcel); + /* + * function: BundleActiveFormRecord, default constructor. + */ BundleActiveFormRecord(); + /* + * function: BundleActiveFormRecord, use formName, formDimension, formId, timeStamp, userId to construct object. + * parameters: formName formDimension formId timeStamp userId + */ BundleActiveFormRecord(const std::string formName, const int32_t formDimension, const int64_t formId, const int64_t timeStamp, const int32_t userId); + /* + * function: ~BundleActiveFormRecord, default destructor. + */ ~BundleActiveFormRecord() {} + /* + * function: UpdateFormRecord, update form record by timestamp. + * parameters: timeStamp + */ + void UpdateFormRecord(const int64_t timeStamp); + /* + * function: operator==, override operator ==. + * parameters: formRecord + * return: true if the formId_ is same. + */ bool operator==(const BundleActiveFormRecord& formRecord) const { return (this->formId_ == formRecord.formId_); } + /* + * function: operator==, override operator ==. + * parameters: formId + * return: true if the formId_ is same. + */ bool operator==(const int64_t formId) const { return (this->formId_ == formId); } + /* + * function: cmp, compare two BundleActiveFormRecord. + * parameters: formRecordA formRecordB + * return: true if formRecordA.count_ > formRecordB. + */ static bool cmp(const BundleActiveFormRecord& formRecordA, const BundleActiveFormRecord& formRecordB); + /* + * function: Marshalling, mashalling form record object to parcel. + * parameters: parcel + * return: result of mashalling, true means successful, flase means failed. + */ + virtual bool Marshalling(Parcel &parcel) const override; + /* + * function: UnMarshalling, Unmashalling record object from parcel. + * parameters: parcel + * return: point to a BundleActiveFormRecord. + */ + std::shared_ptr UnMarshalling(Parcel &parcel); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/include/bundle_active_module_record.h b/services/packageusage/include/bundle_active_module_record.h index c154587..e3e6fe0 100644 --- a/services/packageusage/include/bundle_active_module_record.h +++ b/services/packageusage/include/bundle_active_module_record.h @@ -33,10 +33,11 @@ public: 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); + virtual bool Marshalling(Parcel &parcel) const override; + std::shared_ptr UnMarshalling(Parcel &parcel); + public: std::string deviceId_; std::string bundleName_; diff --git a/services/packageusage/include/bundle_active_package_stats.h b/services/packageusage/include/bundle_active_package_stats.h index 26af6d2..71ac47d 100644 --- a/services/packageusage/include/bundle_active_package_stats.h +++ b/services/packageusage/include/bundle_active_package_stats.h @@ -23,46 +23,71 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActivePackageStats : public Parcelable { public: - std::string bundleName_; - int64_t beginTimeStamp_; // start time of counting - int64_t endTimeStamp_; // stop time of counting - int64_t lastTimeUsed_; // the timestamp of last launch - int64_t totalInFrontTime_; // the total time of using the bundle - int64_t lastContiniousTaskUsed_; - int64_t totalContiniousTaskUsedTime_; - int startCount_; - int bundleStartedCount_; - int lastEvent_; - // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle. - std::map abilities_; - // key is name of continuous task, value is last event of this last continuous task. - std::map longTimeTasks_; - BundleActivePackageStats(); - ~BundleActivePackageStats() {} - BundleActivePackageStats(const BundleActivePackageStats& orig); - std::string GetBundleName(); - int64_t GetBeginTimeStamp(); - int64_t GetEntTimeStamp(); - int64_t GetLastTimeUsed(); - int64_t GetTotalTimeInFront(); - int64_t GetLastTimeFrontServiceUsed(); - int64_t GetTotalTimeFrontServiceUsed(); - int GetLaunchedCount(); - int GetBundleLaunchedCount(); - void Update(const std::string& longTimeTaskName, const int64_t timeStamp, const int eventId, - const std::string& abilityId); - void IncrementTimeUsed(const int64_t timeStamp); - void IncrementServiceTimeUsed(const int64_t timeStamp); - void IncrementBundleLaunchedCount(); - virtual bool Marshalling(Parcel &parcel) const override; - std::shared_ptr UnMarshalling(Parcel &parcel); - void printdata(); + std::string bundleName_; + int64_t beginTimeStamp_; // start time of counting + int64_t endTimeStamp_; // stop time of counting + int64_t lastTimeUsed_; // the timestamp of last launch + int64_t totalInFrontTime_; // the total time of using the bundle + int64_t lastContiniousTaskUsed_; + int64_t totalContiniousTaskUsedTime_; + int startCount_; + int bundleStartedCount_; + int lastEvent_; + // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle. + std::map abilities_; + // key is name of continuous task, value is last event of this last continuous task. + std::map longTimeTasks_; + /* + * function: BundleActivePackageStats, default constructor. + */ + BundleActivePackageStats(); + /* + * function: ~BundleActivePackageStats, default destructor. + */ + ~BundleActivePackageStats() {} + /* + * function: BundleActivePackageStats, copy constructor. + * parameters: orig + */ + BundleActivePackageStats(const BundleActivePackageStats& orig); + /* + * function: Update, update one bundle statistics. + * parameters: longTimeTaskName timeStamp eventId abilityId + */ + void Update(const std::string& longTimeTaskName, const int64_t timeStamp, const int eventId, + const std::string& abilityId); + /* + * function: IncrementTimeUsed, increase bundle's use time. + * parameters: timeStamp + */ + void IncrementTimeUsed(const int64_t timeStamp); + /* + * function: IncrementServiceTimeUsed, increase bundle's continuous task use time. + * parameters: timeStamp + */ + void IncrementServiceTimeUsed(const int64_t timeStamp); + /* + * function: IncrementBundleLaunchedCount, increase bundle's launched times by 1. + */ + void IncrementBundleLaunchedCount(); + /* + * function: Marshalling, mashalling BundleActivePackageStats object to parcel. + * parameters: parcel + * return: result of mashalling, true means successful, flase means failed. + */ + virtual bool Marshalling(Parcel &parcel) const override; + /* + * function: UnMarshalling, Unmashalling BundleActivePackageStats object from parcel. + * parameters: parcel + * return: point to a BundleActivePackageStats. + */ + std::shared_ptr UnMarshalling(Parcel &parcel); private: - bool HasFrontAbility(); - bool AnyLongTimeTaskStarted(); - void UpdateAbility(const int64_t timeStamp, const int eventId, const std::string& abilityId); - void UpdateLongTimeTask(const std::string& longTimeTaskName, const int64_t timeStamp, const int eventId); + bool HasFrontAbility(); + bool AnyLongTimeTaskStarted(); + void UpdateAbility(const int64_t timeStamp, const int eventId, const std::string& abilityId); + void UpdateLongTimeTask(const std::string& longTimeTaskName, const int64_t timeStamp, const int eventId); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/include/bundle_active_period_stats.h b/services/packageusage/include/bundle_active_period_stats.h index 3a7a317..72646b7 100644 --- a/services/packageusage/include/bundle_active_period_stats.h +++ b/services/packageusage/include/bundle_active_period_stats.h @@ -46,18 +46,62 @@ public: BundleActiveEventTracker noninteractiveTracker_; BundleActiveEventTracker keyguardShownTracker_; BundleActiveEventTracker keyguardHiddenTracker_; + /* + * function: BundleActivePeriodStats,default constructor. + */ BundleActivePeriodStats(); + /* + * function: GetOrCreateUsageStats, get or create bundle usage statistics object of a bundle. + * parameters: bundleName + * return: point to bundle usage statistics object. + */ std::shared_ptr GetOrCreateUsageStats(const std::string& bundleName); - BundleActiveEvent BuildEvent(std::string bundleName, std::string timeTaskName); + /* + * function: Update, update usage statistics of specific bundle. + * parameters: bundleName longTimeTaskName timeStamp eventId abilityId + */ void Update(const std::string bundleName, const std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const std::string abilityId); + /* + * function: AddEvent, add a event to member events_. + * parameters: event + */ void AddEvent(BundleActiveEvent event); + /* + * function: UpdateScreenInteractive, update screen interactive time. + * parameters: timeStamp + */ void UpdateScreenInteractive(const int64_t timeStamp); + /* + * function: UpdateScreenNonInteractive, update screen non interactive time. + * parameters: timeStamp + */ void UpdateScreenNonInteractive(const int64_t timeStamp); + /* + * function: UpdateKeyguardShown, key guard shown time. + * parameters: timeStamp + */ void UpdateKeyguardShown(const int64_t timeStamp); + /* + * function: UpdateKeyguardHidden, key guard hidden time. + * parameters: timeStamp + */ void UpdateKeyguardHidden(const int64_t timeStamp); + /* + * function: CommitTime, key guard hidden time. + * parameters: timeStamp + */ void CommitTime(const int64_t timeStamp); + /* + * function: AddEventStatsTo, add all time to eventStatsList. + * parameters: eventStatsList + */ void AddEventStatsTo(std::vector& eventStatsList); + /* + * function: GetCachedString, store string to cache. + * parameters: str + * return: string + */ std::string GetCachedString(std::string str); }; } // namespace DeviceUsageStats diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h index 8c44d35..07088c1 100644 --- a/services/packageusage/include/bundle_active_user_service.h +++ b/services/packageusage/include/bundle_active_user_service.h @@ -57,7 +57,7 @@ public: ~BundleActiveUserService() {} void ReportForShutdown(const BundleActiveEvent& event); void ReportEvent(const BundleActiveEvent& event); - void ReportFormClickedOrRemoved(const BundleActiveEvent& event); + void ReportFormEvent(const BundleActiveEvent& event); void RestoreStats(bool forced); void RenewStatsInMemory(const int64_t timeStamp); void RenewTableTime(int64_t oldTime, int64_t newTime); @@ -87,6 +87,7 @@ private: std::shared_ptr GetOrCreateModuleRecord(const BundleActiveEvent& event); void PrintInMemPackageStats(const int idx); void PrintInMemEventStats(); + void PrintInMemFormStats(); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/src/bundle_active_event.cpp b/services/packageusage/src/bundle_active_event.cpp index c7b764f..adb7d84 100644 --- a/services/packageusage/src/bundle_active_event.cpp +++ b/services/packageusage/src/bundle_active_event.cpp @@ -29,7 +29,7 @@ BundleActiveEvent::BundleActiveEvent() formId_ = 0; formDimension_ = 0; timeStamp_ = 0; - eventId_ = 0; + eventId_ = DEFAULT_EVENT_ID; } BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) @@ -56,36 +56,90 @@ BundleActiveEvent::BundleActiveEvent(int eventId, int64_t timeStamp) timeStamp_ = timeStamp; } -std::string BundleActiveEvent::GetBundleName() +BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string continuousTaskAbilityName) { - return bundleName_; + bundleName_ = bundleName; + continuousTaskAbilityName_ = continuousTaskAbilityName; + abilityName_.clear(); + abilityId_.clear(); + moduleName_.clear(); + modulePackage_.clear(); + formName_.clear(); + formDimension_ = 0; + formId_ = 0; + timeStamp_ = 0; + eventId_ = DEFAULT_EVENT_ID; } -std::string BundleActiveEvent::GetAbilityName() +BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string abilityName, const std::string abilityId) { - return abilityName_; + bundleName_ = bundleName; + continuousTaskAbilityName_.clear(); + abilityName_ = abilityName; + abilityId_ = abilityId; + moduleName_.clear(); + modulePackage_.clear(); + formName_.clear(); + formDimension_ = 0; + formId_ = 0; + timeStamp_ = 0; + eventId_ = DEFAULT_EVENT_ID; } -std::string BundleActiveEvent::GetAbilityId() +BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string moduleName, const std::string modulePackage, + const std::string formName, const int32_t formDimension, const int64_t formId, const int eventId) { - return abilityId_; + bundleName_ = bundleName; + continuousTaskAbilityName_.clear(); + abilityName_.clear(); + abilityId_.clear(); + moduleName_ = moduleName; + modulePackage_ = modulePackage; + formName_ = formName; + formDimension_ = formDimension; + formId_ = formId; + timeStamp_ = 0; + eventId_ = eventId; } -int64_t BundleActiveEvent::GetTimeStamp() +BundleActiveEvent& BundleActiveEvent::operator=(const BundleActiveEvent& orig) { - return timeStamp_; + bundleName_ = orig.bundleName_; + continuousTaskAbilityName_ = orig.continuousTaskAbilityName_; + abilityName_ = orig.abilityName_; + abilityId_ = orig.abilityId_; + moduleName_ = orig.moduleName_; + modulePackage_ = orig.modulePackage_; + formName_ = orig.formName_; + formDimension_ = orig.formDimension_; + formId_ = orig.formId_; + timeStamp_ = orig.timeStamp_; + eventId_ = orig.eventId_; + return *this; } -int BundleActiveEvent::GetEventId() +void BundleActiveEvent::PrintEvent() const { - return eventId_; + BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, ability name is %{public}s, continue task ability is %{public}s, " + "module name is %{public}s, module package is %{public}s, " + "form name is %{public}s, form dimension is %{public}d, form id is %{public}lld, event id is %{public}d", + bundleName_.c_str(), abilityName_.c_str(), continuousTaskAbilityName_.c_str(), moduleName_.c_str(), + modulePackage_.c_str(), formName_.c_str(), formDimension_, formId_, eventId_); } bool BundleActiveEvent::Marshalling(Parcel &parcel) const { if (parcel.WriteString(bundleName_) && - parcel.WriteInt32(eventId_) && - parcel.WriteInt64(timeStamp_)) { + parcel.WriteString(continuousTaskAbilityName_) && + parcel.WriteString(abilityName_) && + parcel.WriteString(abilityId_) && + parcel.WriteString(moduleName_) && + parcel.WriteString(modulePackage_) && + parcel.WriteString(formName_) && + parcel.WriteInt32(formDimension_) && + parcel.WriteInt64(formId_) && + parcel.WriteInt64(timeStamp_) && + parcel.WriteInt32(eventId_)) { return true; } return false; @@ -95,8 +149,16 @@ std::shared_ptr BundleActiveEvent::UnMarshalling(Parcel &parc { std::shared_ptr result = std::make_shared(); result->bundleName_ = parcel.ReadString(); - result->eventId_ = parcel.ReadInt32(); + result->continuousTaskAbilityName_ = parcel.ReadString(); + result->abilityName_ = parcel.ReadString(); + result->abilityId_ = parcel.ReadString(); + result->moduleName_ = parcel.ReadString(); + result->modulePackage_ = parcel.ReadString(); + result->formName_ = parcel.ReadString(); + result->formDimension_ = parcel.ReadInt32(); + result->formId_ = parcel.ReadInt64(); result->timeStamp_ = parcel.ReadInt64(); + result->eventId_ = parcel.ReadInt32(); return result; } } // namespace DeviceUsageStats diff --git a/services/packageusage/src/bundle_active_package_stats.cpp b/services/packageusage/src/bundle_active_package_stats.cpp index f43e081..6865d9f 100644 --- a/services/packageusage/src/bundle_active_package_stats.cpp +++ b/services/packageusage/src/bundle_active_package_stats.cpp @@ -47,51 +47,6 @@ BundleActivePackageStats::BundleActivePackageStats (const BundleActivePackageSta lastEvent_ = orig.lastEvent_; } -std::string BundleActivePackageStats::GetBundleName() -{ - return bundleName_; -} - -int64_t BundleActivePackageStats::GetBeginTimeStamp() -{ - return beginTimeStamp_; -} - -int64_t BundleActivePackageStats::GetEntTimeStamp() -{ - return endTimeStamp_; -} - -int64_t BundleActivePackageStats::GetLastTimeUsed() -{ - return lastTimeUsed_; -} - -int64_t BundleActivePackageStats::GetTotalTimeInFront() -{ - return totalInFrontTime_; -} - -int64_t BundleActivePackageStats::GetLastTimeFrontServiceUsed() -{ - return lastContiniousTaskUsed_; -} - -int64_t BundleActivePackageStats::GetTotalTimeFrontServiceUsed() -{ - return totalContiniousTaskUsedTime_; -} - -int BundleActivePackageStats::GetLaunchedCount() -{ - return startCount_; -} - -int BundleActivePackageStats::GetBundleLaunchedCount() -{ - return bundleStartedCount_; -} - bool BundleActivePackageStats::HasFrontAbility() { for (auto ability : abilities_) { diff --git a/services/packageusage/src/bundle_active_period_stats.cpp b/services/packageusage/src/bundle_active_period_stats.cpp index 22f1eee..d1d09e9 100644 --- a/services/packageusage/src/bundle_active_period_stats.cpp +++ b/services/packageusage/src/bundle_active_period_stats.cpp @@ -42,16 +42,6 @@ std::shared_ptr BundleActivePeriodStats::GetOrCreateUs return bundleStats_[bundleName]; } -BundleActiveEvent BundleActivePeriodStats::BuildEvent(std::string bundleName, std::string timeTaskName) -{ - BundleActiveEvent newEvent; - newEvent.bundleName_ = bundleName; - if (!timeTaskName.empty()) { - newEvent.continuousTaskAbilityName_ = timeTaskName; - } - return newEvent; -} - void BundleActivePeriodStats::Update(const std::string bundleName, const std::string longTimeTaskName, const int64_t timeStamp, const int eventId, const std::string abilityId) { diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index c6d10a6..39ec58c 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -23,7 +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_); + database_.LoadFormData(userId_, moduleRecords_); std::shared_ptr currentDailyStats = currentStats_[BundleActivePeriodStats::PERIOD_DAILY]; if (currentDailyStats != nullptr) { BundleActiveEvent startupEvent(BundleActiveEvent::STARTUP, timeStamp - ONE_SECOND_MILLISECONDS); @@ -90,6 +90,7 @@ void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d," "event is %{public}d", currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_, event.eventId_); + event.PrintEvent(); if (event.timeStamp_ >= dailyExpiryDate_.GetMilliseconds()) { BUNDLE_ACTIVE_LOGI("ReportEvent later than daily expire, renew data in memory"); RenewStatsInMemory(event.timeStamp_); @@ -428,9 +429,27 @@ void BundleActiveUserService::PrintInMemEventStats() } } -void BundleActiveUserService::ReportFormClickedOrRemoved(const BundleActiveEvent& event) +void BundleActiveUserService::PrintInMemFormStats() { - BUNDLE_ACTIVE_LOGI("ReportFormClickedOrRemoved called"); + for (const auto& oneModule : moduleRecords_) { + if (oneModule.second) { + BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, module name is %{public}s, module package is %{public}s, " + "lastusedtime is %{public}lld, launchcount is %{public}d", oneModule.second->bundleName_.c_str(), + oneModule.second->moduleName_.c_str(), oneModule.second->modulePackage_.c_str(), + oneModule.second->lastModuleUsedTime_, oneModule.second->launchedCount_); + BUNDLE_ACTIVE_LOGI("combined info is %{public}s", oneModule.first.c_str()); + for (const auto& oneForm : oneModule.second->formRecords_) { + BUNDLE_ACTIVE_LOGI("form name is %{public}s, form dimension is %{public}d, form id is %{public}lld, " + "lasttouchtime is %{public}lld, touchcount is %{public}d", oneForm.formName_.c_str(), + oneForm.formDimension_, oneForm.formId_, oneForm.formLastUsedTime_, oneForm.count_); + } + } + } +} + +void BundleActiveUserService::ReportFormEvent(const BundleActiveEvent& event) +{ + BUNDLE_ACTIVE_LOGI("ReportFormEvent called"); auto moduleRecord = GetOrCreateModuleRecord(event); if (event.eventId_ == BundleActiveEvent::FORM_IS_CLICKED && moduleRecord) { if (!moduleRecord) { @@ -438,10 +457,12 @@ void BundleActiveUserService::ReportFormClickedOrRemoved(const BundleActiveEvent } moduleRecord->UpdateModuleRecord(event.timeStamp_); moduleRecord->AddOrUpdateOneFormRecord(event.formName_, event.formDimension_, event.formId_, event.timeStamp_); + PrintInMemFormStats(); 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_); + PrintInMemFormStats(); NotifyStatsChanged(); } } @@ -449,6 +470,7 @@ void BundleActiveUserService::ReportFormClickedOrRemoved(const BundleActiveEvent std::shared_ptr BundleActiveUserService::GetOrCreateModuleRecord( const BundleActiveEvent& event) { + BUNDLE_ACTIVE_LOGI("GetOrCreateModuleRecord called"); std::string combinedInfo = event.bundleName_ + " " + event.moduleName_ + " " + event.modulePackage_; auto it = moduleRecords_.find(combinedInfo); if (it == moduleRecords_.end()) { diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 943170a..4f7a194 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -90,12 +90,12 @@ 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); - BundleActiveClient::GetInstance().ReportFormClickedOrRemoved(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, - DEFAULT_MODULE, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, DEFAULT_USERID, - BundleActiveEvent::FORM_IS_REMOVED); + BundleActiveEvent eventA(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, DEFAULT_MODULE, DEFAULT_FORM_NAME, + DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED); + BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID); + BundleActiveEvent eventB(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, DEFAULT_MODULE, DEFAULT_FORM_NAME, + DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_REMOVED); + BundleActiveClient::GetInstance().ReportEvent(eventB, DEFAULT_USERID); } /* -- Gitee From 53346f0b7840175fabffba99b9e89c1451f86fc8 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 29 Mar 2022 12:02:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?review=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8Cjs=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E5=86=85=E6=BA=90=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- frameworks/src/bundle_state_common.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index fc3896f..d907626 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -244,6 +244,9 @@ void BundleStateCommon::SetPromiseInfo(const napi_env &env, const napi_deferred napi_value BundleStateCommon::GetErrorValue(napi_env env, int errCode) { + if (errCode == ERR_OK) { + return NapiGetNull(env); + } napi_value result = nullptr; napi_value eCode = nullptr; NAPI_CALL(env, napi_create_int32(env, errCode, &eCode)); -- Gitee From aa9bb0fb5bc8b0a6e22c051fc03d310a4224e66e Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 29 Mar 2022 14:51:12 +0800 Subject: [PATCH 3/4] =?UTF-8?q?review=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8Cjs=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E5=86=85=E6=BA=90=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- frameworks/src/bundle_state_common.cpp | 56 +++++++++---------- frameworks/src/bundle_state_query.cpp | 3 +- .../napi/include/bundle_state_common.h | 3 + .../src/bundle_active_app_state_obsever.cpp | 3 +- .../packageusage/src/bundle_active_event.cpp | 8 ++- .../src/bundle_active_user_service.cpp | 5 +- 6 files changed, 40 insertions(+), 38 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index d907626..d325386 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -138,64 +138,60 @@ void BundleStateCommon::GetBundleStateInfoForResult(napi_env env, } } -void BundleStateCommon::GetModuleRecordForResult(napi_env env, - const std::vector &moduleRecords, napi_value result) +void BundleStateCommon::GetModuleRecordBasicForResult(napi_env env, + const BundleActiveModuleRecord &oneModuleRecord, napi_value &moduleObject) { - int32_t index = 0; - for (const auto &item : moduleRecords) { - napi_value moduleObject = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &moduleObject)); napi_value bundleName = nullptr; - NAPI_CALL_RETURN_VOID( - env, napi_create_string_utf8(env, item.bundleName_.c_str(), NAPI_AUTO_LENGTH, &bundleName)); + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneModuleRecord.bundleName_.c_str(), + NAPI_AUTO_LENGTH, &bundleName)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "bundleName", bundleName)); - napi_value appLabelId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.appLabelId_, &appLabelId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.appLabelId_, &appLabelId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "appLabelId", appLabelId)); - napi_value moduleName = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, item.moduleName_.c_str(), NAPI_AUTO_LENGTH, + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneModuleRecord.moduleName_.c_str(), NAPI_AUTO_LENGTH, &moduleName)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "name", moduleName)); - napi_value labelId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.labelId_, &labelId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.labelId_, &labelId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "labelId", labelId)); - napi_value descriptionId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.descriptionId_, &descriptionId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.descriptionId_, &descriptionId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "descriptionId", descriptionId)); - napi_value abilityName = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, item.abilityName_.c_str(), NAPI_AUTO_LENGTH, + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, oneModuleRecord.abilityName_.c_str(), NAPI_AUTO_LENGTH, &abilityName)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityName", abilityName)); - napi_value abilityLableId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.abilityLableId_, &abilityLableId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.abilityLableId_, &abilityLableId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityLableId", abilityLableId)); - napi_value abilityDescriptionId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.abilityDescriptionId_, &abilityDescriptionId)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.abilityDescriptionId_, + &abilityDescriptionId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityDescriptionId", abilityDescriptionId)); - napi_value abilityIconId = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.abilityIconId_, &abilityIconId)); + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, oneModuleRecord.abilityIconId_, &abilityIconId)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "abilityIconId", abilityIconId)); - napi_value launchedCount = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, item.launchedCount_, &launchedCount)); + NAPI_CALL_RETURN_VOID(env, napi_create_uint32(env, oneModuleRecord.launchedCount_, &launchedCount)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "launchedCount", launchedCount)); - napi_value lastModuleUsedTime = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.lastModuleUsedTime_, &lastModuleUsedTime)); + NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, oneModuleRecord.lastModuleUsedTime_, &lastModuleUsedTime)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "lastLaunchTime", lastModuleUsedTime)); - napi_value removed = nullptr; - NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.removed_, &removed)); + NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, oneModuleRecord.removed_, &removed)); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, moduleObject, "isRemoved", removed)); +} + +void BundleStateCommon::GetModuleRecordForResult(napi_env env, + const std::vector &moduleRecords, napi_value result) +{ + int32_t index = 0; + for (const auto &item : moduleRecords) { + napi_value moduleObject = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &moduleObject)); + GetModuleRecordBasicForResult(env, item, moduleObject); napi_value formRecords = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &formRecords)); diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 41e3c96..b5eb3a1 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -96,7 +96,8 @@ napi_value GetModuleUsageRecords(napi_env env, napi_callback_info info) AsyncCallbackInfoModuleRecord *asyncCallbackInfo = (AsyncCallbackInfoModuleRecord *)data; if (asyncCallbackInfo != nullptr) { asyncCallbackInfo->info.errorCode = - BundleActiveClient::GetInstance().QueryFormStatistics(asyncCallbackInfo->maxNum, asyncCallbackInfo->moduleRecords); + BundleActiveClient::GetInstance().QueryFormStatistics(asyncCallbackInfo->maxNum, + asyncCallbackInfo->moduleRecords); } else { BUNDLE_ACTIVE_LOGE("QueryBundleStateInfoByInterval, asyncCallbackInfo == nullptr"); } diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index 1153a02..8797caf 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -56,6 +56,9 @@ public: static void GetModuleRecordForResult(napi_env env, const std::vector &moduleRecords, napi_value result); + static void GetModuleRecordBasicForResult(napi_env env, + const BundleActiveModuleRecord &moduleRecords, napi_value &moduleObject); + static void SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, const napi_value &result, const int &errorCode); diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp index 58ff1a6..38be308 100644 --- a/services/common/src/bundle_active_app_state_obsever.cpp +++ b/services/common/src/bundle_active_app_state_obsever.cpp @@ -45,7 +45,8 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData stream << abilityStateData.token.GetRefPtr(); std::string abilityId = stream.str(); BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); - BundleActiveEvent event(abilityStateData.bundleName, abilityStateData.abilityName, abilityStateData.abilityName); + BundleActiveEvent event(abilityStateData.bundleName, abilityStateData.abilityName, + abilityStateData.abilityName); tmpHandlerObject.event_ = event; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); diff --git a/services/packageusage/src/bundle_active_event.cpp b/services/packageusage/src/bundle_active_event.cpp index adb7d84..edb9804 100644 --- a/services/packageusage/src/bundle_active_event.cpp +++ b/services/packageusage/src/bundle_active_event.cpp @@ -71,7 +71,8 @@ BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::st eventId_ = DEFAULT_EVENT_ID; } -BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string abilityName, const std::string abilityId) +BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string abilityName, + const std::string abilityId) { bundleName_ = bundleName; continuousTaskAbilityName_.clear(); @@ -86,8 +87,9 @@ BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::st eventId_ = DEFAULT_EVENT_ID; } -BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string moduleName, const std::string modulePackage, - const std::string formName, const int32_t formDimension, const int64_t formId, const int eventId) +BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string moduleName, + const std::string modulePackage, const std::string formName, const int32_t formDimension, + const int64_t formId, const int eventId) { bundleName_ = bundleName; continuousTaskAbilityName_.clear(); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 39ec58c..5dea3e1 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -87,9 +87,8 @@ void BundleActiveUserService::NotifyNewUpdate() void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) { - BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d," - "event is %{public}d", - currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_, event.eventId_); + BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d,", + currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_); event.PrintEvent(); if (event.timeStamp_ >= dailyExpiryDate_.GetMilliseconds()) { BUNDLE_ACTIVE_LOGI("ReportEvent later than daily expire, renew data in memory"); -- Gitee From a1e719b3e4ec479de414382d5ced8dbfe318df33 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 29 Mar 2022 15:46:45 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9print=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E9=80=BB=E8=BE=91?= 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, 1 insertion(+), 2 deletions(-) diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 5dea3e1..97e834b 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -456,14 +456,13 @@ void BundleActiveUserService::ReportFormEvent(const BundleActiveEvent& event) } moduleRecord->UpdateModuleRecord(event.timeStamp_); moduleRecord->AddOrUpdateOneFormRecord(event.formName_, event.formDimension_, event.formId_, event.timeStamp_); - PrintInMemFormStats(); 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_); - PrintInMemFormStats(); NotifyStatsChanged(); } + PrintInMemFormStats(); } std::shared_ptr BundleActiveUserService::GetOrCreateModuleRecord( -- Gitee