From 6539afbbef305838e4e3aeb433c796d302aff28e Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 28 May 2024 11:00:30 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BC=98=E5=8C=96isLauncherApp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- BUILD.gn | 8 + bundle.json | 1 + .../include/bundle_active_bundle_mgr_helper.h | 7 +- .../include/device_usage_oobe_manager.h | 50 ++++++ .../src/bundle_active_bundle_mgr_helper.cpp | 44 ++++- .../common/src/device_usage_oobe_manager.cpp | 119 ++++++++++++++ utils/include/device_usage_data_share_utils.h | 47 ++++++ utils/src/device_usage_data_share_utils.cpp | 152 ++++++++++++++++++ 8 files changed, 421 insertions(+), 7 deletions(-) create mode 100644 services/common/include/device_usage_oobe_manager.h create mode 100644 services/common/src/device_usage_oobe_manager.cpp create mode 100644 utils/include/device_usage_data_share_utils.h create mode 100644 utils/src/device_usage_data_share_utils.cpp diff --git a/BUILD.gn b/BUILD.gn index 88c0693..120f931 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -175,6 +175,7 @@ ohos_shared_library("usagestatservice") { "services/common/src/bundle_active_shutdown_callback_service.cpp", "services/common/src/bundle_active_stub.cpp", "services/common/src/bundle_active_usage_database.cpp", + "services/common/src/device_usage_oobe_manager.cpp", "services/packagegroup/src/bundle_active_group_controller.cpp", "services/packagegroup/src/bundle_active_group_handler.cpp", "services/packagegroup/src/bundle_active_user_history.cpp", @@ -185,6 +186,7 @@ ohos_shared_library("usagestatservice") { "services/packageusage/src/bundle_active_report_handler.cpp", "services/packageusage/src/bundle_active_stats_combiner.cpp", "services/packageusage/src/bundle_active_user_service.cpp", + "utils/src/device_usage_share_utils.cpp", ] public_configs = [ ":usagestats_public_config" ] @@ -195,6 +197,7 @@ ohos_shared_library("usagestatservice") { external_deps = [ "ability_base:want", + "ability_base:zuri", "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", @@ -203,6 +206,7 @@ ohos_shared_library("usagestatservice") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "data_share:datashare_consumer", "eventhandler:libeventhandler", "hilog:libhilog", "init:libbegetutil", @@ -257,6 +261,7 @@ ohos_static_library("usagestatservice_static") { "services/common/src/bundle_active_shutdown_callback_service.cpp", "services/common/src/bundle_active_stub.cpp", "services/common/src/bundle_active_usage_database.cpp", + "services/common/src/device_usage_oobe_manager.cpp", "services/packagegroup/src/bundle_active_group_controller.cpp", "services/packagegroup/src/bundle_active_group_handler.cpp", "services/packagegroup/src/bundle_active_user_history.cpp", @@ -267,6 +272,7 @@ ohos_static_library("usagestatservice_static") { "services/packageusage/src/bundle_active_report_handler.cpp", "services/packageusage/src/bundle_active_stats_combiner.cpp", "services/packageusage/src/bundle_active_user_service.cpp", + "utils/src/device_usage_share_utils.cpp", ] public_configs = [ ":usagestats_public_config" ] @@ -277,6 +283,7 @@ ohos_static_library("usagestatservice_static") { external_deps = [ "ability_base:want", + "ability_base:zuri", "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", @@ -285,6 +292,7 @@ ohos_static_library("usagestatservice_static") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "data_share:datashare_consumer", "eventhandler:libeventhandler", "hilog:libhilog", "init:libbegetutil", diff --git a/bundle.json b/bundle.json index 60166dd..e7b7105 100644 --- a/bundle.json +++ b/bundle.json @@ -24,6 +24,7 @@ "deps": { "components": [ "bundle_framework", + "data_share", "relational_store", "safwk", "common_event_service", diff --git a/services/common/include/bundle_active_bundle_mgr_helper.h b/services/common/include/bundle_active_bundle_mgr_helper.h index fcebdd7..731f75d 100644 --- a/services/common/include/bundle_active_bundle_mgr_helper.h +++ b/services/common/include/bundle_active_bundle_mgr_helper.h @@ -57,14 +57,19 @@ public: */ bool GetApplicationInfo(const std::string &appName, const AppExecFwk::ApplicationFlag flag, const int userId, AppExecFwk::ApplicationInfo &appInfo); + + bool GetApplicationInfos(const AppExecFwk::ApplicationFlag flag, + const int userId, std::vector &appInfos); bool IsLauncherApp(const std::string &bundleName, const int32_t userId); + void InitLauncherAppMap(); + private: bool Connect(); private: - std::unordered_set launcherAppSet_; + std::map launcherAppMap_; sptr bundleMgr_ = nullptr; std::mutex connectionMutex_; DECLARE_DELAYED_SINGLETON(BundleActiveBundleMgrHelper); diff --git a/services/common/include/device_usage_oobe_manager.h b/services/common/include/device_usage_oobe_manager.h new file mode 100644 index 0000000..a15623f --- /dev/null +++ b/services/common/include/device_usage_oobe_manager.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVICE_USAGE_OOBE_MANAGER_H +#define DEVICE_USAGE_OOBE_MANAGER_H + +#include "data_ability_observer_stub.h" +#include "errors.h" +#include "mutex" +#include + +namespace OHOS { +namespace DeviceUsageStats { +class DeviceUsageOOBEManager { +public: + static DeviceUsageOOBEManager& GetInstance(); + ErrCode UnregisterObserver(); + bool GetOOBValue(); + void Init(); + +private: + class BundleActiveDataShareObserver : public AAFwk::DataAbilityObserverStub { + public: + BundleActiveDataShareObserver() = default; + ~BundleActiveDataShareObserver() = default; + void OnChange() override; + }; + + bool g_oobeValue = false; + static std::mutex mutex_; + static sptr observer_; + DeviceUsageOOBEManager(); + ~DeviceUsageOOBEManager(); + ErrCode RegisterObserver(); +}; +} // namespace DeviceUsageStats +} // namespace OHOS +#endif // DEVICE_USAGE_OOBE_MANAGER \ No newline at end of file diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index 4ec9f9a..5ea8a01 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -32,6 +32,7 @@ BundleActiveBundleMgrHelper::BundleActiveBundleMgrHelper() BundleActiveBundleMgrHelper::~BundleActiveBundleMgrHelper() { + launcherAppMap_.clear(); } void BundleActiveBundleMgrHelper::GetNameForUid(int32_t uid, std::string& bundleName) @@ -63,6 +64,22 @@ bool BundleActiveBundleMgrHelper::GetApplicationInfo(const std::string &appName, return false; } +bool BundleActiveBundleMgrHelper::GetApplicationInfos(const AppExecFwk::ApplicationFlag flag, + const int userId, std::vector &appInfos) +{ + BUNDLE_ACTIVE_LOGD("start get application infos"); + std::lock_guard lock(connectionMutex_); + + if (!Connect()) { + return false; + } + BUNDLE_ACTIVE_LOGD("bundleMgr is null: %{public}d ", bundleMgr_ == nullptr); + if (bundleMgr_ != nullptr && bundleMgr_->GetApplicationInfos(flag, userId, appInfos)) { + return true; + } + return false; +} + bool BundleActiveBundleMgrHelper::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, AppExecFwk::BundleInfo &bundleInfo, int32_t userId) { @@ -102,8 +119,14 @@ bool BundleActiveBundleMgrHelper::Connect() bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, const int32_t userId) { - if (launcherAppSet_.find(bundleName) != launcherAppSet_.end()) { - return true; + if (!DeviceUsageOOBEManager::GetInstance().GetOOBEValue()) { + BUNDLE_ACTIVE_LOGD("not agree obtain app list"); + return false; + } + if (launcherAppMap_.find(bundleName) != launcherAppMap_.end()) { + BUNDLE_ACTIVE_LOGD("launcherAppMap cache, bundleName:%{public}s isLauncherApp:%{public}d", + bundleName.c_str(), launcherAppMap_[bundleName]); + return launcherAppMap_[bundleName]; } AppExecFwk::ApplicationInfo appInfo; if (GetApplicationInfo(bundleName, @@ -111,11 +134,20 @@ bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, c BUNDLE_ACTIVE_LOGE("get applicationInfo failed."); return false; } - if (appInfo.isLauncherApp) { - launcherAppSet_.insert(bundleName); - return true; + launcherAppMap_[bundleName] = appInfo.isLauncherApp; + BUNDLE_ACTIVE_LOGD("insert launcherAppMap, bundleName:%{public}s isLauncherApp:%{public}d", + bundleName.c_str(), launcherAppMap_[bundleName]); + return appInfo.isLauncherApp; +} + +void BundleActiveBundleMgrHelper::InitLauncherAppMap() +{ + BUNDLE_ACTIVE_LOGI("agree obtain app list, init laucherAppMap"); + std::vector appInfos; + GetApplicationInfos(AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, AppExecFwk::Constants::ALL_USERUD, appInfos); + for (auto appInfo : appInfos) { + launcherAppMap_[appInfo.bundleName] = appInfo.isLauncherApp; } - return false; } } // namespace DeviceUsageStats } // namespace OHOS \ No newline at end of file diff --git a/services/common/src/device_usage_oobe_manager.cpp b/services/common/src/device_usage_oobe_manager.cpp new file mode 100644 index 0000000..935af84 --- /dev/null +++ b/services/common/src/device_usage_oobe_manager.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_usage_oobe_datashare_utils.h" +#include "bundle_active_log.h" +#include "device_usage_oobe_manager.h" +#include +#include "ipc_skeleton.h" + +namespace OHOS { +namespace DeviceUsageStats { +std::mutex DeviceUsageOOBEManager::mutex_; +sptr DeviceUsageOOBEManager::observer_ = nullptr; +namespace { +const std::string KEYWORD = "basic_statement_agreed"; +} // namespace + +DeviceUsageOOBEManager::DeviceUsageOOBEManager() +{ + Init(); +} + +DeviceUsageOOBEManager::~DeviceUsageOOBEManager() +{ + BUNDLE_ACTIVE_LOGI("DeviceUsageOOBEManager has been deconstructed"); +} + +DeviceUsageOOBEManager& DeviceUsageOOBEManager::GetInstance() +{ + static DeviceUsageOOBEManager instance; + return instance; +} + +bool DeviceUsageOOBEManager::GetOOBValue() +{ + std::lock_guard lock(mutex_); + return g_oobeValue; +} + +ErrCode DeviceUsageOOBEManager::RegisterObserver() +{ + std::lock_guard lock(mutex_); + std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); + auto uri = DataShareUtils::GetInstance().AssembleUri(KEYWORD); + auto helper = DataShareUtils::GetInstance().CreateDataShareHelper(); + if (helper == nullptr) { + IPCSkeleton::SetCallingIdentity(callingIdentity); + BUNDLE_ACTIVE_LOGE("RegisterObserver: helper does not created!"); + return ERR_NO_INIT; + } + if (observer_ != nullptr) { + BUNDLE_ACTIVE_LOGE("Secondary RegisterObserver!"); + UnregisterObserver(); + } + observer_ = new (std::nothrow)BundleActiveDataShareObserver(); + if (observer_ == nullptr) { + IPCSkeleton::SetCallingIdentity(callingIdentity); + return ERR_INVALID_OPERATION; + } + helper->RegisterObserver(uri, observer_); + DataShareUtils::GetInstance().ReleaseDataShareHelper(helper); + IPCSkeleton::SetCallingIdentity(callingIdentity); + BUNDLE_ACTIVE_LOGI("succeed to register observer of uri=%{public}s", uri.ToString().c_str()); + return ERR_OK; +} + +ErrCode DeviceUsageOOBEManager::UnregisterObserver() +{ + std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); + auto uri = DataShareUtils::GetInstance().AssembleUri(KEYWORD); + auto helper = DataShareUtils::GetInstance().CreateDataShareHelper(); + if (helper == nullptr) { + IPCSkeleton::SetCallingIdentity(callingIdentity); + BUNDLE_ACTIVE_LOGE("UnregisterObserver: helper does not created!"); + return ERR_NO_INIT; + } + helper->UnregisterObserver(uri, observer_); + DataShareUtils::GetInstance().ReleaseDataShareHelper(helper); + observer_ = nullptr; + IPCSkeleton::SetCallingIdentity(callingIdentity); + BUNDLE_ACTIVE_LOGI("succeed to register observer of uri=%{public}s", uri.ToString().c_str()); + return ERR_OK; +} + +void DeviceUsageOOBEManager::BundleActiveDataShareObserver::OnChange() +{ + BundleActiveBundleMgrHelper::GetInstance()->InitLauncherAppMap(); + DeviceUsageOOBEManager::GetInstance().g_oobeValue = true; +} + + +void DeviceUsageOOBEManager::Init() +{ + int resultValue = 0; + auto dataShareUtils = ResourceSchedule::DataShareUtils::GetInstance(); + dataShareUtils.GetValue(KEYWORD, resultValue); + if (resultValue != 0) { + BundleActiveBundleMgrHelper::GetInstance()->InitLauncherAppMap(); + g_oobeValue = true; + return; + } + RegisterObserver(); +} + +} // namespace DeviceUsageStats +} // namespace OHOS + diff --git a/utils/include/device_usage_data_share_utils.h b/utils/include/device_usage_data_share_utils.h new file mode 100644 index 0000000..dcf2635 --- /dev/null +++ b/utils/include/device_usage_data_share_utils.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVICE_USAGE_DATA_SHARE_UTILS_H +#define DEVICE_USAGE_DATA_SHARE_UTILS_H + +#include "datashare_helper.h" +#include "errors.h" +#include "ipc_skeleton.h" +#include "res_sched_log.h" +#include +#include "mutex" + +namespace OHOS { +namespace DeviceUsageStats { +class DeviceUsageDataShareUtils { +public: + ~DeviceUsageDataShareUtils (); + static DeviceUsageDataShareUtils& GetInstance(); + ErrCode GetValue(const std::string& key, int& value); + Uri AssembleUri(const std::string& key); + bool ReleaseDataShareHelper(std::shared_ptr& helper); + std::shared_ptr CreateDataShareHelper(); + +private: + DeviceUsageDataShareUtils (); + static sptr remoteObj_; + static std::mutex mutex_; + ErrCode GetStringValue(const std::string& key, std::string& value); + void InitSystemAbilityManager(); +}; +} // namespace DeviceUsageStats +} // namespace OHOS +#endif // DEVICE_USAGE_DATA_SHARE_UTILS_H + diff --git a/utils/src/device_usage_data_share_utils.cpp b/utils/src/device_usage_data_share_utils.cpp new file mode 100644 index 0000000..5a32541 --- /dev/null +++ b/utils/src/device_usage_data_share_utils.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "datashare_errno.h" +#include "datashare_predicates.h" +#include "datashare_result_set.h" +#include "datashare_values_bucket.h" +#include "iservice_registry.h" +#include "device_usage_oobe_datashare_utils.h" +#include "bundle_active_log.h" +#include "system_ability_definition.h" +#include "uri.h" + +namespace OHOS { +namespace DeviceUsageStats { + +sptr DeviceUsageDataShareUtils::remoteObj_; +std::mutex DeviceUsageDataShareUtils::mutex_; +namespace { +const std::string SETTING_COLUMN_KEYWORD = "KEYWORD"; +const std::string SETTING_COLUMN_VALUE = "VALUE"; +const std::string SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true"; +} // namespace + +DeviceUsageDataShareUtils::DeviceUsageDataShareUtils() = default; +DeviceUsageDataShareUtils::~DeviceUsageDataShareUtils() = default; + +DeviceUsageDataShareUtils& DeviceUsageDataShareUtils::GetInstance() +{ + static DeviceUsageDataShareUtils instance; + instance.InitSystemAbilityManager(); + return instance; +} + +ErrCode DeviceUsageDataShareUtils::GetStringValue(const std::string& key, std::string& value) +{ + auto helper = CreateDataShareHelper(); + if (helper == nullptr) { + BUNDLE_ACTIVE_LOGE("DeviceUsageDataShareUtils: helper does not created!"); + return ERR_NO_INIT; + } + std::vector columns = {SETTING_COLUMN_VALUE}; + DataShare::DataSharePredicates predicates; + predicates.EqualTo(SETTING_COLUMN_KEYWORD, key); + BUNDLE_ACTIVE_LOGD("keyWord=%{public}s", key.c_str()); + Uri uri(AssembleUri(key)); + auto resultSet = helper->Query(uri, predicates, columns); + ReleaseDataShareHelper(helper); + if (resultSet == nullptr) { + BUNDLE_ACTIVE_LOGE("helper->Query return nullptr"); + return ERR_INVALID_OPERATION; + } + int32_t count; + resultSet->GetRowCount(count); + if (count == 0) { + BUNDLE_ACTIVE_LOGW("not found value, keyWord=%{public}s, count=%{public}d", key.c_str(), count); + return ERR_NAME_NOT_FOUND; + } + const int32_t INDEX = 0; + resultSet->GoToRow(INDEX); + int32_t ret = resultSet->GetString(INDEX, value); + if (ret != DataShare::E_OK) { + BUNDLE_ACTIVE_LOGW("resultSet->GetString return not ok, ret=%{public}d", ret); + return ERR_INVALID_VALUE; + } + resultSet->Close(); + return ERR_OK; +} + +ErrCode DeviceUsageDataShareUtils::GetValue(const std::string& key, int& value) +{ + std::string result; + std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); + int32_t ret = GetStringValue(key, result); + IPCSkeleton::SetCallingIdentity(callingIdentity); + if (ret != ERR_OK) { + BUNDLE_ACTIVE_LOGW("resultSet->GetStringValue return not ok, ret=%{public}d", ret); + return ret; + } + char* pEnd = nullptr; + int64_t intResult = std::strtol(result.c_str(), &pEnd, ); + if (pEnd == result.c_str() || *pEnd != '\0' || (intResult < INT_MIN || intResult > INT_MAX)) { + BUNDLE_ACTIVE_LOGW("getValue string to int fail"); + return ret; + } + value = intResult; + return ERR_OK; +} + +std::shared_ptr DeviceUsageDataShareUtils::CreateDataShareHelper() +{ + if (remoteObj_ == nullptr) { + BUNDLE_ACTIVE_LOGE("Get remoteObj return nullptr!"); + return nullptr; + } + auto helper = DataShare::DataShareHelper::Creator(remoteObj_, SETTING_URI_PROXY); + if (helper == nullptr) { + BUNDLE_ACTIVE_LOGW("helper is nullptr, uri=%{public}s, remoteObj_=%{public}p", SETTING_URI_PROXY.c_str(), + remoteObj_.GetRefPtr()); + return nullptr; + } + return helper; +} + +bool DeviceUsageDataShareUtils::ReleaseDataShareHelper(std::shared_ptr& helper) +{ + if (helper == nullptr) { + BUNDLE_ACTIVE_LOGW("release helper fail, helper is null!"); + return false; + } + if (!helper->Release()) { + BUNDLE_ACTIVE_LOGW("release helper fail, remoteObj_%{public}p", remoteObj_.GetRefPtr()); + return false; + } + return true; +} + +void DeviceUsageDataShareUtils::InitSystemAbilityManager() +{ + auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (sam == nullptr) { + BUNDLE_ACTIVE_LOGE("get sam return nullptr"); + return; + } + auto remoteObj = sam->GetSystemAbility(BACKGROUD_TASK_MANAGER_SERVICE_ID); + if (remoteObj == nullptr) { + BUNDLE_ACTIVE_LOGE("Get remoteObj return nullptr, systemAbilityId=%{public}d", BACKGROUD_TASK_MANAGER_SERVICE_ID); + return; + } + remoteObj_ = remoteObj; +} + +Uri DeviceUsageDataShareUtils::AssembleUri(const std::string& key) +{ + Uri uri(SETTING_URI_PROXY + "&key=" + key); + return uri; +} +} // namespace DeviceUsageStats +} // namespace OHOS + -- Gitee From 1e79572eafc64e31b6bdf307f6e989dce9f02e59 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 28 May 2024 14:18:15 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E4=BC=98=E5=8C=96IPC=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- BUILD.gn | 4 ++-- .../src/bundle_active_bundle_mgr_helper.cpp | 7 +++++-- .../common/src/device_usage_oobe_manager.cpp | 19 ++++++++++--------- utils/src/device_usage_data_share_utils.cpp | 10 ++++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 120f931..c9158e9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -186,7 +186,7 @@ ohos_shared_library("usagestatservice") { "services/packageusage/src/bundle_active_report_handler.cpp", "services/packageusage/src/bundle_active_stats_combiner.cpp", "services/packageusage/src/bundle_active_user_service.cpp", - "utils/src/device_usage_share_utils.cpp", + "utils/src/device_usage_data_share_utils.cpp", ] public_configs = [ ":usagestats_public_config" ] @@ -272,7 +272,7 @@ ohos_static_library("usagestatservice_static") { "services/packageusage/src/bundle_active_report_handler.cpp", "services/packageusage/src/bundle_active_stats_combiner.cpp", "services/packageusage/src/bundle_active_user_service.cpp", - "utils/src/device_usage_share_utils.cpp", + "utils/src/device_usage_data_share_utils.cpp", ] public_configs = [ ":usagestats_public_config" ] diff --git a/services/common/src/bundle_active_bundle_mgr_helper.cpp b/services/common/src/bundle_active_bundle_mgr_helper.cpp index 5ea8a01..624f0b2 100644 --- a/services/common/src/bundle_active_bundle_mgr_helper.cpp +++ b/services/common/src/bundle_active_bundle_mgr_helper.cpp @@ -15,6 +15,8 @@ #include "bundle_active_bundle_mgr_helper.h" +#include "device_usage_oobe_manager.h" +#include "device_usage_data_share_utils.h" #include "bundle_active_log.h" #include "accesstoken_kit.h" #include "application_info.h" @@ -136,7 +138,7 @@ bool BundleActiveBundleMgrHelper::IsLauncherApp(const std::string &bundleName, c } launcherAppMap_[bundleName] = appInfo.isLauncherApp; BUNDLE_ACTIVE_LOGD("insert launcherAppMap, bundleName:%{public}s isLauncherApp:%{public}d", - bundleName.c_str(), launcherAppMap_[bundleName]); + bundleName.c_str(), launcherAppMap_[bundleName]); return appInfo.isLauncherApp; } @@ -144,7 +146,8 @@ void BundleActiveBundleMgrHelper::InitLauncherAppMap() { BUNDLE_ACTIVE_LOGI("agree obtain app list, init laucherAppMap"); std::vector appInfos; - GetApplicationInfos(AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, AppExecFwk::Constants::ALL_USERUD, appInfos); + GetApplicationInfos(AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, + AppExecFwk::Constants::ALL_USERID, appInfos); for (auto appInfo : appInfos) { launcherAppMap_[appInfo.bundleName] = appInfo.isLauncherApp; } diff --git a/services/common/src/device_usage_oobe_manager.cpp b/services/common/src/device_usage_oobe_manager.cpp index 935af84..342732c 100644 --- a/services/common/src/device_usage_oobe_manager.cpp +++ b/services/common/src/device_usage_oobe_manager.cpp @@ -13,7 +13,8 @@ * limitations under the License. */ -#include "device_usage_oobe_datashare_utils.h" +#include "device_usage_data_share_utils.h" +#include "bundle_active_bundle_mgr_helper.h" #include "bundle_active_log.h" #include "device_usage_oobe_manager.h" #include @@ -53,8 +54,8 @@ ErrCode DeviceUsageOOBEManager::RegisterObserver() { std::lock_guard lock(mutex_); std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); - auto uri = DataShareUtils::GetInstance().AssembleUri(KEYWORD); - auto helper = DataShareUtils::GetInstance().CreateDataShareHelper(); + auto uri = DeviceUsageDataShareUtils::GetInstance().AssembleUri(KEYWORD); + auto helper = DeviceUsageDataShareUtils::GetInstance().CreateDataShareHelper(); if (helper == nullptr) { IPCSkeleton::SetCallingIdentity(callingIdentity); BUNDLE_ACTIVE_LOGE("RegisterObserver: helper does not created!"); @@ -70,7 +71,7 @@ ErrCode DeviceUsageOOBEManager::RegisterObserver() return ERR_INVALID_OPERATION; } helper->RegisterObserver(uri, observer_); - DataShareUtils::GetInstance().ReleaseDataShareHelper(helper); + DeviceUsageDataShareUtils::GetInstance().ReleaseDataShareHelper(helper); IPCSkeleton::SetCallingIdentity(callingIdentity); BUNDLE_ACTIVE_LOGI("succeed to register observer of uri=%{public}s", uri.ToString().c_str()); return ERR_OK; @@ -79,15 +80,15 @@ ErrCode DeviceUsageOOBEManager::RegisterObserver() ErrCode DeviceUsageOOBEManager::UnregisterObserver() { std::string callingIdentity = IPCSkeleton::ResetCallingIdentity(); - auto uri = DataShareUtils::GetInstance().AssembleUri(KEYWORD); - auto helper = DataShareUtils::GetInstance().CreateDataShareHelper(); + auto uri = DeviceUsageDataShareUtils::GetInstance().AssembleUri(KEYWORD); + auto helper = DeviceUsageDataShareUtils::GetInstance().CreateDataShareHelper(); if (helper == nullptr) { IPCSkeleton::SetCallingIdentity(callingIdentity); BUNDLE_ACTIVE_LOGE("UnregisterObserver: helper does not created!"); return ERR_NO_INIT; } helper->UnregisterObserver(uri, observer_); - DataShareUtils::GetInstance().ReleaseDataShareHelper(helper); + DeviceUsageDataShareUtils::GetInstance().ReleaseDataShareHelper(helper); observer_ = nullptr; IPCSkeleton::SetCallingIdentity(callingIdentity); BUNDLE_ACTIVE_LOGI("succeed to register observer of uri=%{public}s", uri.ToString().c_str()); @@ -104,8 +105,8 @@ void DeviceUsageOOBEManager::BundleActiveDataShareObserver::OnChange() void DeviceUsageOOBEManager::Init() { int resultValue = 0; - auto dataShareUtils = ResourceSchedule::DataShareUtils::GetInstance(); - dataShareUtils.GetValue(KEYWORD, resultValue); + auto DeviceUsageDataShareUtils = DeviceUsageDataShareUtils::GetInstance(); + DeviceUsageDataShareUtils.GetValue(KEYWORD, resultValue); if (resultValue != 0) { BundleActiveBundleMgrHelper::GetInstance()->InitLauncherAppMap(); g_oobeValue = true; diff --git a/utils/src/device_usage_data_share_utils.cpp b/utils/src/device_usage_data_share_utils.cpp index 5a32541..754b883 100644 --- a/utils/src/device_usage_data_share_utils.cpp +++ b/utils/src/device_usage_data_share_utils.cpp @@ -18,7 +18,7 @@ #include "datashare_result_set.h" #include "datashare_values_bucket.h" #include "iservice_registry.h" -#include "device_usage_oobe_datashare_utils.h" +#include "device_usage_data_share_utils.h" #include "bundle_active_log.h" #include "system_ability_definition.h" #include "uri.h" @@ -29,6 +29,7 @@ namespace DeviceUsageStats { sptr DeviceUsageDataShareUtils::remoteObj_; std::mutex DeviceUsageDataShareUtils::mutex_; namespace { +const int32_t PARAM_NUM_TEN = 10; const std::string SETTING_COLUMN_KEYWORD = "KEYWORD"; const std::string SETTING_COLUMN_VALUE = "VALUE"; const std::string SETTING_URI_PROXY = "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true"; @@ -90,7 +91,7 @@ ErrCode DeviceUsageDataShareUtils::GetValue(const std::string& key, int& value) return ret; } char* pEnd = nullptr; - int64_t intResult = std::strtol(result.c_str(), &pEnd, ); + int64_t intResult = std::strtol(result.c_str(), &pEnd, PARAM_NUM_TEN); if (pEnd == result.c_str() || *pEnd != '\0' || (intResult < INT_MIN || intResult > INT_MAX)) { BUNDLE_ACTIVE_LOGW("getValue string to int fail"); return ret; @@ -134,9 +135,10 @@ void DeviceUsageDataShareUtils::InitSystemAbilityManager() BUNDLE_ACTIVE_LOGE("get sam return nullptr"); return; } - auto remoteObj = sam->GetSystemAbility(BACKGROUD_TASK_MANAGER_SERVICE_ID); + auto remoteObj = sam->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID); if (remoteObj == nullptr) { - BUNDLE_ACTIVE_LOGE("Get remoteObj return nullptr, systemAbilityId=%{public}d", BACKGROUD_TASK_MANAGER_SERVICE_ID); + BUNDLE_ACTIVE_LOGE("Get remoteObj return nullptr, systemAbilityId=%{public}d", + BACKGROUND_TASK_MANAGER_SERVICE_ID); return; } remoteObj_ = remoteObj; -- Gitee From 27cb74bb313480fbc0d248b390950b6216792890 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 28 May 2024 14:55:51 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BC=98=E5=8C=96IPC=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- .../include/device_usage_oobe_manager.h | 2 +- .../common/src/device_usage_oobe_manager.cpp | 2 +- test/unittest/bundle_active_total_test.cpp | 100 ++++++++++++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) diff --git a/services/common/include/device_usage_oobe_manager.h b/services/common/include/device_usage_oobe_manager.h index a15623f..639220c 100644 --- a/services/common/include/device_usage_oobe_manager.h +++ b/services/common/include/device_usage_oobe_manager.h @@ -27,7 +27,7 @@ class DeviceUsageOOBEManager { public: static DeviceUsageOOBEManager& GetInstance(); ErrCode UnregisterObserver(); - bool GetOOBValue(); + bool GetOOBEValue(); void Init(); private: diff --git a/services/common/src/device_usage_oobe_manager.cpp b/services/common/src/device_usage_oobe_manager.cpp index 342732c..545266d 100644 --- a/services/common/src/device_usage_oobe_manager.cpp +++ b/services/common/src/device_usage_oobe_manager.cpp @@ -44,7 +44,7 @@ DeviceUsageOOBEManager& DeviceUsageOOBEManager::GetInstance() return instance; } -bool DeviceUsageOOBEManager::GetOOBValue() +bool DeviceUsageOOBEManager::GetOOBEValue() { std::lock_guard lock(mutex_); return g_oobeValue; diff --git a/test/unittest/bundle_active_total_test.cpp b/test/unittest/bundle_active_total_test.cpp index d6f1efc..449a39d 100644 --- a/test/unittest/bundle_active_total_test.cpp +++ b/test/unittest/bundle_active_total_test.cpp @@ -134,6 +134,106 @@ HWTEST_F(BundleActiveTotalTest, BundleActiveBundleMgrHelperTest_001, Function | test.GetBundleInfo(string, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_EXTENSION_INFO, bundleInfo, 0); } +/* + * @tc.name: BundleActiveBundleMgrHelperTest_002 + * @tc.desc: test GetApplicationInfos + * @tc.type: FUNC + * @tc.require: issuesI9SQ6G + */ +HWTEST_F(PackageUsageTest, BundleActiveBundleMgrHelperTest_002, Function | MediumTest | Level0) +{ + AppExecFwk::ApplicationFlag flag = AppExecFwk::GET_BASIC_APPLICATION_INFO; + std::vector appInfos; + auto bundleActiveBundleMgrHelper = BundleActiveBundleMgrHelper::GetInstance(); + bundleActiveBundleMgrHelper.GetApplicationInfos(flag, 0, appInfos); + SUCCEED(); +} + +/* + * @tc.name: BundleActiveBundleMgrHelperTest_003 + * @tc.desc: test is launcherApp + * @tc.type: FUNC + * @tc.require: issuesI9SQ6G + */ +HWTEST_F(PackageUsageTest, BundleActiveBundleMgrHelperTest_003, Function | MediumTest | Level0) +{ + BundleActiveBundleMgrHelper::GetInstance().InitLauncherAppMap(); + DeviceUsageOOBEManager::GetInstance().g_oobeValue = true; + BundleActiveBundleMgrHelper::GetInstance().isLauncherApp("test", 0); + BundleActiveBundleMgrHelper::GetInstance().launcherAppMap_["test"] = false; + BundleActiveBundleMgrHelper::GetInstance().isLauncherApp("test", 0); + SUCCEED(); +} + +/* + * @tc.name: DeviceUsageOOBEManager_001 + * @tc.desc: test RegisterObserver + * @tc.type: FUNC + * @tc.require: issuesI9SQ6G + */ +HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_001, Function | MediumTest | Level0) +{ + DeviceUsageOOBEManager::GetInstance().Init(); + DeviceUsageOOBEManager::GetInstance().RegisterObserver(); + SUCCEED(); +} + +/* + * @tc.name: DeviceUsageOOBEManager_001 + * @tc.desc: test UnregisterObserver + * @tc.type: FUNC + * @tc.require: issuesI9SQ6G + */ +HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_002, Function | MediumTest | Level0) +{ + DeviceUsageOOBEManager::GetInstance().Init(); + DeviceUsageOOBEManager::GetInstance().UnregisterObserver(); + SUCCEED(); +} + +/* + * @tc.name: DeviceUsageOOBEManager_001 + * @tc.desc: test observer onChange + * @tc.type: FUNC + * @tc.require: issuesI9SQ6G + */ +HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_003, Function | MediumTest | Level0) +{ + DeviceUsageOOBEManager::GetInstance().observer_.onChange(); + SUCCEED(); +} + +/* + * @tc.name: DeviceUsageDataShareUtils_001 + * @tc.desc: test observer onChange + * @tc.type: FUNC + * @tc.require: issuesI9SQ6G + */ +HWTEST_F(PackageUsageTest, DeviceUsageDataShareUtils_001, Function | MediumTest | Level0) +{ + string key = "basic_statement_agreed"; + int value = 0; + DeviceUsageDataShareUtils::GetInstance().InitSystemAbilityManager(); + DeviceUsageDataShareUtils::GetInstance().CreateDataShareHelper(); + DeviceUsageDataShareUtils::GetInstance().GetValue(key, value); + DeviceUsageDataShareUtils::GetInstance().ReleaseDataShareHelper(); + SUCCEED(); +} + +/* + * @tc.name: DeviceUsageDataShareUtils_001 + * @tc.desc: test observer onChange + * @tc.type: FUNC + * @tc.require: issuesI9SQ6G + */ +HWTEST_F(PackageUsageTest, DeviceUsageDataShareUtils_002, Function | MediumTest | Level0) +{ + string key = "basic_statement_agreed"; + int value = 0; + DeviceUsageDataShareUtils::GetInstance().AssembleUri(key); + SUCCEED(); +} + /* * @tc.name: BundleActiveAppStateObserverTest_001 * @tc.desc: test the interface of bundle_active_app_state_observer -- Gitee From a38d49719121c50d86a868205886604929450e0d Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 28 May 2024 14:58:33 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=87=8F=E5=B0=91IPC=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- test/unittest/bundle_active_total_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unittest/bundle_active_total_test.cpp b/test/unittest/bundle_active_total_test.cpp index 449a39d..43492e3 100644 --- a/test/unittest/bundle_active_total_test.cpp +++ b/test/unittest/bundle_active_total_test.cpp @@ -32,6 +32,8 @@ #include "bundle_active_shutdown_callback_service.h" #include "bundle_active_binary_search.h" #include "bundle_active_debug_mode.h" +#include "device_usage_data_share_utils.h" +#include "device_usage_oobe_manager.h" using namespace testing::ext; -- Gitee From 2fc8108d5c58ed3f9c58b10628b1b7b2e396d369 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 28 May 2024 15:47:15 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=87=8F=E5=B0=91IPC=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- test/unittest/BUILD.gn | 2 + test/unittest/bundle_active_total_test.cpp | 38 +++++++++---------- utils/include/device_usage_data_share_utils.h | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index b976982..977bda2 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -48,6 +48,7 @@ ohos_unittest("BundleActiveTotalTest") { external_deps = [ "ability_base:want", + "ability_base:zuri", "ability_runtime:app_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", @@ -56,6 +57,7 @@ ohos_unittest("BundleActiveTotalTest") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "data_share:datashare_consumer", "eventhandler:libeventhandler", "hilog:libhilog", "init:libbegetutil", diff --git a/test/unittest/bundle_active_total_test.cpp b/test/unittest/bundle_active_total_test.cpp index 43492e3..8c4bc31 100644 --- a/test/unittest/bundle_active_total_test.cpp +++ b/test/unittest/bundle_active_total_test.cpp @@ -142,12 +142,11 @@ HWTEST_F(BundleActiveTotalTest, BundleActiveBundleMgrHelperTest_001, Function | * @tc.type: FUNC * @tc.require: issuesI9SQ6G */ -HWTEST_F(PackageUsageTest, BundleActiveBundleMgrHelperTest_002, Function | MediumTest | Level0) +HWTEST_F(BundleActiveTotalTest, BundleActiveBundleMgrHelperTest_002, Function | MediumTest | Level0) { AppExecFwk::ApplicationFlag flag = AppExecFwk::GET_BASIC_APPLICATION_INFO; std::vector appInfos; - auto bundleActiveBundleMgrHelper = BundleActiveBundleMgrHelper::GetInstance(); - bundleActiveBundleMgrHelper.GetApplicationInfos(flag, 0, appInfos); + BundleActiveBundleMgrHelper::GetInstance()->GetApplicationInfos(flag, 0, appInfos); SUCCEED(); } @@ -157,13 +156,13 @@ HWTEST_F(PackageUsageTest, BundleActiveBundleMgrHelperTest_002, Function | Mediu * @tc.type: FUNC * @tc.require: issuesI9SQ6G */ -HWTEST_F(PackageUsageTest, BundleActiveBundleMgrHelperTest_003, Function | MediumTest | Level0) +HWTEST_F(BundleActiveTotalTest, BundleActiveBundleMgrHelperTest_003, Function | MediumTest | Level0) { - BundleActiveBundleMgrHelper::GetInstance().InitLauncherAppMap(); + BundleActiveBundleMgrHelper::GetInstance()->InitLauncherAppMap(); DeviceUsageOOBEManager::GetInstance().g_oobeValue = true; - BundleActiveBundleMgrHelper::GetInstance().isLauncherApp("test", 0); - BundleActiveBundleMgrHelper::GetInstance().launcherAppMap_["test"] = false; - BundleActiveBundleMgrHelper::GetInstance().isLauncherApp("test", 0); + BundleActiveBundleMgrHelper::GetInstance()->IsLauncherApp("test", 0); + BundleActiveBundleMgrHelper::GetInstance()->launcherAppMap_["test"] = false; + BundleActiveBundleMgrHelper::GetInstance()->IsLauncherApp("test", 0); SUCCEED(); } @@ -173,10 +172,10 @@ HWTEST_F(PackageUsageTest, BundleActiveBundleMgrHelperTest_003, Function | Mediu * @tc.type: FUNC * @tc.require: issuesI9SQ6G */ -HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_001, Function | MediumTest | Level0) +HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_001, Function | MediumTest | Level0) { - DeviceUsageOOBEManager::GetInstance().Init(); - DeviceUsageOOBEManager::GetInstance().RegisterObserver(); + DeviceUsageOOBEManager::GetInstance()->Init(); + DeviceUsageOOBEManager::GetInstance()->RegisterObserver(); SUCCEED(); } @@ -186,10 +185,10 @@ HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_001, Function | MediumTest | L * @tc.type: FUNC * @tc.require: issuesI9SQ6G */ -HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_002, Function | MediumTest | Level0) +HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_002, Function | MediumTest | Level0) { - DeviceUsageOOBEManager::GetInstance().Init(); - DeviceUsageOOBEManager::GetInstance().UnregisterObserver(); + DeviceUsageOOBEManager::GetInstance()->Init(); + DeviceUsageOOBEManager::GetInstance()->UnregisterObserver(); SUCCEED(); } @@ -199,9 +198,10 @@ HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_002, Function | MediumTest | L * @tc.type: FUNC * @tc.require: issuesI9SQ6G */ -HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_003, Function | MediumTest | Level0) +HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_003, Function | MediumTest | Level0) { - DeviceUsageOOBEManager::GetInstance().observer_.onChange(); + DeviceUsageOOBEManager::GetInstance()->observer_ = new DeviceUsageOOBEManager::BundleActiveDataShareObserver(); + DeviceUsageOOBEManager::GetInstance()->observer_->OnChange(); SUCCEED(); } @@ -211,14 +211,13 @@ HWTEST_F(PackageUsageTest, DeviceUsageOOBEManager_003, Function | MediumTest | L * @tc.type: FUNC * @tc.require: issuesI9SQ6G */ -HWTEST_F(PackageUsageTest, DeviceUsageDataShareUtils_001, Function | MediumTest | Level0) +HWTEST_F(BundleActiveTotalTest, DeviceUsageDataShareUtils_001, Function | MediumTest | Level0) { string key = "basic_statement_agreed"; int value = 0; DeviceUsageDataShareUtils::GetInstance().InitSystemAbilityManager(); DeviceUsageDataShareUtils::GetInstance().CreateDataShareHelper(); DeviceUsageDataShareUtils::GetInstance().GetValue(key, value); - DeviceUsageDataShareUtils::GetInstance().ReleaseDataShareHelper(); SUCCEED(); } @@ -228,10 +227,9 @@ HWTEST_F(PackageUsageTest, DeviceUsageDataShareUtils_001, Function | MediumTest * @tc.type: FUNC * @tc.require: issuesI9SQ6G */ -HWTEST_F(PackageUsageTest, DeviceUsageDataShareUtils_002, Function | MediumTest | Level0) +HWTEST_F(BundleActiveTotalTest, DeviceUsageDataShareUtils_002, Function | MediumTest | Level0) { string key = "basic_statement_agreed"; - int value = 0; DeviceUsageDataShareUtils::GetInstance().AssembleUri(key); SUCCEED(); } diff --git a/utils/include/device_usage_data_share_utils.h b/utils/include/device_usage_data_share_utils.h index dcf2635..ec6c61c 100644 --- a/utils/include/device_usage_data_share_utils.h +++ b/utils/include/device_usage_data_share_utils.h @@ -19,7 +19,6 @@ #include "datashare_helper.h" #include "errors.h" #include "ipc_skeleton.h" -#include "res_sched_log.h" #include #include "mutex" -- Gitee From d5521de3f3f3f76e9751824283ba2a172bdfd2d7 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 28 May 2024 16:46:33 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=87=8F=E5=B0=91IPC=E9=80=9A=E8=AE=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- test/unittest/bundle_active_total_test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unittest/bundle_active_total_test.cpp b/test/unittest/bundle_active_total_test.cpp index 8c4bc31..b486456 100644 --- a/test/unittest/bundle_active_total_test.cpp +++ b/test/unittest/bundle_active_total_test.cpp @@ -174,8 +174,8 @@ HWTEST_F(BundleActiveTotalTest, BundleActiveBundleMgrHelperTest_003, Function | */ HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_001, Function | MediumTest | Level0) { - DeviceUsageOOBEManager::GetInstance()->Init(); - DeviceUsageOOBEManager::GetInstance()->RegisterObserver(); + DeviceUsageOOBEManager::GetInstance().Init(); + DeviceUsageOOBEManager::GetInstance().RegisterObserver(); SUCCEED(); } @@ -187,8 +187,8 @@ HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_001, Function | MediumTes */ HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_002, Function | MediumTest | Level0) { - DeviceUsageOOBEManager::GetInstance()->Init(); - DeviceUsageOOBEManager::GetInstance()->UnregisterObserver(); + DeviceUsageOOBEManager::GetInstance().Init(); + DeviceUsageOOBEManager::GetInstance().UnregisterObserver(); SUCCEED(); } @@ -200,8 +200,8 @@ HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_002, Function | MediumTes */ HWTEST_F(BundleActiveTotalTest, DeviceUsageOOBEManager_003, Function | MediumTest | Level0) { - DeviceUsageOOBEManager::GetInstance()->observer_ = new DeviceUsageOOBEManager::BundleActiveDataShareObserver(); - DeviceUsageOOBEManager::GetInstance()->observer_->OnChange(); + DeviceUsageOOBEManager::GetInstance().observer_ = new DeviceUsageOOBEManager::BundleActiveDataShareObserver(); + DeviceUsageOOBEManager::GetInstance().observer_->OnChange(); SUCCEED(); } -- Gitee From 16bdcbfa940665402eb852366235fbdc80db38c1 Mon Sep 17 00:00:00 2001 From: fengyang Date: Tue, 28 May 2024 18:55:37 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=87=8F=E5=B0=91IPC=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- BUILD.gn | 2 ++ test/unittest/BUILD.gn | 1 + 2 files changed, 3 insertions(+) diff --git a/BUILD.gn b/BUILD.gn index c9158e9..4e5b76c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -199,6 +199,7 @@ ohos_shared_library("usagestatservice") { "ability_base:want", "ability_base:zuri", "ability_runtime:app_manager", + "ability_runtime:dataobs_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", @@ -285,6 +286,7 @@ ohos_static_library("usagestatservice_static") { "ability_base:want", "ability_base:zuri", "ability_runtime:app_manager", + "ability_runtime:dataobs_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 977bda2..ef097d7 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -50,6 +50,7 @@ ohos_unittest("BundleActiveTotalTest") { "ability_base:want", "ability_base:zuri", "ability_runtime:app_manager", + "ability_runtime:dataobs_manager", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", -- Gitee