diff --git a/appdata-sandbox-app.json b/appdata-sandbox-app.json index 8a104e794812ba994916117251620a6f75e529c0..ef1ab3917e6a1ff3bd6d205984999200b89d6302 100755 --- a/appdata-sandbox-app.json +++ b/appdata-sandbox-app.json @@ -72,7 +72,7 @@ "src-path" : "/vendor/etc/hiai", "sandbox-path" : "/vendor/etc/hiai" }, { - "src-path" : "/data/local/shader_cache/cloud/common", + "src-path" : "/data/app/el1/public/shader_cache/cloud/common", "sandbox-path" : "/data/storage/shader_cache/common" }, { "src-path" : "/data/service/el0/public/for-all-app", @@ -142,10 +142,10 @@ "src-path" : "/data/app/el1//aot_compiler/ark_profile/", "sandbox-path" : "/data/storage/ark-profile" }, { - "src-path" : "/data/local/shader_cache/local/", + "src-path" : "/data/app/el1//shader_cache/", "sandbox-path" : "/data/storage/shader_cache/local" }, { - "src-path" : "/data/local/shader_cache/cloud/", + "src-path" : "/data/app/el1/public/shader_cache/cloud/", "sandbox-path" : "/data/storage/shader_cache/cloud" }, { "src-path" : "/data/service/el1/public/themes//a/app", @@ -269,8 +269,11 @@ }, { "name": "ohos.permission.ACCESS_SHADER_CACHE_DIR", "mount-paths": [{ - "src-path": "/data/local/shader_cache", - "sandbox-path": "/data/storage/shader_caches" + "src-path": "/data/service/el1/public/shader_cache/local", + "sandbox-path": "/data/storage/shader_caches/local" + }, { + "src-path": "/data/app/el1/public/shader_cache/cloud", + "sandbox-path": "/data/storage/shader_caches/cloud" }] }, { "name": "ohos.permission.ACCESS_HIVIEWX", diff --git a/appdata-sandbox-gpu.json b/appdata-sandbox-gpu.json index 78a5f8123420552c3a88374d155885dd4e7c7294..5e1c977e2e81e59317353fde0e4f3447fe8bd0e9 100644 --- a/appdata-sandbox-gpu.json +++ b/appdata-sandbox-gpu.json @@ -41,7 +41,7 @@ "src-path" : "/vendor/etc/vulkan/icd.d", "sandbox-path" : "/vendor/etc/vulkan/icd.d" }, { - "src-path" : "/data/local/shader_cache/cloud/common", + "src-path" : "/data/app/el1/public/shader_cache/cloud/common", "sandbox-path" : "/data/storage/shader_cache/common" }], "symbol-links" : [{ @@ -79,10 +79,10 @@ "src-path" : "/module_update/ArkWebCore/app/", "sandbox-path" : "/module_update/ArkWebCore/app/" }, { - "src-path" : "/data/local/shader_cache/local/", + "src-path" : "/data/app/el1//shader_cache/", "sandbox-path" : "/data/storage/shader_cache/local" }, { - "src-path" : "/data/local/shader_cache/cloud/", + "src-path" : "/data/app/el1/public/shader_cache/cloud/", "sandbox-path" : "/data/storage/shader_cache/cloud" }] } diff --git a/appdata-sandbox.json b/appdata-sandbox.json index 4aaf262338b513584aef5d6f81eb3e958022d634..e608a745fb3dea33f66368387aecd619da6a8aeb 100755 --- a/appdata-sandbox.json +++ b/appdata-sandbox.json @@ -154,17 +154,17 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/shader_cache/local/", + "src-path" : "/data/app/el1//shader_cache/", "sandbox-path" : "/data/storage/shader_cache/local", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/shader_cache/cloud/", + "src-path" : "/data/app/el1/public/shader_cache/cloud/", "sandbox-path" : "/data/storage/shader_cache/cloud", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/shader_cache/cloud/common", + "src-path" : "/data/app/el1/public/shader_cache/cloud/common", "sandbox-path" : "/data/storage/shader_cache/common", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" @@ -629,17 +629,17 @@ "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/shader_cache/local/", + "src-path" : "/data/app/el1//shader_cache/", "sandbox-path" : "/data/storage/shader_cache/local", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/shader_cache/cloud/", + "src-path" : "/data/app/el1/public/shader_cache/cloud/", "sandbox-path" : "/data/storage/shader_cache/cloud", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" }, { - "src-path" : "/data/local/shader_cache/cloud/common", + "src-path" : "/data/app/el1/public/shader_cache/cloud/common", "sandbox-path" : "/data/storage/shader_cache/common", "sandbox-flags" : [ "bind", "rec" ], "check-action-status": "false" @@ -845,8 +845,12 @@ "ohos.permission.ACCESS_SHADER_CACHE_DIR":[{ "sandbox-switch": "ON", "mount-paths": [{ - "src-path": "/data/local/shader_cache", - "sandbox-path": "/data/storage/shader_caches", + "src-path": "/data/service/el1/public/shader_cache/local", + "sandbox-path": "/data/storage/shader_caches/local", + "sandbox-flags": [ "bind", "rec" ] + }, { + "src-path": "/data/app/el1/public/shader_cache/cloud", + "sandbox-path": "/data/storage/shader_caches/cloud", "sandbox-flags": [ "bind", "rec" ] } ] diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index bd2f16d15d06d8b785a0a5c617fb257c4e03cb48..f04bcf1a1e1fe0a47a8685c62d485c7bc393602f 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -295,6 +295,7 @@ int AppSpawnClientAddPermission(AppSpawnClientHandle handle, AppSpawnReqMsgHandl #define MSG_EXT_NAME_JIT_PERMISSIONS "Permissions" #define MSG_EXT_NAME_USERID "uid" #define MSG_EXT_NAME_EXTENSION_TYPE "ExtensionType" +#define MSG_EXT_NAME_PARENT_UID "ParentUid" int AppSpawnReqMsgAddExtInfo(AppSpawnReqMsgHandle reqHandle, const char *name, const uint8_t *value, uint32_t valueLen); diff --git a/modules/sandbox/appspawn_sandbox.h b/modules/sandbox/appspawn_sandbox.h index d6b8cb0a6bcb1d9aa75a3824b805eed1291dafbe..de2a041c0d1ec350806317eaf9ba3630fa2c72e5 100644 --- a/modules/sandbox/appspawn_sandbox.h +++ b/modules/sandbox/appspawn_sandbox.h @@ -38,6 +38,7 @@ extern "C" { #define PARAMETER_PACKAGE_NAME "" #define PARAMETER_USER_ID "" +#define PARAMETER_HOST_USER_ID "" #define PARAMETER_PACKAGE_INDEX "" #define ARK_WEB_PERSIST_PACKAGE_NAME "persist.arkwebcore.package_name" #define PARAMETER_ARK_WEB_PACKAGE_INDEX "" diff --git a/modules/sandbox/sandbox_cfgvar.c b/modules/sandbox/sandbox_cfgvar.c index 11268230d4c03ea2219fbafc94ddeebf0fa3d803..6c88524f124ee40dfa14304ece23158d2c8b0a31 100644 --- a/modules/sandbox/sandbox_cfgvar.c +++ b/modules/sandbox/sandbox_cfgvar.c @@ -68,6 +68,25 @@ static int VarCurrentUseIdReplace(const SandboxContext *context, return 0; } +static int VarCurrentHostUserIdReplace(const SandboxContext *context, + const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData) +{ + int uid = 0; + int len = 0; + char *hostUid = + (char *)GetAppSpawnMsgExtInfo(context->message, MSG_EXT_NAME_PARENT_UID, NULL); + if (hostUid != NULL) { + uid = atoi(hostUid); + len = sprintf_s((char *)buffer, bufferLen, "%d", uid / UID_BASE); + } else { + len = sprintf_s((char *)buffer, bufferLen, "%s", "hostUserId"); + } + APPSPAWN_CHECK(len > 0 && ((uint32_t)len < bufferLen), + return -1, "Failed to format path app: %{public}s", context->bundleName); + *realLen = (uint32_t)len; + return 0; +} + static int VarArkWebPackageNameReplace(const SandboxContext *context, const char *buffer, uint32_t bufferLen, uint32_t *realLen, const VarExtraData *extraData) @@ -348,6 +367,7 @@ void AddDefaultVariable(void) { AddVariableReplaceHandler(PARAMETER_PACKAGE_NAME, VarPackageNameReplace); AddVariableReplaceHandler(PARAMETER_USER_ID, VarCurrentUseIdReplace); + AddVariableReplaceHandler(PARAMETER_HOST_USER_ID, VarCurrentHostUserIdReplace); AddVariableReplaceHandler(PARAMETER_PACKAGE_INDEX, VarPackageNameIndexReplace); AddVariableReplaceHandler(PARAMETER_ARK_WEB_PACKAGE_INDEX, VarArkWebPackageNameReplace); /* diff --git a/modules/sandbox/sandbox_utils.cpp b/modules/sandbox/sandbox_utils.cpp index 605eceb950de80fa6ae161e7bdda0c076b98b437..7030ed4bcd4beec6707577a06fc05e617b2aa520 100644 --- a/modules/sandbox/sandbox_utils.cpp +++ b/modules/sandbox/sandbox_utils.cpp @@ -86,6 +86,7 @@ namespace { const std::string g_packageNameIndex = ""; const std::string g_variablePackageName = ""; const std::string g_arkWebPackageName = ""; + const std::string g_hostUserId = ""; const std::string g_sandBoxDir = "/mnt/sandbox/"; const std::string g_statusCheck = "true"; const std::string g_sbxSwitchCheck = "ON"; @@ -551,6 +552,20 @@ static std::string ReplaceVariablePackageName(const AppSpawningCtx *appProperty, return tmpSandboxPath; } +static std::string ReplaceHostUserId(const AppSpawningCtx *appProperty, const std::string &path) +{ + std::string tmpSandboxPath = path; + int32_t uid = 0; + const char *userId = + (const char *)(GetAppSpawnMsgExtInfo(appProperty->message, MSG_EXT_NAME_PARENT_UID, NULL)); + if (userId != nullptr) { + uid = atoi(userId); + } + tmpSandboxPath = replace_all(tmpSandboxPath, g_hostUserId, std::to_string(uid / UID_BASE)); + APPSPAWN_LOGV("tmpSandboxPath %{public}s", tmpSandboxPath.c_str()); + return tmpSandboxPath; +} + string SandboxUtils::ConvertToRealPath(const AppSpawningCtx *appProperty, std::string path) { AppSpawnMsgBundleInfo *info = @@ -575,6 +590,10 @@ string SandboxUtils::ConvertToRealPath(const AppSpawningCtx *appProperty, std::s path = replace_all(path, g_userId, std::to_string(dacInfo->uid / UID_BASE)); } + if (path.find(g_hostUserId) != std::string::npos) { + path = ReplaceHostUserId(appProperty, path); + } + if (path.find(g_variablePackageName) != std::string::npos) { path = ReplaceVariablePackageName(appProperty, path); }