diff --git a/BUILD.gn b/BUILD.gn index 49eb71240a776b81ee74c98220a8c74e35e9d912..2c0227e7beda4a1226893f84a588d20b8949f4d6 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 4807ae3e507ed6fec16656b5274db6314ccba6bb..b4ef590d359acad7d84ccaf87a6bb3bb78a22e58 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 34a84a882c98340c00afd36d177933e7291d133a..0b964ccd339c45c18bfcbb054018b43c8d8e60ff 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 4ac518e25e6d114c3e04ca51f64b02b7469f0caf..57ed7ac2d04ac04bb7826e761131a18117ae1744 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", ] }