From e7f81f99ea97992a127a891e7da1f7f378620111 Mon Sep 17 00:00:00 2001 From: Haryslee Date: Tue, 25 Mar 2025 11:44:02 +0800 Subject: [PATCH] fix the test issue of security component Signed-off-by: Haryslee --- BUILD.gn | 1 + .../sa/test/BUILD.gn | 8 --- .../mock/include/ability_manager_client.h | 47 +++++++++++++++ .../sa/test/mock/include/bundle_info.h | 58 ++++++++++++++++++ .../sa/test/mock/include/bundle_mgr_client.h | 42 +++++++++++++ .../sa/test/mock/include/display.h | 30 ++++++++++ .../sa/test/mock/include/display_info.h | 59 +++++++++++++++++++ .../sa/test/mock/include/display_manager.h | 46 +++++++++++++++ 8 files changed, 283 insertions(+), 8 deletions(-) create mode 100644 services/security_component_service/sa/test/mock/include/ability_manager_client.h create mode 100644 services/security_component_service/sa/test/mock/include/bundle_info.h create mode 100644 services/security_component_service/sa/test/mock/include/bundle_mgr_client.h create mode 100644 services/security_component_service/sa/test/mock/include/display.h create mode 100644 services/security_component_service/sa/test/mock/include/display_info.h create mode 100644 services/security_component_service/sa/test/mock/include/display_manager.h diff --git a/BUILD.gn b/BUILD.gn index 0d544d7..c5a8fe5 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + import("//build/ohos.gni") group("security_component_build_module") { diff --git a/services/security_component_service/sa/test/BUILD.gn b/services/security_component_service/sa/test/BUILD.gn index 3d71a92..58f619a 100644 --- a/services/security_component_service/sa/test/BUILD.gn +++ b/services/security_component_service/sa/test/BUILD.gn @@ -75,11 +75,8 @@ ohos_unittest("sec_comp_service_test") { "ability_base:base", "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_manager", "ability_runtime:runtime", "access_token:libtoken_setproc", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", "googletest:gmock_main", @@ -89,7 +86,6 @@ ohos_unittest("sec_comp_service_test") { "hitrace:hitrace_meter", "ipc:ipc_core", "json:nlohmann_json_static", - "window_manager:libdm", ] } @@ -148,11 +144,8 @@ ohos_unittest("sec_comp_service_mock_test") { "ability_base:base", "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_manager", "ability_runtime:runtime", "access_token:libtoken_setproc", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", "c_utils:utils", "eventhandler:libeventhandler", "googletest:gmock_main", @@ -162,7 +155,6 @@ ohos_unittest("sec_comp_service_mock_test") { "hitrace:hitrace_meter", "ipc:ipc_core", "json:nlohmann_json_static", - "window_manager:libdm", ] } diff --git a/services/security_component_service/sa/test/mock/include/ability_manager_client.h b/services/security_component_service/sa/test/mock/include/ability_manager_client.h new file mode 100644 index 0000000..edcd967 --- /dev/null +++ b/services/security_component_service/sa/test/mock/include/ability_manager_client.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 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 OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_CLIENT_H +#define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_CLIENT_H + +#include +#include "iremote_object.h" +#include "want.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class AbilityManagerClient + * AbilityManagerClient is used to access ability manager services. + */ +class AbilityManagerClient { +public: + AbilityManagerClient() = default; + virtual ~AbilityManagerClient() = default; + static std::shared_ptr GetInstance() + { + static std::shared_ptr instance_ = + std::shared_ptr(new AbilityManagerClient()); + return instance_; + } + + ErrCode StartExtensionAbility(const Want &want, sptr callerToken) + { + return 0; + } +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_CLIENT_H diff --git a/services/security_component_service/sa/test/mock/include/bundle_info.h b/services/security_component_service/sa/test/mock/include/bundle_info.h new file mode 100644 index 0000000..1313452 --- /dev/null +++ b/services/security_component_service/sa/test/mock/include/bundle_info.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_BUNDLE_INFO_H +#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_BUNDLE_INFO_H + +#include +#include + +namespace OHOS { +namespace AppExecFwk { +enum BundleFlag { + // get bundle info except abilityInfos + GET_BUNDLE_DEFAULT = 0x00000000, + // get bundle info include abilityInfos + GET_BUNDLE_WITH_ABILITIES = 0x00000001, + // get bundle info include request permissions + GET_BUNDLE_WITH_REQUESTED_PERMISSION = 0x00000010, + // get bundle info include extension info + GET_BUNDLE_WITH_EXTENSION_INFO = 0x00000020, + // get bundle info include hash value + GET_BUNDLE_WITH_HASH_VALUE = 0x00000030, + // get bundle info inlcude menu, only for dump usage + GET_BUNDLE_WITH_MENU = 0x00000040, + // get bundle info inlcude router map, only for dump usage + GET_BUNDLE_WITH_ROUTER_MAP = 0x00000080, + // get bundle info include skill info + GET_BUNDLE_WITH_SKILL = 0x00000800, +}; + +// configuration information about a bundle +struct BundleInfo { + bool isNewVersion = false; + bool isKeepAlive = false; + bool singleton = false; + bool isPreInstallApp = false; + + bool isNativeApp = false; + + bool entryInstallationFree = false; // application : false; atomic service : true + bool isDifferentName = false; + std::string versionName; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_BUNDLE_INFO_H diff --git a/services/security_component_service/sa/test/mock/include/bundle_mgr_client.h b/services/security_component_service/sa/test/mock/include/bundle_mgr_client.h new file mode 100644 index 0000000..1e20d42 --- /dev/null +++ b/services/security_component_service/sa/test/mock/include/bundle_mgr_client.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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 FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H +#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H + +#include "want.h" +#include "bundle_info.h" + +namespace OHOS { +namespace AppExecFwk { + +class BundleMgrClient { +public: + BundleMgrClient() = default; + virtual ~BundleMgrClient() = default; + + ErrCode GetNameForUid(const int uid, std::string &name) + { + return 0; + } + bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId = 0) + { + return true; + } +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_CORE_INCLUDE_BUNDLEMGR_BUNDLE_MGR_CLIENT_H diff --git a/services/security_component_service/sa/test/mock/include/display.h b/services/security_component_service/sa/test/mock/include/display.h new file mode 100644 index 0000000..8dd4053 --- /dev/null +++ b/services/security_component_service/sa/test/mock/include/display.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef SECURITY_COMPONENT_MANAGER_DISPLAY_MOCK_H +#define SECURITY_COMPONENT_MANAGER_DISPLAY_MOCK_H +#include "display_info.h" +#include "refbase.h" + +namespace OHOS::Rosen { +class Display : public RefBase { +public: + sptr GetDisplayInfo() const + { + return sptr::MakeSptr(); + } +}; +} +#endif // SECURITY_COMPONENT_MANAGER_DISPLAY_MOCK_H \ No newline at end of file diff --git a/services/security_component_service/sa/test/mock/include/display_info.h b/services/security_component_service/sa/test/mock/include/display_info.h new file mode 100644 index 0000000..04b582a --- /dev/null +++ b/services/security_component_service/sa/test/mock/include/display_info.h @@ -0,0 +1,59 @@ +/* + * 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. + */ + +#ifndef SECURITY_COMPONENT_MANAGER_DISPLAY_INFO_MOCK_H +#define SECURITY_COMPONENT_MANAGER_DISPLAY_INFO_MOCK_H +#include +#include + +namespace OHOS::Rosen { +namespace { +static const int32_t DEFAULT_SCREEN_SIZE = 1500; +}; + +class DisplayInfo : public Parcelable { +public: + bool Marshalling(Parcel &parcel) const override + { + return true; + } + + int32_t GetWidth() const + { + return DEFAULT_SCREEN_SIZE; + } + + int32_t GetHeight() const + { + return DEFAULT_SCREEN_SIZE; + } + + int32_t GetPhysicalHeight() const + { + return DEFAULT_SCREEN_SIZE; + } + + int32_t GetAvailableHeight() const + { + return DEFAULT_SCREEN_SIZE; + } + + std::vector GetCreaseRects() const + { + return std::vector(); + } +}; +} +#endif // SECURITY_COMPONENT_MANAGER_DISPLAY_INFO_MOCK_H diff --git a/services/security_component_service/sa/test/mock/include/display_manager.h b/services/security_component_service/sa/test/mock/include/display_manager.h new file mode 100644 index 0000000..7861d6b --- /dev/null +++ b/services/security_component_service/sa/test/mock/include/display_manager.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef SECURITY_COMPONENT_MANAGER_DISPLAY_MANAGER_MOCK_H +#define SECURITY_COMPONENT_MANAGER_DISPLAY_MANAGER_MOCK_H +#include "display.h" +#include "display_info.h" + +namespace OHOS::Rosen { +class DisplayManager { +public: + static DisplayManager& GetInstance() + { + static DisplayManager instance; + return instance; + } + + sptr GetDefaultDisplaySync() + { + return sptr::MakeSptr(); + } + + sptr GetDisplayById(uint64_t displayId) + { + return sptr::MakeSptr(); + } + + sptr GetCurrentFoldCreaseRegion() + { + return sptr::MakeSptr(); + } +}; +} +#endif // SECURITY_COMPONENT_MANAGER_DISPLAY_MANAGER_MOCK_H -- Gitee