From 37bd14e241d13fd37f4679bbabe5db2c80294478 Mon Sep 17 00:00:00 2001 From: vampire_z Date: Fri, 22 Apr 2022 10:36:43 +0800 Subject: [PATCH 1/3] surport for 64-bit Signed-off-by: vampire_z --- frameworks/src/bundle_state_common.cpp | 8 +- frameworks/src/bundle_state_query.cpp | 87 +++++++------- .../innerkits/include/bundle_active_client.h | 20 ++-- .../innerkits/include/bundle_active_proxy.h | 19 +-- .../innerkits/src/bundle_active_client.cpp | 17 +-- .../innerkits/src/bundle_active_proxy.cpp | 63 +++++----- .../napi/include/bundle_state_common.h | 8 +- .../napi/include/bundle_state_data.h | 14 +-- .../napi/include/bundle_state_inner_errors.h | 4 +- .../common/include/bundle_active_constant.h | 84 ++++++------- services/common/include/bundle_active_core.h | 48 ++++---- .../include/bundle_active_open_callback.h | 2 +- .../common/include/bundle_active_service.h | 23 ++-- .../include/bundle_active_usage_database.h | 56 ++++----- .../common/include/ibundle_active_service.h | 17 +-- .../src/bundle_active_app_state_obsever.cpp | 6 +- ...bundle_active_continuous_task_observer.cpp | 8 +- services/common/src/bundle_active_core.cpp | 74 ++++++------ .../common/src/bundle_active_debug_mode.cpp | 2 +- .../src/bundle_active_open_callback.cpp | 2 +- services/common/src/bundle_active_service.cpp | 72 +++++------ .../bundle_active_shutdown_callback_proxy.cpp | 2 +- services/common/src/bundle_active_stub.cpp | 50 ++++---- .../src/bundle_active_usage_database.cpp | 112 +++++++++--------- .../include/bundle_active_group_common.h | 20 ++-- .../include/bundle_active_group_controller.h | 32 ++--- .../include/bundle_active_group_handler.h | 8 +- .../include/bundle_active_package_history.h | 4 +- .../include/bundle_active_user_history.h | 18 +-- .../src/bundle_active_group_controller.cpp | 53 ++++----- .../src/bundle_active_group_handler.cpp | 2 +- .../src/bundle_active_user_history.cpp | 47 ++++---- .../include/bundle_active_calendar.h | 10 +- .../include/bundle_active_event.h | 46 +++---- .../include/bundle_active_event_list.h | 4 +- .../include/bundle_active_event_stats.h | 16 +-- .../include/bundle_active_event_tracker.h | 4 +- .../include/bundle_active_package_stats.h | 16 +-- .../include/bundle_active_period_stats.h | 16 +-- .../include/bundle_active_report_handler.h | 10 +- .../bundle_active_stats_update_listener.h | 4 +- .../include/bundle_active_user_service.h | 16 +-- .../src/bundle_active_calendar.cpp | 10 +- .../packageusage/src/bundle_active_event.cpp | 8 +- .../src/bundle_active_event_list.cpp | 20 ++-- .../src/bundle_active_event_stats.cpp | 12 +- .../src/bundle_active_event_tracker.cpp | 2 +- .../src/bundle_active_package_stats.cpp | 10 +- .../src/bundle_active_period_stats.cpp | 2 +- .../src/bundle_active_stats_combiner.cpp | 9 +- .../src/bundle_active_user_service.cpp | 81 ++++++------- .../unittest/device_usage_statistics_test.cpp | 8 +- 52 files changed, 634 insertions(+), 652 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 6c1910e..8732486 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -39,7 +39,7 @@ void BundleStateCommon::GetCallbackPromiseResult(const napi_env &env, } void BundleStateCommon::SetCallbackInfo( - const napi_env &env, const napi_ref &callbackIn, const int &errorCode, const napi_value &result) + const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result) { napi_value undefined = nullptr; napi_get_undefined(env, &undefined); @@ -229,7 +229,7 @@ void BundleStateCommon::GetModuleRecordForResult(napi_env env, } void BundleStateCommon::SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, - const napi_value &result, const int &errorCode) + const napi_value &result, const int32_t &errorCode) { if (errorCode == ERR_OK) { napi_resolve_deferred(env, deferred, result); @@ -238,7 +238,7 @@ void BundleStateCommon::SetPromiseInfo(const napi_env &env, const napi_deferred } } -napi_value BundleStateCommon::GetErrorValue(napi_env env, int errCode) +napi_value BundleStateCommon::GetErrorValue(napi_env env, int32_t errCode) { if (errCode == ERR_OK) { return NapiGetNull(env); @@ -251,7 +251,7 @@ napi_value BundleStateCommon::GetErrorValue(napi_env env, int errCode) return result; } -napi_value BundleStateCommon::JSParaError(const napi_env &env, const napi_ref &callback, const int &errorCode) +napi_value BundleStateCommon::JSParaError(const napi_env &env, const napi_ref &callback, const int32_t &errorCode) { if (callback) { napi_value result = nullptr; diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 01a1e7b..0fd0b86 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include #include "securec.h" @@ -23,22 +24,22 @@ namespace OHOS { namespace DeviceUsageStats { -const u_int32_t IS_IDLE_STATE_MIN_PARAMS = 1; -const u_int32_t IS_IDLE_STATE_PARAMS = 2; -const u_int32_t PRIORITY_GROUP_MIN_PARAMS = 0; -const u_int32_t PRIORITY_GROUP_PARAMS = 1; -const u_int32_t STATES_MIN_PARAMS = 2; -const u_int32_t STATES_PARAMS = 3; -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 = 0; -const u_int32_t MODULE_RECORDS_MIDDLE_PARAMS = 1; -const u_int32_t MODULE_RECORDS_PARAMS = 2; -const u_int32_t SECOND_ARG = 2; -const u_int32_t THIRD_ARG = 3; -const int MAXNUM_UP_LIMIT = 1000; +const uint32_t IS_IDLE_STATE_MIN_PARAMS = 1; +const uint32_t IS_IDLE_STATE_PARAMS = 2; +const uint32_t PRIORITY_GROUP_MIN_PARAMS = 0; +const uint32_t PRIORITY_GROUP_PARAMS = 1; +const uint32_t STATES_MIN_PARAMS = 2; +const uint32_t STATES_PARAMS = 3; +const uint32_t APP_USAGE_MIN_PARAMS_BY_INTERVAL = 3; +const uint32_t APP_USAGE_PARAMS_BY_INTERVAL = 4; +const uint32_t APP_USAGE_MIN_PARAMS = 2; +const uint32_t APP_USAGE_PARAMS = 3; +const uint32_t MODULE_RECORDS_MIN_PARAMS = 0; +const uint32_t MODULE_RECORDS_MIDDLE_PARAMS = 1; +const uint32_t MODULE_RECORDS_PARAMS = 2; +const uint32_t SECOND_ARG = 2; +const uint32_t THIRD_ARG = 3; +const int32_t MAXNUM_UP_LIMIT = 1000; napi_value ParseModuleRecordsParameters(const napi_env &env, const napi_callback_info &info, ModuleRecordParamsInfo ¶ms) @@ -205,8 +206,8 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); } - if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoIsIdleState), 0, sizeof(AsyncCallbackInfoIsIdleState)) != - EOK) { + if (memset_s(asyncCallbackInfo, sizeof(AsyncCallbackInfoIsIdleState), 0, sizeof(AsyncCallbackInfoIsIdleState)) + != EOK) { params.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED; delete asyncCallbackInfo; asyncCallbackInfo = nullptr; @@ -365,8 +366,8 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info & params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID; } if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) { - BUNDLE_ACTIVE_LOGE("ParseStatesParameters endTime(%{public}lld) <= beginTime(%{public}lld)", - (long long)params.endTime, (long long)params.beginTime); + BUNDLE_ACTIVE_LOGE("ParseStatesParameters endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", + params.endTime, params.beginTime); params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL; } @@ -405,11 +406,11 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) asyncCallbackInfo->env = env; asyncCallbackInfo->asyncWork = nullptr; asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->beginTime: %{public}lld", - (long long)asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->beginTime: %{public}" PRId64 "", + asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->endTime: %{public}lld", - (long long)asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->endTime: %{public}" PRId64 "", + asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; @@ -480,11 +481,11 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) asyncCallbackInfo->env = env; asyncCallbackInfo->asyncWork = nullptr; asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->beginTime: %{public}lld", - (long long)asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->beginTime: %{public}" PRId64 "", + asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->endTime: %{public}lld", - (long long)asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->endTime: %{public}" PRId64 "", + asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; @@ -572,8 +573,8 @@ napi_value ParseAppUsageParametersByInterval(const napi_env &env, const napi_cal params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID; } if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) { - BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval endTime(%{public}lld) <= beginTime(%{public}lld)", - (long long)params.endTime, (long long)params.beginTime); + BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval endTime(%{public}" PRId64 ") " + "<= beginTime(%{public}" PRId64 ")", params.endTime, params.beginTime); params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL; } @@ -615,11 +616,11 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info) BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->intervalType: %{public}d", asyncCallbackInfo->intervalType); asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->beginTime: %{public}lld", - (long long)asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->beginTime: %{public}" PRId64 "", + asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->endTime: %{public}lld", - (long long)asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->endTime: %{public}" PRId64 "", + asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; napi_create_string_latin1(env, "QueryBundleStateInfoByInterval", NAPI_AUTO_LENGTH, &resourceName); @@ -676,8 +677,7 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, beginTime type is invalid."); params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID; } - if ((params.errorCode == ERR_OK) - && (params.beginTime < TIME_NUMBER_MIN)) { + if ((params.errorCode == ERR_OK) && (params.beginTime < TIME_NUMBER_MIN)) { BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed failed, beginTime value is invalid."); params.errorCode = ERR_USAGE_STATS_BEGIN_TIME_INVALID; } @@ -688,14 +688,13 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, endTime type is invalid."); params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID; } - if ((params.errorCode == ERR_OK) - && (params.endTime < TIME_NUMBER_MIN)) { + if ((params.errorCode == ERR_OK) && (params.endTime < TIME_NUMBER_MIN)) { BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed failed, endTime value is invalid."); params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID; } if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) { - BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters endTime(%{public}lld) <= beginTime(%{public}lld)", - (long long)params.endTime, (long long)params.beginTime); + BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", + params.endTime, params.beginTime); params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL; } @@ -734,11 +733,11 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) asyncCallbackInfo->env = env; asyncCallbackInfo->asyncWork = nullptr; asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->beginTime: %{public}lld", - (long long)asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->beginTime: %{public}" PRId64 "", + asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->endTime: %{public}lld", - (long long)asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->endTime: %{public}" PRId64 "", + asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; napi_create_string_latin1(env, "QueryBundleStateInfos", NAPI_AUTO_LENGTH, &resourceName); diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 85a5318..2714dc4 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -27,13 +27,13 @@ namespace DeviceUsageStats { class BundleActiveClient { public: // max number of query modules result. - const int MAXNUM_UP_LIMIT = 1000; + const int32_t MAXNUM_UP_LIMIT = 1000; /* * function: ReportEvent, used to report event. * parameters: event, userId * return: errorcode. */ - int ReportEvent(BundleActiveEvent event, const int userId); + int32_t ReportEvent(BundleActiveEvent event, const int32_t userId); /* * function: IsBundleIdle, used to check whether specific bundle is idle. * parameters: bundleName @@ -45,26 +45,26 @@ public: * 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, int userId = -1); + std::vector QueryPackageStats(const int32_t intervalType, const int64_t beginTime, + const int64_t endTime, int32_t& errCode, int32_t userId = -1); /* * 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, int userId = -1); + std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode, + int32_t userId = -1); /* * 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); + void SetBundleGroup(std::string bundleName, const int32_t newGroup, const int32_t userId); /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ - std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, + std::vector QueryCurrentPackageStats(const int32_t intervalType, const int64_t beginTime, const int64_t endTime); /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. @@ -76,14 +76,14 @@ public: * function: QueryPackageGroup, query bundle priority group calling bundle. * return: the priority group of calling bundle. */ - int QueryPackageGroup(); + int32_t QueryPackageGroup(); /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. * parameters: maxNum, results, userId, default userId is -1 for JS API, * if other SAs call this API, they should explicit define userId * return: errorcode. */ - int QueryFormStatistics(int32_t maxNum, std::vector& results, int userId = -1); + int32_t QueryFormStatistics(int32_t maxNum, std::vector& results, int32_t userId = -1); /* * function: GetInstance, get instance of client. * return: object of BundleActiveClient. diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index de35a83..2308c9a 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -16,6 +16,8 @@ #ifndef BUNDLE_ACTIVE_PROXY_H #define BUNDLE_ACTIVE_PROXY_H +#include + #include "ibundle_active_service.h" #include "bundle_active_event.h" #include "bundle_active_package_stats.h" @@ -31,7 +33,7 @@ public: * parameters: event, userId * return: errorcode. */ - int ReportEvent(BundleActiveEvent& event, const int userId) override; + int32_t ReportEvent(BundleActiveEvent& event, const int32_t userId) override; /* * function: IsBundleIdle, used to check whether specific bundle is idle. * parameters: bundleName @@ -43,26 +45,26 @@ public: * 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, int userId = -1) override; + std::vector QueryPackageStats(const int32_t intervalType, const int64_t beginTime, + const int64_t endTime, int32_t& errCode, int32_t userId = -1) 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, int userId = -1) override; + int32_t& errCode, int32_t userId = -1) 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; + void SetBundleGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) override; /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ - std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, + std::vector QueryCurrentPackageStats(const int32_t intervalType, const int64_t beginTime, const int64_t endTime) override; /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. @@ -74,14 +76,15 @@ public: * function: QueryPackageGroup, query bundle priority group calling bundle. * return: the priority group of calling bundle. */ - int QueryPackageGroup() override; + int32_t QueryPackageGroup() override; /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. * parameters: maxNum, results, userId, default userId is -1 for JS API, * if other SAs call this API, they should explicit define userId * return: errorcode. */ - int QueryFormStatistics(int32_t maxNum, std::vector& results, int userId = -1) override; + int32_t QueryFormStatistics(int32_t maxNum, std::vector& results, + int32_t userId = -1) override; /* * function: BundleActiveProxy, default constructor. * parameters: impl diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index ef7bb21..c6f1a14 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -45,7 +45,7 @@ bool BundleActiveClient::GetBundleActiveProxy() return true; } -int BundleActiveClient::ReportEvent(BundleActiveEvent event, const int userId) +int32_t BundleActiveClient::ReportEvent(BundleActiveEvent event, const int32_t userId) { BUNDLE_ACTIVE_LOGI("BundleActiveClient::ReportEvent called"); if (!GetBundleActiveProxy()) { @@ -62,8 +62,8 @@ bool BundleActiveClient::IsBundleIdle(const std::string& bundleName) return bundleActiveProxy_->IsBundleIdle(bundleName); } -std::vector BundleActiveClient::QueryPackageStats(const int intervalType, - const int64_t beginTime, const int64_t endTime, int32_t& errCode, int userId) +std::vector BundleActiveClient::QueryPackageStats(const int32_t intervalType, + const int64_t beginTime, const int64_t endTime, int32_t& errCode, int32_t userId) { if (!GetBundleActiveProxy()) { return std::vector(0); @@ -72,7 +72,7 @@ std::vector BundleActiveClient::QueryPackageStats(cons } std::vector BundleActiveClient::QueryEvents(const int64_t beginTime, - const int64_t endTime, int32_t& errCode, int userId) + const int64_t endTime, int32_t& errCode, int32_t userId) { if (!GetBundleActiveProxy()) { return std::vector(0); @@ -80,7 +80,7 @@ std::vector BundleActiveClient::QueryEvents(const int64_t beg return bundleActiveProxy_->QueryEvents(beginTime, endTime, errCode, userId); } -void BundleActiveClient::SetBundleGroup(std::string bundleName, const int newGroup, const int userId) +void BundleActiveClient::SetBundleGroup(std::string bundleName, const int32_t newGroup, const int32_t userId) { if (!GetBundleActiveProxy()) { return; @@ -89,7 +89,7 @@ void BundleActiveClient::SetBundleGroup(std::string bundleName, const int newGro return; } -std::vector BundleActiveClient::QueryCurrentPackageStats(const int intervalType, +std::vector BundleActiveClient::QueryCurrentPackageStats(const int32_t intervalType, const int64_t beginTime, const int64_t endTime) { if (!GetBundleActiveProxy()) { @@ -106,7 +106,7 @@ std::vector BundleActiveClient::QueryCurrentEvents(const int6 return bundleActiveProxy_->QueryCurrentEvents(beginTime, endTime); } -int BundleActiveClient::QueryPackageGroup() +int32_t BundleActiveClient::QueryPackageGroup() { if (!GetBundleActiveProxy()) { return -1; @@ -114,7 +114,8 @@ int BundleActiveClient::QueryPackageGroup() return bundleActiveProxy_->QueryPackageGroup(); } -int BundleActiveClient::QueryFormStatistics(int32_t maxNum, std::vector& results, int userId) +int32_t BundleActiveClient::QueryFormStatistics(int32_t maxNum, std::vector& results, + int32_t userId) { if (maxNum <= 0 || maxNum > MAXNUM_UP_LIMIT) { BUNDLE_ACTIVE_LOGI("maxNum is illegal, maxNum is %{public}d", maxNum); diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index f74fb04..3332433 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -17,7 +17,7 @@ namespace OHOS { namespace DeviceUsageStats { -int BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int userId) +int32_t BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t userId) { MessageParcel data; MessageParcel reply; @@ -48,8 +48,8 @@ bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName) return result; } -std::vector BundleActiveProxy::QueryPackageStats(const int intervalType, - const int64_t beginTime, const int64_t endTime, int32_t& errCode, int userId) +std::vector BundleActiveProxy::QueryPackageStats(const int32_t intervalType, + const int64_t beginTime, const int64_t endTime, int32_t& errCode, int32_t userId) { MessageParcel data; MessageParcel reply; @@ -67,7 +67,7 @@ std::vector BundleActiveProxy::QueryPackageStats(const errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; @@ -75,18 +75,18 @@ std::vector BundleActiveProxy::QueryPackageStats(const result.push_back(*tmp); } for (uint32_t i = 0; i < result.size(); i++) { - BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, " - "lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, " - "totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld", + BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}u, bundleName_ is %{public}s, " + "lastTimeUsed_ is %{public}" PRId64 ", lastContiniousTaskUsed_ is %{public}" PRId64 ", " + "totalInFrontTime_ is %{public}" PRId64 ", totalContiniousTaskUsedTime_ is %{public}" PRId64 "", i + 1, result[i].bundleName_.c_str(), - (long long)result[i].lastTimeUsed_, (long long)result[i].lastContiniousTaskUsed_, - (long long)result[i].totalInFrontTime_, (long long)result[i].totalContiniousTaskUsedTime_); + result[i].lastTimeUsed_, result[i].lastContiniousTaskUsed_, + result[i].totalInFrontTime_, result[i].totalContiniousTaskUsedTime_); } return result; } std::vector BundleActiveProxy::QueryEvents(const int64_t beginTime, - const int64_t endTime, int32_t& errCode, int userId) + const int64_t endTime, int32_t& errCode, int32_t userId) { MessageParcel data; MessageParcel reply; @@ -103,7 +103,7 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; @@ -116,7 +116,7 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi return result; } -void BundleActiveProxy::SetBundleGroup(const std::string& bundleName, int newGroup, int userId) +void BundleActiveProxy::SetBundleGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) { MessageParcel data; MessageParcel reply; @@ -130,7 +130,7 @@ void BundleActiveProxy::SetBundleGroup(const std::string& bundleName, int newGro Remote() -> SendRequest(SET_BUNDLE_GROUP, data, reply, option); } -std::vector BundleActiveProxy::QueryCurrentPackageStats(const int intervalType, +std::vector BundleActiveProxy::QueryCurrentPackageStats(const int32_t intervalType, const int64_t beginTime, const int64_t endTime) { MessageParcel data; @@ -146,7 +146,7 @@ std::vector BundleActiveProxy::QueryCurrentPackageStat Remote() -> SendRequest(QUERY_CURRENT_USAGE_STATS, data, reply, option); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; @@ -155,11 +155,11 @@ std::vector BundleActiveProxy::QueryCurrentPackageStat } for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, " - "lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, " - "totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld", + "lastTimeUsed_ is %{public}" PRId64 ", lastContiniousTaskUsed_ is %{public}" PRId64 ", " + "totalInFrontTime_ is %{public}" PRId64 ", totalContiniousTaskUsedTime_ is %{public}" PRId64 "", i + 1, result[i].bundleName_.c_str(), - (long long)result[i].lastTimeUsed_, (long long)result[i].lastContiniousTaskUsed_, - (long long)result[i].totalInFrontTime_, (long long)result[i].totalContiniousTaskUsedTime_); + result[i].lastTimeUsed_, result[i].lastContiniousTaskUsed_, + result[i].totalInFrontTime_, result[i].totalContiniousTaskUsedTime_); } return result; } @@ -178,7 +178,7 @@ std::vector BundleActiveProxy::QueryCurrentEvents(const int64 Remote() -> SendRequest(QUERY_CURRENT_EVENTS, data, reply, option); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; @@ -187,13 +187,13 @@ std::vector BundleActiveProxy::QueryCurrentEvents(const int64 } for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("QueryCurrentEvents event id is %{public}d, bundle name is %{public}s," - "time stamp is %{public}lld", - result[i].eventId_, result[i].bundleName_.c_str(), (long long)result[i].timeStamp_); + "time stamp is %{public}" PRId64 "", + result[i].eventId_, result[i].bundleName_.c_str(), result[i].timeStamp_); } return result; } -int BundleActiveProxy::QueryPackageGroup() +int32_t BundleActiveProxy::QueryPackageGroup() { MessageParcel data; MessageParcel reply; @@ -207,7 +207,8 @@ int BundleActiveProxy::QueryPackageGroup() return packageGroup; } -int BundleActiveProxy::QueryFormStatistics(int32_t maxNum, std::vector& results, int userId) +int32_t BundleActiveProxy::QueryFormStatistics(int32_t maxNum, std::vector& results, + int32_t userId) { MessageParcel data; MessageParcel reply; @@ -221,7 +222,7 @@ int BundleActiveProxy::QueryFormStatistics(int32_t maxNum, std::vector tmp; - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { tmp = tmp->UnMarshalling(reply); if (tmp == nullptr) { continue; @@ -230,14 +231,12 @@ int BundleActiveProxy::QueryFormStatistics(int32_t maxNum, std::vector &BundleActiveState, napi_value result); @@ -60,9 +60,9 @@ public: const BundleActiveModuleRecord &moduleRecords, napi_value moduleObject); static void SetPromiseInfo(const napi_env &env, const napi_deferred &deferred, - const napi_value &result, const int &errorCode); + const napi_value &result, const int32_t &errorCode); - static napi_value JSParaError(const napi_env &env, const napi_ref &callback, const int &errorCode); + static napi_value JSParaError(const napi_env &env, const napi_ref &callback, const int32_t &errorCode); static std::string GetTypeStringValue(napi_env env, napi_value param, const std::string &result); diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h index a7c6358..3f95f28 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_data.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_data.h @@ -47,7 +47,7 @@ struct CallbackPromiseInfo { napi_ref callback = nullptr; napi_deferred deferred = nullptr; bool isCallback = false; - int errorCode = 0; + int32_t errorCode = 0; }; struct AsyncCallbackInfoIsIdleState { @@ -104,19 +104,19 @@ struct AsyncCallbackInfoModuleRecord { struct IsIdleStateParamsInfo { std::string bundleName; napi_ref callback = nullptr; - int errorCode = 0; + int32_t errorCode = 0; }; struct PriorityGroupParamsInfo { napi_ref callback = nullptr; - int errorCode = 0; + int32_t errorCode = 0; }; struct StatesParamsInfo { int64_t beginTime; int64_t endTime; napi_ref callback = nullptr; - int errorCode = 0; + int32_t errorCode = 0; }; struct AppUsageParamsByIntervalInfo { @@ -124,20 +124,20 @@ struct AppUsageParamsByIntervalInfo { int64_t beginTime; int64_t endTime; napi_ref callback = nullptr; - int errorCode = 0; + int32_t errorCode = 0; }; struct AppUsageParamsInfo { int64_t beginTime; int64_t endTime; napi_ref callback = nullptr; - int errorCode = 0; + int32_t errorCode = 0; }; struct ModuleRecordParamsInfo { int32_t maxNum; napi_ref callback = nullptr; - int errorCode = 0; + int32_t errorCode = 0; }; } // namespace DeviceUsageStats } // namespace OHOS 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 5e5669a..3576ab1 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_inner_errors.h @@ -31,7 +31,7 @@ namespace DeviceUsageStats { */ // DeviceUsageStats's module const defined. -enum : int { +enum : int32_t { DEVICE_USAGE_STATS_MODULE_COMMON = 0x01, }; @@ -39,7 +39,7 @@ enum : int { constexpr ErrCode DEVICE_USAGE_STATS_COMMON_ERR_OFFSET = ErrCodeOffset(SUBSYS_IAWARE, DEVICE_USAGE_STATS_MODULE_COMMON); // Device Usage Stats Common Error Code Defined. -enum : int { +enum : int32_t { ERR_USAGE_STATS_BUNDLENAME_EMPTY = DEVICE_USAGE_STATS_COMMON_ERR_OFFSET + 1, ERR_USAGE_STATS_BUNDLENAME_TYPE, ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR, diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index 9c00caf..82bf37e 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -42,48 +42,48 @@ const int32_t BUNDLE_ACTIVE_RDB_VERSION = 1; const int32_t BUNDLE_ACTIVE_DB_INDEX_NORMAL = 0; const int32_t BUNDLE_ACTIVE_DB_INDEX_MODULE = 1; const int32_t BUNDLE_ACTIVE_DB_INDEX_FORM = 2; -const int USER_ID_COLUMN_INDEX = 0; -const int BUNDLE_NAME_COLUMN_INDEX = 1; -const int BUNDLE_STARTED_COUNT_COLUMN_INDEX = 2; -const int LAST_TIME_COLUMN_INDEX = 3; -const int LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX = 4; -const int TOTAL_TIME_COLUMN_INDEX = 5; -const int TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX = 6; -const int EVENT_ID_COLUMN_INDEX = 2; -const int TIME_STAMP_COLUMN_INDEX = 3; -const int ABILITY_ID_COLUMN_INDEX = 4; -const int LAST_BOOT_FROM_USED_TIME_COLUMN_INDEX = 2; -const int LAST_SCREEN_USED_TIME_COLUMN_INDEX = 3; -const int CURRENT_GROUP_COLUMN_INDEX = 4; -const int REASON_IN_GROUP_COLUMN_INDEX = 5; -const int BUNDLE_ALIVE_TIMEOUT_TIME_COLUMN_INDEX = 6; -const int BUNDLE_DAILY_TIMEOUT_TIME_COLUMN_INDEX = 7; -const int BOOT_BASED_DURATION_COLUMN_INDEX = 0; -const int SCREEN_ON_DURATION_COLUMN_INDEX = 1; -const int DURATION_FLAG_COLUMN_INDEX = 2; -const int MODULE_NAME_COLUMN_INDEX = 2; -const int MODULE_USED_COUNT_COLUMN_INDEX = 3; -const int MODULE_LAST_TIME_COLUMN_INDEX = 4; -const int FORM_NAME_COLUMN_INDEX = 3; -const int FORM_DIMENSION_COLUMN_INDEX = 4; -const int FORM_ID_COLUMN_INDEX = 5; -const int FORM_COUNT_COLUMN_INDEX = 6; -const int FORM_LAST_TIME_COLUMN_INDEX = 7; -const int TWO_SECONDS = 2 * 1000; -const int64_t THIRTY_MINUTE = 30 * 60 * 1000; -const int64_t SIX_DAY_IN_MILLIS_MAX_DEBUG = (int64_t)6 * 1 * 10 * 60 * 1000; -const int64_t SIX_DAY_IN_MILLIS_MAX = (int64_t)6 * 24 * 60 * 60 * 1000; -const int64_t ONE_DAY_TIME_DEBUG = (int64_t)1 * 10 * 60 * 1000; -const int64_t ONE_DAY_TIME = (int64_t)1 * 24 * 60 * 60 * 1000; -const int64_t ONE_WEEK_TIME_DEBUG = (int64_t)1 * 20 * 60 * 1000; -const int64_t ONE_WEEK_TIME = (int64_t)7 * 24 * 60 * 60 * 1000; -const int64_t ONE_MONTH_TIME_DEBUG = (int64_t)1 * 30 * 60 * 1000; -const int64_t ONE_MONTH_TIME = (int64_t)30 * 24 * 60 * 60 * 1000; -const int64_t ONE_YEAR_TIME_DEBUG = (int64_t)1 * 40 * 60 * 1000; -const int64_t ONE_YEAR_TIME = (int64_t)365 * 24 * 60 * 60 * 1000; -const int64_t LAST_TIME_IN_MILLIS_MIN = 0; -const int64_t EVENT_TIME_IN_MILLIS_MIN = 0; -const int64_t EVENT_BEGIN_TIME_INITIAL_VALUE = -1; +const int32_t USER_ID_COLUMN_INDEX = 0; +const int32_t BUNDLE_NAME_COLUMN_INDEX = 1; +const int32_t BUNDLE_STARTED_COUNT_COLUMN_INDEX = 2; +const int32_t LAST_TIME_COLUMN_INDEX = 3; +const int32_t LAST_TIME_CONTINUOUS_TASK_COLUMN_INDEX = 4; +const int32_t TOTAL_TIME_COLUMN_INDEX = 5; +const int32_t TOTAL_TIME_CONTINUOUS_TASK_COLUMN_INDEX = 6; +const int32_t EVENT_ID_COLUMN_INDEX = 2; +const int32_t TIME_STAMP_COLUMN_INDEX = 3; +const int32_t ABILITY_ID_COLUMN_INDEX = 4; +const int32_t LAST_BOOT_FROM_USED_TIME_COLUMN_INDEX = 2; +const int32_t LAST_SCREEN_USED_TIME_COLUMN_INDEX = 3; +const int32_t CURRENT_GROUP_COLUMN_INDEX = 4; +const int32_t REASON_IN_GROUP_COLUMN_INDEX = 5; +const int32_t BUNDLE_ALIVE_TIMEOUT_TIME_COLUMN_INDEX = 6; +const int32_t BUNDLE_DAILY_TIMEOUT_TIME_COLUMN_INDEX = 7; +const int32_t BOOT_BASED_DURATION_COLUMN_INDEX = 0; +const int32_t SCREEN_ON_DURATION_COLUMN_INDEX = 1; +const int32_t DURATION_FLAG_COLUMN_INDEX = 2; +const int32_t MODULE_NAME_COLUMN_INDEX = 2; +const int32_t MODULE_USED_COUNT_COLUMN_INDEX = 3; +const int32_t MODULE_LAST_TIME_COLUMN_INDEX = 4; +const int32_t FORM_NAME_COLUMN_INDEX = 3; +const int32_t FORM_DIMENSION_COLUMN_INDEX = 4; +const int32_t FORM_ID_COLUMN_INDEX = 5; +const int32_t FORM_COUNT_COLUMN_INDEX = 6; +const int32_t FORM_LAST_TIME_COLUMN_INDEX = 7; +const int64_t TWO_SECONDS = 2 * 1000LL; +const int64_t THIRTY_MINUTE = 30 * 60 * 1000LL; +const int64_t SIX_DAY_IN_MILLIS_MAX_DEBUG = 6 * 1 * 10 * 60 * 1000LL; +const int64_t SIX_DAY_IN_MILLIS_MAX = 6 * 24 * 60 * 60 * 1000LL; +const int64_t ONE_DAY_TIME_DEBUG = 1 * 10 * 60 * 1000LL; +const int64_t ONE_DAY_TIME = 1 * 24 * 60 * 60 * 1000LL; +const int64_t ONE_WEEK_TIME_DEBUG = 1 * 20 * 60 * 1000LL; +const int64_t ONE_WEEK_TIME = 7 * 24 * 60 * 60 * 1000LL; +const int64_t ONE_MONTH_TIME_DEBUG = 1 * 30 * 60 * 1000LL; +const int64_t ONE_MONTH_TIME = 30 * 24 * 60 * 60 * 1000LL; +const int64_t ONE_YEAR_TIME_DEBUG = 1 * 40 * 60 * 1000LL; +const int64_t ONE_YEAR_TIME = 365 * 24 * 60 * 60 * 1000LL; +const int64_t LAST_TIME_IN_MILLIS_MIN = 0LL; +const int64_t EVENT_TIME_IN_MILLIS_MIN = 0LL; +const int64_t EVENT_BEGIN_TIME_INITIAL_VALUE = -1LL; const std::string PACKAGE_LOG_TABLE = "PackageLog"; const std::string PACKAGE_LOG_TABLE_INDEX_PREFIX = "PackageLogIndex"; const std::string EVENT_LOG_TABLE = "DeviceEventLog"; diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 785e50c..3c861ce 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -36,10 +36,10 @@ namespace DeviceUsageStats { class BundleActiveReportHandlerObject { public: BundleActiveEvent event_; - int userId_; + int32_t userId_; std::string bundleName_; BundleActiveReportHandlerObject(); - BundleActiveReportHandlerObject(const int userId, const std::string bundleName); + BundleActiveReportHandlerObject(const int32_t userId, const std::string bundleName); BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig); ~BundleActiveReportHandlerObject() {} }; @@ -54,17 +54,17 @@ public: * function: ReportEvent, used to report ability fourground/background/destroy event. * parameters: event, userId */ - int ReportEvent(BundleActiveEvent& event, const int userId); + int32_t ReportEvent(BundleActiveEvent& event, const int32_t userId); /* * function: ReportEventToAllUserId, report flush to disk, end_of_day event to service. * parameters: event */ - int ReportEventToAllUserId(BundleActiveEvent& event); + int32_t ReportEventToAllUserId(BundleActiveEvent& event); /* * function: OnStatsChanged, report flush to disk, end_of_day event to service. * parameters: userId */ - void OnStatsChanged(const int userId) override; + void OnStatsChanged(const int32_t userId) override; /* * function: OnStatsChanged, when device reboot after more than one day, BundleActiveUserService * will use it to flush group info. @@ -74,13 +74,13 @@ public: * function: OnSystemUpdate, now is emtpy, later will called when system is updated. * parameters: userId */ - void OnSystemUpdate(int userId) override; + void OnSystemUpdate(int32_t userId) override; /* * function: OnBundleUninstalled when received a PACKATE_REMOVED commen event, * BundleActiveCommonEventSubscriber call it to remove data. * parameters: userId, bundleName */ - void OnBundleUninstalled(const int userId, const std::string& bundleName); + void OnBundleUninstalled(const int32_t userId, const std::string& bundleName); /* * function: Init, BundleAciveService call it to init systemTimeShot_, realTimeShot_, * create bundleGroupController_ object. @@ -101,12 +101,12 @@ public: * function: RestoreToDatabase, restore bundle usage data and form data to database * parameters: userId */ - void RestoreToDatabase(const int userId); + void RestoreToDatabase(const int32_t userId); /* * function: RestoreToDatabaseLocked, flush database for one user data * parameters: userId */ - void RestoreToDatabaseLocked(const int userId); + void RestoreToDatabaseLocked(const int32_t userId); /* * function: ShutDown, called when device shutdown, update the in-memory stat and flush the database. */ @@ -116,42 +116,42 @@ public: * parameters: userId, intervalType, beginTime, endTime, bundleName * return: vector of BundleActivePackageStats */ - std::vector QueryPackageStats(const int userId, const int intervalType, + std::vector QueryPackageStats(const int32_t userId, const int32_t intervalType, const int64_t beginTime, const int64_t endTime, std::string bundleName); // query the event stat for calling user. - std::vector QueryEvents(const int userId, const int64_t beginTime, + std::vector QueryEvents(const int32_t userId, const int64_t beginTime, const int64_t endTime, std::string bundleName); // check the app idle state for calling user. - int IsBundleIdle(const std::string& bundleName, const int userId); + int32_t IsBundleIdle(const std::string& bundleName, const int32_t 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); + int32_t QueryPackageGroup(const int32_t userId, const std::string bundleName); + int32_t QueryFormStatistics(int32_t maxNum, std::vector& results, int32_t userId); // get the wall time and check if the wall time is changed. - int64_t CheckTimeChangeAndGetWallTime(int userId = 0); + int64_t CheckTimeChangeAndGetWallTime(int32_t userId = 0); // convert event timestamp from boot based time to wall time. void ConvertToSystemTimeLocked(BundleActiveEvent& event); // get or create BundleActiveUserService object for specifice user. - std::shared_ptr GetUserDataAndInitializeIfNeeded(const int userId, + std::shared_ptr GetUserDataAndInitializeIfNeeded(const int32_t userId, const int64_t timeStamp, const bool debug); // when received a USER_REMOVED commen event, call it to remove data. - void OnUserRemoved(const int userId); + void OnUserRemoved(const int32_t userId); // when user switched, restore old userdata. - void OnUserSwitched(const int userId); + void OnUserSwitched(const int32_t userId); // force set app group. - void SetBundleGroup(const std::string& bundleName, const int newGroup, const int userId); + void SetBundleGroup(const std::string& bundleName, const int32_t newGroup, const int32_t userId); // get all user in device. - void GetAllActiveUser(std::vector& activatedOsAccountIds); + 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_; + int32_t currentUsedUser_; private: int64_t flushInterval_; static const int64_t TIME_CHANGE_THRESHOLD_MILLIS = TWO_SECONDS; - const int DEFAULT_USER_ID = -1; - std::map visibleActivities_; + const int32_t DEFAULT_USER_ID = -1; + std::map visibleActivities_; // use weak_ptr to avoid circulate reference of core and handler. std::weak_ptr handler_; std::shared_ptr bundleGroupController_; @@ -159,7 +159,7 @@ private: int64_t systemTimeShot_; int64_t realTimeShot_; std::mutex mutex_; - std::map> userStatServices_; + std::map> userStatServices_; void RegisterSubscriber(); std::shared_ptr commonEventSubscriber_; void RestoreAllData(); diff --git a/services/common/include/bundle_active_open_callback.h b/services/common/include/bundle_active_open_callback.h index 7bd1a7d..f2f3ba3 100644 --- a/services/common/include/bundle_active_open_callback.h +++ b/services/common/include/bundle_active_open_callback.h @@ -28,7 +28,7 @@ public: BundleActiveOpenCallback(); ~BundleActiveOpenCallback(); int32_t OnCreate(NativeRdb::RdbStore &rdbStore) override; - int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) override; + int32_t OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) override; }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index ceac5de..3a3501a 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -45,7 +45,7 @@ public: * parameters: event, userId * return: errorcode. */ - int ReportEvent(BundleActiveEvent& event, const int userId) override; + int32_t ReportEvent(BundleActiveEvent& event, const int32_t userId) override; /* * function: IsBundleIdle, used to check whether specific bundle is idle. * parameters: bundleName @@ -57,26 +57,26 @@ public: * 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, int userId = -1) override; + std::vector QueryPackageStats(const int32_t intervalType, const int64_t beginTime, + const int64_t endTime, int32_t& errCode, int32_t userId = -1) 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, int userId = -1) override; + int32_t& errCode, int32_t userId = -1) 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; + void SetBundleGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) override; /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ - std::vector QueryCurrentPackageStats(const int intervalType, const int64_t beginTime, + std::vector QueryCurrentPackageStats(const int32_t intervalType, const int64_t beginTime, const int64_t endTime) override; /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. @@ -88,19 +88,20 @@ public: * function: QueryPackageGroup, query bundle priority group calling bundle. * return: the priority group of calling bundle. */ - int QueryPackageGroup() override; + int32_t QueryPackageGroup() override; /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. * parameters: maxNum, results, userId, default userId is -1 for JS API, * if other SAs call this API, they should explicit define userId * return: errorcode. */ - int QueryFormStatistics(int32_t maxNum, std::vector& results, int userId = -1) override; + int32_t QueryFormStatistics(int32_t maxNum, std::vector& results, + int32_t userId = -1) override; /* * function: BundleActiveService, default constructor. * parameters: systemAbilityId, runOnCreate */ - BundleActiveService(int32_t systemAbilityId, int runOnCreate) + BundleActiveService(int32_t systemAbilityId, int32_t runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) {} /* * function: ~BundleActiveService, default destructor. @@ -120,11 +121,11 @@ private: sptr shutdownCallback_; std::shared_ptr runner_; std::shared_ptr handler_; - int ConvertIntervalType(const int intervalType); + int32_t ConvertIntervalType(const int32_t intervalType); void InitNecessaryState(); void InitService(); bool GetBundleMgrProxy(); - bool CheckBundleIsSystemAppAndHasPermission(const int uid, OHOS::Security::AccessToken::AccessTokenID tokenId, + bool CheckBundleIsSystemAppAndHasPermission(const int32_t uid, OHOS::Security::AccessToken::AccessTokenID tokenId, int32_t& errCode); void InitAppStateSubscriber(const std::shared_ptr& reportHandler); void InitContinuousSubscriber(const std::shared_ptr& reportHandler); diff --git a/services/common/include/bundle_active_usage_database.h b/services/common/include/bundle_active_usage_database.h index b7ddbd1..f26373c 100644 --- a/services/common/include/bundle_active_usage_database.h +++ b/services/common/include/bundle_active_usage_database.h @@ -42,25 +42,25 @@ public: void InitDatabaseTableInfo(int64_t currentTime); void InitUsageGroupDatabase(const int32_t databaseType, const bool forModuleRecords); void UpdateUsageData(int32_t databaseType, BundleActivePeriodStats &stats); - std::shared_ptr GetCurrentUsageData(int32_t databaseType, int userId); + std::shared_ptr GetCurrentUsageData(int32_t databaseType, int32_t userId); void RenewTableTime(int64_t timeDiffMillis); int32_t GetOptimalIntervalType(int64_t beginTime, int64_t endTime); void RemoveOldData(int64_t currentTime); std::vector QueryDatabaseUsageStats(int32_t databaseType, int64_t beginTime, - int64_t endTime, int userId); - std::vector QueryDatabaseEvents(int64_t beginTime, int64_t endTime, int userId, + int64_t endTime, int32_t userId); + std::vector QueryDatabaseEvents(int64_t beginTime, int64_t endTime, int32_t userId, std::string bundleName); void PutDurationData(int64_t bootBasedDuration, int64_t screenOnDuration); std::pair GetDurationData(); - void PutBundleHistoryData(int userId, std::shared_ptr>> userHistory); std::shared_ptr>> - GetBundleHistoryData(int userId); - void OnPackageUninstalled(const int userId, const std::string& bundleName); + GetBundleHistoryData(int32_t userId); + void OnPackageUninstalled(const int32_t userId, const std::string& bundleName); void ChangeToDebug(); - void UpdateModuleData(const int userId, + void UpdateModuleData(const int32_t userId, std::map>& moduleRecords, const int64_t timeStamp); - void RemoveFormData(const int userId, const std::string bundleName, + void RemoveFormData(const int32_t userId, const std::string bundleName, const std::string moduleName, const std::string formName, const int32_t formDimension, const int64_t formId); void LoadModuleData(const int32_t userId, std::map GetBundleActiveRdbStore(unsigned int databaseType); + void HandleTableInfo(uint32_t databaseType); + std::shared_ptr GetBundleActiveRdbStore(uint32_t databaseType); int64_t ParseStartTime(const std::string &tableName); int32_t NearIndexOnOrAfterCurrentTime(int64_t currentTime, std::vector &sortedTableArray); int32_t NearIndexOnOrBeforeCurrentTime(int64_t currentTime, std::vector &sortedTableArray); - int32_t RenameTableName(unsigned int databaseType, int64_t tableOldTime, int64_t tableNewTime); - std::string GetTableIndexSql(unsigned int databaseType, int64_t tableTime, bool createFlag, + int32_t RenameTableName(uint32_t databaseType, int64_t tableOldTime, int64_t tableNewTime); + std::string GetTableIndexSql(uint32_t databaseType, int64_t tableTime, bool createFlag, int32_t indexFlag = BUNDLE_ACTIVE_DB_INDEX_NORMAL); - int32_t SetNewIndexWhenTimeChanged(unsigned int databaseType, int64_t tableOldTime, + int32_t SetNewIndexWhenTimeChanged(uint32_t databaseType, int64_t tableOldTime, int64_t tableNewTime, std::shared_ptr rdbStore); - void FlushPackageInfo(unsigned int databaseType, const BundleActivePeriodStats &stats); - void FlushEventInfo(unsigned int databaseType, BundleActivePeriodStats &stats); - void DeleteExcessiveTableData(unsigned int databaseType); - int32_t DeleteInvalidTable(unsigned int databaseType, int64_t tableTimeMillis); - std::unique_ptr> GetOverdueTableCreateTime(unsigned int databaseType, + void FlushPackageInfo(uint32_t databaseType, const BundleActivePeriodStats &stats); + void FlushEventInfo(uint32_t databaseType, BundleActivePeriodStats &stats); + void DeleteExcessiveTableData(uint32_t databaseType); + int32_t DeleteInvalidTable(uint32_t databaseType, int64_t tableTimeMillis); + std::unique_ptr> GetOverdueTableCreateTime(uint32_t databaseType, int64_t currentTimeMillis); - int32_t CreatePackageLogTable(unsigned int databaseType, int64_t currentTimeMillis); - int32_t CreateEventLogTable(unsigned int databaseType, int64_t currentTimeMillis); - int32_t CreateDurationTable(unsigned int databaseType); - int32_t CreateBundleHistoryTable(unsigned int databaseType); - int32_t CreateModuleRecordTable(unsigned int databaseType, int64_t timeStamp); - int32_t CreateFormRecordTable(unsigned int databaseType, int64_t timeStamp); - std::unique_ptr QueryStatsInfoByStep(unsigned int databaseType, + int32_t CreatePackageLogTable(uint32_t databaseType, int64_t currentTimeMillis); + int32_t CreateEventLogTable(uint32_t databaseType, int64_t currentTimeMillis); + int32_t CreateDurationTable(uint32_t databaseType); + int32_t CreateBundleHistoryTable(uint32_t databaseType); + int32_t CreateModuleRecordTable(uint32_t databaseType, int64_t timeStamp); + int32_t CreateFormRecordTable(uint32_t databaseType, int64_t timeStamp); + std::unique_ptr QueryStatsInfoByStep(uint32_t databaseType, const std::string &sql, const std::vector &selectionArgs); - void DeleteUninstalledInfo(const int userId, const std::string& bundleName, const std::string& tableName, - unsigned int databaseType); + void DeleteUninstalledInfo(const int32_t userId, const std::string& bundleName, const std::string& tableName, + uint32_t databaseType); int32_t CreateDatabasePath(); int64_t GetSystemTimeMs(); - void CheckDatabaseFile(unsigned int databaseType); + void CheckDatabaseFile(uint32_t databaseType); void UpdateFormData(const int32_t userId, const std::string bundleName, const std::string moduleName, const BundleActiveFormRecord& formRecord, std::shared_ptr rdbStore); diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h index d223bee..f3e18cc 100644 --- a/services/common/include/ibundle_active_service.h +++ b/services/common/include/ibundle_active_service.h @@ -49,7 +49,7 @@ public: * parameters: event, userId * return: errorcode. */ - virtual int ReportEvent(BundleActiveEvent& event, const int userId) = 0; + virtual int32_t ReportEvent(BundleActiveEvent& event, const int32_t userId) = 0; /* * function: IsBundleIdle, used to check whether specific bundle is idle. * parameters: bundleName @@ -61,21 +61,21 @@ public: * 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, int userId) = 0; + virtual std::vector QueryPackageStats(const int32_t intervalType, const int64_t beginTime, + const int64_t endTime, int32_t& errCode, int32_t userId) = 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, int userId) = 0; + int32_t& errCode, int32_t userId) = 0; /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. * parameters: intervalType, beginTime, endTime * return: vector of calling bundle usage statistics. */ - virtual std::vector QueryCurrentPackageStats(const int intervalType, + virtual std::vector QueryCurrentPackageStats(const int32_t intervalType, const int64_t beginTime, const int64_t endTime) = 0; /* * function: QueryCurrentEvents, query bundle usage statistics in specific time span for calling bundle. @@ -87,19 +87,20 @@ public: * function: QueryPackageGroup, query bundle priority group calling bundle. * return: the priority group of calling bundle. */ - virtual int QueryPackageGroup() = 0; + virtual int32_t 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; + virtual void SetBundleGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) = 0; /* * function: QueryFormStatistics, query all from usage statistics in specific time span for calling user. * parameters: maxNum, results, userId, default userId is -1 for JS API, * if other SAs call this API, they should explicit define userId * return: errorcode. */ - virtual int QueryFormStatistics(int32_t maxNum, std::vector& results, int userId) = 0; + virtual int32_t QueryFormStatistics(int32_t maxNum, std::vector& results, + int32_t userId) = 0; public: enum { diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp index daa6d56..786adf6 100644 --- a/services/common/src/bundle_active_app_state_obsever.cpp +++ b/services/common/src/bundle_active_app_state_obsever.cpp @@ -25,7 +25,7 @@ namespace DeviceUsageStats { #ifndef OS_ACCOUNT_PART_ENABLED namespace { constexpr int32_t UID_TRANSFORM_DIVISOR = 200000; -void GetOsAccountIdFromUid(int uid, int &osAccountId) +void GetOsAccountIdFromUid(int32_t uid, int32_t &osAccountId) { osAccountId = uid / UID_TRANSFORM_DIVISOR; } @@ -43,13 +43,13 @@ void BundleActiveAppStateObserver::Init(const std::shared_ptr& reportHandler) { if (reportHandler != nullptr) { - BUNDLE_ACTIVE_LOGI("BundleActiveAppStateObserver::Init report handler is not null, init success"); + BUNDLE_ACTIVE_LOGI("report handler is not null, init success"); reportHandler_ = reportHandler; } } @@ -75,10 +75,10 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( const std::shared_ptr& continuousTaskCallbackInfo, const bool isStart) { - int uid = continuousTaskCallbackInfo->GetCreatorUid(); - int pid = continuousTaskCallbackInfo->GetCreatorPid(); + int32_t uid = continuousTaskCallbackInfo->GetCreatorUid(); + pid_t pid = continuousTaskCallbackInfo->GetCreatorPid(); std::string continuousTaskAbilityName_ = continuousTaskCallbackInfo->GetAbilityName(); - int userId = -1; + int32_t userId = -1; std::string bundleName = ""; if (GetBundleMgr()) { bundleMgr_->GetBundleNameForUid(uid, bundleName); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 537315e..7ffad68 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -34,7 +34,7 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject() bundleName_ = ""; } -BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const int userId, const std::string bundleName) +BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const int32_t userId, const std::string bundleName) { userId_ = userId; bundleName_ = bundleName; @@ -146,7 +146,7 @@ void BundleActiveCore::Init() realTimeShot_ = timer->GetBootTimeMs(); systemTimeShot_ = GetSystemTimeMs(); bundleGroupController_ = std::make_shared(debugCore_); - BUNDLE_ACTIVE_LOGI("system time shot is %{public}lld", (long long)systemTimeShot_); + BUNDLE_ACTIVE_LOGI("system time shot is %{public}" PRId64 "", systemTimeShot_); } void BundleActiveCore::InitBundleGroupController() @@ -170,7 +170,7 @@ void BundleActiveCore::InitBundleGroupController() return; } RegisterSubscriber(); - std::vector activatedOsAccountIds; + std::vector activatedOsAccountIds; bundleGroupController_->bundleGroupEnable_ = true; GetAllActiveUser(activatedOsAccountIds); if (activatedOsAccountIds.size() == 0) { @@ -187,7 +187,7 @@ void BundleActiveCore::SetHandler(const std::shared_ptr BundleActiveCore::GetUserDataAndInitializeIfNeeded(const int userId, +std::shared_ptr BundleActiveCore::GetUserDataAndInitializeIfNeeded(const int32_t userId, const int64_t timeStamp, const bool debug) { BUNDLE_ACTIVE_LOGI("GetUserDataAndInitializeIfNeeded called"); @@ -207,7 +207,7 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial return it->second; } -void BundleActiveCore::OnBundleUninstalled(const int userId, const std::string& bundleName) +void BundleActiveCore::OnBundleUninstalled(const int32_t userId, const std::string& bundleName) { BUNDLE_ACTIVE_LOGI("OnBundleUninstalled CALLED"); std::lock_guard lock(mutex_); @@ -223,7 +223,7 @@ void BundleActiveCore::OnBundleUninstalled(const int userId, const std::string& bundleGroupController_->OnBundleUninstalled(userId, bundleName); } -void BundleActiveCore::OnStatsChanged(const int userId) +void BundleActiveCore::OnStatsChanged(const int32_t userId) { if (!handler_.expired()) { BundleActiveReportHandlerObject tmpHandlerObject; @@ -262,7 +262,7 @@ void BundleActiveCore::RestoreAllData() } } -void BundleActiveCore::RestoreToDatabase(const int userId) +void BundleActiveCore::RestoreToDatabase(const int32_t userId) { BUNDLE_ACTIVE_LOGI("RestoreToDatabase called"); sptr timer = MiscServices::TimeServiceClient::GetInstance(); @@ -277,7 +277,7 @@ void BundleActiveCore::RestoreToDatabase(const int userId) RestoreToDatabaseLocked(userId); } -void BundleActiveCore::RestoreToDatabaseLocked(const int userId) +void BundleActiveCore::RestoreToDatabaseLocked(const int32_t userId) { BUNDLE_ACTIVE_LOGI("RestoreToDatabaseLocked called"); auto it = userStatServices_.find(userId); @@ -301,7 +301,7 @@ void BundleActiveCore::ShutDown() int64_t timeStamp = timer->GetBootTimeMs(); BundleActiveEvent event(BundleActiveEvent::SHUTDOWN, timeStamp); event.bundleName_ = BundleActiveEvent::DEVICE_EVENT_PACKAGE_NAME; - std::vector activatedOsAccountIds; + std::vector activatedOsAccountIds; GetAllActiveUser(activatedOsAccountIds); if (activatedOsAccountIds.size() == 0) { BUNDLE_ACTIVE_LOGI("query activated account failed, no account activated"); @@ -320,11 +320,11 @@ void BundleActiveCore::OnStatsReload() bundleGroupController_->CheckIdleStatsOneTime(); } -void BundleActiveCore::OnSystemUpdate(int userId) +void BundleActiveCore::OnSystemUpdate(int32_t userId) { } -int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int userId) +int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int32_t userId) { BUNDLE_ACTIVE_LOGI("CheckTimeChangeAndGetWallTime called, userId is %{public}d", userId); sptr timer = MiscServices::TimeServiceClient::GetInstance(); @@ -335,10 +335,9 @@ int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int userId) if (actualSystemTime == -1 || actualRealTime == -1) { return -1; } - BUNDLE_ACTIVE_LOGI("asystime is %{public}lld, artime is %{public}lld, esystime is %{public}lld, " - "diff is %{public}lld", - (long long)actualSystemTime, (long long)actualRealTime, - (long long)expectedSystemTime, (long long)diffSystemTime); + BUNDLE_ACTIVE_LOGI("asystime is %{public}" PRId64 ", artime is %{public}" PRId64 ", " + "esystime is %{public}" PRId64 ", diff is %{public}" PRId64 "", + actualSystemTime, actualRealTime, expectedSystemTime, diffSystemTime); if (std::abs(diffSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) { // 时区变换逻辑 auto it = userStatServices_.find(userId); @@ -369,7 +368,7 @@ void BundleActiveCore::ConvertToSystemTimeLocked(BundleActiveEvent& event) event.timeStamp_ = std::max((int64_t)0, event.timeStamp_ - realTimeShot_) + systemTimeShot_; } -void BundleActiveCore::OnUserRemoved(const int userId) +void BundleActiveCore::OnUserRemoved(const int32_t userId) { BUNDLE_ACTIVE_LOGI("OnUserRemoved called"); std::lock_guard lock(mutex_); @@ -383,7 +382,7 @@ void BundleActiveCore::OnUserRemoved(const int userId) bundleGroupController_->OnUserRemoved(userId); } -void BundleActiveCore::OnUserSwitched(const int userId) +void BundleActiveCore::OnUserSwitched(const int32_t userId) { sptr timer = MiscServices::TimeServiceClient::GetInstance(); auto it = userStatServices_.find(currentUsedUser_); @@ -397,7 +396,7 @@ void BundleActiveCore::OnUserSwitched(const int userId) it->second->ReportEvent(event); it->second->RestoreStats(true); } - std::vector activatedOsAccountIds; + std::vector activatedOsAccountIds; GetAllActiveUser(activatedOsAccountIds); if (activatedOsAccountIds.size() == 0) { BUNDLE_ACTIVE_LOGI("query activated account failed, no account activated"); @@ -411,9 +410,9 @@ void BundleActiveCore::OnUserSwitched(const int userId) OnStatsChanged(userId); } -int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) +int32_t BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int32_t userId) { - BUNDLE_ACTIVE_LOGI("FLUSH interval is %{public}lld, debug is %{public}d", (long long)flushInterval_, debugCore_); + BUNDLE_ACTIVE_LOGI("FLUSH interval is %{public}" PRId64 ", debug is %{public}d", flushInterval_, debugCore_); event.PrintEvent(debugCore_); std::lock_guard lock(mutex_); if (userId == 0 || userId == -1) { @@ -432,9 +431,8 @@ 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, " - "eventid %{public}d, in lock range", event.bundleName_.c_str(), - (long long)event.timeStamp_, userId, event.eventId_); + BUNDLE_ACTIVE_LOGI("report event called, bundle name %{public}s time %{public}" PRId64 " 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) { return -1; @@ -456,7 +454,7 @@ int BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int userId) return 0; } -int BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event) +int32_t BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event) { BUNDLE_ACTIVE_LOGI("ReportEventToAllUserId called"); int64_t timeNow = CheckTimeChangeAndGetWallTime(); @@ -475,16 +473,15 @@ int BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event) BUNDLE_ACTIVE_LOGE("get user data service failed!"); return -1; } - BUNDLE_ACTIVE_LOGI("ReportEventToAllUserId SERVICE user ID IS userId %{public}d", - service->userId_); + BUNDLE_ACTIVE_LOGI("ReportEventToAllUserId SERVICE user ID IS userId %{public}d", service->userId_); service->ReportForShutdown(event); return 0; } return 0; } -std::vector BundleActiveCore::QueryPackageStats(const int userId, const int intervalType, - const int64_t beginTime, const int64_t endTime, std::string bundleName) +std::vector BundleActiveCore::QueryPackageStats(const int32_t userId, + const int32_t intervalType, const int64_t beginTime, const int64_t endTime, std::string bundleName) { BUNDLE_ACTIVE_LOGI("QueryPackageStats called"); std::lock_guard lock(mutex_); @@ -493,8 +490,8 @@ std::vector BundleActiveCore::QueryPackageStats(const if (timeNow == -1) { return result; } - BUNDLE_ACTIVE_LOGI("QueryPackageStats begin time is %{public}lld, end time is %{public}lld, " - "intervaltype is %{public}d", (long long)beginTime, (long long)endTime, intervalType); + BUNDLE_ACTIVE_LOGI("QueryPackageStats begin time is %{public}" PRId64 ", end time is %{public}" PRId64 ", " + "intervaltype is %{public}d", beginTime, endTime, intervalType); if (beginTime > timeNow || beginTime >= endTime) { BUNDLE_ACTIVE_LOGI("QueryPackageStats time span illegal"); return result; @@ -508,7 +505,7 @@ std::vector BundleActiveCore::QueryPackageStats(const return result; } -std::vector BundleActiveCore::QueryEvents(const int userId, const int64_t beginTime, +std::vector BundleActiveCore::QueryEvents(const int32_t userId, const int64_t beginTime, const int64_t endTime, std::string bundleName) { BUNDLE_ACTIVE_LOGI("QueryEvents called"); @@ -529,7 +526,8 @@ std::vector BundleActiveCore::QueryEvents(const int userId, c return result; } -int BundleActiveCore::QueryFormStatistics(int32_t maxNum, std::vector& results, int userId) +int32_t BundleActiveCore::QueryFormStatistics(int32_t maxNum, std::vector& results, + int32_t userId) { std::lock_guard lock(mutex_); int64_t timeNow = CheckTimeChangeAndGetWallTime(userId); @@ -540,29 +538,29 @@ int BundleActiveCore::QueryFormStatistics(int32_t maxNum, std::vectorQueryFormStatistics(maxNum, results); + int32_t errCode = service->QueryFormStatistics(maxNum, results); return errCode; } -void BundleActiveCore::SetBundleGroup(const std::string& bundleName, const int newGroup, const int userId) +void BundleActiveCore::SetBundleGroup(const std::string& bundleName, const int32_t newGroup, const int32_t userId) { - int newReason = GROUP_CONTROL_REASON_FORCED; + int32_t newReason = GROUP_CONTROL_REASON_FORCED; sptr timer = MiscServices::TimeServiceClient::GetInstance(); int64_t bootBasedTimeStamp = timer->GetBootTimeMs(); bundleGroupController_->SetBundleGroup(bundleName, userId, newGroup, newReason, bootBasedTimeStamp, false); } -int BundleActiveCore::QueryPackageGroup(const int userId, const std::string bundleName) +int32_t BundleActiveCore::QueryPackageGroup(const int32_t userId, const std::string bundleName) { return bundleGroupController_->QueryPackageGroup(userId, bundleName); } -int BundleActiveCore::IsBundleIdle(const std::string& bundleName, const int userId) +int32_t BundleActiveCore::IsBundleIdle(const std::string& bundleName, const int32_t userId) { return bundleGroupController_->IsBundleIdle(bundleName, userId); } -void BundleActiveCore::GetAllActiveUser(std::vector& activatedOsAccountIds) +void BundleActiveCore::GetAllActiveUser(std::vector& activatedOsAccountIds) { #ifdef OS_ACCOUNT_PART_ENABLED if (AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds) != ERR_OK) { diff --git a/services/common/src/bundle_active_debug_mode.cpp b/services/common/src/bundle_active_debug_mode.cpp index 5863fc6..7aa894c 100644 --- a/services/common/src/bundle_active_debug_mode.cpp +++ b/services/common/src/bundle_active_debug_mode.cpp @@ -23,7 +23,7 @@ using OHOS::system::GetParameter; namespace OHOS { namespace DeviceUsageStats { -constexpr int DEBUG_ON_DEFAULT = false; +constexpr int32_t DEBUG_ON_DEFAULT = 0; std::string DEBUG_MODE = "persist.sys.device_usage_debug_on"; const bool DEBUG_ON = static_cast(GetIntParameter(DEBUG_MODE, DEBUG_ON_DEFAULT)); } // namespace DeviceUsageStats diff --git a/services/common/src/bundle_active_open_callback.cpp b/services/common/src/bundle_active_open_callback.cpp index c114102..81e35cf 100644 --- a/services/common/src/bundle_active_open_callback.cpp +++ b/services/common/src/bundle_active_open_callback.cpp @@ -33,7 +33,7 @@ int32_t BundleActiveOpenCallback::OnCreate(NativeRdb::RdbStore &rdbStore) return NativeRdb::E_OK; }; -int32_t BundleActiveOpenCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int oldVersion, int newVersion) +int32_t BundleActiveOpenCallback::OnUpgrade(NativeRdb::RdbStore &rdbStore, int32_t oldVersion, int32_t newVersion) { (void)rdbStore; (void)oldVersion; diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 01dfab1..cdfef0e 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -27,10 +27,10 @@ namespace OHOS { namespace DeviceUsageStats { using namespace OHOS::Security; -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 int32_t PERIOD_BEST_JS = 0; +static const int32_t PERIOD_YEARLY_JS = 4; +static const int32_t PERIOD_BEST_SERVICE = 4; +static const int32_t DELAY_TIME = 2000; static const std::string PERMITTED_PROCESS_NAME = "foundation"; REGISTER_SYSTEM_ABILITY_BY_ID(BundleActiveService, DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, true); @@ -51,7 +51,7 @@ void BundleActiveService::OnStart() } InitNecessaryState(); - int ret = Publish(this); + int32_t ret = Publish(this); if (!ret) { BUNDLE_ACTIVE_LOGE("[Server] OnStart, Register SystemAbility[1907] FAIL."); return; @@ -203,13 +203,13 @@ void BundleActiveService::OnStop() BUNDLE_ACTIVE_LOGI("[Server] OnStop"); } -int BundleActiveService::ReportEvent(BundleActiveEvent& event, const int userId) +int32_t BundleActiveService::ReportEvent(BundleActiveEvent& event, const int32_t userId) { AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); if ((AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE)) { AccessToken::NativeTokenInfo callingTokenInfo; AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, callingTokenInfo); - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("calling process name is %{public}s, uid is %{public}d", callingTokenInfo.processName.c_str(), callingUid); if (callingTokenInfo.processName == PERMITTED_PROCESS_NAME) { @@ -236,11 +236,11 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName) { // get uid BUNDLE_ACTIVE_LOGI("Is bundle active called"); - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("UID is %{public}d", callingUid); // get user id - int userId = -1; - int result = -1; + int32_t userId = -1; + int32_t result = -1; OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); if (ret == ERR_OK && userId != -1) { result = bundleActiveCore_->IsBundleIdle(bundleName, userId); @@ -251,14 +251,13 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName) return true; } -std::vector BundleActiveService::QueryPackageStats(const int intervalType, - const int64_t beginTime, const int64_t endTime, int32_t& errCode, int userId) +std::vector BundleActiveService::QueryPackageStats(const int32_t intervalType, + const int64_t beginTime, const int64_t endTime, int32_t& errCode, int32_t userId) { - BUNDLE_ACTIVE_LOGI("QueryPackageStats stats called, intervaltype is %{public}d", - intervalType); + BUNDLE_ACTIVE_LOGI("QueryPackageStats stats called, intervaltype is %{public}d", intervalType); std::vector result; // get uid - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); BUNDLE_ACTIVE_LOGI("QueryPackageStats UID is %{public}d", callingUid); if (userId == -1) { @@ -276,7 +275,7 @@ std::vector BundleActiveService::QueryPackageStats(con if (isSystemAppAndHasPermission == true || AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE) { - int convertedIntervalType = ConvertIntervalType(intervalType); + int32_t convertedIntervalType = ConvertIntervalType(intervalType); result = bundleActiveCore_->QueryPackageStats(userId, convertedIntervalType, beginTime, endTime, ""); } } @@ -284,12 +283,12 @@ std::vector BundleActiveService::QueryPackageStats(con } std::vector BundleActiveService::QueryEvents(const int64_t beginTime, - const int64_t endTime, int32_t& errCode, int userId) + const int64_t endTime, int32_t& errCode, int32_t userId) { BUNDLE_ACTIVE_LOGI("QueryEvents stats called"); std::vector result; // get uid - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); BUNDLE_ACTIVE_LOGI("QueryEvents UID is %{public}d", callingUid); if (userId == -1) { @@ -313,23 +312,23 @@ std::vector BundleActiveService::QueryEvents(const int64_t be return result; } -void BundleActiveService::SetBundleGroup(const std::string& bundleName, int newGroup, int userId) +void BundleActiveService::SetBundleGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) { bundleActiveCore_->SetBundleGroup(bundleName, newGroup, userId); } -std::vector BundleActiveService::QueryCurrentPackageStats(const int intervalType, +std::vector BundleActiveService::QueryCurrentPackageStats(const int32_t intervalType, const int64_t beginTime, const int64_t endTime) { BUNDLE_ACTIVE_LOGI("QueryCurrentPackageStats stats called"); std::vector result; // get uid - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); BUNDLE_ACTIVE_LOGI("UID is %{public}d", callingUid); // get userid - int userId = -1; + int32_t userId = -1; OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); if (ret == ERR_OK && userId != -1) { BUNDLE_ACTIVE_LOGI("QueryCurrentPackageStats userid is %{public}d", userId); @@ -342,7 +341,7 @@ std::vector BundleActiveService::QueryCurrentPackageSt sptrBundleMgr_->GetBundleNameForUid(callingUid, bundleName); bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, tokenId, errCode); if (!bundleName.empty() && isSystemAppAndHasPermission == true) { - int convertedIntervalType = ConvertIntervalType(intervalType); + int32_t convertedIntervalType = ConvertIntervalType(intervalType); result = bundleActiveCore_->QueryPackageStats(userId, convertedIntervalType, beginTime, endTime, bundleName); } @@ -357,10 +356,10 @@ std::vector BundleActiveService::QueryCurrentEvents(const int BUNDLE_ACTIVE_LOGI("QueryCurrentEvents stats called"); std::vector result; // get uid - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("QueryCurrentEvents UID is %{public}d", callingUid); // get userid - int userId = -1; + int32_t userId = -1; OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); if (ret == ERR_OK && userId != -1) { if (!GetBundleMgrProxy()) { @@ -379,15 +378,15 @@ std::vector BundleActiveService::QueryCurrentEvents(const int return result; } -int BundleActiveService::QueryPackageGroup() +int32_t BundleActiveService::QueryPackageGroup() { BUNDLE_ACTIVE_LOGI("QueryPackageGroup stats called"); // get uid - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("QueryPackageGroup UID is %{public}d", callingUid); // get userid - int userId = -1; - int result = -1; + int32_t userId = -1; + int32_t result = -1; OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); BUNDLE_ACTIVE_LOGI("QueryPackageGroup user id is %{public}d", userId); if (ret == ERR_OK && userId != -1) { @@ -430,7 +429,7 @@ bool BundleActiveService::GetBundleMgrProxy() return true; } -int BundleActiveService::ConvertIntervalType(const int intervalType) +int32_t BundleActiveService::ConvertIntervalType(const int32_t intervalType) { if (intervalType == PERIOD_BEST_JS) { return PERIOD_BEST_SERVICE; @@ -440,7 +439,7 @@ int BundleActiveService::ConvertIntervalType(const int intervalType) return -1; } -bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int uid, +bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int32_t uid, OHOS::Security::AccessToken::AccessTokenID tokenId, int32_t& errCode) { if (!GetBundleMgrProxy()) { @@ -451,7 +450,7 @@ bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int uid, sptrBundleMgr_->GetBundleNameForUid(uid, bundleName); bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(uid); - int bundleHasPermission = AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, NEEDED_PERMISSION); + int32_t bundleHasPermission = AccessToken::AccessTokenKit::VerifyAccessToken(tokenId, NEEDED_PERMISSION); if (!bundleIsSystemApp) { errCode = BUNDLE_ACTIVE_FAIL; BUNDLE_ACTIVE_LOGE("%{public}s is not system app", bundleName.c_str()); @@ -461,15 +460,16 @@ bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int uid, BUNDLE_ACTIVE_LOGE("%{public}s hasn't permission", bundleName.c_str()); return false; } else { - BUNDLE_ACTIVE_LOGI(" %{public}s is system app %{public}d, " - "has permission %{public}d", bundleName.c_str(), bundleIsSystemApp, bundleHasPermission); + BUNDLE_ACTIVE_LOGI(" %{public}s is system app %{public}d, has permission %{public}d", + bundleName.c_str(), bundleIsSystemApp, bundleHasPermission); return true; } } -int BundleActiveService::QueryFormStatistics(int32_t maxNum, std::vector& results, int userId) +int32_t BundleActiveService::QueryFormStatistics(int32_t maxNum, std::vector& results, + int32_t userId) { - int callingUid = OHOS::IPCSkeleton::GetCallingUid(); + int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("QueryFormStatistics UID is %{public}d", callingUid); // get userid when userId is -1 int32_t errCode = 0; diff --git a/services/common/src/bundle_active_shutdown_callback_proxy.cpp b/services/common/src/bundle_active_shutdown_callback_proxy.cpp index 565e54e..a8c60c3 100644 --- a/services/common/src/bundle_active_shutdown_callback_proxy.cpp +++ b/services/common/src/bundle_active_shutdown_callback_proxy.cpp @@ -29,7 +29,7 @@ void BundleActiveShutdownCallbackProxy::ShutdownCallback() if (!data.WriteInterfaceToken(BundleActiveShutdownCallbackProxy::GetDescriptor())) { return; } - int ret = remote->SendRequest(IShutdownCallback::POWER_SHUTDOWN_CHANGED, data, reply, option); + int32_t ret = remote->SendRequest(IShutdownCallback::POWER_SHUTDOWN_CHANGED, data, reply, option); if (ret != ERR_OK) { BUNDLE_ACTIVE_LOGE("BundleActiveShutdownCallbackProxy::ShutdownCallback failed!"); } diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index fb11273..ad5037c 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -28,36 +28,34 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me } switch (code) { case REPORT_EVENT: { - int userId = data.ReadInt32(); + int32_t userId = data.ReadInt32(); std::shared_ptr tmpEvent; tmpEvent = tmpEvent->UnMarshalling(data); if (!tmpEvent) { return -1; } - int result = ReportEvent(*tmpEvent, userId); + int32_t result = ReportEvent(*tmpEvent, userId); return reply.WriteInt32(result); } case IS_BUNDLE_IDLE: { std::string bundleName = data.ReadString(); - int result = IsBundleIdle(bundleName); + int32_t result = IsBundleIdle(bundleName); return reply.WriteInt32(result); } case QUERY_USAGE_STATS: { std::vector result; - int size = 0; - int intervalType = data.ReadInt32(); - BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_USAGE_STATS intervaltype is %{public}d", - intervalType); + int32_t intervalType = data.ReadInt32(); + BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_USAGE_STATS intervaltype is %{public}d", intervalType); int64_t beginTime = data.ReadInt64(); int64_t endTime = data.ReadInt64(); int32_t userId = data.ReadInt32(); int32_t errCode = data.ReadInt32(); result = QueryPackageStats(intervalType, beginTime, endTime, errCode, userId); reply.WriteInt32(errCode); - size = static_cast(result.size()); + int32_t size = static_cast(result.size()); BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_USAGE_STATS result size is %{public}d", size); reply.WriteInt32(size); - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { bool tmp = result[i].Marshalling(reply); if (tmp == false) { return 1; @@ -67,16 +65,15 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me } case QUERY_EVENTS: { std::vector result; - int size = 0; int64_t beginTime = data.ReadInt64(); int64_t endTime = data.ReadInt64(); int32_t userId = data.ReadInt32(); int32_t errCode = data.ReadInt32(); result = QueryEvents(beginTime, endTime, errCode, userId); - size = static_cast(result.size()); + int32_t size = static_cast(result.size()); reply.WriteInt32(errCode); reply.WriteInt32(size); - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { bool tmp = result[i].Marshalling(reply); if (tmp == false) { return 1; @@ -86,25 +83,22 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me } case SET_BUNDLE_GROUP: { std::string bundleName = data.ReadString(); - int newGroup = data.ReadInt32(); - int userId = data.ReadInt32(); + int32_t newGroup = data.ReadInt32(); + int32_t userId = data.ReadInt32(); SetBundleGroup(bundleName, newGroup, userId); return 0; } case QUERY_CURRENT_USAGE_STATS: { std::vector result; - int size = 0; - int intervalType = data.ReadInt32(); - BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_CURRENT_USAGE_STATS intervaltype " - "is %{public}d", intervalType); + int32_t intervalType = data.ReadInt32(); + BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_CURRENT_USAGE_STATS intervaltype is %{public}d", intervalType); int64_t beginTime = data.ReadInt64(); int64_t endTime = data.ReadInt64(); result = QueryCurrentPackageStats(intervalType, beginTime, endTime); - size = static_cast(result.size()); - BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_CURRENT_USAGE_STATS result size " - "is %{public}d", size); + int32_t size = static_cast(result.size()); + BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_CURRENT_USAGE_STATS result size is %{public}d", size); reply.WriteInt32(size); - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { bool tmp = result[i].Marshalling(reply); if (tmp == false) { return 1; @@ -114,13 +108,12 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me } case QUERY_CURRENT_EVENTS: { std::vector result; - int size = 0; int64_t beginTime = data.ReadInt64(); int64_t endTime = data.ReadInt64(); result = QueryCurrentEvents(beginTime, endTime); - size = static_cast(result.size()); + int32_t size = static_cast(result.size()); reply.WriteInt32(size); - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { bool tmp = result[i].Marshalling(reply); if (tmp == false) { return 1; @@ -129,20 +122,19 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me return size == 0; } case QUERY_BUNDLE_GROUP: { - int result = -1; + int32_t result = -1; result = QueryPackageGroup(); return reply.WriteInt32(result); } case QUERY_FORM_STATS: { std::vector results; - int size = 0; int32_t maxNum = data.ReadInt32(); int32_t userId = data.ReadInt32(); int32_t errCode = QueryFormStatistics(maxNum, results, userId); - size = static_cast(results.size()); + int32_t size = static_cast(results.size()); reply.WriteInt32(errCode); reply.WriteInt32(size); - for (int i = 0; i < size; i++) { + for (int32_t i = 0; i < size; i++) { bool tmp = results[i].Marshalling(reply); if (tmp == false) { return 1; diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index ab171e6..82e112d 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -120,7 +120,7 @@ void BundleActiveUsageDatabase::InitUsageGroupDatabase(const int32_t databaseTyp int32_t BundleActiveUsageDatabase::CreateDatabasePath() { if (access(BUNDLE_ACTIVE_DATABASE_DIR.c_str(), F_OK) != 0) { - int createDir = mkdir(BUNDLE_ACTIVE_DATABASE_DIR.c_str(), S_IRWXU); + int32_t createDir = mkdir(BUNDLE_ACTIVE_DATABASE_DIR.c_str(), S_IRWXU); if (createDir != 0) { BUNDLE_ACTIVE_LOGE("failed to create directory %{public}s", BUNDLE_ACTIVE_DATABASE_DIR.c_str()); return BUNDLE_ACTIVE_FAIL; @@ -137,11 +137,11 @@ void BundleActiveUsageDatabase::InitDatabaseTableInfo(int64_t currentTime) return; } CheckDatabaseVersion(); - for (unsigned int i = 0; i < databaseFiles_.size(); i++) { + for (uint32_t i = 0; i < databaseFiles_.size(); i++) { HandleTableInfo(i); DeleteExcessiveTableData(i); } - for (unsigned int i = 0; i < sortedTableArray_.size(); i++) { + for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { int32_t startIndex = NearIndexOnOrAfterCurrentTime(currentTime, sortedTableArray_.at(i)); if (startIndex < BUNDLE_ACTIVE_SUCCESS) { continue; @@ -201,7 +201,7 @@ int32_t BundleActiveUsageDatabase::NearIndexOnOrBeforeCurrentTime(int64_t curren return index - 1; } -unique_ptr BundleActiveUsageDatabase::QueryStatsInfoByStep(unsigned int databaseType, +unique_ptr BundleActiveUsageDatabase::QueryStatsInfoByStep(uint32_t databaseType, const string &sql, const vector &selectionArgs) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); @@ -218,7 +218,7 @@ unique_ptr BundleActiveUsageDatabase::QueryStatsInfoByStep return result; } -void BundleActiveUsageDatabase::HandleTableInfo(unsigned int databaseType) +void BundleActiveUsageDatabase::HandleTableInfo(uint32_t databaseType) { string queryDatabaseTableNames = "select * from sqlite_master where type = ?"; vector queryCondition; @@ -262,7 +262,7 @@ void BundleActiveUsageDatabase::HandleTableInfo(unsigned int databaseType) } } -void BundleActiveUsageDatabase::DeleteExcessiveTableData(unsigned int databaseType) +void BundleActiveUsageDatabase::DeleteExcessiveTableData(uint32_t databaseType) { if (databaseType >= 0 && databaseType < sortedTableArray_.size()) { if (sortedTableArray_.at(databaseType).empty()) { @@ -313,7 +313,7 @@ void BundleActiveUsageDatabase::DeleteExcessiveTableData(unsigned int databaseTy } } -std::unique_ptr> BundleActiveUsageDatabase::GetOverdueTableCreateTime(unsigned int databaseType, +std::unique_ptr> BundleActiveUsageDatabase::GetOverdueTableCreateTime(uint32_t databaseType, int64_t currentTimeMillis) { std::unique_ptr> overdueTableCreateTime = std::make_unique>(); @@ -349,7 +349,7 @@ std::unique_ptr> BundleActiveUsageDatabase::GetOverdueTable return overdueTableCreateTime; } -int32_t BundleActiveUsageDatabase::DeleteInvalidTable(unsigned int databaseType, int64_t tableTimeMillis) +int32_t BundleActiveUsageDatabase::DeleteInvalidTable(uint32_t databaseType, int64_t tableTimeMillis) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -405,12 +405,12 @@ void BundleActiveUsageDatabase::CheckDatabaseVersion() } } -shared_ptr BundleActiveUsageDatabase::GetBundleActiveRdbStore(unsigned int databaseType) +shared_ptr BundleActiveUsageDatabase::GetBundleActiveRdbStore(uint32_t databaseType) { shared_ptr rdbStore; string file = databaseFiles_.at(databaseType); if (bundleActiveRdbStoreCache_.find(file) == bundleActiveRdbStoreCache_.end()) { - int errCode(BUNDLE_ACTIVE_FAIL); + int32_t errCode(BUNDLE_ACTIVE_FAIL); string currDatabaseFileConfig = BUNDLE_ACTIVE_DATABASE_DIR + databaseFiles_.at(databaseType); RdbStoreConfig config(currDatabaseFileConfig); BundleActiveOpenCallback rdbDataCallBack; @@ -430,7 +430,7 @@ shared_ptr BundleActiveUsageDatabase::GetBundleActiveRdbSto return rdbStore; } -void BundleActiveUsageDatabase::CheckDatabaseFile(unsigned int databaseType) +void BundleActiveUsageDatabase::CheckDatabaseFile(uint32_t databaseType) { std::string databaseFileName = databaseFiles_.at(databaseType); std::string dbFile; @@ -456,7 +456,7 @@ void BundleActiveUsageDatabase::CheckDatabaseFile(unsigned int databaseType) } } -int32_t BundleActiveUsageDatabase::CreateEventLogTable(unsigned int databaseType, int64_t currentTimeMillis) +int32_t BundleActiveUsageDatabase::CreateEventLogTable(uint32_t databaseType, int64_t currentTimeMillis) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -487,7 +487,7 @@ int32_t BundleActiveUsageDatabase::CreateEventLogTable(unsigned int databaseType return BUNDLE_ACTIVE_SUCCESS; } -int32_t BundleActiveUsageDatabase::CreatePackageLogTable(unsigned int databaseType, int64_t currentTimeMillis) +int32_t BundleActiveUsageDatabase::CreatePackageLogTable(uint32_t databaseType, int64_t currentTimeMillis) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -519,7 +519,7 @@ int32_t BundleActiveUsageDatabase::CreatePackageLogTable(unsigned int databaseTy return BUNDLE_ACTIVE_SUCCESS; } -int32_t BundleActiveUsageDatabase::CreateModuleRecordTable(unsigned int databaseType, int64_t timeStamp) +int32_t BundleActiveUsageDatabase::CreateModuleRecordTable(uint32_t databaseType, int64_t timeStamp) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -550,7 +550,7 @@ int32_t BundleActiveUsageDatabase::CreateModuleRecordTable(unsigned int database return BUNDLE_ACTIVE_SUCCESS; } -int32_t BundleActiveUsageDatabase::CreateFormRecordTable(unsigned int databaseType, int64_t timeStamp) +int32_t BundleActiveUsageDatabase::CreateFormRecordTable(uint32_t databaseType, int64_t timeStamp) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -584,7 +584,7 @@ int32_t BundleActiveUsageDatabase::CreateFormRecordTable(unsigned int databaseTy return BUNDLE_ACTIVE_SUCCESS; } -int32_t BundleActiveUsageDatabase::CreateDurationTable(unsigned int databaseType) +int32_t BundleActiveUsageDatabase::CreateDurationTable(uint32_t databaseType) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -604,7 +604,7 @@ int32_t BundleActiveUsageDatabase::CreateDurationTable(unsigned int databaseType return BUNDLE_ACTIVE_SUCCESS; } -int32_t BundleActiveUsageDatabase::CreateBundleHistoryTable(unsigned int databaseType) +int32_t BundleActiveUsageDatabase::CreateBundleHistoryTable(uint32_t databaseType) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -637,7 +637,7 @@ int32_t BundleActiveUsageDatabase::CreateBundleHistoryTable(unsigned int databas return BUNDLE_ACTIVE_SUCCESS; } -void BundleActiveUsageDatabase::PutBundleHistoryData(int userId, +void BundleActiveUsageDatabase::PutBundleHistoryData(int32_t userId, shared_ptr>> userHistory) { lock_guard lock(databaseMutex_); @@ -658,8 +658,8 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId, int64_t outRowId = BUNDLE_ACTIVE_FAIL; NativeRdb::ValuesBucket valuesBucket; vector queryCondition; - int updatedcount = 0; - int unupdatedcount = 0; + int32_t updatedcount = 0; + int32_t unupdatedcount = 0; for (auto iter = userHistory->begin(); iter != userHistory->end(); iter++) { if (iter->second == nullptr || !iter->second->isChanged_) { unupdatedcount++; @@ -670,7 +670,7 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId, valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_BOOT_FROM_USED_TIME, iter->second->lastBootFromUsedTimeStamp_); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_LAST_SCREEN_USED_TIME, iter->second->lastScreenUsedTimeStamp_); valuesBucket.PutInt(BUNDLE_ACTIVE_DB_CURRENT_GROUP, iter->second->currentGroup_); - valuesBucket.PutInt(BUNDLE_ACTIVE_DB_REASON_IN_GROUP, static_cast(iter->second->reasonInGroup_)); + valuesBucket.PutInt(BUNDLE_ACTIVE_DB_REASON_IN_GROUP, static_cast(iter->second->reasonInGroup_)); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_BUNDLE_ALIVE_TIMEOUT_TIME, iter->second->bundleAliveTimeoutTimeStamp_); valuesBucket.PutLong(BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME, iter->second->bundleDailyTimeoutTimeStamp_); rdbStore->Update(changeRow, BUNDLE_HISTORY_LOG_TABLE, valuesBucket, "userId = ? and bundleName = ?", @@ -693,7 +693,7 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId, } shared_ptr>> BundleActiveUsageDatabase::GetBundleHistoryData( - int userId) + int32_t userId) { lock_guard lock(databaseMutex_); if (bundleHistoryTableName_ == UNKNOWN_TABLE_NAME) { @@ -716,7 +716,7 @@ shared_ptr>> BundleActiveUsag shared_ptr>> userUsageHistory = make_shared>>(); shared_ptr usageHistory; - int currentBundleGroupReason = 0; + int32_t currentBundleGroupReason = 0; for (int32_t i = 0; i < tableRowNumber; i++) { bundleActiveResult->GoToRow(i); bundleActiveResult->GetString(BUNDLE_NAME_COLUMN_INDEX, bundleName); @@ -783,7 +783,7 @@ pair BundleActiveUsageDatabase::GetDurationData() return durationData; } -void BundleActiveUsageDatabase::FlushPackageInfo(unsigned int databaseType, const BundleActivePeriodStats &stats) +void BundleActiveUsageDatabase::FlushPackageInfo(uint32_t databaseType, const BundleActivePeriodStats &stats) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); string tableName = PACKAGE_LOG_TABLE + to_string(stats.beginTime_); @@ -822,7 +822,7 @@ void BundleActiveUsageDatabase::FlushPackageInfo(unsigned int databaseType, cons } shared_ptr BundleActiveUsageDatabase::GetCurrentUsageData(int32_t databaseType, - int userId) + int32_t userId) { lock_guard lock(databaseMutex_); if (databaseType < 0 || databaseType >= static_cast(sortedTableArray_.size())) { @@ -830,7 +830,7 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa return nullptr; } - int tableNumber = static_cast(sortedTableArray_.at(databaseType).size()); + int32_t tableNumber = static_cast(sortedTableArray_.at(databaseType).size()); if (tableNumber == TABLE_NOT_EXIST) { return nullptr; } @@ -880,7 +880,7 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa return intervalStats; } -void BundleActiveUsageDatabase::FlushEventInfo(unsigned int databaseType, BundleActivePeriodStats &stats) +void BundleActiveUsageDatabase::FlushEventInfo(uint32_t databaseType, BundleActivePeriodStats &stats) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -904,7 +904,7 @@ void BundleActiveUsageDatabase::FlushEventInfo(unsigned int databaseType, Bundle } } -string BundleActiveUsageDatabase::GetTableIndexSql(unsigned int databaseType, int64_t tableTime, bool createFlag, +string BundleActiveUsageDatabase::GetTableIndexSql(uint32_t databaseType, int64_t tableTime, bool createFlag, int32_t indexFlag) { string tableIndexSql; @@ -954,7 +954,7 @@ string BundleActiveUsageDatabase::GetTableIndexSql(unsigned int databaseType, in return tableIndexSql; } -int32_t BundleActiveUsageDatabase::SetNewIndexWhenTimeChanged(unsigned int databaseType, int64_t tableOldTime, +int32_t BundleActiveUsageDatabase::SetNewIndexWhenTimeChanged(uint32_t databaseType, int64_t tableOldTime, int64_t tableNewTime, std::shared_ptr rdbStore) { if (rdbStore == nullptr) { @@ -1000,7 +1000,7 @@ int32_t BundleActiveUsageDatabase::SetNewIndexWhenTimeChanged(unsigned int datab return BUNDLE_ACTIVE_SUCCESS; } -int32_t BundleActiveUsageDatabase::RenameTableName(unsigned int databaseType, int64_t tableOldTime, +int32_t BundleActiveUsageDatabase::RenameTableName(uint32_t databaseType, int64_t tableOldTime, int64_t tableNewTime) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); @@ -1016,7 +1016,7 @@ int32_t BundleActiveUsageDatabase::RenameTableName(unsigned int databaseType, in if (renamePackageTableName != NativeRdb::E_OK) { return BUNDLE_ACTIVE_FAIL; } - int setResult = SetNewIndexWhenTimeChanged(databaseType, tableOldTime, tableNewTime, rdbStore); + int32_t setResult = SetNewIndexWhenTimeChanged(databaseType, tableOldTime, tableNewTime, rdbStore); if (setResult != BUNDLE_ACTIVE_SUCCESS) { return BUNDLE_ACTIVE_FAIL; } @@ -1028,7 +1028,7 @@ int32_t BundleActiveUsageDatabase::RenameTableName(unsigned int databaseType, in if (renameEventTableName != NativeRdb::E_OK) { return BUNDLE_ACTIVE_FAIL; } - int setResult = SetNewIndexWhenTimeChanged(databaseType, tableOldTime, tableNewTime, rdbStore); + int32_t setResult = SetNewIndexWhenTimeChanged(databaseType, tableOldTime, tableNewTime, rdbStore); if (setResult != BUNDLE_ACTIVE_SUCCESS) { return BUNDLE_ACTIVE_FAIL; } @@ -1047,7 +1047,7 @@ int32_t BundleActiveUsageDatabase::RenameTableName(unsigned int databaseType, in if (renameFormTableName != NativeRdb::E_OK) { return BUNDLE_ACTIVE_FAIL; } - int setResult = SetNewIndexWhenTimeChanged(databaseType, tableOldTime, tableNewTime, rdbStore); + int32_t setResult = SetNewIndexWhenTimeChanged(databaseType, tableOldTime, tableNewTime, rdbStore); if (setResult != BUNDLE_ACTIVE_SUCCESS) { return BUNDLE_ACTIVE_FAIL; } @@ -1083,7 +1083,7 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime) std::unique_ptr> overdueYearsTableCreateTime = GetOverdueTableCreateTime(YEARLY_DATABASE_INDEX, calendar_->GetMilliseconds()); if (overdueYearsTableCreateTime != nullptr) { - for (unsigned int i = 0; i < overdueYearsTableCreateTime->size(); i++) { + for (uint32_t i = 0; i < overdueYearsTableCreateTime->size(); i++) { DeleteInvalidTable(YEARLY_DATABASE_INDEX, overdueYearsTableCreateTime->at(i)); } } @@ -1092,7 +1092,7 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime) std::unique_ptr> overdueMonthsTableCreateTime = GetOverdueTableCreateTime(MONTHLY_DATABASE_INDEX, calendar_->GetMilliseconds()); if (overdueMonthsTableCreateTime != nullptr) { - for (unsigned int i = 0; i < overdueMonthsTableCreateTime->size(); i++) { + for (uint32_t i = 0; i < overdueMonthsTableCreateTime->size(); i++) { DeleteInvalidTable(MONTHLY_DATABASE_INDEX, overdueMonthsTableCreateTime->at(i)); } } @@ -1101,7 +1101,7 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime) std::unique_ptr> overdueWeeksTableCreateTime = GetOverdueTableCreateTime(WEEKLY_DATABASE_INDEX, calendar_->GetMilliseconds()); if (overdueWeeksTableCreateTime != nullptr) { - for (unsigned int i = 0; i < overdueWeeksTableCreateTime->size(); i++) { + for (uint32_t i = 0; i < overdueWeeksTableCreateTime->size(); i++) { DeleteInvalidTable(WEEKLY_DATABASE_INDEX, overdueWeeksTableCreateTime->at(i)); } } @@ -1110,11 +1110,11 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime) std::unique_ptr> overdueDaysTableCreateTime = GetOverdueTableCreateTime(DAILY_DATABASE_INDEX, calendar_->GetMilliseconds()); if (overdueDaysTableCreateTime != nullptr) { - for (unsigned int i = 0; i < overdueDaysTableCreateTime->size(); i++) { + for (uint32_t i = 0; i < overdueDaysTableCreateTime->size(); i++) { DeleteInvalidTable(DAILY_DATABASE_INDEX, overdueDaysTableCreateTime->at(i)); } } - for (unsigned int i = 0; i < sortedTableArray_.size(); i++) { + for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { HandleTableInfo(i); DeleteExcessiveTableData(i); } @@ -1123,14 +1123,14 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime) void BundleActiveUsageDatabase::RenewTableTime(int64_t changedTime) { lock_guard lock(databaseMutex_); - for (unsigned int i = 0; i < sortedTableArray_.size(); i++) { + for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { if (sortedTableArray_.at(i).empty()) { continue; } vector tableArray = sortedTableArray_.at(i); - for (unsigned int j = 0; j < tableArray.size(); j++) { + for (uint32_t j = 0; j < tableArray.size(); j++) { int64_t newTime = tableArray.at(j) + changedTime; - BUNDLE_ACTIVE_LOGI("new table time is %{public}lld", (long long)newTime); + BUNDLE_ACTIVE_LOGI("new table time is %{public}" PRId64 "", newTime); if (newTime < 0) { DeleteInvalidTable(i, tableArray.at(j)); } else { @@ -1200,7 +1200,7 @@ void BundleActiveUsageDatabase::UpdateUsageData(int32_t databaseType, BundleActi } vector BundleActiveUsageDatabase::QueryDatabaseUsageStats(int32_t databaseType, - int64_t beginTime, int64_t endTime, int userId) + int64_t beginTime, int64_t endTime, int32_t userId) { lock_guard lock(databaseMutex_); vector databaseUsageStats; @@ -1209,8 +1209,7 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt return databaseUsageStats; } if (endTime <= beginTime) { - BUNDLE_ACTIVE_LOGE("endTime(%{public}lld) <= beginTime(%{public}lld)", - (long long)endTime, (long long)beginTime); + BUNDLE_ACTIVE_LOGE("endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", endTime, beginTime); return databaseUsageStats; } int32_t startIndex = NearIndexOnOrBeforeCurrentTime(beginTime, sortedTableArray_.at(databaseType)); @@ -1293,7 +1292,7 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt } vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t beginTime, int64_t endTime, - int userId, string bundleName) + int32_t userId, string bundleName) { lock_guard lock(databaseMutex_); vector databaseEvents; @@ -1302,14 +1301,13 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t return databaseEvents; } if (endTime <= beginTime) { - BUNDLE_ACTIVE_LOGE("endTime(%{public}lld) <= beginTime(%{public}lld)", - (long long)endTime, (long long)beginTime); + BUNDLE_ACTIVE_LOGE("endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", endTime, beginTime); return databaseEvents; } int64_t eventTableTime = ParseStartTime(eventTableName_); if (endTime < eventTableTime) { - BUNDLE_ACTIVE_LOGE("endTime(%{public}lld) <= eventTableTime(%{public}lld)", - (long long)endTime, (long long)eventTableTime); + BUNDLE_ACTIVE_LOGE("endTime(%{public}" PRId64 ") <= eventTableTime(%{public}" PRId64 ")", + endTime, eventTableTime); return databaseEvents; } vector queryCondition; @@ -1350,7 +1348,7 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t return databaseEvents; } -void BundleActiveUsageDatabase::OnPackageUninstalled(const int userId, const string& bundleName) +void BundleActiveUsageDatabase::OnPackageUninstalled(const int32_t userId, const string& bundleName) { lock_guard lock(databaseMutex_); for (uint32_t i = 0; i < sortedTableArray_.size(); i++) { @@ -1376,8 +1374,8 @@ void BundleActiveUsageDatabase::OnPackageUninstalled(const int userId, const str } } -void BundleActiveUsageDatabase::DeleteUninstalledInfo(const int userId, const string& bundleName, - const string& tableName, unsigned int databaseType) +void BundleActiveUsageDatabase::DeleteUninstalledInfo(const int32_t userId, const string& bundleName, + const string& tableName, uint32_t databaseType) { shared_ptr rdbStore = GetBundleActiveRdbStore(databaseType); if (rdbStore == nullptr) { @@ -1413,7 +1411,7 @@ int64_t BundleActiveUsageDatabase::GetSystemTimeMs() return static_cast(tarDate); } -void BundleActiveUsageDatabase::UpdateModuleData(const int userId, +void BundleActiveUsageDatabase::UpdateModuleData(const int32_t userId, std::map>& moduleRecords, const int64_t timeStamp) { lock_guard lock(databaseMutex_); @@ -1502,7 +1500,7 @@ void BundleActiveUsageDatabase::UpdateFormData(const int32_t userId, const std:: } } -void BundleActiveUsageDatabase::RemoveFormData(const int userId, const std::string bundleName, +void BundleActiveUsageDatabase::RemoveFormData(const int32_t userId, const std::string bundleName, const std::string moduleName, const std::string formName, const int32_t formDimension, const int64_t formId) { @@ -1521,12 +1519,12 @@ void BundleActiveUsageDatabase::RemoveFormData(const int userId, const std::stri queryCondition.emplace_back(formName); queryCondition.emplace_back(to_string(formDimension)); queryCondition.emplace_back(to_string(formId)); - int r = rdbStore->Delete(deletedRows, formRecordsTableName_, + int32_t ret = rdbStore->Delete(deletedRows, formRecordsTableName_, "userId = ? and bundleName = ? and moduleName = ? and formName = ? and formDimension = ? " "and formId = ?", queryCondition); - if (r != NativeRdb::E_OK) { - BUNDLE_ACTIVE_LOGE("delete event data failed, rdb error number: %{public}d", r); + if (ret != NativeRdb::E_OK) { + BUNDLE_ACTIVE_LOGE("delete event data failed, rdb error number: %{public}d", ret); } } } diff --git a/services/packagegroup/include/bundle_active_group_common.h b/services/packagegroup/include/bundle_active_group_common.h index 48208ac..b607952 100644 --- a/services/packagegroup/include/bundle_active_group_common.h +++ b/services/packagegroup/include/bundle_active_group_common.h @@ -19,16 +19,16 @@ namespace OHOS { namespace DeviceUsageStats { namespace DeviceUsageStatsGroupConst { -const int ACTIVE_GROUP_UNKNOWN = -1; -const int ACTIVE_GROUP_FORCED_SET = 5; -const int ACTIVE_GROUP_ALIVE = 10; -const int ACTIVE_GROUP_DAILY = 20; -const int ACTIVE_GROUP_FIXED = 30; -const int ACTIVE_GROUP_RARE = 40; -const int ACTIVE_GROUP_LIMIT = 50; -const int ACTIVE_GROUP_NEVER = 60; -const int64_t FIVE_SECOND = 5 * 1000; -const int64_t ONE_MINUTE = 60 * 1000; +const int32_t ACTIVE_GROUP_UNKNOWN = -1; +const int32_t ACTIVE_GROUP_FORCED_SET = 5; +const int32_t ACTIVE_GROUP_ALIVE = 10; +const int32_t ACTIVE_GROUP_DAILY = 20; +const int32_t ACTIVE_GROUP_FIXED = 30; +const int32_t ACTIVE_GROUP_RARE = 40; +const int32_t ACTIVE_GROUP_LIMIT = 50; +const int32_t ACTIVE_GROUP_NEVER = 60; +const int64_t FIVE_SECOND = 5 * 1000LL; +const int64_t ONE_MINUTE = 60 * 1000LL; const int64_t TWO_MINUTE = 2 * ONE_MINUTE; const int64_t THREE_MINUTE = 3 * ONE_MINUTE; const int64_t FOUR_MINUTE = 4 * ONE_MINUTE; diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 4bfb845..0f534cd 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -43,7 +43,7 @@ public: using ApplicationFlag = OHOS::AppExecFwk::ApplicationFlag; OHOS::AppExecFwk::ApplicationFlag flag = OHOS::AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO; bool bundleGroupEnable_ = true; - const int LEVEL_GROUP[4] = { + const int32_t LEVEL_GROUP[4] = { ACTIVE_GROUP_ALIVE, ACTIVE_GROUP_DAILY, ACTIVE_GROUP_FIXED, @@ -56,30 +56,30 @@ public: std::shared_ptr bundleUserHistory_; void SetHandlerAndCreateUserHistory(const std::shared_ptr& groupHandler, const int64_t bootFromTimeStamp); - void ReportEvent(const BundleActiveEvent& event, const int64_t bootBasedTimeStamp, const int userId); - void CheckAndUpdateGroup(const std::string& bundleName, const int userId, const int64_t bootBasedTimeStamp); - bool CheckEachBundleState(const int userId); + void ReportEvent(const BundleActiveEvent& event, const int64_t bootBasedTimeStamp, const int32_t userId); + void CheckAndUpdateGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp); + bool CheckEachBundleState(const int32_t userId); void CheckIdleStatsOneTime(); - void PeriodCheckBundleState(const int userId); - void OnUserRemoved(const int userId); - void OnBundleUninstalled(const int userId, const std::string bundleName); + void PeriodCheckBundleState(const int32_t userId); + void OnUserRemoved(const int32_t userId); + void OnBundleUninstalled(const int32_t userId, const std::string bundleName); void OnScreenChanged(const bool& isScreenOn, const int64_t bootFromTimeStamp); - void SetBundleGroup(const std::string& bundleName, const int userId, int newGroup, uint32_t reason, + void SetBundleGroup(const std::string& bundleName, const int32_t userId, int32_t newGroup, uint32_t reason, const int64_t bootBasedTimeStamp, const bool& resetTimeout); - void RestoreToDatabase(const int userId); + void RestoreToDatabase(const int32_t userId); void RestoreDurationToDatabase(); - bool IsBundleInstalled(const std::string& bundleName, const int userId); + bool IsBundleInstalled(const std::string& bundleName, const int32_t userId); bool IsScreenOn(); - int IsBundleIdle(const std::string& bundleName, const int userId); - int QueryPackageGroup(const int userId, const std::string& bundleName); - void ShutDown(const int64_t bootBasedTimeStamp, const int userId); - void OnUserSwitched(const int userId, const int currentUsedUser); + int32_t IsBundleIdle(const std::string& bundleName, const int32_t userId); + int32_t QueryPackageGroup(const int32_t userId, const std::string& bundleName); + void ShutDown(const int64_t bootBasedTimeStamp, const int32_t userId); + void OnUserSwitched(const int32_t userId, const int32_t currentUsedUser); private: std::mutex mutex_; bool GetBundleMgrProxy(); std::weak_ptr activeGroupHandler_; - uint32_t EventToGroupReason(const int eventId); + uint32_t EventToGroupReason(const int32_t eventId); int64_t timeoutForDirectlyUse_; int64_t timeoutForNotifySeen_; int64_t timeoutForSystemInteraction_; @@ -87,7 +87,7 @@ private: sptr sptrBundleMgr_; bool calculationTimeOut(const std::shared_ptr& oneBundleHistory, const int64_t bootBasedTimeStamp); - int GetNewGroup(const std::string& bundleName, const int userId, const int64_t bootBasedTimeStamp); + int32_t GetNewGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packagegroup/include/bundle_active_group_handler.h b/services/packagegroup/include/bundle_active_group_handler.h index cea2d17..96ec7bf 100644 --- a/services/packagegroup/include/bundle_active_group_handler.h +++ b/services/packagegroup/include/bundle_active_group_handler.h @@ -28,7 +28,7 @@ namespace DeviceUsageStats { class BundleActiveGroupHandlerObject { public: std::string bundleName_; - int userId_; + int32_t userId_; BundleActiveGroupHandlerObject(); BundleActiveGroupHandlerObject(const BundleActiveGroupHandlerObject& orig); ~BundleActiveGroupHandlerObject() {} @@ -45,9 +45,9 @@ public: */ void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; void Init(const std::shared_ptr& bundleActiveController); - static const int MSG_CHECK_BUNDLE_STATE = 0; - static const int MSG_ONE_TIME_CHECK_BUNDLE_STATE = 1; - static const int MSG_CHECK_IDLE_STATE = 2; + static const int32_t MSG_CHECK_BUNDLE_STATE = 0; + static const int32_t MSG_ONE_TIME_CHECK_BUNDLE_STATE = 1; + static const int32_t MSG_CHECK_IDLE_STATE = 2; int64_t checkIdleInterval_; private: diff --git a/services/packagegroup/include/bundle_active_package_history.h b/services/packagegroup/include/bundle_active_package_history.h index 3a1af0d..ac4b450 100644 --- a/services/packagegroup/include/bundle_active_package_history.h +++ b/services/packagegroup/include/bundle_active_package_history.h @@ -25,8 +25,8 @@ public: int64_t lastBootFromUsedTimeStamp_; int64_t lastScreenUsedTimeStamp_; int64_t lastGroupCalculatedTimeStamp_; - int lastCalculatedGroup_; - int currentGroup_; + int32_t lastCalculatedGroup_; + int32_t currentGroup_; uint32_t reasonInGroup_; int64_t bundleAliveTimeoutTimeStamp_; int64_t bundleDailyTimeoutTimeStamp_; diff --git a/services/packagegroup/include/bundle_active_user_history.h b/services/packagegroup/include/bundle_active_user_history.h index 5e18960..7279324 100644 --- a/services/packagegroup/include/bundle_active_user_history.h +++ b/services/packagegroup/include/bundle_active_user_history.h @@ -38,27 +38,27 @@ public: BundleActiveUsageDatabase database_; BundleActiveUserHistory(const int64_t bootBasedTimeStamp); std::shared_ptr GetUsageHistoryForBundle(const std::string& bundleName, - const int userId, const int64_t bootBasedTimeStamp, const bool& create); + const int32_t userId, const int64_t bootBasedTimeStamp, const bool& create); std::shared_ptr>> GetUserHistory( - const int userId, const bool& create); + const int32_t userId, const bool& create); std::shared_ptr GetUsageHistoryInUserHistory(std::shared_ptr>> oneUserHistory, std::string bundleName, int64_t bootBasedTimeStamp, bool create); int64_t GetBootBasedTimeStamp(int64_t bootBasedTimeStamp); int64_t GetScreenOnTimeStamp(int64_t bootBasedTimeStamp); void ReportUsage(std::shared_ptr oneBundleUsageHistory, const std::string& bundleName, - const int newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, + const int32_t newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, const int64_t timeUntilNextCheck); - void SetBundleGroup(const std::string& bundleName, const int userId, const int64_t bootBasedTimeStamp, - int newGroup, uint32_t groupReason, const bool& resetTimeout); - int GetLevelIndex(const std::string& bundleName, const int userId, const int64_t bootBasedTimeStamp, + void SetBundleGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, + int32_t newGroup, uint32_t groupReason, const bool& resetTimeout); + int32_t GetLevelIndex(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const std::vector screenTimeLeve, const std::vector bootFromTimeLevel); void WriteDeviceDuration(); - void WriteBundleUsage(const int userId); - void PrintData(int userId); + void WriteBundleUsage(const int32_t userId); + void PrintData(int32_t userId); void UpdateBootBasedAndScreenTime(const bool& isScreenOn, const int64_t bootBasedTimeStamp, const bool& isShutdown = false); - void OnBundleUninstalled(const int userId, const std::string bundleName); + void OnBundleUninstalled(const int32_t userId, const std::string bundleName); private: bool isScreenOn_; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 7b1d841..1782433 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -46,13 +46,13 @@ void BundleActiveGroupController::RestoreDurationToDatabase() bundleUserHistory_->WriteDeviceDuration(); } -void BundleActiveGroupController::RestoreToDatabase(const int userId) +void BundleActiveGroupController::RestoreToDatabase(const int32_t userId) { std::lock_guard lock(mutex_); bundleUserHistory_->WriteBundleUsage(userId); } -void BundleActiveGroupController::OnUserRemoved(const int userId) +void BundleActiveGroupController::OnUserRemoved(const int32_t userId) { std::lock_guard lock(mutex_); bundleUserHistory_->userHistory_.erase(userId); @@ -61,7 +61,7 @@ void BundleActiveGroupController::OnUserRemoved(const int userId) } } -void BundleActiveGroupController::OnUserSwitched(const int userId, const int currentUsedUser) +void BundleActiveGroupController::OnUserSwitched(const int32_t userId, const int32_t currentUsedUser) { BUNDLE_ACTIVE_LOGI("last time check for user %{public}d", currentUsedUser); CheckEachBundleState(currentUsedUser); @@ -85,14 +85,14 @@ void BundleActiveGroupController::SetHandlerAndCreateUserHistory( { if (bundleUserHistory_ == nullptr) { BUNDLE_ACTIVE_LOGI("SetHandlerAndCreateUserHistory bundleUserHistory_ is null, " - "called constructor, bootstamp is %{public}lld", (long long)bootFromTimeStamp); + "called constructor, bootstamp is %{public}" PRId64 "", bootFromTimeStamp); bundleUserHistory_ = std::make_shared(bootFromTimeStamp); } OnScreenChanged(IsScreenOn(), bootFromTimeStamp); activeGroupHandler_ = groupHandler; } -void BundleActiveGroupController::OnBundleUninstalled(const int userId, const std::string bundleName) +void BundleActiveGroupController::OnBundleUninstalled(const int32_t userId, const std::string bundleName) { std::lock_guard lock(mutex_); BUNDLE_ACTIVE_LOGI("OnBundleUninstalled called, userId is %{public}d, bundlename is %{public}s", @@ -128,7 +128,7 @@ bool BundleActiveGroupController::GetBundleMgrProxy() return true; } -void BundleActiveGroupController::PeriodCheckBundleState(const int userId) +void BundleActiveGroupController::PeriodCheckBundleState(const int32_t userId) { BUNDLE_ACTIVE_LOGI("PeriodCheckBundleState called"); if (!activeGroupHandler_.expired()) { @@ -142,7 +142,7 @@ void BundleActiveGroupController::PeriodCheckBundleState(const int userId) } } -bool BundleActiveGroupController::CheckEachBundleState(const int userId) +bool BundleActiveGroupController::CheckEachBundleState(const int32_t userId) { BUNDLE_ACTIVE_LOGI("CheckEachBundleState called, userid is %{public}d", userId); std::vector allBundlesForUser; @@ -172,10 +172,10 @@ void BundleActiveGroupController::CheckIdleStatsOneTime() } } -int BundleActiveGroupController::GetNewGroup(const std::string& bundleName, const int userId, +int32_t BundleActiveGroupController::GetNewGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp) { - int groupIndex = bundleUserHistory_->GetLevelIndex(bundleName, userId, bootBasedTimeStamp, screenTimeLevel_, + int32_t groupIndex = bundleUserHistory_->GetLevelIndex(bundleName, userId, bootBasedTimeStamp, screenTimeLevel_, bootTimeLevel_); if (groupIndex < 0) { return -1; @@ -194,7 +194,7 @@ bool BundleActiveGroupController::calculationTimeOut( - lastGroupCalculatedTimeStamp > timeoutCalculated_; } -uint32_t BundleActiveGroupController::EventToGroupReason(const int eventId) +uint32_t BundleActiveGroupController::EventToGroupReason(const int32_t eventId) { switch (eventId) { case BundleActiveEvent::ABILITY_FOREGROUND: @@ -215,7 +215,7 @@ uint32_t BundleActiveGroupController::EventToGroupReason(const int eventId) } void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, const int64_t bootBasedTimeStamp, - const int userId) + const int32_t userId) { BUNDLE_ACTIVE_LOGI("ReportEvent called"); if (bundleGroupEnable_ == false) { @@ -225,7 +225,7 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co if (IsBundleInstalled(event.bundleName_, userId) == false) { return; } - int eventId = event.eventId_; + int32_t eventId = event.eventId_; if (eventId == BundleActiveEvent::ABILITY_FOREGROUND || eventId == BundleActiveEvent::ABILITY_BACKGROUND || eventId == BundleActiveEvent::SYSTEM_INTERACTIVE || @@ -269,7 +269,7 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co } } -void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleName, const int userId, +void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp) { std::lock_guard lock(mutex_); @@ -282,8 +282,8 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN if (oldGroupControlReason == GROUP_CONTROL_REASON_FORCED) { return; } - int oldGroup = oneBundleHistory->currentGroup_; - int newGroup = std::max(oldGroup, ACTIVE_GROUP_ALIVE); + int32_t oldGroup = oneBundleHistory->currentGroup_; + int32_t newGroup = std::max(oldGroup, ACTIVE_GROUP_ALIVE); if (oldGroupControlReason == GROUP_CONTROL_REASON_DEFAULT || oldGroupControlReason == GROUP_CONTROL_REASON_USAGE || oldGroupControlReason == GROUP_CONTROL_REASON_TIMEOUT) { @@ -313,7 +313,7 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN } } -void BundleActiveGroupController::SetBundleGroup(const std::string& bundleName, const int userId, int newGroup, +void BundleActiveGroupController::SetBundleGroup(const std::string& bundleName, const int32_t userId, int32_t newGroup, uint32_t reason, const int64_t bootBasedTimeStamp, const bool& resetTimeout) { std::lock_guard lock(mutex_); @@ -327,10 +327,9 @@ void BundleActiveGroupController::SetBundleGroup(const std::string& bundleName, int64_t bootBasedTimeStampAdjusted = bundleUserHistory_->GetBootBasedTimeStamp(bootBasedTimeStamp); if (newGroup > ACTIVE_GROUP_ALIVE && oneBundleHistory->bundleAliveTimeoutTimeStamp_ > bootBasedTimeStampAdjusted) { - BUNDLE_ACTIVE_LOGI("%{public}s should be decreased, but time out in alive is not expire! now is %{public}lld," - "timeout is %{public}lld", - bundleName.c_str(), - (long long)bootBasedTimeStampAdjusted, (long long)oneBundleHistory->bundleAliveTimeoutTimeStamp_); + BUNDLE_ACTIVE_LOGI("%{public}s should be decreased, but time out in alive is not expire! now is " + "%{public}" PRId64 ", timeout is %{public}" PRId64 "", + bundleName.c_str(), bootBasedTimeStampAdjusted, oneBundleHistory->bundleAliveTimeoutTimeStamp_); newGroup = ACTIVE_GROUP_ALIVE; reason = oneBundleHistory->reasonInGroup_; } else if (newGroup > ACTIVE_GROUP_DAILY && oneBundleHistory->bundleDailyTimeoutTimeStamp_ > @@ -345,7 +344,7 @@ void BundleActiveGroupController::SetBundleGroup(const std::string& bundleName, bundleUserHistory_->SetBundleGroup(bundleName, userId, bootBasedTimeStamp, newGroup, reason, false); } -int BundleActiveGroupController::IsBundleIdle(const std::string& bundleName, const int userId) +int32_t BundleActiveGroupController::IsBundleIdle(const std::string& bundleName, const int32_t userId) { sptr timer = MiscServices::TimeServiceClient::GetInstance(); if (IsBundleInstalled(bundleName, userId) == false) { @@ -357,17 +356,15 @@ int BundleActiveGroupController::IsBundleIdle(const std::string& bundleName, con if (oneBundleHistory == nullptr) { return 1; } else if (oneBundleHistory->currentGroup_ >= ACTIVE_GROUP_RARE) { - BUNDLE_ACTIVE_LOGI("IsBundleIdle, bundle group is %{public}d", - oneBundleHistory->currentGroup_); + BUNDLE_ACTIVE_LOGI("IsBundleIdle, bundle group is %{public}d", oneBundleHistory->currentGroup_); return 1; } else { - BUNDLE_ACTIVE_LOGI("IsBundleIdle, bundle group is %{public}d", - oneBundleHistory->currentGroup_); + BUNDLE_ACTIVE_LOGI("IsBundleIdle, bundle group is %{public}d", oneBundleHistory->currentGroup_); return 0; } } -int BundleActiveGroupController::QueryPackageGroup(const int userId, const std::string& bundleName) +int32_t BundleActiveGroupController::QueryPackageGroup(const int32_t userId, const std::string& bundleName) { BUNDLE_ACTIVE_LOGI("QueryPackageGroup called"); sptr timer = MiscServices::TimeServiceClient::GetInstance(); @@ -384,7 +381,7 @@ int BundleActiveGroupController::QueryPackageGroup(const int userId, const std:: } } -bool BundleActiveGroupController::IsBundleInstalled(const std::string& bundleName, const int userId) +bool BundleActiveGroupController::IsBundleInstalled(const std::string& bundleName, const int32_t userId) { ApplicationInfo bundleInfo; if (sptrBundleMgr_ != nullptr && sptrBundleMgr_->GetApplicationInfo( @@ -395,7 +392,7 @@ bool BundleActiveGroupController::IsBundleInstalled(const std::string& bundleNam return true; } -void BundleActiveGroupController::ShutDown(const int64_t bootBasedTimeStamp, const int userId) +void BundleActiveGroupController::ShutDown(const int64_t bootBasedTimeStamp, const int32_t userId) { BUNDLE_ACTIVE_LOGI("ShutDown called"); CheckEachBundleState(userId); diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index 5f2d8c7..6c6ec42 100644 --- a/services/packagegroup/src/bundle_active_group_handler.cpp +++ b/services/packagegroup/src/bundle_active_group_handler.cpp @@ -69,7 +69,7 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe break; } case MSG_ONE_TIME_CHECK_BUNDLE_STATE: { - std::vector activatedOsAccountIds; + std::vector activatedOsAccountIds; #ifdef OS_ACCOUNT_PART_ENABLED if (AccountSA::OsAccountManager::QueryActiveOsAccountIds(activatedOsAccountIds) != ERR_OK) { BUNDLE_ACTIVE_LOGI("query activated account failed"); diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index ae50439..76ce3b9 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -40,7 +40,7 @@ void BundleActiveUserHistory::WriteDeviceDuration() database_.PutDurationData(bootBasedDuration_, ScreenOnDuration_); } -void BundleActiveUserHistory::WriteBundleUsage(const int userId) +void BundleActiveUserHistory::WriteBundleUsage(const int32_t userId) { BUNDLE_ACTIVE_LOGI("WriteBundleUsage called"); auto userHistory = GetUserHistory(userId, false); @@ -51,7 +51,7 @@ void BundleActiveUserHistory::WriteBundleUsage(const int userId) database_.PutBundleHistoryData(userId, userHistory); } -void BundleActiveUserHistory::OnBundleUninstalled(const int userId, const std::string bundleName) +void BundleActiveUserHistory::OnBundleUninstalled(const int32_t userId, const std::string bundleName) { database_.OnPackageUninstalled(userId, bundleName); } @@ -67,7 +67,7 @@ BundleActiveUserHistory::BundleActiveUserHistory(const int64_t bootBasedTimeStam isScreenOn_ = false; } -int BundleActiveUserHistory::GetLevelIndex(const string& bundleName, const int userId, +int32_t BundleActiveUserHistory::GetLevelIndex(const string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const std::vector screenTimeLevel, const std::vector bootFromTimeLevel) { @@ -81,10 +81,9 @@ int BundleActiveUserHistory::GetLevelIndex(const string& bundleName, const int u } int64_t screenDiff = GetScreenOnTimeStamp(bootBasedTimeStamp) - oneBundleHistory->lastScreenUsedTimeStamp_; int64_t bootFromDiff = GetBootBasedTimeStamp(bootBasedTimeStamp) - oneBundleHistory->lastBootFromUsedTimeStamp_; - BUNDLE_ACTIVE_LOGI("screendiff is %{public}lld, bootfromdiff is %{public}lld, bundle name is %{public}s," - "userid is %{public}d", - (long long)screenDiff, (long long)bootFromDiff, bundleName.c_str(), userId); - for (int i = 3; i >= 0; i--) { + BUNDLE_ACTIVE_LOGI("screendiff is %{public}" PRId64 ", bootfromdiff is %{public}" PRId64 ", " + "bundle name is %{public}s, userid is %{public}d", screenDiff, bootFromDiff, bundleName.c_str(), userId); + for (int32_t i = 3; i >= 0; i--) { if (screenDiff >= screenTimeLevel[i] && bootFromDiff >= bootFromTimeLevel[i]) { return i; } @@ -107,7 +106,7 @@ int64_t BundleActiveUserHistory::GetScreenOnTimeStamp(int64_t bootBasedTimeStamp } shared_ptr>> BundleActiveUserHistory::GetUserHistory( - const int userId, const bool& create) + const int32_t userId, const bool& create) { auto it = userHistory_.find(userId); if (it == userHistory_.end() && create) { @@ -147,7 +146,7 @@ shared_ptr BundleActiveUserHistory::GetUsageHistoryI } shared_ptr BundleActiveUserHistory::GetUsageHistoryForBundle( - const string& bundleName, const int userId, const int64_t bootBasedTimeStamp, const bool& create) + const string& bundleName, const int32_t userId, const int64_t bootBasedTimeStamp, const bool& create) { auto oneUserHistory = GetUserHistory(userId, create); if (oneUserHistory == nullptr) { @@ -161,7 +160,7 @@ shared_ptr BundleActiveUserHistory::GetUsageHistoryF } void BundleActiveUserHistory::ReportUsage(shared_ptr oneBundleUsageHistory, - const string& bundleName, const int newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, + const string& bundleName, const int32_t newGroup, const uint32_t groupReason, const int64_t bootBasedTimeStamp, const int64_t timeUntilNextCheck) { if (timeUntilNextCheck > bootBasedTimeStamp) { @@ -188,18 +187,17 @@ void BundleActiveUserHistory::ReportUsage(shared_ptr oneBundleUsageHistory->isChanged_ = true; } -void BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const int userId, - const int64_t bootBasedTimeStamp, int newGroup, uint32_t groupReason, const bool& resetTimeout) +void BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const int32_t userId, + const int64_t bootBasedTimeStamp, int32_t newGroup, uint32_t groupReason, const bool& resetTimeout) { BUNDLE_ACTIVE_LOGI("set %{public}s to group %{public}d, reason is %{public}d, userId is %{public}d", bundleName.c_str(), newGroup, groupReason, userId); - shared_ptr>> userBundleHistory = - GetUserHistory(userId, false); + shared_ptr>> userBundleHistory = GetUserHistory(userId, false); if (userBundleHistory == nullptr) { return; } - shared_ptr oneBundleHistory = GetUsageHistoryInUserHistory( - userBundleHistory, bundleName, bootBasedTimeStamp, false); + shared_ptr oneBundleHistory = GetUsageHistoryInUserHistory(userBundleHistory, + bundleName, bootBasedTimeStamp, false); if (oneBundleHistory == nullptr) { return; } @@ -234,7 +232,7 @@ void BundleActiveUserHistory::UpdateBootBasedAndScreenTime(const bool& isScreenO database_.PutDurationData(bootBasedDuration_, ScreenOnDuration_); } -void BundleActiveUserHistory::PrintData(int userId) +void BundleActiveUserHistory::PrintData(int32_t userId) { auto oneUserHistory = GetUserHistory(userId, false); BUNDLE_ACTIVE_LOGI("PrintData screen is %{public}d", isScreenOn_); @@ -242,14 +240,13 @@ void BundleActiveUserHistory::PrintData(int userId) return; } for (auto oneBundleUsage : (*oneUserHistory)) { - BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, lastBootFromUsedTimeStamp_ is %{public}lld, " - "lastScreenUsedTimeStamp_ is %{public}lld, currentGroup_ is %{public}d, reasonInGroup_ is %{public}d, " - "daily time out %{public}lld, alive time out %{public}lld", oneBundleUsage.first.c_str(), - (long long)oneBundleUsage.second->lastBootFromUsedTimeStamp_, - (long long)oneBundleUsage.second->lastScreenUsedTimeStamp_, - oneBundleUsage.second->currentGroup_, oneBundleUsage.second->reasonInGroup_, - (long long)oneBundleUsage.second->bundleDailyTimeoutTimeStamp_, - (long long)oneBundleUsage.second->bundleAliveTimeoutTimeStamp_); + BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, lastBootFromUsedTimeStamp_ is %{public}" PRId64 ", " + "lastScreenUsedTimeStamp_ is %{public}" PRId64 ", currentGroup_ is %{public}d, " + "reasonInGroup_ is %{public}d, daily time out %{public}" PRId64 ", alive time out %{public}" PRId64 "", + oneBundleUsage.first.c_str(), oneBundleUsage.second->lastBootFromUsedTimeStamp_, + oneBundleUsage.second->lastScreenUsedTimeStamp_, oneBundleUsage.second->currentGroup_, + oneBundleUsage.second->reasonInGroup_, oneBundleUsage.second->bundleDailyTimeoutTimeStamp_, + oneBundleUsage.second->bundleAliveTimeoutTimeStamp_); } } } // namespace DeviceUsageStats diff --git a/services/packageusage/include/bundle_active_calendar.h b/services/packageusage/include/bundle_active_calendar.h index 4bde454..41230b1 100644 --- a/services/packageusage/include/bundle_active_calendar.h +++ b/services/packageusage/include/bundle_active_calendar.h @@ -43,13 +43,13 @@ public: void TruncateToWeek(); void TruncateToMonth(); void TruncateToYear(); - void IncreaseDays(const int val); - void IncreaseWeeks(const int val); - void IncreaseMonths(const int val); - void IncreaseYears(const int val); + void IncreaseDays(const int64_t val); + void IncreaseWeeks(const int64_t val); + void IncreaseMonths(const int64_t val); + void IncreaseYears(const int64_t val); void SetMilliseconds(const int64_t timeStamp); int64_t GetMilliseconds(); - void TruncateTo(int intervalType); + void TruncateTo(int32_t intervalType); private: int64_t time_; diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index 74a98ed..1af7351 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -16,6 +16,8 @@ #ifndef BUNDLE_ACTIVE_EVENT_H #define BUNDLE_ACTIVE_EVENT_H +#include + #include "ibundle_active_service.h" namespace OHOS { @@ -23,26 +25,26 @@ namespace DeviceUsageStats { class BundleActiveEvent : public Parcelable { public: // external events - static const int ABILITY_FOREGROUND = 2; // onForeground() called, ability is in front. - static const int ABILITY_BACKGROUND = 3; // onBackground() called, ability is in background. - static const int ABILITY_STOP = 4; // onStop() called, ability is destroyed. - static const int LONG_TIME_TASK_STARTTED = 5; - static const int LONG_TIME_TASK_ENDED = 6; - static const int SYSTEM_INTERACTIVE = 7; - static const int USER_INTERACTIVE = 8; + static const int32_t ABILITY_FOREGROUND = 2; // onForeground() called, ability is in front. + static const int32_t ABILITY_BACKGROUND = 3; // onBackground() called, ability is in background. + static const int32_t ABILITY_STOP = 4; // onStop() called, ability is destroyed. + static const int32_t LONG_TIME_TASK_STARTTED = 5; + static const int32_t LONG_TIME_TASK_ENDED = 6; + static const int32_t SYSTEM_INTERACTIVE = 7; + static const int32_t 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; - static const int FLUSH = 12; - static const int SCREEN_INTERACTIVE = 13; - static const int SCREEN_NON_INTERACTIVE = 14; - 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; + static const int32_t DEFAULT_EVENT_ID = 0; + static const int32_t END_OF_THE_DAY = 9; + static const int32_t SHUTDOWN = 10; + static const int32_t STARTUP = 11; + static const int32_t FLUSH = 12; + static const int32_t SCREEN_INTERACTIVE = 13; + static const int32_t SCREEN_NON_INTERACTIVE = 14; + static const int32_t KEYGUARD_SHOWN = 15; + static const int32_t KEYGUARD_HIDDEN = 16; + static const int32_t NOTIFICATION_SEEN = 17; + static const int32_t FORM_IS_CLICKED = 18; + static const int32_t FORM_IS_REMOVED = 19; inline static const std::string DEVICE_EVENT_PACKAGE_NAME = "openharmony"; std::string bundleName_; std::string continuousTaskAbilityName_; @@ -53,7 +55,7 @@ public: int32_t formDimension_; int64_t formId_; int64_t timeStamp_; - int eventId_; + int32_t eventId_; public: /* @@ -69,7 +71,7 @@ public: * function: BundleActiveEvent, constructor using event Id, time stamp. * parameters: eventId, timeStamp */ - BundleActiveEvent(int eventId, int64_t timeStamp); + BundleActiveEvent(int32_t eventId, int64_t timeStamp); /* * function: BundleActiveEvent, constructor of continuous task event. * parameters: bundleName, continuousTaskAbilityName @@ -86,7 +88,7 @@ public: * parameters: bundleName, moduleName, formName, formDimension, formId, eventId */ BundleActiveEvent(const std::string bundleName, const std::string moduleName, - const std::string formName, const int32_t formDimension, const int64_t formId, const int eventId); + const std::string formName, const int32_t formDimension, const int64_t formId, const int32_t eventId); void PrintEvent(const bool debug) const; /* * function: operator=, override operator =. diff --git a/services/packageusage/include/bundle_active_event_list.h b/services/packageusage/include/bundle_active_event_list.h index 6c45a57..978529a 100644 --- a/services/packageusage/include/bundle_active_event_list.h +++ b/services/packageusage/include/bundle_active_event_list.h @@ -35,7 +35,7 @@ public: * function: Size, get size of member events_. * return: size of member events_ */ - int Size(); + int32_t Size(); /* * function: Clear, clear all event in member events_. */ @@ -50,7 +50,7 @@ public: * parameters: timeStamp * return: the index of inserting. */ - int FindBestIndex(const int64_t timeStamp); + int32_t FindBestIndex(const int64_t timeStamp); /* * function: Merge, merge two BundleActiveEventList. * parameters: right diff --git a/services/packageusage/include/bundle_active_event_stats.h b/services/packageusage/include/bundle_active_event_stats.h index 13bc807..34ee080 100644 --- a/services/packageusage/include/bundle_active_event_stats.h +++ b/services/packageusage/include/bundle_active_event_stats.h @@ -22,12 +22,12 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActiveEventStats { public: - int eventId_; + int32_t eventId_; int64_t beginTimeStamp_; int64_t endTimeStamp_; int64_t lastEventTime_; int64_t totalTime_; - int count_; + int32_t count_; /* * function: BundleActiveEventStats, default constructor. */ @@ -41,32 +41,32 @@ public: * function: GetEventId, get eventId. * return: member eventId_. */ - int GetEventId(); + int32_t GetEventId(); /* * function: GetFirstTimeStamp, get first time stamp. * return: member beginTimeStamp_. */ - int GetFirstTimeStamp(); + int64_t GetFirstTimeStamp(); /* * function: GetLastTimeStamp, get last time stamp. * return: member endTimeStamp_. */ - int GetLastTimeStamp(); + int64_t GetLastTimeStamp(); /* * function: GetLastEventTime, get last event time. * return: member lastEventTime_. */ - int GetLastEventTime(); + int64_t GetLastEventTime(); /* * function: GetTotalTime, get total time. * return: member totalTime_. */ - int GetTotalTime(); + int64_t GetTotalTime(); /* * function: GetCount, get count. * return: member count_. */ - int GetCount(); + int32_t GetCount(); /* * function: add, add statistics from another BundleActvieEventStats object. * parameters: right diff --git a/services/packageusage/include/bundle_active_event_tracker.h b/services/packageusage/include/bundle_active_event_tracker.h index 7e8757b..624006b 100644 --- a/services/packageusage/include/bundle_active_event_tracker.h +++ b/services/packageusage/include/bundle_active_event_tracker.h @@ -26,10 +26,10 @@ public: int64_t curStartTime_; int64_t lastEventTime_; int64_t duration_; - int64_t count_; + int32_t count_; void CommitTime(const int64_t timeStamp); void Update(int64_t timeStamp); - void AddToEventStats(std::vector& eventStatsList, int eventId, int64_t beginTime, + void AddToEventStats(std::vector& eventStatsList, int32_t eventId, int64_t beginTime, int64_t endTime); BundleActiveEventTracker(); }; diff --git a/services/packageusage/include/bundle_active_package_stats.h b/services/packageusage/include/bundle_active_package_stats.h index 71ac47d..846948f 100644 --- a/services/packageusage/include/bundle_active_package_stats.h +++ b/services/packageusage/include/bundle_active_package_stats.h @@ -30,13 +30,13 @@ public: int64_t totalInFrontTime_; // the total time of using the bundle int64_t lastContiniousTaskUsed_; int64_t totalContiniousTaskUsedTime_; - int startCount_; - int bundleStartedCount_; - int lastEvent_; + int32_t startCount_; + int32_t bundleStartedCount_; + int32_t lastEvent_; // key is abilityId, value is the last event of this ability. Restore all abilities' last event of bundle. - std::map abilities_; + std::map abilities_; // key is name of continuous task, value is last event of this last continuous task. - std::map longTimeTasks_; + std::map longTimeTasks_; /* * function: BundleActivePackageStats, default constructor. */ @@ -54,7 +54,7 @@ public: * function: Update, update one bundle statistics. * parameters: longTimeTaskName timeStamp eventId abilityId */ - void Update(const std::string& longTimeTaskName, const int64_t timeStamp, const int eventId, + void Update(const std::string& longTimeTaskName, const int64_t timeStamp, const int32_t eventId, const std::string& abilityId); /* * function: IncrementTimeUsed, increase bundle's use time. @@ -86,8 +86,8 @@ public: 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); + void UpdateAbility(const int64_t timeStamp, const int32_t eventId, const std::string& abilityId); + void UpdateLongTimeTask(const std::string& longTimeTaskName, const int64_t timeStamp, const int32_t 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 2cd7951..e2efc70 100644 --- a/services/packageusage/include/bundle_active_period_stats.h +++ b/services/packageusage/include/bundle_active_period_stats.h @@ -29,16 +29,16 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActivePeriodStats { public: - static const int PERIOD_DAILY = 0; - static const int PERIOD_WEEKLY = 1; - static const int PERIOD_MONTHLY = 2; - static const int PERIOD_YEARLY = 3; - static const int PERIOD_BEST = 4; - static const int PERIOD_COUNT = 4; + static const int32_t PERIOD_DAILY = 0; + static const int32_t PERIOD_WEEKLY = 1; + static const int32_t PERIOD_MONTHLY = 2; + static const int32_t PERIOD_YEARLY = 3; + static const int32_t PERIOD_BEST = 4; + static const int32_t PERIOD_COUNT = 4; int64_t beginTime_; int64_t endTime_; int64_t lastTimeSaved_; - int userId_; + int32_t userId_; std::map> bundleStats_; BundleActiveEventList events_; std::set packetNamesCache_; @@ -61,7 +61,7 @@ public: * 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); + const int32_t eventId, const std::string abilityId); /* * function: AddEvent, add a event to member events_. * parameters: event diff --git a/services/packageusage/include/bundle_active_report_handler.h b/services/packageusage/include/bundle_active_report_handler.h index dd44984..4e0802c 100644 --- a/services/packageusage/include/bundle_active_report_handler.h +++ b/services/packageusage/include/bundle_active_report_handler.h @@ -35,11 +35,11 @@ public: */ void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; void Init(const std::shared_ptr& bundleActiveCore); - static const int MSG_REPORT_EVENT = 0; - static const int MSG_FLUSH_TO_DISK = 1; - static const int MSG_REMOVE_USER = 2; - static const int MSG_BUNDLE_UNINSTALLED = 3; - static const int MSG_SWITCH_USER = 4; + static const int32_t MSG_REPORT_EVENT = 0; + static const int32_t MSG_FLUSH_TO_DISK = 1; + static const int32_t MSG_REMOVE_USER = 2; + static const int32_t MSG_BUNDLE_UNINSTALLED = 3; + static const int32_t MSG_SWITCH_USER = 4; private: std::shared_ptr bundleActiveCore_; diff --git a/services/packageusage/include/bundle_active_stats_update_listener.h b/services/packageusage/include/bundle_active_stats_update_listener.h index b5de8d2..127b60f 100644 --- a/services/packageusage/include/bundle_active_stats_update_listener.h +++ b/services/packageusage/include/bundle_active_stats_update_listener.h @@ -19,9 +19,9 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActiveStatsUpdateListener { - virtual void OnStatsChanged(const int userId) = 0; + virtual void OnStatsChanged(const int32_t userId) = 0; virtual void OnStatsReload() = 0; - virtual void OnSystemUpdate(int userId) = 0; + virtual void OnSystemUpdate(int32_t userId) = 0; }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h index 99cf5db..cb56fc9 100644 --- a/services/packageusage/include/bundle_active_user_service.h +++ b/services/packageusage/include/bundle_active_user_service.h @@ -35,9 +35,9 @@ class BundleActiveCore; class BundleActiveUserService { public: BundleActiveUserService() = delete; - BundleActiveUserService(const int userId, BundleActiveCore& listener, const bool debug):listener_(listener) + BundleActiveUserService(const int32_t userId, BundleActiveCore& listener, const bool debug):listener_(listener) { - for (int i = 0; i < BundleActivePeriodStats::PERIOD_COUNT; i++) { + for (int32_t i = 0; i < BundleActivePeriodStats::PERIOD_COUNT; i++) { currentStats_.push_back(nullptr); } userId_ = userId; @@ -64,13 +64,13 @@ public: void RenewTableTime(int64_t oldTime, int64_t newTime); void OnUserRemoved(); void DeleteUninstalledBundleStats(const std::string& bundleName); - int userId_; + int32_t userId_; BundleActiveCalendar dailyExpiryDate_; - std::vector QueryPackageStats(int intervalType, const int64_t beginTime, - 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, + std::vector QueryPackageStats(int32_t intervalType, const int64_t beginTime, + const int64_t endTime, const int32_t userId, const std::string& bundleName); + std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, const int32_t userId, const std::string& bundleName); - int QueryFormStatistics(int32_t maxNum, std::vector& results); + int32_t QueryFormStatistics(int32_t maxNum, std::vector& results); void LoadActiveStats(const int64_t timeStamp, const bool& force, const bool& timeChanged); void LoadModuleAndFormStats(); @@ -87,7 +87,7 @@ private: void NotifyStatsChanged(); void NotifyNewUpdate(); std::shared_ptr GetOrCreateModuleRecord(const BundleActiveEvent& event); - void PrintInMemPackageStats(const int idx, const bool debug); + void PrintInMemPackageStats(const int32_t idx, const bool debug); void PrintInMemEventStats(const bool debug); void PrintInMemFormStats(const bool debug, const bool printform); }; diff --git a/services/packageusage/src/bundle_active_calendar.cpp b/services/packageusage/src/bundle_active_calendar.cpp index 270742a..709284b 100644 --- a/services/packageusage/src/bundle_active_calendar.cpp +++ b/services/packageusage/src/bundle_active_calendar.cpp @@ -47,22 +47,22 @@ void BundleActiveCalendar::TruncateToYear() time_ -= time_ % yearMilliseconds_; } -void BundleActiveCalendar::IncreaseDays(const int val) +void BundleActiveCalendar::IncreaseDays(const int64_t val) { time_ += val * dayMilliseconds_; } -void BundleActiveCalendar::IncreaseWeeks(const int val) +void BundleActiveCalendar::IncreaseWeeks(const int64_t val) { time_ += val* weekMilliseconds_; } -void BundleActiveCalendar::IncreaseMonths(const int val) +void BundleActiveCalendar::IncreaseMonths(const int64_t val) { time_ += val * monthMilliseconds_; } -void BundleActiveCalendar::IncreaseYears(const int val) +void BundleActiveCalendar::IncreaseYears(const int64_t val) { time_ += val * yearMilliseconds_; } @@ -85,7 +85,7 @@ void BundleActiveCalendar::ChangeToDebug() yearMilliseconds_ = ONE_YEAR_TIME_DEBUG; } -void BundleActiveCalendar::TruncateTo(int intervalType) +void BundleActiveCalendar::TruncateTo(int32_t intervalType) { switch (intervalType) { case BundleActivePeriodStats::PERIOD_DAILY: diff --git a/services/packageusage/src/bundle_active_event.cpp b/services/packageusage/src/bundle_active_event.cpp index 41130aa..59e90a2 100644 --- a/services/packageusage/src/bundle_active_event.cpp +++ b/services/packageusage/src/bundle_active_event.cpp @@ -45,7 +45,7 @@ BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) eventId_ = orig.eventId_; } -BundleActiveEvent::BundleActiveEvent(int eventId, int64_t timeStamp) +BundleActiveEvent::BundleActiveEvent(int32_t eventId, int64_t timeStamp) { bundleName_.clear(); continuousTaskAbilityName_.clear(); @@ -90,7 +90,7 @@ BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::st BundleActiveEvent::BundleActiveEvent(const std::string bundleName, const std::string moduleName, const std::string formName, const int32_t formDimension, - const int64_t formId, const int eventId) + const int64_t formId, const int32_t eventId) { bundleName_ = bundleName; continuousTaskAbilityName_.clear(); @@ -126,9 +126,9 @@ void BundleActiveEvent::PrintEvent(const bool debug) const } BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, ability name is %{public}s, continue task ability is %{public}s, " "module name is %{public}s, " - "form name is %{public}s, form dimension is %{public}d, form id is %{public}lld, event id is %{public}d", + "form name is %{public}s, form dimension is %{public}d, form id is %{public}" PRId64 ", event id is %{public}d", bundleName_.c_str(), abilityName_.c_str(), continuousTaskAbilityName_.c_str(), moduleName_.c_str(), - formName_.c_str(), formDimension_, (long long)formId_, eventId_); + formName_.c_str(), formDimension_, formId_, eventId_); } bool BundleActiveEvent::Marshalling(Parcel &parcel) const diff --git a/services/packageusage/src/bundle_active_event_list.cpp b/services/packageusage/src/bundle_active_event_list.cpp index 66d47e3..0d496b5 100644 --- a/services/packageusage/src/bundle_active_event_list.cpp +++ b/services/packageusage/src/bundle_active_event_list.cpp @@ -21,7 +21,7 @@ BundleActiveEventList::BundleActiveEventList() { } -int BundleActiveEventList::Size() +int32_t BundleActiveEventList::Size() { return events_.size(); } @@ -38,18 +38,18 @@ void BundleActiveEventList::Insert(BundleActiveEvent event) events_.push_back(event); return; } - int insertIdx = FindBestIndex(event.timeStamp_); + int32_t insertIdx = FindBestIndex(event.timeStamp_); events_.insert(events_.begin() + insertIdx, event); } -int BundleActiveEventList::FindBestIndex(const int64_t timeStamp) +int32_t BundleActiveEventList::FindBestIndex(const int64_t timeStamp) { - int size = static_cast(events_.size()); - int result = size; - int lo = 0; - int hi = size - 1; + int32_t size = static_cast(events_.size()); + int32_t result = size; + int32_t lo = 0; + int32_t hi = size - 1; while (lo <= hi) { - int mid = (hi - lo) / 2 + lo; + int32_t mid = (hi - lo) / 2 + lo; int64_t midTimeStamp = events_[mid].timeStamp_; if (midTimeStamp >= timeStamp) { hi = mid - 1; @@ -63,8 +63,8 @@ int BundleActiveEventList::FindBestIndex(const int64_t timeStamp) void BundleActiveEventList::Merge(const BundleActiveEventList& right) { - int size = static_cast(right.events_.size()); - for (int i = 0; i < size; i++) { + int32_t size = static_cast(right.events_.size()); + for (int32_t i = 0; i < size; i++) { Insert(right.events_[i]); } } diff --git a/services/packageusage/src/bundle_active_event_stats.cpp b/services/packageusage/src/bundle_active_event_stats.cpp index 988c09b..a433446 100644 --- a/services/packageusage/src/bundle_active_event_stats.cpp +++ b/services/packageusage/src/bundle_active_event_stats.cpp @@ -37,32 +37,32 @@ BundleActiveEventStats::BundleActiveEventStats(const BundleActiveEventStats& ori count_ = orig.count_; } -int BundleActiveEventStats::GetEventId() +int32_t BundleActiveEventStats::GetEventId() { return eventId_; } -int BundleActiveEventStats::GetFirstTimeStamp() +int64_t BundleActiveEventStats::GetFirstTimeStamp() { return beginTimeStamp_; } -int BundleActiveEventStats::GetLastTimeStamp() +int64_t BundleActiveEventStats::GetLastTimeStamp() { return endTimeStamp_; } -int BundleActiveEventStats::GetLastEventTime() +int64_t BundleActiveEventStats::GetLastEventTime() { return lastEventTime_; } -int BundleActiveEventStats::GetTotalTime() +int64_t BundleActiveEventStats::GetTotalTime() { return totalTime_; } -int BundleActiveEventStats::GetCount() +int32_t BundleActiveEventStats::GetCount() { return count_; } diff --git a/services/packageusage/src/bundle_active_event_tracker.cpp b/services/packageusage/src/bundle_active_event_tracker.cpp index a1165bd..a4ec038 100644 --- a/services/packageusage/src/bundle_active_event_tracker.cpp +++ b/services/packageusage/src/bundle_active_event_tracker.cpp @@ -43,7 +43,7 @@ void BundleActiveEventTracker::Update(int64_t timeStamp) lastEventTime_ = timeStamp; } -void BundleActiveEventTracker::AddToEventStats(std::vector& eventStatsList, int eventId, +void BundleActiveEventTracker::AddToEventStats(std::vector& eventStatsList, int32_t eventId, int64_t beginTime, int64_t endTime) { if (count_ || duration_) { diff --git a/services/packageusage/src/bundle_active_package_stats.cpp b/services/packageusage/src/bundle_active_package_stats.cpp index 6865d9f..1728bbd 100644 --- a/services/packageusage/src/bundle_active_package_stats.cpp +++ b/services/packageusage/src/bundle_active_package_stats.cpp @@ -83,7 +83,7 @@ void BundleActivePackageStats::IncrementBundleLaunchedCount() bundleStartedCount_ += 1; } -void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int eventId, +void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int32_t eventId, const std::string& abilityId) { if (eventId != BundleActiveEvent::ABILITY_FOREGROUND && eventId != BundleActiveEvent::ABILITY_BACKGROUND && @@ -95,7 +95,7 @@ void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int } std::map::iterator it = abilities_.find(abilityId); if (it != abilities_.end()) { - int lastEventId = it->second; + int32_t lastEventId = it->second; // When we receive a new event, first update the time stats according to the last event in map. switch (lastEventId) { case BundleActiveEvent::ABILITY_FOREGROUND: @@ -124,7 +124,7 @@ void BundleActivePackageStats::UpdateAbility(const int64_t timeStamp, const int } void BundleActivePackageStats::UpdateLongTimeTask(const std::string& longTimeTaskName, const int64_t timeStamp, - const int eventId) + const int32_t eventId) { if (eventId != BundleActiveEvent::LONG_TIME_TASK_STARTTED && eventId != BundleActiveEvent::LONG_TIME_TASK_ENDED) { return; @@ -133,7 +133,7 @@ void BundleActivePackageStats::UpdateLongTimeTask(const std::string& longTimeTas // When we receive a new event, first update the time stats according to the last service event in map. std::map::iterator it = longTimeTasks_.find(longTimeTaskName); if (it != longTimeTasks_.end()) { - int lastEventId = it->second; + int32_t lastEventId = it->second; switch (lastEventId) { case BundleActiveEvent::LONG_TIME_TASK_STARTTED: IncrementServiceTimeUsed(timeStamp); @@ -157,7 +157,7 @@ void BundleActivePackageStats::UpdateLongTimeTask(const std::string& longTimeTas } void BundleActivePackageStats::Update(const std::string& longTimeTaskName, const int64_t timeStamp, - const int eventId, const std::string& abilityId) + const int32_t eventId, const std::string& abilityId) { switch (eventId) { case BundleActiveEvent::ABILITY_FOREGROUND: diff --git a/services/packageusage/src/bundle_active_period_stats.cpp b/services/packageusage/src/bundle_active_period_stats.cpp index d1d09e9..d223d62 100644 --- a/services/packageusage/src/bundle_active_period_stats.cpp +++ b/services/packageusage/src/bundle_active_period_stats.cpp @@ -43,7 +43,7 @@ std::shared_ptr BundleActivePeriodStats::GetOrCreateUs } void BundleActivePeriodStats::Update(const std::string bundleName, const std::string longTimeTaskName, - const int64_t timeStamp, const int eventId, const std::string abilityId) + const int64_t timeStamp, const int32_t eventId, const std::string abilityId) { if (eventId == BundleActiveEvent::SHUTDOWN || eventId == BundleActiveEvent::FLUSH) { for (std::map>::iterator it = bundleStats_.begin(); diff --git a/services/packageusage/src/bundle_active_stats_combiner.cpp b/services/packageusage/src/bundle_active_stats_combiner.cpp index e704baf..bc1dd9c 100644 --- a/services/packageusage/src/bundle_active_stats_combiner.cpp +++ b/services/packageusage/src/bundle_active_stats_combiner.cpp @@ -30,13 +30,12 @@ void BundleActiveStatsCombiner::combine( } void BundleActiveStatsCombiner::combine(const std::shared_ptr& stats, - std::vector& accumulatedResult, - int64_t beginTime) + std::vector& accumulatedResult, int64_t beginTime) { BUNDLE_ACTIVE_LOGI("BundleActiveEvent combine called"); - int startIndex = stats->events_.FindBestIndex(beginTime); - int size = static_cast(stats->events_.events_.size()); - for (int i = startIndex; i < size; i++) { + int32_t startIndex = stats->events_.FindBestIndex(beginTime); + int32_t size = static_cast(stats->events_.events_.size()); + for (int32_t i = startIndex; i < size; i++) { accumulatedResult.push_back(stats->events_.events_[i]); } } diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 0f2bfd6..e4b5a90 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -33,12 +33,11 @@ void BundleActiveUserService::Init(const int64_t timeStamp) startupEvent.bundleName_ = BundleActiveEvent::DEVICE_EVENT_PACKAGE_NAME; currentDailyStats->AddEvent(startupEvent); for (auto it : currentDailyStats->events_.events_) { - BUNDLE_ACTIVE_LOGI("Init event id is %{public}d, time stamp is %{public}lld", - it.eventId_, (long long)it.timeStamp_); + BUNDLE_ACTIVE_LOGI("Init event id is %{public}d, time stamp is %{public}" PRId64 "", + it.eventId_, it.timeStamp_); } - BUNDLE_ACTIVE_LOGI("Init currentDailyStats begintime is %{public}lld, " - "expire time is %{public}lld", (long long)currentDailyStats->beginTime_, - (long long)dailyExpiryDate_.GetMilliseconds()); + BUNDLE_ACTIVE_LOGI("Init currentDailyStats begintime is %{public}" PRId64 ", " + "expire time is %{public}" PRId64 "", currentDailyStats->beginTime_, dailyExpiryDate_.GetMilliseconds()); } } @@ -75,8 +74,7 @@ void BundleActiveUserService::DeleteUninstalledBundleStats(const std::string& bu void BundleActiveUserService::RenewTableTime(int64_t oldTime, int64_t newTime) { BUNDLE_ACTIVE_LOGI("RenewTableTime called"); - BUNDLE_ACTIVE_LOGI("RenewTableTime called current event size is %{public}d", - currentStats_[0]->events_.Size()); + BUNDLE_ACTIVE_LOGI("RenewTableTime called current event size is %{public}d", currentStats_[0]->events_.Size()); database_.RenewTableTime(newTime - oldTime); } @@ -97,8 +95,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,", - (long long)currentStats_[0]->beginTime_, (long long)dailyExpiryDate_.GetMilliseconds(), userId_); + BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}" PRId64 ", E time is %{public}" PRId64 ", " + "userId is %{public}d,", currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_); event.PrintEvent(debugUserService_); if (event.timeStamp_ >= dailyExpiryDate_.GetMilliseconds()) { BUNDLE_ACTIVE_LOGI("ReportEvent later than daily expire, renew data in memory"); @@ -199,7 +197,7 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo } for (uint32_t intervalType = 0; intervalType < periodLength_.size(); intervalType++) { tmpCalendar.SetMilliseconds(timeStamp); - tmpCalendar.TruncateTo(static_cast(intervalType)); + tmpCalendar.TruncateTo(static_cast(intervalType)); if (!force && currentStats_[intervalType] != nullptr && currentStats_[intervalType]->beginTime_ == tmpCalendar.GetMilliseconds()) { continue; @@ -210,10 +208,9 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo BUNDLE_ACTIVE_LOGI("LoadActiveStats inter type is %{public}d, " "bundle size is %{public}zu", intervalType, stats->bundleStats_.size()); // 如果当前时间在stats的统计时间范围内,则可以从数据库加载数据 - BUNDLE_ACTIVE_LOGI("interval type is %{public}d, database stat BEGIN time is %{public}lld, " - "timestamp is %{public}lld, expect end is %{public}lld", - intervalType, (long long)stats->beginTime_, (long long)timeStamp, - (long long)stats->beginTime_ + periodLength_[intervalType]); + BUNDLE_ACTIVE_LOGI("interval type is %{public}d, database stat BEGIN time is %{public}" PRId64 ", " + "timestamp is %{public}" PRId64 ", expect end is %{public}" PRId64 "", + intervalType, stats->beginTime_, timeStamp, stats->beginTime_ + periodLength_[intervalType]); if (timeStamp > stats->beginTime_ && timeStamp < stats->beginTime_ + periodLength_[intervalType]) { currentStats_[intervalType] = stats; } @@ -239,9 +236,9 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo dailyExpiryDate_.TruncateToDay(); } listener_.OnStatsReload(); - BUNDLE_ACTIVE_LOGI("LoadActiveStats current expire time is %{public}lld, " - "begin time is %{public}lld", (long long)dailyExpiryDate_.GetMilliseconds(), - (long long)tmpCalendar.GetMilliseconds()); + BUNDLE_ACTIVE_LOGI("LoadActiveStats current expire time is %{public}" PRId64 ", " + "begin time is %{public}" PRId64 "", dailyExpiryDate_.GetMilliseconds(), + tmpCalendar.GetMilliseconds()); } void BundleActiveUserService::LoadModuleAndFormStats() @@ -306,8 +303,8 @@ void BundleActiveUserService::RenewStatsInMemory(const int64_t timeStamp) RestoreStats(true); } -std::vector BundleActiveUserService::QueryPackageStats(int intervalType, - const int64_t beginTime, const int64_t endTime, const int userId, const std::string& bundleName) +std::vector BundleActiveUserService::QueryPackageStats(int32_t intervalType, + const int64_t beginTime, const int64_t endTime, const int32_t userId, const std::string& bundleName) { std::vector result; if (intervalType == BundleActivePeriodStats::PERIOD_BEST) { @@ -316,7 +313,7 @@ std::vector BundleActiveUserService::QueryPackageStats intervalType = BundleActivePeriodStats::PERIOD_DAILY; } } - if (intervalType < 0 || intervalType >= static_cast(currentStats_.size())) { + if (intervalType < 0 || intervalType >= static_cast(currentStats_.size())) { return result; } auto currentStats = currentStats_[intervalType]; @@ -336,7 +333,7 @@ std::vector BundleActiveUserService::QueryPackageStats } int64_t truncatedEndTime = std::min(currentStats->beginTime_, endTime); result = database_.QueryDatabaseUsageStats(intervalType, beginTime, truncatedEndTime, userId); - BUNDLE_ACTIVE_LOGI("Query package data in db result size is %{public}d", static_cast(result.size())); + BUNDLE_ACTIVE_LOGI("Query package data in db result size is %{public}zu", result.size()); PrintInMemPackageStats(intervalType, debugUserService_); // if we need a in-memory stats, combine current stats with result from database. if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) { @@ -360,7 +357,7 @@ std::vector BundleActiveUserService::QueryPackageStats } std::vector BundleActiveUserService::QueryEvents(const int64_t beginTime, const int64_t endTime, - const int userId, const std::string& bundleName) + const int32_t userId, const std::string& bundleName) { BUNDLE_ACTIVE_LOGI("QueryEvents called"); std::vector result; @@ -379,9 +376,9 @@ std::vector BundleActiveUserService::QueryEvents(const int64_ // if we need a in-memory stats, combine current stats with result from database. if (currentStats->endTime_ != 0 && endTime > currentStats->beginTime_) { BUNDLE_ACTIVE_LOGI("QueryEvents need in memory stats"); - int eventBeginIdx = currentStats->events_.FindBestIndex(beginTime); - int eventSize = currentStats->events_.Size(); - for (int i = eventBeginIdx; i < eventSize; i++) { + int32_t eventBeginIdx = currentStats->events_.FindBestIndex(beginTime); + int32_t eventSize = currentStats->events_.Size(); + for (int32_t i = eventBeginIdx; i < eventSize; i++) { if (currentStats->events_.events_[i].timeStamp_ <= endTime) { if (bundleName.empty() || currentStats->events_.events_[i].bundleName_ == bundleName) { result.push_back(currentStats->events_.events_[i]); @@ -392,7 +389,7 @@ std::vector BundleActiveUserService::QueryEvents(const int64_ return result; } -int BundleActiveUserService::QueryFormStatistics(int32_t maxNum, std::vector& results) +int32_t BundleActiveUserService::QueryFormStatistics(int32_t maxNum, std::vector& results) { BUNDLE_ACTIVE_LOGI("QueryFormStatistics called, MAX IS %{public}d", maxNum); for (auto oneModuleRecord = moduleRecords_.begin(); oneModuleRecord != moduleRecords_.end(); oneModuleRecord++) { @@ -411,7 +408,7 @@ int BundleActiveUserService::QueryFormStatistics(int32_t maxNum, std::vectortotalInFrontTime_; int64_t lastTimeContinuousTaskUsed = it.second->lastContiniousTaskUsed_; int64_t totalTimeContinuousTaskUsed = it.second->totalContiniousTaskUsedTime_; - BUNDLE_ACTIVE_LOGI("bundle stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld" - "total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld", - (long long)totalUsedTime, (long long)lastTimeUsed, - (long long)totalTimeContinuousTaskUsed, (long long)lastTimeContinuousTaskUsed); + BUNDLE_ACTIVE_LOGI("bundle stat is, totaltime is %{public}" PRId64 ", lastTimeUsed is %{public}" PRId64 "" + "total continuous task is %{public}" PRId64 ", lastTimeContinuousTaskUsed is %{public}" PRId64 "", + totalUsedTime, lastTimeUsed, totalTimeContinuousTaskUsed, lastTimeContinuousTaskUsed); } } @@ -436,17 +432,17 @@ void BundleActiveUserService::PrintInMemEventStats(const bool debug) return; } BUNDLE_ACTIVE_LOGI("PrintInMemEventStats called"); - int idx = 0; - int size = static_cast(currentStats_[idx]->events_.events_.size()); - for (int i = 0; i < size; i++) { + int32_t idx = 0; + int32_t size = static_cast(currentStats_[idx]->events_.events_.size()); + for (int32_t i = 0; i < size; i++) { std::string abilityId = currentStats_[idx]->events_.events_[i].abilityId_; std::string abilityname = currentStats_[idx]->events_.events_[i].abilityName_; std::string bundlename = currentStats_[idx]->events_.events_[i].bundleName_; - int eventid = currentStats_[idx]->events_.events_[i].eventId_; + int32_t eventid = currentStats_[idx]->events_.events_[i].eventId_; int64_t timestamp = currentStats_[idx]->events_.events_[i].timeStamp_; BUNDLE_ACTIVE_LOGI("In mem, event stat is, abilityid is %{public}s, abilityname is %{public}s, " - "bundlename is %{public}s, eventid is %{public}d, timestamp is %{public}lld", - abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, (long long)timestamp); + "bundlename is %{public}s, eventid is %{public}d, timestamp is %{public}" PRId64 "", + abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, timestamp); } } @@ -458,17 +454,16 @@ void BundleActiveUserService::PrintInMemFormStats(const bool debug, const bool p for (const auto& oneModule : moduleRecords_) { if (oneModule.second) { BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, module name is %{public}s, " - "lastusedtime is %{public}lld, launchcount is %{public}d", oneModule.second->bundleName_.c_str(), + "lastusedtime is %{public}" PRId64 ", launchcount is %{public}d", oneModule.second->bundleName_.c_str(), oneModule.second->moduleName_.c_str(), - (long long)oneModule.second->lastModuleUsedTime_, oneModule.second->launchedCount_); + oneModule.second->lastModuleUsedTime_, oneModule.second->launchedCount_); BUNDLE_ACTIVE_LOGI("combined info is %{public}s", oneModule.first.c_str()); if (printform) { 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_, (long long)oneForm.formId_, - (long long)oneForm.formLastUsedTime_, oneForm.count_); + "form id is %{public}" PRId64 ", " + "lasttouchtime is %{public}" PRId64 ", touchcount is %{public}d", oneForm.formName_.c_str(), + oneForm.formDimension_, oneForm.formId_, oneForm.formLastUsedTime_, oneForm.count_); } } } diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 46edec5..e057e4d 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -37,7 +37,7 @@ 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; +static int32_t DEFAULT_USERID = 0; static int64_t LARGE_NUM = 20000000000000; class DeviceUsageStatisticsTest : public testing::Test { @@ -156,7 +156,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_IsBundleIdle_001, */ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackageGroup_001, Function | MediumTest | Level0) { - int result = BundleActiveClient::GetInstance().QueryPackageGroup(); + int32_t result = BundleActiveClient::GetInstance().QueryPackageGroup(); EXPECT_EQ(result, -1); } @@ -168,12 +168,12 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackageGroup_ */ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryFormStatistics_001, Function | MediumTest | Level0) { - int maxNum = 1; + int32_t maxNum = 1; BundleActiveEvent eventA(DEFAULT_BUNDLENAME, DEFAULT_MODULENAME, DEFAULT_FORM_NAME, DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED); BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID); std::vector results; - int errCode = BundleActiveClient::GetInstance().QueryFormStatistics(maxNum, results, DEFAULT_USERID); + int32_t errCode = BundleActiveClient::GetInstance().QueryFormStatistics(maxNum, results, DEFAULT_USERID); EXPECT_EQ(errCode, 0); EXPECT_EQ(results.size(), 0); } -- Gitee From 322c606804e2f04cfd282cc23a0dafc361ce9a5c Mon Sep 17 00:00:00 2001 From: vampire_z Date: Fri, 22 Apr 2022 17:41:55 +0800 Subject: [PATCH 2/3] support for 64-bit Signed-off-by: vampire_z --- init/device_usage_statistics_service.cfg | 5 ++--- services/common/include/bundle_active_constant.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/init/device_usage_statistics_service.cfg b/init/device_usage_statistics_service.cfg index b4f759b..2154baa 100644 --- a/init/device_usage_statistics_service.cfg +++ b/init/device_usage_statistics_service.cfg @@ -2,7 +2,6 @@ "jobs" : [{ "name" : "post-fs-data", "cmds" : [ - "mkdir /data/service/el1/public/bundle_usage 0711 device_usage_stats device_usage_stats", "start device_usage_stats_service" ] } @@ -10,8 +9,8 @@ "services" : [{ "name" : "device_usage_stats_service", "path" : ["/system/bin/sa_main", "/system/profile/device_usage_stats_service.xml"], - "uid" : "device_usage_stats", - "gid" : ["device_usage_stats", "shell"] + "uid" : "system", + "gid" : ["system", "shell"] } ] } \ No newline at end of file diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index 82bf37e..e20b850 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -121,7 +121,7 @@ const std::string BUNDLE_ACTIVE_DB_BUNDLE_DAILY_TIMEOUT_TIME = "bundleDailyTimeo const std::string BUNDLE_ACTIVE_DB_BOOT_BASED_DURATION = "bootBasedDuration"; const std::string BUNDLE_ACTIVE_DB_SCREEN_ON_DURATION = "screenOnDuration"; const std::string REFRESH_DATABASE_RUNNER_NAME = "RefreshDatabase"; -const std::string BUNDLE_ACTIVE_DATABASE_DIR = "/data/service/el1/public/bundle_usage/"; +const std::string BUNDLE_ACTIVE_DATABASE_DIR = "/data/system_ce/bundle_usage/"; const std::string BUNDLE_ACTIVE_VERSION_FILE = "/version"; const std::string DATABASE_FILE_TABLE_NAME = "table"; const std::string SQLITE_MASTER_NAME = "name"; -- Gitee From 7e724e5fe131ea22840e099e9c2382ea17915ff3 Mon Sep 17 00:00:00 2001 From: vampire_z Date: Tue, 26 Apr 2022 17:23:29 +0800 Subject: [PATCH 3/3] surport for 64-bit Signed-off-by: vampire_z --- BUILD.gn | 35 +++++++++++- bundle.json | 3 +- frameworks/src/bundle_state_query.cpp | 45 ++++++++------- .../innerkits/include/bundle_active_client.h | 1 + .../innerkits/include/bundle_active_proxy.h | 2 - .../innerkits/src/bundle_active_client.cpp | 55 +++++++++++++++++++ .../innerkits/src/bundle_active_proxy.cpp | 33 +++++------ services/common/src/bundle_active_core.cpp | 20 +++---- .../src/bundle_active_usage_database.cpp | 12 ++-- .../src/bundle_active_group_controller.cpp | 9 +-- .../src/bundle_active_user_history.cpp | 20 ++++--- .../include/bundle_active_event.h | 7 ++- .../include/bundle_active_form_record.h | 5 ++ .../include/bundle_active_module_record.h | 1 + .../include/bundle_active_package_stats.h | 6 ++ .../packageusage/src/bundle_active_event.cpp | 10 +++- .../src/bundle_active_form_record.cpp | 9 +++ .../src/bundle_active_module_record.cpp | 8 +++ .../src/bundle_active_package_stats.cpp | 10 ++++ .../src/bundle_active_user_service.cpp | 54 +++++++++--------- .../unittest/device_usage_statistics_test.cpp | 2 +- 21 files changed, 246 insertions(+), 101 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index b1802af..095b5be 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -135,7 +135,7 @@ ohos_shared_library("usagestatservice") { "background_task_mgr:bgtaskmgr_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", - "ces_standard:cesfwk_innerkits", + "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", @@ -157,3 +157,36 @@ ohos_shared_library("usagestatservice") { part_name = "${device_usage_statistics_part_name}" subsystem_name = "resourceschedule" } + +ohos_executable("deviceusagestats") { + include_dirs = [ + "services/common/include", + "services/packageusage/include", + "services/packagegroup/include", + "interfaces/innerkits/include", + "utils/dump/include", + ] + + sources = [ + "utils/dump/src/bundle_active_shell_command.cpp", + "utils/dump/src/main.cpp", + "utils/dump/src/shell_command.cpp", + ] + + deps = [ ":usagestatsinner" ] + + configs = [] + + external_deps = [ + "ability_base:want", + "ability_runtime:wantagent_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "utils_base:utils", + ] + + install_enable = true + part_name = "${device_usage_statistics_part_name}" +} diff --git a/bundle.json b/bundle.json index 8dbbd21..051e76f 100644 --- a/bundle.json +++ b/bundle.json @@ -51,7 +51,8 @@ "//foundation/resourceschedule/device_usage_statistics:usagestatservice", "//foundation/resourceschedule/device_usage_statistics:device_usage_statistics_sa_profile", "//foundation/resourceschedule/device_usage_statistics:device_usage_statistics_service_init", - "//foundation/resourceschedule/device_usage_statistics:bundlestate" + "//foundation/resourceschedule/device_usage_statistics:bundlestate", + "//foundation/resourceschedule/device_usage_statistics:deviceusagestats" ], "inner_kits": [ { diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 0fd0b86..47870cb 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include #include #include "securec.h" @@ -366,8 +365,8 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info & params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID; } if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) { - BUNDLE_ACTIVE_LOGE("ParseStatesParameters endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", - params.endTime, params.beginTime); + BUNDLE_ACTIVE_LOGE("ParseStatesParameters endTime(%{public}lld) <= beginTime(%{public}lld)", + (long long)params.endTime, (long long)params.beginTime); params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL; } @@ -406,11 +405,11 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) asyncCallbackInfo->env = env; asyncCallbackInfo->asyncWork = nullptr; asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->beginTime: %{public}" PRId64 "", - asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->beginTime: %{public}lld", + (long long)asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->endTime: %{public}" PRId64 "", - asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryCurrentBundleActiveStates asyncCallbackInfo->endTime: %{public}lld", + (long long)asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; @@ -481,11 +480,11 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) asyncCallbackInfo->env = env; asyncCallbackInfo->asyncWork = nullptr; asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->beginTime: %{public}" PRId64 "", - asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->beginTime: %{public}lld", + (long long)asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->endTime: %{public}" PRId64 "", - asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryBundleActiveStates asyncCallbackInfo->endTime: %{public}lld", + (long long)asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; @@ -573,8 +572,8 @@ napi_value ParseAppUsageParametersByInterval(const napi_env &env, const napi_cal params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID; } if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) { - BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval endTime(%{public}" PRId64 ") " - "<= beginTime(%{public}" PRId64 ")", params.endTime, params.beginTime); + BUNDLE_ACTIVE_LOGE("ParseAppUsageParametersByInterval endTime(%{public}lld) <= beginTime(%{public}lld)", + (long long)params.endTime, (long long)params.beginTime); params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL; } @@ -616,11 +615,11 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info) BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->intervalType: %{public}d", asyncCallbackInfo->intervalType); asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->beginTime: %{public}" PRId64 "", - asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->beginTime: %{public}lld", + (long long)asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->endTime: %{public}" PRId64 "", - asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfoByInterval asyncCallbackInfo->endTime: %{public}lld", + (long long)asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; napi_create_string_latin1(env, "QueryBundleStateInfoByInterval", NAPI_AUTO_LENGTH, &resourceName); @@ -693,8 +692,8 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info params.errorCode = ERR_USAGE_STATS_END_TIME_INVALID; } if ((params.errorCode == ERR_OK) && (params.endTime <= params.beginTime)) { - BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", - params.endTime, params.beginTime); + BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters endTime(%{public}lld) <= beginTime(%{public}lld)", + (long long)params.endTime, (long long)params.beginTime); params.errorCode = ERR_USAGE_STATS_TIME_INTERVAL; } @@ -733,11 +732,11 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) asyncCallbackInfo->env = env; asyncCallbackInfo->asyncWork = nullptr; asyncCallbackInfo->beginTime = params.beginTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->beginTime: %{public}" PRId64 "", - asyncCallbackInfo->beginTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->beginTime: %{public}lld", + (long long)asyncCallbackInfo->beginTime); asyncCallbackInfo->endTime = params.endTime; - BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->endTime: %{public}" PRId64 "", - asyncCallbackInfo->endTime); + BUNDLE_ACTIVE_LOGI("QueryBundleStateInfos asyncCallbackInfo->endTime: %{public}lld", + (long long)asyncCallbackInfo->endTime); BundleStateCommon::SettingCallbackPromiseInfo(env, params.callback, asyncCallbackInfo->info, promise); napi_value resourceName = nullptr; napi_create_string_latin1(env, "QueryBundleStateInfos", NAPI_AUTO_LENGTH, &resourceName); diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 2714dc4..3e60e1c 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -98,6 +98,7 @@ public: */ ~BundleActiveClient() {} + int32_t ShellDump(const std::vector &dumpOption, std::vector &dumpInfo); private: bool GetBundleActiveProxy(); sptr bundleActiveProxy_; diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index 2308c9a..50db119 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -16,8 +16,6 @@ #ifndef BUNDLE_ACTIVE_PROXY_H #define BUNDLE_ACTIVE_PROXY_H -#include - #include "ibundle_active_service.h" #include "bundle_active_event.h" #include "bundle_active_package_stats.h" diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index c6f1a14..ae9f263 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -17,6 +17,11 @@ namespace OHOS { namespace DeviceUsageStats { +namespace { + const int32_t EVENTS_PARAM = 5; + const int32_t PACKAGE_USAGE_PARAM = 6; + const int32_t MODULE_USAGE_PARAM = 4; +} BundleActiveClient& BundleActiveClient::GetInstance() { static BundleActiveClient instance; @@ -126,6 +131,56 @@ int32_t BundleActiveClient::QueryFormStatistics(int32_t maxNum, std::vectorQueryFormStatistics(maxNum, results, userId); } + +int32_t BundleActiveClient::ShellDump(const std::vector &dumpOption, std::vector &dumpInfo) +{ + int32_t ret = -1; + + if (dumpOption[1] == "Events") { + std::vector eventResult; + if (static_cast(dumpOption.size()) != EVENTS_PARAM) { + return ret; + } + int64_t beginTime = std::stoll(dumpOption[2]); + int64_t endTime = std::stoll(dumpOption[3]); + int32_t userId = std::stoi(dumpOption[4]); + eventResult = this->QueryEvents(beginTime, endTime, ret, userId); + for (auto& oneEvent : eventResult) { + dumpInfo.emplace_back(oneEvent.ToString()); + } + } else if (dumpOption[1] == "PackageUsage") { + std::vector packageUsageResult; + if (static_cast(dumpOption.size()) != PACKAGE_USAGE_PARAM) { + return ret; + } + int32_t intervalType = std::stoi(dumpOption[2]); + int64_t beginTime = std::stoll(dumpOption[3]); + int64_t endTime = std::stoll(dumpOption[4]); + int32_t userId = std::stoi(dumpOption[5]); + packageUsageResult = this->QueryPackageStats(intervalType, beginTime, endTime, ret, userId); + for (auto& onePackageRecord : packageUsageResult) { + dumpInfo.emplace_back(onePackageRecord.ToString()); + } + } else if (dumpOption[1] == "ModuleUsage") { + std::vector moduleResult; + if (static_cast(dumpOption.size()) != MODULE_USAGE_PARAM) { + return ret; + } + int32_t maxNum = std::stoi(dumpOption[2]); + int32_t userId = std::stoi(dumpOption[3]); + BUNDLE_ACTIVE_LOGI("M is %{public}d, u is %{public}d", maxNum, userId); + ret = this->QueryFormStatistics(maxNum, moduleResult, userId); + for (auto& oneModuleRecord : moduleResult) { + dumpInfo.emplace_back(oneModuleRecord.ToString()); + for (uint32_t i = 0; i < oneModuleRecord.formRecords_.size(); i++) { + std::string oneFormInfo = "form " + std::to_string(static_cast(i) + 1) + ", "; + dumpInfo.emplace_back(oneFormInfo + oneModuleRecord.formRecords_[i].ToString()); + } + } + } + + return ret; +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 3332433..43cfd63 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -75,12 +75,12 @@ std::vector BundleActiveProxy::QueryPackageStats(const result.push_back(*tmp); } for (uint32_t i = 0; i < result.size(); i++) { - BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}u, bundleName_ is %{public}s, " - "lastTimeUsed_ is %{public}" PRId64 ", lastContiniousTaskUsed_ is %{public}" PRId64 ", " - "totalInFrontTime_ is %{public}" PRId64 ", totalContiniousTaskUsedTime_ is %{public}" PRId64 "", + BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, " + "lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, " + "totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld", i + 1, result[i].bundleName_.c_str(), - result[i].lastTimeUsed_, result[i].lastContiniousTaskUsed_, - result[i].totalInFrontTime_, result[i].totalContiniousTaskUsedTime_); + (long long)result[i].lastTimeUsed_, (long long)result[i].lastContiniousTaskUsed_, + (long long)result[i].totalInFrontTime_, (long long)result[i].totalContiniousTaskUsedTime_); } return result; } @@ -155,11 +155,11 @@ std::vector BundleActiveProxy::QueryCurrentPackageStat } for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("QueryPackageStats result idx is %{public}d, bundleName_ is %{public}s, " - "lastTimeUsed_ is %{public}" PRId64 ", lastContiniousTaskUsed_ is %{public}" PRId64 ", " - "totalInFrontTime_ is %{public}" PRId64 ", totalContiniousTaskUsedTime_ is %{public}" PRId64 "", + "lastTimeUsed_ is %{public}lld, lastContiniousTaskUsed_ is %{public}lld, " + "totalInFrontTime_ is %{public}lld, totalContiniousTaskUsedTime_ is %{public}lld", i + 1, result[i].bundleName_.c_str(), - result[i].lastTimeUsed_, result[i].lastContiniousTaskUsed_, - result[i].totalInFrontTime_, result[i].totalContiniousTaskUsedTime_); + (long long)result[i].lastTimeUsed_, (long long)result[i].lastContiniousTaskUsed_, + (long long)result[i].totalInFrontTime_, (long long)result[i].totalContiniousTaskUsedTime_); } return result; } @@ -187,8 +187,8 @@ std::vector BundleActiveProxy::QueryCurrentEvents(const int64 } for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("QueryCurrentEvents event id is %{public}d, bundle name is %{public}s," - "time stamp is %{public}" PRId64 "", - result[i].eventId_, result[i].bundleName_.c_str(), result[i].timeStamp_); + "time stamp is %{public}lld", + result[i].eventId_, result[i].bundleName_.c_str(), (long long)result[i].timeStamp_); } return result; } @@ -231,12 +231,13 @@ int32_t BundleActiveProxy::QueryFormStatistics(int32_t maxNum, std::vectorGetBootTimeMs(); systemTimeShot_ = GetSystemTimeMs(); bundleGroupController_ = std::make_shared(debugCore_); - BUNDLE_ACTIVE_LOGI("system time shot is %{public}" PRId64 "", systemTimeShot_); + BUNDLE_ACTIVE_LOGI("system time shot is %{public}lld", (long long)systemTimeShot_); } void BundleActiveCore::InitBundleGroupController() @@ -335,9 +335,8 @@ int64_t BundleActiveCore::CheckTimeChangeAndGetWallTime(int32_t userId) if (actualSystemTime == -1 || actualRealTime == -1) { return -1; } - BUNDLE_ACTIVE_LOGI("asystime is %{public}" PRId64 ", artime is %{public}" PRId64 ", " - "esystime is %{public}" PRId64 ", diff is %{public}" PRId64 "", - actualSystemTime, actualRealTime, expectedSystemTime, diffSystemTime); + BUNDLE_ACTIVE_LOGI("asystime is %{public}lld, artime is %{public}lld, esystime is %{public}lld, diff is %{public}lld", + (long long)actualSystemTime, (long long)actualRealTime, (long long)expectedSystemTime, (long long)diffSystemTime); if (std::abs(diffSystemTime) > TIME_CHANGE_THRESHOLD_MILLIS) { // 时区变换逻辑 auto it = userStatServices_.find(userId); @@ -412,7 +411,7 @@ void BundleActiveCore::OnUserSwitched(const int32_t userId) int32_t BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int32_t userId) { - BUNDLE_ACTIVE_LOGI("FLUSH interval is %{public}" PRId64 ", debug is %{public}d", flushInterval_, debugCore_); + BUNDLE_ACTIVE_LOGI("FLUSH interval is %{public}lld, debug is %{public}d", (long long)flushInterval_, debugCore_); event.PrintEvent(debugCore_); std::lock_guard lock(mutex_); if (userId == 0 || userId == -1) { @@ -431,8 +430,9 @@ int32_t BundleActiveCore::ReportEvent(BundleActiveEvent& event, const int32_t us return 0; } - BUNDLE_ACTIVE_LOGI("report event called, bundle name %{public}s time %{public}" PRId64 " userId %{public}d, " - "eventid %{public}d, in lock range", event.bundleName_.c_str(), event.timeStamp_, userId, event.eventId_); + 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(), + (long long)event.timeStamp_, userId, event.eventId_); int64_t timeNow = CheckTimeChangeAndGetWallTime(userId); if (timeNow == -1) { return -1; @@ -490,8 +490,8 @@ std::vector BundleActiveCore::QueryPackageStats(const if (timeNow == -1) { return result; } - BUNDLE_ACTIVE_LOGI("QueryPackageStats begin time is %{public}" PRId64 ", end time is %{public}" PRId64 ", " - "intervaltype is %{public}d", beginTime, endTime, intervalType); + BUNDLE_ACTIVE_LOGI("QueryPackageStats begin time is %{public}lld, end time is %{public}lld, " + "intervaltype is %{public}d", (long long)beginTime, (long long)endTime, intervalType); if (beginTime > timeNow || beginTime >= endTime) { BUNDLE_ACTIVE_LOGI("QueryPackageStats time span illegal"); return result; diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 82e112d..2195f2e 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -1130,7 +1130,7 @@ void BundleActiveUsageDatabase::RenewTableTime(int64_t changedTime) vector tableArray = sortedTableArray_.at(i); for (uint32_t j = 0; j < tableArray.size(); j++) { int64_t newTime = tableArray.at(j) + changedTime; - BUNDLE_ACTIVE_LOGI("new table time is %{public}" PRId64 "", newTime); + BUNDLE_ACTIVE_LOGI("new table time is %{public}lld", (long long)newTime); if (newTime < 0) { DeleteInvalidTable(i, tableArray.at(j)); } else { @@ -1209,7 +1209,8 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt return databaseUsageStats; } if (endTime <= beginTime) { - BUNDLE_ACTIVE_LOGE("endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", endTime, beginTime); + BUNDLE_ACTIVE_LOGE("endTime(%{public}lld) <= beginTime(%{public}lld)", + (long long)endTime, (long long)beginTime); return databaseUsageStats; } int32_t startIndex = NearIndexOnOrBeforeCurrentTime(beginTime, sortedTableArray_.at(databaseType)); @@ -1301,13 +1302,14 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t return databaseEvents; } if (endTime <= beginTime) { - BUNDLE_ACTIVE_LOGE("endTime(%{public}" PRId64 ") <= beginTime(%{public}" PRId64 ")", endTime, beginTime); + BUNDLE_ACTIVE_LOGE("endTime(%{public}lld) <= beginTime(%{public}lld)", + (long long)endTime, (long long)beginTime); return databaseEvents; } int64_t eventTableTime = ParseStartTime(eventTableName_); if (endTime < eventTableTime) { - BUNDLE_ACTIVE_LOGE("endTime(%{public}" PRId64 ") <= eventTableTime(%{public}" PRId64 ")", - endTime, eventTableTime); + BUNDLE_ACTIVE_LOGE("endTime(%{public}lld) <= eventTableTime(%{public}lld)", + (long long)endTime, (long long)eventTableTime); return databaseEvents; } vector queryCondition; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 1782433..119dd47 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -85,7 +85,7 @@ void BundleActiveGroupController::SetHandlerAndCreateUserHistory( { if (bundleUserHistory_ == nullptr) { BUNDLE_ACTIVE_LOGI("SetHandlerAndCreateUserHistory bundleUserHistory_ is null, " - "called constructor, bootstamp is %{public}" PRId64 "", bootFromTimeStamp); + "called constructor, bootstamp is %{public}lld", (long long)bootFromTimeStamp); bundleUserHistory_ = std::make_shared(bootFromTimeStamp); } OnScreenChanged(IsScreenOn(), bootFromTimeStamp); @@ -327,9 +327,10 @@ void BundleActiveGroupController::SetBundleGroup(const std::string& bundleName, int64_t bootBasedTimeStampAdjusted = bundleUserHistory_->GetBootBasedTimeStamp(bootBasedTimeStamp); if (newGroup > ACTIVE_GROUP_ALIVE && oneBundleHistory->bundleAliveTimeoutTimeStamp_ > bootBasedTimeStampAdjusted) { - BUNDLE_ACTIVE_LOGI("%{public}s should be decreased, but time out in alive is not expire! now is " - "%{public}" PRId64 ", timeout is %{public}" PRId64 "", - bundleName.c_str(), bootBasedTimeStampAdjusted, oneBundleHistory->bundleAliveTimeoutTimeStamp_); + BUNDLE_ACTIVE_LOGI("%{public}s should be decreased, but time out in alive is not expire! now is %{public}lld," + "timeout is %{public}lld", + bundleName.c_str(), + (long long)bootBasedTimeStampAdjusted, (long long)oneBundleHistory->bundleAliveTimeoutTimeStamp_); newGroup = ACTIVE_GROUP_ALIVE; reason = oneBundleHistory->reasonInGroup_; } else if (newGroup > ACTIVE_GROUP_DAILY && oneBundleHistory->bundleDailyTimeoutTimeStamp_ > diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 76ce3b9..42175f3 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -81,8 +81,9 @@ int32_t BundleActiveUserHistory::GetLevelIndex(const string& bundleName, const i } int64_t screenDiff = GetScreenOnTimeStamp(bootBasedTimeStamp) - oneBundleHistory->lastScreenUsedTimeStamp_; int64_t bootFromDiff = GetBootBasedTimeStamp(bootBasedTimeStamp) - oneBundleHistory->lastBootFromUsedTimeStamp_; - BUNDLE_ACTIVE_LOGI("screendiff is %{public}" PRId64 ", bootfromdiff is %{public}" PRId64 ", " - "bundle name is %{public}s, userid is %{public}d", screenDiff, bootFromDiff, bundleName.c_str(), userId); + BUNDLE_ACTIVE_LOGI("screendiff is %{public}lld, bootfromdiff is %{public}lld, bundle name is %{public}s," + "userid is %{public}d", + (long long)screenDiff, (long long)bootFromDiff, bundleName.c_str(), userId); for (int32_t i = 3; i >= 0; i--) { if (screenDiff >= screenTimeLevel[i] && bootFromDiff >= bootFromTimeLevel[i]) { return i; @@ -240,13 +241,14 @@ void BundleActiveUserHistory::PrintData(int32_t userId) return; } for (auto oneBundleUsage : (*oneUserHistory)) { - BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, lastBootFromUsedTimeStamp_ is %{public}" PRId64 ", " - "lastScreenUsedTimeStamp_ is %{public}" PRId64 ", currentGroup_ is %{public}d, " - "reasonInGroup_ is %{public}d, daily time out %{public}" PRId64 ", alive time out %{public}" PRId64 "", - oneBundleUsage.first.c_str(), oneBundleUsage.second->lastBootFromUsedTimeStamp_, - oneBundleUsage.second->lastScreenUsedTimeStamp_, oneBundleUsage.second->currentGroup_, - oneBundleUsage.second->reasonInGroup_, oneBundleUsage.second->bundleDailyTimeoutTimeStamp_, - oneBundleUsage.second->bundleAliveTimeoutTimeStamp_); + BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, lastBootFromUsedTimeStamp_ is %{public}lld, " + "lastScreenUsedTimeStamp_ is %{public}lld, currentGroup_ is %{public}d, reasonInGroup_ is %{public}d, " + "daily time out %{public}lld, alive time out %{public}lld", oneBundleUsage.first.c_str(), + (long long)oneBundleUsage.second->lastBootFromUsedTimeStamp_, + (long long)oneBundleUsage.second->lastScreenUsedTimeStamp_, + oneBundleUsage.second->currentGroup_, oneBundleUsage.second->reasonInGroup_, + (long long)oneBundleUsage.second->bundleDailyTimeoutTimeStamp_, + (long long)oneBundleUsage.second->bundleAliveTimeoutTimeStamp_); } } } // namespace DeviceUsageStats diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index 1af7351..57ce14b 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -16,8 +16,6 @@ #ifndef BUNDLE_ACTIVE_EVENT_H #define BUNDLE_ACTIVE_EVENT_H -#include - #include "ibundle_active_service.h" namespace OHOS { @@ -108,6 +106,11 @@ public: * return: point to a BundleActiveEvent. */ std::shared_ptr UnMarshalling(Parcel &parcel); + /* + * function: ToString, change event object to string. + * return: string of bundlename, timestamp, eventid. + */ + std::string ToString(); }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/include/bundle_active_form_record.h b/services/packageusage/include/bundle_active_form_record.h index ac6e07b..a773947 100644 --- a/services/packageusage/include/bundle_active_form_record.h +++ b/services/packageusage/include/bundle_active_form_record.h @@ -92,6 +92,11 @@ public: * return: point to a BundleActiveFormRecord. */ std::shared_ptr UnMarshalling(Parcel &parcel); + /* + * function: ToString, change form record object to string. + * return: string of form name, form id, form dimension, last used time and touch count. + */ + std::string ToString(); }; } // 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 65f7f09..69bbf24 100644 --- a/services/packageusage/include/bundle_active_module_record.h +++ b/services/packageusage/include/bundle_active_module_record.h @@ -37,6 +37,7 @@ public: static bool cmp(const BundleActiveModuleRecord& moduleRecordA, const BundleActiveModuleRecord& moduleRecordB); virtual bool Marshalling(Parcel &parcel) const override; std::shared_ptr UnMarshalling(Parcel &parcel); + std::string ToString(); public: std::string deviceId_; diff --git a/services/packageusage/include/bundle_active_package_stats.h b/services/packageusage/include/bundle_active_package_stats.h index 846948f..285ea17 100644 --- a/services/packageusage/include/bundle_active_package_stats.h +++ b/services/packageusage/include/bundle_active_package_stats.h @@ -82,6 +82,12 @@ public: * return: point to a BundleActivePackageStats. */ std::shared_ptr UnMarshalling(Parcel &parcel); + /* + * function: ToString, change module record object to string. + * return: string of bundle name, last used time, total front time, last continuous task used time, + * total continuous task time. + */ + std::string ToString(); private: bool HasFrontAbility(); diff --git a/services/packageusage/src/bundle_active_event.cpp b/services/packageusage/src/bundle_active_event.cpp index 59e90a2..a96c4cf 100644 --- a/services/packageusage/src/bundle_active_event.cpp +++ b/services/packageusage/src/bundle_active_event.cpp @@ -126,9 +126,9 @@ void BundleActiveEvent::PrintEvent(const bool debug) const } BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, ability name is %{public}s, continue task ability is %{public}s, " "module name is %{public}s, " - "form name is %{public}s, form dimension is %{public}d, form id is %{public}" PRId64 ", event id is %{public}d", + "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(), - formName_.c_str(), formDimension_, formId_, eventId_); + formName_.c_str(), formDimension_, (long long)formId_, eventId_); } bool BundleActiveEvent::Marshalling(Parcel &parcel) const @@ -163,6 +163,12 @@ std::shared_ptr BundleActiveEvent::UnMarshalling(Parcel &parc result->eventId_ = parcel.ReadInt32(); return result; } + +std::string BundleActiveEvent::ToString() +{ + return "bundle name is " + this->bundleName_ + ", event is " + + std::to_string(this->eventId_) + ", timestamp is " + std::to_string(this->timeStamp_) + "\n"; +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/src/bundle_active_form_record.cpp b/services/packageusage/src/bundle_active_form_record.cpp index 0f7de8b..3ef3c59 100644 --- a/services/packageusage/src/bundle_active_form_record.cpp +++ b/services/packageusage/src/bundle_active_form_record.cpp @@ -84,6 +84,15 @@ bool BundleActiveFormRecord::cmp(const BundleActiveFormRecord& formRecordA, { return formRecordA.count_ > formRecordB.count_; } + +std::string BundleActiveFormRecord::ToString() +{ + return "form name is " + this->formName_ + + ", form dimension is " + std::to_string(this->formDimension_) + + ", form id is " + std::to_string(this->formId_) + + ", last used time stamp is" + std::to_string(this->formLastUsedTime_) + + ", touch count is " + std::to_string(this->count_) + "\n"; +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/src/bundle_active_module_record.cpp b/services/packageusage/src/bundle_active_module_record.cpp index 7cf83d9..9032d92 100644 --- a/services/packageusage/src/bundle_active_module_record.cpp +++ b/services/packageusage/src/bundle_active_module_record.cpp @@ -123,6 +123,14 @@ bool BundleActiveModuleRecord::cmp(const BundleActiveModuleRecord& moduleRecordA { return moduleRecordA.lastModuleUsedTime_ > moduleRecordB.lastModuleUsedTime_; } + +std::string BundleActiveModuleRecord::ToString() +{ + return "bundle name is " + this->bundleName_ + + ", module name is " + this->moduleName_ + + ", last used time stamp is " + std::to_string(this->lastModuleUsedTime_) + + ", module is used for " + std::to_string(this->launchedCount_) + " times\n"; +} } // 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 1728bbd..142d763 100644 --- a/services/packageusage/src/bundle_active_package_stats.cpp +++ b/services/packageusage/src/bundle_active_package_stats.cpp @@ -219,6 +219,16 @@ std::shared_ptr BundleActivePackageStats::UnMarshallin result->totalContiniousTaskUsedTime_ = parcel.ReadInt64(); return result; } + +std::string BundleActivePackageStats::ToString() +{ + return "bundle name is " + this->bundleName_ + + ", last used time stamp is " + std::to_string(this->lastTimeUsed_) + + ", total time in front is " + std::to_string(this->totalInFrontTime_) + + ", last continuous task used time is " + std::to_string(this->lastContiniousTaskUsed_) + + ", total continuous task time is " + + std::to_string(this->totalContiniousTaskUsedTime_) + "\n"; +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index e4b5a90..c79f1d6 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -33,11 +33,12 @@ void BundleActiveUserService::Init(const int64_t timeStamp) startupEvent.bundleName_ = BundleActiveEvent::DEVICE_EVENT_PACKAGE_NAME; currentDailyStats->AddEvent(startupEvent); for (auto it : currentDailyStats->events_.events_) { - BUNDLE_ACTIVE_LOGI("Init event id is %{public}d, time stamp is %{public}" PRId64 "", - it.eventId_, it.timeStamp_); + BUNDLE_ACTIVE_LOGI("Init event id is %{public}d, time stamp is %{public}lld", + it.eventId_, (long long)it.timeStamp_); } - BUNDLE_ACTIVE_LOGI("Init currentDailyStats begintime is %{public}" PRId64 ", " - "expire time is %{public}" PRId64 "", currentDailyStats->beginTime_, dailyExpiryDate_.GetMilliseconds()); + BUNDLE_ACTIVE_LOGI("Init currentDailyStats begintime is %{public}lld, " + "expire time is %{public}lld", (long long)currentDailyStats->beginTime_, + (long long)dailyExpiryDate_.GetMilliseconds()); } } @@ -95,8 +96,8 @@ void BundleActiveUserService::NotifyNewUpdate() void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) { - BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}" PRId64 ", E time is %{public}" PRId64 ", " - "userId is %{public}d,", currentStats_[0]->beginTime_, dailyExpiryDate_.GetMilliseconds(), userId_); + BUNDLE_ACTIVE_LOGI("ReportEvent, B time is %{public}lld, E time is %{public}lld, userId is %{public}d,", + (long long)currentStats_[0]->beginTime_, (long long)dailyExpiryDate_.GetMilliseconds(), userId_); event.PrintEvent(debugUserService_); if (event.timeStamp_ >= dailyExpiryDate_.GetMilliseconds()) { BUNDLE_ACTIVE_LOGI("ReportEvent later than daily expire, renew data in memory"); @@ -208,9 +209,10 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo BUNDLE_ACTIVE_LOGI("LoadActiveStats inter type is %{public}d, " "bundle size is %{public}zu", intervalType, stats->bundleStats_.size()); // 如果当前时间在stats的统计时间范围内,则可以从数据库加载数据 - BUNDLE_ACTIVE_LOGI("interval type is %{public}d, database stat BEGIN time is %{public}" PRId64 ", " - "timestamp is %{public}" PRId64 ", expect end is %{public}" PRId64 "", - intervalType, stats->beginTime_, timeStamp, stats->beginTime_ + periodLength_[intervalType]); + BUNDLE_ACTIVE_LOGI("interval type is %{public}d, database stat BEGIN time is %{public}lld, " + "timestamp is %{public}lld, expect end is %{public}lld", + intervalType, (long long)stats->beginTime_, (long long)timeStamp, + (long long)stats->beginTime_ + periodLength_[intervalType]); if (timeStamp > stats->beginTime_ && timeStamp < stats->beginTime_ + periodLength_[intervalType]) { currentStats_[intervalType] = stats; } @@ -236,9 +238,9 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo dailyExpiryDate_.TruncateToDay(); } listener_.OnStatsReload(); - BUNDLE_ACTIVE_LOGI("LoadActiveStats current expire time is %{public}" PRId64 ", " - "begin time is %{public}" PRId64 "", dailyExpiryDate_.GetMilliseconds(), - tmpCalendar.GetMilliseconds()); + BUNDLE_ACTIVE_LOGI("LoadActiveStats current expire time is %{public}lld, " + "begin time is %{public}lld", (long long)dailyExpiryDate_.GetMilliseconds(), + (long long)tmpCalendar.GetMilliseconds()); } void BundleActiveUserService::LoadModuleAndFormStats() @@ -341,13 +343,13 @@ std::vector BundleActiveUserService::QueryPackageStats for (auto it : currentStats->bundleStats_) { if (bundleName.empty()) { if ((it.second->totalInFrontTime_ != 0 || it.second->totalContiniousTaskUsedTime_ != 0) && - it.second->lastTimeUsed_ > beginTime && it.second->lastTimeUsed_ < endTime) { + it.second->lastTimeUsed_ >= beginTime && it.second->lastTimeUsed_ <= endTime) { result.push_back(*(it.second)); } } else { if ((it.second->totalInFrontTime_ != 0 || it.second->totalContiniousTaskUsedTime_ != 0) && - it.second->bundleName_ == bundleName && it.second->lastTimeUsed_ > beginTime && - it.second->lastTimeUsed_ < endTime) { + it.second->bundleName_ == bundleName && it.second->lastTimeUsed_ >= beginTime && + it.second->lastTimeUsed_ <= endTime) { result.push_back(*(it.second)); } } @@ -420,9 +422,10 @@ void BundleActiveUserService::PrintInMemPackageStats(const int32_t idx, const bo int64_t totalUsedTime = it.second->totalInFrontTime_; int64_t lastTimeContinuousTaskUsed = it.second->lastContiniousTaskUsed_; int64_t totalTimeContinuousTaskUsed = it.second->totalContiniousTaskUsedTime_; - BUNDLE_ACTIVE_LOGI("bundle stat is, totaltime is %{public}" PRId64 ", lastTimeUsed is %{public}" PRId64 "" - "total continuous task is %{public}" PRId64 ", lastTimeContinuousTaskUsed is %{public}" PRId64 "", - totalUsedTime, lastTimeUsed, totalTimeContinuousTaskUsed, lastTimeContinuousTaskUsed); + BUNDLE_ACTIVE_LOGI("bundle stat is, totaltime is %{public}lld, lastTimeUsed is %{public}lld" + "total continuous task is %{public}lld, lastTimeContinuousTaskUsed is %{public}lld", + (long long)totalUsedTime, (long long)lastTimeUsed, + (long long)totalTimeContinuousTaskUsed, (long long)lastTimeContinuousTaskUsed); } } @@ -441,8 +444,8 @@ void BundleActiveUserService::PrintInMemEventStats(const bool debug) int32_t eventid = currentStats_[idx]->events_.events_[i].eventId_; int64_t timestamp = currentStats_[idx]->events_.events_[i].timeStamp_; BUNDLE_ACTIVE_LOGI("In mem, event stat is, abilityid is %{public}s, abilityname is %{public}s, " - "bundlename is %{public}s, eventid is %{public}d, timestamp is %{public}" PRId64 "", - abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, timestamp); + "bundlename is %{public}s, eventid is %{public}d, timestamp is %{public}lld", + abilityId.c_str(), abilityname.c_str(), bundlename.c_str(), eventid, (long long)timestamp); } } @@ -454,16 +457,17 @@ void BundleActiveUserService::PrintInMemFormStats(const bool debug, const bool p for (const auto& oneModule : moduleRecords_) { if (oneModule.second) { BUNDLE_ACTIVE_LOGI("bundle name is %{public}s, module name is %{public}s, " - "lastusedtime is %{public}" PRId64 ", launchcount is %{public}d", oneModule.second->bundleName_.c_str(), + "lastusedtime is %{public}lld, launchcount is %{public}d", oneModule.second->bundleName_.c_str(), oneModule.second->moduleName_.c_str(), - oneModule.second->lastModuleUsedTime_, oneModule.second->launchedCount_); + (long long)oneModule.second->lastModuleUsedTime_, oneModule.second->launchedCount_); BUNDLE_ACTIVE_LOGI("combined info is %{public}s", oneModule.first.c_str()); if (printform) { for (const auto& oneForm : oneModule.second->formRecords_) { BUNDLE_ACTIVE_LOGI("form name is %{public}s, form dimension is %{public}d, " - "form id is %{public}" PRId64 ", " - "lasttouchtime is %{public}" PRId64 ", touchcount is %{public}d", oneForm.formName_.c_str(), - oneForm.formDimension_, oneForm.formId_, oneForm.formLastUsedTime_, oneForm.count_); + "form id is %{public}lld, " + "lasttouchtime is %{public}lld, touchcount is %{public}d", oneForm.formName_.c_str(), + oneForm.formDimension_, (long long)oneForm.formId_, + (long long)oneForm.formLastUsedTime_, oneForm.count_); } } } diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index e057e4d..9a4eca3 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -107,7 +107,7 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryEvents_001, F { int32_t errCode = 0; std::vector result = BundleActiveClient::GetInstance().QueryEvents(0, LARGE_NUM, errCode); - EXPECT_EQ(result.size(), 0); + EXPECT_EQ(result.size(), 1); } /* -- Gitee