From 2d37741535e23a52749d95d3c33592699b17f1df Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Fri, 4 Mar 2022 18:26:05 +0800 Subject: [PATCH 1/3] modify codex Signed-off-by: wyuanchao --- frameworks/src/bundle_state_query.cpp | 24 ++++++++--------- .../innerkits/src/bundle_active_proxy.cpp | 8 +++--- .../napi/include/bundle_state_common.h | 3 --- .../common/include/bundle_active_constant.h | 4 ++- services/common/include/bundle_active_core.h | 4 +-- .../src/bundle_active_binary_search.cpp | 10 +++---- services/common/src/bundle_active_core.cpp | 4 +-- services/common/src/bundle_active_service.cpp | 15 +++++++++-- services/common/src/bundle_active_stub.cpp | 2 +- .../src/bundle_active_usage_database.cpp | 26 +++++++++---------- .../include/bundle_active_group_common.h | 10 +++---- .../include/bundle_active_group_controller.h | 2 +- .../include/bundle_active_group_handler.h | 3 ++- .../include/bundle_active_package_history.h | 16 ++++++------ .../src/bundle_active_group_controller.cpp | 4 +-- .../src/bundle_active_group_handler.cpp | 2 +- .../include/bundle_active_event.h | 6 ++--- .../include/bundle_active_event_stats.h | 10 +++---- .../packageusage/src/bundle_active_event.cpp | 6 ----- .../src/bundle_active_event_list.cpp | 8 +++--- .../src/bundle_active_stats_combiner.cpp | 2 +- .../src/bundle_active_user_service.cpp | 10 +++---- 22 files changed, 91 insertions(+), 88 deletions(-) diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 75a97be..8d84091 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -21,18 +21,18 @@ namespace OHOS { namespace DeviceUsageStats { -static const int32_t Is_Idle_State_MIN_PARAMS = 1; -static const int32_t Is_Idle_State_PARAMS = 2; -static const int32_t Priority_Group_MIN_PARAMS = 0; -static const int32_t Priority_Group_PARAMS = 1; -static const int32_t States_MIN_PARAMS = 2; -static const int32_t States_PARAMS = 3; -static const int32_t App_Usage_MIN_PARAMS_BY_INTERVAL = 3; -static const int32_t App_Usage_PARAMS_BY_INTERVAL = 4; -static const int32_t App_Usage_MIN_PARAMS = 2; -static const int32_t App_Usage_PARAMS = 3; -static const int32_t SECOND_ARG = 2; -static const int32_t THIRD_ARG = 3; +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 SECOND_ARG = 2; +const u_int32_t THIRD_ARG = 3; napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_info &info, IsIdleStateParamsInfo ¶ms) diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 068794f..31fd4e9 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -78,7 +78,7 @@ std::vector BundleActiveProxy::QueryPackageStats(const } result.push_back(*tmp); } - for (int i = 0; i < result.size(); i++) { + for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("BundleActiveProxy::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", @@ -109,7 +109,7 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi } result.push_back(*tmp); } - for (int i = 0; i < result.size(); i++) { + for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("BundleActiveProxy::QueryEvents event id is %{public}d, bundle name is %{public}s, " "time stamp is %{public}lld", result[i].eventId_, result[i].bundleName_.c_str(), result[i].timeStamp_); } @@ -153,7 +153,7 @@ std::vector BundleActiveProxy::QueryCurrentPackageStat } result.push_back(*tmp); } - for (int i = 0; i < result.size(); i++) { + for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("BundleActiveProxy::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", @@ -184,7 +184,7 @@ std::vector BundleActiveProxy::QueryCurrentEvents(const int64 } result.push_back(*tmp); } - for (int i = 0; i < result.size(); i++) { + for (uint32_t i = 0; i < result.size(); i++) { BUNDLE_ACTIVE_LOGI("event id is %{public}d, bundle name is %{public}s, time stamp is %{public}lld", result[i].eventId_, result[i].bundleName_.c_str(), result[i].timeStamp_); } diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index 5e8daf4..61bbf2e 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -18,9 +18,6 @@ #include "bundle_active_client.h" #include "bundle_state_data.h" -#include "bundle_state_query.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" namespace OHOS { namespace DeviceUsageStats { diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index d3caa42..0266f6c 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -28,7 +28,6 @@ const int32_t NO_UPDATE_ROW = 0; const int32_t NO_DELETE_ROW = 0; const int32_t EVENT_TABLE_NUMBER = 1; const int32_t APP_GROUP_TABLE_NUMBER = 2; -const int32_t TABLE_NOT_EXIST = 0; const int32_t DAILY_DATABASE_INDEX = 0; const int32_t WEEKLY_DATABASE_INDEX = 1; const int32_t MONTHLY_DATABASE_INDEX = 2; @@ -39,6 +38,7 @@ const int32_t BUNDLE_ACTIVE_CURRENT_VERSION = 1; const int32_t BUNDLE_ACTIVE_SUCCESS = 0; const int32_t BUNDLE_ACTIVE_FAIL = -1; const int32_t BUNDLE_ACTIVE_RDB_VERSION = 1; +const uint32_t TABLE_NOT_EXIST = 0; const int USER_ID_COLUMN_INDEX = 0; const int BUNDLE_NAME_COLUMN_INDEX = 1; const int BUNDLE_STARTED_COUNT_COLUMN_INDEX = 2; @@ -59,10 +59,12 @@ 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 TWO_SECONDS = 2 * 1000; +const int USERID_INITIAL_VALUE = -1; const int64_t SIX_DAY_IN_MILLIS_MAX = 6 * 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 std::string BUNDLE_NAME_INITIAL_VALUE = ""; 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 1956dc5..b84b7b5 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -34,8 +34,8 @@ namespace DeviceUsageStats { class BundleActiveReportHandlerObject { public: BundleActiveEvent event_; - int userId_; - std::string bundleName_; + int userId_ = -1; + std::string bundleName_ = ""; BundleActiveReportHandlerObject() {}; BundleActiveReportHandlerObject(const BundleActiveReportHandlerObject& orig); ~BundleActiveReportHandlerObject() {}; diff --git a/services/common/src/bundle_active_binary_search.cpp b/services/common/src/bundle_active_binary_search.cpp index 9b284d8..8f29f7f 100644 --- a/services/common/src/bundle_active_binary_search.cpp +++ b/services/common/src/bundle_active_binary_search.cpp @@ -28,20 +28,20 @@ BundleActiveBinarySearch::~BundleActiveBinarySearch() int32_t BundleActiveBinarySearch::BinarySearch(const std::vector &tableNameArray, int64_t targetValue) { - int32_t low = 0; - int32_t high = tableNameArray.size() - 1; + uint32_t low = 0; + uint32_t high = tableNameArray.size() - 1; while (low <= high) { - int32_t mid = (low + high) >> 1; + uint32_t mid = (low + high) >> 1; int64_t midValue = tableNameArray.at(mid); if (midValue < targetValue) { low = mid + 1; } else if (midValue > targetValue) { high = mid - 1; } else { - return mid; + return static_cast(mid); } } - return ~low; + return static_cast(~low); } } } \ No newline at end of file diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 5f09345..b6d9d62 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -30,7 +30,6 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const BundleAct event_.abilityId_ = orig.event_.abilityId_; event_.timeStamp_ = orig.event_.timeStamp_; event_.eventId_ = orig.event_.eventId_; - event_.isidle_ = orig.event_.isidle_; event_.continuousTaskAbilityName_ = orig.event_.continuousTaskAbilityName_; userId_ = orig.userId_; bundleName_ = orig.bundleName_; @@ -38,6 +37,7 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const BundleAct BundleActiveCore::BundleActiveCore() { + systemTimeShot_ = -1; } BundleActiveCore::~BundleActiveCore() @@ -157,7 +157,7 @@ void BundleActiveCore::InitBundleGroupController() std::vector osAccountInfos; GetAllActiveUser(osAccountInfos); bundleGroupController_->bundleGroupEnable_ = true; - for (int i = 0; i < osAccountInfos.size(); i++) { + for (u_int32_t i = 0; i < osAccountInfos.size(); i++) { bundleGroupController_->PeriodCheckBundleState(osAccountInfos[i].GetLocalId()); } } diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 9b7bfd2..90e9f61 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -98,7 +98,12 @@ void BundleActiveService::InitNecessaryState() } else { return; } - shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); + try { + shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); + } catch(const std::bad_alloc &e) { + BUNDLE_ACTIVE_LOGE("Memory allocation failed"); + return; + } auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); powerManagerClient.RegisterShutdownCallback(shutdownCallback_); InitAppStateSubscriber(reportHandler_); @@ -170,7 +175,13 @@ void BundleActiveService::OnStop() auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); powerManagerClient.UnRegisterShutdownCallback(shutdownCallback_); } else { - shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); + try { + shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); + } + catch(const std::bad_alloc &e) { + BUNDLE_ACTIVE_LOGE("Memory allocation failed"); + return; + } } auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); powerManagerClient.UnRegisterShutdownCallback(shutdownCallback_); diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index 99beeea..f25bffe 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -50,7 +50,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me int64_t beginTime = data.ReadInt64(); int64_t endTime = data.ReadInt64(); result = QueryPackageStats(intervalType, beginTime, endTime); - size = result.size(); + size = static_cast(result.size()); BUNDLE_ACTIVE_LOGI("BundleActiveStub::OnRemoteRequest QUERY_USAGE_STATS result size is %{public}d", size); reply.WriteInt32(size); for (int i = 0; i < size; i++) { diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 49330f0..7c83f36 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -131,7 +131,7 @@ void BundleActiveUsageDatabase::InitDatabaseTableInfo(int64_t currentTime) if (startIndex < BUNDLE_ACTIVE_SUCCESS) { continue; } - int32_t tableNumber = sortedTableArray_.at(i).size(); + int32_t tableNumber = static_cast(sortedTableArray_.at(i).size()); for (int32_t j = startIndex; j < tableNumber; j++) { DeleteInvalidTable(i, sortedTableArray_.at(i).at(startIndex)); sortedTableArray_.at(i).erase(sortedTableArray_.at(i).begin() + startIndex); @@ -149,11 +149,11 @@ int32_t BundleActiveUsageDatabase::NearIndexOnOrAfterCurrentTime(int64_t current vector &sortedTableArray) { int32_t low = 0; - int32_t high = sortedTableArray.size() - 1; + int32_t high = static_cast(sortedTableArray.size() - 1); int32_t mid = -1; int64_t tableTime = -1; while (low <= high) { - mid = (low + high) >> 1; + mid = (high - low) / 2 + low; tableTime = sortedTableArray.at(mid); if (currentTime > tableTime) { low = mid + 1; @@ -165,7 +165,7 @@ int32_t BundleActiveUsageDatabase::NearIndexOnOrAfterCurrentTime(int64_t current } if (currentTime < tableTime) { return mid; - } else if (currentTime > tableTime && low < sortedTableArray.size()) { + } else if (currentTime > tableTime && low < static_cast(sortedTableArray.size())) { return low; } else { return BUNDLE_ACTIVE_FAIL; @@ -235,7 +235,7 @@ void BundleActiveUsageDatabase::HandleTableInfo(unsigned int databaseType) sort(sortedTableArray_.at(databaseType).begin(), sortedTableArray_.at(databaseType).end()); } if ((databaseType == DAILY_DATABASE_INDEX) && !sortedTableArray_.at(databaseType).empty()) { - int lastTableIndex = sortedTableArray_.at(databaseType).size() - 1; + uint32_t lastTableIndex = sortedTableArray_.at(databaseType).size() - 1; eventBeginTime_ = sortedTableArray_.at(databaseType).at(lastTableIndex); } } else if (databaseType == EVENT_DATABASE_INDEX) { @@ -258,7 +258,8 @@ void BundleActiveUsageDatabase::DeleteExcessiveTableData(unsigned int databaseTy BUNDLE_ACTIVE_LOGE("database table not exist"); return; } - int32_t deleteNumber = sortedTableArray_.at(databaseType).size() - MAX_FILES_EVERY_INTERVAL_TYPE[databaseType]; + int32_t existingNumber = static_cast(sortedTableArray_.at(databaseType).size()); + int32_t deleteNumber = existingNumber - MAX_FILES_EVERY_INTERVAL_TYPE[databaseType]; if (deleteNumber > 0) { for (int32_t i = 0; i < deleteNumber; i++) { // 删除多余文件 @@ -704,12 +705,12 @@ shared_ptr BundleActiveUsageDatabase::GetCurrentUsageDa int userId) { lock_guard lock(databaseMutex_); - if (databaseType < 0 || databaseType >= sortedTableArray_.size()) { + if (databaseType < 0 || databaseType >= static_cast(sortedTableArray_.size())) { BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}d", databaseType); return nullptr; } - int tableNumber = sortedTableArray_.at(databaseType).size(); + uint32_t tableNumber = sortedTableArray_.at(databaseType).size(); if (tableNumber == TABLE_NOT_EXIST) { return nullptr; } @@ -865,10 +866,9 @@ int32_t BundleActiveUsageDatabase::GetOptimalIntervalType(int64_t beginTime, int lock_guard lock(databaseMutex_); int32_t optimalIntervalType = -1; int64_t leastTimeDiff = numeric_limits::max(); - for (int32_t i = sortedTableArray_.size() - 1; i >= 0; i--) { + for (uint32_t i = sortedTableArray_.size() - 1; i >= 0; i--) { int32_t index = NearIndexOnOrBeforeCurrentTime(beginTime, sortedTableArray_.at(i)); - int32_t size = sortedTableArray_.at(i).size(); - if (index >= 0 && index < size) { + if (index >= 0 && index < static_cast(sortedTableArray_.at(i).size())) { int64_t diff = abs(sortedTableArray_.at(i).at(index) - beginTime); if (diff < leastTimeDiff) { leastTimeDiff = diff; @@ -982,7 +982,7 @@ void BundleActiveUsageDatabase::UpdateUsageData(int32_t databaseType, BundleActi eventBeginTime_ = stats.beginTime_; DeleteExcessiveTableData(EVENT_DATABASE_INDEX); } - packageTableIndex = ~packageTableIndex; + packageTableIndex = static_cast(~packageTableIndex); sortedTableArray_.at(databaseType).insert(sortedTableArray_.at(databaseType).begin() + packageTableIndex, stats.beginTime_); DeleteExcessiveTableData(databaseType); @@ -998,7 +998,7 @@ vector BundleActiveUsageDatabase::QueryDatabaseUsageSt { lock_guard lock(databaseMutex_); vector databaseUsageStats; - if (databaseType < 0 || databaseType >= sortedTableArray_.size()) { + if (databaseType < 0 || databaseType >= static_cast(sortedTableArray_.size())) { BUNDLE_ACTIVE_LOGE("databaseType is invalid, databaseType = %{public}d", databaseType); return databaseUsageStats; } diff --git a/services/packagegroup/include/bundle_active_group_common.h b/services/packagegroup/include/bundle_active_group_common.h index f530520..3c08575 100644 --- a/services/packagegroup/include/bundle_active_group_common.h +++ b/services/packagegroup/include/bundle_active_group_common.h @@ -43,11 +43,11 @@ const int64_t DEFAULT_EVENT_TIMEOUT = ONE_HOUR; const int64_t DEFAULT_NOTIFY_EVENT_TIMEOUT = 12 * ONE_HOUR; const int64_t DEFAULT_SYSTEevent__TIMEOUT = 2 * ONE_HOUR; const int64_t DEFAULT_LONT_TIME_TASK_START_EVENT_TIMEOUT = 30 * ONE_MINUTE; -const int GROUP_CONTROL_REASON_MASK = 0xFF00; -const int GROUP_CONTROL_REASON_DEFAULT = 0x0100; -const int GROUP_CONTROL_REASON_TIMEOUT = 0x0200; -const int GROUP_CONTROL_REASON_USAGE = 0x0300; -const int GROUP_CONTROL_REASON_FORCED = 0x0400; +const u_int32_t GROUP_CONTROL_REASON_MASK = 0xFF00; +const u_int32_t GROUP_CONTROL_REASON_DEFAULT = 0x0100; +const u_int32_t GROUP_CONTROL_REASON_TIMEOUT = 0x0200; +const u_int32_t GROUP_CONTROL_REASON_USAGE = 0x0300; +const u_int32_t GROUP_CONTROL_REASON_FORCED = 0x0400; const int GROUP_CONTROL_REASON_CALCULATED = 0x0500; const int GROUP_EVENT_REASON_MASK = 0x00FF; const int GROUP_EVENT_REASON_SYSTEM = 0x0001; diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index c0589b7..7c8405d 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -42,7 +42,7 @@ public: using BundleFlag = OHOS::AppExecFwk::BundleFlag; using ApplicationFlag = OHOS::AppExecFwk::ApplicationFlag; OHOS::AppExecFwk::ApplicationFlag flag = OHOS::AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO; - bool bundleGroupEnable_; + bool bundleGroupEnable_ = true; bool debug_ = true; const int LEVEL_GROUP[4] = { ACTIVE_GROUP_ALIVE, diff --git a/services/packagegroup/include/bundle_active_group_handler.h b/services/packagegroup/include/bundle_active_group_handler.h index cb9ec0d..a12f09e 100644 --- a/services/packagegroup/include/bundle_active_group_handler.h +++ b/services/packagegroup/include/bundle_active_group_handler.h @@ -19,6 +19,7 @@ #include "event_handler.h" #include "event_runner.h" +#include "bundle_active_constant.h" #include "ibundle_active_service.h" #include "bundle_active_group_controller.h" #include "bundle_active_group_common.h" @@ -29,7 +30,7 @@ class BundleActiveGroupHandlerObject { public: std::string bundleName_; int userId_; - BundleActiveGroupHandlerObject() {}; + BundleActiveGroupHandlerObject():bundleName_(BUNDLE_NAME_INITIAL_VALUE), userId_(USERID_INITIAL_VALUE) {}; BundleActiveGroupHandlerObject(const BundleActiveGroupHandlerObject& orig); ~BundleActiveGroupHandlerObject() {}; }; diff --git a/services/packagegroup/include/bundle_active_package_history.h b/services/packagegroup/include/bundle_active_package_history.h index c78c304..9803c45 100644 --- a/services/packagegroup/include/bundle_active_package_history.h +++ b/services/packagegroup/include/bundle_active_package_history.h @@ -22,14 +22,14 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActivePackageHistory { public: - int64_t lastBootFromUsedTimeStamp_; - int64_t lastScreenUsedTimeStamp_; - int64_t lastGroupCalculatedTimeStamp_; - int lastCalculatedGroup_; - int currentGroup_; - int reasonInGroup_; - int64_t bundleAliveTimeoutTimeStamp_; - int64_t bundleDailyTimeoutTimeStamp_; + int64_t lastBootFromUsedTimeStamp_ = 0; + int64_t lastScreenUsedTimeStamp_ = 0; + int64_t lastGroupCalculatedTimeStamp_ = 0; + int lastCalculatedGroup_ = 0; + int currentGroup_ = 0; + int reasonInGroup_ = 0; + int64_t bundleAliveTimeoutTimeStamp_ = 0; + int64_t bundleDailyTimeoutTimeStamp_ = 0; BundleActivePackageHistory() {}; ~BundleActivePackageHistory() {}; }; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index ca79fea..be03b75 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -244,8 +244,8 @@ void BundleActiveGroupController::CheckAndUpdateGroup(const std::string& bundleN if (oneBundleHistory == nullptr) { return; } - int groupReason = oneBundleHistory->reasonInGroup_; - int oldGroupControlReason = groupReason & GROUP_CONTROL_REASON_MASK; + u_int32_t groupReason = oneBundleHistory->reasonInGroup_; + u_int32_t oldGroupControlReason = groupReason & GROUP_CONTROL_REASON_MASK; if (oldGroupControlReason == GROUP_CONTROL_REASON_FORCED) { return; } diff --git a/services/packagegroup/src/bundle_active_group_handler.cpp b/services/packagegroup/src/bundle_active_group_handler.cpp index ce1e089..a51784d 100644 --- a/services/packagegroup/src/bundle_active_group_handler.cpp +++ b/services/packagegroup/src/bundle_active_group_handler.cpp @@ -64,7 +64,7 @@ void BundleActiveGroupHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointe BUNDLE_ACTIVE_LOGI("BundleActiveCore::GetAllActiveUser size is 0"); return; } - for (int i = 0; i < osAccountInfos.size(); i++) { + for (u_int32_t i = 0; i < osAccountInfos.size(); i++) { bundleActiveGroupController_->CheckEachBundleState(osAccountInfos[i].GetLocalId()); bundleActiveGroupController_->RestoreToDatabase(osAccountInfos[i].GetLocalId()); } diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index d438384..952b024 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -45,9 +45,8 @@ public: std::string continuousTaskAbilityName_; std::string abilityName_; std::string abilityId_; - int64_t timeStamp_; - int eventId_; - bool isidle_; + int64_t timeStamp_ = -1; + int eventId_ = -1; public: BundleActiveEvent() {}; @@ -58,7 +57,6 @@ public: std::string GetAbilityId(); int64_t GetTimeStamp(); int GetEventId(); - bool GetIsIdle(); virtual bool Marshalling(Parcel &parcel) const override; std::shared_ptr Unmarshalling(Parcel &parcel); }; diff --git a/services/packageusage/include/bundle_active_event_stats.h b/services/packageusage/include/bundle_active_event_stats.h index a2f3900..64843ee 100644 --- a/services/packageusage/include/bundle_active_event_stats.h +++ b/services/packageusage/include/bundle_active_event_stats.h @@ -23,11 +23,11 @@ namespace DeviceUsageStats { class BundleActiveEventStats { public: int eventId_; - int64_t beginTimeStamp_; - int64_t endTimeStamp_; - int64_t lastEventTime_; - int64_t totalTime_; - int count_; + int64_t beginTimeStamp_ = -1; + int64_t endTimeStamp_ = -1; + int64_t lastEventTime_ = -1; + int64_t totalTime_ = 0; + int count_ = 0; BundleActiveEventStats() {}; BundleActiveEventStats(const BundleActiveEventStats& orig); int GetEventId(); diff --git a/services/packageusage/src/bundle_active_event.cpp b/services/packageusage/src/bundle_active_event.cpp index c29ebc3..9cb7e68 100644 --- a/services/packageusage/src/bundle_active_event.cpp +++ b/services/packageusage/src/bundle_active_event.cpp @@ -24,7 +24,6 @@ BundleActiveEvent::BundleActiveEvent (const BundleActiveEvent& orig) abilityId_ = orig.abilityId_; timeStamp_ = orig.timeStamp_; eventId_ = orig.eventId_; - isidle_ = orig.isidle_; } BundleActiveEvent::BundleActiveEvent(int eventId, int64_t timeStamp) @@ -61,11 +60,6 @@ int BundleActiveEvent::GetEventId() return eventId_; } -bool BundleActiveEvent::GetIsIdle() -{ - return isidle_; -} - bool BundleActiveEvent::Marshalling(Parcel &parcel) const { if (parcel.WriteString(bundleName_) && diff --git a/services/packageusage/src/bundle_active_event_list.cpp b/services/packageusage/src/bundle_active_event_list.cpp index 86d0c3d..5732ec6 100644 --- a/services/packageusage/src/bundle_active_event_list.cpp +++ b/services/packageusage/src/bundle_active_event_list.cpp @@ -33,7 +33,7 @@ void BundleActiveEventList::Clear() void BundleActiveEventList::Insert(BundleActiveEvent event) { - int size = events_.size(); + uint32_t size = events_.size(); if (size == 0 || event.timeStamp_ >= events_.back().timeStamp_) { events_.push_back(event); return; @@ -44,7 +44,7 @@ void BundleActiveEventList::Insert(BundleActiveEvent event) int BundleActiveEventList::FindBestIndex(const int64_t timeStamp) { - int size = events_.size(); + int size = static_cast(events_.size()); int result = size; int lo = 0; int hi = size - 1; @@ -63,8 +63,8 @@ int BundleActiveEventList::FindBestIndex(const int64_t timeStamp) void BundleActiveEventList::Merge(const BundleActiveEventList& right) { - int size = right.events_.size(); - for (int i = 0; i < size; i++) { + u_int32_t size = right.events_.size(); + for (uint32_t i = 0; i < size; i++) { Insert(right.events_[i]); } } diff --git a/services/packageusage/src/bundle_active_stats_combiner.cpp b/services/packageusage/src/bundle_active_stats_combiner.cpp index 88ddd97..7bc2b83 100644 --- a/services/packageusage/src/bundle_active_stats_combiner.cpp +++ b/services/packageusage/src/bundle_active_stats_combiner.cpp @@ -35,7 +35,7 @@ void BundleActiveStatsCombiner::combine(const std::shared_ptr { BUNDLE_ACTIVE_LOGI("BundleActiveStatsCombiner::combine called"); int startIndex = stats->events_.FindBestIndex(beginTime); - int size = stats->events_.events_.size(); + int size = static_cast(stats->events_.events_.size()); for (int 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 cdc1639..e75102f 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -162,7 +162,7 @@ void BundleActiveUserService::RestoreStats() BUNDLE_ACTIVE_LOGI("BundleActiveUserService::RestoreStats() called"); if (statsChanged_) { BUNDLE_ACTIVE_LOGI("BundleActiveUserService::RestoreStats() stat changed is true"); - for (int i = 0; i < currentStats_.size(); i++) { + for (uint32_t i = 0; i < currentStats_.size(); i++) { database_.UpdateUsageData(i, *(currentStats_[i])); } currentStats_[BundleActivePeriodStats::PERIOD_DAILY]->events_.Clear(); @@ -176,7 +176,7 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo BundleActiveCalendar tmpCalendar(0); tmpCalendar.SetMilliseconds(timeStamp); tmpCalendar.TruncateTo(BundleActivePeriodStats::PERIOD_DAILY); - for (int intervalType = 0; intervalType < PERIOD_LENGTH.size(); intervalType++) { + for (uint32_t intervalType = 0; intervalType < PERIOD_LENGTH.size(); intervalType++) { if (!force && currentStats_[intervalType] != nullptr && currentStats_[intervalType]->beginTime_ == tmpCalendar.GetMilliseconds()) { continue; @@ -276,7 +276,7 @@ std::vector BundleActiveUserService::QueryPackageStats intervalType = BundleActivePeriodStats::PERIOD_DAILY; } } - if (intervalType < 0 || intervalType >= currentStats_.size()) { + if (intervalType < 0 || intervalType >= static_cast(currentStats_.size())) { return result; } @@ -366,8 +366,8 @@ void BundleActiveUserService::printstat() BUNDLE_ACTIVE_LOGI("event stat is, totaltime is %{public}lld, lasttimeused is %{public}lld", totalusedtime, lasttimeused); } - int size = currentStats_[idx]->events_.events_.size(); - for (int i = 0; i < size; i++) { + uint32_t size = currentStats_[idx]->events_.events_.size(); + for (uint32_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_; -- Gitee From dcc5792ef9ba97d0ae7f4c80fd5b7b401d881210 Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Fri, 4 Mar 2022 18:57:32 +0800 Subject: [PATCH 2/3] modify codex Signed-off-by: wyuanchao --- services/common/src/bundle_active_usage_database.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 7c83f36..4ec6d67 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -152,8 +152,9 @@ int32_t BundleActiveUsageDatabase::NearIndexOnOrAfterCurrentTime(int64_t current int32_t high = static_cast(sortedTableArray.size() - 1); int32_t mid = -1; int64_t tableTime = -1; + int32_t divisor = 2; while (low <= high) { - mid = (high - low) / 2 + low; + mid = (high + low) / divisor; tableTime = sortedTableArray.at(mid); if (currentTime > tableTime) { low = mid + 1; @@ -982,7 +983,7 @@ void BundleActiveUsageDatabase::UpdateUsageData(int32_t databaseType, BundleActi eventBeginTime_ = stats.beginTime_; DeleteExcessiveTableData(EVENT_DATABASE_INDEX); } - packageTableIndex = static_cast(~packageTableIndex); + packageTableIndex = static_cast(~packageTableIndex); sortedTableArray_.at(databaseType).insert(sortedTableArray_.at(databaseType).begin() + packageTableIndex, stats.beginTime_); DeleteExcessiveTableData(databaseType); -- Gitee From c704556417aa0190493af87ede3c156e0a55b204 Mon Sep 17 00:00:00 2001 From: wyuanchao Date: Fri, 4 Mar 2022 21:15:47 +0800 Subject: [PATCH 3/3] codex Signed-off-by: wyuanchao --- frameworks/src/bundle_state_common.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 525b3d3..58d1df2 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -112,6 +112,10 @@ void BundleStateCommon::GetBundleStateInfoByIntervalForResult( void BundleStateCommon::GetBundleStateInfoForResult(napi_env env, const std::shared_ptr> &packageStats, napi_value result) { + if (packageStats == nullptr) { + BUNDLE_ACTIVE_LOGE("PackageStats is nullptr"); + return; + } for (const auto &item : *packageStats) { napi_value packageObject = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &packageObject)); -- Gitee