解决冲突

Signed-off-by: laiguizhong <laiguizhong@huawei.com>
This commit is contained in:
laiguizhong 2022-06-21 03:33:43 -07:00
commit 59eb8ef1ce
5 changed files with 108 additions and 14 deletions

View File

@ -24,10 +24,6 @@ config("appspawn_config") {
"//utils/native/base/include",
"util/include",
"${aafwk_path}/frameworks/kits/appkit/native/app/include",
"${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr",
"${aafwk_path}/interfaces/innerkits/ability_manager/include",
"${aafwk_path}/frameworks/kits/ability/native/include",
"${aafwk_path}/services/abilitymgr/include",
"//base/global/resource_management/interfaces/inner_api/include",
"//base/security/access_token/interfaces/innerkits/token_setproc/include",
"//base/startup/init_lite/services/log",

36
appdata-sandbox.json Normal file → Executable file
View File

@ -162,6 +162,16 @@
"check-action-status": "false"
}
],
"flags-point" : [{
"flags": "NOT_SUPPORTED",
"mount-paths" : [{
"src-path" : "/data/app/el1/bundle/public/",
"sandbox-path" : "/data/bundles/",
"sandbox-flags" : [ "bind", "rec" ],
"check-action-status": "true"
}
]}
],
"symbol-links" : [
]
}]
@ -228,14 +238,26 @@
"symbol-links" : []
}],
"ohos.samples.ecg" : [{
"sandbox-switch": "OFF",
"sandbox-switch": "ON",
"sandbox-root" : "/mnt/sandbox/<PackageName>",
"mount-paths" : [{
"src-path" : "/data/app/el1/bundle/public/",
"sandbox-path" : "/data/bundles/",
"sandbox-flags" : [ "bind", "rec" ],
"check-action-status": "true"
}
"mount-paths" : [],
"flags-point" : [{
"flags": "NOT_SUPPORTED",
"mount-paths" : [{
"src-path" : "/data/app/el1/bundle/public/",
"sandbox-path" : "/data/bundles/",
"sandbox-flags" : [ "bind", "rec" ],
"check-action-status": "true"
}
]}, {
"flags": "START_FLAGS_BACKUP",
"mount-paths" : [{
"src-path" : "/data/app/el1/bundle/public/",
"sandbox-path" : "/data/bundles/",
"sandbox-flags" : [ "bind", "rec" ],
"check-action-status": "true"
}
]}
],
"symbol-links" : []
}],

View File

@ -38,7 +38,7 @@ ohos_moduletest("AppSpawnModuleTest") {
]
external_deps = [
"ability_runtime:app_manager",
"bundle_framework:appexecfwk_base",
"hiviewdfx_hilog_native:libhilog",
]
}

View File

@ -42,6 +42,12 @@ private:
static int32_t DoSandboxFilePrivateBind(const ClientSocket::AppProperty *appProperty, nlohmann::json &wholeConfig);
static int32_t DoSandboxFilePrivateSymlink(const ClientSocket::AppProperty *appProperty,
nlohmann::json &wholeConfig);
static int32_t DoSandboxFilePrivateFlagsPointHandle(const ClientSocket::AppProperty *appProperty,
nlohmann::json &wholeConfig);
static int32_t DoSandboxFileCommonFlagsPointHandle(const ClientSocket::AppProperty *appProperty,
nlohmann::json &wholeConfig);
static int32_t HandleFlagsPoint(const ClientSocket::AppProperty *appProperty,
nlohmann::json &wholeConfig);
static int32_t SetPrivateAppSandboxProperty(const ClientSocket::AppProperty *appProperty);
static int32_t SetCommonAppSandboxProperty(const ClientSocket::AppProperty *appProperty,
std::string &sandboxPackagePath);
@ -68,4 +74,4 @@ private:
};
} // namespace AppSpawn
} // namespace OHOS
#endif // SANDBOX_UTILS_H
#endif // SANDBOX_UTILS_H

72
util/src/sandbox_utils.cpp Normal file → Executable file
View File

