diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index 94c8a8e6dde48e88e30a7a71b00a403e3e690acf..92af04d7c15a7f3da34e525ee79f6d64e74027e8 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -569,18 +569,6 @@ bool BundleMgrHelper::ProcessPreload(const Want &want) return bundleMgr->ProcessPreload(newWant); } -sptr BundleMgrHelper::GetAppControlProxy() -{ - TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "called"); - auto bundleMgr = Connect(); - if (bundleMgr == nullptr) { - TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "null bundleMgr"); - return nullptr; - } - - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - return bundleMgr->GetAppControlProxy(); -} bool BundleMgrHelper::QueryExtensionAbilityInfos(const Want &want, const int32_t &flag, const int32_t &userId, std::vector &extensionInfos) diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index 3862786ed6c4f836224d8800ce8b9c26fbaa2b73..e3ff272f246319e20f8ff9bacceda486c70d37ac 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -67,7 +67,6 @@ public: std::vector &bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID); sptr GetQuickFixManagerProxy(); bool ProcessPreload(const Want &want); - sptr GetAppControlProxy(); bool QueryExtensionAbilityInfos(const Want &want, const int32_t &flag, const int32_t &userId, std::vector &extensionInfos); ErrCode GetBundleInfoV9( diff --git a/services/abilitymgr/include/utils/ability_util.h b/services/abilitymgr/include/utils/ability_util.h index 60db8367785bfe7c5769c49b49039eab285e8714..0fc160b77ca1fda7114235cd92263b47983090e6 100644 --- a/services/abilitymgr/include/utils/ability_util.h +++ b/services/abilitymgr/include/utils/ability_util.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -22,6 +22,7 @@ #include "ability_config.h" #include "ability_manager_client.h" #include "ability_manager_errors.h" +#include "app_control_client.h" #include "app_jump_control_rule.h" #include "bundle_mgr_helper.h" #include "hilog_tag_wrapper.h" @@ -217,12 +218,8 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi TAG_LOGE(AAFwkTag::ABILITYMGR, "GetBundleManagerHelper failed"); return false; } - auto appControlMgr = bundleMgrHelper->GetAppControlProxy(); - if (appControlMgr == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Get appControlMgr failed"); - return false; - } - int ret = IN_PROCESS_CALL(appControlMgr->ConfirmAppJumpControlRule(callerPkg, targetPkg, userId)); + int ret = IN_PROCESS_CALL(AppExecFwk::AppControlClient::GetInstance().ConfirmAppJumpControlRule(callerPkg, + targetPkg, userId)); return ret == ERR_OK; } diff --git a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp index a49d513d223ea3080f358a4055d88cab62976fd5..44ed6a9b2f3de2857d6a486896aee04b2c68403a 100644 --- a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -17,6 +17,7 @@ #include "ability_util.h" #include "accesstoken_kit.h" +#include "app_control_client.h" #include "hitrace_meter.h" #include "permission_constants.h" #include "start_ability_utils.h" @@ -111,14 +112,9 @@ bool AbilityJumpInterceptor::CheckControl(std::shared_ptrGetAppControlProxy(); - if (appControlMgr == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appControlMgr"); - return false; - } - if (IN_PROCESS_CALL(appControlMgr->GetAppJumpControlRule(callerBundleName, targetBundleName, - userId, controlRule)) != ERR_OK) { + if (IN_PROCESS_CALL(AppExecFwk::AppControlClient::GetInstance().GetAppJumpControlRule(callerBundleName, + targetBundleName, userId, controlRule)) != ERR_OK) { TAG_LOGI(AAFwkTag::ABILITYMGR, "no jump rule"); return true; } diff --git a/services/abilitymgr/src/interceptor/control_interceptor.cpp b/services/abilitymgr/src/interceptor/control_interceptor.cpp index a16512aad2d1ce5d2158caae64eade245f2e5410..a7d637d9116b0578f1ca35b6cd0f04e6042e84a6 100644 --- a/services/abilitymgr/src/interceptor/control_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/control_interceptor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -17,6 +17,7 @@ #include "ability_util.h" #include "appexecfwk_errors.h" +#include "app_control_client.h" #include "hitrace_meter.h" namespace OHOS { @@ -78,18 +79,13 @@ bool ControlInterceptor::CheckControl(const Want &want, int32_t userId, // get disposed status std::string bundleName = want.GetBundle(); - auto appControlMgr = bundleMgrHelper->GetAppControlProxy(); - if (appControlMgr == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appControlMgr"); - return false; - } HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "GetAppRunningControlRule"); std::string identity = IPCSkeleton::ResetCallingIdentity(); if (identity == "") { TAG_LOGE(AAFwkTag::ABILITYMGR, "getId fail"); } - auto ret = appControlMgr->GetAppRunningControlRule(bundleName, userId, controlRule); + auto ret = AppExecFwk::AppControlClient::GetInstance().GetAppRunningControlRule(bundleName, userId, controlRule); if (ret == ERR_BUNDLE_MANAGER_PERMISSION_DENIED) { IPCSkeleton::SetCallingIdentity(identity, true); } else { diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index b6850d7c04c3f0fb1df0e6658b98c94fa97059ac..7a95ef4305a91bcb80c0be36e84662cb67c376c4 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -16,6 +16,7 @@ #include "interceptor/disposed_rule_interceptor.h" #include "ability_manager_service.h" +#include "app_control_client.h" #include "global_constant.h" #include "hitrace_meter.h" #include "iservice_registry.h" @@ -96,20 +97,15 @@ bool DisposedRuleInterceptor::CheckControl(const Want &want, int32_t userId, // get disposed status std::string bundleName = want.GetBundle(); - auto appControlMgr = bundleMgrHelper->GetAppControlProxy(); - if (appControlMgr == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "null appControlMgr"); - return false; - } std::vector disposedRuleList; { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "GetAbilityRunningControlRule"); int32_t ret = ERR_OK; if (appIndex > 0 && appIndex <= AbilityRuntime::GlobalConstant::MAX_APP_CLONE_INDEX) { - ret = IN_PROCESS_CALL(appControlMgr->GetAbilityRunningControlRule(bundleName, + ret = IN_PROCESS_CALL(AppExecFwk::AppControlClient::GetInstance().GetAbilityRunningControlRule(bundleName, userId, disposedRuleList, appIndex)); } else { - ret = IN_PROCESS_CALL(appControlMgr->GetAbilityRunningControlRule(bundleName, + ret = IN_PROCESS_CALL(AppExecFwk::AppControlClient::GetInstance().GetAbilityRunningControlRule(bundleName, userId, disposedRuleList, 0)); } if (ret != ERR_OK || disposedRuleList.empty()) { diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp index a6731b31a3925d34cb6bb0a3527a3e698c8d3eee..986b7964813490f30d7cfef89d908d6311c0c171 100755 --- a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp +++ b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -101,7 +101,6 @@ void BundleMgrHelperFuzztest1(bool boolParam, std::string &stringParam, int32_t bmHelper->GetBundleInfos(static_cast(int32Param), bundleInfos, int32Param); bmHelper->GetQuickFixManagerProxy(); bmHelper->ProcessPreload(want); - bmHelper->GetAppControlProxy(); bmHelper->QueryExtensionAbilityInfos(want, int32Param, int32Param, extensionInfos); bmHelper->GetBundleInfoV9(stringParam, int32Param, bundleInfo, int32Param); } diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/bundlemgr/mock_app_control_manager.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/bundlemgr/mock_app_control_manager.h index 3334fd435b028365d11da2c77cd270b6f4ae5eef..936099b6bbc9c91e1ef07cb905bc70214c120cd7 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/bundlemgr/mock_app_control_manager.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/bundlemgr/mock_app_control_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -16,17 +16,18 @@ #ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_CONTROL_MANAGER_H #define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_CONTROL_MANAGER_H -#include "want.h" #include -#include "app_control_interface.h" + #include "iremote_proxy.h" +#include "mock_iapp_control_mgr.h" +#include "want.h" namespace OHOS { namespace AppExecFwk { namespace { const int32_t UNSPECIFIED_USER_ID = -2; } -class AppControlProxy : public IRemoteProxy { +class AppControlProxy : public IRemoteProxy { public: using Want = OHOS::AAFwk::Want; @@ -34,43 +35,77 @@ public: virtual ~AppControlProxy(); // for app install control rule - virtual ErrCode AddAppInstallControlRule(const std::vector& appIds, - const AppInstallControlRuleType controlRuleType, int32_t userId) override; - virtual ErrCode DeleteAppInstallControlRule(const AppInstallControlRuleType controlRuleType, - const std::vector& appIds, int32_t userId) override; - virtual ErrCode DeleteAppInstallControlRule( - const AppInstallControlRuleType controlRuleType, int32_t userId) override; - virtual ErrCode GetAppInstallControlRule( - const AppInstallControlRuleType controlRuleType, int32_t userId, std::vector& appIds) override; + ErrCode AddAppInstallControlRule(const std::vector &appIds, + const AppInstallControlRuleType controlRuleType, int32_t userId, int32_t &funcResult) override; + + ErrCode DeleteAppInstallControlRule(const AppInstallControlRuleType controlRuleType, + const std::vector &appIds, int32_t userId, int32_t &funcResult) override; + + ErrCode DeleteAppInstallControlRule( + const AppInstallControlRuleType controlRuleType, int32_t userId, int32_t &funcResult) override; + + ErrCode GetAppInstallControlRule(const AppInstallControlRuleType controlRuleType, int32_t userId, + std::vector &appIds, int32_t &funcResult) override; + // for app running control rule - virtual ErrCode AddAppRunningControlRule( - const std::vector& controlRule, int32_t userId) override; - virtual ErrCode DeleteAppRunningControlRule( - const std::vector& controlRule, int32_t userId) override; - virtual ErrCode DeleteAppRunningControlRule(int32_t userId) override; - virtual ErrCode GetAppRunningControlRule(int32_t userId, std::vector& appIds) override; - virtual ErrCode GetAppRunningControlRule( - const std::string& bundleName, int32_t userId, AppRunningControlRuleResult& controlRuleResult) override; - - virtual ErrCode GetAbilityRunningControlRule(const std::string &bundleName, int32_t userId, - std::vector &disposedRuleList, int32_t appIndex = 0) override; - - virtual ErrCode ConfirmAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName, - int32_t userId) override; - virtual ErrCode AddAppJumpControlRule(const std::vector &controlRules, int32_t userId) override; - virtual ErrCode DeleteAppJumpControlRule(const std::vector &controlRules, - int32_t userId) override; - virtual ErrCode DeleteRuleByCallerBundleName(const std::string &callerBundleName, int32_t userId) override; - virtual ErrCode DeleteRuleByTargetBundleName(const std::string &targetBundleName, int32_t userId) override; - virtual ErrCode GetAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName, - int32_t userId, AppJumpControlRule &controlRule) override; - - virtual ErrCode SetDisposedStatus( - const std::string& appId, const Want& want, int32_t userId = UNSPECIFIED_USER_ID) override; - virtual ErrCode DeleteDisposedStatus( - const std::string& appId, int32_t userId = UNSPECIFIED_USER_ID) override; - virtual ErrCode GetDisposedStatus( - const std::string& appId, Want& want, int32_t userId = UNSPECIFIED_USER_ID) override; + ErrCode AddAppRunningControlRule( + const std::vector &controlRules, int32_t userId, int32_t &funcResult) override; + ErrCode DeleteAppRunningControlRule( + const std::vector &controlRules, int32_t userId, int32_t &funcResult) override; + ErrCode DeleteAppRunningControlRule(int32_t userId, int32_t &funcResult) override; + ErrCode GetAppRunningControlRule(int32_t userId, std::vector &appIds, int32_t &funcResult) override; + ErrCode GetAppRunningControlRule(const std::string &bundleName, int32_t userId, + AppRunningControlRuleResult &controlRule, int32_t &funcResult) override; + + // for app jump control rule + ErrCode ConfirmAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName, + int32_t userId, int32_t &funcResult) override; + ErrCode AddAppJumpControlRule(const std::vector &controlRules, int32_t userId, + int32_t &funcResult) override; + ErrCode DeleteAppJumpControlRule(const std::vector &controlRules, + int32_t userId, int32_t &funcResult) override; + ErrCode DeleteRuleByCallerBundleName(const std::string &callerBundleName, int32_t userId, + int32_t &funcResult) override; + ErrCode DeleteRuleByTargetBundleName(const std::string &targetBundleName, int32_t userId, + int32_t &funcResult) override; + ErrCode GetAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName, + int32_t userId, AppJumpControlRule &controlRule, int32_t &funcResult) override; + + ErrCode SetDisposedStatus( + const std::string &appId, const Want &want, int32_t userId, int32_t &funcResult) override; + + ErrCode DeleteDisposedStatus( + const std::string &appId, int32_t userId, int32_t &funcResult) override; + + ErrCode GetDisposedStatus( + const std::string &appId, int32_t userId, Want &want, int32_t &funcResult) override; + + ErrCode SetDisposedRule( + const std::string &appId, int32_t userId, DisposedRule &DisposedRule, int32_t &funcResult) override; + + ErrCode GetDisposedRule( + const std::string &appId, int32_t userId, DisposedRule &DisposedRule, int32_t &funcResult) override; + + ErrCode GetAbilityRunningControlRule(const std::string &bundleName, int32_t userId, + int32_t appIndex, std::vector& disposedRules, int32_t &funcResult) override; + + ErrCode SetDisposedRuleForCloneApp(const std::string &appId, int32_t appIndex, int32_t userId, + DisposedRule &DisposedRule, int32_t &funcResult) override; + + ErrCode GetDisposedRuleForCloneApp(const std::string &appId, int32_t appIndex, int32_t userId, + DisposedRule &DisposedRule, int32_t &funcResult) override; + + ErrCode DeleteDisposedRuleForCloneApp( + const std::string &appId, int32_t appIndex, int32_t userId, int32_t &funcResult) override; + + ErrCode GetUninstallDisposedRule(const std::string &appIdentifier, int32_t appIndex, + int32_t userId, UninstallDisposedRule &rule, int32_t &funcResult) override; + + ErrCode SetUninstallDisposedRule(const std::string &appIdentifier, const UninstallDisposedRule &rule, + int32_t appIndex, int32_t userId, int32_t &funcResult) override; + + ErrCode DeleteUninstallDisposedRule(const std::string &appIdentifier, int32_t appIndex, + int32_t userId, int32_t &funcResult) override; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/bundlemgr/mock_iapp_control_mgr.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/bundlemgr/mock_iapp_control_mgr.h new file mode 100644 index 0000000000000000000000000000000000000000..a4f9072931fc6f68e0c0ce598544076c3bbeed68 --- /dev/null +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/bundlemgr/mock_iapp_control_mgr.h @@ -0,0 +1,241 @@ +/* + * 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_IAPP_CONTROL_MGR_H +#define MOCK_OHOS_ABILITY_RUNTIME__MOCK_IAPP_CONTROL_MGR_H + +#include +#include +#include +#include +#include "app_jump_control_rule.h" +#include "app_running_control_rule.h" +#include "app_running_control_rule_result.h" +#include "disposed_rule.h" +#include "iapp_control_mgr_types.h" +#include "want.h" + +using OHOS::AAFwk::Want; +using OHOS::AppExecFwk::AppJumpControlRule; +using OHOS::AppExecFwk::AppRunningControlRule; +using OHOS::AppExecFwk::AppRunningControlRuleResult; +using OHOS::AppExecFwk::DisposedRule; +using OHOS::AppExecFwk::UninstallDisposedRule; +using OHOS::AppExecFwk::DisposedRuleConfiguration; + +namespace OHOS { +namespace AppExecFwk { +using namespace OHOS::AppExecFwk; + +enum class IAppControlMgrIpcCode { + COMMAND_ADD_APP_INSTALL_CONTROL_RULE = 0, + COMMAND_DELETE_APP_INSTALL_CONTROL_RULE = 1, + COMMAND_DELETE_APP_INSTALL_CONTROL_RULE_IN_APPINSTALLCONTROLRULETYPE_IN_INT_OUT_INT = 2, + COMMAND_GET_APP_INSTALL_CONTROL_RULE = 3, + COMMAND_ADD_APP_RUNNING_CONTROL_RULE = 4, + COMMAND_DELETE_APP_RUNNING_CONTROL_RULE = 5, + COMMAND_DELETE_APP_RUNNING_CONTROL_RULE_IN_INT_OUT_INT = 6, + COMMAND_GET_APP_RUNNING_CONTROL_RULE = 7, + COMMAND_GET_APP_RUNNING_CONTROL_RULE_IN_STRING_IN_INT_OUT_APPRUNNINGCONTROLRULERESULT_OUT_INT = 8, + COMMAND_SET_DISPOSED_STATUS = 9, + COMMAND_DELETE_DISPOSED_STATUS = 10, + COMMAND_GET_DISPOSED_STATUS = 11, + COMMAND_CONFIRM_APP_JUMP_CONTROL_RULE = 12, + COMMAND_ADD_APP_JUMP_CONTROL_RULE = 13, + COMMAND_DELETE_APP_JUMP_CONTROL_RULE = 14, + COMMAND_DELETE_RULE_BY_CALLER_BUNDLE_NAME = 15, + COMMAND_DELETE_RULE_BY_TARGET_BUNDLE_NAME = 16, + COMMAND_GET_APP_JUMP_CONTROL_RULE = 17, + COMMAND_GET_DISPOSED_RULE = 18, + COMMAND_SET_DISPOSED_RULE = 19, + COMMAND_GET_ABILITY_RUNNING_CONTROL_RULE = 20, + COMMAND_GET_DISPOSED_RULE_FOR_CLONE_APP = 21, + COMMAND_SET_DISPOSED_RULE_FOR_CLONE_APP = 22, + COMMAND_DELETE_DISPOSED_RULE_FOR_CLONE_APP = 23, + COMMAND_GET_UNINSTALL_DISPOSED_RULE = 24, + COMMAND_SET_UNINSTALL_DISPOSED_RULE = 25, + COMMAND_DELETE_UNINSTALL_DISPOSED_RULE = 26, +}; + +class MockIAppControlMgr : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AppExecFwk.IAppControlMgr"); + + virtual ErrCode AddAppInstallControlRule( + const std::vector& appIds, + AppInstallControlRuleType controlRuleType, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteAppInstallControlRule( + AppInstallControlRuleType controlRuleType, + const std::vector& appIds, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteAppInstallControlRule( + AppInstallControlRuleType controlRuleType, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode GetAppInstallControlRule( + AppInstallControlRuleType controlRuleType, + int32_t userId, + std::vector& appIds, + int32_t& funcResult) = 0; + + virtual ErrCode AddAppRunningControlRule( + const std::vector& controlRules, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteAppRunningControlRule( + const std::vector& controlRules, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteAppRunningControlRule( + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode GetAppRunningControlRule( + int32_t userId, + std::vector& appIds, + int32_t& funcResult) = 0; + + virtual ErrCode GetAppRunningControlRule( + const std::string& bundleName, + int32_t userId, + AppRunningControlRuleResult& controlRuleResult, + int32_t& funcResult) = 0; + + virtual ErrCode SetDisposedStatus( + const std::string& appId, + const Want& want, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteDisposedStatus( + const std::string& appId, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode GetDisposedStatus( + const std::string& appId, + int32_t userId, + Want& want, + int32_t& funcResult) = 0; + + virtual ErrCode ConfirmAppJumpControlRule( + const std::string& callerBundleName, + const std::string& targetBundleName, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode AddAppJumpControlRule( + const std::vector& controlRules, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteAppJumpControlRule( + const std::vector& controlRules, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteRuleByCallerBundleName( + const std::string& callerBundleName, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteRuleByTargetBundleName( + const std::string& targetBundleName, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode GetAppJumpControlRule( + const std::string& callerBundleName, + const std::string& targetBundleName, + int32_t userId, + AppJumpControlRule& controlRule, + int32_t& funcResult) = 0; + + virtual ErrCode GetDisposedRule( + const std::string& appId, + int32_t userId, + DisposedRule& disposedRule, + int32_t& funcResult) = 0; + + virtual ErrCode SetDisposedRule( + const std::string& appId, + int32_t userId, + DisposedRule& disposedRule, + int32_t& funcResult) = 0; + + virtual ErrCode GetAbilityRunningControlRule( + const std::string& bundleName, + int32_t userId, + int32_t appIndex, + std::vector& disposedRules, + int32_t& funcResult) = 0; + + virtual ErrCode GetDisposedRuleForCloneApp( + const std::string& appId, + int32_t appIndex, + int32_t userId, + DisposedRule& disposedRule, + int32_t& funcResult) = 0; + + virtual ErrCode SetDisposedRuleForCloneApp( + const std::string& appId, + int32_t appIndex, + int32_t userId, + DisposedRule& disposedRule, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteDisposedRuleForCloneApp( + const std::string& appId, + int32_t appIndex, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode GetUninstallDisposedRule( + const std::string& appIdentifier, + int32_t appIndex, + int32_t userId, + UninstallDisposedRule& rule, + int32_t& funcResult) = 0; + + virtual ErrCode SetUninstallDisposedRule( + const std::string& appIdentifier, + const UninstallDisposedRule& rule, + int32_t appIndex, + int32_t userId, + int32_t& funcResult) = 0; + + virtual ErrCode DeleteUninstallDisposedRule( + const std::string& appIdentifier, + int32_t appIndex, + int32_t userId, + int32_t& funcResult) = 0; + +protected: + const int VECTOR_MAX_SIZE = 102400; + const int LIST_MAX_SIZE = 102400; + const int SET_MAX_SIZE = 102400; + const int MAP_MAX_SIZE = 102400; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // MOCK_OHOS_ABILITY_RUNTIME__MOCK_IAPP_CONTROL_MGR_H \ No newline at end of file diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/bundlemgr/mock_app_control_manager.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/bundlemgr/mock_app_control_manager.cpp index 0a9c9a17caac5324451c4d29b7591ba7f7686f07..2b9e3de134e49e11d7f6cdca44fc73786dd369d3 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/bundlemgr/mock_app_control_manager.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/bundlemgr/mock_app_control_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -17,7 +17,7 @@ namespace OHOS { namespace AppExecFwk { -AppControlProxy::AppControlProxy(const sptr& object) : IRemoteProxy(object) +AppControlProxy::AppControlProxy(const sptr& object) : IRemoteProxy(object) { } @@ -25,54 +25,55 @@ AppControlProxy::~AppControlProxy() { } -ErrCode AppControlProxy::AddAppInstallControlRule(const std::vector& appIds, - const AppInstallControlRuleType controlRuleType, int32_t userId) +ErrCode AppControlProxy::AddAppInstallControlRule(const std::vector &appIds, + const AppInstallControlRuleType controlRuleType, int32_t userId, int32_t &funcResult) { return ERR_OK; } ErrCode AppControlProxy::DeleteAppInstallControlRule(const AppInstallControlRuleType controlRuleType, - const std::vector& appIds, int32_t userId) + const std::vector &appIds, int32_t userId, int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::DeleteAppInstallControlRule( - const AppInstallControlRuleType controlRuleType, int32_t userId) +ErrCode AppControlProxy::DeleteAppInstallControlRule(const AppInstallControlRuleType controlRuleType, int32_t userId, + int32_t &funcResult) { return ERR_OK; } - -ErrCode AppControlProxy::GetAppInstallControlRule( - const AppInstallControlRuleType controlRuleType, int32_t userId, std::vector& appIds) +ErrCode AppControlProxy::GetAppInstallControlRule(const AppInstallControlRuleType controlRuleType, int32_t userId, + std::vector &appIds, int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::AddAppRunningControlRule( - const std::vector& controlRules, int32_t userId) +// for app running control rule +ErrCode AppControlProxy::AddAppRunningControlRule(const std::vector &controlRules, + int32_t userId, int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::DeleteAppRunningControlRule( - const std::vector& controlRules, int32_t userId) +ErrCode AppControlProxy::DeleteAppRunningControlRule(const std::vector &controlRules, + int32_t userId, int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::DeleteAppRunningControlRule(int32_t userId) +ErrCode AppControlProxy::DeleteAppRunningControlRule(int32_t userId, int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::GetAppRunningControlRule(int32_t userId, std::vector& appIds) +ErrCode AppControlProxy::GetAppRunningControlRule(int32_t userId, std::vector &appIds, + int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::GetAppRunningControlRule( - const std::string& bundleName, int32_t userId, AppRunningControlRuleResult& controlRuleResult) +ErrCode AppControlProxy::GetAppRunningControlRule(const std::string &bundleName, int32_t userId, + AppRunningControlRuleResult &controlRuleResult, int32_t &funcResult) { if (bundleName.compare("com.test.control2") == 0) { return ERR_INVALID_VALUE; @@ -90,70 +91,125 @@ ErrCode AppControlProxy::GetAppRunningControlRule( return ERR_OK; } -ErrCode AppControlProxy::GetAbilityRunningControlRule( - const std::string &bundleName, int32_t userId, std::vector &disposedRuleList, int32_t appIndex) +// for app jump control rule +ErrCode AppControlProxy::ConfirmAppJumpControlRule(const std::string &callerBundleName, + const std::string &targetBundleName, int32_t userId, int32_t &funcResult) { - if (bundleName == "com.acts.disposedrulehap") { - DisposedRule disposedRule; - ElementName element; + return ERR_OK; +} - disposedRule.priority = 0; - disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_ABILITY; - disposedRule.controlType = AppExecFwk::ControlType::DISALLOWED_LIST; - element.SetAbilityName("MainAbility2"); - element.SetModuleName("entry"); - disposedRule.elementList.push_back(element); - (*disposedRule.want).SetElementName("com.example.disposedruletest", - "DisposedAbility2"); - disposedRuleList.push_back(disposedRule); - return ERR_OK; - } - return ERR_INVALID_VALUE; +ErrCode AppControlProxy::AddAppJumpControlRule(const std::vector &controlRules, int32_t userId, + int32_t &funcResult) +{ + return ERR_OK; } -ErrCode AppControlProxy::ConfirmAppJumpControlRule(const std::string &callerBundleName, - const std::string &targetBundleName, int32_t userId) +ErrCode AppControlProxy::DeleteAppJumpControlRule(const std::vector &controlRules, int32_t userId, + int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::AddAppJumpControlRule(const std::vector &controlRules, int32_t userId) +ErrCode AppControlProxy::DeleteRuleByCallerBundleName(const std::string &callerBundleName, int32_t userId, + int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::DeleteAppJumpControlRule(const std::vector &controlRules, int32_t userId) +ErrCode AppControlProxy::DeleteRuleByTargetBundleName(const std::string &targetBundleName, int32_t userId, + int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::DeleteRuleByCallerBundleName(const std::string &callerBundleName, int32_t userId) +ErrCode AppControlProxy::GetAppJumpControlRule(const std::string &callerBundleName, + const std::string &targetBundleName, int32_t userId, AppJumpControlRule &controlRule, int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::DeleteRuleByTargetBundleName(const std::string &targetBundleName, int32_t userId) +ErrCode AppControlProxy::SetDisposedStatus(const std::string &appId, const Want &want, int32_t userId, + int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::GetAppJumpControlRule(const std::string &callerBundleName, - const std::string &targetBundleName, int32_t userId, AppJumpControlRule &controlRule) +ErrCode AppControlProxy::DeleteDisposedStatus(const std::string &appId, int32_t userId, int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::SetDisposedStatus(const std::string& appId, const Want& want, int32_t userId) +ErrCode AppControlProxy::GetDisposedStatus(const std::string &appId, int32_t userId, Want &want, + int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::DeleteDisposedStatus(const std::string& appId, int32_t userId) +ErrCode AppControlProxy::SetDisposedRule(const std::string &appId, int32_t userId, DisposedRule &DisposedRule, + int32_t &funcResult) { return ERR_OK; } -ErrCode AppControlProxy::GetDisposedStatus(const std::string& appId, Want& want, int32_t userId) +ErrCode AppControlProxy::GetDisposedRule(const std::string &appId, int32_t userId, DisposedRule &DisposedRule, + int32_t &funcResult) +{ + return ERR_OK; +} + +ErrCode AppControlProxy::GetAbilityRunningControlRule(const std::string &bundleName, int32_t userId, + int32_t appIndex, std::vector& disposedRuleList, int32_t &funcResult) +{ + if (bundleName == "com.acts.disposedrulehap") { + DisposedRule disposedRule; + ElementName element; + + disposedRule.priority = 0; + disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_ABILITY; + disposedRule.controlType = AppExecFwk::ControlType::DISALLOWED_LIST; + element.SetAbilityName("MainAbility2"); + element.SetModuleName("entry"); + disposedRule.elementList.push_back(element); + (*disposedRule.want).SetElementName("com.example.disposedruletest", + "DisposedAbility2"); + disposedRuleList.push_back(disposedRule); + return ERR_OK; + } + return ERR_INVALID_VALUE; +} + +ErrCode AppControlProxy::SetDisposedRuleForCloneApp(const std::string &appId, int32_t appIndex, int32_t userId, + DisposedRule &DisposedRule, int32_t &funcResult) +{ + return ERR_OK; +} + +ErrCode AppControlProxy::GetDisposedRuleForCloneApp(const std::string &appId, int32_t appIndex, int32_t userId, + DisposedRule &DisposedRule, int32_t &funcResult) +{ + return ERR_OK; +} + +ErrCode AppControlProxy::DeleteDisposedRuleForCloneApp(const std::string &appId, int32_t appIndex, int32_t userId, + int32_t &funcResult) +{ + return ERR_OK; +} + +ErrCode AppControlProxy::GetUninstallDisposedRule(const std::string &appIdentifier, int32_t appIndex, + int32_t userId, UninstallDisposedRule &rule, int32_t &funcResult) +{ + return ERR_OK; +} + +ErrCode AppControlProxy::SetUninstallDisposedRule(const std::string &appIdentifier, const UninstallDisposedRule &rule, + int32_t appIndex, int32_t userId, int32_t &funcResult) +{ + return ERR_OK; +} + +ErrCode AppControlProxy::DeleteUninstallDisposedRule(const std::string &appIdentifier, int32_t appIndex, + int32_t userId, int32_t &funcResult) { return ERR_OK; } diff --git a/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h b/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h index 8e7a3c0371315f1887fdf2e772d23d0e52ef27a7..5da632a3c226d0379b8b893e524ca53203a312ee 100644 --- a/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h +++ b/test/unittest/ability_manager_service_mock_test/mock/include/bundle_mgr_helper.h @@ -38,7 +38,6 @@ public: ErrCode GetCloneBundleInfo(const std::string &bundleName, int32_t flags, int32_t appCloneIndex, BundleInfo &bundleInfo, int32_t userId); ErrCode GetSandboxBundleInfo(const std::string &bundleName, int32_t appIndex, int32_t userId, BundleInfo &info); - sptr GetAppControlProxy(); bool GetApplicationInfo( const std::string &appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo &appInfo); bool GetApplicationInfo(const std::string &appName, int32_t flags, int32_t userId, ApplicationInfo &appInfo); diff --git a/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp index c579fc0be6498a585a9da546c0e5e0e92fc51eff..1469f8739138944e14277fcd12bf9ea9a584303d 100644 --- a/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/ability_manager_service_mock_test/mock/src/mock_bundle_mgr_helper.cpp @@ -118,11 +118,6 @@ ErrCode BundleMgrHelper::GetSandboxBundleInfo( return ERR_OK; } -sptr BundleMgrHelper::GetAppControlProxy() -{ - return nullptr; -} - bool BundleMgrHelper::GetApplicationInfo( const std::string &appName, const ApplicationFlag flag, const int32_t userId, ApplicationInfo &appInfo) { diff --git a/test/unittest/app_exit_reason_helper_fourth_test/mock/include/bundle_mgr_helper.h b/test/unittest/app_exit_reason_helper_fourth_test/mock/include/bundle_mgr_helper.h index 4e80baf1c13c952a34832503bfd386c7db2440fd..bbeb6e659fd82af03f5057c01df77c5652184830 100644 --- a/test/unittest/app_exit_reason_helper_fourth_test/mock/include/bundle_mgr_helper.h +++ b/test/unittest/app_exit_reason_helper_fourth_test/mock/include/bundle_mgr_helper.h @@ -17,7 +17,6 @@ #define OHOS_ABILITY_RUNTIME_BUNDLE_MGR_HELPER_H #include "ability_keep_alive_service.h" -#include "app_control_interface.h" #include "bundle_info.h" namespace OHOS { @@ -152,11 +151,6 @@ public: return false; } - sptr GetAppControlProxy() - { - return nullptr; - } - bool QueryExtensionAbilityInfos(const AAFwk::Want& want, const int32_t& flag, const int32_t& userId, std::vector& extensionInfos) { diff --git a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp index 817574298de80de1e658e041752c21587e2c3061..3e1eaa34d694466dd4712a7e31b730fe81de5d48 100755 --- a/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/app_mgr_service_inner_eighth_test/mock/src/mock_bundle_mgr_helper.cpp @@ -181,11 +181,6 @@ 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) { diff --git a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp index 88fbfdea14d87ce20d537b56ad6b06392a34dcc6..ddd5813e2dc6f60e58e046d92a4a5a03ef3da335 100755 --- a/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp +++ b/test/unittest/app_mgr_service_inner_seventh_test/mock/src/mock_bundle_mgr_helper.cpp @@ -180,11 +180,6 @@ 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) { diff --git a/test/unittest/app_mgr_service_inner_sixth_test/mock/include/mock_bundle_mgr_helper.h b/test/unittest/app_mgr_service_inner_sixth_test/mock/include/mock_bundle_mgr_helper.h index e6862802f30c3093f9b542b163cf9676a2902c7e..d4ab77b8d537ccac2a967faaa2ed5c02bbf1b102 100755 --- a/test/unittest/app_mgr_service_inner_sixth_test/mock/include/mock_bundle_mgr_helper.h +++ b/test/unittest/app_mgr_service_inner_sixth_test/mock/include/mock_bundle_mgr_helper.h @@ -64,7 +64,6 @@ public: int32_t flags, std::vector& bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID); sptr GetQuickFixManagerProxy(); bool ProcessPreload(const Want& want); - sptr GetAppControlProxy(); bool QueryExtensionAbilityInfos(const Want& want, const int32_t& flag, const int32_t& userId, std::vector& extensionInfos); ErrCode GetBundleInfoV9(const std::string& bundleName, int32_t flags, BundleInfo& bundleInfo, int32_t userId); diff --git a/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp b/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp index 7624899366b7e2f1f1c5bc89b700a0e696273706..21e99874499b3da59d700f183b29efafdc189fd9 100644 --- a/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp +++ b/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-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 @@ -305,17 +305,6 @@ HWTEST_F(BundleMgrHelperTest, BundleMgrHelperTest_QueryExtensionAbilityInfos_002 EXPECT_EQ(ret, false); } -/** - * @tc.name: BundleMgrHelperTest_GetAppControlProxy_001 - * @tc.desc: GetAppControlProxy - * @tc.type: FUNC - */ -HWTEST_F(BundleMgrHelperTest, BundleMgrHelperTest_GetAppControlProxy_001, TestSize.Level1) -{ - auto ret = bundleMgrHelper->GetAppControlProxy(); - EXPECT_NE(ret, nullptr); -} - /** * @tc.name: BundleMgrHelperTest_QueryExtensionAbilityInfos_001 * @tc.desc: QueryExtensionAbilityInfos