From 0f3b347ed5d966b6a2bfaac016eaec5df3f2a901 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 15 Mar 2022 22:07:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E6=84=8F=E8=A7=81=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 --- frameworks/src/bundle_state_query.cpp | 9 +-------- .../src/bundle_active_continuous_task_observer.cpp | 1 - services/common/src/bundle_active_core.cpp | 9 +++++++-- test/unittest/device_usage_statistics_test.cpp | 2 +- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index b9218b9..13fdb07 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -96,7 +96,6 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) asyncCallbackInfo->state = BundleActiveClient::GetInstance().IsBundleIdle( asyncCallbackInfo->bundleName); } else { - asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; BUNDLE_ACTIVE_LOGE("IsIdleState, asyncCallbackInfo == nullptr"); } }, @@ -168,7 +167,6 @@ napi_value QueryAppUsagePriorityGroup(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { asyncCallbackInfo->priorityGroup = BundleActiveClient::GetInstance().QueryPackageGroup(); } else { - asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; BUNDLE_ACTIVE_LOGE("QueryAppUsagePriorityGroup, asyncCallbackInfo == nullptr"); } }, @@ -203,7 +201,6 @@ napi_value ParseStatesParameters(const napi_env &env, const napi_callback_info & NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); NAPI_ASSERT(env, argc == STATES_MIN_PARAMS || argc == STATES_PARAMS, "Invalid number of parameters"); - // argv[0] : beginTime if (BundleStateCommon::GetInt64NumberValue(env, argv[0], params.beginTime) == nullptr) { BUNDLE_ACTIVE_LOGE("ParseStatesParameters failed, beginTime type is invalid."); @@ -278,7 +275,6 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) BundleActiveClient::GetInstance().QueryCurrentEvents(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime); } else { - asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; BUNDLE_ACTIVE_LOGE("QueryCurrentBundleActiveStates, asyncCallbackInfo == nullptr"); } }, @@ -345,7 +341,6 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) BundleActiveClient::GetInstance().QueryEvents(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime); } else { - asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; BUNDLE_ACTIVE_LOGE("QueryBundleActiveStates, asyncCallbackInfo == nullptr"); } }, @@ -470,7 +465,6 @@ napi_value QueryBundleStateInfoByInterval(napi_env env, napi_callback_info info) BundleActiveClient::GetInstance().QueryPackageStats(asyncCallbackInfo->intervalType, asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime); } else { - asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; BUNDLE_ACTIVE_LOGE("QueryBundleStateInfoByInterval, asyncCallbackInfo == nullptr"); } }, @@ -508,7 +502,7 @@ napi_value ParseAppUsageParameters(const napi_env &env, const napi_callback_info NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL)); NAPI_ASSERT(env, argc == APP_USAGE_MIN_PARAMS || argc == APP_USAGE_PARAMS, "Invalid number of parameters"); - + // argv[0] : beginTime if (BundleStateCommon::GetInt64NumberValue(env, argv[0], params.beginTime) == nullptr) { BUNDLE_ACTIVE_LOGE("ParseAppUsageParameters failed, beginTime type is invalid."); @@ -580,7 +574,6 @@ napi_value QueryBundleStateInfos(napi_env env, napi_callback_info info) asyncCallbackInfo->packageStats = BundleStateCommon::GetPackageStats(asyncCallbackInfo->beginTime, asyncCallbackInfo->endTime); } else { - asyncCallbackInfo->info.errorCode = ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR; BUNDLE_ACTIVE_LOGE("QueryBundleStateInfos asyncCallbackInfo == nullptr"); } }, diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index a64c720..157f121 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -87,7 +87,6 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( } OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); if (ret == ERR_OK && userId != -1 && !bundleName.empty()) { - std::stringstream stream; BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); tmpHandlerObject.event_.bundleName_ = bundleName; tmpHandlerObject.event_.abilityName_ = ""; diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index c5467ed..815c9db 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -109,8 +109,7 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da std::make_shared(tmpHandlerObject); auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_BUNDLE_UNINSTALLED, handlerobjToPtr); - bundleActiveReportHandler_.lock()->SendEvent(BundleActiveReportHandler::MSG_BUNDLE_UNINSTALLED, - handlerobjToPtr); + bundleActiveReportHandler_.lock()->SendEvent(event); } } } @@ -167,6 +166,8 @@ void BundleActiveCore::InitBundleGroupController() bundleGroupHandler_->Init(bundleGroupController_); bundleGroupController_->SetHandlerAndCreateUserHistory(bundleGroupHandler_, realTimeShot_); BUNDLE_ACTIVE_LOGI("Init Set group controller and handler done"); + } else { + return; } RegisterSubscriber(); std::vector activatedOsAccountIds; @@ -195,6 +196,9 @@ std::shared_ptr BundleActiveCore::GetUserDataAndInitial BUNDLE_ACTIVE_LOGI("first initialize user service"); std::shared_ptr service = std::make_shared(userId, *this, debug); + if (service == nullptr) { + return nullptr; + } service->Init(timeStamp); userStatServices_[userId] = service; if (service == nullptr) { @@ -244,6 +248,7 @@ void BundleActiveCore::RestoreAllData() std::shared_ptr service = it->second; if (service == nullptr) { BUNDLE_ACTIVE_LOGI("service in BundleActiveCore::RestoreToDatabaseLocked() is null"); + return; } BUNDLE_ACTIVE_LOGI("userid is %{public}d ", service->userId_); service->RestoreStats(true); diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 693799d..5fce198 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -34,7 +34,7 @@ static std::string DEFAULT_BUNDLENAME = "com.ohos.camera"; static std::string DEFAULT_ABILITYID = "1234"; static std::string DEFAULT_ABILITYNAME = "testability"; static int DEFAULT_USERID = 0; -static int LARGE_NUM = LARGE_NUM; +static int LARGE_NUM = 20000000000000; class DeviceUsageStatisticsTest : public testing::Test { public: -- Gitee From 523adfa62f1d7651658c3f14991c6ff6e5ff2231 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 15 Mar 2022 22:28:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=89=AB=E6=8F=8F?= =?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 --- test/unittest/device_usage_statistics_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 5fce198..af96e16 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -34,7 +34,7 @@ static std::string DEFAULT_BUNDLENAME = "com.ohos.camera"; static std::string DEFAULT_ABILITYID = "1234"; static std::string DEFAULT_ABILITYNAME = "testability"; static int DEFAULT_USERID = 0; -static int LARGE_NUM = 20000000000000; +static int64_t LARGE_NUM = 20000000000000; class DeviceUsageStatisticsTest : public testing::Test { public: -- Gitee From fd52b9a508c4a2344b7699d87857113764cb9b0c Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 15 Mar 2022 22:50:01 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=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/common/src/bundle_active_core.cpp | 4 +--- services/common/src/bundle_active_service.cpp | 3 +-- services/common/src/bundle_active_usage_database.cpp | 4 +--- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index 815c9db..ad83e21 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -69,7 +69,6 @@ void BundleActiveCommonEventSubscriber::OnReceiveEvent(const CommonEventData &da std::lock_guard lock(mutex_); std::string action = data.GetWant().GetAction(); BUNDLE_ACTIVE_LOGI("OnReceiveEvent action is %{public}s", action.c_str()); - auto want = data.GetWant(); if (action == CommonEventSupport::COMMON_EVENT_SCREEN_OFF || action == CommonEventSupport::COMMON_EVENT_SCREEN_ON) { if (!activeGroupController_.expired()) { @@ -459,8 +458,7 @@ int BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event) return -1; } if (userStatServices_.empty()) { - std::shared_ptr service = GetUserDataAndInitializeIfNeeded(DEFAULT_USER_ID, timeNow, - debugCore_); + return DEFAULT_USER_ID; } for (std::map>::iterator it = userStatServices_.begin(); it != userStatServices_.end(); it++) { diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 652450d..065fe97 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -75,8 +75,7 @@ void BundleActiveService::InitNecessaryState() return; } - if (systemAbilityManager == nullptr - || systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID) == nullptr + if (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 diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 2ade1f2..277adb3 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -375,8 +375,8 @@ int32_t BundleActiveUsageDatabase::DeleteInvalidTable(unsigned int databaseType, int64_t BundleActiveUsageDatabase::ParseStartTime(const string &tableName) { - int64_t invalidStartTime(BUNDLE_ACTIVE_FAIL); if (tableName.empty()) { + int64_t invalidStartTime(BUNDLE_ACTIVE_FAIL); return invalidStartTime; } string tableTime = tableName; @@ -984,7 +984,6 @@ void BundleActiveUsageDatabase::RemoveOldData(int64_t currentTime) void BundleActiveUsageDatabase::RenewTableTime(int64_t changedTime) { lock_guard lock(databaseMutex_); - string logInfo; for (unsigned int i = 0; i < sortedTableArray_.size(); i++) { if (sortedTableArray_.at(i).empty()) { continue; @@ -1187,7 +1186,6 @@ vector BundleActiveUsageDatabase::QueryDatabaseEvents(int64_t int32_t tableRowNumber; bundleActiveResult->GetRowCount(tableRowNumber); BundleActiveEvent event; - string timeStamp; string relativeTimeStamp; for (int32_t i = 0; i < tableRowNumber; i++) { bundleActiveResult->GoToRow(i); -- Gitee