!3149 add os api name

Merge pull request !3149 from 杨浩/0914osapiname
This commit is contained in:
openharmony_ci 2024-09-20 03:22:46 +00:00 committed by Gitee
commit 8db2b4a9ae
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 21 additions and 0 deletions

View File

@ -187,6 +187,7 @@ uint32_t GetUintParameter(const char *key, uint32_t def);
const char *GetDistributionOSName(void);
const char *GetDistributionOSVersion(void);
int GetDistributionOSApiVersion(void);
const char *GetDistributionOSApiName(void);
const char *GetDistributionOSReleaseType(void);
#ifdef __cplusplus

View File

@ -147,6 +147,7 @@
GetDistributionOSName;
GetDistributionOSVersion;
GetDistributionOSApiVersion;
GetDistributionOSApiName;
GetDistributionOSReleaseType;
SaveParameters;
OH_StrArrayGetIndex;

View File

@ -397,6 +397,15 @@ int GetDistributionOSApiVersion(void)
}
return atoi(distributionOsApiVersion);
}
const char *GetDistributionOSApiName(void)
{
static const char *distributionOsApiName = NULL;
GetProperty("const.product.os.dist.apiname", &distributionOsApiName);
if (distributionOsApiName == NULL) {
distributionOsApiName = EMPTY_STR;
}
return distributionOsApiName;
}
const char *GetDistributionOSReleaseType(void)
{

View File

@ -420,6 +420,15 @@ static napi_value NAPI_GetDistributionOSApiVersion(napi_env env, napi_callback_i
return napiValue;
}
static napi_value NAPI_GetDistributionOSApiName(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *val = GetDistributionOSApiName();
NAPI_CALL(env, napi_create_string_utf8(env, val, strlen(val), &napiValue));
return napiValue;
}
static napi_value NAPI_GetDistributionOSReleaseType(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
@ -523,6 +532,7 @@ static napi_value Init(napi_env env, napi_value exports)
{"distributionOSName", nullptr, nullptr, NAPI_GetDistributionOSName, nullptr, nullptr, napi_default, nullptr},
{"distributionOSVersion", nullptr, nullptr, NAPI_GetDistributionOSVersion, nullptr, nullptr, napi_default, nullptr},
{"distributionOSApiVersion", nullptr, nullptr, NAPI_GetDistributionOSApiVersion, nullptr, nullptr, napi_default, nullptr},
{"distributionOSApiName", nullptr, nullptr, NAPI_GetDistributionOSApiName, nullptr, nullptr, napi_default, nullptr},
{"distributionOSReleaseType", nullptr, nullptr, NAPI_GetDistributionOSReleaseType, nullptr, nullptr, napi_default, nullptr},
{"ODID", nullptr, nullptr, GetDevOdid, nullptr, nullptr, napi_default, nullptr},
};