diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 525b3d362aad8e2b8c7ff0e9a632879e5ffe7149..58d1df2c73dd67d7dbd41dfe6455c0d9ba21112e 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)); diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 75a97beba83afc149a8b67c5ae7a1f81ed935228..8d84091dfa25928e9616a1d61b1889ebf6f2198c 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 068794f08f8d3a55148f756c3c173d4647faba60..31fd4e9915f10929b78c94ca21d39b96c4189cac 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 5e8daf4642d1195c4b1037b9515b09ffcf867404..61bbf2e31f62158ab83329b6ea9c06927323b4c2 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 d3caa42ea5c57ae4c1616808233a57b7a0815a70..0266f6c966e65b64a9f3399492341b9f2396158c 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 1956dc510ccb8fa3d437a4709fe7b1d93bf7c05e..b84b7b5e285e48141af46c76497de5ffa2d67414 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 9b284d8426f62c1e2ce3ed70ab6a62b9c1a011cd..8f29f7f08569953b1fc1618488adb489ba542fce 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 5f09345ebfd4174517bbd07d0b47d6d3450f5fe7..b6d9d6252c3df87adaae91fd9af1de39557354ef 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 9b7bfd26662bbd3b9cbac0a797f3e3e7b34d34e5..90e9f61b1566afd7045f249077e7bed23279c13f 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 99beeea269752e3665563d37f46b87acfcf356ee..f25bffe8a292f7ad4e10409af50586c31f32ee1b 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 49330f0d551698f27a84b0fd7f6a7d80d716378b..4ec6d675b7908dfba7285d1f26ae78831bb76825 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,12 @@ 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; + int32_t divisor = 2; while (low <= high) { - mid = (low + high) >> 1; + mid = (high + low) / divisor; tableTime = sortedTableArray.at(mid); if (currentTime > tableTime) { low = mid + 1; @@ -165,7 +166,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 +236,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 +259,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 +706,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 +867,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 +983,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 +999,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 f530520da92a22eaede41847929e7d0f05659347..3c085753f42d185766854d5922edca843cf4cdd2 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 c0589b7218e011eefed595c774d53f8e83ba8ac6..7c8405d87790ee856d5d60ab77d33ec95044be7c 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 cb9ec0ddfb1df08d979a49472428dba0b5ebefde..a12f09e9252163a9952b75d73c286ecedc2faf76 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 c78c30408a973ad9b76a477ffe5d9d1f2a2c57f1..9803c45ad44e3cd91c038c6a0aa6150d2cdce284 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 ca79fead8deee27763ffbc680d3a25f559bdab55..be03b756ca82d545c98f9238ca6f0220b45b5c33 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 ce1e0898361635bbbc535092faada9508f1223c6..a51784de97186ab9d60c5c0c6244e371b0c3929b 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 d4383847f81b245fb187f80c20657e8457648471..952b024b2b49ae350f42c9cac869ecefec36d11d 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 a2f390016721708f69af820c2a459e01097d9325..64843ee7087dc36640908bec25b9640fffb47edb 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 c29ebc33a3561ada5be5044f361aa3832fb95735..9cb7e6897b0b0a392a6aac9fe8bb04836fff00a7 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 86d0c3da95211a8ab179460d17096fc530a91d19..5732ec69fc79991aa8c0e901a3291db90cb3987d 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 88ddd974801d008a9a35733f00458f014928a57b..7bc2b837b130a759399661beb61c062bf8abb042 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 cdc163937ced6cc91e990018a7f2ce21eb1920db..e75102f6a8d07fbaa43f26938bef4cf06766f553 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_;