From 7ddf50aec23e855bb6d063bb2022f6ed49aee2fd Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 26 May 2022 15:05:41 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9BundleActiveUserService?= =?UTF-8?q?=E4=B8=ADlistener=5F=E5=AE=9A=E4=B9=89=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_core.h | 2 +- services/common/src/bundle_active_core.cpp | 2 +- .../include/bundle_active_user_service.h | 4 ++-- .../packageusage/src/bundle_active_user_service.cpp | 12 +++++++++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 3c861ce..a955ed1 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -46,7 +46,7 @@ public: class BundleActiveReportHandler; -class BundleActiveCore : public BundleActiveStatsUpdateListener { +class BundleActiveCore : public BundleActiveStatsUpdateListener, public std::enable_shared_from_this{ public: BundleActiveCore(); virtual ~BundleActiveCore(); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 15dcdc5..f9ee8ca 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -194,7 +194,7 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial std::map>::iterator it = userStatServices_.find(userId); if (it == userStatServices_.end()) { BUNDLE_ACTIVE_LOGI("first initialize user service"); - std::shared_ptr service = std::make_shared(userId, *this, + std::shared_ptr service = std::make_shared(userId, shared_from_this(), debug); if (service == nullptr) { return nullptr; diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h index cb56fc9..e2692bd 100644 --- a/services/packageusage/include/bundle_active_user_service.h +++ b/services/packageusage/include/bundle_active_user_service.h @@ -35,7 +35,7 @@ class BundleActiveCore; class BundleActiveUserService { public: BundleActiveUserService() = delete; - BundleActiveUserService(const int32_t userId, BundleActiveCore& listener, const bool debug):listener_(listener) + BundleActiveUserService(const int32_t userId, std::shared_ptr listener, const bool debug):listener_(listener) { for (int32_t i = 0; i < BundleActivePeriodStats::PERIOD_COUNT; i++) { currentStats_.push_back(nullptr); @@ -82,7 +82,7 @@ private: bool statsChanged_; bool debugUserService_; std::string lastForegroundBundle_; - BundleActiveCore& listener_; + std::weak_ptr listener_; std::vector periodLength_ = {0, 0, 0, 0}; void NotifyStatsChanged(); void NotifyNewUpdate(); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index c79f1d6..d032480 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -85,13 +85,17 @@ void BundleActiveUserService::NotifyStatsChanged() if (!statsChanged_) { BUNDLE_ACTIVE_LOGI("NotifyStatsChanged() set stats changed to true"); statsChanged_ = true; - listener_.OnStatsChanged(userId_); + if (!listener_.expired()) { + listener_.lock()->OnStatsChanged(userId_); + } } } void BundleActiveUserService::NotifyNewUpdate() { - listener_.OnSystemUpdate(userId_); + if (!listener_.expired()) { + listener_.lock()->OnSystemUpdate(userId_); + } } void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) @@ -237,7 +241,9 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo if (!timeChanged) { dailyExpiryDate_.TruncateToDay(); } - listener_.OnStatsReload(); + if (!listener_.expired()) { + listener_.lock()->CheckTimeChangeAndGetWallTime(); + } BUNDLE_ACTIVE_LOGI("LoadActiveStats current expire time is %{public}lld, " "begin time is %{public}lld", (long long)dailyExpiryDate_.GetMilliseconds(), (long long)tmpCalendar.GetMilliseconds()); -- Gitee From d6aef41649d915a87546bdbd7209e853d52dbace Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 26 May 2022 15:24:50 +0800 Subject: [PATCH 2/4] CODEX Signed-off-by: houdisheng --- services/common/include/bundle_active_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index a955ed1..32758b0 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -46,7 +46,7 @@ public: class BundleActiveReportHandler; -class BundleActiveCore : public BundleActiveStatsUpdateListener, public std::enable_shared_from_this{ +class BundleActiveCore : public BundleActiveStatsUpdateListener, public std::enable_shared_from_this { public: BundleActiveCore(); virtual ~BundleActiveCore(); -- Gitee From 22897186a413f1330aac8708bb1a04df07541497 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 26 May 2022 21:01:19 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=85=B3=E9=97=ADdb=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_constant.h | 2 +- services/common/include/bundle_active_core.h | 2 +- services/common/src/bundle_active_core.cpp | 2 +- .../include/bundle_active_user_service.h | 4 ++-- .../packageusage/src/bundle_active_user_service.cpp | 12 +++--------- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index 82bf37e..35c5dd6 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -126,7 +126,7 @@ const std::string BUNDLE_ACTIVE_VERSION_FILE = "/version"; const std::string DATABASE_FILE_TABLE_NAME = "table"; const std::string SQLITE_MASTER_NAME = "name"; const std::string DATABASE_TYPE[] = {"daily", "weekly", "monthly", "yearly", "event", "usageGroup"}; -const std::string SUFFIX_TYPE[] = {".db", ".db-shm", ".db-wal"}; +const std::string SUFFIX_TYPE[] = {".db"}; } // namespace DeviceUsageStats } // namespace OHOS #endif // BUNDLE_ACTIVE_CONSTANT_H diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 32758b0..3c861ce 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -46,7 +46,7 @@ public: class BundleActiveReportHandler; -class BundleActiveCore : public BundleActiveStatsUpdateListener, public std::enable_shared_from_this { +class BundleActiveCore : public BundleActiveStatsUpdateListener { public: BundleActiveCore(); virtual ~BundleActiveCore(); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index f9ee8ca..15dcdc5 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -194,7 +194,7 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial std::map>::iterator it = userStatServices_.find(userId); if (it == userStatServices_.end()) { BUNDLE_ACTIVE_LOGI("first initialize user service"); - std::shared_ptr service = std::make_shared(userId, shared_from_this(), + std::shared_ptr service = std::make_shared(userId, *this, debug); if (service == nullptr) { return nullptr; diff --git a/services/packageusage/include/bundle_active_user_service.h b/services/packageusage/include/bundle_active_user_service.h index e2692bd..cb56fc9 100644 --- a/services/packageusage/include/bundle_active_user_service.h +++ b/services/packageusage/include/bundle_active_user_service.h @@ -35,7 +35,7 @@ class BundleActiveCore; class BundleActiveUserService { public: BundleActiveUserService() = delete; - BundleActiveUserService(const int32_t userId, std::shared_ptr listener, const bool debug):listener_(listener) + BundleActiveUserService(const int32_t userId, BundleActiveCore& listener, const bool debug):listener_(listener) { for (int32_t i = 0; i < BundleActivePeriodStats::PERIOD_COUNT; i++) { currentStats_.push_back(nullptr); @@ -82,7 +82,7 @@ private: bool statsChanged_; bool debugUserService_; std::string lastForegroundBundle_; - std::weak_ptr listener_; + BundleActiveCore& listener_; std::vector periodLength_ = {0, 0, 0, 0}; void NotifyStatsChanged(); void NotifyNewUpdate(); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index d032480..4b4e5f4 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -85,17 +85,13 @@ void BundleActiveUserService::NotifyStatsChanged() if (!statsChanged_) { BUNDLE_ACTIVE_LOGI("NotifyStatsChanged() set stats changed to true"); statsChanged_ = true; - if (!listener_.expired()) { - listener_.lock()->OnStatsChanged(userId_); - } + listener_.OnStatsChanged(userId_); } } void BundleActiveUserService::NotifyNewUpdate() { - if (!listener_.expired()) { - listener_.lock()->OnSystemUpdate(userId_); - } + listener_.OnSystemUpdate(userId_); } void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) @@ -241,9 +237,7 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo if (!timeChanged) { dailyExpiryDate_.TruncateToDay(); } - if (!listener_.expired()) { - listener_.lock()->CheckTimeChangeAndGetWallTime(); - } + listener_.CheckTimeChangeAndGetWallTime(); BUNDLE_ACTIVE_LOGI("LoadActiveStats current expire time is %{public}lld, " "begin time is %{public}lld", (long long)dailyExpiryDate_.GetMilliseconds(), (long long)tmpCalendar.GetMilliseconds()); -- Gitee From 12c7a67132b20ad14d0027eb41ce30d776fa294a Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 26 May 2022 21:08:01 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=85=B3=E9=97=ADdb=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_usage_database.cpp | 1 + services/packageusage/src/bundle_active_user_service.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 2195f2e..d41f9d2 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -414,6 +414,7 @@ shared_ptr BundleActiveUsageDatabase::GetBundleActiveRdbSto string currDatabaseFileConfig = BUNDLE_ACTIVE_DATABASE_DIR + databaseFiles_.at(databaseType); RdbStoreConfig config(currDatabaseFileConfig); BundleActiveOpenCallback rdbDataCallBack; + config.SetJournalMode(NativeRdb::JournalMode::MODE_OFF); rdbStore = RdbHelper::GetRdbStore(config, BUNDLE_ACTIVE_RDB_VERSION, rdbDataCallBack, errCode); if ((rdbStore == nullptr)) { BUNDLE_ACTIVE_LOGE("rdbStore is nullptr"); diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 4b4e5f4..c79f1d6 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -237,7 +237,7 @@ void BundleActiveUserService::LoadActiveStats(const int64_t timeStamp, const boo if (!timeChanged) { dailyExpiryDate_.TruncateToDay(); } - listener_.CheckTimeChangeAndGetWallTime(); + listener_.OnStatsReload(); BUNDLE_ACTIVE_LOGI("LoadActiveStats current expire time is %{public}lld, " "begin time is %{public}lld", (long long)dailyExpiryDate_.GetMilliseconds(), (long long)tmpCalendar.GetMilliseconds()); -- Gitee