提交 3f69b573 编写于 作者: R renwei

Merge branch 'master' of gitee.com:openharmony/startup_init_lite

Change-Id: I0a742fff28c67b451eaa1fb3596a4f5015782fdf
......@@ -59,7 +59,7 @@ init将系统启动分为三个阶段:
* 分组并行启动
无须显式添加start命令,服务的start-mode属性为非condition配置,init将会为该服务按策略分组并在该分组服务启动时统一拉起
* 按需启动
按需启动的服务应当被认为是无须在系统启动过程中被拉起的,而是当需要时,这个当需要时的触发条件可能是被init监听的相关socket有消息上报、samgr收到客户端的请求需要拉起SA服务等情况,按需启动的服务需要配置ondemand属性为true,start-mode属性需要配置为condition
按需启动的服务应当被认为是无须在系统启动过程中被拉起的,而是当需要时,这个当需要时的触发条件可能是被init监听的相关socket有消息上报、samgr收到客户端的请求需要拉起SA服务等情况,按需启动的服务需要配置ondemand属性为true,该属性拥有高优先级,配置该属性后服务将不再受start-mode属性控制,统一通过按需启动方式拉起
对于每个服务的启动,进程的运行,init提供了以保障系统安全性为目的的沙盒运行环境。每个进程运行时都有不同的环境约束,各个分层之间进程的资源隔离,确保每个进程都在各自的沙盒环境下运行,只访问允许的系统资源。
......@@ -120,8 +120,7 @@ init的关键配置文件init.cfg位于代码仓库base/startup/init_lite/servic
]
}],
"critical" : [ 0, 15, 5],
"ondemand" : true,
"start-mode" : "condition"
"ondemand" : true
}, {
"name" : "service2",
"path" : ["/system/bin/process2"],
......
......@@ -13,8 +13,12 @@
declare_args() {
param_feature_watcher = true
param_feature_deviceinfo = true
param_test = true
param_begetctl_liteos_support = false
enable_ohos_startup_init_lite_use_thirdparty_mbedtls = true
enable_ohos_startup_init_lite_use_posix_file_api = false
config_ohos_startup_init_lite_data_path = ""
if (defined(product_name) && product_name == "rk3568") {
boot_kernel_extended_cmdline =
"hardware=rk3568 default_boot_device=fe310000.sdhci"
......
......@@ -22,7 +22,7 @@
"deps": {
"components": [
"selinux",
"ipc",
"ipc",
"safwk",
"samgr_standard",
"utils_base",
......@@ -43,7 +43,7 @@
"//base/startup/init_lite/services/begetctl:paramshell",
"//base/startup/init_lite/services/plugin:plugin",
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
"//base/startup/init_lite/interfaces/kits:deviceinfo_ndk",
"//base/startup/init_lite/interfaces/kits/syscap:deviceinfo_ndk",
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/interfaces/innerkits/file:libfile",
"//base/startup/init_lite/interfaces/innerkits/socket:libsocket",
......@@ -64,7 +64,12 @@
"init_reboot.h",
"service_control.h",
"beget_ext.h",
"systemcapability.h"
"systemcapability.h",
"syspara/parameter.h",
"syspara/parameters.h",
"syspara/param_wrapper.h",
"syspara/sysparam_errno.h",
"syspara/sysversion.h"
]
},
"name": "//base/startup/init_lite/interfaces/innerkits:libbegetutil"
......@@ -73,7 +78,9 @@
"header": {
"header_base": "//base/startup/init_lite/interfaces/innerkits/include/",
"header_files": [
"service_watcher.h"
"service_watcher.h",
"syspara/parameter.h",
"syspara/sysparam_errno.h"
]
},
"name": "//base/startup/init_lite/interfaces/innerkits:libbeget_proxy"
......
......@@ -10,6 +10,7 @@
# 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_lite/begetd.gni")
import("//build/ohos.gni")
import("//build/ohos/sa_profile/sa_profile.gni")
......@@ -25,19 +26,27 @@ ohos_prebuilt_etc("device_info.cfg") {
}
ohos_shared_library("deviceinfoservice") {
sources = [ "device_info_stub.cpp" ]
sources = [
"//base/startup/init_lite/interfaces/innerkits/syspara/param_comm.c",
"device_info_stub.cpp",
]
defines = [ "DINFO_LABEL=\"DeviceInfoService\"" ]
include_dirs = [
".",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/syspara_lite/hals/parameter/include",
"//base/startup/init_lite/interfaces/innerkits/include/syspara",
"//base/startup/init_lite/interfaces/innerkits/syspara",
]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/syspara_lite/hals/parameter:sysparam_hal",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/openssl:libcrypto_shared",
]
external_deps = [
......@@ -53,9 +62,11 @@ ohos_shared_library("deviceinfoservice") {
}
group("device_info_group") {
deps = [
":device_info.cfg",
":device_info_profile",
":deviceinfoservice",
]
if (param_feature_deviceinfo) {
deps = [
":device_info.cfg",
":device_info_profile",
":deviceinfoservice",
]
}
}
/*
* Copyright (c) 2021 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 "beget_ext.h"
#ifdef PARAM_FEATURE_DEVICEINFO
#include "device_info_kits.h"
#endif
#include "param_comm.h"
#include "securec.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
int AclGetDevUdid(char *udid, int size)
{
if (udid == nullptr || size < UDID_LEN) {
return -1;
}
#ifdef PARAM_FEATURE_DEVICEINFO
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetUdid(result);
if (ret == 0) {
ret = strcpy_s(udid, size, result.c_str());
}
#else
int ret = GetDevUdid_(udid, size);
#endif
BEGET_LOGI("AclGetDevUdid %s", udid);
return ret;
}
const char *AclGetSerial(void)
{
static char serialNumber[MAX_SERIAL_LEN] = {"1234567890"};
#ifdef PARAM_FEATURE_DEVICEINFO
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetSerialID(result);
if (ret == 0) {
ret = strcpy_s(serialNumber, sizeof(serialNumber), result.c_str());
BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
}
#else
const char *tmpSerial = GetSerial_();
if (tmpSerial != nullptr) {
int ret = strcpy_s(serialNumber, sizeof(serialNumber), tmpSerial);
BEGET_ERROR_CHECK(ret == 0, return nullptr, "Failed to copy");
}
#endif
BEGET_LOGI("AclGetSerial %s", serialNumber);
return serialNumber;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
\ No newline at end of file
......@@ -22,11 +22,6 @@
#include "system_ability_definition.h"
#include "securec.h"
namespace {
static constexpr int UDID_LEN = 65;
static constexpr int MAX_SERIAL_LEN = 65;
} // namespace name
namespace OHOS {
namespace device_info {
DeviceInfoKits::DeviceInfoKits() {}
......@@ -96,48 +91,3 @@ int32_t DeviceInfoKits::GetSerialID(std::string& result)
}
} // namespace device_info
} // namespace OHOS
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
int AclGetDevUdid(char *udid, int size)
{
if (udid == nullptr || size < UDID_LEN) {
return -1;
}
printf("AclGetDevUdid \n");
DINFO_LOGI("AclGetDevUdid");
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetUdid(result);
if (ret == 0) {
ret = strcpy_s(udid, size, result.c_str());
}
printf("GetDevUdid %s \n", udid);
DINFO_LOGI("GetDevUdid %s", udid);
return ret;
}
const char *AclGetSerial(void)
{
DINFO_LOGI("AclGetSerial");
static char serialNumber[MAX_SERIAL_LEN] = {"1234567890"};
std::string result = {};
OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
int ret = instance.GetSerialID(result);
if (ret == 0) {
ret = strcpy_s(serialNumber, sizeof(serialNumber), result.c_str());
DINFO_CHECK(ret == 0, return nullptr, "Failed to copy");
}
DINFO_LOGI("GetSerial %s", serialNumber);
return serialNumber;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
\ No newline at end of file
......@@ -19,16 +19,12 @@
#include "idevice_info.h"
#include "ipc_skeleton.h"
#include "accesstoken_kit.h"
#include "parameter_hal.h"
#include "parcel.h"
#include "string_ex.h"
#include "system_ability_definition.h"
#include "param_comm.h"
using std::u16string;
namespace {
static constexpr int UDID_LEN = 65;
} // namespace name
namespace OHOS {
using namespace Security;
using namespace Security::AccessToken;
......@@ -50,7 +46,7 @@ int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code,
return ERR_FAIL;
}
char localDeviceInfo[UDID_LEN] = {0};
ret = HalGetDevUdid(localDeviceInfo, UDID_LEN);
ret = GetDevUdid_(localDeviceInfo, UDID_LEN);
DINFO_CHECK(ret == 0, break, "Failed to get dev udid");
reply.WriteString16(Str8ToStr16(localDeviceInfo));
break;
......@@ -59,9 +55,10 @@ int32_t DeviceInfoStub::OnRemoteRequest(uint32_t code,
if (!CheckPermission(data, PERMISSION_UDID)) {
return ERR_FAIL;
}
const char *serialNumber = HalGetSerial();
const char *serialNumber = GetSerial_();
DINFO_CHECK(serialNumber != nullptr, break, "Failed to get serialNumber");
reply.WriteString16(Str8ToStr16(serialNumber));
free((void *)serialNumber);
break;
}
default: {
......
......@@ -22,7 +22,7 @@ shared_library("libinitsync_shared") {
cflags = [ "-Wall" ]
include_dirs = [
"//base/startup/init_lite/initsync/include",
"//base/startup/init_lite/interfaces/kits",
"//base/startup/init_lite/interfaces/kits/syscap",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
]
......@@ -37,7 +37,7 @@ static_library("libinitsync_static") {
cflags = [ "-Wall" ]
include_dirs = [
"//base/startup/init_lite/initsync/include",
"//base/startup/init_lite/interfaces/kits",
"//base/startup/init_lite/interfaces/kits/syscap",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
]
......
......@@ -10,37 +10,134 @@
# 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_lite/begetd.gni")
if (!defined(ohos_lite) || ohos_kernel_type != "liteos_m") {
syspara_sources = [
"syscap/init_syscap.c",
"syspara/param_comm.c",
"syspara/parameter.c",
"syspara/sysversion.c",
]
}
config("exported_header_files") {
visibility = [ ":*" ]
include_dirs = [
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/interfaces/innerkits/include/syspara",
"//base/startup/init_lite/interfaces/innerkits/include/token",
]
}
if (defined(ohos_lite)) {
static_library("libbegetutil") {
sources = [ "//base/startup/init_lite/services/log/init_log.c" ]
defines = [
"_GNU_SOURCE",
"OHOS_LITE",
"INIT_LOG_INIT=3",
]
include_dirs = [
"./include",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/interfaces/innerkits/fd_holder",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/utils:libinit_tools",
"//third_party/bounds_checking_function:libsec_static",
]
import("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
shared_library("libbegetutil") {
sources = [ "//base/startup/init_lite/services/log/init_log.c" ]
sources += syspara_sources
public_configs = [ ":exported_header_files" ]
cflags = [ "-fPIC" ]
defines = [
"_GNU_SOURCE",
"INIT_LOG_INIT=3",
"OHOS_LITE",
]
include_dirs = [
"./include",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/interfaces/innerkits/fd_holder",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/interfaces/innerkits/include",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//base/startup/init_lite/services/utils:libinit_tools",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/mbedtls:mbedtls",
]
defines += [
"INCREMENTAL_VERSION=\"${ohos_version}\"",
"BUILD_TYPE=\"${ohos_build_type}\"",
"BUILD_USER=\"${ohos_build_user}\"",
"BUILD_TIME=\"${ohos_build_time}\"",
"BUILD_HOST=\"${ohos_build_host}\"",
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
"USE_MBEDTLS",
]
deps += [ "//base/startup/init_lite/services/param:param_client" ]
if (ohos_kernel_type == "liteos_a") {
defines += [ "__LITEOS_A__" ]
} else if (ohos_kernel_type == "linux") {
defines += [ "__LINUX__" ]
deps += [ "//base/startup/init_lite/services/loopevent:loopevent" ]
}
}
}
if (ohos_kernel_type == "liteos_m") {
static_library("libbegetutil") {
sources = [ "//base/startup/init_lite/services/log/init_log.c" ]
sources += [ "syscap/init_syscap.c" ]
public_configs = [ ":exported_header_files" ]
defines = [
"_GNU_SOURCE",
"INIT_LOG_INIT=3",
"OHOS_LITE",
"__LITEOS_M__",
]
include_dirs = [
"./include",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/interfaces/innerkits/fd_holder",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/interfaces/innerkits/include",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_static",
"//base/startup/init_lite/services/utils:libinit_tools",
"//third_party/bounds_checking_function:libsec_static",
]
defines += [
"INCREMENTAL_VERSION=\"${ohos_version}\"",
"BUILD_TYPE=\"${ohos_build_type}\"",
"BUILD_USER=\"${ohos_build_user}\"",
"BUILD_TIME=\"${ohos_build_time}\"",
"BUILD_HOST=\"${ohos_build_host}\"",
"BUILD_ROOTHASH=\"${ohos_build_roothash}\"",
]
if (enable_ohos_startup_init_lite_use_thirdparty_mbedtls) {
deps += [ "//third_party/mbedtls:mbedtls" ]
defines += [ "USE_MBEDTLS" ]
}
deps += [ "//base/startup/init_lite/services/param:param_client" ]
}
}
lite_component("parameter") {
features = [ ":libbegetutil" ]
}
} else {
import("//base/startup/init_lite/begetd.gni")
import("//build/ohos.gni")
config("exported_header_files") {
visibility = [ ":*" ]
include_dirs = [ "include/" ]
ndk_lib("parameter_notes") {
if (ohos_kernel_type != "liteos_m") {
lib_extension = ".so"
}
deps = [ ":libbegetutil" ]
head_files =
[ "//base/startup/init_lite/interfaces/innerkits/include/syspara" ]
}
} else {
import("//build/ohos.gni")
fs_manager_sources = [
"fs_manager/fstab.c",
......@@ -56,24 +153,34 @@ if (defined(ohos_lite)) {
"reboot/init_reboot_innerkits.c",
"service_control/service_control.c",
"socket/init_socket.c",
"syscap/init_syscap.c",
]
sources += fs_manager_sources
defines = [ "INIT_AGENT" ]
sources += syspara_sources
sources += [ "syspara/param_wrapper.cpp" ]
defines = [
"INIT_AGENT",
"INIT_FILE",
"_GNU_SOURCE",
"INIT_FILE",
]
include_dirs = [
"./include",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/interfaces/innerkits/fd_holder",
"//base/startup/init_lite/interfaces/innerkits/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits/sandbox:libsandbox",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/openssl:libcrypto_shared",
]
external_deps = [
"hilog_native:libhilog_base",
......@@ -89,9 +196,12 @@ if (defined(ohos_lite)) {
# watcher lib must separate compilation avoid interdependence.
ohos_shared_library("libbeget_proxy") {
defines = [
"INIT_AGENT",
"_GNU_SOURCE",
]
sources = [
"//base/startup/init_lite/device_info/device_info_kits.cpp",
"//base/startup/init_lite/device_info/device_info_proxy.cpp",
"//base/startup/init_lite/device_info/device_info.cpp",
"//base/startup/init_lite/services/log/init_log.c",
"service_watcher/service_watcher.c",
]
......@@ -100,18 +210,58 @@ if (defined(ohos_lite)) {
"./include",
"//base/startup/init_lite/device_info",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/interfaces/innerkits/syspara",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/param/include",
"//third_party/bounds_checking_function/include",
]
defines = [ "INIT_AGENT" ]
deps = [
"//base/startup/init_lite/services/param/watcher:param_watcheragent",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
]
if (param_feature_watcher) {
sources += [
"//base/startup/init_lite/services/param/watcher/agent/watcher.cpp",
"//base/startup/init_lite/services/param/watcher/agent/watcher_manager_kits.cpp",
"//base/startup/init_lite/services/param/watcher/agent/watcher_manager_proxy.cpp",
"//base/startup/init_lite/services/param/watcher/agent/watcher_stub.cpp",
]
include_dirs += [
"//base/startup/init_lite/services/param/watcher/include",
"//base/startup/init_lite/services/log",
]
deps += [
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/openssl:libcrypto_shared",
]
} else {
defines += [ "NO_PARAM_WATCHER" ]
}
if (param_feature_deviceinfo) {
sources += [
"//base/startup/init_lite/device_info/device_info_kits.cpp",
"//base/startup/init_lite/device_info/device_info_proxy.cpp",
]
defines += [ "PARAM_FEATURE_DEVICEINFO" ]
} else {
sources += [
"//base/startup/init_lite/interfaces/innerkits/syspara/param_comm.c",
]
deps += [
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/openssl:libcrypto_shared",
]
}
external_deps = [
"hilog_native:libhilog_base",
"ipc:ipc_core",
......@@ -119,6 +269,7 @@ if (defined(ohos_lite)) {
"samgr_standard:samgr_proxy",
"utils_base:utils",
]
public_configs = [ ":exported_header_files" ]
part_name = "init"
install_images = [ "system" ]
}
......@@ -131,6 +282,7 @@ if (defined(ohos_lite)) {
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/param/include",
]
part_name = "init"
......
......@@ -19,23 +19,26 @@ service_file_include = [
"//base/startup/init_lite/services/include",
"//third_party/bounds_checking_function/include",
]
service_file_deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
ohos_static_library("libfile_static") {
sources = service_file_sources
include_dirs = service_file_include
deps = service_file_deps
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
part_name = "init"
}
ohos_shared_library("libfile") {
sources = service_file_sources
include_dirs = service_file_include
deps = service_file_deps
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
]
part_name = "init"
install_images = [ "system" ]
}
......@@ -15,6 +15,7 @@
#ifndef BEGET_EXT_API_H
#define BEGET_EXT_API_H
#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
......
......@@ -16,7 +16,7 @@
#ifndef SERVICE_WATCH_API_H
#define SERVICE_WATCH_API_H
#include "sys_param.h"
#include "init_param.h"
#include "service_control.h"
#ifdef __cplusplus
......
/*
* Copyright (c) 2021 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 STARTUP_SYSVERSION_API_H
#define STARTUP_SYSVERSION_API_H
#include <string>
namespace OHOS {
namespace system {
int GetStringParameter(const std::string key, std::string &value, const std::string def = "");
int GetIntParameter(const std::string key, int def);
}
}
#endif // STARTUP_SYSVERSION_API_H
/*
* Copyright (c) 2021 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 STARTUP_SYSPARAM_PARAMETER_API_H
#define STARTUP_SYSPARAM_PARAMETER_API_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
#define PARAM_CONST_VALUE_LEN_MAX 4096
#define PARAM_VALUE_LEN_MAX 96
#define PARAM_NAME_LEN_MAX 96
#define OS_FULL_NAME_LEN 128
#define VERSION_ID_MAX_LEN 256
static const char EMPTY_STR[] = { "" };
/**
* @brief Obtains a system parameter matching the specified <b>key</b>.
*
* If no system parameter is found, the <b>def</b> parameter will be returned.\n
*
* @param key Indicates the key for the system parameter to query.
* The value can contain lowercase letters, digits, underscores (_), and dots (.).
* Its length cannot exceed 32 bytes (including the end-of-text character in the string).
* @param def Indicates the default value to return when no query result is found.
* This parameter is specified by the caller.
* @param value Indicates the data buffer that stores the query result.
* This parameter is applied for and released by the caller and can be used as an output parameter.
* @param len Indicates the length of the data in the buffer.
* @return Returns the number of bytes of the system parameter if the operation is successful;
* returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios.
* @since 1
* @version 1
*/
int GetParameter(const char *key, const char *def, char *value, unsigned int len);
/**
* @brief Sets or updates a system parameter.
*
* You can use this function to set a system parameter that matches <b>key</b> as <b>value</b>.\n
*
* @param key Indicates the key for the parameter to set or update.
* The value can contain lowercase letters, digits, underscores (_), and dots (.).
* Its length cannot exceed 32 bytes (including the end-of-text character in the string).
* @param value Indicates the system parameter value.
* Its length cannot exceed 128 bytes (including the end-of-text character in the string).
* @return Returns <b>0</b> if the operation is successful;
* returns <b>-9</b> if a parameter is incorrect; returns <b>-1</b> in other scenarios.
* @since 1
* @version 1
*/
int SetParameter(const char *key, const char *value);
/**
* @brief Wait for a system parameter with specified value.
*
* You can use this function to wait a system parameter that matches <b>key</b> as <b>value</b>.\n
*
* @param key Indicates the key for the parameter to wait.
* The value can contain lowercase letters, digits, underscores (_), and dots (.).
* Its length cannot exceed 96 bytes (including the end-of-text character in the string).
* @param value Indicates the system parameter value.
* Its length cannot exceed 96 bytes (including the end-of-text character in the string).
* value can use "*" to do arbitrary match.
* @param timeout Indicates the timeout value, in seconds.
* <=0 means wait for ever.
* >0 means wait for specified seconds
* @return Returns <b>0</b> if the operation is successful;
* returns <b>-10</b> if timeout; returns <b>-1</b> in other scenarios.
* @since 1.1
* @version 1.1
*/
int WaitParameter(const char *key, const char *value, int timeout);
/**
* @brief Watch for system parameter values.
*
* You can use this function to watch system parameter values.\n
*
* @param keyprefix Indicates the key prefix for the parameter to be watched.
* If keyprefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.".
* @param callback Indicates value change callback.
* If callback is NULL, it means to cancel the watch.
* @return Returns <b>0</b> if the operation is successful;
* returns <b>-1</b> in other scenarios.
* @since 1.1
* @version 1.1
*/
typedef void (*ParameterChgPtr)(const char *key, const char *value, void *context);
int WatchParameter(const char *keyprefix, ParameterChgPtr callback, void *context);
const char *GetSecurityPatchTag(void);
const char *GetOSFullName(void);
const char *GetVersionId(void);
const char *GetBuildRootHash(void);
const char *GetOsReleaseType(void);
int GetSdkApiVersion(void);
const char *GetDeviceType(void);
const char *GetProductModel(void);
const char *GetManufacture(void);
const char *GetBrand(void);
const char *GetMarketName(void);
const char *GetProductSeries(void);
const char *GetSoftwareModel(void);
const char *GetHardwareModel(void);
const char *GetHardwareProfile(void);
const char *GetSerial(void);
const char *GetAbiList(void);
const char *GetDisplayVersion(void);
const char *GetIncrementalVersion(void);
const char *GetBootloaderVersion(void);
const char *GetBuildType(void);
const char *GetBuildUser(void);
const char *GetBuildHost(void);
const char *GetBuildTime(void);
int GetFirstApiVersion(void);
int GetDevUdid(char *udid, int size);
const char *AclGetSerial(void);
int AclGetDevUdid(char *udid, int size);
/**
* @brief Obtains a system parameter matching the specified <b>key</b>.
*
* If no system parameter is found, return -1.\n
*
* @param key Indicates the key for the system parameter to find.
* @return Returns the index for parameter;
* returns <b>handle</b> if a parameter is correct; returns <b>-1</b> in other scenarios.
* @since 1
* @version 1
*/
unsigned int FindParameter(const char *key);
unsigned int GetParameterCommitId(unsigned int handle);
int GetParameterName(unsigned int handle, char *key, unsigned int len);
int GetParameterValue(unsigned int handle, char *value, unsigned int len);
long long GetSystemCommitId(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif // STARTUP_SYSPARAM_PARAMETER_API_H
/*
* Copyright (c) 2021 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 SYSTEM_PARAMETERS_H
#define SYSTEM_PARAMETERS_H
#include <limits>
#include <string>
namespace OHOS {
namespace system {
/*
* Returns the current value of the system parameter `key`.
* If the parameter is empty or doesn't exist, `def` will be returned.
*/
std::string GetParameter(const std::string& key, const std::string& def);
/*
* Returns true if the system parameter `key` has the value "1", "y", "yes", "on", or "true",
* false for "0", "n", "no", "off", or "false", or `def` otherwise.
*/
bool GetBoolParameter(const std::string& key, bool def);
/*
* Returns the signed integer corresponding to the system parameter `key`.
* If the parameter is empty, doesn't exist, doesn't have an integer value, or is outside
* the optional bounds, returns `def`.
*/
template<typename T>
T GetIntParameter(const std::string& key, T def, T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max());
/*
* Returns the unsigned integer corresponding to the system parameter `key`.
* If the parameter is empty, doesn't exist, doesn't have an integer value, or is outside
* the optional bound, returns `def`.
*/
template<typename T>
T GetUintParameter(const std::string& key, T def, T max = std::numeric_limits<T>::max());
/*
* Sets the system parameter `key` to `value`.
* Note that system parameter setting is inherently asynchronous so a return value of `true`
* isn't particularly meaningful, and immediately reading back the value won't necessarily
* tell you whether or not your call succeeded. A `false` return value definitely means failure.
*/
bool SetParameter(const std::string& key, const std::string& value);
/*
* Obtains the device type of your product represented by a string.
*/
std::string GetDeviceType(void);
} // namespace system
} // namespace OHOS
#endif // SYSTEM_PARAMETERS_H
\ No newline at end of file
/*
* Copyright (c) 2021 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 OHOS_STARTUP_SYSPARAM_ERRNO_H
#define OHOS_STARTUP_SYSPARAM_ERRNO_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
/* --------------------------------------------------------------------------------------------*
* Definition of error code. The error codes are applicable to both the application and kernel
* -------------------------------------------------------------------------------------------- */
enum OHOSStartUpSysParamErrorCode {
EC_SUCCESS = 0, /* OK or No error */
EC_FAILURE = -1, /* Execution failed */
EC_INVALID = -9, /* Invalid argument */
EC_SYSTEM_ERR = -10, /* system error */
};
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif // OHOS_STARTUP_SYSPARAM_ERRNO_H
/*
* Copyright (c) 2021 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 BASE_STARTUP_PARAM_REQUEST_H
#define BASE_STARTUP_PARAM_REQUEST_H
#include <stdatomic.h>
#include "param_manager.h"
#include "sys_param.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
typedef struct {
ParamWorkSpace paramSpace;
int clientFd;
pthread_mutex_t mutex;
} ClientWorkSpace;
int WatchParamCheck(const char *keyprefix);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif
/*
* Copyright (c) 2021 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 STARTUP_SYSVERSION_API_H
#define STARTUP_SYSVERSION_API_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
int GetMajorVersion(void);
int GetSeniorVersion(void);
int GetFeatureVersion(void);
int GetBuildVersion(void);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif // STARTUP_SYSVERSION_API_H
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2020 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
* 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,
......@@ -13,51 +13,63 @@
* limitations under the License.
*/
#ifndef BASE_STARTUP_PARAM_SERVICE_H
#define BASE_STARTUP_PARAM_SERVICE_H
#include <limits.h>
#include <stdio.h>
#ifndef TOKEN_H
#define TOKEN_H
#include "param_manager.h"
#include "sys_param.h"
#include <stdio.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#endif /* __cplusplus */
#define PARAM_WATCH_FLAGS_WAIT 0x01
struct CmdLineEntry {
char *key;
int set;
};
typedef struct cmdLineInfo {
const char* name;
int (*processor)(const char* name, const char* value, int);
} cmdLineInfo;
int WriteParam(const WorkSpace *workSpace, const char *name, const char *value, uint32_t *dataIndex, int onlyAdd);
int InitPersistParamWorkSpace(const ParamWorkSpace *workSpace);
void ClosePersistParamWorkSpace(void);
int LoadPersistParam(ParamWorkSpace *workSpace);
int WritePersistParam(ParamWorkSpace *workSpace, const char *name, const char *value);
#ifdef STARTUP_INIT_TEST
int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *msg);
int AddSecurityLabel(const ParamAuditData *auditData, void *context);
int OnIncomingConnect(LoopHandle loop, TaskHandle server);
PARAM_STATIC void ProcessBeforeEvent(const ParamTaskPtr stream,
uint64_t eventId, const uint8_t *content, uint32_t size);
#endif
/**
* @brief Read token value form device.
*
* @param token The token value, len The token len.
* @returns 0 if it succeeds and get the update area token,
* 1 if it succeeds and get the pre-made token,
* -1 if it fails, -2 if it no pre-made token.
*/
int ReadToken(char *token, unsigned int len);
/**
* @brief Write token value to device.
*
* @param token The token value, len The token len.
* @returns 0 if it succeeds, -1 if it fails.
*/
int WriteToken(const char *token, unsigned int len);
/**
* @brief Get AcKey value form device.
*
* @param acKey The acKey value, len The acKey len.
* @returns 0 if it succeeds, -1 if it fails.
*/
int GetAcKey(char *acKey, unsigned int len);
/**
* @brief Get ProdId value form device.
*
* @param productId The productId value, len The productId len.
* @returns 0 if it succeeds, -1 if it fails.
*/
int GetProdId(char *productId, unsigned int len);
/**
* @brief Get ProdKey value form device.
*
* @param productKey The productKey value, len The productKey len.
* @returns 0 if it succeeds, -1 if it fails.
*/
int GetProdKey(char *productKey, unsigned int len);
int ProcessParamWaitAdd(ParamWorkSpace *worksapce, const ParamTaskPtr worker, const ParamMessage *msg);
int ProcessParamWatchAdd(ParamWorkSpace *worksapce, const ParamTaskPtr worker, const ParamMessage *msg);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif
\ No newline at end of file
#endif /* __cplusplus */
#endif // TOKEN_H
\ No newline at end of file
......@@ -19,9 +19,8 @@
#include <unistd.h>
#include "beget_ext.h"
#include "param.h"
#include "securec.h"
#include "sys_param.h"
#include "init_param.h"
// Refer to parameter limit, value size should not bigger than 96
#define MAX_REBOOT_OPTION_SIZE PARAM_VALUE_LEN_MAX
......
......@@ -58,7 +58,6 @@ ohos_static_library("libsandbox_static") {
]
deps = [
"//base/startup/init_lite/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
"//third_party/cJSON:cjson_static",
]
part_name = "init"
......
......@@ -23,7 +23,7 @@
#include "beget_ext.h"
#include "init_utils.h"
#include "securec.h"
#include "sys_param.h"
#include "init_param.h"
static int StartProcess(const char *name, const char *extArgv[], int extArgc)
{
......
......@@ -21,8 +21,10 @@
#include "beget_ext.h"
#include "init_utils.h"
#include "parameter.h"
#include "securec.h"
#include "service_control.h"
#include "sysparam_errno.h"
static void ServiceStateChange(const char *key, const char *value, void *context)
{
......@@ -55,3 +57,16 @@ int ServiceWatchForStatus(const char *serviceName, ServiceStatusChangePtr change
}
return 0;
}
int WatchParameter(const char *keyprefix, ParameterChgPtr callback, void *context)
{
if (keyprefix == NULL) {
return EC_INVALID;
}
#ifdef NO_PARAM_WATCHER
printf("ParameterWatcher is disabled.");
return EC_INVALID;
#else
return SystemWatchParameter(keyprefix, callback, context);
#endif
}
\ No newline at end of file
......@@ -19,7 +19,7 @@ service_socket_include = [
"//third_party/bounds_checking_function/include",
]
service_socket_deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/log:init_log",
"//third_party/bounds_checking_function:libsec_static",
]
......
......@@ -22,11 +22,10 @@ ohos_shared_library("syscap") {
include_dirs = [
"../include",
"../../../services/include/param",
"//base/startup/init_lite/services/include/param",
]
deps = [
"../../../services/log:init_log",
"../../../services/param:param_client",
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
"//third_party/bounds_checking_function:libsec_shared",
]
......
......@@ -18,7 +18,7 @@
#include <string.h>
#include <errno.h>
#include "sys_param.h"
#include "init_param.h"
#include "beget_ext.h"
#include "securec.h"
#include "systemcapability.h"
......
/*
* Copyright (c) 2021 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 "param_comm.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "init_param.h"
#include "parameter.h"
#include "sysparam_errno.h"
#ifdef USE_MBEDTLS
#include "mbedtls/sha256.h"
#elif !(defined OHOS_LITE)
#include "openssl/sha.h"
#endif
#include "securec.h"
static const char *g_emptyStr = "";
int HalGetParameter(const char *key, const char *def, char *value, uint32_t len)
{
if ((key == NULL) || (value == NULL)) {
return EC_INVALID;
}
uint32_t size = len;
int ret = SystemGetParameter(key, NULL, &size);
if ((size > len) || (ret != 0)) {
return strcpy_s(value, len, def);
}
size = len;
return (SystemGetParameter(key, value, &size) == 0) ? EC_SUCCESS : EC_FAILURE;
}
const char *GetProperty(const char *key, const char **paramHolder)
{
if (paramHolder == NULL) {
return NULL;
}
if (*paramHolder != NULL) {
return *paramHolder;
}
uint32_t len = 0;
int ret = SystemGetParameter(key, NULL, &len);
if (ret == 0 && len > 0) {
char *res = (char *)malloc(len + 1);
if (res == NULL) {
return g_emptyStr;
}
ret = SystemGetParameter(key, res, &len);
if (ret != 0) {
free(res);
return g_emptyStr;
}
*paramHolder = res;
}
return *paramHolder;
}
int StringToLL(const char *str, long long int *out)
{
const char* s = str;
while (isspace(*s)) {
s++;
}
size_t len = strlen(str);
int positiveHex = (len > 1 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'));
int negativeHex = (len > 2 && s[0] == '-' && s[1] == '0' && (s[2] == 'x' || s[2] == 'X')); // 2: shorttest
int base = (positiveHex || negativeHex) ? HEX : DECIMAL;
char* end = NULL;
errno = 0;
*out = strtoll(s, &end, base);
if (errno != 0) {
return -1;
}
if (s == end || *end != '\0') {
return -1;
}
return 0;
}
int StringToULL(const char *str, unsigned long long int *out)
{
const char* s = str;
while (isspace(*s)) {
s++;
}
if (s[0] == '-') {
return -1;
}
int base = (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) ? HEX : DECIMAL;
char* end = NULL;
errno = 0;
*out = strtoull(s, &end, base);
if (errno != 0) {
return -1;
}
if (end == s) {
return -1;
}
if (*end != '\0') {
return -1;
}
return 0;
}
const char *GetProductModel_(void)
{
static const char *productModel = NULL;
return GetProperty("const.product.model", &productModel);
}
const char *GetManufacture_(void)
{
static const char *productManufacture = NULL;
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_ret(&context, 0);
mbedtls_sha256_update_ret(&context, (const unsigned char)input, strlen(input));
mbedtls_sha256_finish_ret(&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;
}
#elif !(defined OHOS_LITE)
static int GetSha256Value(const char *input, char *udid, int udidSize)
{
char buf[DEV_BUF_LENGTH] = { 0 };
unsigned char hash[SHA256_DIGEST_LENGTH] = { 0 };
SHA256_CTX sha256;
if ((SHA256_Init(&sha256) == 0) || (SHA256_Update(&sha256, input, strlen(input)) == 0) ||
(SHA256_Final(hash, &sha256) == 0)) {
return -1;
}
for (size_t i = 0; i < SHA256_DIGEST_LENGTH; i++) {
unsigned char value = hash[i];
(void)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 -1;
}
}
return 0;
}
#else
static int GetSha256Value(const char *input, char *udid, int udidSize)
{
return EC_FAILURE;
}
#endif
const char *GetSerial_(void)
{
const char *serialNumberss = NULL;
GetProperty("ohos.boot.sn", &serialNumberss);
return serialNumberss;
}
int GetDevUdid_(char *udid, int size)
{
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 <= 0 || tmpSize > DEV_BUF_MAX_LENGTH) {
free((void *)sn);
return -1;
}
char *tmp = (char *)malloc(tmpSize);
if (tmp == NULL) {
free((void *)sn);
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);
free((void *)sn);
return -1;
}
int ret = GetSha256Value(tmp, udid, size);
free(tmp);
free((void *)sn);
return ret;
}
\ No newline at end of file
......@@ -13,50 +13,37 @@
* limitations under the License.
*/
#ifndef BASE_STARTUP_PARAM_H
#define BASE_STARTUP_PARAM_H
#include <stdint.h>
#include <stdio.h>
#ifndef INIT_PARAM_COMM_H
#define INIT_PARAM_COMM_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#endif /* __cplusplus */
#define UDID_LEN 65
#define MAX_SERIAL_LEN 65
#define HASH_LENGTH 32
#define DEV_BUF_LENGTH 3
#define DEV_BUF_MAX_LENGTH 1024
#define DECIMAL 10
#define HEX 16
#define PARAM_CONST_VALUE_LEN_MAX 4096
#define PARAM_VALUE_LEN_MAX 96
#define PARAM_NAME_LEN_MAX 96
typedef uint32_t ParamHandle;
const char *GetProperty(const char *key, const char **paramHolder);
typedef enum {
PARAM_CODE_ERROR = -1,
PARAM_CODE_SUCCESS = 0,
PARAM_CODE_INVALID_PARAM = 100,
PARAM_CODE_INVALID_NAME,
PARAM_CODE_INVALID_VALUE,
PARAM_CODE_REACHED_MAX,
PARAM_CODE_NOT_SUPPORT,
PARAM_CODE_TIMEOUT,
PARAM_CODE_NOT_FOUND,
PARAM_CODE_READ_ONLY,
PARAM_CODE_FAIL_CONNECT,
PARAM_CODE_NODE_EXIST,
PARAM_CODE_MAX
} PARAM_CODE;
int StringToULL(const char *str, unsigned long long int *out);
int StringToLL(const char *str, long long int *out);
int HalGetParameter(const char *key, const char *def, char *value, unsigned int len);
typedef enum {
EVENT_TRIGGER_PARAM,
EVENT_TRIGGER_BOOT,
EVENT_TRIGGER_PARAM_WAIT,
EVENT_TRIGGER_PARAM_WATCH
} EventType;
const char *GetProductModel_(void);
const char *GetManufacture_(void);
const char *GetSerial_(void);
int GetDevUdid_(char *udid, int size);
#define LOAD_PARAM_NORMAL 0x00
#define LOAD_PARAM_ONLY_ADD 0x01
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif
\ No newline at end of file
#endif /* __cplusplus */
#endif // STARTUP_PARAM_COMM_H
/*
* Copyright (c) 2021 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 "param_wrapper.h"
#include <unordered_map>
#include <vector>
#include <climits>
#include "param_comm.h"
#include "init_param.h"
#include "sysparam_errno.h"
#include "securec.h"
#include "parameter.h"
#include "parameters.h"
namespace OHOS {
namespace system {
bool SetParameter(const std::string& key, const std::string& value)
{
int ret = SystemSetParameter(key.c_str(), value.c_str());
return (ret == 0) ? EC_SUCCESS : EC_FAILURE;
}
template<typename T>
bool StringToInt(const std::string& str, T min, T max, T& out)
{
long long int result = 0;
if (StringToLL(str.c_str(), &result) != 0) {
return false;
}
if (result < min || max < result) {
return false;
}
out = static_cast<T>(result);
return true;
}
template<typename T>
bool StringToUint(const std::string& str, T max, T& out)
{
unsigned long long int result = 0;
if (StringToULL(str.c_str(), &result) != 0) {
return false;
}
if (max < result) {
return false;
}
out = static_cast<T>(result);
return true;
}
std::string GetParameter(const std::string& key, const std::string& def)
{
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret != 0) {
return std::string(def);
}
std::vector<char> value(size + 1);
ret = SystemReadParam(key.c_str(), value.data(), &size);
if (ret == 0) {
return std::string(value.data());
}
return std::string(def);
}
bool GetBoolParameter(const std::string& key, bool def)
{
static const std::string trueMap[] = { "1", "y", "yes", "on", "true" };
static const std::string falseMap[] = { "0", "off", "n", "no", "false" };
std::string value = GetParameter(key, "");
for (size_t i = 0; i < sizeof(trueMap) / sizeof(trueMap[0]); i++) {
if (trueMap[i] == value) {
return true;
}
}
for (size_t i = 0; i < sizeof(falseMap) / sizeof(falseMap[0]); i++) {
if (falseMap[i] == value) {
return false;
}
}
return def;
}
int GetStringParameter(const std::string key, std::string &value, const std::string def)
{
uint32_t size = 0;
int ret = SystemReadParam(key.c_str(), NULL, &size);
if (ret != 0) {
value = def;
return EC_FAILURE;
}
value.resize(size + 1);
ret = SystemReadParam(key.c_str(), const_cast<char *>(value.data()), &size);
if (ret == 0) {
return EC_SUCCESS;
}
value = def;
return EC_FAILURE;
}
template<typename T>
T GetIntParameter(const std::string& key, T def, T min, T max)
{
if (!std::is_signed<T>::value) {
return def;
}
T result;
std::string value = GetParameter(key, "");
if (!value.empty() && StringToInt(value, min, max, result)) {
return result;
}
return def;
}
template int8_t GetIntParameter(const std::string&, int8_t, int8_t, int8_t);
template int16_t GetIntParameter(const std::string&, int16_t, int16_t, int16_t);
template int32_t GetIntParameter(const std::string&, int32_t, int32_t, int32_t);
template int64_t GetIntParameter(const std::string&, int64_t, int64_t, int64_t);
template<typename T>
T GetUintParameter(const std::string& key, T def, T max)
{
if (!std::is_unsigned<T>::value) {
return def;
}
T result;
std::string value = GetParameter(key, "");
if (!value.empty() && StringToUint(value, max, result)) {
return result;
}
return def;
}
template uint8_t GetUintParameter(const std::string&, uint8_t, uint8_t);
template uint16_t GetUintParameter(const std::string&, uint16_t, uint16_t);
template uint32_t GetUintParameter(const std::string&, uint32_t, uint32_t);
template uint64_t GetUintParameter(const std::string&, uint64_t, uint64_t);
std::string GetDeviceType(void)
{
std::unordered_map<std::string, std::string> deviceTypeMap = {
{"watch", "wearable"},
{"fitnessWatch", "liteWearable"},
};
static const char *productType = nullptr;
const char *type = GetProperty("const.build.characteristics", &productType);
if (deviceTypeMap.count(type) != 0) {
return deviceTypeMap[type];
}
return std::string(type);
}
int GetIntParameter(const std::string key, int def)
{
return GetIntParameter(key, def, INT_MIN, INT_MAX);
}
} // namespace system
} // namespace OHOS
\ No newline at end of file
/*
* Copyright (c) 2021 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 "parameter.h"
#include <stdint.h>
#include <stdlib.h>
#include "param_comm.h"
#include "init_param.h"
#include "sysparam_errno.h"
#include "securec.h"
#include "sysversion.h"
int WaitParameter(const char *key, const char *value, int timeout)
{
if ((key == NULL) || (value == NULL)) {
return EC_INVALID;
}
return SystemWaitParameter(key, value, timeout);
}
uint32_t FindParameter(const char *key)
{
if (key == NULL) {
return (uint32_t)(-1);
}
uint32_t handle = 0;
int ret = SystemFindParameter(key, &handle);
if (ret != 0) {
return (uint32_t)(-1);
}
return handle;
}
uint32_t GetParameterCommitId(uint32_t handle)
{
uint32_t commitId = 0;
int ret = SystemGetParameterCommitId(handle, &commitId);
if (ret != 0) {
return (uint32_t)(-1);
}
return commitId;
}
int GetParameterName(uint32_t handle, char *name, uint32_t len)
{
if (name == NULL) {
return EC_INVALID;
}
int ret = SystemGetParameterName(handle, name, len);
return (ret != 0) ? EC_FAILURE : strlen(name);
}
int GetParameterValue(uint32_t handle, char *value, uint32_t len)
{
if (value == NULL) {
return EC_INVALID;
}
uint32_t size = len;
int ret = SystemGetParameterValue(handle, value, &size);
return (ret != 0) ? EC_FAILURE : strlen(value);
}
int GetParameter(const char *key, const char *def, char *value, uint32_t len)
{
if ((key == NULL) || (value == NULL)) {
return EC_INVALID;
}
int ret = HalGetParameter(key, def, value, len);
return (ret != 0) ? EC_INVALID : strlen(value);
}
int GetIntParameter(const char *key, int def)
{
int out = 0;
char value[32] = {0}; // 32 max for int
int ret = GetParameter(key, "0", value, sizeof(value));
if (ret != 0) {
return out;
}
long long int result = 0;
if (StringToLL(value, &result) != 0) {
return def;
}
return (int32_t)result;
}
int SetParameter(const char *key, const char *value)
{
if ((key == NULL) || (value == NULL)) {
return EC_INVALID;
}
int ret = SystemSetParameter(key, value);
return (ret == 0) ? EC_SUCCESS : EC_FAILURE;
}
const char *GetDeviceType(void)
{
static const char *productType = NULL;
return GetProperty("const.build.characteristics", &productType);
}
const char *GetProductModel(void)
{
return GetProductModel_();
}
const char *GetManufacture(void)
{
return GetManufacture_();
}
const char *GetBrand(void)
{
static const char *productBrand = NULL;
return GetProperty("const.product.brand", &productBrand);
}
const char *GetMarketName(void)
{
static const char *marketName = NULL;
return GetProperty("const.product.name", &marketName);
}
const char *GetProductSeries(void)
{
static const char *productSeries = NULL;
return GetProperty("const.build.product", &productSeries);
}
const char *GetSoftwareModel(void)
{
static const char *softwareModel = NULL;
return GetProperty("const.software.model", &softwareModel);
}
const char *GetHardwareModel(void)
{
static const char *hardwareModel = NULL;
return GetProperty("const.product.hardwareversion", &hardwareModel);
}
const char *GetHardwareProfile(void)
{
static const char *hardwareProfile = NULL;
return GetProperty("const.product.hardwareprofile", &hardwareProfile);
}
const char *GetAbiList(void)
{
static const char *productAbiList = NULL;
return GetProperty("const.product.cpu.abilist", &productAbiList);
}
const char *GetBootloaderVersion(void)
{
static const char *productBootloader = NULL;
return GetProperty("const.product.bootloader.version", &productBootloader);
}
int GetFirstApiVersion(void)
{
static const char *firstApiVersion = NULL;
GetProperty("const.product.firstapiversion", &firstApiVersion);
if (firstApiVersion == NULL) {
return 0;
}
return atoi(firstApiVersion);
}
const char *GetDisplayVersion(void)
{
static const char *displayVersion = NULL;
return GetProperty("const.product.software.version", &displayVersion);
}
const char *GetIncrementalVersion(void)
{
static const char *incrementalVersion = NULL;
return GetProperty("const.product.incremental.version", &incrementalVersion);
}
const char *HalGetOsReleaseType(void)
{
static const char *osReleaseType = NULL;
return GetProperty("const.ohos.releasetype", &osReleaseType);
}
const char *HalGetSdkApiVersion(void)
{
static const char *sdkApiVersion = NULL;
return GetProperty("const.ohos.apiversion", &sdkApiVersion);
}
const char *GetBuildType(void)
{
static const char *buildType = NULL;
return GetProperty("const.product.build.type", &buildType);
}
const char *GetBuildUser(void)
{
static const char *buildUser = NULL;
return GetProperty("const.product.build.user", &buildUser);
}
const char *GetBuildHost(void)
{
static const char *buildHost = NULL;
return GetProperty("const.product.build.host", &buildHost);
}
const char *GetBuildTime(void)
{
static const char *buildTime = NULL;
return GetProperty("const.product.build.date", &buildTime);
}
const char *GetSerial(void)
{
static const char *ohos_serial = NULL;
return GetProperty("ohos.boot.sn", &ohos_serial);
}
int GetDevUdid(char *udid, int size)
{
return GetDevUdid_(udid, size);
}
static const char *GetOSName(void)
{
static const char *osName = NULL;
return GetProperty("const.ohos.name", &osName);
}
static const char *BuildOSFullName(void)
{
const char release[] = "Release";
char value[OS_FULL_NAME_LEN];
const char *releaseType = GetOsReleaseType();
int length;
if ((releaseType == NULL) || (strncmp(releaseType, release, sizeof(release) - 1) == 0)) {
length = sprintf_s(value, OS_FULL_NAME_LEN, "%s-%d.%d.%d.%d",
GetOSName(), GetMajorVersion(), GetSeniorVersion(), GetFeatureVersion(), GetBuildVersion());
} else {
length = sprintf_s(value, OS_FULL_NAME_LEN, "%s-%d.%d.%d.%d(%s)",
GetOSName(), GetMajorVersion(), GetSeniorVersion(), GetFeatureVersion(), GetBuildVersion(), releaseType);
}
if (length < 0) {
return EMPTY_STR;
}
const char *osFullName = strdup(value);
return osFullName;
}
const char *GetOSFullName(void)
{
static const char *osFullName = NULL;
if (osFullName != NULL) {
return osFullName;
}
osFullName = BuildOSFullName();
if (osFullName == NULL) {
return EMPTY_STR;
}
return osFullName;
}
static int GetSdkApiLevel(void)
{
static const char *sdkApiLevel = NULL;
GetProperty("const.ohos.sdkapilevel", &sdkApiLevel);
if (sdkApiLevel == NULL) {
return 0;
}
return atoi(sdkApiLevel);
}
static const char *BuildVersionId(void)
{
char value[VERSION_ID_MAX_LEN];
int len = sprintf_s(value, VERSION_ID_MAX_LEN, "%s/%s/%s/%s/%s/%s/%s/%d/%s/%s",
GetDeviceType(), GetManufacture(), GetBrand(), GetProductSeries(),
GetOSFullName(), GetProductModel(), GetSoftwareModel(),
GetSdkApiLevel(), GetIncrementalVersion(), GetBuildType());
if (len <= 0) {
return EMPTY_STR;
}
const char *versionId = strdup(value);
return versionId;
}
const char *GetVersionId(void)
{
static const char *ohosVersionId = NULL;
if (ohosVersionId != NULL) {
return ohosVersionId;
}
ohosVersionId = BuildVersionId();
if (ohosVersionId == NULL) {
return EMPTY_STR;
}
return ohosVersionId;
}
const char *GetOsReleaseType(void)
{
static const char *osReleaseType = NULL;
return GetProperty("const.ohos.releasetype", &osReleaseType);
}
int GetSdkApiVersion(void)
{
static const char *sdkApiVersion = NULL;
GetProperty("const.ohos.apiversion", &sdkApiVersion);
if (sdkApiVersion == NULL) {
return 0;
}
return atoi(sdkApiVersion);
}
const char *GetSecurityPatchTag(void)
{
static const char *securityPatchTag = NULL;
return GetProperty("const.ohos.version.security_patch", &securityPatchTag);
}
const char *GetBuildRootHash(void)
{
static const char *buildRootHash = NULL;
return GetProperty("const.ohos.buildroothash", &buildRootHash);
}
\ No newline at end of file
/*
* Copyright (c) 2021 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 "sysversion.h"
/* *
* Major(M) version number.
*/
static int g_majorVersion = 2;
/* *
* Senior(S) version number.
*/
static int g_seniorVersion = 2;
/* *
* Feature(F) version number.
*/
static int g_featureVersion = 0;
/* *
* Build(B) version number.
*/
static int g_buildVersion = 0;
/* *
* Obtains the major (M) version number, which increases with any updates to the overall architecture.
* <p>The M version number monotonically increases from 1 to 99.
*
* @return Returns the M version number.
* @since 4
*/
int GetMajorVersion(void)
{
return g_majorVersion;
}
/* *
* Obtains the senior (S) version number, which increases with any updates to the partial
* architecture or major features.
* <p>The S version number monotonically increases from 0 to 99.
*
* @return Returns the S version number.
* @since 4
*/
int GetSeniorVersion(void)
{
return g_seniorVersion;
}
/* *
* Obtains the feature (F) version number, which increases with any planned new features.
* <p>The F version number monotonically increases from 0 or 1 to 99.
*
* @return Returns the F version number.
* @since 3
*/
int GetFeatureVersion(void)
{
return g_featureVersion;
}
/* *
* Obtains the build (B) version number, which increases with each new development build.
* <p>The B version number monotonically increases from 0 or 1 to 999.
*
* @return Returns the B version number.
* @since 3
*/
int GetBuildVersion(void)
{
return g_buildVersion;
}
\ No newline at end of file
#
# Copyright (c) 2020 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("//build/lite/config/component/lite_component.gni")
import("//build/lite/ndk/ndk.gni")
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
shared_library("token_shared") {
cflags = [ "-Wall" ]
include_dirs = [
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/interfaces/innerkits/include/token",
"//utils/native/lite/include",
"//base/startup/init_lite/interfaces/innerkits/token",
]
sources = [ "src/token_impl_posix/token.c" ]
public_deps = [
"$ohos_product_adapter_dir/utils/token:haltoken_shared",
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
]
}
}
if (ohos_kernel_type == "liteos_m") {
static_library("token_static") {
sources = [ "src/token_impl_hal/token.c" ]
include_dirs = [
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/interfaces/innerkits/include/token",
"//utils/native/lite/include",
"//base/startup/init_lite/interfaces/innerkits/token",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
]
deps = [ "$ohos_product_adapter_dir/utils/token:hal_token_static" ]
}
}
lite_component("token") {
features = []
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
features += [ ":token_shared" ]
}
if (ohos_kernel_type == "liteos_m") {
features += [ ":token_static" ]
}
}
ndk_lib("token_notes1") {
if (ohos_kernel_type != "liteos_m") {
lib_extension = ".so"
}
deps = []
if (ohos_kernel_type != "liteos_m") {
deps +=
[ "//base/startup/init_lite/interfaces/innerkits/token:token_shared" ]
}
head_files = [ "//base/startup/init_lite/interfaces/include/token" ]
}
/*
* Copyright (c) 2020 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 HAL_TOKEN_H
#define HAL_TOKEN_H
#include <stdio.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
#define KIT_FRAMEWORK_UID_MAX 1000
/**
* @brief Read token value from device.
*
* @param token the result token value, if read successfully.
* @param len length of the token.
* @returns 0 if success and get the update area token,
* 1 if success and get the pre-made token,
* -1 if failed,
* -2 if no pre-made token.
*/
int HalReadToken(char *token, unsigned int len);
/**
* @brief Write token value to device.
*
* @param token the token to write.
* @param len length of the token.
* @returns 0 if success, otherwise -1.
*/
int HalWriteToken(const char *token, unsigned int len);
/**
* @brief Get AcKey value from device.
*
* @param acKey the result acKey, if get successfully.
* @param len length of the acKey.
* @returns 0 if success, otherwise -1.
*/
int HalGetAcKey(char *acKey, unsigned int len);
/**
* @brief Get ProdId value from device.
*
* @param productId product IDs to be populated with.
* @param len length of the productId.
* @returns 0 if success, otherwise -1.
*/
int HalGetProdId(char *productId, unsigned int len);
/**
* @brief Get ProdKey value from device.
*
* @param productKey The productKey value
* @param len The productKey len.
* @returns 0 if success, otherwise -1.
*/
int HalGetProdKey(char *productKey, unsigned int len);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif // HAL_TOKEN_H
/*
* Copyright (c) 2020 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 "token.h"
#include "hal_token.h"
#include "log.h"
#include "ohos_errno.h"
int ReadToken(char *token, unsigned int len)
{
if (token == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "token is nullptr\n");
return EC_FAILURE;
}
return HalReadToken(token, len);
}
int WriteToken(const char *token, unsigned int len)
{
if (token == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "token is nullptr\n");
return EC_FAILURE;
}
return HalWriteToken(token, len);
}
int GetAcKey(char *acKey, unsigned int len)
{
if (acKey == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "acKey is nullptr");
return EC_FAILURE;
}
return HalGetAcKey(acKey, len);
}
int GetProdId(char *productId, unsigned int len)
{
if (productId == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "productId is nullptr");
return EC_FAILURE;
}
return HalGetProdId(productId, len);
}
int GetProdKey(char *productKey, unsigned int len)
{
if (productKey == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "productKey is nullptr");
return EC_FAILURE;
}
return HalGetProdKey(productKey, len);
}
\ No newline at end of file
/*
* Copyright (c) 2020 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 "token.h"
#include <pthread.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include "hal_token.h"
#include "log.h"
#include "ohos_errno.h"
static pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
static int UidVerify(void)
{
uid_t uid;
uid = getuid();
if (uid >= KIT_FRAMEWORK_UID_MAX) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "uid verify failed, get uid:%d", uid);
return EC_FAILURE;
}
return EC_SUCCESS;
}
int ReadToken(char *token, unsigned int len)
{
int ret;
if (token == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "token is nullptr");
return EC_FAILURE;
}
ret = UidVerify();
if (ret != EC_SUCCESS) {
return EC_FAILURE;
}
pthread_mutex_lock(&g_mutex);
ret = HalReadToken(token, len);
pthread_mutex_unlock(&g_mutex);
return ret;
}
int WriteToken(const char *token, unsigned int len)
{
int ret;
if (token == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "token is nullptr");
return EC_FAILURE;
}
ret = UidVerify();
if (ret != EC_SUCCESS) {
return EC_FAILURE;
}
pthread_mutex_lock(&g_mutex);
ret = HalWriteToken(token, len);
pthread_mutex_unlock(&g_mutex);
return ret;
}
int GetAcKey(char *acKey, unsigned int len)
{
if (acKey == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "acKey is nullptr");
return EC_FAILURE;
}
int ret = UidVerify();
if (ret != EC_SUCCESS) {
return EC_FAILURE;
}
return HalGetAcKey(acKey, len);
}
int GetProdId(char *productId, unsigned int len)
{
if (productId == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "productId is nullptr");
return EC_FAILURE;
}
return HalGetProdId(productId, len);
}
int GetProdKey(char *productKey, unsigned int len)
{
if (productKey == NULL) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "productKey is nullptr");
return EC_FAILURE;
}
int ret = UidVerify();
if (ret != EC_SUCCESS) {
return EC_FAILURE;
}
return HalGetProdKey(productKey, len);
}
\ No newline at end of file
/*
* Copyright (c) 2021 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.
*/
/**
* A static class pertaining to the product information.
*
* @devices phone, tablet
* @since 6
* @Syscap SystemCapability.Startup.SysInfo
*/
declare namespace deviceInfo {
/**
* Obtains the device type represented by a string,
* which can be {@code phone} (or {@code default} for phones), {@code wearable}, {@code liteWearable},
* {@code tablet}, {@code tv}, {@code car}, or {@code smartVision}.
*
* @since 6
*/
const deviceType: string;
/**
* Obtains the device manufacturer represented by a string.
*
* @since 6
*/
const manufacture: string;
/**
* Obtains the device brand represented by a string.
*
* @since 6
*/
const brand: string;
/**
* Obtains the external product series represented by a string.
*
* @since 6
*/
const marketName: string;
/**
* Obtains the product series represented by a string.
*
* @since 6
*/
const productSeries: string;
/**
* Obtains the product model represented by a string.
*
* @since 6
*/
const productModel: string;
/**
* Obtains the software model represented by a string.
*
* @since 6
*/
const softwareModel: string;
/**
* Obtains the hardware model represented by a string.
*
* @since 6
*/
const hardwareModel: string;
/**
* Obtains the hardware profile represented by a string.
*
* @since 6
*/
const hardwareProfile: string;
/**
* Obtains the device serial number represented by a string.
*
* @since 6
*/
const serial: string;
/**
* Obtains the bootloader version number represented by a string.
*
* @since 6
*/
const bootloaderVersion: string;
/**
* Obtains the application binary interface (Abi) list represented by a string.
*
* @since 6
*/
const abiList: string;
/**
* Obtains the security patch level represented by a string.
*
* @since 6
*/
const securityPatchTag: string;
/**
* Obtains the product version represented by a string.
*
* @since 6
*/
const displayVersion: string;
/**
* Obtains the incremental version represented by a string.
*
* @since 6
*/
const incrementalVersion: string;
/**
* Obtains the OS release type represented by a string.
*
* <p>The OS release category can be {@code Release}, {@code Beta}, or {@code Canary}.
* The specific release type may be {@code Release}, {@code Beta1}, or others alike.
*
* @since 6
*/
const osReleaseType: string;
/**
* Obtains the OS version represented by a string.
*
* @since 6
*/
const osFullName: string;
/**
* Obtains the major (M) version number, which increases with any updates to the overall architecture.
* <p>The M version number monotonically increases from 1 to 99.
*
* @since 6
*/
const majorVersion: number;
/**
* Obtains the senior (S) version number, which increases with any updates to the partial
* architecture or major features.
* <p>The S version number monotonically increases from 0 to 99.
*
* @since 6
*/
const seniorVersion: number;
/**
* Obtains the feature (F) version number, which increases with any planned new features.
* <p>The F version number monotonically increases from 0 or 1 to 99.
*
* @since 6
*/
const featureVersion: number;
/**
* Obtains the build (B) version number, which increases with each new development build.
* <p>The B version number monotonically increases from 0 or 1 to 999.
*
* @since 6
*/
const buildVersion: number;
/**
* Obtains the SDK API version number.
*
* @since 6
*/
const sdkApiVersion: number;
/**
* Obtains the first API version number.
*
* @since 6
*/
const firstApiVersion: number;
/**
* Obtains the version ID by a string.
*
* @since 6
*/
const versionId: string;
/**
* Obtains the build types of the same baseline code.
*
* @since 6
*/
const buildType: string;
/**
* Obtains the different build user of the same baseline code.
*
* @since 6
*/
const buildUser: string;
/**
* Obtains the different build host of the same baseline code.
*
* @since 6
*/
const buildHost: string;
/**
* Obtains the build time.
*
* @since 6
*/
const buildTime: string;
/**
* Obtains the version hash.
*
* @since 6
*/
const buildRootHash: string;
/**
* Obtains the device udid.
*
* @since 7
*/
const udid: string;
}
export default deviceInfo;
/*
* Copyright (c) 2021 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 { AsyncCallback, BusinessError } from './basic';
/**
* The interface of system parameters class.
*
* @devices phone, tablet
* @since 6
* @Syscap SystemCapability.Startup.SysInfo
* @systemapi
*/
declare namespace systemParameter {
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param def Default value.
* @return if the parameter is empty or doesn't exist, empty string will be returned.
* @since 6
*/
function getSync(key: string, def?: string): string;
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param callback Callback function.
* @since 6
*/
function get(key: string, callback: AsyncCallback<string>): void;
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param def Default value.
* @param callback Callback function.
* @since 6
*/
function get(key: string, def: string, callback: AsyncCallback<string>): void;
/**
* Gets the value of the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param def Default value.
* @return Promise, which is used to obtain the result asynchronously.
* @since 6
*/
function get(key: string, def?: string): Promise<string>;
/**
* Sets a value for the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param value System attribute value to set.
* @since 6
*/
function setSync(key: string, value: string): void;
/**
* Sets a value for the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param value System attribute value to set.
* @param callback Callback function.
* @since 6
*/
function set(key: string, value: string, callback: AsyncCallback<void>): void;
/**
* Sets a value for the attribute with the specified key.
*
* @param key Key of the system attribute.
* @param value Default value.
* @return Promise, which is used to obtain the result asynchronously.
* @since 6
*/
function set(key: string, value: string): Promise<void>;
/**
* Wait for a parameter with specified value.
*
* @param key Key of the system parameter.
* @param value System parameter value to be wait.
* @param timeout Indicates the timeout value, in seconds.
* <=0 means wait for ever.
* >0 means wait for specified seconds
* @param callback Callback function.
* @since 7
*/
function wait(key: string, value: string, timeout: number, callback: AsyncCallback<void>): void;
/**
* Sets a value for the parameter with the specified key.
*
* @param key Key of the system parameter.
* @param value System parameter value to be wait.
* @param timeout Indicates the timeout value, in seconds.
* <=0 means wait for ever.
* >0 means wait for specified seconds
* @return Promise, which is used to obtain the result asynchronously.
* @since 7
*/
function wait(key: string, value: string, timeout: number): Promise<void>;
/**
* Wait for a parameter with specified value.
*
* @param keyPrefix Key prefix of the system parameters to be watched.
* @param callback Callback function.
* @since 7
*/
function getWatcher(keyPrefix: string): Watcher;
/**
* Called when the system parameter value changes. You need to implement this method in a child class.
*
* @param key Indicates changed system parameter key name.
* @param value Indicates changed system parameter value.
* @since 7
*/
export interface ParameterChangeCallback {
(key: string, value: string): void;
}
export interface Watcher {
/**
* Subscribe to parameter value changess
*
* @since 7
*/
on(eventType: 'valueChange', callback: ParameterChangeCallback): void;
/**
* Unsubscribe to parameter value changess
*
* @since 7
*/
off(eventType: 'valueChange', callback?: ParameterChangeCallback): void;
}
}
export default systemParameter;
# Copyright (c) 2021 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("//build/ohos.gni")
ohos_shared_library("deviceinfo_init") {
include_dirs = [ "//base/startup/init_lite/interfaces/innerkits/include" ]
sources = [ "src/native_deviceinfo_js.cpp" ]
deps = [
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"napi:ace_napi",
]
relative_install_dir = "module"
subsystem_name = "startup"
part_name = "startup_l2"
}
ohos_shared_library("systemparameter_init") {
include_dirs = [ "src" ]
sources = [
"src/native_parameters_js.cpp",
"src/native_parameters_watch.cpp",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"napi:ace_napi",
]
relative_install_dir = "module"
subsystem_name = "startup"
part_name = "startup_l2"
}
group("syspara_js_init") {
deps = [
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
]
if (support_jsapi) {
deps += [
":deviceinfo_init",
":systemparameter_init",
]
}
}
/*
* Copyright (c) 2021 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 <cstdio>
#include <string>
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "parameter.h"
#include "sysversion.h"
const int UDID_LEN = 65;
static napi_value GetDeviceType(napi_env env, napi_callback_info info)
{
napi_value deviceType = nullptr;
const char *value = GetDeviceType();
NAPI_CALL(env, napi_create_string_utf8(env, value, strlen(value), &deviceType));
return deviceType;
}
static napi_value GetManufacture(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *manfactureName = GetManufacture();
NAPI_CALL(env, napi_create_string_utf8(env, manfactureName, strlen(manfactureName), &napiValue));
return napiValue;
}
static napi_value GetBrand(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *productBrand = GetBrand();
NAPI_CALL(env, napi_create_string_utf8(env, productBrand, strlen(productBrand), &napiValue));
return napiValue;
}
static napi_value GetMarketName(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *marketName = GetMarketName();
NAPI_CALL(env, napi_create_string_utf8(env, marketName, strlen(marketName), &napiValue));
return napiValue;
}
static napi_value GetProductSeries(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *productSeries = GetProductSeries();
NAPI_CALL(env, napi_create_string_utf8(env, productSeries, strlen(productSeries), &napiValue));
return napiValue;
}
static napi_value GetProductModel(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *productModel = GetProductModel();
NAPI_CALL(env, napi_create_string_utf8(env, productModel, strlen(productModel), &napiValue));
return napiValue;
}
static napi_value GetSoftwareModel(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *softwareModel = GetSoftwareModel();
NAPI_CALL(env, napi_create_string_utf8(env, softwareModel, strlen(softwareModel), &napiValue));
return napiValue;
}
static napi_value GetHardwareModel(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *hardwareModel = GetHardwareModel();
NAPI_CALL(env, napi_create_string_utf8(env, hardwareModel, strlen(hardwareModel), &napiValue));
return napiValue;
}
static napi_value GetHardwareProfile(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *hardwareProfile = GetHardwareProfile();
NAPI_CALL(env, napi_create_string_utf8(env, hardwareProfile, strlen(hardwareProfile), &napiValue));
return napiValue;
}
static napi_value GetSerial(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *serialNumber = AclGetSerial();
NAPI_CALL(env, napi_create_string_utf8(env, serialNumber, strlen(serialNumber), &napiValue));
return napiValue;
}
static napi_value GetBootloaderVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *bootloaderVersion = GetBootloaderVersion();
NAPI_CALL(env, napi_create_string_utf8(env, bootloaderVersion, strlen(bootloaderVersion), &napiValue));
return napiValue;
}
static napi_value GetAbiList(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *abiList = GetAbiList();
NAPI_CALL(env, napi_create_string_utf8(env, abiList, strlen(abiList), &napiValue));
return napiValue;
}
static napi_value GetSecurityPatchTag(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *securityPatchTag = GetSecurityPatchTag();
NAPI_CALL(env, napi_create_string_utf8(env, securityPatchTag, strlen(securityPatchTag), &napiValue));
return napiValue;
}
static napi_value GetDisplayVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *productVersion = GetDisplayVersion();
NAPI_CALL(env, napi_create_string_utf8(env, productVersion, strlen(productVersion), &napiValue));
return napiValue;
}
static napi_value GetIncrementalVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *incrementalVersion = GetIncrementalVersion();
NAPI_CALL(env, napi_create_string_utf8(env, incrementalVersion, strlen(incrementalVersion), &napiValue));
return napiValue;
}
static napi_value GetOsReleaseType(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *osReleaseType = GetOsReleaseType();
NAPI_CALL(env, napi_create_string_utf8(env, osReleaseType, strlen(osReleaseType), &napiValue));
return napiValue;
}
static napi_value GetOSFullName(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *osVersion = GetOSFullName();
NAPI_CALL(env, napi_create_string_utf8(env, osVersion, strlen(osVersion), &napiValue));
return napiValue;
}
static napi_value GetMajorVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
int majorVersion = GetMajorVersion();
NAPI_CALL(env, napi_create_int32(env, majorVersion, &napiValue));
return napiValue;
}
static napi_value GetSeniorVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
int seniorVersion = GetSeniorVersion();
NAPI_CALL(env, napi_create_int32(env, seniorVersion, &napiValue));
return napiValue;
}
static napi_value GetFeatureVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
int featureVersion = GetFeatureVersion();
NAPI_CALL(env, napi_create_int32(env, featureVersion, &napiValue));
return napiValue;
}
static napi_value GetBuildVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
int buildVersion = GetBuildVersion();
NAPI_CALL(env, napi_create_int32(env, buildVersion, &napiValue));
return napiValue;
}
static napi_value GetSdkApiVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
int sdkApiVersion = GetSdkApiVersion();
NAPI_CALL(env, napi_create_int32(env, sdkApiVersion, &napiValue));
return napiValue;
}
static napi_value GetFirstApiVersion(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
int firstApiVersion = GetFirstApiVersion();
NAPI_CALL(env, napi_create_int32(env, firstApiVersion, &napiValue));
return napiValue;
}
static napi_value GetVersionId(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *versionId = GetVersionId();
NAPI_CALL(env, napi_create_string_utf8(env, versionId, strlen(versionId), &napiValue));
return napiValue;
}
static napi_value GetBuildType(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *buildType = GetBuildType();
NAPI_CALL(env, napi_create_string_utf8(env, buildType, strlen(buildType), &napiValue));
return napiValue;
}
static napi_value GetBuildUser(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *buildUser = GetBuildUser();
NAPI_CALL(env, napi_create_string_utf8(env, buildUser, strlen(buildUser), &napiValue));
return napiValue;
}
static napi_value GetBuildHost(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *buildHost = GetBuildHost();
NAPI_CALL(env, napi_create_string_utf8(env, buildHost, strlen(buildHost), &napiValue));
return napiValue;
}
static napi_value GetBuildTime(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *buildTime = GetBuildTime();
NAPI_CALL(env, napi_create_string_utf8(env, buildTime, strlen(buildTime), &napiValue));
return napiValue;
}
static napi_value GetBuildRootHash(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
const char *buildRootHash = GetBuildRootHash();
NAPI_CALL(env, napi_create_string_utf8(env, buildRootHash, strlen(buildRootHash), &napiValue));
return napiValue;
}
static napi_value GetDevUdid(napi_env env, napi_callback_info info)
{
napi_value napiValue = nullptr;
char localDeviceId[UDID_LEN] = {0};
AclGetDevUdid(localDeviceId, UDID_LEN);
NAPI_CALL(env, napi_create_string_utf8(env, localDeviceId, strlen(localDeviceId), &napiValue));
return napiValue;
}
EXTERN_C_START
/*
* Module init
*/
static napi_value Init(napi_env env, napi_value exports)
{
/*
* Attribute definition
*/
napi_property_descriptor desc[] = {
{"deviceType", nullptr, nullptr, GetDeviceType, nullptr, nullptr, napi_default, nullptr},
{"manufacture", nullptr, nullptr, GetManufacture, nullptr, nullptr, napi_default, nullptr},
{"brand", nullptr, nullptr, GetBrand, nullptr, nullptr, napi_default, nullptr},
{"marketName", nullptr, nullptr, GetMarketName, nullptr, nullptr, napi_default, nullptr},
{"productSeries", nullptr, nullptr, GetProductSeries, nullptr, nullptr, napi_default, nullptr},
{"productModel", nullptr, nullptr, GetProductModel, nullptr, nullptr, napi_default, nullptr},
{"softwareModel", nullptr, nullptr, GetSoftwareModel, nullptr, nullptr, napi_default, nullptr},
{"hardwareModel", nullptr, nullptr, GetHardwareModel, nullptr, nullptr, napi_default, nullptr},
{"hardwareProfile", nullptr, nullptr, GetHardwareProfile, nullptr, nullptr, napi_default, nullptr},
{"serial", nullptr, nullptr, GetSerial, nullptr, nullptr, napi_default, nullptr},
{"bootloaderVersion", nullptr, nullptr, GetBootloaderVersion, nullptr, nullptr, napi_default, nullptr},
{"abiList", nullptr, nullptr, GetAbiList, nullptr, nullptr, napi_default, nullptr},
{"securityPatchTag", nullptr, nullptr, GetSecurityPatchTag, nullptr, nullptr, napi_default, nullptr},
{"displayVersion", nullptr, nullptr, GetDisplayVersion, nullptr, nullptr, napi_default, nullptr},
{"incrementalVersion", nullptr, nullptr, GetIncrementalVersion, nullptr, nullptr, napi_default, nullptr},
{"osReleaseType", nullptr, nullptr, GetOsReleaseType, nullptr, nullptr, napi_default, nullptr},
{"osFullName", nullptr, nullptr, GetOSFullName, nullptr, nullptr, napi_default, nullptr},
{"majorVersion", nullptr, nullptr, GetMajorVersion, nullptr, nullptr, napi_default, nullptr},
{"seniorVersion", nullptr, nullptr, GetSeniorVersion, nullptr, nullptr, napi_default, nullptr},
{"featureVersion", nullptr, nullptr, GetFeatureVersion, nullptr, nullptr, napi_default, nullptr},
{"buildVersion", nullptr, nullptr, GetBuildVersion, nullptr, nullptr, napi_default, nullptr},
{"sdkApiVersion", nullptr, nullptr, GetSdkApiVersion, nullptr, nullptr, napi_default, nullptr},
{"firstApiVersion", nullptr, nullptr, GetFirstApiVersion, nullptr, nullptr, napi_default, nullptr},
{"versionId", nullptr, nullptr, GetVersionId, nullptr, nullptr, napi_default, nullptr},
{"buildType", nullptr, nullptr, GetBuildType, nullptr, nullptr, napi_default, nullptr},
{"buildUser", nullptr, nullptr, GetBuildUser, nullptr, nullptr, napi_default, nullptr},
{"buildHost", nullptr, nullptr, GetBuildHost, nullptr, nullptr, napi_default, nullptr},
{"buildTime", nullptr, nullptr, GetBuildTime, nullptr, nullptr, napi_default, nullptr},
{"buildRootHash", nullptr, nullptr, GetBuildRootHash, nullptr, nullptr, napi_default, nullptr},
{"udid", nullptr, nullptr, GetDevUdid, nullptr, nullptr, napi_default, nullptr},
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc));
return exports;
}
EXTERN_C_END
/*
* Module definition
*/
static napi_module _module = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = NULL,
.nm_register_func = Init,
.nm_modname = "deviceInfo",
.nm_priv = ((void *)0),
.reserved = { 0 }
};
/*
* Module registration function
*/
extern "C" __attribute__((constructor)) void RegisterModule(void)
{
napi_module_register(&_module);
}
/*
* Copyright (c) 2021 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 "native_parameters_js.h"
static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, 0, "StartupParametersJs" };
using namespace OHOS::HiviewDFX;
static constexpr int MAX_LENGTH = 128;
static constexpr int ARGC_NUMBER = 2;
static constexpr int ARGC_THREE_NUMBER = 3;
static constexpr int BUF_LENGTH = 256;
using StorageAsyncContext = struct {
napi_env env = nullptr;
napi_async_work work = nullptr;
char key[BUF_LENGTH] = { 0 };
size_t keyLen = 0;
char value[BUF_LENGTH] = { 0 };
size_t valueLen = 0;
napi_deferred deferred = nullptr;
napi_ref callbackRef = nullptr;
int status = -1;
std::string getValue;
};
using StorageAsyncContextPtr = StorageAsyncContext *;
static void SetCallbackWork(napi_env env, StorageAsyncContextPtr asyncContext)
{
napi_value resource = nullptr;
napi_create_string_utf8(env, "JSStartupSet", NAPI_AUTO_LENGTH, &resource);
napi_create_async_work(
env, nullptr, resource,
[](napi_env env, void *data) {
StorageAsyncContext *asyncContext = (StorageAsyncContext *)data;
asyncContext->status = SetParameter(asyncContext->key, asyncContext->value);
HiLog::Debug(LABEL,
"JSApp set::asyncContext-> status = %{public}d, asyncContext->key = %{public}s, asyncContext->value = "
"%{public}s.",
asyncContext->status, asyncContext->key, asyncContext->value);
},
[](napi_env env, napi_status status, void *data) {
StorageAsyncContext *asyncContext = (StorageAsyncContext *)data;
napi_value result[ARGC_NUMBER] = { 0 };
if (asyncContext->status == 0) {
napi_get_undefined(env, &result[0]);
napi_get_undefined(env, &result[1]);
} else {
napi_value value = nullptr;
napi_create_object(env, &result[0]);
napi_create_int32(env, asyncContext->status, &value);
napi_set_named_property(env, result[0], "code", value);
napi_get_undefined(env, &result[1]);
}
if (asyncContext->deferred) {
if (asyncContext->status == 0) {
napi_resolve_deferred(env, asyncContext->deferred, result[1]);
} else {
napi_reject_deferred(env, asyncContext->deferred, result[0]);
}
} else {
napi_value callback = nullptr;
napi_value callResult = nullptr;
napi_get_reference_value(env, asyncContext->callbackRef, &callback);
napi_call_function(env, nullptr, callback, ARGC_NUMBER, result, &callResult);
napi_delete_reference(env, asyncContext->callbackRef);
}
napi_delete_async_work(env, asyncContext->work);
delete asyncContext;
},
(void *)asyncContext, &asyncContext->work);
napi_queue_async_work(env, asyncContext->work);
}
static napi_value Set(napi_env env, napi_callback_info info)
{
size_t argc = ARGC_THREE_NUMBER;
napi_value argv[ARGC_THREE_NUMBER] = { nullptr };
napi_value thisVar = nullptr;
void *data = nullptr;
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
NAPI_ASSERT(env, argc >= ARGC_NUMBER, "requires 2 parameter");
StorageAsyncContextPtr asyncContext = new StorageAsyncContext();
asyncContext->env = env;
for (size_t i = 0; i < argc; i++) {
napi_valuetype valueType = napi_null;
napi_typeof(env, argv[i], &valueType);
if (i == 0 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->key,
BUF_LENGTH - 1, &asyncContext->keyLen);
} else if (i == 1 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->value,
BUF_LENGTH - 1, &asyncContext->valueLen);
} else if (i == ARGC_NUMBER && valueType == napi_function) {
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
} else {
delete asyncContext;
NAPI_ASSERT(env, false, "type mismatch");
}
}
napi_value result = nullptr;
if (asyncContext->callbackRef == nullptr) {
napi_create_promise(env, &asyncContext->deferred, &result);
} else {
napi_get_undefined(env, &result);
}
SetCallbackWork(env, asyncContext);
return result;
}
static napi_value SetSync(napi_env env, napi_callback_info info)
{
size_t argc = ARGC_NUMBER;
napi_value args[ARGC_NUMBER] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
NAPI_ASSERT(env, argc == ARGC_NUMBER, "Wrong number of arguments");
napi_valuetype valuetype0 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
napi_valuetype valuetype1 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
NAPI_ASSERT(env, valuetype0 == napi_string && valuetype1 == napi_string, "Wrong argument type. string expected.");
char keyBuf[BUF_LENGTH] = { 0 };
size_t keySize = 0;
NAPI_CALL(env, napi_get_value_string_utf8(env, args[0], keyBuf, BUF_LENGTH - 1, &keySize));
if (keySize >= MAX_LENGTH) {
return nullptr;
}
char valueBuf[BUF_LENGTH] = { 0 };
size_t valueSize = 0;
NAPI_CALL(env, napi_get_value_string_utf8(env, args[1], valueBuf, BUF_LENGTH - 1, &valueSize));
if (valueSize >= MAX_LENGTH) {
return nullptr;
}
std::string keyStr = keyBuf;
std::string valueStr = valueBuf;
int setResult = SetParameter(keyStr.c_str(), valueStr.c_str());
HiLog::Debug(LABEL, "JSApp SetSync::setResult = %{public}d, input keyBuf = %{public}s.", setResult, keyBuf);
napi_value napiValue = nullptr;
if (setResult != 0) { // set failed
std::stringstream ss;
ss << "set: " << keyStr << " failed, error code: " << setResult;
napi_throw_error((env), nullptr, ss.str().c_str());
} else {
napi_get_undefined(env, &napiValue);
}
return napiValue;
}
static napi_value GetSync(napi_env env, napi_callback_info info)
{
size_t argc = ARGC_NUMBER;
napi_value args[ARGC_NUMBER] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
NAPI_ASSERT(env, argc == 1 || argc == ARGC_NUMBER, "Wrong number of arguments");
napi_valuetype valuetype0 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype0));
NAPI_ASSERT(env, valuetype0 == napi_string, "Wrong argument type. Numbers expected.");
if (argc == ARGC_NUMBER) {
napi_valuetype valuetype1 = napi_null;
NAPI_CALL(env, napi_typeof(env, args[1], &valuetype1));
NAPI_ASSERT(env, valuetype1 == napi_string, "Wrong argument type. string expected.");
}
char keyBuf[BUF_LENGTH] = { 0 };
size_t keySize = 0;
NAPI_CALL(env, napi_get_value_string_utf8(env, args[0], keyBuf, BUF_LENGTH - 1, &keySize));
if (keySize >= MAX_LENGTH) {
return nullptr;
}
std::string keyStr = keyBuf;
std::string valueStr = "";
std::string getValue = "";
if (argc == ARGC_NUMBER) {
char valueBuf[BUF_LENGTH] = { 0 };
size_t valueSize = 0;
NAPI_CALL(env, napi_get_value_string_utf8(env, args[1], valueBuf, BUF_LENGTH - 1, &valueSize));
if (valueSize >= MAX_LENGTH) {
return nullptr;
}
valueStr = valueBuf;
}
int ret = OHOS::system::GetStringParameter(keyStr, getValue, valueStr);
HiLog::Debug(LABEL, "JSApp GetSync::getValue = %{public}s, input keyStr = %{public}s.", getValue.c_str(), keyBuf);
napi_value napiValue = nullptr;
if (ret == 0) {
const char *value = getValue.c_str();
NAPI_CALL(env, napi_create_string_utf8(env, value, strlen(value), &napiValue));
}
return napiValue;
}
static void GetCallbackWork(napi_env env, StorageAsyncContextPtr asyncContext)
{
napi_value resource = nullptr;
napi_create_string_utf8(env, "JSStartupGet", NAPI_AUTO_LENGTH, &resource);
napi_create_async_work(
env, nullptr, resource,
[](napi_env env, void *data) {
StorageAsyncContext *asyncContext = (StorageAsyncContext *)data;
asyncContext->status =
OHOS::system::GetStringParameter(asyncContext->key, asyncContext->getValue, asyncContext->value);
HiLog::Debug(LABEL,
"JSApp get::asyncContext->status = %{public}d, asyncContext->getValue = %{public}s, asyncContext->key "
"= %{public}s, value = %{public}s.",
asyncContext->status, asyncContext->getValue.c_str(), asyncContext->key, asyncContext->value);
},
[](napi_env env, napi_status status, void *data) {
StorageAsyncContext *asyncContext = (StorageAsyncContext *)data;
napi_value result[ARGC_NUMBER] = { 0 };
if (asyncContext->status == 0) {
napi_get_undefined(env, &result[0]);
napi_create_string_utf8(env, asyncContext->getValue.c_str(), strlen(asyncContext->getValue.c_str()),
&result[1]);
} else {
napi_value message = nullptr;
napi_create_object(env, &result[0]);
napi_create_int32(env, asyncContext->status, &message);
napi_set_named_property(env, result[0], "code", message);
napi_get_undefined(env, &result[1]);
}
if (asyncContext->deferred) {
if (asyncContext->status == 0) {
napi_resolve_deferred(env, asyncContext->deferred, result[1]);
} else {
napi_reject_deferred(env, asyncContext->deferred, result[0]);
}
} else {
napi_value callback = nullptr;
napi_value callResult = nullptr;
napi_get_reference_value(env, asyncContext->callbackRef, &callback);
napi_call_function(env, nullptr, callback, ARGC_NUMBER, result, &callResult);
napi_delete_reference(env, asyncContext->callbackRef);
}
napi_delete_async_work(env, asyncContext->work);
delete asyncContext;
},
(void *)asyncContext, &asyncContext->work);
napi_queue_async_work(env, asyncContext->work);
}
static napi_value Get(napi_env env, napi_callback_info info)
{
size_t argc = ARGC_THREE_NUMBER;
napi_value argv[ARGC_THREE_NUMBER] = { nullptr };
napi_value thisVar = nullptr;
void *data = nullptr;
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
NAPI_ASSERT(env, argc >= 1, "requires 1 parameter");
StorageAsyncContextPtr asyncContext = new StorageAsyncContext();
asyncContext->env = env;
for (size_t i = 0; i < argc; i++) {
napi_valuetype valueType = napi_null;
napi_typeof(env, argv[i], &valueType);
if (i == 0 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->key,
BUF_LENGTH - 1, &asyncContext->keyLen);
} else if (i == 1 && valueType == napi_string) {
napi_get_value_string_utf8(env, argv[i], asyncContext->value,
BUF_LENGTH - 1, &asyncContext->valueLen);
} else if (i == 1 && valueType == napi_function) {
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
break;
} else if (i == ARGC_NUMBER && valueType == napi_function) {
napi_create_reference(env, argv[i], 1, &asyncContext->callbackRef);
} else {
delete asyncContext;
NAPI_ASSERT(env, false, "type mismatch");
}
}
napi_value result = nullptr;
if (asyncContext->callbackRef == nullptr) {
napi_create_promise(env, &asyncContext->deferred, &result);
} else {
napi_get_undefined(env, &result);
}
GetCallbackWork(env, asyncContext);
return result;
}
EXTERN_C_START
/*
* Module init
*/
static napi_value Init(napi_env env, napi_value exports)
{
/*
* Attribute definition
*/
napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("set", Set),
DECLARE_NAPI_FUNCTION("setSync", SetSync),
DECLARE_NAPI_FUNCTION("get", Get),
DECLARE_NAPI_FUNCTION("getSync", GetSync),
DECLARE_NAPI_FUNCTION("wait", ParamWait),
DECLARE_NAPI_FUNCTION("getWatcher", GetWatcher)
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc));
return RegisterWatcher(env, exports);
}
EXTERN_C_END
/*
* Module definition
*/
static napi_module _module = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = NULL,
.nm_register_func = Init,
.nm_modname = "systemParameter",
.nm_priv = ((void *)0),
.reserved = { 0 }
};
/*
* Module registration function
*/
extern "C" __attribute__((constructor)) void RegisterModule(void)
{
napi_module_register(&_module);
}
/*
* Copyright (c) 2021 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 NATIVE_PARAMETERS_JS_H
#define NATIVE_PARAMETERS_JS_H
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <map>
#include <mutex>
#include <sstream>
#include <string>
#include <unistd.h>
#include "hilog/log.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "param_wrapper.h"
#include "parameter.h"
#define PARAM_JS_CHECK(retCode, exper, ...) \
if (!(retCode)) { \
HiLog::Error(LABEL, __VA_ARGS__); \
exper; \
}
EXTERN_C_START
napi_value GetWatcher(napi_env env, napi_callback_info info);
napi_value ParamWait(napi_env env, napi_callback_info info);
napi_value RegisterWatcher(napi_env env, napi_value exports);
EXTERN_C_END
#endif // NATIVE_PARAMETERS_JS_H
\ No newline at end of file
此差异已折叠。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2022 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 argparse
import os
import sys
def DecodeCfgLine(data):
data.replace('\n', '').replace('\r', '')
data = data.strip()
if (len(data) == 0 or data[0] == '#'):
return "", ""
strs = data.split('=')
if len(strs) <= 1:
return "", ""
return strs[0].strip(), strs[1].strip()
def GetParamFromCfg(cfgName):
dict = {}
with open(cfgName) as afile:
data = afile.readline()
while data:
name, value = DecodeCfgLine(data)
if len(name) != 0 and len(value) != 0:
dict[name] = value
print("sample file name={%s %s}"%(name, value))
data = afile.readline()
return dict
def DecodeCodeLine(data):
data.replace('\n', '').replace('\r', '')
data = data.strip()
if (not data.startswith("PARAM_MAP")):
return "", ""
dataLen = len(data)
data = data[len("PARAM_MAP") + 1 : dataLen - 1]
data = data.strip()
strs = data.split(',')
if len(strs) <= 1:
return "", ""
return strs[0].strip(), strs[1].strip()
def GetParamFromCCode(codeName):
dict = {}
with open(codeName) as afile:
data = afile.readline()
while data:
name, value = DecodeCodeLine(data)
if len(name) != 0 and len(value) != 0:
dict[name] = value
data = afile.readline()
return dict
def WriteMapToCode(codeName, dict):
try:
f = open(codeName, 'w+')
# write file header
f.write('#ifndef PARAM_LITE_DEF_CFG_' + os.linesep)
f.write('#define PARAM_LITE_DEF_CFG_' + os.linesep)
f.write('#include <stdint.h>' + os.linesep + os.linesep)
f.write('#ifdef __cplusplus' + os.linesep)
f.write('#if __cplusplus' + os.linesep)
f.write('extern "C" {' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif' + os.linesep + os.linesep)
#define struct
f.write('typedef struct Node_ {' + os.linesep)
f.write(' const char *name;' + os.linesep)
f.write(' const char *value;' + os.linesep)
f.write('} Node;' + os.linesep + os.linesep)
f.write('#define PARAM_MAP(name, value) {(const char *)#name, (const char *)#value},')
f.write(os.linesep + os.linesep)
# write data
f.write('static Node g_paramDefCfgNodes[] = {' + os.linesep)
for name, value in dict.items():
str = " PARAM_MAP({0}, {1})".format(name, value)
f.write(str + os.linesep)
f.write('};' + os.linesep + os.linesep)
#end
f.write('#ifdef __cplusplus' + os.linesep)
f.write('#if __cplusplus' + os.linesep)
f.write('}' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif' + os.linesep)
f.write('#endif // PARAM_LITE_DEF_CFG_' + os.linesep)
except IOError:
print("Error: open or write file %s fail"%{codeName})
else:
f.close()
return 0
def AddToCodeDict(codeDict, cfgDict, high = True):
for name, value in cfgDict.items():
# check if name exit
hasKey = name in codeDict #codeDict.has_key(name)
if hasKey and high:
codeDict[name] = value
elif not hasKey:
codeDict[name] = value
return codeDict
def main():
parser = argparse.ArgumentParser(
description='A common change param.para file to h.')
parser.add_argument(
'--source',
help='The source to change.',
required=True)
parser.add_argument(
'--dest_dir',
help='Path that the source should be changed to.',
required=True)
parser.add_argument(
'--priority',
help='If priority is 1, replace the parameter if it exist.',
required=True)
args = parser.parse_args()
out_dir = args.dest_dir
if not os.path.exists(out_dir):
os.makedirs(out_dir, exist_ok=True)
print(out_dir)
source = args.source
assert os.path.exists(source)
srcDict = GetParamFromCfg(source)
dst = out_dir + "param_cfg.h"
if os.path.exists(dst):
dstDict = GetParamFromCCode(dst)
else:
dstDict = {}
dstDict = AddToCodeDict(dstDict, srcDict, True)
WriteMapToCode(dst, dstDict)
return 0
if __name__ == '__main__':
sys.exit(main())
......@@ -25,13 +25,13 @@ init_common_sources = [
if (defined(ohos_lite)) {
# feature: init
executable("init_lite") {
executable("lite_init") {
output_name = "init"
defines = [
"_GNU_SOURCE", #syscall function need this macro definition
"_GNU_SOURCE",
"OHOS_LITE",
"__MUSL__",
]
defines += [ "__MUSL__" ]
sources = [
"init/adapter/init_adapter.c",
"init/lite/init.c",
......@@ -40,49 +40,49 @@ if (defined(ohos_lite)) {
"init/lite/init_reboot.c",
"init/lite/init_service.c",
"init/lite/init_signal_handler.c",
"log/init_log.c",
"utils/init_hashmap.c",
"utils/init_utils.c",
"utils/list.c",
]
sources += init_common_sources
include_dirs = [
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/include/param",
"//base/startup/init_lite/services/init/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/services/loopevent/include",
"//base/startup/init_lite/interfaces/innerkits/include",
"//third_party/cJSON",
"//third_party/bounds_checking_function/include",
"//base/startup/syspara_lite/interfaces/kits",
"//base/hiviewdfx/hilog_lite/interfaces/native/kits",
"//base/startup/init_lite/interfaces/innerkits/fd_holder",
]
cflags = [ "-Wall" ]
ldflags = []
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//base/startup/init_lite/initsync:initsync",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/syspara_lite/frameworks/parameter:parameter",
"//build/lite/config/component/cJSON:cjson_shared",
"//third_party/bounds_checking_function:libsec_shared",
"//base/startup/init_lite/services/param:param_init",
"//base/startup/init_lite/services/utils:libinit_tools",
"//build/lite/config/component/cJSON:cjson_static",
"//third_party/bounds_checking_function:libsec_static",
]
ldflags = []
if (ohos_kernel_type == "liteos_a") {
defines += [ "__LITEOS_A__" ]
include_dirs += [
"//kernel/liteos_a/syscall",
"//base/startup/init_lite/interfaces/kits",
"//kernel/liteos_a/kernel/include",
"//base/startup/init_lite/interfaces/kits/syscap",
"//base/startup/init_lite/initsync/include",
]
deps += [ "//base/startup/init_lite/initsync:initsync" ]
}
if (ohos_kernel_type == "linux") {
defines += [ "NEED_EXEC_RCS_LINUX" ]
defines += [ "_GNU_SOURCE" ]
defines += [
"NEED_EXEC_RCS_LINUX",
"__LINUX__",
]
ldflags += [
"-lm",
"-lpthread",
......@@ -96,7 +96,46 @@ if (defined(ohos_lite)) {
if (ohos_build_type == "debug") {
group("unittest") {
deps = [ "//base/startup/init_lite/test/unittest/common:unittest" ]
deps = [ "//base/startup/init_lite/test/unittest/lite:init_test" ]
}
}
copy("ohos.para") {
sources = [ "//base/startup/init_lite/services/etc/param/ohos.para" ]
outputs = [ "$root_out_dir/system/etc/param/ohos.para" ]
}
copy("ohos.para.dac") {
sources = [ "//base/startup/init_lite/services/etc/param/ohos.para.dac" ]
outputs = [ "$root_out_dir/system/etc/param/ohos.para.dac" ]
}
copy("ohos.const") {
sources =
[ "//base/startup/init_lite/services/etc/param/ohos_const/ohos.para" ]
outputs = [ "$root_out_dir/system/etc/param/ohos_const/ohos.para" ]
}
copy("ohos.passwd") {
sources = [ "//base/startup/init_lite/services/etc_lite/passwd" ]
outputs = [ "$root_out_dir/etc/passwd" ]
}
copy("ohos.group") {
sources = [ "//base/startup/init_lite/services/etc_lite/group" ]
outputs = [ "$root_out_dir/etc/group" ]
}
group("init_lite") {
deps = [
":lite_init",
":ohos.const",
":ohos.para",
":ohos.para.dac",
]
if (ohos_kernel_type == "linux") {
deps += [
":ohos.group",
":ohos.passwd",
]
}
}
} else {
......@@ -148,7 +187,7 @@ if (defined(ohos_lite)) {
"//base/startup/init_lite/interfaces/innerkits/sandbox:libsandbox_static",
"//base/startup/init_lite/services/log:init_log",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param:param_service",
"//base/startup/init_lite/services/param:param_init",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
"//base/startup/init_lite/ueventd:libueventd_ramdisk_static",
......@@ -180,7 +219,7 @@ if (defined(ohos_lite)) {
cflags += [ "-DWITH_SELINUX" ]
}
defines = []
defines = [ "PARAM_SUPPORT_TRIGGER" ]
if (param_test) {
defines += [
"OHOS_SERVICE_DUMP",
......@@ -218,13 +257,12 @@ if (defined(ohos_lite)) {
":init",
":init_etc",
"//base/startup/init_lite/services/param:param_client",
"//base/startup/init_lite/services/param:param_service",
"//base/startup/init_lite/services/param:param_init",
]
if (param_feature_watcher) {
deps += [
"//base/startup/init_lite/services/param/watcher:param_watcher",
"//base/startup/init_lite/services/param/watcher:param_watcher.rc",
"//base/startup/init_lite/services/param/watcher:param_watcheragent",
"//base/startup/init_lite/services/param/watcher/sa_profile:param_watcher_profile",
]
}
......
......@@ -11,134 +11,182 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/startup/init_lite/begetd.gni")
import("//build/ohos.gni")
ohos_executable("begetctl") {
sources = [
"bootchart_cmd.c",
"init_cmd_reboot.c",
"main.c",
"misc_daemon.cpp",
"param_cmd.c",
"sandbox.cpp",
"service_control.c",
"shell/shell_bas.c",
]
defines = [ "INIT_AGENT" ]
if (defined(product_name) && product_name == "rk3568") {
defines += [ "PRODUCT_RK" ]
}
include_dirs = [
".",
"shell",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/services/include/param/",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/services/loopevent/include",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/interfaces/innerkits/sandbox/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
"//base/startup/init_lite/interfaces/innerkits/sandbox:libsandbox_static",
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps = [ "utils_base:utils" ]
if (param_test) {
sources += [ "//base/startup/init_lite/test/plugintest/plugin_param_cmd.c" ]
deps += [
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param/watcher:param_watcheragent",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
if (defined(ohos_lite)) {
executable("begetctl") {
output_name = "begetctl"
sources = [
"main.c",
"param_cmd.c",
"shell/shell_bas.c",
]
defines += [
"OHOS_SERVICE_DUMP",
"INIT_TEST",
defines = [
"_GNU_SOURCE", #syscall function need this macro definition
"__MUSL__",
]
include_dirs = [
".",
"shell",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/services/include/param/",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/services/loopevent/include",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/interfaces/innerkits/sandbox/include",
"//third_party/cJSON",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
"//base/startup/init_lite/services/utils:libinit_tools",
"//build/lite/config/component/cJSON:cjson_static",
"//third_party/bounds_checking_function:libsec_static",
]
external_deps += [ "startup_l2:syspara" ]
}
if (build_selinux) {
include_dirs += [ "//third_party/selinux/libselinux/include/" ]
deps += [ "//third_party/selinux:libselinux" ]
external_deps += [ "selinux:libparaperm_checker" ]
defines += [ "WITH_SELINUX" ]
group("begetctl_cmd") {
if (param_begetctl_liteos_support) {
deps = [ ":begetctl" ]
}
}
} else {
import("//build/ohos.gni")
symlink_target_name = [
"misc_daemon",
"reboot",
"devctl",
"service",
"service_control",
"start_service",
"stop_service",
"service",
"param",
"sandbox",
]
install_images = [ "system" ]
install_enable = true
part_name = "init"
}
ohos_executable("begetctl") {
sources = [
"bootchart_cmd.c",
"init_cmd_reboot.c",
"main.c",
"misc_daemon.cpp",
"param_cmd.c",
"sandbox.cpp",
"service_control.c",
"shell/shell_bas.c",
]
ohos_executable("paramshell") {
sources = [
"param_cmd.c",
"shell/shell_bas.c",
"shell/shell_main.c",
]
defines = [ "INIT_AGENT" ]
include_dirs = [
".",
"shell",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara/include",
"//base/startup/init_lite/services/include/param/",
"//base/startup/init_lite/services/loopevent/include",
"//base/startup/init_lite/services/param/include",
"//third_party/bounds_checking_function/include",
]
deps = [
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
if (param_test) {
sources += [ "//base/startup/init_lite/test/plugintest/plugin_param_cmd.c" ]
deps += [
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/param/watcher:param_watcheragent",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
"//base/startup/syspara_lite/interfaces/innerkits/native/syspara:syspara",
defines = [ "_GNU_SOURCE" ]
if (defined(product_name) && product_name == "rk3568") {
defines += [ "PRODUCT_RK" ]
}
include_dirs = [
".",
"shell",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/services/include/param/",
"//base/startup/init_lite/services/param/include",
"//base/startup/init_lite/services/loopevent/include",
"//third_party/bounds_checking_function/include",
"//base/startup/init_lite/interfaces/innerkits/sandbox/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
"//base/startup/init_lite/interfaces/innerkits/sandbox:libsandbox",
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_shared",
]
defines += [
"OHOS_SERVICE_DUMP",
"INIT_TEST",
external_deps = [ "utils_base:utils" ]
if (param_test) {
sources +=
[ "//base/startup/init_lite/test/plugintest/plugin_param_cmd.c" ]
deps += [
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
]
defines += [
"OHOS_SERVICE_DUMP",
"INIT_TEST",
]
}
if (build_selinux) {
include_dirs += [
"//third_party/selinux/libselinux/include/",
"//base/security/selinux/interfaces/policycoreutils/include/",
]
deps += [ "//third_party/selinux:libselinux" ]
external_deps += [ "selinux:libparaperm_checker" ]
defines += [ "PARAM_SUPPORT_SELINUX" ]
}
symlink_target_name = [
"misc_daemon",
"reboot",
"devctl",
"service",
"service_control",
"start_service",
"stop_service",
"service",
"param",
"sandbox",
]
install_images = [ "system" ]
install_enable = true
part_name = "init"
}
install_images = [ "system" ]
install_enable = true
ohos_executable("paramshell") {
sources = [
"param_cmd.c",
"shell/shell_bas.c",
"shell/shell_main.c",
]
defines = [ "_GNU_SOURCE" ]
part_name = "init"
include_dirs = [
".",
"shell",
"//base/startup/init_lite/services/include",
"//base/startup/init_lite/services/log",
"//base/startup/init_lite/interfaces/innerkits/include",
"//base/startup/init_lite/services/include/param/",
"//base/startup/init_lite/services/loopevent/include",
"//base/startup/init_lite/services/param/include",
"//third_party/bounds_checking_function/include",
]
deps = [
"//base/startup/init_lite/interfaces/innerkits:libbegetutil",
"//base/startup/init_lite/services/log:agent_log",
"//base/startup/init_lite/services/param:param_client",
"//third_party/bounds_checking_function:libsec_static",
]
if (build_selinux) {
deps += [ "//third_party/selinux:libselinux" ]
external_deps = [ "selinux:libparaperm_checker" ]
defines += [ "PARAM_SUPPORT_SELINUX" ]
}
if (param_test) {
sources +=
[ "//base/startup/init_lite/test/plugintest/plugin_param_cmd.c" ]
deps += [
"//base/startup/init_lite/interfaces/innerkits:libbeget_proxy",
"//base/startup/init_lite/services/loopevent:loopevent",
"//base/startup/init_lite/services/utils:libinit_tools",
"//base/startup/init_lite/services/utils:libinit_utils",
]
defines += [
"OHOS_SERVICE_DUMP",
"INIT_TEST",
]
}
install_images = [ "system" ]
install_enable = true
part_name = "init"
}
}
......@@ -17,7 +17,7 @@
#include <string.h>
#include "begetctl.h"
#include "sys_param.h"
#include "init_param.h"
static int bootchartCmdEnable(BShellHandle shell, int argc, char **argv)
{
......
......@@ -19,7 +19,7 @@
#include "begetctl.h"
#include "shell.h"
#include "shell_utils.h"
#include "sys_param.h"
#include "init_param.h"
static BShellHandle g_handle = NULL;
static int32_t ShellOuput(const char *data, int32_t len)
......@@ -69,12 +69,17 @@ int main(int argc, char *argv[])
printf("Failed to copy\n");
}
}
BShellHandle handle = GetShellHandle();
if (handle == NULL) {
printf("Failed to get shell handle \n");
return 0;
}
SetInitLogLevel(0);
BShellParamCmdRegister(g_handle, 0);
BShellParamCmdRegister(handle, 0);
#ifdef INIT_TEST
BShellCmdRegister(g_handle, 0);
BShellCmdRegister(handle, 0);
#endif
BShellEnvDirectExecute(g_handle, number, args);
BShellEnvDirectExecute(handle, number, args);
demoExit();
return 0;
}
......@@ -29,7 +29,7 @@
#include "fs_manager/fs_manager.h"
#include "shell.h"
#include "shell_utils.h"
#include "sys_param.h"
#include "init_param.h"
constexpr int MAX_LOGO_SIZE = 1024 * 2038;
constexpr int PARTITION_INFO_POS = 1144;
......
......@@ -27,12 +27,12 @@
#include "param_security.h"
#include "param_utils.h"
#include "shell_utils.h"
#include "sys_param.h"
#ifdef WITH_SELINUX
#include "init_param.h"
#ifdef PARAM_SUPPORT_SELINUX
#include <policycoreutils.h>
#include <selinux/selinux.h>
#include "selinux_parameter.h"
#endif // WITH_SELINUX
#endif // PARAM_SUPPORT_SELINUX
#define MASK_LENGTH_MAX 4
pid_t g_shellPid = 0;
......@@ -160,30 +160,25 @@ static void ShowParam(BShellHandle shell, const char *name, const char *value)
BSH_LOGE("Failed to get param security for %s", name);
return;
}
BShellEnvOutput(shell, "Parameter infomation:\r\n");
#ifdef PARAM_SUPPORT_SELINUX
BShellEnvOutput(shell, "selinux : %s \r\n", auditData.label);
#endif
char permissionStr[3][MASK_LENGTH_MAX] = {}; // 3 permission
struct passwd *user = getpwuid(auditData.dacData.uid);
struct group *group = getgrgid(auditData.dacData.gid);
if (user == NULL || group == NULL) {
BSH_LOGE("Failed to get group for user for %s", name);
return;
}
BShellEnvOutput(shell, "Parameter infomation:\r\n");
#ifdef WITH_SELINUX
const char *context = NULL;
if (strcmp(name, "#") != 0) {
context = GetParamLabel(name);
}
if (context != NULL) {
BShellEnvOutput(shell, "selinux : %s \r\n", context);
} else {
BShellEnvOutput(shell, "selinux : null \r\n");
if (user != NULL && group != NULL) {
BShellEnvOutput(shell, " dac : %s(%s) %s(%s) (%s) \r\n",
user->pw_name,
GetPermissionString(auditData.dacData.mode, 0, permissionStr[0], MASK_LENGTH_MAX),
group->gr_name,
GetPermissionString(auditData.dacData.mode,DAC_GROUP_START, permissionStr[1], MASK_LENGTH_MAX),
// 2 other
GetPermissionString(auditData.dacData.mode, DAC_OTHER_START, permissionStr[2], MASK_LENGTH_MAX));
}
if (strcmp("#", name) != 0) {
BShellEnvOutput(shell, " name : %s\r\n", name);
}
#endif
BShellEnvOutput(shell, " dac : %s(%s) %s(%s) (%s) \r\n",
user->pw_name, GetPermissionString(auditData.dacData.mode, 0, permissionStr[0], MASK_LENGTH_MAX),
group->gr_name, GetPermissionString(auditData.dacData.mode, DAC_GROUP_START, permissionStr[1], MASK_LENGTH_MAX),
GetPermissionString(auditData.dacData.mode, DAC_OTHER_START, permissionStr[2], MASK_LENGTH_MAX)); // 2 other
BShellEnvOutput(shell, " name : %s\r\n", name);
if (value != NULL) {
BShellEnvOutput(shell, " value: %s\r\n", value);
}
......@@ -406,7 +401,7 @@ static int32_t BShellParamCmdShell(BShellHandle shell, int32_t argc, char *argv[
if (pid == 0) {
setuid(2000); // 2000 shell group
setgid(2000); // 2000 shell group
#ifdef WITH_SELINUX
#ifdef PARAM_SUPPORT_SELINUX
setcon("u:r:normal_hap_domain:s0");
#endif
if (argc >= 2) { // 2 min argc
......
......@@ -19,7 +19,7 @@
#include <string.h>
#include "begetctl.h"
#include "sys_param.h"
#include "init_param.h"
#include "init_utils.h"
#define SERVICE_START_NUMBER 2
......
......@@ -76,25 +76,26 @@ int main(int argc, char *args[])
SetInitLogLevel(0);
BSH_LOGV("BShellEnvStart %d", argc);
do {
if (g_handle == NULL) {
BShellInfo info = {PARAM_SHELL_DEFAULT_PROMPT, ShellInput, ShellOuput};
BShellEnvInit(&g_handle, &info);
BShellHandle handle = GetShellHandle();
if (handle == NULL) {
printf("Failed to get shell handle \n");
return 0;
}
const ParamInfo *param = BShellEnvGetReservedParam(g_handle, PARAM_REVERESD_NAME_CURR_PARAMETER);
const ParamInfo *param = BShellEnvGetReservedParam(handle, PARAM_REVERESD_NAME_CURR_PARAMETER);
BSH_CHECK(param != NULL && param->type == PARAM_STRING, break, "Failed to get revered param");
BShellEnvSetParam(g_handle, param->name, param->desc, param->type, (void *)"");
BShellEnvSetParam(handle, param->name, param->desc, param->type, (void *)"");
if (argc > 1) {
int ret = SetParamShellPrompt(g_handle, args[1]);
int ret = SetParamShellPrompt(handle, args[1]);
if (ret != 0) {
break;
}
}
BShellParamCmdRegister(g_handle, 1);
BShellParamCmdRegister(handle, 1);
#ifdef INIT_TEST
BShellCmdRegister(g_handle, 1);
BShellCmdRegister(handle, 1);
#endif
BShellEnvStart(g_handle);
BShellEnvLoop(g_handle);
BShellEnvStart(handle);
BShellEnvLoop(handle);
} while (0);
demoExit();
tcsetattr(0, TCSAFLUSH, &terminalState);
......
......@@ -28,3 +28,10 @@ persist.sys.usb.config = root:root:0777
# default forbit other user to start service
ohos.servicectrl. = system:servicectrl:0775
#permission for system
persist.window.boot. = root:system:0775
#permission for log
debug.bytrace. = root:system:0775
persist.distributed_hardware.device_manager. = system:system:0775
\ No newline at end of file
此差异已折叠。
root:x:0:0:::/bin/false
bin:x:2:2:::/bin/false
system:x:1000:1000:::/bin/false
shell:x:2000:2000:::/bin/false
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册