diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 525b3d362aad8e2b8c7ff0e9a632879e5ffe7149..6c8ec0bd7892ea16071192f5c80a75db48f2dba9 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("wangyuanchao packageStats is invalid"); + 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/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_core.cpp b/services/common/src/bundle_active_core.cpp index 5f09345ebfd4174517bbd07d0b47d6d3450f5fe7..6b7e3120c48ffb7d9980004467af8bcdbe19a253 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 (uint32_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..1532f330f242c7ac0046933b1a6dbdaad8db796d 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,12 @@ 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..03d42abe9db56e0019b62ab8e60372713b24e7f5 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..3b715cd1261e39a39eb4c91e6267e4380921e534 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); @@ -704,12 +704,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,9 +865,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 (int32_t i = static_cast(sortedTableArray_.size() - 1); i >= 0; i--) { int32_t index = NearIndexOnOrBeforeCurrentTime(beginTime, sortedTableArray_.at(i)); - int32_t size = sortedTableArray_.at(i).size(); + int32_t size = static_cast(sortedTableArray_.at(i).size()); if (index >= 0 && index < size) { int64_t diff = abs(sortedTableArray_.at(i).at(index) - beginTime); if (diff < leastTimeDiff) { @@ -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 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..946582a2b04e30078ab914b0ff4ceb772257d978 100644 --- a/services/packagegroup/include/bundle_active_group_handler.h +++ b/services/packagegroup/include/bundle_active_group_handler.h @@ -27,8 +27,8 @@ namespace OHOS { namespace DeviceUsageStats { class BundleActiveGroupHandlerObject { public: - std::string bundleName_; - int userId_; + std::string bundleName_ = ""; + int userId_ = -1; BundleActiveGroupHandlerObject() {}; 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_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..92a203cee0ee92502c952d66b336684068f9f2db 100644 --- a/services/packageusage/src/bundle_active_event.cpp +++ b/services/packageusage/src/bundle_active_event.cpp @@ -61,11 +61,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_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..bde22bc73fa3ada9a92550c95eb21a7bea42f516 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; }