diff --git a/interfaces/innerkits/common/BUILD.gn b/interfaces/innerkits/common/BUILD.gn index e9616a511f673ba6b594cb123127b7cdb3ccf8bd..aa5c9c7381eb38e4052680fd5c3f65e35896cfa9 100644 --- a/interfaces/innerkits/common/BUILD.gn +++ b/interfaces/innerkits/common/BUILD.gn @@ -13,6 +13,12 @@ import("//build/ohos.gni") +config("all_config_samgr_common") { + include_dirs = [ + "include", + ] +} + config("config_samgr_common") { include_dirs = [ "include", @@ -35,6 +41,13 @@ ohos_shared_library("samgr_common") { ] public_configs = [ ":config_samgr_common" ] + + all_dependent_configs = [ ":all_config_samgr_common" ] + + deps = [ + "//third_party/libxml2:libxml2", + ] + if (is_standard_system) { external_deps = [ "c_utils:utils", @@ -45,7 +58,6 @@ ohos_shared_library("samgr_common") { part_name = "samgr" } - public_deps = [ "//third_party/libxml2:libxml2" ] subsystem_name = "systemabilitymgr" } ################################################################################ diff --git a/interfaces/innerkits/lsamgr/BUILD.gn b/interfaces/innerkits/lsamgr/BUILD.gn index 52180645644ef03ff11daf0b639b950e451f0807..4ad4689e1b75555c718bcc61a8a01edefedfde8f 100644 --- a/interfaces/innerkits/lsamgr/BUILD.gn +++ b/interfaces/innerkits/lsamgr/BUILD.gn @@ -35,7 +35,7 @@ ohos_shared_library("lsamgr") { "//foundation/systemabilitymgr/samgr/test/resource:coverage_flags", ] - public_configs = [ ":public_config_lsamgr" ] + all_dependent_configs = [ ":public_config_lsamgr" ] if (is_standard_system) { external_deps = [ diff --git a/interfaces/innerkits/samgr_proxy/BUILD.gn b/interfaces/innerkits/samgr_proxy/BUILD.gn index b419f5b3931600569091dbddad97ff7b2f6621e3..4a92478c198ba5631a1b4dc6ac7e63edf6726094 100644 --- a/interfaces/innerkits/samgr_proxy/BUILD.gn +++ b/interfaces/innerkits/samgr_proxy/BUILD.gn @@ -42,7 +42,7 @@ ohos_shared_library("samgr_proxy") { "//foundation/systemabilitymgr/samgr/test/resource:coverage_flags", ] - public_configs = [ ":samgr_proxy_config" ] + all_dependent_configs = [ ":samgr_proxy_config" ] if (is_standard_system) { external_deps = [ diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index 60a1bceb98f17e7dcc527a7a14ea9b92163d9a81..75c300359601719b0ee894082b2c8b1f15b41b20 100644 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -77,7 +77,6 @@ ohos_executable("samgr") { external_deps += [ "selinux:libservice_checker" ] defines = [ "WITH_SELINUX" ] } - public_deps = [ "//third_party/libxml2:libxml2" ] part_name = "samgr" } subsystem_name = "systemabilitymgr" diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn index d6b62ae85c6cbf187abcd394e3af30a1c7c70e95..a401bb55d03c4169bfd13f5ea0a06e7018c369e3 100644 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("SystemAbilityMgrTest") { "${samgr_services_dir}/source/system_ability_manager_stub.cpp", "${samgr_services_dir}/source/system_ability_status_change_proxy.cpp", "${samgr_services_dir}/test/unittest/src/itest_transaction_service.cpp", + "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_mgr_test.cpp", "//foundation/systemabilitymgr/samgr/services/dfx/source/hisysevent_adapter.cpp", @@ -63,6 +64,8 @@ ohos_unittest("SystemAbilityMgrTest") { external_deps = [ "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "eventhandler:libeventhandler", "hisysevent_native:libhisysevent", @@ -79,6 +82,7 @@ ohos_unittest("SystemAbilityMgrProxyTest") { sources = [ "${samgr_services_dir}/test/unittest/src/itest_transaction_service.cpp", + "${samgr_services_dir}/test/unittest/src/mock_permission.cpp", "${samgr_services_dir}/test/unittest/src/sa_status_change_mock.cpp", "${samgr_services_dir}/test/unittest/src/system_ability_mgr_proxy_test.cpp", ] @@ -100,6 +104,9 @@ ohos_unittest("SystemAbilityMgrProxyTest") { ] external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/samgr/native/test/unittest/include/mock_permission.h b/services/samgr/native/test/unittest/include/mock_permission.h new file mode 100644 index 0000000000000000000000000000000000000000..d6ebb45deeb50a531d73c53cbf3ed907f9f1aefe --- /dev/null +++ b/services/samgr/native/test/unittest/include/mock_permission.h @@ -0,0 +1,25 @@ +/* + * 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 SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H +#define SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H + +namespace OHOS { +class TestMockPermission { +public: + static void MockPermission(); +}; +} // namespace OHOS +#endif // SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/mock_permission.cpp b/services/samgr/native/test/unittest/src/mock_permission.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a526f61556c9c650e9d7fbfeb86ebc00844bf16 --- /dev/null +++ b/services/samgr/native/test/unittest/src/mock_permission.cpp @@ -0,0 +1,41 @@ +/* + * 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. + */ + +#include "mock_permission.h" + +#include "nativetoken_kit.h" +#include "token_setproc.h" + +namespace OHOS { +void TestMockPermission::MockPermission() +{ + static const char *PERMS[] = { + "ohos.permission.DISTRIBUTED_DATASYNC" + }; + uint64_t tokenId; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .aclsNum = 0, + .dcaps = nullptr, + .perms = PERMS, + .acls = nullptr, + .processName = "distributedsched", + .aplStr = "system_core", + }; + tokenId = GetAccessTokenId(&infoInstance); + SetSelfTokenID(tokenId); +} +} \ No newline at end of file diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp index 19088bb1bfbc9d2e024d4f2740ee5e2953925078..04c859a98615d749e636bca9cc8d349bf6dad8fb 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_proxy_test.cpp @@ -16,6 +16,7 @@ #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "itest_transaction_service.h" +#include "mock_permission.h" #include "sa_status_change_mock.h" #include "string_ex.h" #include "system_ability_manager_proxy.h" @@ -45,6 +46,7 @@ void SystemAbilityMgrProxyTest::TearDownTestCase() void SystemAbilityMgrProxyTest::SetUp() { + TestMockPermission::MockPermission(); DTEST_LOG << "SetUp" << std::endl; } diff --git a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp index 742a1f3a39915df6df2d00603dcab41dfa2245ee..dd766a7d990f23f62d46ca0f1a9759aa49e73c41 100644 --- a/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp +++ b/services/samgr/native/test/unittest/src/system_ability_mgr_test.cpp @@ -17,6 +17,7 @@ #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "itest_transaction_service.h" +#include "mock_permission.h" #include "parameter.h" #include "sa_status_change_mock.h" #include "string_ex.h" @@ -56,6 +57,7 @@ void SystemAbilityMgrTest::TearDownTestCase() void SystemAbilityMgrTest::SetUp() { + TestMockPermission::MockPermission(); DTEST_LOG << "SetUp" << std::endl; }