From 52fd7bee4ba66660c16028e8cec25c348100934b Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Wed, 11 Jun 2025 11:08:21 +0800 Subject: [PATCH] add AbilityPermissionUtil unittest cases for ability_runtime Signed-off-by: zhangzezhong --- test/unittest/BUILD.gn | 1 + .../BUILD.gn | 97 +++++ .../ability_permission_util_second_test.cpp | 252 ++++++++++++ .../mock/include/mock_app_mgr_service.h | 284 +++++++++++++ .../mock/include/mock_app_utils.h | 146 +++++++ .../mock/include/mock_my_flag.h | 33 ++ .../include/mock_permission_verification.h | 74 ++++ .../mock/src/mock_app_mgr_service.cpp | 34 ++ .../mock/src/mock_app_mgr_utils.cpp | 35 ++ .../mock/src/mock_app_scheduler.cpp | 254 ++++++++++++ .../mock/src/mock_app_utils.cpp | 255 ++++++++++++ .../mock/src/mock_bundle_mgr_helper.cpp | 382 ++++++++++++++++++ .../mock/src/mock_my_flag.cpp | 24 ++ .../mock/src/mock_permission_verification.cpp | 135 +++++++ 14 files changed, 2006 insertions(+) create mode 100644 test/unittest/ability_permission_util_second_test/BUILD.gn create mode 100644 test/unittest/ability_permission_util_second_test/ability_permission_util_second_test.cpp create mode 100644 test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h create mode 100644 test/unittest/ability_permission_util_second_test/mock/include/mock_app_utils.h create mode 100644 test/unittest/ability_permission_util_second_test/mock/include/mock_my_flag.h create mode 100644 test/unittest/ability_permission_util_second_test/mock/include/mock_permission_verification.h create mode 100644 test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_service.cpp create mode 100644 test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_utils.cpp create mode 100644 test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp create mode 100644 test/unittest/ability_permission_util_second_test/mock/src/mock_app_utils.cpp create mode 100755 test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp create mode 100644 test/unittest/ability_permission_util_second_test/mock/src/mock_my_flag.cpp create mode 100644 test/unittest/ability_permission_util_second_test/mock/src/mock_permission_verification.cpp diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 32e588e4846..830217abb1e 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -172,6 +172,7 @@ group("unittest") { "ability_manager_service_twelfth_test:unittest", "ability_manager_stub_second_test:unittest", "ability_manager_stub_test:unittest", + "ability_permission_util_second_test:unittest", "ability_permission_util_test:unittest", "ability_record_death_manager_test:unittest", "ability_record_dump_test:unittest", diff --git a/test/unittest/ability_permission_util_second_test/BUILD.gn b/test/unittest/ability_permission_util_second_test/BUILD.gn new file mode 100644 index 00000000000..5683a121f60 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/BUILD.gn @@ -0,0 +1,97 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/ability_runtime/abilitymgr" + +ohos_unittest("ability_permission_util_second_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime/", + "${ability_runtime_path}/interfaces/inner_api/ability_manager/include", + "${ability_runtime_test_path}/mock/ability_manager_collaborator", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", + "${ability_runtime_test_path}/mock/mock_sa_call", + "${ability_runtime_test_path}/mock/prepare_terminate_callback", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/include", + "${ability_runtime_test_path}/unittest/app_debug_listener_stub_test", + "mock/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] + + sources = [ + "ability_permission_util_second_test.cpp", + "mock/src/mock_app_mgr_service.cpp", + "mock/src/mock_app_mgr_utils.cpp", + "mock/src/mock_app_scheduler.cpp", + "mock/src/mock_app_utils.cpp", + "mock/src/mock_bundle_mgr_helper.cpp", + "mock/src/mock_my_flag.cpp", + "mock/src/mock_permission_verification.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "access_token:libaccesstoken_sdk", + "appspawn:appspawn_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "googletest:gmock_main", + "googletest:gtest_main", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "init:libbegetutil", + "ipc:ipc_core", + "json:nlohmann_json_static", + "jsoncpp:jsoncpp", + "kv_store:distributeddata_mgr", + "memory_utils:libmeminfo", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":ability_permission_util_second_test" ] +} diff --git a/test/unittest/ability_permission_util_second_test/ability_permission_util_second_test.cpp b/test/unittest/ability_permission_util_second_test/ability_permission_util_second_test.cpp new file mode 100644 index 00000000000..350631b6647 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/ability_permission_util_second_test.cpp @@ -0,0 +1,252 @@ +/* + * 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. + */ + +#include +#include "mock_permission_verification.h" +#define private public +#include "utils/ability_permission_util.h" +#include "ability_info.h" +#include "ability_record.h" +#include "ability_util.h" +#include "accesstoken_kit.h" +#include "app_utils.h" +#include "ipc_skeleton.h" +#include "running_process_info.h" +#include "permission_constants.h" +#include "permission_verification.h" +#undef private +#include "hilog_tag_wrapper.h" +#include "parameters.h" +#include "mock_my_flag.h" +#include "start_ability_utils.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; +using AbilityRequest = OHOS::AAFwk::AbilityRequest; +using OHOS::AppExecFwk::AbilityType; +using OHOS::AAFwk::AbilityPermissionUtil; + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr int32_t ERR_INVALID_VALUE = 22; +} // namespace +class AbilityPermissionUtilSecondTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void AbilityPermissionUtilSecondTest::SetUpTestCase(void) {} +void AbilityPermissionUtilSecondTest::TearDownTestCase(void) {} +void AbilityPermissionUtilSecondTest::SetUp() {} +void AbilityPermissionUtilSecondTest::TearDown() {} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstanceAndAppClone_0100 + * @tc.desc: IsDominateScreen + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_IsDominateScreen_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0100 start"); + Want want; + MyFlag::callCount_ = 0; + auto result = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, false); + EXPECT_FALSE(result); + EXPECT_EQ(MyFlag::callCount_, 3); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0100 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_IsDominateScreen_0200 + * @tc.desc: IsDominateScreen + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_IsDominateScreen_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0200 start"); + Want want; + MyFlag::mockFlag_ = 1; + MyFlag::callCount_ = 0; + auto result = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, false); + EXPECT_FALSE(result); + EXPECT_EQ(MyFlag::callCount_, 3); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0200 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_IsDominateScreen_0300 + * @tc.desc: IsDominateScreen + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_IsDominateScreen_0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0300 start"); + Want want; + MyFlag::mockFlag_ = 1; + MyFlag::isBundleName_ = 1; + MyFlag::callCount_ = 0; + auto result = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, false); + EXPECT_FALSE(result); + EXPECT_EQ(MyFlag::callCount_, 3); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0300 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_IsDominateScreen_0400 + * @tc.desc: IsDominateScreen + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_IsDominateScreen_0400, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0400 start"); + Want want; + MyFlag::mockFlag_ = 1; + MyFlag::isBundleName_ = 0; + MyFlag::callCount_ = 0; + auto result = AbilityPermissionUtil::GetInstance().IsDominateScreen(want, false); + EXPECT_FALSE(result); + EXPECT_EQ(MyFlag::callCount_, 3); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_IsDominateScreen_0400 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstance_0100 + * @tc.desc: CheckMultiInstance + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_CheckMultiInstance_0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0100 start"); + Want want; + MyFlag::mockFlag_ = 0; + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstance(want, nullptr, true, "", 0); + EXPECT_EQ(result, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0100 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstance_0200 + * @tc.desc: CheckMultiInstance + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_CheckMultiInstance_0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0200 start"); + Want want; + MyFlag::mockFlag_ = 1; + auto result = AbilityPermissionUtil::GetInstance().CheckMultiInstance(want, nullptr, true, "", 0); + EXPECT_EQ(result, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstance_0200 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstanceAndAppClone0100 + * @tc.desc: CheckMultiInstanceAndAppClone + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone0100 start"); + Want want; + StartAbilityUtils::startAbilityInfo = std::make_shared(); + StartAbilityUtils::startAbilityInfo->abilityInfo.bundleName = "bundleName"; + StartAbilityUtils::startAbilityInfo->abilityInfo.name = "name"; + StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo.bundleType = + static_cast(AppExecFwk::BundleType::APP); + StartAbilityUtils::startAbilityInfo->abilityInfo.type = AppExecFwk::AbilityType::PAGE; + StartAbilityUtils::startAbilityInfo->abilityInfo.extensionAbilityType = ExtensionAbilityType::SERVICE; + StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo.multiAppMode.multiAppModeType = + AppExecFwk::MultiAppModeType::UNSPECIFIED; + int32_t result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 1, 1, nullptr); + EXPECT_EQ(result, ERR_MULTI_APP_NOT_SUPPORTED); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone0100 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstanceAndAppClone0200 + * @tc.desc: CheckMultiInstanceAndAppClone + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone0200, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone0200 start"); + Want want; + StartAbilityUtils::startAbilityInfo = std::make_shared(); + StartAbilityUtils::startAbilityInfo->abilityInfo.bundleName = "bundleName"; + StartAbilityUtils::startAbilityInfo->abilityInfo.name = "name"; + StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo.bundleType = + static_cast(AppExecFwk::BundleType::APP); + StartAbilityUtils::startAbilityInfo->abilityInfo.type = AppExecFwk::AbilityType::PAGE; + StartAbilityUtils::startAbilityInfo->abilityInfo.extensionAbilityType = ExtensionAbilityType::SERVICE; + StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo.multiAppMode.multiAppModeType = + AppExecFwk::MultiAppModeType::MULTI_INSTANCE; + int32_t result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 1, 1, nullptr); + EXPECT_EQ(result, ERR_NOT_SUPPORT_APP_CLONE); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone0200 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckMultiInstanceAndAppClone0300 + * @tc.desc: CheckMultiInstanceAndAppClone + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_CheckMultiInstanceAndAppClone0300, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone0300 start"); + Want want; + StartAbilityUtils::startAbilityInfo = std::make_shared(); + StartAbilityUtils::startAbilityInfo->abilityInfo.bundleName = "bundleName"; + StartAbilityUtils::startAbilityInfo->abilityInfo.name = "name"; + StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo.bundleType = + static_cast(AppExecFwk::BundleType::APP); + StartAbilityUtils::startAbilityInfo->abilityInfo.type = AppExecFwk::AbilityType::PAGE; + StartAbilityUtils::startAbilityInfo->abilityInfo.extensionAbilityType = ExtensionAbilityType::SERVICE; + StartAbilityUtils::startAbilityInfo->abilityInfo.applicationInfo.multiAppMode.multiAppModeType = + AppExecFwk::MultiAppModeType::MULTI_INSTANCE; + int32_t result = AbilityPermissionUtil::GetInstance().CheckMultiInstanceAndAppClone(want, 1, 0, nullptr); + EXPECT_EQ(result, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckMultiInstanceAndAppClone0300 end"); +} + +/** + * @tc.name: AbilityPermissionUtil_CheckPrepareTerminateEnable0100 + * @tc.desc: CheckPrepareTerminateEnable + * @tc.type: FUNC + * @tc.require: NA + */ +HWTEST_F(AbilityPermissionUtilSecondTest, AbilityPermissionUtil_CheckPrepareTerminateEnable0100, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckPrepareTerminateEnable0100 start"); + std::shared_ptr abilityRecord{ nullptr }; + int32_t result = AbilityPermissionUtil::GetInstance().CheckPrepareTerminateEnable(abilityRecord); + EXPECT_EQ(result, ERR_INVALID_VALUE); + TAG_LOGI(AAFwkTag::TEST, "AbilityPermissionUtil_CheckPrepareTerminateEnable0100 end"); +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h new file mode 100644 index 00000000000..103841abcf9 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_mgr_service.h @@ -0,0 +1,284 @@ +/* + * 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 MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_H +#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_H + +#include "gmock/gmock.h" +#include "semaphore_ex.h" +#include "app_mgr_stub.h" +#include "app_malloc_info.h" + +namespace OHOS { +namespace AppExecFwk { +class MockAppMgrService : public AppMgrStub { +public: + MOCK_METHOD6(LoadAbility, + void(const sptr& token, const sptr& preToken, + const std::shared_ptr& abilityInfo, const std::shared_ptr& appInfo, + const std::shared_ptr& want, int32_t abilityRecordId)); + MOCK_METHOD2(TerminateAbility, void(const sptr& token, bool clearMissionFlag)); + MOCK_METHOD2(UpdateAbilityState, void(const sptr& token, const AbilityState state)); + MOCK_METHOD1(AttachApplication, void(const sptr& app)); + MOCK_METHOD1(NotifyMemoryLevel, int(int32_t level)); + MOCK_METHOD1(NotifyProcMemoryLevel, int32_t(const std::map &procLevelMap)); + MOCK_METHOD2(DumpHeapMemory, int(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)); + MOCK_METHOD1(ApplicationForegrounded, void(const int32_t recordId)); + MOCK_METHOD1(ApplicationBackgrounded, void(const int32_t recordId)); + MOCK_METHOD1(ApplicationTerminated, void(const int32_t recordId)); + MOCK_METHOD1(AbilityCleaned, void(const sptr& token)); + MOCK_METHOD4(UpdateApplicationInfoInstalled, int(const std::string&, const int uid, const std::string&, bool)); + MOCK_METHOD3(KillApplication, int32_t(const std::string& appName, const bool clearPageStack, int32_t appIndex)); + MOCK_METHOD3(ForceKillApplication, int32_t(const std::string& appName, const int userId, const int appIndex)); + MOCK_METHOD1(KillProcessesByAccessTokenId, int32_t(const uint32_t accessTokenId)); + MOCK_METHOD3(KillApplicationByUid, int(const std::string&, const int uid, const std::string&)); + MOCK_METHOD1(IsBackgroundRunningRestricted, int(const std::string& bundleName)); + MOCK_METHOD1(GetAllRunningProcesses, int(std::vector& info)); + MOCK_METHOD2(GetRunningProcessesByBundleType, int(const BundleType bundleType, + std::vector& info)); + MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector& info, int32_t userId)); + MOCK_METHOD1(GetAllRenderProcesses, int(std::vector& info)); + MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector&)); + MOCK_METHOD0(GetAmsMgr, sptr()); + MOCK_METHOD1(GetAppFreezingTime, void(int& time)); + MOCK_METHOD1(SetAppFreezingTime, void(int time)); + MOCK_METHOD3(ClearUpApplicationData, int32_t(const std::string& bundleName, int32_t appCloneIndex, int32_t userId)); + MOCK_METHOD1(ClearUpApplicationDataBySelf, int32_t(int32_t userId)); + MOCK_METHOD1(StartupResidentProcess, void(const std::vector& bundleInfos)); + MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId)); + MOCK_METHOD0(PreStartNWebSpawnProcess, int()); + MOCK_METHOD6(StartRenderProcess, int(const std::string&, int32_t, int32_t, int32_t, pid_t&, bool)); + MOCK_METHOD1(AttachRenderProcess, void(const sptr& renderScheduler)); + MOCK_METHOD1(SaveBrowserChannel, void(sptr browser)); + MOCK_METHOD2(GetRenderProcessTerminationStatus, int(pid_t renderPid, int& status)); + MOCK_METHOD2(RegisterApplicationStateObserver, int32_t(const sptr& observer, + const std::vector& bundleNameList)); + MOCK_METHOD1(UnregisterApplicationStateObserver, int32_t(const sptr& observer)); + MOCK_METHOD3(ScheduleAcceptWantDone, + void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag)); + MOCK_METHOD3(ScheduleNewProcessRequestDone, + void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag)); + MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector>& tokens)); + MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config)); + MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId)); + MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name, + int32_t appIndex)); + MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr& observer)); + MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr& observer)); + MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName)); + MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName, + const sptr& callback)); + MOCK_METHOD2(NotifyHotReloadPage, int32_t(const std::string& bundleName, const sptr& callback)); + MOCK_METHOD2(NotifyUnLoadRepairPatch, int32_t(const std::string& bundleName, + const sptr& callback)); + MOCK_METHOD2(IsSharedBundleRunning, bool(const std::string &bundleName, uint32_t versionCode)); + MOCK_METHOD3(GetBundleNameByPid, int32_t(const int pid, std::string &bundleName, int32_t &uid)); + MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData)); + MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData)); + MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize)); + MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId, + std::vector &info)); + MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector &instanceKeys)); + MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName, + std::vector &instanceKeys, int32_t userId)); + MOCK_METHOD2(IsApplicationRunning, int32_t(const std::string &bundleName, bool &isRunning)); + MOCK_METHOD3(IsAppRunning, int32_t(const std::string &bundleName, + int32_t appCloneIndex, bool &isRunning)); + MOCK_METHOD3(IsAppRunningByBundleNameAndUserId, int32_t(const std::string &bundleName, + int32_t userId, bool &isRunning)); +#ifdef SUPPORT_CHILD_PROCESS + MOCK_METHOD2(StartChildProcess, int32_t(pid_t &childPid, const ChildProcessRequest &request)); + MOCK_METHOD1(GetChildProcessInfoForSelf, int32_t(ChildProcessInfo &info)); + MOCK_METHOD1(AttachChildProcess, void(const sptr &childScheduler)); + MOCK_METHOD0(ExitChildProcessSafely, void()); +#endif // SUPPORT_CHILD_PROCESS + MOCK_METHOD1(RegisterRenderStateObserver, int32_t(const sptr &observer)); + MOCK_METHOD1(UnregisterRenderStateObserver, int32_t(const sptr &observer)); + MOCK_METHOD2(UpdateRenderState, int32_t(pid_t renderPid, int32_t state)); + MOCK_METHOD0(IsFinalAppProcess, bool()); + MOCK_METHOD1(SetSupportedProcessCacheSelf, int32_t(bool isSupport)); + MOCK_METHOD2(IsProcessCacheSupported, int32_t(int32_t pid, bool &isSupported)); + MOCK_METHOD2(SetProcessCacheEnable, int32_t(int32_t pid, bool enable)); + MOCK_METHOD2(SetSupportedProcessCache, int32_t(int32_t pid, bool isSupport)); +#ifdef SUPPORT_CHILD_PROCESS + MOCK_METHOD4(StartNativeChildProcess, int32_t(const std::string &libName, int32_t childProcessCount, + const sptr &callback, const std::string &customProcessName)); +#endif // SUPPORT_CHILD_PROCESS + MOCK_METHOD2(GetSupportedProcessCachePids, int32_t(const std::string &bundleName, + std::vector &pidList)); + MOCK_METHOD1(RegisterKiaInterceptor, int32_t(const sptr &interceptor)); + MOCK_METHOD2(CheckIsKiaProcess, int32_t(pid_t pid, bool &isKia)); + virtual int StartUserTestProcess( + const AAFwk::Want &want, const sptr &observer, const BundleInfo &bundleInfo, int32_t userId) + { + return 0; + } + + virtual int32_t RegisterAppForegroundStateObserver(const sptr &observer) + { + return 0; + } + + virtual int32_t RegisterAbilityForegroundStateObserver(const sptr &observer) + { + return 0; + } + + virtual int32_t UnregisterAppForegroundStateObserver(const sptr &observer) + { + return 0; + } + + virtual int32_t UnregisterAbilityForegroundStateObserver(const sptr &observer) + { + return 0; + } + + virtual int32_t RegisterAppForegroundStateObserver(const sptr &observer) + { + return 0; + } + + virtual int32_t UnregisterAppForegroundStateObserver(const sptr &observer) + { + return 0; + } + + virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override + { + return 0; + } + + virtual int FinishUserTest(const std::string& msg, const int64_t& resultCode, const std::string& bundleName) + { + return 0; + } + + virtual int GetProcessRunningInformation(RunningProcessInfo &info) + { + return 0; + } + + virtual void RegisterAppStateCallback(const sptr& callback) + { + callback_ = callback; + } + + int32_t CheckPermissionImpl([[maybe_unused]] const int32_t recordId, const std::string& data) + { + data_ = data; + return 0; + } + + virtual int32_t JudgeSandboxByPid(pid_t pid, bool &isSandbox) + { + return 0; + } + + void KillApplicationImpl(const std::string& data) + { + data_ = data; + } + + const std::string& GetData() const + { + return data_; + } + + void Wait() + { + sem_.Wait(); + } + + void Post() + { + sem_.Post(); + } + + void UpdateState() const + { + if (!callback_) { + return; + } + AppProcessData processData; + processData.pid = 1; + processData.appState = ApplicationState::APP_STATE_CREATE; + callback_->OnAppStateChanged(processData); + } + + void Terminate(const sptr& token) const + { + if (!callback_) { + return; + } + AbilityState st = AbilityState::ABILITY_STATE_CREATE; + callback_->OnAbilityRequestDone(token, st); + } + + MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); + + int InvokeSendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) + { + code_ = code; + + return 0; + } + + int code_; + + virtual bool SetAppFreezeFilter(int32_t pid) + { + return false; + } + + virtual int32_t ChangeAppGcState(pid_t pid, int32_t state, uint64_t tid = 0) + { + return 0; + } + + int32_t RegisterAppRunningStatusListener(const sptr &listener) + { + return 0; + } + + int32_t UnregisterAppRunningStatusListener(const sptr &listener) + { + return 0; + } + + int32_t DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) + { + return 0; + } + + int32_t DumpCjHeapMemory(OHOS::AppExecFwk::CjHeapDumpInfo &info) + { + return 0; + } + + int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName, + RunningMultiAppInfo &info) override; + + static int32_t retCode_; + static RunningMultiAppInfo retInfo_; + +private: + Semaphore sem_; + std::string data_; + sptr callback_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_H diff --git a/test/unittest/ability_permission_util_second_test/mock/include/mock_app_utils.h b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_utils.h new file mode 100644 index 00000000000..45beb8f9496 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/include/mock_app_utils.h @@ -0,0 +1,146 @@ +/* + * 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_APP_UTILS_H +#define OHOS_ABILITY_RUNTIME_APP_UTILS_H + +#include +#include +#include "nocopyable.h" + +namespace OHOS { +namespace AAFwk { +constexpr const int32_t DEFAULT_MAX_EXT_PER_PROC = 10; +constexpr const int32_t DEFAULT_MAX_EXT_PER_DEV = 100; +constexpr const int32_t DEFAULT_INVALID_VALUE = -1; +constexpr const int32_t DEFAULT_MAX_CHILD_PROCESS = 0; +template +class DeviceConfiguration { +public: + bool isLoaded = false; + T value; +}; + +/** + * @class AppUtils + * provides app utils. + */ +class AppUtils { +public: + /** + * GetInstance, get an instance of AppUtils. + * + * @return An instance of AppUtils. + */ + static AppUtils &GetInstance(); + + ~AppUtils(); + + bool IsLauncher(const std::string &bundleName) const; + bool IsLauncherAbility(const std::string &abilityName) const; + bool IsInheritWindowSplitScreenMode(); + bool IsSupportAncoApp(); + int32_t GetTimeoutUnitTimeRatio(); + bool IsSelectorDialogDefaultPossion(); + bool IsStartSpecifiedProcess(); + bool IsUseMultiRenderProcess(); + bool IsLimitMaximumOfRenderProcess(); + bool IsGrantPersistUriPermission(); + bool IsStartOptionsWithAnimation(); + bool IsMultiProcessModel(); + bool IsStartOptionsWithProcessOptions(); + bool EnableMoveUIAbilityToBackgroundApi(); + bool IsLaunchEmbededUIAbility(); + bool IsSupportNativeChildProcess(); + bool IsSupportMultiInstance(); + bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); + bool IsAllowNativeChildProcess(const std::string &appIdentifier); + int32_t GetLimitMaximumExtensionsPerProc(); + bool IsBigMemoryUnrelatedKeepAliveProc(const std::string &bundleName); + bool IsRequireBigMemoryProcess(const std::string &bundleName); + int32_t GetLimitMaximumExtensionsPerDevice(); + std::string GetCacheExtensionTypeList(); + bool IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName); + std::string GetBrokerDelegateBundleName(); + int32_t GetCollaboratorBrokerUID(); + int32_t GetCollaboratorBrokerReserveUID(); + int32_t MaxChildProcess(); + std::string GetMigrateClientBundleName(); + bool IsConnectSupportCrossUser(); + bool IsSupportAppServiceExtension(); + bool IsPrepareTerminateEnabled(); + bool IsCacheExtensionAbilityByList(const std::string& bundleName, const std::string& abilityName); + bool IsSystemReasonMessage(const std::string &reasonMessage); + bool InResidentWhiteList(const std::string &bundleName); + const std::vector &GetResidentWhiteList(); + +private: + void LoadResidentProcessInExtremeMemory(); + void LoadAllowNativeChildProcessApps(); + void LoadStartAbilityWithoutCallerToken(); + bool IsCacheAbilityEnabled(); + void LoadCacheAbilityList(); + void LoadProcessProhibitedFromRestarting(); + void LoadRequireBigMemoryApp(); + void LoadResidentWhiteList(); + AppUtils(); + + volatile bool isSceneBoard_ = false; + volatile DeviceConfiguration isInheritWindowSplitScreenMode_ = {false, true}; + volatile DeviceConfiguration isSupportAncoApp_ = {false, false}; + volatile DeviceConfiguration timeoutUnitTimeRatio_ = {false, 1}; + volatile DeviceConfiguration isSelectorDialogDefaultPossion_ = {false, true}; + volatile DeviceConfiguration isStartSpecifiedProcess_ = {false, false}; + volatile DeviceConfiguration isUseMultiRenderProcess_ = {false, true}; + volatile DeviceConfiguration isLimitMaximumOfRenderProcess_ = {false, true}; + volatile DeviceConfiguration isGrantPersistUriPermission_ = {false, false}; + volatile DeviceConfiguration isStartOptionsWithAnimation_ = {false, false}; + volatile DeviceConfiguration isMultiProcessModel_ = {false, false}; + volatile DeviceConfiguration isStartOptionsWithProcessOptions_ = {false, false}; + volatile DeviceConfiguration enableMoveUIAbilityToBackgroundApi_ = {false, true}; + volatile DeviceConfiguration isLaunchEmbededUIAbility_ = {false, false}; + volatile DeviceConfiguration isSupportNativeChildProcess_ = {false, false}; + volatile DeviceConfiguration isSupportMultiInstance_ = {false, false}; + std::mutex isConnectSupportCrossUserMutex_; + volatile DeviceConfiguration isConnectSupportCrossUser_ = {false, false}; + volatile DeviceConfiguration isSupportAppServiceExtension_ = {false, false}; + DeviceConfiguration>> + residentProcessInExtremeMemory_ = {false, {}}; + std::mutex residentProcessInExtremeMemoryMutex_; + DeviceConfiguration> processProhibitedFromRestarting_ = {false, {}}; + std::mutex processProhibitedFromRestartingMutex_; + DeviceConfiguration> requireBigMemoryApp_ = {false, {}}; + std::mutex requireBigMemoryAppMutex_; + DeviceConfiguration> + allowStartNativeProcessApps_ = {false, {}}; + volatile DeviceConfiguration limitMaximumExtensionsPerProc_ = {false, DEFAULT_MAX_EXT_PER_PROC}; + volatile DeviceConfiguration limitMaximumExtensionsPerDevice_ = {false, DEFAULT_MAX_EXT_PER_DEV}; + DeviceConfiguration>> + startAbilityWithoutCallerToken_ = {false, {}}; + std::mutex startAbilityWithoutCallerTokenMutex_; + DeviceConfiguration brokerDelegateBundleName_ = {false, ""}; + volatile DeviceConfiguration collaboratorBrokerUid_ = {false, DEFAULT_INVALID_VALUE}; + volatile DeviceConfiguration collaboratorBrokerReserveUid_ = {false, DEFAULT_INVALID_VALUE}; + volatile DeviceConfiguration maxChildProcess_ = {false, DEFAULT_MAX_CHILD_PROCESS}; + DeviceConfiguration migrateClientBundleName_ = {true, "com.huwei.hmos.migratecilent"}; + DeviceConfiguration>> + cacheAbilityList_ = {false, {}}; + DeviceConfiguration> residentWhiteList_ = {false, {}}; + std::mutex residentWhiteListMutex_; + DISALLOW_COPY_AND_MOVE(AppUtils); +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H diff --git a/test/unittest/ability_permission_util_second_test/mock/include/mock_my_flag.h b/test/unittest/ability_permission_util_second_test/mock/include/mock_my_flag.h new file mode 100644 index 00000000000..0ac3502896e --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/include/mock_my_flag.h @@ -0,0 +1,33 @@ +/* + * 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 MOCK_MY_FLAG_H +#define MOCK_MY_FLAG_H +namespace OHOS { +namespace AAFwk { +class MyFlag { +public: + enum FLAG { + IS_SA_CALL = 1, + IS_SHELL_CALL, + IS_SA_AND_SHELL_CALL, + }; + static int mockFlag_; + static int isBundleName_; + static int callCount_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // MOCK_MY_FLAG_H \ No newline at end of file diff --git a/test/unittest/ability_permission_util_second_test/mock/include/mock_permission_verification.h b/test/unittest/ability_permission_util_second_test/mock/include/mock_permission_verification.h new file mode 100644 index 00000000000..c81e958f426 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/include/mock_permission_verification.h @@ -0,0 +1,74 @@ +/* + * 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_PERMISSION_VERIFICATION_H +#define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H + +#include "ipc_skeleton.h" +#include "singleton.h" +#include "want.h" +#include "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { + +class PermissionVerification : public DelayedSingleton { +public: +struct VerificationInfo { + bool visible = false; + bool isBackgroundCall = true; + bool associatedWakeUp = false; + uint32_t accessTokenId = 0; + int32_t apiTargetVersion = 0; +}; + + PermissionVerification() = default; + ~PermissionVerification() = default; + + bool VerifyCallingPermission(const std::string &permissionName) const; + bool IsSACall() const; + bool IsShellCall() const; + bool CheckSpecificSystemAbilityAccessPermission() const; + bool VerifyRunningInfoPerm() const; + bool VerifyControllerPerm() const; + bool VerifyDlpPermission(Want &want) const; + int VerifyAccountPermission() const; + bool VerifyMissionPermission() const; + int VerifyAppStateObserverPermission() const; + int32_t VerifyUpdateConfigurationPerm() const; + bool VerifyInstallBundlePermission() const; + bool VerifyGetBundleInfoPrivilegedPermission() const; + int CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const; + int CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const; + int CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const; + int CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const; + int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const; + unsigned int GetCallingTokenID() const; + bool JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const; + bool JudgeStartAbilityFromBackground(const bool isBackgroundCall) const; + bool JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const; + int JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const; + inline bool IsCallFromSameAccessToken(const uint32_t accessTokenId) const + { + return IPCSkeleton::GetCallingTokenID() == accessTokenId; + } + bool JudgeCallerIsAllowedToUseSystemAPI() const; + bool IsSystemAppCall() const; + bool VerifyPrepareTerminatePermission() const; + bool VerifySetProcessCachePermission() const; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H \ No newline at end of file diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_service.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_service.cpp new file mode 100644 index 00000000000..86ca0600a73 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_service.cpp @@ -0,0 +1,34 @@ +/* + * 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. + */ + +#include "mock_app_mgr_service.h" + +namespace OHOS { +namespace AppExecFwk { +int32_t MockAppMgrService::retCode_ = 0; +RunningMultiAppInfo MockAppMgrService::retInfo_; + +int32_t MockAppMgrService::GetRunningMultiAppInfoByBundleName(const std::string &bundleName, + RunningMultiAppInfo &info) +{ + if (retCode_ != 0) { + return retCode_; + } + + info = retInfo_; + return 0; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_utils.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_utils.cpp new file mode 100644 index 00000000000..3103205d682 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_mgr_utils.cpp @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#include "app_mgr_util.h" +#include "mock_app_mgr_service.h" +#include "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { +sptr AppMgrUtil::appMgr_ = nullptr; + +OHOS::sptr AppMgrUtil::GetAppMgr() +{ + if (0 == MyFlag::mockFlag_) { + return appMgr_; + } + + sptr mockAppMgr(new AppExecFwk::MockAppMgrService()); + appMgr_ = iface_cast(mockAppMgr); + return appMgr_; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp new file mode 100644 index 00000000000..8f44c754c21 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_scheduler.cpp @@ -0,0 +1,254 @@ +/* + * 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. + */ + +#include "ability_manager_errors.h" +#include "ability_util.h" +#include "app_scheduler.h" +#include "appmgr/app_mgr_constants.h" +#include "hilog_tag_wrapper.h" +#include "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { +AppScheduler::AppScheduler() +{ + TAG_LOGI(AAFwkTag::TEST, " Test AppScheduler::AppScheduler()"); +} + +AppScheduler::~AppScheduler() +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::~AppScheduler()"); +} + +bool AppScheduler::Init(const std::weak_ptr& callback) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::Init()"); + if (!callback.lock()) { + return false; + } + return true; +} + +int AppScheduler::LoadAbility(const AbilityRuntime::LoadParam& loadParam, const AppExecFwk::AbilityInfo& abilityInfo, + const AppExecFwk::ApplicationInfo& applicationInfo, const AAFwk::Want& want) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::LoadAbility()"); + if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { + return INNER_ERR; + } + return ERR_OK; +} + +int AppScheduler::TerminateAbility(const sptr& token, bool isClearMissionFlag) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::TerminateAbility()"); + return ERR_OK; +} + +void AppScheduler::MoveToForeground(const sptr& token) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::MoveToForeground()"); +} + +void AppScheduler::MoveToBackground(const sptr& token) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::MoveToBackground()"); +} + +void AppScheduler::KillProcessByAbilityToken(const sptr& token) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::KillProcessByAbilityToken()"); +} + +void AppScheduler::KillProcessesByUserId( + int32_t userId, bool isNeedSendAppSpawnMsg, sptr callback) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::KillProcessesByUserId()"); +} + +AppAbilityState AppScheduler::ConvertToAppAbilityState(const int32_t state) +{ + AppExecFwk::AbilityState abilityState = static_cast(state); + switch (abilityState) { + case AppExecFwk::AbilityState::ABILITY_STATE_FOREGROUND: { + return AppAbilityState::ABILITY_STATE_FOREGROUND; + } + case AppExecFwk::AbilityState::ABILITY_STATE_BACKGROUND: { + return AppAbilityState::ABILITY_STATE_BACKGROUND; + } + default: + return AppAbilityState::ABILITY_STATE_UNDEFINED; + } +} + +AppAbilityState AppScheduler::GetAbilityState() const +{ + return appAbilityState_; +} + +void AppScheduler::OnAbilityRequestDone(const sptr& token, const AppExecFwk::AbilityState state) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::OnAbilityRequestDone()"); +} + +int AppScheduler::KillApplication(const std::string& bundleName, bool clearPageStack, int32_t appIndex) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::KillApplication()"); + return ERR_OK; +} + +void AppScheduler::AttachTimeOut(const sptr& token) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::AttachTimeOut()"); +} + +void AppScheduler::PrepareTerminate(const sptr& token, bool clearMissionFlag) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::PrepareTerminate()"); +} + +void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData& appData) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::OnAppStateChanged()"); +} + +void AppScheduler::NotifyConfigurationChange(const AppExecFwk::Configuration& config, int32_t userId) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::NotifyConfigurationChange()"); +} + +void AppScheduler::NotifyStartResidentProcess(std::vector& bundleInfos) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::NotifyStartResidentProcess()"); +} + +void AppScheduler::NotifyStartKeepAliveProcess(std::vector& bundleInfos) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::NotifyStartKeepAliveProcess()"); +} + +void AppScheduler::OnAppRemoteDied(const std::vector>& abilityTokens) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::OnAppRemoteDied()"); +} + +void AppScheduler::OnStartProcessFailed(sptr token) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::OnStartProcessFailed()"); +} + +void AppScheduler::NotifyAppPreCache(int32_t pid, int32_t userId) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::NotifyAppPreCache()"); +} + +void AppScheduler::UpdateAbilityState(const sptr& token, const AppExecFwk::AbilityState state) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::UpdateAbilityState()"); +} + +void AppScheduler::UpdateExtensionState(const sptr& token, const AppExecFwk::ExtensionState state) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::UpdateExtensionState()"); +} + +void AppScheduler::StartupResidentProcess(const std::vector& bundleInfos) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::StartupResidentProcess()"); +} + +int AppScheduler::GetProcessRunningInfos(std::vector& info) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::GetProcessRunningInfos()"); + return 0; +} + +void AppScheduler::GetRunningProcessInfoByToken(const sptr& token, AppExecFwk::RunningProcessInfo& info) +{ + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::GetRunningProcessInfoByToken()"); +} + +void AppScheduler::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo& info) const +{ + MyFlag::callCount_++; + info.isTestProcess = true; + if (1 == MyFlag::mockFlag_) { + info.isTestProcess = false; + } + TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::GetRunningProcessInfoByPid()"); +} + +bool AppScheduler::IsMemorySizeSufficent() const +{ + return true; +} + +void AppScheduler::StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t) {} + +int AppScheduler::StartUserTest( + const Want& want, const sptr& observer, const AppExecFwk::BundleInfo& bundleInfo, int32_t userId) +{ + return 0; +} + +int AppScheduler::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo& application, bool& debug) +{ + if (pid < 0) { + return -1; + } + + return 0; +} + +int32_t AppScheduler::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string& exitMsg) +{ + if (pid < 0) { + return -1; + } + + return 0; +} + +int AppScheduler::GetAbilityRecordsByProcessID(const int pid, std::vector>& tokens) +{ + return 0; +} + +int32_t AppScheduler::RegisterAppDebugListener(const sptr& listener) +{ + return 0; +} + +int32_t AppScheduler::UnregisterAppDebugListener(const sptr& listener) +{ + return 0; +} + +int32_t AppScheduler::AttachAppDebug(const std::string& bundleName, bool isDebugFromLocal) +{ + return 0; +} + +int32_t AppScheduler::DetachAppDebug(const std::string& bundleName) +{ + return 0; +} + +int32_t AppScheduler::RegisterAbilityDebugResponse(const sptr& response) +{ + return 0; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_app_utils.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_utils.cpp new file mode 100644 index 00000000000..560b03c2a47 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_app_utils.cpp @@ -0,0 +1,255 @@ +/* + * 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. + */ + +#include "mock_app_utils.h" +#include "mock_my_flag.h" + + +namespace OHOS { +namespace AAFwk { + +AppUtils::~AppUtils() {} + +AppUtils::AppUtils() {} + +AppUtils &AppUtils::GetInstance() +{ + static AppUtils utils; + return utils; +} + +bool AppUtils::IsLauncher(const std::string &bundleName) const +{ + return true; +} + +bool AppUtils::IsLauncherAbility(const std::string &abilityName) const +{ + return true; +} + +bool AppUtils::IsInheritWindowSplitScreenMode() +{ + return true; +} + +bool AppUtils::IsSupportAncoApp() +{ + return true; +} + +int32_t AppUtils::GetTimeoutUnitTimeRatio() +{ + return 0; +} + +bool AppUtils::IsSelectorDialogDefaultPossion() +{ + return true; +} + +bool AppUtils::IsStartSpecifiedProcess() +{ + return true; +} + +bool AppUtils::IsUseMultiRenderProcess() +{ + return true; +} + +bool AppUtils::IsLimitMaximumOfRenderProcess() +{ + return true; +} + +bool AppUtils::IsGrantPersistUriPermission() +{ + return true; +} + +bool AppUtils::IsStartOptionsWithAnimation() +{ + return true; +} + +bool AppUtils::IsMultiProcessModel() +{ + return true; +} + +bool AppUtils::IsStartOptionsWithProcessOptions() +{ + return true; +} + +bool AppUtils::EnableMoveUIAbilityToBackgroundApi() +{ + return true; +} + +bool AppUtils::IsLaunchEmbededUIAbility() +{ + return true; +} + +bool AppUtils::IsSupportNativeChildProcess() +{ + return true; +} + +bool AppUtils::IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName) +{ + return true; +} + +bool AppUtils::IsBigMemoryUnrelatedKeepAliveProc(const std::string &bundleName) +{ + return true; +} + +bool AppUtils::IsRequireBigMemoryProcess(const std::string &bundleName) +{ + return true; +} + +void AppUtils::LoadProcessProhibitedFromRestarting() +{ +} + +void AppUtils::LoadRequireBigMemoryApp() +{ +} + +void AppUtils::LoadResidentProcessInExtremeMemory() +{ +} + +bool AppUtils::IsAllowNativeChildProcess(const std::string &appIdentifier) +{ + return true; +} + +void AppUtils::LoadAllowNativeChildProcessApps() +{ +} + +int32_t AppUtils::GetLimitMaximumExtensionsPerProc() +{ + return 0; +} + +int32_t AppUtils::GetLimitMaximumExtensionsPerDevice() +{ + return 0; +} + +std::string AppUtils::GetCacheExtensionTypeList() +{ + return ""; +} + +bool AppUtils::IsAllowStartAbilityWithoutCallerToken(const std::string& bundleName, const std::string& abilityName) +{ + MyFlag::callCount_++; + return true; +} + +void AppUtils::LoadStartAbilityWithoutCallerToken() +{ +} + +std::string AppUtils::GetBrokerDelegateBundleName() +{ + return ""; +} + +int32_t AppUtils::GetCollaboratorBrokerUID() +{ + return 0; +} + +int32_t AppUtils::GetCollaboratorBrokerReserveUID() +{ + return 0; +} + +int32_t AppUtils::MaxChildProcess() +{ + return 0; +} + +bool AppUtils::IsSupportMultiInstance() +{ + return true; +} + +std::string AppUtils::GetMigrateClientBundleName() +{ + return ""; +} + +bool AppUtils::IsConnectSupportCrossUser() +{ + return true; +} + +bool AppUtils::IsPrepareTerminateEnabled() +{ + return true; +} + +bool AppUtils::IsSystemReasonMessage(const std::string &reasonMessage) +{ + return true; +} + +bool AppUtils::IsCacheAbilityEnabled() +{ + return true; +} + +void AppUtils::LoadCacheAbilityList() +{ +} + +bool AppUtils::IsCacheExtensionAbilityByList(const std::string& bundleName, const std::string& abilityName) +{ + return true; +} + +void AppUtils::LoadResidentWhiteList() +{ +} + +const std::vector& AppUtils::GetResidentWhiteList() +{ + std::vector temp; + temp.push_back("com.example.resident.process"); + return temp; +} + +bool AppUtils::InResidentWhiteList(const std::string &bundleName) +{ + return false; +} + +bool AppUtils::IsSupportAppServiceExtension() +{ + return true; +} + +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp new file mode 100755 index 00000000000..b49f03f696f --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_bundle_mgr_helper.cpp @@ -0,0 +1,382 @@ +/* + * 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. + */ + +#include "bundle_mgr_helper.h" +#include "mock_my_flag.h" + +namespace OHOS { +namespace AppExecFwk { + +BundleMgrHelper::BundleMgrHelper() +{ +} + +BundleMgrHelper::~BundleMgrHelper() +{ +} + +void BundleMgrHelper::PreConnect() +{ +} + +void BundleMgrHelper::ConnectTillSuccess() +{ +} + +void BundleMgrHelper::SetBmsReady(bool bmsReady) +{ +} + +ErrCode BundleMgrHelper::GetNameForUid(const int32_t uid, std::string& name) +{ + AAFwk::MyFlag::callCount_++; + if (1 == AAFwk::MyFlag::isBundleName_) { + return ERR_OK; + } + return ERR_APPEXECFWK_SERVICE_INTERNAL_ERROR; +} + +ErrCode BundleMgrHelper::GetNameAndIndexForUid(const int32_t uid, std::string& bundleName, int32_t& appIndex) +{ + return ERR_OK; +} + +bool BundleMgrHelper::GetBundleInfo(const std::string& bundleName, + const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId) +{ + AAFwk::MyFlag::callCount_++; + if (1 == AAFwk::MyFlag::isBundleName_) { + return true; + } + return false; +} + +ErrCode BundleMgrHelper::InstallSandboxApp(const std::string& bundleName, + int32_t dlpType, int32_t userId, int32_t& appIndex) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::UninstallSandboxApp(const std::string& bundleName, + int32_t appIndex, int32_t userId) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetUninstalledBundleInfo(const std::string bundleName, BundleInfo& bundleInfo) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetSandboxBundleInfo(const std::string& bundleName, + int32_t appIndex, int32_t userId, BundleInfo& info) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetSandboxAbilityInfo(const Want& want, + int32_t appIndex, int32_t flags, int32_t userId, AbilityInfo& abilityInfo) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetSandboxExtAbilityInfos(const Want& want, int32_t appIndex, int32_t flags, int32_t userId, + std::vector& extensionInfos) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetSandboxHapModuleInfo( + const AbilityInfo& abilityInfo, int32_t appIndex, int32_t userId, HapModuleInfo& hapModuleInfo) +{ + return ERR_OK; +} + +bool BundleMgrHelper::GetBundleInfo(const std::string& bundleName, + int32_t flags, BundleInfo& bundleInfo, int32_t userId) +{ + return false; +} + +std::string BundleMgrHelper::GetAppIdByBundleName(const std::string& bundleName, const int32_t userId) +{ + return ""; +} + +bool BundleMgrHelper::GetHapModuleInfo(const AbilityInfo& abilityInfo, HapModuleInfo& hapModuleInfo) +{ + return ERR_OK; +} + +std::string BundleMgrHelper::GetAbilityLabel(const std::string& bundleName, const std::string& abilityName) +{ + return ""; +} + + +std::string BundleMgrHelper::GetAppType(const std::string& bundleName) +{ + return ""; +} + +ErrCode BundleMgrHelper::GetBaseSharedBundleInfos(const std::string& bundleName, + std::vector& baseSharedBundleInfos, + GetDependentBundleInfoFlag flag) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetBundleInfoForSelf(int32_t flags, BundleInfo& bundleInfo) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetDependentBundleInfo(const std::string& sharedBundleName, BundleInfo& sharedBundleInfo, + GetDependentBundleInfoFlag flag) +{ + return ERR_OK; +} + +bool BundleMgrHelper::GetGroupDir(const std::string& dataGroupId, std::string& dir) +{ + return false; +} + +sptr BundleMgrHelper::GetOverlayManagerProxy() +{ + sptr getOverlay_ = nullptr; + return getOverlay_; +} + +bool BundleMgrHelper::QueryAbilityInfo(const Want& want, AbilityInfo& abilityInfo) +{ + return false; +} + +bool BundleMgrHelper::QueryAbilityInfo(const Want& want, int32_t flags, int32_t userId, AbilityInfo& abilityInfo) +{ + return true; +} + +bool BundleMgrHelper::GetBundleInfos( + int32_t flags, std::vector& bundleInfos, int32_t userId) +{ + return false; +} + +sptr BundleMgrHelper::GetQuickFixManagerProxy() +{ + return nullptr; +} + +bool BundleMgrHelper::ProcessPreload(const Want& want) +{ + return false; +} + +sptr BundleMgrHelper::GetAppControlProxy() +{ + return nullptr; +} + +bool BundleMgrHelper::QueryExtensionAbilityInfos(const Want& want, const int32_t& flag, const int32_t& userId, + std::vector& extensionInfos) +{ + return false; +} + +ErrCode BundleMgrHelper::GetBundleInfoV9(const std::string& bundleName, + int32_t flags, BundleInfo& bundleInfo, int32_t userId) +{ + return ERR_OK; +} + +bool BundleMgrHelper::GetApplicationInfo( + const std::string& appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo& appInfo) +{ + return true; +} + +bool BundleMgrHelper::GetApplicationInfo(const std::string& appName, + int32_t flags, int32_t userId, ApplicationInfo& appInfo) +{ + return false; +} + +bool BundleMgrHelper::GetApplicationInfoWithAppIndex( + const std::string& appName, int32_t appIndex, int32_t userId, ApplicationInfo& appInfo) +{ + return false; +} + +ErrCode BundleMgrHelper::GetJsonProfile(ProfileType profileType, const std::string& bundleName, + const std::string& moduleName, std::string& profile, int32_t userId) +{ + return ERR_OK; +} + +bool BundleMgrHelper::UnregisterBundleEventCallback(const sptr& bundleEventCallback) +{ + return false; +} + +bool BundleMgrHelper::QueryExtensionAbilityInfoByUri( + const std::string& uri, int32_t userId, ExtensionAbilityInfo& extensionAbilityInfo) +{ + return false; +} + +bool BundleMgrHelper::ImplicitQueryInfoByPriority( + const Want& want, int32_t flags, int32_t userId, AbilityInfo& abilityInfo, ExtensionAbilityInfo& extensionInfo) +{ + return false; +} + +bool BundleMgrHelper::QueryAbilityInfoByUri(const std::string& abilityUri, int32_t userId, AbilityInfo& abilityInfo) +{ + return false; +} + +bool BundleMgrHelper::QueryAbilityInfo( + const Want& want, int32_t flags, int32_t userId, AbilityInfo& abilityInfo, const sptr& callBack) +{ + return false; +} + +void BundleMgrHelper::UpgradeAtomicService(const Want& want, int32_t userId) {} + +bool BundleMgrHelper::ImplicitQueryInfos(const Want& want, int32_t flags, int32_t userId, bool withDefault, + std::vector& abilityInfos, std::vector& extensionInfos, + bool& findDefaultApp) +{ + return false; +} + +bool BundleMgrHelper::CleanBundleDataFiles(const std::string& bundleName, int32_t userId, int32_t appCloneIndex) +{ + return false; +} + +bool BundleMgrHelper::QueryDataGroupInfos(const std::string& bundleName, + int32_t userId, std::vector& infos) +{ + return false; +} + +bool BundleMgrHelper::RegisterBundleEventCallback(const sptr& bundleEventCallback) +{ + return false; +} + +bool BundleMgrHelper::GetBundleInfos( + const BundleFlag flag, std::vector& bundleInfos, int32_t userId) +{ + return false; +} + +bool BundleMgrHelper::GetHapModuleInfo(const AbilityInfo& abilityInfo, int32_t userId, HapModuleInfo& hapModuleInfo) +{ + return false; +} + +bool BundleMgrHelper::QueryAppGalleryBundleName(std::string& bundleName) +{ + return false; +} + +ErrCode BundleMgrHelper::GetUidByBundleName(const std::string& bundleName, int32_t userId, int32_t appCloneIndex) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::QueryExtensionAbilityInfosOnlyWithTypeName(const std::string& extensionTypeName, + const uint32_t flag, const int32_t userId, std::vector& extensionInfos) +{ + return ERR_OK; +} + +sptr BundleMgrHelper::GetDefaultAppProxy() +{ + return nullptr; +} + +ErrCode BundleMgrHelper::GetLaunchWantForBundle(const std::string& bundleName, Want& want, int32_t userId) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::QueryCloneAbilityInfo( + const ElementName& element, int32_t flags, int32_t appCloneIndex, AbilityInfo& abilityInfo, int32_t userId) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetCloneBundleInfo( + const std::string& bundleName, int32_t flags, int32_t appCloneIndex, BundleInfo& bundleInfo, int32_t userId) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::QueryCloneExtensionAbilityInfoWithAppIndex(const ElementName& element, + int32_t flags, int32_t appCloneIndex, ExtensionAbilityInfo& extensionInfo, int32_t userId) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetCloneAppIndexes(const std::string& bundleName, + std::vector& appIndexes, int32_t userId) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetSignatureInfoByBundleName(const std::string& bundleName, SignatureInfo& signatureInfo) +{ + return ERR_OK; +} + +std::string BundleMgrHelper::GetStringById( + const std::string& bundleName, const std::string& moduleName, uint32_t resId, int32_t userId) +{ + return ""; +} + +std::string BundleMgrHelper::GetDataDir(const std::string& bundleName, const int32_t appIndex) +{ + return ""; +} + +ErrCode BundleMgrHelper::GetPluginInfosForSelf(std::vector &pluginBundleInfos) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::GetPluginAbilityInfo(const std::string &hostBundleName, const std::string &pluginBundleName, + const std::string &pluginModuleName, const std::string &pluginAbilityName, int32_t userId, + AbilityInfo &pluginAbilityInfo) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::RegisterPluginEventCallback(sptr pluginEventCallback) +{ + return ERR_OK; +} + +ErrCode BundleMgrHelper::UnregisterPluginEventCallback(sptr pluginEventCallback) +{ + return ERR_OK; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_my_flag.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_my_flag.cpp new file mode 100644 index 00000000000..2d4bacd6a33 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_my_flag.cpp @@ -0,0 +1,24 @@ +/* + * 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. + */ + +#include "mock_my_flag.h" + +namespace OHOS { +namespace AAFwk { +int MyFlag::mockFlag_ = 0; +int MyFlag::isBundleName_ = 0; +int MyFlag::callCount_ = 0; +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/ability_permission_util_second_test/mock/src/mock_permission_verification.cpp b/test/unittest/ability_permission_util_second_test/mock/src/mock_permission_verification.cpp new file mode 100644 index 00000000000..cc35c2c8044 --- /dev/null +++ b/test/unittest/ability_permission_util_second_test/mock/src/mock_permission_verification.cpp @@ -0,0 +1,135 @@ +/* + * 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. + */ + +#include "mock_permission_verification.h" + +namespace OHOS { +namespace AAFwk { + +bool PermissionVerification::VerifyCallingPermission(const std::string &permissionName) const +{ + return !!(MyFlag::mockFlag_); +} +bool PermissionVerification::IsSACall() const +{ + MyFlag::callCount_++; + return false; +} +bool PermissionVerification::IsShellCall() const +{ + MyFlag::callCount_++; + return false; +} +bool PermissionVerification::CheckSpecificSystemAbilityAccessPermission() const +{ + return !!(MyFlag::mockFlag_); +} +bool PermissionVerification::VerifyRunningInfoPerm() const +{ + return !!(MyFlag::mockFlag_); +} +bool PermissionVerification::VerifyControllerPerm() const +{ + return !!(MyFlag::mockFlag_); +} +#ifdef WITH_DLP +bool PermissionVerification::VerifyDlpPermission(Want &want) const +{ + return !!(MyFlag::mockFlag_); +} +#endif // WITH_DLP +int PermissionVerification::VerifyAccountPermission() const +{ + return MyFlag::mockFlag_; +} +bool PermissionVerification::VerifyMissionPermission() const +{ + return !!(MyFlag::mockFlag_); +} +int PermissionVerification::VerifyAppStateObserverPermission() const +{ + return MyFlag::mockFlag_; +} +int32_t PermissionVerification::VerifyUpdateConfigurationPerm() const +{ + return static_cast(MyFlag::mockFlag_); +} +bool PermissionVerification::VerifyInstallBundlePermission() const +{ + return !!(MyFlag::mockFlag_); +} +bool PermissionVerification::VerifyGetBundleInfoPrivilegedPermission() const +{ + return !!(MyFlag::mockFlag_); +} +int PermissionVerification::CheckCallDataAbilityPermission(const VerificationInfo &verificationInfo, bool isShell) const +{ + return MyFlag::mockFlag_; +} +int PermissionVerification::CheckCallServiceAbilityPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::mockFlag_; +} +int PermissionVerification::CheckCallAbilityPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::mockFlag_; +} +int PermissionVerification::CheckCallServiceExtensionPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::mockFlag_; +} +int PermissionVerification::CheckStartByCallPermission(const VerificationInfo &verificationInfo) const +{ + return MyFlag::mockFlag_; +} +unsigned int PermissionVerification::GetCallingTokenID() const +{ + return static_cast(MyFlag::mockFlag_); +} +bool PermissionVerification::JudgeStartInvisibleAbility(const uint32_t accessTokenId, const bool visible) const +{ + return !!(MyFlag::mockFlag_); +} +bool PermissionVerification::JudgeStartAbilityFromBackground(const bool isBackgroundCall) const +{ + return !!(MyFlag::mockFlag_); +} +bool PermissionVerification::JudgeAssociatedWakeUp(const uint32_t accessTokenId, const bool associatedWakeUp) const +{ + return !!(MyFlag::mockFlag_); +} +int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo &verificationInfo) const +{ + return MyFlag::mockFlag_; +} +bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const +{ + return true; +} +bool PermissionVerification::VerifyPrepareTerminatePermission() const +{ + return true; +} +bool PermissionVerification::IsSystemAppCall() const +{ + return true; +} + +bool PermissionVerification::VerifySetProcessCachePermission() const +{ + return true; +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file -- Gitee