diff --git a/BUILD.gn b/BUILD.gn index cf37d4bd1a33e1a6aee7b57d512f276d010cdd1d..9505c9170614822f71b5eba1cb59679401a5579f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -34,7 +34,6 @@ ohos_shared_library("usagestatsinner") { ] external_deps = [ - "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", @@ -74,7 +73,6 @@ ohos_shared_library("bundlestate") { ] external_deps = [ - "dmsfwk_standard:zuri", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "napi:ace_napi", @@ -131,7 +129,6 @@ ohos_shared_library("usagestatservice") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "ces_standard:cesfwk_innerkits", - "dmsfwk_standard:zuri", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/bundle.json b/bundle.json index 374597e52cc4435e876404cd38dacbab31eeec8f..8dbbd215bd8531f6661b327d82152234da0206f7 100644 --- a/bundle.json +++ b/bundle.json @@ -31,7 +31,6 @@ "want", "appexecfwk_base", "appexecfwk_core", - "zuri", "base", "time_service", "utils", diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index c0ec21705dda6664982e55965135d2de37b46d7f..64732cd3c9821fb31fe4ed3e05aab679850bd786 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -66,6 +66,7 @@ private: std::shared_ptr handler_; int ConvertIntervalType(const int intervalType); void InitNecessaryState(); + void InitService(); bool GetBundleMgrProxy(); bool CheckBundleIsSystemAppAndHasPermission(const int uid, const int userId); void InitAppStateSubscriber(const std::shared_ptr& reportHandler); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 052dbfa1ca15365cff9b53b0e25a00da6f6060d1..7e9ff8823a00a2fa74cc6f96386e9f3be4432850 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -218,13 +218,16 @@ void BundleActiveCore::OnBundleUninstalled(const int userId, const std::string& void BundleActiveCore::OnStatsChanged(const int userId) { if (!handler_.expired()) { - BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event"); BundleActiveReportHandlerObject tmpHandlerObject; tmpHandlerObject.userId_ = userId; std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_FLUSH_TO_DISK, handlerobjToPtr); - handler_.lock()->SendEvent(event, FLUSH_INTERVAL); + if (handler_.lock()->HasInnerEvent(static_cast(BundleActiveReportHandler::MSG_FLUSH_TO_DISK)) == + false) { + BUNDLE_ACTIVE_LOGI("OnStatsChanged send flush to disk event"); + handler_.lock()->SendEvent(event, FLUSH_INTERVAL); + } } } diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 5673785421e299a36ff49797cf9b9bf2ae609f5e..652450d2660e25558d3dded3810a6e88302fb732 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -75,6 +75,24 @@ void BundleActiveService::InitNecessaryState() return; } + if (systemAbilityManager == nullptr + || systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) == nullptr + || systemAbilityManager->GetSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(COMMON_EVENT_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(TIME_SERVICE_ID) == nullptr) { + BUNDLE_ACTIVE_LOGI("request system service object is not ready yet!"); + auto task = [this]() { this->InitNecessaryState(); }; + handler_->PostTask(task, DELAY_TIME); + return; + } + + InitService(); +} + +void BundleActiveService::InitService() +{ if (bundleActiveCore_ == nullptr) { bundleActiveCore_ = std::make_shared(); bundleActiveCore_->Init(); @@ -118,6 +136,9 @@ OHOS::sptr BundleActiveService::GetAppManagerInstance OHOS::sptr systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); OHOS::sptr object = systemAbilityManager->GetSystemAbility(OHOS::APP_MGR_SERVICE_ID); + if (!object) { + return nullptr; + } return OHOS::iface_cast(object); } @@ -141,7 +162,7 @@ bool BundleActiveService::SubscribeAppState() { BUNDLE_ACTIVE_LOGI("SubscribeAppState called"); sptr appManager = GetAppManagerInstance(); - if (appStateObserver_ == nullptr) { + if (appStateObserver_ == nullptr || appManager == nullptr) { BUNDLE_ACTIVE_LOGE("SubscribeAppState appstateobserver is null, return"); return false; } diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 091dd41dadd939af3b843a0086f2e9784f3aec52..4433bcc69d9d1c9875ee86288519ee5e634d265f 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -552,8 +552,11 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId, int64_t outRowId = BUNDLE_ACTIVE_FAIL; NativeRdb::ValuesBucket valuesBucket; vector queryCondition; + int updatedcount = 0; + int unupdatedcount = 0; for (auto iter = userHistory->begin(); iter != userHistory->end(); iter++) { - if (iter->second == nullptr) { + if (iter->second == nullptr || !iter->second->isChanged_) { + unupdatedcount++; continue; } queryCondition.push_back(to_string(userId)); @@ -576,7 +579,11 @@ void BundleActiveUsageDatabase::PutBundleHistoryData(int userId, } valuesBucket.Clear(); queryCondition.clear(); + iter->second->isChanged_ = false; + updatedcount++; } + BUNDLE_ACTIVE_LOGI("PutBundleHistoryData, update %{public}d bundles, keep %{public}d bundles group", + updatedcount, unupdatedcount); } shared_ptr>> BundleActiveUsageDatabase::GetBundleHistoryData( diff --git a/services/packagegroup/include/bundle_active_package_history.h b/services/packagegroup/include/bundle_active_package_history.h index ff25c7ab9e91bb052944f4f20fb0952802229060..bfced5544d64252cdde0e666702413a16f2f3ad4 100644 --- a/services/packagegroup/include/bundle_active_package_history.h +++ b/services/packagegroup/include/bundle_active_package_history.h @@ -30,6 +30,7 @@ public: uint32_t reasonInGroup_; int64_t bundleAliveTimeoutTimeStamp_; int64_t bundleDailyTimeoutTimeStamp_; + bool isChanged_; BundleActivePackageHistory(); ~BundleActivePackageHistory() {}; }; diff --git a/services/packagegroup/src/bundle_active_user_history.cpp b/services/packagegroup/src/bundle_active_user_history.cpp index 5055d7c98215092d044b26f98b7b933bd01285f5..255cc49994c17fd7a67522df6a5e1ad36012e1ee 100644 --- a/services/packagegroup/src/bundle_active_user_history.cpp +++ b/services/packagegroup/src/bundle_active_user_history.cpp @@ -32,6 +32,7 @@ BundleActivePackageHistory::BundleActivePackageHistory() bundleAliveTimeoutTimeStamp_ = 0; bundleDailyTimeoutTimeStamp_ = 0; lastCalculatedGroup_ = ACTIVE_GROUP_NEVER; + isChanged_ = false; }; void BundleActiveUserHistory::WriteDeviceDuration() @@ -202,6 +203,7 @@ void BundleActiveUserHistory::SetBundleGroup(const string& bundleName, const int oneBundleHistory->bundleAliveTimeoutTimeStamp_ = setTimeStamp; oneBundleHistory->bundleDailyTimeoutTimeStamp_ = setTimeStamp; } + oneBundleHistory->isChanged_ = true; } void BundleActiveUserHistory::UpdateBootBasedAndScreenTime(const bool& isScreenOn, const int64_t bootBasedTimeStamp,