mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 07:00:17 +00:00
Add support for silk enable
Signed-off-by: cheyongxiang <cheyongxiang1@huawei.com>
This commit is contained in:
parent
17d52ac15a
commit
5f85184d3f
@ -20,6 +20,7 @@ ohos_shared_library("appspawn_common") {
|
||||
"appspawn_cgroup.c",
|
||||
"appspawn_common.c",
|
||||
"appspawn_namespace.c",
|
||||
"appspawn_silk.c",
|
||||
]
|
||||
include_dirs = [
|
||||
".",
|
||||
@ -27,13 +28,17 @@ ohos_shared_library("appspawn_common") {
|
||||
"${appspawn_path}/standard",
|
||||
]
|
||||
cflags = []
|
||||
deps = [ "${appspawn_path}/modules/module_engine:libappspawn_module_engine" ]
|
||||
deps = [
|
||||
"${appspawn_path}/modules/module_engine:libappspawn_module_engine",
|
||||
"${appspawn_path}/util:libappspawn_util",
|
||||
]
|
||||
defines = [ "GRAPHIC_PERMISSION_CHECK" ]
|
||||
external_deps = [
|
||||
"access_token:libtoken_setproc",
|
||||
"access_token:libtokenid_sdk",
|
||||
"cJSON:cjson",
|
||||
"c_utils:utils",
|
||||
"config_policy:configpolicy_util",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"netmanager_base:netsys_client",
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "appspawn_hook.h"
|
||||
#include "appspawn_msg.h"
|
||||
#include "appspawn_manager.h"
|
||||
#include "appspawn_silk.h"
|
||||
#include "init_param.h"
|
||||
#include "parameter.h"
|
||||
#include "securec.h"
|
||||
@ -440,9 +441,17 @@ static int SpawnEnableCache(AppSpawnMgr *content, AppSpawningCtx *property)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void SpawnLoadSilk(const AppSpawnMgr *content, const AppSpawningCtx *property)
|
||||
{
|
||||
const char *processName = GetBundleName(property);
|
||||
APPSPAWN_CHECK(processName != NULL, return, "Can not get bundle name");
|
||||
LoadSilkLibrary(processName);
|
||||
}
|
||||
|
||||
static int SpawnSetProperties(AppSpawnMgr *content, AppSpawningCtx *property)
|
||||
{
|
||||
APPSPAWN_LOGV("Spawning: set child property");
|
||||
SpawnLoadSilk(content, property);
|
||||
(void)umask(DEFAULT_UMASK);
|
||||
int ret = SetKeepCapabilities(content, property);
|
||||
APPSPAWN_CHECK_ONLY_EXPER(ret == 0, return ret);
|
||||
@ -512,10 +521,17 @@ static int SpawnGetSpawningFlag(AppSpawnMgr *content, AppSpawningCtx *property)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int SpawnLoadConfig(AppSpawnMgr *content)
|
||||
{
|
||||
LoadSilkConfig();
|
||||
return 0;
|
||||
}
|
||||
|
||||
MODULE_CONSTRUCTOR(void)
|
||||
{
|
||||
APPSPAWN_LOGV("Load common module ...");
|
||||
AddPreloadHook(HOOK_PRIO_COMMON, PreLoadSetSeccompFilter);
|
||||
AddPreloadHook(HOOK_PRIO_COMMON, SpawnLoadConfig);
|
||||
|
||||
AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_HIGHEST, SpawnGetSpawningFlag);
|
||||
AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_HIGHEST, SpawnInitSpawningEnv);
|
||||
|
137
modules/common/appspawn_silk.c
Normal file
137
modules/common/appspawn_silk.c
Normal file
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 <dlfcn.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "appspawn_server.h"
|
||||
#include "appspawn_silk.h"
|
||||
#include "appspawn_utils.h"
|
||||
#include "config_policy_utils.h"
|
||||
#include "cJSON.h"
|
||||
#include "json_utils.h"
|
||||
#include "securec.h"
|
||||
|
||||
#define SILK_JSON_CONFIG_PATH "/vendor/etc/silk/silk.json"
|
||||
#define SILK_JSON_ENABLE_ITEM "enabled_app_list"
|
||||
#define SILK_JSON_LIBRARY_PATH "/vendor/lib64/chipsetsdk/libsilk.so.0.1"
|
||||
|
||||
#define SILK_JSON_MAX 128
|
||||
#define SILK_JSON_NAME_MAX 256
|
||||
|
||||
struct SilkConfig {
|
||||
char **configItems;
|
||||
int configCursor;
|
||||
};
|
||||
|
||||
static struct SilkConfig g_silkConfig = {0};
|
||||
|
||||
static void ParseSilkConfig(const cJSON *root, struct SilkConfig *config)
|
||||
{
|
||||
cJSON *silkJson = cJSON_GetObjectItemCaseSensitive(root, SILK_JSON_ENABLE_ITEM);
|
||||
if (silkJson == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t configCount = cJSON_GetArraySize(silkJson);
|
||||
APPSPAWN_CHECK(configCount <= SILK_JSON_MAX, configCount = SILK_JSON_MAX,
|
||||
"config count %{public}u is larger than %{public}d", configCount, SILK_JSON_MAX);
|
||||
config->configItems = (char **)malloc(configCount * sizeof(char *));
|
||||
APPSPAWN_CHECK(config->configItems != NULL, return, "Alloc for silk config items failed");
|
||||
int ret = memset_s(config->configItems, configCount * sizeof(char *), 0, configCount * sizeof(char *));
|
||||
APPSPAWN_CHECK(ret == 0, free(config->configItems);
|
||||
config->configItems = NULL; return,
|
||||
"Memset silk config items failed");
|
||||
|
||||
for (uint32_t i = 0; i < configCount; ++i) {
|
||||
const char *appName = cJSON_GetStringValue(cJSON_GetArrayItem(silkJson, i));
|
||||
APPSPAWN_CHECK(appName != NULL, break, "appName is NULL");
|
||||
APPSPAWN_LOGI("Enable silk appName %{public}s", appName);
|
||||
|
||||
int len = strlen(appName) + 1;
|
||||
APPSPAWN_CHECK(len <= SILK_JSON_NAME_MAX, continue,
|
||||
"appName %{public}s is larger than the maximum limit", appName);
|
||||
char **item = &config->configItems[config->configCursor];
|
||||
*item = (char *)malloc(len * sizeof(char));
|
||||
APPSPAWN_CHECK(*item != NULL, break, "Alloc for config item failed");
|
||||
|
||||
ret = memset_s(*item, len * sizeof(char), 0, len * sizeof(char));
|
||||
APPSPAWN_CHECK(ret == 0, free(*item);
|
||||
*item = NULL; break,
|
||||
"Memset config item %{public}s failed", appName);
|
||||
|
||||
ret = strncpy_s(*item, len, appName, len - 1);
|
||||
APPSPAWN_CHECK(ret == 0, free(*item);
|
||||
*item = NULL; break,
|
||||
"Copy config item %{public}s failed", appName);
|
||||
config->configCursor++;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadSilkConfig(void)
|
||||
{
|
||||
cJSON *root = GetJsonObjFromFile(SILK_JSON_CONFIG_PATH);
|
||||
APPSPAWN_CHECK(root != NULL, return, "Failed to load silk config");
|
||||
ParseSilkConfig(root, &g_silkConfig);
|
||||
cJSON_Delete(root);
|
||||
}
|
||||
|
||||
static void FreeSilkConfigItems(void)
|
||||
{
|
||||
for (int i = 0; i < g_silkConfig.configCursor; i++) {
|
||||
if (g_silkConfig.configItems[i] != NULL) {
|
||||
free(g_silkConfig.configItems[i]);
|
||||
g_silkConfig.configItems[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void FreeSilkConfig(void)
|
||||
{
|
||||
free(g_silkConfig.configItems);
|
||||
g_silkConfig.configItems = NULL;
|
||||
g_silkConfig.configCursor = 0;
|
||||
}
|
||||
|
||||
static void FreeAllSilkConfig(void)
|
||||
{
|
||||
FreeSilkConfigItems();
|
||||
FreeSilkConfig();
|
||||
}
|
||||
|
||||
void LoadSilkLibrary(const char *packageName)
|
||||
{
|
||||
APPSPAWN_CHECK(g_silkConfig.configItems != NULL, return,
|
||||
"Load silk library failed for configItems is NULL");
|
||||
APPSPAWN_CHECK(packageName != NULL, FreeAllSilkConfig(); return,
|
||||
"Load silk library failed for packageName is NULL");
|
||||
char **appName = NULL;
|
||||
void *handle = NULL;
|
||||
for (int i = 0; i < g_silkConfig.configCursor; i++) {
|
||||
appName = &g_silkConfig.configItems[i];
|
||||
if (*appName == NULL) {
|
||||
break;
|
||||
}
|
||||
if (handle == NULL && strcmp(*appName, packageName) == 0) {
|
||||
handle = dlopen(SILK_JSON_LIBRARY_PATH, RTLD_NOW);
|
||||
APPSPAWN_LOGI("Enable Silk AppName %{public}s result:%{public}s",
|
||||
*appName, handle ? "success" : "failed");
|
||||
}
|
||||
free(*appName);
|
||||
*appName = NULL;
|
||||
}
|
||||
FreeSilkConfig();
|
||||
}
|
22
modules/common/appspawn_silk.h
Normal file
22
modules/common/appspawn_silk.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 APPSPAWN_SILK_CPP
|
||||
#define APPSPAWN_SILK_CPP
|
||||
|
||||
void LoadSilkConfig(void);
|
||||
void LoadSilkLibrary(const char *packageName);
|
||||
|
||||
#endif
|
@ -89,6 +89,7 @@ ohos_unittest("AppSpawn_ut") {
|
||||
"${appspawn_path}/modules/common/appspawn_cgroup.c",
|
||||
"${appspawn_path}/modules/common/appspawn_common.c",
|
||||
"${appspawn_path}/modules/common/appspawn_namespace.c",
|
||||
"${appspawn_path}/modules/common/appspawn_silk.c",
|
||||
"${appspawn_path}/modules/nweb_adapter/nwebspawn_adapter.cpp",
|
||||
"${appspawn_path}/modules/sandbox/appspawn_mount_template.c",
|
||||
"${appspawn_path}/modules/sandbox/appspawn_permission.c",
|
||||
|
Loading…
Reference in New Issue
Block a user