From 50509e22c82bfb2575eafb8125f8411b28721812 Mon Sep 17 00:00:00 2001 From: changzheng6 Date: Thu, 7 Apr 2022 21:52:54 +0800 Subject: [PATCH 1/4] modify bms dep Signed-off-by: changzheng6 --- appexecfwk.gni | 7 +++ services/bundlemgr/BUILD.gn | 6 ++- services/bundlemgr/appexecfwk_bundlemgr.gni | 1 + .../include/ability_manager_helper.h | 29 +++++++++++ .../bundlemgr/src/ability_manager_helper.cpp | 52 +++++++++++++++++++ .../bundlemgr/src/base_bundle_installer.cpp | 40 +++++--------- services/bundlemgr/src/bundle_clone_mgr.cpp | 29 ++--------- 7 files changed, 111 insertions(+), 53 deletions(-) create mode 100644 services/bundlemgr/include/ability_manager_helper.h create mode 100644 services/bundlemgr/src/ability_manager_helper.cpp diff --git a/appexecfwk.gni b/appexecfwk.gni index 9a586fd72a..bfdb0f43c4 100644 --- a/appexecfwk.gni +++ b/appexecfwk.gni @@ -23,11 +23,17 @@ tools_path = "${appexecfwk_path}/tools" declare_args() { bundle_framework_graphics = true + ability_runtime_enable = true account_enable = true configpolicy_enable = true device_manager_enable = true hicollie_enable = true + if (defined(global_parts_info) && + !defined(global_parts_info.aafwk_ability_runtime)) { + ability_runtime_enable = false + } + if (defined(global_parts_info) && !defined(global_parts_info.account_os_account_standard)) { account_enable = false @@ -49,6 +55,7 @@ declare_args() { } print("bundle_framework_graphics = " + "$bundle_framework_graphics") + print("ability_runtime_enable = " + "$ability_runtime_enable") print("account_enable = " + "$account_enable") print("configpolicy_enable = " + "$configpolicy_enable") print("device_manager_enable = " + "$device_manager_enable") diff --git a/services/bundlemgr/BUILD.gn b/services/bundlemgr/BUILD.gn index 9fc0b5fb46..4cfec2d540 100644 --- a/services/bundlemgr/BUILD.gn +++ b/services/bundlemgr/BUILD.gn @@ -166,7 +166,6 @@ ohos_shared_library("libbms") { external_deps = [ "ability_base:want", - "ability_runtime:app_manager", "access_token:libaccesstoken_sdk", "appverify:libhapverify", "bundle_framework:appexecfwk_base", @@ -185,6 +184,11 @@ ohos_shared_library("libbms") { "startup_l2:syspara", ] + if (ability_runtime_enable) { + external_deps += [ "ability_runtime:ability_manager" ] + defines += [ "ABILITY_RUNTIME_ENABLE" ] + } + if (account_enable) { external_deps += [ "os_account_standard:os_account_innerkits" ] defines += [ "ACCOUNT_ENABLE" ] diff --git a/services/bundlemgr/appexecfwk_bundlemgr.gni b/services/bundlemgr/appexecfwk_bundlemgr.gni index 0bdbe89501..c2042896cc 100644 --- a/services/bundlemgr/appexecfwk_bundlemgr.gni +++ b/services/bundlemgr/appexecfwk_bundlemgr.gni @@ -23,6 +23,7 @@ install_daemon_sources = [ ] bundle_install_sources = [ + "${services_path}/bundlemgr/src/ability_manager_helper.cpp", "${services_path}/bundlemgr/src/base_bundle_installer.cpp", "${services_path}/bundlemgr/src/bundle_exception_handler.cpp", "${services_path}/bundlemgr/src/bundle_installer.cpp", diff --git a/services/bundlemgr/include/ability_manager_helper.h b/services/bundlemgr/include/ability_manager_helper.h new file mode 100644 index 0000000000..6c616707d0 --- /dev/null +++ b/services/bundlemgr/include/ability_manager_helper.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_ABILITY_MANAGER_HELPER_H +#define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_ABILITY_MANAGER_HELPER_H + +#include + +namespace OHOS { +namespace AppExecFwk { +class AbilityManagerHelper { +public: + static bool UninstallApplicationProcesses(const std::string &bundleName, const int uid); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_ABILITY_MANAGER_HELPER_H diff --git a/services/bundlemgr/src/ability_manager_helper.cpp b/services/bundlemgr/src/ability_manager_helper.cpp new file mode 100644 index 0000000000..2e974e9110 --- /dev/null +++ b/services/bundlemgr/src/ability_manager_helper.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ability_manager_helper.h" + +#include + +#include "app_log_wrapper.h" +#include "system_ability_helper.h" +#include "system_ability_definition.h" + +#ifdef ABILITY_RUNTIME_ENABLE +#include "ability_manager_interface.h" +#endif + +namespace OHOS { +namespace AppExecFwk { +bool AbilityManagerHelper::UninstallApplicationProcesses(const std::string &bundleName, const int uid) +{ +#ifdef ABILITY_RUNTIME_ENABLE + APP_LOGI("uninstall kill running processes, app name is %{public}s", bundleName.c_str()); + sptr abilityMgrProxy = + iface_cast(SystemAbilityHelper::GetSystemAbility(ABILITY_MGR_SERVICE_ID)); + if (!abilityMgrProxy) { + APP_LOGE("fail to find the app mgr service to kill application"); + return false; + } + if (abilityMgrProxy->UninstallApp(bundleName, uid) != 0) { + APP_LOGE("kill application process failed"); + return false; + } + return true; +#else + APP_LOGI("ABILITY_RUNTIME_ENABLE is false"); + // ACCOUNT_ENABLE is false, do nothing and return -1. + return true; +#endif +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index f4a29b918c..6eafbb1dd2 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -19,46 +19,29 @@ #include #include -#include "ability_manager_interface.h" +#include "nlohmann/json.hpp" + +#include "ability_manager_helper.h" #include "app_log_wrapper.h" +#include "bundle_clone_mgr.h" #include "bundle_constants.h" #include "bundle_extractor.h" #include "bundle_mgr_service.h" #include "bundle_parser.h" #include "bundle_permission_mgr.h" #include "bundle_util.h" +#include "bundle_verify_mgr.h" #include "bytrace.h" #include "datetime_ex.h" #include "installd_client.h" -#include "nlohmann/json.hpp" #include "perf_profile.h" +#include "scope_guard.h" #include "string_ex.h" -#include "system_ability_definition.h" -#include "system_ability_helper.h" #include "systemcapability.h" -#include "bundle_clone_mgr.h" -#include "scope_guard.h" -#include "bundle_verify_mgr.h" + namespace OHOS { namespace AppExecFwk { using namespace OHOS::Security; -namespace { -bool UninstallApplicationProcesses(const std::string &bundleName, const int uid) -{ - APP_LOGI("uninstall kill running processes, app name is %{public}s", bundleName.c_str()); - sptr abilityMgrProxy = - iface_cast(SystemAbilityHelper::GetSystemAbility(ABILITY_MGR_SERVICE_ID)); - if (!abilityMgrProxy) { - APP_LOGE("fail to find the app mgr service to kill application"); - return false; - } - if (abilityMgrProxy->UninstallApp(bundleName, uid) != 0) { - APP_LOGE("kill application process failed"); - return false; - } - return true; -} -} // namespace BaseBundleInstaller::BaseBundleInstaller() { @@ -603,7 +586,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( // reboot scan case will not kill the bundle if (installParam.noSkipsKill) { // kill the bundle process during uninstall. - if (!UninstallApplicationProcesses(oldInfo.GetApplicationName(), uid)) { + if (!AbilityManagerHelper::UninstallApplicationProcesses(oldInfo.GetApplicationName(), uid)) { APP_LOGE("can not kill process"); dataMgr_->UpdateBundleInstallState(bundleName, InstallState::INSTALL_SUCCESS); return ERR_APPEXECFWK_UNINSTALL_KILLING_APP_ERROR; @@ -694,7 +677,7 @@ ErrCode BaseBundleInstaller::ProcessBundleUninstall( // reboot scan case will not kill the bundle if (installParam.noSkipsKill) { // kill the bundle process during uninstall. - if (!UninstallApplicationProcesses(oldInfo.GetApplicationName(), uid)) { + if (!AbilityManagerHelper::UninstallApplicationProcesses(oldInfo.GetApplicationName(), uid)) { APP_LOGE("can not kill process"); return ERR_APPEXECFWK_UNINSTALL_KILLING_APP_ERROR; } @@ -1052,7 +1035,8 @@ ErrCode BaseBundleInstaller::ProcessModuleUpdate(InnerBundleInfo &newInfo, // reboot scan case will not kill the bundle if (noSkipsKill) { // kill the bundle process during updating - if (!UninstallApplicationProcesses(oldInfo.GetApplicationName(), oldInfo.GetUid(userId_))) { + if (!AbilityManagerHelper::UninstallApplicationProcesses( + oldInfo.GetApplicationName(), oldInfo.GetUid(userId_))) { APP_LOGE("fail to kill running application"); return ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR; } @@ -1602,7 +1586,7 @@ ErrCode BaseBundleInstaller::UninstallLowerVersionFeature(const std::vector moduleVec = info.GetModuleNameVec(); diff --git a/services/bundlemgr/src/bundle_clone_mgr.cpp b/services/bundlemgr/src/bundle_clone_mgr.cpp index bc0b790b29..7a40d0ecec 100644 --- a/services/bundlemgr/src/bundle_clone_mgr.cpp +++ b/services/bundlemgr/src/bundle_clone_mgr.cpp @@ -17,35 +17,16 @@ #include #include -#include "installd_client.h" -#include "bundle_mgr_service.h" -#include "ability_manager_interface.h" -#include "system_ability_helper.h" -#include "system_ability_definition.h" #include "nlohmann/json.hpp" + +#include "ability_manager_helper.h" +#include "bundle_mgr_service.h" +#include "installd_client.h" #include "ipc_skeleton.h" #include "scope_guard.h" namespace OHOS { namespace AppExecFwk { -namespace { -bool UninstallApplicationProcesses(const std::string &bundleName, const int uid) -{ - APP_LOGI("remove cloned bundle kill running processes, app name is %{public}s", bundleName.c_str()); - sptr abilityMgrProxy = - iface_cast(SystemAbilityHelper::GetSystemAbility(ABILITY_MGR_SERVICE_ID)); - if (!abilityMgrProxy) { - APP_LOGE("fail to find the app mgr service to kill application"); - return false; - } - if (abilityMgrProxy->UninstallApp(bundleName, uid) != 0) { - APP_LOGE("kill application process failed"); - return false; - } - return true; -} -} - BundleCloneMgr::BundleCloneMgr() { APP_LOGI(""); @@ -311,7 +292,7 @@ bool BundleCloneMgr::RemoveClonedBundle(const std::string &oldName, const std::s APP_LOGD("bundleName_ is %{public}s", bundleName_.c_str()); ScopeGuard enableGuard([&] { dataMgr_->EnableBundle(bundleName_); }); - if (!UninstallApplicationProcesses(newcloneInfo_.GetApplicationName(), uid)) { + if (!AbilityManagerHelper::UninstallApplicationProcesses(newcloneInfo_.GetApplicationName(), uid)) { APP_LOGE("can not kill process"); return false; } -- Gitee From c847184b40a11fad9885203c6f400b5073904901 Mon Sep 17 00:00:00 2001 From: changzheng6 Date: Thu, 7 Apr 2022 21:58:01 +0800 Subject: [PATCH 2/4] modify bms dep Signed-off-by: changzheng6 --- services/bundlemgr/src/ability_manager_helper.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/bundlemgr/src/ability_manager_helper.cpp b/services/bundlemgr/src/ability_manager_helper.cpp index 2e974e9110..87eb6376b6 100644 --- a/services/bundlemgr/src/ability_manager_helper.cpp +++ b/services/bundlemgr/src/ability_manager_helper.cpp @@ -15,8 +15,6 @@ #include "ability_manager_helper.h" -#include - #include "app_log_wrapper.h" #include "system_ability_helper.h" #include "system_ability_definition.h" -- Gitee From 20c61787c3c831b797bfc33c1f76d88d079f60d2 Mon Sep 17 00:00:00 2001 From: changzheng6 Date: Thu, 7 Apr 2022 21:59:14 +0800 Subject: [PATCH 3/4] modify bms dep Signed-off-by: changzheng6 --- services/bundlemgr/src/ability_manager_helper.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/bundlemgr/src/ability_manager_helper.cpp b/services/bundlemgr/src/ability_manager_helper.cpp index 87eb6376b6..46ff7bcb7b 100644 --- a/services/bundlemgr/src/ability_manager_helper.cpp +++ b/services/bundlemgr/src/ability_manager_helper.cpp @@ -42,7 +42,6 @@ bool AbilityManagerHelper::UninstallApplicationProcesses(const std::string &bund return true; #else APP_LOGI("ABILITY_RUNTIME_ENABLE is false"); - // ACCOUNT_ENABLE is false, do nothing and return -1. return true; #endif } -- Gitee From 1c38715052521a187d7a2c2948bc3cf0e3ad2fc4 Mon Sep 17 00:00:00 2001 From: changzheng6 Date: Fri, 8 Apr 2022 09:37:06 +0800 Subject: [PATCH 4/4] modify bms dep Signed-off-by: changzheng6 --- services/bundlemgr/src/base_bundle_installer.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/services/bundlemgr/src/base_bundle_installer.cpp b/services/bundlemgr/src/base_bundle_installer.cpp index 6eafbb1dd2..6d4e5a9fd0 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -15,10 +15,6 @@ #include "base_bundle_installer.h" -#include -#include -#include - #include "nlohmann/json.hpp" #include "ability_manager_helper.h" -- Gitee