mirror of
https://github.com/openharmony/customization_config_policy.git
synced 2026-07-20 19:34:22 -04:00
Config policy adapte mini sytem
Signed-off-by: zhr758 <zhanghaoran@huawei.com>
This commit is contained in:
@@ -17,6 +17,11 @@ if (defined(ohos_lite)) {
|
||||
import("//build/ohos.gni")
|
||||
}
|
||||
|
||||
declare_args() {
|
||||
# if fs has prefix before OH path, set it here
|
||||
config_policy_fs_prefix = ""
|
||||
}
|
||||
|
||||
config_policy_sources = [ "src/config_policy_utils.c" ]
|
||||
config("config_policy_config") {
|
||||
include_dirs = [
|
||||
@@ -26,9 +31,20 @@ config("config_policy_config") {
|
||||
]
|
||||
}
|
||||
|
||||
if (defined(ohos_lite)) {
|
||||
if (defined(ohos_lite) && ohos_kernel_type == "liteos_m") {
|
||||
static_library("configpolicy_util") {
|
||||
sources = config_policy_sources
|
||||
if (config_policy_fs_prefix != "") {
|
||||
print("cust config_policy_fs_prefix: ${config_policy_fs_prefix}")
|
||||
defines = [ "ROOT_PREFIX=\"${config_policy_fs_prefix}\"" ]
|
||||
}
|
||||
include_dirs = [
|
||||
"//base/customization/config_policy/interfaces/inner_api/include",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
]
|
||||
}
|
||||
} else if (defined(ohos_lite)) {
|
||||
shared_library("configpolicy_util") {
|
||||
defines = [ "OHOS_LITE" ]
|
||||
sources = config_policy_sources
|
||||
public_configs = [ ":config_policy_config" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config_policy_impl.h"
|
||||
#ifndef OHOS_LITE
|
||||
#ifndef __LITEOS__
|
||||
#include "init_param.h"
|
||||
#endif
|
||||
|
||||
@@ -46,6 +46,23 @@ typedef struct {
|
||||
char *segs[1];
|
||||
} SplitedStr;
|
||||
|
||||
#ifdef __LITEOS_M__
|
||||
// The data will be used always, so prealloc to avoid memory fragment
|
||||
static char gConfigPolicy[MINI_CONFIG_POLICY_BUF_SIZE] = {0};
|
||||
void SetMiniConfigPolicy(const char *policy)
|
||||
{
|
||||
if (gConfigPolicy[0] != 0) {
|
||||
return; // now only set once
|
||||
}
|
||||
(void)strcpy_s(gConfigPolicy, sizeof(gConfigPolicy), policy);
|
||||
}
|
||||
|
||||
__WEAK void TrigSetMiniConfigPolicy()
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* query function, the memory is allocated in function
|
||||
* @return value, or NULL if not exist or strlen(value) is 0
|
||||
@@ -71,6 +88,7 @@ static void FreeIf(void *p)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __LITEOS__
|
||||
static char *CustGetSystemParam(const char *name)
|
||||
{
|
||||
char *value = NULL;
|
||||
@@ -119,6 +137,7 @@ static char *GetOpkeyPath(int type)
|
||||
FreeIf(result);
|
||||
return NULL;
|
||||
}
|
||||
#endif // __LITEOS__
|
||||
|
||||
static SplitedStr *SplitStr(char *str, char delim)
|
||||
{
|
||||
@@ -151,6 +170,7 @@ static void FreeSplitedStr(SplitedStr *p)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __LITEOS__
|
||||
// get follow x rule from param variant
|
||||
// *mode: read from contains param variant, mode is output param.
|
||||
// return: extra path rule.
|
||||
@@ -237,6 +257,12 @@ static SplitedStr *GetFollowXPathByMode(const char *relPath, int followMode, con
|
||||
SplitedStr *result = expandVal ? SplitStr(expandVal, ',') : NULL;
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
static SplitedStr *GetFollowXPathByMode(const char *relPath, int followMode, const char *extra)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *TrimInplace(char *str, bool moveToStart)
|
||||
{
|
||||
@@ -344,13 +370,22 @@ static void GetCfgDirRealPolicyValue(CfgDir *res)
|
||||
if (res == NULL) {
|
||||
return;
|
||||
}
|
||||
#ifndef OHOS_LITE
|
||||
#ifdef __LITEOS_M__
|
||||
if (gConfigPolicy[0] == '\0') {
|
||||
TrigSetMiniConfigPolicy();
|
||||
}
|
||||
if (gConfigPolicy[0] != '\0') {
|
||||
res->realPolicyValue = strdup(gConfigPolicy);
|
||||
}
|
||||
#elif defined(__LITEOS__)
|
||||
// use default, now do nothing
|
||||
#else
|
||||
res->realPolicyValue = CustGetSystemParam(CUST_KEY_POLICY_LAYER);
|
||||
if (res->realPolicyValue != NULL) {
|
||||
#endif
|
||||
if (res->realPolicyValue != NULL && res->realPolicyValue[0]) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
res->realPolicyValue = strdup("/system:/chipset:/sys_prod:/chip_prod");
|
||||
res->realPolicyValue = strdup(DEFAULT_LAYER);
|
||||
}
|
||||
|
||||
void FreeCfgFiles(CfgFiles *res)
|
||||
|
||||
@@ -30,6 +30,19 @@ extern "C" {
|
||||
// opkey info for sim1
|
||||
#define CUST_OPKEY1 "telephony.sim.opkey1"
|
||||
|
||||
// if fs need path prefix, set ROOT_PREFIX before include current file
|
||||
#ifndef ROOT_PREFIX
|
||||
#define ROOT_PREFIX ""
|
||||
#endif
|
||||
#define DEFAULT_LAYER ROOT_PREFIX"/system:"ROOT_PREFIX"/chipset:"ROOT_PREFIX"/sys_prod:"ROOT_PREFIX"/chip_prod"
|
||||
|
||||
#ifdef __LITEOS_M__
|
||||
#define MINI_CONFIG_POLICY_BUF_SIZE 256
|
||||
// for mini system, if exceed max size will not set
|
||||
void SetMiniConfigPolicy(const char *policy);
|
||||
__WEAK void TrigSetMiniConfigPolicy();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user