From a16113db12d789cd5caae4312f6151dc37ee1d71 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 11:33:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?codex=EF=BC=8C=E5=86=85=E6=BA=90issue?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/src/bundle_active_client.cpp | 6 +++--- services/common/src/bundle_active_binary_search.cpp | 3 ++- services/common/src/bundle_active_service.cpp | 2 +- .../packagegroup/include/bundle_active_group_controller.h | 2 +- .../packagegroup/src/bundle_active_group_controller.cpp | 2 +- services/packagegroup/src/bundle_active_user_history.cpp | 1 + services/packageusage/src/bundle_active_event_stats.cpp | 1 + 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 1487c37..6a3f282 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -27,19 +27,19 @@ BundleActiveClient& BundleActiveClient::GetInstance() bool BundleActiveClient::GetBundleActiveProxy() { sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { + if (!samgr) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager."); return false; } sptr object = samgr->GetSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID); - if (object == nullptr) { + if (!object) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbility[1920] ."); return false; } bundleActiveProxy_ = iface_cast(object); - if (bundleActiveProxy_ == nullptr) { + if (!bundleActiveProxy_) { BUNDLE_ACTIVE_LOGE("Failed to get BundleActiveClient."); return false; } diff --git a/services/common/src/bundle_active_binary_search.cpp b/services/common/src/bundle_active_binary_search.cpp index f16cf93..28ce020 100644 --- a/services/common/src/bundle_active_binary_search.cpp +++ b/services/common/src/bundle_active_binary_search.cpp @@ -30,8 +30,9 @@ int32_t BundleActiveBinarySearch::BinarySearch(const std::vector &table { int32_t low = 0; int32_t high = static_cast(tableNameArray.size() - 1); + int32_t divider = 2; while (low <= high) { - int32_t mid = (low + high) >> 1; + int32_t mid = (low + high) / divider; int64_t midValue = tableNameArray.at(mid); if (midValue < targetValue) { low = mid + 1; diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 09eb93d..7853b3b 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -100,7 +100,7 @@ void BundleActiveService::InitNecessaryState() } try { shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); - } catch(const std::bad_alloc &e) { + } catch (const std::bad_alloc &e) { BUNDLE_ACTIVE_LOGE("Memory allocation failed"); return; } diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index 6763202..a5d57b3 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -94,7 +94,7 @@ private: int64_t timeoutForDirectlyUse_ = debug_ ? THREE_MINUTE : ONE_HOUR; int64_t timeoutForNotifySeen_ = debug_ ? ONE_MINUTE : TWELVE_HOUR; int64_t timeoutForSystemInteraction_ = debug_ ? ONE_MINUTE : TEN_MINUTE; - int64_t timeoutCalculated_; + int64_t timeoutCalculated_ = 0; sptr sptrBundleMgr_; bool calculationTimeOut(const std::shared_ptr& oneBundleHistory, const int64_t bootBasedTimeStamp); diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 519311f..82062ab 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -221,7 +221,7 @@ void BundleActiveGroupController::ReportEvent(const BundleActiveEvent& event, co return; } int64_t timeUntilNextCheck; - int eventReason = EventToGroupReason(eventId); + uint32_t eventReason = EventToGroupReason(eventId); switch (eventId) { case BundleActiveEvent::NOTIFICATION_SEEN: bundleUserHistory_->ReportUsage(bundleUsageHistory, event.bundleName_, ACTIVE_GROUP_DAILY, diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 5179f8f..599907d 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -31,6 +31,7 @@ BundleActivePackageHistory::BundleActivePackageHistory() reasonInGroup_ = DeviceUsageStatsGroupConst::GROUP_CONTROL_REASON_DEFAULT; bundleAliveTimeoutTimeStamp_ = 0; bundleDailyTimeoutTimeStamp_ = 0; + lastCalculatedGroup_ = 60; }; void BundleActiveUserHistory::WriteDeviceDuration() diff --git a/services/packageusage/src/bundle_active_event_stats.cpp b/services/packageusage/src/bundle_active_event_stats.cpp index 4dfa187..3bb55e0 100644 --- a/services/packageusage/src/bundle_active_event_stats.cpp +++ b/services/packageusage/src/bundle_active_event_stats.cpp @@ -19,6 +19,7 @@ namespace OHOS { namespace DeviceUsageStats { BundleActiveEventStats::BundleActiveEventStats() { + eventId_ = 0; beginTimeStamp_ = 0; endTimeStamp_ = 0; lastEventTime_ = 0; -- Gitee From 564e5bc0bd99d9c13eb308b3aa8477168f033225 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 8 Mar 2022 15:36:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?codex=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/packagegroup/src/bundle_active_user_history.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 599907d..5055d7c 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -31,7 +31,7 @@ BundleActivePackageHistory::BundleActivePackageHistory() reasonInGroup_ = DeviceUsageStatsGroupConst::GROUP_CONTROL_REASON_DEFAULT; bundleAliveTimeoutTimeStamp_ = 0; bundleDailyTimeoutTimeStamp_ = 0; - lastCalculatedGroup_ = 60; + lastCalculatedGroup_ = ACTIVE_GROUP_NEVER; }; void BundleActiveUserHistory::WriteDeviceDuration() -- Gitee