mirror of
https://gitee.com/openharmony/startup_init
synced 2024-12-13 13:54:18 +00:00
Merge branch 'master' of gitee.com:openharmony/startup_init_lite into 0410_begetutil
Signed-off-by: cheng_jinsong <chengjinsong2@huawei.com>
This commit is contained in:
commit
4f32bfd4a1
@ -53,8 +53,8 @@ if (!defined(ohos_lite)) {
|
||||
deps = [
|
||||
"//base/startup/init/interfaces/innerkits:libbegetutil",
|
||||
"//base/startup/init/services/log:agent_log",
|
||||
"//base/startup/init/services/modules/udid:libudidcomm",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
@ -54,7 +54,6 @@ if (defined(ohos_lite)) {
|
||||
defines = [
|
||||
"_GNU_SOURCE",
|
||||
"OHOS_LITE",
|
||||
"USE_MBEDTLS",
|
||||
]
|
||||
sources = []
|
||||
include_dirs = include_common
|
||||
@ -63,10 +62,10 @@ if (defined(ohos_lite)) {
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
|
||||
"//base/startup/init/services/modules/init_hook:inithook",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
deps += [
|
||||
"//base/startup/init/services/log:init_log",
|
||||
"//base/startup/init/services/modules/udid:libudidcomm",
|
||||
"//base/startup/init/services/utils:libinit_utils",
|
||||
]
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
@ -104,6 +103,7 @@ if (defined(ohos_lite)) {
|
||||
deps = [
|
||||
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static",
|
||||
"//base/startup/init/services/modules/init_hook:inithook",
|
||||
"//base/startup/init/services/modules/udid:libudidcomm",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
]
|
||||
|
||||
@ -126,10 +126,6 @@ if (defined(ohos_lite)) {
|
||||
sources += [ "syscap/init_syscap.c" ]
|
||||
}
|
||||
|
||||
if (enable_ohos_startup_init_lite_use_thirdparty_mbedtls) {
|
||||
deps += [ "//third_party/mbedtls:mbedtls" ]
|
||||
defines += [ "USE_MBEDTLS" ]
|
||||
}
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
deps += [
|
||||
"//base/startup/init/services/log:init_log",
|
||||
@ -181,7 +177,6 @@ if (defined(ohos_lite)) {
|
||||
defines = [
|
||||
"INIT_AGENT",
|
||||
"_GNU_SOURCE",
|
||||
"USE_MBEDTLS",
|
||||
]
|
||||
if (target_cpu == "arm64") {
|
||||
defines += [ "SUPPORT_64BIT" ]
|
||||
@ -196,10 +191,10 @@ if (defined(ohos_lite)) {
|
||||
"//base/startup/init/interfaces/innerkits/socket:libsocket",
|
||||
"//base/startup/init/services/log:agent_log",
|
||||
"//base/startup/init/services/loopevent:loopevent",
|
||||
"//base/startup/init/services/modules/udid:libudidcomm",
|
||||
"//base/startup/init/services/param/linux:param_client",
|
||||
"//base/startup/init/services/utils:libinit_utils",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
deps += [ "//base/startup/init/services/param/base:param_base" ]
|
||||
if (startup_begetutil_extra_modules != "") {
|
||||
@ -224,7 +219,6 @@ if (defined(ohos_lite)) {
|
||||
defines = [
|
||||
"INIT_AGENT",
|
||||
"_GNU_SOURCE",
|
||||
"USE_MBEDTLS",
|
||||
]
|
||||
sources = [
|
||||
"//base/startup/init/device_info/device_info.cpp",
|
||||
@ -287,7 +281,6 @@ if (defined(ohos_lite)) {
|
||||
defines = [
|
||||
"INIT_AGENT",
|
||||
"_GNU_SOURCE",
|
||||
"USE_MBEDTLS",
|
||||
]
|
||||
if (target_cpu == "arm64") {
|
||||
defines += [ "SUPPORT_64BIT" ]
|
||||
@ -297,10 +290,10 @@ if (defined(ohos_lite)) {
|
||||
deps = [
|
||||
"//base/startup/init/services/log:agent_log",
|
||||
"//base/startup/init/services/loopevent:loopevent",
|
||||
"//base/startup/init/services/modules/udid:libudidcomm",
|
||||
"//base/startup/init/services/param/linux:param_client",
|
||||
"//base/startup/init/services/utils:libinit_utils",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
deps += [ "//base/startup/init/services/param/base:param_base" ]
|
||||
external_deps = [
|
||||
|
@ -19,15 +19,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "init_param.h"
|
||||
#ifdef LITEOS_SUPPORT
|
||||
#include "hal_sys_param.h"
|
||||
#endif
|
||||
#include "parameter.h"
|
||||
#include "sysparam_errno.h"
|
||||
#ifdef USE_MBEDTLS
|
||||
#include "mbedtls/sha256.h"
|
||||
#endif
|
||||
|
||||
#include "securec.h"
|
||||
#include "beget_ext.h"
|
||||
|
||||
@ -137,92 +130,6 @@ INIT_LOCAL_API const char *GetManufacture_(void)
|
||||
return GetProperty("const.product.manufacturer", &productManufacture);
|
||||
}
|
||||
|
||||
#ifdef USE_MBEDTLS
|
||||
static int GetSha256Value(const char *input, char *udid, int udidSize)
|
||||
{
|
||||
if (input == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
char buf[DEV_BUF_LENGTH] = { 0 };
|
||||
unsigned char hash[HASH_LENGTH] = { 0 };
|
||||
|
||||
mbedtls_sha256_context context;
|
||||
mbedtls_sha256_init(&context);
|
||||
mbedtls_sha256_starts(&context, 0);
|
||||
mbedtls_sha256_update(&context, (const unsigned char *)input, strlen(input));
|
||||
mbedtls_sha256_finish(&context, hash);
|
||||
|
||||
for (size_t i = 0; i < HASH_LENGTH; i++) {
|
||||
unsigned char value = hash[i];
|
||||
memset_s(buf, DEV_BUF_LENGTH, 0, DEV_BUF_LENGTH);
|
||||
int len = sprintf_s(buf, sizeof(buf), "%02X", value);
|
||||
if (len > 0 && strcat_s(udid, udidSize, buf) != 0) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
#else
|
||||
static int GetSha256Value(const char *input, char *udid, int udidSize)
|
||||
{
|
||||
(void)input;
|
||||
(void)udid;
|
||||
(void)udidSize;
|
||||
return EC_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
INIT_LOCAL_API const char *GetSerial_(void)
|
||||
{
|
||||
#ifdef LITEOS_SUPPORT
|
||||
return HalGetSerial();
|
||||
#else
|
||||
static char *ohosSerial = NULL;
|
||||
if (ohosSerial == NULL) {
|
||||
BEGET_CHECK((ohosSerial = (char *)calloc(1, PARAM_VALUE_LEN_MAX)) != NULL, return NULL);
|
||||
}
|
||||
uint32_t len = PARAM_VALUE_LEN_MAX;
|
||||
int ret = SystemGetParameter("ohos.boot.sn", ohosSerial, &len);
|
||||
BEGET_CHECK(ret == 0, return NULL);
|
||||
return ohosSerial;
|
||||
#endif
|
||||
}
|
||||
|
||||
INIT_LOCAL_API int GetDevUdid_(char *udid, int size)
|
||||
{
|
||||
if (size < UDID_LEN || udid == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
uint32_t len = (uint32_t)size;
|
||||
int ret = SystemGetParameter("const.product.udid", udid, &len);
|
||||
BEGET_CHECK(ret != 0, return ret);
|
||||
|
||||
const char *manufacture = GetManufacture_();
|
||||
const char *model = GetProductModel_();
|
||||
const char *sn = GetSerial_();
|
||||
if (manufacture == NULL || model == NULL || sn == NULL) {
|
||||
return -1;
|
||||
}
|
||||
int tmpSize = strlen(manufacture) + strlen(model) + strlen(sn) + 1;
|
||||
if (tmpSize <= 1 || tmpSize > DEV_BUF_MAX_LENGTH) {
|
||||
return -1;
|
||||
}
|
||||
char *tmp = NULL;
|
||||
BEGET_CHECK((tmp = (char *)malloc(tmpSize)) != NULL, return -1);
|
||||
|
||||
(void)memset_s(tmp, tmpSize, 0, tmpSize);
|
||||
if ((strcat_s(tmp, tmpSize, manufacture) != 0) || (strcat_s(tmp, tmpSize, model) != 0) ||
|
||||
(strcat_s(tmp, tmpSize, sn) != 0)) {
|
||||
free(tmp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = GetSha256Value(tmp, udid, size);
|
||||
free(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
INIT_LOCAL_API const char *GetFullName_(void)
|
||||
{
|
||||
static const char *fillname = NULL;
|
||||
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AsyncCallback, BusinessError } from './basic';
|
||||
import { AsyncCallback, BusinessError } from './@ohos.base';
|
||||
|
||||
/**
|
||||
* The interface of system parameters class.
|
||||
|
@ -19,6 +19,7 @@ group("static_modules") {
|
||||
"bootevent:libbootevent_static",
|
||||
"init_hook:inithook",
|
||||
"reboot:libreboot_static",
|
||||
"udid:libudid_static",
|
||||
]
|
||||
if (build_seccomp) {
|
||||
deps += [ "seccomp:libseccomp_static" ]
|
||||
@ -34,6 +35,7 @@ group("modulesgroup") {
|
||||
deps = [
|
||||
"bootchart:bootchart",
|
||||
"reboot:rebootmodule",
|
||||
"udid:udidmodule",
|
||||
]
|
||||
if (build_seccomp) {
|
||||
deps += [ "seccomp:seccomp_filter" ]
|
||||
|
@ -974,7 +974,7 @@ class SeccompPolicyParser:
|
||||
self.parse_file(file_name)
|
||||
|
||||
for file_name in args.keyprocess_file:
|
||||
if file_name.lower().endswith('key_process.seccomp.policy'):
|
||||
if file_name.lower().endswith('privileged_process.seccomp.policy'):
|
||||
self.key_process_flag = True
|
||||
self.parse_file(file_name)
|
||||
self.key_process_flag = False
|
||||
|
121
services/modules/udid/BUILD.gn
Normal file
121
services/modules/udid/BUILD.gn
Normal file
@ -0,0 +1,121 @@
|
||||
# Copyright (c) 2023 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.
|
||||
|
||||
import("//base/startup/init/begetd.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
comm_include = [
|
||||
".",
|
||||
"..",
|
||||
"../init_hook",
|
||||
"../../include/param",
|
||||
"../../../interfaces/innerkits/include",
|
||||
"../../../interfaces/innerkits/include/syspara",
|
||||
"../../../interfaces/innerkits/syspara",
|
||||
]
|
||||
|
||||
if (defined(ohos_lite)) {
|
||||
static_library("libudidcomm") {
|
||||
defines = [
|
||||
"_GNU_SOURCE",
|
||||
"OHOS_LITE",
|
||||
]
|
||||
include_dirs = comm_include
|
||||
include_dirs += [
|
||||
"../../../interfaces/innerkits/init_module_engine/include",
|
||||
"../../../interfaces/hals",
|
||||
]
|
||||
sources = [
|
||||
"udid_adp.c",
|
||||
"udid_comm.c",
|
||||
]
|
||||
|
||||
deps = []
|
||||
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
|
||||
deps += [
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
} else if (ohos_kernel_type == "liteos_m") {
|
||||
deps += [
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
"//third_party/mbedtls:mbedtls",
|
||||
]
|
||||
}
|
||||
|
||||
#if product exit, use product
|
||||
if (enable_ohos_startup_init_feature_begetctl_liteos) {
|
||||
PRODUCT_HAL_SYSPARAM_PATH =
|
||||
rebase_path("${ohos_product_adapter_dir}/utils/sys_param")
|
||||
cmd = "if [ -f ${PRODUCT_HAL_SYSPARAM_PATH}/BUILD.gn ]; then echo true; else echo false; fi"
|
||||
PRODUCT_HAL_SYSPARAM_EXISTS =
|
||||
exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
|
||||
if (PRODUCT_HAL_SYSPARAM_EXISTS) {
|
||||
deps += [ "$ohos_product_adapter_dir/utils/sys_param:hal_sysparam" ]
|
||||
}
|
||||
deps += [ "../../../interfaces/hals/utils/sys_param:hal_sys_param" ]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ohos_shared_library("udidmodule") {
|
||||
sources = [
|
||||
"udid_adp.c",
|
||||
"udid_comm.c",
|
||||
]
|
||||
defines = [ "_GNU_SOURCE" ]
|
||||
include_dirs = comm_include
|
||||
deps = [
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
"//third_party/mbedtls:mbedtls_shared",
|
||||
]
|
||||
|
||||
external_deps = [ "init:libinit_module_engine" ]
|
||||
|
||||
part_name = "init"
|
||||
subsystem_name = "startup"
|
||||
if (target_cpu == "arm64") {
|
||||
module_install_dir = "lib64/init"
|
||||
} else {
|
||||
module_install_dir = "lib/init"
|
||||
}
|
||||
install_images = [
|
||||
"system",
|
||||
"updater",
|
||||
]
|
||||
}
|
||||
|
||||
config("udid_static_config") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
|
||||
ohos_source_set("libudid_static") {
|
||||
sources = [ "udid_static.c" ]
|
||||
defines = [ "_GNU_SOURCE" ]
|
||||
include_dirs = comm_include
|
||||
public_configs = [ ":udid_static_config" ]
|
||||
public_configs += [ "../../../interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
|
||||
part_name = "init"
|
||||
subsystem_name = "startup"
|
||||
}
|
||||
|
||||
# for begetutil
|
||||
ohos_static_library("libudidcomm") {
|
||||
sources = [ "udid_comm.c" ]
|
||||
defines = [ "_GNU_SOURCE" ]
|
||||
include_dirs = comm_include
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
|
||||
|
||||
part_name = "init"
|
||||
subsystem_name = "startup"
|
||||
}
|
||||
}
|
24
services/modules/udid/udid.h
Normal file
24
services/modules/udid/udid.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 PLUGIN_UDID_H
|
||||
#define PLUGIN_UDID_H
|
||||
|
||||
#include "beget_ext.h"
|
||||
|
||||
INIT_LOCAL_API int GetUdidFromParam(char *udid, uint32_t size);
|
||||
INIT_LOCAL_API int CalcDevUdid(char *udid, uint32_t size);
|
||||
|
||||
#endif /* PLUGIN_UDID_H */
|
95
services/modules/udid/udid_adp.c
Normal file
95
services/modules/udid/udid_adp.c
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "udid.h"
|
||||
#ifndef OHOS_LITE
|
||||
#include "init_module_engine.h"
|
||||
#endif
|
||||
#include "init_param.h"
|
||||
#include "param_comm.h"
|
||||
#include "securec.h"
|
||||
#include "sysparam_errno.h"
|
||||
|
||||
#include "mbedtls/sha256.h"
|
||||
|
||||
static int GetSha256Value(const char *input, char *udid, uint32_t udidSize)
|
||||
{
|
||||
if (input == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
char buf[DEV_BUF_LENGTH] = { 0 };
|
||||
unsigned char hash[HASH_LENGTH] = { 0 };
|
||||
|
||||
mbedtls_sha256_context context;
|
||||
mbedtls_sha256_init(&context);
|
||||
mbedtls_sha256_starts(&context, 0);
|
||||
mbedtls_sha256_update(&context, (const unsigned char *)input, strlen(input));
|
||||
mbedtls_sha256_finish(&context, hash);
|
||||
|
||||
for (size_t i = 0; i < HASH_LENGTH; i++) {
|
||||
unsigned char value = hash[i];
|
||||
memset_s(buf, DEV_BUF_LENGTH, 0, DEV_BUF_LENGTH);
|
||||
int len = sprintf_s(buf, sizeof(buf), "%02X", value);
|
||||
if (len > 0 && strcat_s(udid, udidSize, buf) != 0) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
}
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
INIT_LOCAL_API int CalcDevUdid(char *udid, uint32_t size)
|
||||
{
|
||||
char *tmp = NULL;
|
||||
BEGET_ERROR_CHECK((tmp = (char *)calloc(1, DEV_BUF_MAX_LENGTH)) != NULL, return -1, "calloc memory failed!");
|
||||
|
||||
uint32_t manufactureLen = PARAM_VALUE_LEN_MAX;
|
||||
int ret = SystemReadParam("const.product.manufacturer", tmp, &manufactureLen);
|
||||
BEGET_ERROR_CHECK(ret == 0, free(tmp);
|
||||
return -1, "Read param const.product.manufacturer failed!");
|
||||
|
||||
uint32_t modelLen = PARAM_VALUE_LEN_MAX;
|
||||
ret = SystemReadParam("const.product.model", tmp + manufactureLen, &modelLen);
|
||||
BEGET_ERROR_CHECK(ret == 0, free(tmp);
|
||||
return -1, "Read param const.product.model failed!");
|
||||
const char *serial = GetSerial_();
|
||||
BEGET_ERROR_CHECK(serial != NULL, free(tmp);
|
||||
return -1, "Read param serial failed!");
|
||||
ret = strcat_s(tmp, DEV_BUF_MAX_LENGTH, serial);
|
||||
BEGET_ERROR_CHECK(ret != -1, free(tmp);
|
||||
return -1, "Cat serial failed!");
|
||||
ret = GetSha256Value(tmp, udid, size);
|
||||
free(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OHOS_LITE
|
||||
static void SetDevUdid()
|
||||
{
|
||||
BEGET_LOGI("Begin calculate udid");
|
||||
char udid[UDID_LEN] = {0};
|
||||
uint32_t size = (uint32_t)sizeof(udid);
|
||||
int ret = GetUdidFromParam(udid, size);
|
||||
if (ret != 0) {
|
||||
ret = CalcDevUdid(udid, size);
|
||||
BEGET_ERROR_CHECK(ret == 0, return, "calculate udid is failed!")
|
||||
}
|
||||
ret = SystemWriteParam("const.product.devUdid", udid);
|
||||
BEGET_ERROR_CHECK(ret == 0, return, "write param const.product.devUdid failed!");
|
||||
}
|
||||
|
||||
MODULE_CONSTRUCTOR(void)
|
||||
{
|
||||
SetDevUdid();
|
||||
}
|
||||
#endif
|
66
services/modules/udid/udid_comm.c
Normal file
66
services/modules/udid/udid_comm.c
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "udid.h"
|
||||
|
||||
#ifdef OHOS_LITE
|
||||
#include "hal_sys_param.h"
|
||||
#endif
|
||||
#include "init_param.h"
|
||||
#include "param_comm.h"
|
||||
#include "securec.h"
|
||||
#include "sysparam_errno.h"
|
||||
|
||||
INIT_LOCAL_API const char *GetSerial_(void)
|
||||
{
|
||||
#ifdef OHOS_LITE
|
||||
return HalGetSerial();
|
||||
#else
|
||||
static char *ohosSerial = NULL;
|
||||
if (ohosSerial == NULL) {
|
||||
BEGET_CHECK((ohosSerial = (char *)calloc(1, PARAM_VALUE_LEN_MAX)) != NULL, return NULL);
|
||||
}
|
||||
uint32_t len = PARAM_VALUE_LEN_MAX;
|
||||
int ret = SystemGetParameter("ohos.boot.sn", ohosSerial, &len);
|
||||
BEGET_CHECK(ret == 0, return NULL);
|
||||
return ohosSerial;
|
||||
#endif
|
||||
}
|
||||
|
||||
INIT_LOCAL_API int GetUdidFromParam(char *udid, uint32_t size)
|
||||
{
|
||||
uint32_t len = size;
|
||||
int ret = SystemGetParameter("const.product.udid", udid, &len);
|
||||
BEGET_CHECK(ret != 0, return ret);
|
||||
|
||||
len = size;
|
||||
ret = SystemGetParameter("const.product.devUdid", udid, &len);
|
||||
BEGET_CHECK(ret != 0, return ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
INIT_LOCAL_API int GetDevUdid_(char *udid, int size)
|
||||
{
|
||||
if (size < UDID_LEN || udid == NULL) {
|
||||
return EC_FAILURE;
|
||||
}
|
||||
|
||||
int ret = GetUdidFromParam(udid, (uint32_t)size);
|
||||
BEGET_CHECK(ret != 0, return ret);
|
||||
|
||||
#ifdef OHOS_LITE
|
||||
ret = CalcDevUdid(udid, size);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
34
services/modules/udid/udid_static.c
Normal file
34
services/modules/udid/udid_static.c
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "init_hook.h"
|
||||
#include "init_module_engine.h"
|
||||
#include "plugin_adapter.h"
|
||||
|
||||
static int UDidCalc(const HOOK_INFO *hookInfo, void *cookie)
|
||||
{
|
||||
PLUGIN_LOGI("Begin install udidmodule.");
|
||||
|
||||
InitModuleMgrInstall("udidmodule");
|
||||
PLUGIN_LOGI("Begin uninstall udidmodule.");
|
||||
InitModuleMgrUnInstall("udidmodule");
|
||||
|
||||
PLUGIN_LOGI("Uninstall udidmodule finished.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
MODULE_CONSTRUCTOR(void)
|
||||
{
|
||||
InitAddPreCfgLoadHook(0, UDidCalc);
|
||||
}
|
@ -110,6 +110,9 @@ ohos_unittest("init_unittest") {
|
||||
"//base/startup/init/services/modules/reboot/reboot.c",
|
||||
"//base/startup/init/services/modules/reboot/reboot_misc.c",
|
||||
"//base/startup/init/services/modules/reboot/reboot_static.c",
|
||||
"//base/startup/init/services/modules/udid/udid_adp.c",
|
||||
"//base/startup/init/services/modules/udid/udid_comm.c",
|
||||
"//base/startup/init/services/modules/udid/udid_static.c",
|
||||
"//base/startup/init/services/param/adapter/param_dac.c",
|
||||
"//base/startup/init/services/param/adapter/param_persistadp.c",
|
||||
"//base/startup/init/services/param/base/param_base.c",
|
||||
@ -232,6 +235,7 @@ ohos_unittest("init_unittest") {
|
||||
"//base/startup/init/services/modules/init_hook",
|
||||
"//base/startup/init/services/modules/selinux",
|
||||
"//base/startup/init/services/modules/reboot",
|
||||
"//base/startup/init/services/modules/udid",
|
||||
"//base/startup/init/services/loopevent/utils",
|
||||
"//base/startup/init/services/param/adapter",
|
||||
"//base/startup/init/services/param/base",
|
||||
|
@ -37,6 +37,8 @@ if (defined(ohos_lite)) {
|
||||
}
|
||||
param_common_sources = [
|
||||
"//base/startup/init/services/modules/init_hook/param_hook.c",
|
||||
"//base/startup/init/services/modules/udid/udid_adp.c",
|
||||
"//base/startup/init/services/modules/udid/udid_comm.c",
|
||||
"//base/startup/init/services/param/manager/param_manager.c",
|
||||
"//base/startup/init/services/param/manager/param_persist.c",
|
||||
"//base/startup/init/services/param/manager/param_server.c",
|
||||
@ -112,6 +114,7 @@ if (defined(ohos_lite)) {
|
||||
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
|
||||
"//base/startup/init/interfaces/innerkits/fd_holder",
|
||||
"//base/startup/init/interfaces/hals",
|
||||
"//base/startup/init/services/modules/udid",
|
||||
]
|
||||
|
||||
sources = sysparam_source
|
||||
|
Loading…
Reference in New Issue
Block a user