diff --git a/frameworks/config_policy/BUILD.gn b/frameworks/config_policy/BUILD.gn index 5317390dac936550e1b89c397785b75432eb034b..91b2529c7f9a0e52fa8fc07186be4f9f5441eb10 100644 --- a/frameworks/config_policy/BUILD.gn +++ b/frameworks/config_policy/BUILD.gn @@ -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" ] diff --git a/frameworks/config_policy/src/config_policy_utils.c b/frameworks/config_policy/src/config_policy_utils.c index 92b7c45def4ae039cc739187989b126e7d99bdf7..eb3539a525b305e018f5b344e17de1761a7fbfb3 100644 --- a/frameworks/config_policy/src/config_policy_utils.c +++ b/frameworks/config_policy/src/config_policy_utils.c @@ -21,7 +21,7 @@ #include #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) diff --git a/interfaces/inner_api/include/config_policy_impl.h b/interfaces/inner_api/include/config_policy_impl.h index b13d4a98c343f9fd021c039fdfcb94a6299bee07..8a0d98acc8e400ec19d1f1a544df322ea4f19c6c 100644 --- a/interfaces/inner_api/include/config_policy_impl.h +++ b/interfaces/inner_api/include/config_policy_impl.h @@ -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 }