From 07f1a9b2350a33a2916906af8ce181766c7c3d7f Mon Sep 17 00:00:00 2001 From: Zheng Yongjun Date: Mon, 24 Jan 2022 12:00:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8bundleName=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AFprocessname=E4=BD=9C=E4=B8=BA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E5=90=8D=EF=BC=8C=E9=80=82=E9=85=8D=E5=8C=85=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zheng Yongjun Change-Id: I3691a57de0440b9dac2e34957c8e2da44d4c6c78 --- BUILD.gn | 7 +++ src/appspawn_server.cpp | 60 +++++++++++++++----- test/BUILD.gn | 8 ++- test/unittest/app_spawn_server_test/BUILD.gn | 14 +++++ 4 files changed, 75 insertions(+), 14 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 49eb7124..2c0227e7 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -62,8 +62,15 @@ ohos_static_library("appspawn_server") { "//utils/native/base:utils", ] external_deps = [ + "ability_runtime:app_manager", + "ability_runtime:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "hilog_native:libhilog", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", ] subsystem_name = "${subsystem_name}" diff --git a/src/appspawn_server.cpp b/src/appspawn_server.cpp index 4807ae3e..b4ef590d 100644 --- a/src/appspawn_server.cpp +++ b/src/appspawn_server.cpp @@ -31,6 +31,10 @@ #include "hilog/log.h" #include "main_thread.h" #include "securec.h" +#include "bundle_mgr_interface.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" #include #include @@ -119,6 +123,43 @@ static void UninstallSigHandler() } #endif +static sptr GetBundleMgrProxy() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return nullptr; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (!remoteObject) { + return nullptr; + } + + return iface_cast(remoteObject); +} + +std::vector GetApplicationNamesById(int32_t uid) +{ + std::vector bundleNames; + sptr mgr = GetBundleMgrProxy(); + if (mgr != nullptr) { + mgr->GetBundlesForUid(uid, bundleNames); + } + + return bundleNames; +} + +std::string GetApplicationNameById(int32_t uid) +{ + std::vector bundleNames = GetApplicationNamesById(uid); + if (bundleNames.empty()) { + return ""; + } + + return bundleNames.front(); +} + AppSpawnServer::AppSpawnServer(const std::string &socketName) { socketName_ = socketName; @@ -421,9 +462,10 @@ int32_t AppSpawnServer::DoAppSandboxMount(const ClientSocket::AppProperty *appPr std::string destDataPath = rootPath + "/data/storage/el2/base"; int rc = 0; - oriInstallPath += appProperty->processName; - oriDataPath += appProperty->processName; - oriDatabasePath += appProperty->processName; + std::string bundleName = GetApplicationNameById(appProperty->uid); + oriInstallPath += bundleName; + oriDataPath += bundleName; + oriDatabasePath += bundleName; std::map mountMap; mountMap[oriInstallPath] = destAPI7InstallPath; @@ -433,7 +475,7 @@ int32_t AppSpawnServer::DoAppSandboxMount(const ClientSocket::AppProperty *appPr std::map::iterator iter; for (iter = mountMap.begin(); iter != mountMap.end(); iter++) { - rc = DoAppSandboxMountOnce(iter->first.c_str(), iter->second.c_str()); + rc = DoAppSandboxMountOnce(iter->second.c_str(), iter->first.c_str()); if (rc) { return rc; } @@ -465,14 +507,6 @@ void AppSpawnServer::DoAppSandboxMkdir(std::string sandboxPackagePath, const Cli mkdir(dirPath.c_str(), FILE_MODE); dirPath = sandboxPackagePath + "/data/storage/el2/database"; mkdir(dirPath.c_str(), FILE_MODE); - - // create applications folder for compatibility purpose - dirPath = sandboxPackagePath + "/data/accounts"; - mkdir(dirPath.c_str(), FILE_MODE); - dirPath = sandboxPackagePath + "/data/accounts/account_0"; - mkdir(dirPath.c_str(), FILE_MODE); - dirPath = sandboxPackagePath + "/data/accounts/account_0/applications"; - mkdir(dirPath.c_str(), FILE_MODE); } int32_t AppSpawnServer::SetAppSandboxProperty(const ClientSocket::AppProperty *appProperty) @@ -482,7 +516,7 @@ int32_t AppSpawnServer::SetAppSandboxProperty(const ClientSocket::AppProperty *a // create /mnt/sandbox/ path, later put it to rootfs module std::string sandboxPackagePath = "/mnt/sandbox/"; mkdir(sandboxPackagePath.c_str(), FILE_MODE); - sandboxPackagePath += appProperty->processName; + sandboxPackagePath += GetApplicationNameById(appProperty->uid); mkdir(sandboxPackagePath.c_str(), FILE_MODE); // add pid to a new mnt namespace diff --git a/test/BUILD.gn b/test/BUILD.gn index 34a84a88..0b964ccd 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -64,5 +64,11 @@ ohos_source_set("appspawn_test_source") { deps = [] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + external_deps = [ + "ability_runtime:app_manager", + "ability_runtime:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", + ] } diff --git a/test/unittest/app_spawn_server_test/BUILD.gn b/test/unittest/app_spawn_server_test/BUILD.gn index 4ac518e2..57ed7ac2 100755 --- a/test/unittest/app_spawn_server_test/BUILD.gn +++ b/test/unittest/app_spawn_server_test/BUILD.gn @@ -34,8 +34,15 @@ ohos_unittest("AppSpawnServerOverrideTest") { deps = [ "${appspawn_path}/test:appspawn_test_source" ] external_deps = [ + "ability_runtime:app_manager", + "ability_runtime:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "hilog_native:libhilog", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", ] } @@ -59,8 +66,15 @@ ohos_unittest("AppSpawnServerMockTest") { deps = [ "${appspawn_path}/test:appspawn_test_source" ] external_deps = [ + "ability_runtime:app_manager", + "ability_runtime:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "hilog_native:libhilog", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", ] } -- Gitee