diff --git a/appexecfwk.gni b/appexecfwk.gni index 9a586fd72a27a7f49d3cda2558073093df41871f..bfdb0f43c45e70c791f4ffe35b8f91e5a120c71d 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 9fc0b5fb464fc7fc0aa22f476b1f908935949aef..4cfec2d540769fa44fb53cd09b6fdcc32107f2b3 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 0bdbe89501fedacffc0bb06755f567b4d0abe839..c2042896cc57182103bbae839735f4525feb5072 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 0000000000000000000000000000000000000000..6c616707d0874d0fc5f10f7e835a940c988a98db --- /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 0000000000000000000000000000000000000000..46ff7bcb7b5b38e22ae3bf4c93dfd0d91f1919f3 --- /dev/null +++ b/services/bundlemgr/src/ability_manager_helper.cpp @@ -0,0 +1,49 @@ +/* + * 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 "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"); + 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 f4a29b918ca6d5447e430634199031df366abb84..6d4e5a9fd0a32c6845bf2d8c281517abe93ab834 100644 --- a/services/bundlemgr/src/base_bundle_installer.cpp +++ b/services/bundlemgr/src/base_bundle_installer.cpp @@ -15,50 +15,29 @@ #include "base_bundle_installer.h" -#include -#include -#include +#include "nlohmann/json.hpp" -#include "ability_manager_interface.h" +#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 +582,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 +673,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 +1031,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 +1582,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 bc0b790b2913d53ef1d8998280daf0309a5ab56b..7a40d0ececa28627871f8c43173fb232acb779fd 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; }