@ -74,6 +74,8 @@ namespace {
const char *SANDBOX_ROOT_PREFIX = "sandbox-root";
const char *TOP_SANDBOX_SWITCH_PREFIX = "top-sandbox-switch";
const char *TARGET_NAME = "target-name";
const char *FLAGS_POINT = "flags-point";
const char *FLAGS = "flags";
const char *WARGNAR_DEVICE_PATH = "/3rdmodem";
}
@ -441,6 +443,66 @@ int32_t SandboxUtils::DoSandboxFilePrivateSymlink(const ClientSocket::AppPropert
return 0;
}
static int ConvertFlagStr(const std::string &flagStr)
{
const std::map<std::string, int> flagsMap = {{"0", 0}, {"START_FLAGS_BACKUP", 1}};
if (flagsMap.count(flagStr)) {
return flagsMap.at(flagStr);
}
return -1;
}
int32_t SandboxUtils::HandleFlagsPoint(const ClientSocket::AppProperty *appProperty,
nlohmann::json &appConfig)
{
if (appConfig.find(FLAGS_POINT) == appConfig.end()) {
return 0;
}
nlohmann::json flagsPoints = appConfig[FLAGS_POINT];
unsigned int flagsPointSize = flagsPoints.size();
for (unsigned int i = 0; i < flagsPointSize; i++) {
nlohmann::json flagPoint = flagsPoints[i];
if (flagPoint.find(FLAGS) != flagPoint.end()) {
std::string flagsStr = flagPoint[FLAGS].get<std::string>();
int flag = ConvertFlagStr(flagsStr);
if (appProperty->flags == flag) {
return DoAllMntPointsMount(appProperty, flagPoint);
}
} else {
APPSPAWN_LOGE("read flags config failed, app name is %s", appProperty->bundleName);
}
}
return 0;
}
int32_t SandboxUtils::DoSandboxFilePrivateFlagsPointHandle(const ClientSocket::AppProperty *appProperty,
nlohmann::json &wholeConfig)
{
nlohmann::json privateAppConfig = wholeConfig[PRIVATE_PREFIX][0];
if (privateAppConfig.find(appProperty->bundleName) != privateAppConfig.end()) {
return HandleFlagsPoint(appProperty, privateAppConfig[appProperty->bundleName][0]);
}
return 0;
}
int32_t SandboxUtils::DoSandboxFileCommonFlagsPointHandle(const ClientSocket::AppProperty *appProperty,
nlohmann::json &wholeConfig)
{
nlohmann::json commonConfig = wholeConfig[COMMON_PREFIX][0];
if (commonConfig.find(APP_RESOURCES) != commonConfig.end()) {
return HandleFlagsPoint(appProperty, commonConfig[APP_RESOURCES][0]);
}
return 0;
}
int32_t SandboxUtils::DoSandboxFileCommonBind(const ClientSocket::AppProperty *appProperty, nlohmann::json &wholeConfig)
{
nlohmann::json commonConfig = wholeConfig[COMMON_PREFIX][0];
@ -490,6 +552,10 @@ int32_t SandboxUtils::SetPrivateAppSandboxProperty_(const ClientSocket::AppPrope
ret = DoSandboxFilePrivateSymlink(appProperty, config);
APPSPAWN_CHECK_ONLY_LOG(ret == 0, "DoSandboxFilePrivateSymlink failed");
ret = DoSandboxFilePrivateFlagsPointHandle(appProperty, config);
APPSPAWN_CHECK_ONLY_LOG(ret == 0, "DoSandboxFilePrivateFlagsPointHandle failed");
return ret;
}
@ -518,8 +584,12 @@ int32_t SandboxUtils::SetCommonAppSandboxProperty_(const ClientSocket::AppProper
// if sandbox switch is off, don't do symlink work again
if (CheckAppSandboxSwitchStatus(appProperty) == true && (CheckTotalSandboxSwitchStatus(appProperty) == true)) {
rc = DoSandboxFileCommonSymlink(appProperty, config);
APPSPAWN_CHECK_ONLY_LOG(rc == 0, "DoSandboxFileCommonSymlink failed, %s", appProperty->bundleName);
APPSPAWN_CHECK(rc == 0, return rc, "DoSandboxFileCommonSymlink failed, %s", appProperty->bundleName);
}
rc = DoSandboxFileCommonFlagsPointHandle(appProperty, config);
APPSPAWN_CHECK_ONLY_LOG(rc == 0, "DoSandboxFilePrivateFlagsPointHandle failed");
return rc;
}