diff --git a/BUILD.gn b/BUILD.gn
index d77eb00b46ea7be51e1880304711bb13cd887ed6..473ca595fd73fdbe6e8cbb6c367e28dec42d5adf 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -19,6 +19,7 @@ group("init_fwk_group") {
"device_info:device_info_group",
"interfaces/innerkits:innergroup",
"interfaces/kits:kitsgroup",
+ "interfaces/taihe:taihe_group",
"services:startup_init",
"services/begetctl:begetctl_cmd",
"services/loopevent:loopeventgroup",
diff --git a/OAT.xml b/OAT.xml
index c1aad8ed79533fe7c068bb8ea881afd0de548ee4..0cfc6f85984101a02c77fe7ebbd15e9adbbacd7a 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -39,14 +39,12 @@
-
-
diff --git a/README.md b/README.md
index 4ab9187dca06b5d5521718445bd4716abd19f08e..1230e1e1a7525b3534300e269dedafbc39f02942 100644
--- a/README.md
+++ b/README.md
@@ -20,10 +20,6 @@ base/startup/init/ # init module
├── src # Source files for the init module
└── test # Source files of the test cases for the init module
└── unittest
-vendor
-└──huawei
- └──camera
- └──init_configs # init configuration files (in JSON format, and deployed in /etc/init.cfg after image burning)
```
## Constraints
diff --git a/begetd.gni b/begetd.gni
index 4109325f3520ed115bc4b2e216d39c9ef1edfcb7..1bcc555e8d9daab81c7468ff5492c74aeec1cc20 100644
--- a/begetd.gni
+++ b/begetd.gni
@@ -88,4 +88,7 @@ declare_args() {
# seccomp custom
init_feature_custom_sandbox = false
+
+ # init sasn support
+ init_feature_support_asan = true
}
diff --git a/bundle.json b/bundle.json
index d5c3b8a3e39fc6a369e37cf3ef0cade51d45eb4c..4ea02f8e9b566009ca9cc16208cfee33ea59ab1a 100755
--- a/bundle.json
+++ b/bundle.json
@@ -56,6 +56,7 @@
"napi",
"ipc",
"config_policy",
+ "hdf_core",
"hilog",
"hilog_lite",
"samgr",
@@ -72,10 +73,11 @@
"zlib",
"cJSON",
"mksh",
- "libunwind",
"toybox",
"hicollie",
- "drivers_interface_partitionslot"
+ "drivers_interface_partitionslot",
+ "code_signature",
+ "runtime_core"
],
"third_party": [
"mksh",
@@ -197,6 +199,12 @@
},
{
"name": "//base/startup/init/interfaces/kits/syscap_ts:syscap_ts"
+ },
+ {
+ "name": "//base/startup/init/interfaces/kits/cj:cj_device_info_ffi"
+ },
+ {
+ "name": "//base/startup/init/interfaces/kits/cj:cj_system_parameter_enhance_ffi"
}
],
"test": [
diff --git a/device_info/device_info_kits.cpp b/device_info/device_info_kits.cpp
index e17c8120aa30f9bfce5647e910c129b3f1c05cc9..d613c3597c4058195f0f5b99d40f458ea68a96a4 100644
--- a/device_info/device_info_kits.cpp
+++ b/device_info/device_info_kits.cpp
@@ -29,6 +29,7 @@ namespace device_info {
static const int DEVINFO_SAID = 3902;
static const int DEVICEINFO_LOAD_SA_TIMEOUT_MS = 5000;
+static const int NOT_FOUND_SERVICE_ERROR_NUMBER = 29189;
DeviceInfoKits::DeviceInfoKits() {}
@@ -104,6 +105,22 @@ void DeviceInfoKits::FinishStartSAFailed()
deviceInfoLoadCon_.notify_one();
}
+sptr DeviceInfoKits::RetryGetService(std::unique_lock &lock)
+{
+ DINFO_LOGI("deviceService is dead, retry get service");
+ if (deviceInfoService_ != nullptr) {
+ sptr object = deviceInfoService_->AsObject();
+ if ((deathRecipient_ != nullptr)) {
+ DINFO_CHECK(object != nullptr, return GetService(lock), "object is null");
+ object->RemoveDeathRecipient(deathRecipient_);
+ }
+ if (object != nullptr) {
+ deviceInfoService_ = nullptr;
+ }
+ }
+ return GetService(lock);
+}
+
int32_t DeviceInfoKits::GetUdid(std::string& result)
{
std::unique_lock lock(lock_);
@@ -117,7 +134,12 @@ int32_t DeviceInfoKits::GetUdid(std::string& result)
auto deviceService = GetService(lock);
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get deviceinfo manager");
int ret = deviceService->GetUdid(result);
- DINFO_LOGV("GetSerialID from remote ret = %d", ret);
+ if (ret == NOT_FOUND_SERVICE_ERROR_NUMBER) {
+ auto newDeviceService = RetryGetService(lock);
+ DINFO_CHECK(newDeviceService != nullptr, return -1, "Failed to get deviceinfo manager again");
+ ret = newDeviceService->GetUdid(result);
+ }
+ DINFO_LOGI("GetSerialID from remote ret = %d", ret);
if (ret == 0 || ret == SYSPARAM_PERMISSION_DENIED) {
resultPair = std::make_optional(std::make_pair(ret, result));
}
@@ -137,7 +159,12 @@ int32_t DeviceInfoKits::GetSerialID(std::string& result)
auto deviceService = GetService(lock);
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get deviceinfo manager");
int ret = deviceService->GetSerialID(result);
- DINFO_LOGV("GetSerialID from remote ret = %d", ret);
+ if (ret == NOT_FOUND_SERVICE_ERROR_NUMBER) {
+ auto newDeviceService = RetryGetService(lock);
+ DINFO_CHECK(newDeviceService != nullptr, return -1, "Failed to get deviceinfo manager again");
+ ret = newDeviceService->GetSerialID(result);
+ }
+ DINFO_LOGI("GetSerialID from remote ret = %d", ret);
if (ret == 0 || ret == SYSPARAM_PERMISSION_DENIED) {
resultPair = std::make_optional(std::make_pair(ret, result));
}
@@ -157,7 +184,12 @@ int32_t DeviceInfoKits::GetDiskSN(std::string& result)
auto deviceService = GetService(lock);
DINFO_CHECK(deviceService != nullptr, return -1, "Failed to get deviceinfo manager");
int ret = deviceService->GetDiskSN(result);
- DINFO_LOGV("GetDiskSN from remote ret = %d", ret);
+ if (ret == NOT_FOUND_SERVICE_ERROR_NUMBER) {
+ auto newDeviceService = RetryGetService(lock);
+ DINFO_CHECK(newDeviceService != nullptr, return -1, "Failed to get deviceinfo manager again");
+ ret = newDeviceService->GetDiskSN(result);
+ }
+ DINFO_LOGI("GetDiskSN from remote ret = %d", ret);
if (ret == 0 || ret == SYSPARAM_PERMISSION_DENIED) {
resultPair = std::make_optional(std::make_pair(ret, result));
}
diff --git a/device_info/device_info_kits.h b/device_info/device_info_kits.h
index c44a1f413fa8fdbe83982411b0f6ad28603ea83c..6571d72bfdf2adf3764e85cc86e763b7c8d02323 100644
--- a/device_info/device_info_kits.h
+++ b/device_info/device_info_kits.h
@@ -55,6 +55,7 @@ private:
std::condition_variable deviceInfoLoadCon_;
sptr deathRecipient_ {};
sptr deviceInfoService_ {};
+ sptr RetryGetService(std::unique_lock &lock);
};
} // namespace device_info
} // namespace OHOS
diff --git a/device_info/device_info_service.cpp b/device_info/device_info_service.cpp
index 58f7bfc2986d03d887653a9a181c89144b654e40..7014391801ec7756372ad650764a73d329ce0947 100644
--- a/device_info/device_info_service.cpp
+++ b/device_info/device_info_service.cpp
@@ -104,8 +104,23 @@ int32_t DeviceInfoService::CallbackEnter(uint32_t code)
std::unique_lock lock(g_lock);
(void)clock_gettime(CLOCK_MONOTONIC, &g_lastTime);
}
- if (!CheckPermission("ohos.permission.sec.ACCESS_UDID")) {
- return SYSPARAM_PERMISSION_DENIED;
+ switch (code) {
+ case static_cast(IDeviceInfoIpcCode::COMMAND_GET_UDID):
+ case static_cast(IDeviceInfoIpcCode::COMMAND_GET_SERIAL_I_D): {
+ if (!CheckPermission("ohos.permission.sec.ACCESS_UDID")) {
+ return SYSPARAM_PERMISSION_DENIED;
+ }
+ break;
+ }
+ case static_cast(IDeviceInfoIpcCode::COMMAND_GET_DISK_S_N): {
+ if (!CheckPermission("ohos.permission.ACCESS_DISK_PHY_INFO")) {
+ return SYSPARAM_PERMISSION_DENIED;
+ }
+ break;
+ }
+ default: {
+ return SYSPARAM_PERMISSION_DENIED;
+ }
}
return 0;
}
diff --git a/device_info/etc/3902.json b/device_info/etc/3902.json
index 4eeaf8415761e9d1eb09dbb2f935ec20e7bc6279..4f2e81c33c64de6200478e84470ece5414e49d1a 100644
--- a/device_info/etc/3902.json
+++ b/device_info/etc/3902.json
@@ -6,7 +6,16 @@
"libpath": "libdeviceinfoservice.z.so",
"run-on-create": true,
"distributed": false,
- "dump_level": 1
+ "dump_level": 1,
+ "recycle-strategy": "low-memory",
+ "stop-on-demand": {
+ "param": [
+ {
+ "name": "resourceschedule.memmgr.low.memory.prepare",
+ "value": "true"
+ }
+ ]
+ }
}
]
}
\ No newline at end of file
diff --git a/device_info/etc/deviceinfoservice.cfg b/device_info/etc/deviceinfoservice.cfg
index 6a4ca239c2e9d5c74e8d9f510671ef55b03c2111..613d1efe0acfb2d5d0520ba4a7104822fbf61aab 100755
--- a/device_info/etc/deviceinfoservice.cfg
+++ b/device_info/etc/deviceinfoservice.cfg
@@ -5,8 +5,7 @@
"uid" : "deviceinfo",
"gid" : ["deviceinfo", "shell"],
"ondemand" : true,
- "secon" : "u:r:deviceinfoservice:s0",
- "recycle-strategy": "low-memory"
+ "secon" : "u:r:deviceinfoservice:s0"
}
]
}
\ No newline at end of file
diff --git a/initsync/src/init_sync.c b/initsync/src/init_sync.c
index e58145b6cc970367cc6c35704bf1b3e99065544b..f0f072e12a587c897ddf21e74fa459318d4f4959 100644
--- a/initsync/src/init_sync.c
+++ b/initsync/src/init_sync.c
@@ -27,7 +27,7 @@
static int SendCmd(int cmd, unsigned long arg)
{
- int fd = open(QUICKSTART_NODE, O_RDONLY);
+ int fd = open(QUICKSTART_NODE, O_RDONLY | O_CLOEXEC);
if (fd != -1) {
int ret = ioctl(fd, cmd, arg);
if (ret == -1) {
diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn
index 83610a793d2b00159f2cc2bd815fc9c4715da2d2..68c8fa4696537cd982a08d2b2a44e7dda4ff8162 100755
--- a/interfaces/innerkits/BUILD.gn
+++ b/interfaces/innerkits/BUILD.gn
@@ -172,8 +172,8 @@ if (defined(ohos_lite)) {
idl_gen_interface("deviceinfo_interface") {
sources = [ "IDeviceInfo.idl" ]
- log_domainid = "0xD001718"
- log_tag = "deviceinfo"
+ log_domainid = "0xD002C08"
+ log_tag = "DeviceInfoKits"
part_name = "init"
subsystem_name = "startup"
}
@@ -220,8 +220,8 @@ if (defined(ohos_lite)) {
idl_gen_interface("param_watcher_interface") {
sources = [ "../../services/param/watcher/IWatcherManager.idl" ]
sources_callback = [ "IWatcher.idl" ]
- log_domainid = "0xD001720"
- log_tag = "watcher"
+ log_domainid = "0xD002C03"
+ log_tag = "PARAM_WATCHER"
part_name = "init"
subsystem_name = "startup"
}
@@ -290,7 +290,7 @@ if (defined(ohos_lite)) {
sources += modulemgr_sources
innerapi_tags = [
- "chipsetsdk",
+ "chipsetsdk_sp",
"platformsdk",
"sasdk",
]
@@ -400,7 +400,7 @@ if (defined(ohos_lite)) {
]
public_configs = [ ":exported_header_files" ]
innerapi_tags = [
- "chipsetsdk",
+ "chipsetsdk_sp",
"platformsdk",
]
part_name = "init"
diff --git a/interfaces/innerkits/control_fd/control_fd_client.c b/interfaces/innerkits/control_fd/control_fd_client.c
index c909fb45d7d703113c74c1c3d5f1484d5f14716e..9315ea04e3b644d78e8396777765a2294acac097 100644
--- a/interfaces/innerkits/control_fd/control_fd_client.c
+++ b/interfaces/innerkits/control_fd/control_fd_client.c
@@ -180,7 +180,6 @@ int InitPtyInterface(CmdAgent *agent, uint16_t type, const char *cmd, CallbackSe
BEGET_ERROR_CHECK(chmod(ptsbuffer, S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == 0,
close(pfd); return -1, "Failed to chmod %s, err=%d", ptsbuffer, errno);
agent->ptyFd = pfd;
-
LE_WatchInfo info = {};
info.flags = 0;
info.events = EVENT_READ;
@@ -191,13 +190,12 @@ int InitPtyInterface(CmdAgent *agent, uint16_t type, const char *cmd, CallbackSe
info.processEvent = ProcessPtyWrite;
info.fd = STDIN_FILENO; // read stdin and write ptmx
BEGET_ERROR_CHECK(LE_StartWatcher(LE_GetDefaultLoop(), &agent->input, &info, agent) == LE_SUCCESS,
- close(pfd); return -1, "[control_fd] Failed le_loop start watcher stdin read and write ptmx");
- if (g_sendMsg == NULL) {
- ret = SendCmdMessage(agent, type, cmd, ptsbuffer);
- } else {
- ret = g_sendMsg(agent, type, cmd, ptsbuffer);
- }
- BEGET_ERROR_CHECK(ret == 0, close(pfd); return -1, "[control_fd] Failed send message");
+ LE_RemoveWatcher(LE_GetDefaultLoop(), agent->reader);
+ close(pfd); return -1, "[control_fd] Failed le_loop start watcher stdin read and write ptmx");
+ ret = g_sendMsg == NULL ? SendCmdMessage(agent, type, cmd, ptsbuffer) : g_sendMsg(agent, type, cmd, ptsbuffer);
+ BEGET_ERROR_CHECK(ret == 0, LE_RemoveWatcher(LE_GetDefaultLoop(), agent->reader);
+ LE_RemoveWatcher(LE_GetDefaultLoop(), agent->input);
+ close(pfd); return -1, "[control_fd] Failed send message");
#endif
return 0;
}
diff --git a/interfaces/innerkits/fs_manager/BUILD.gn b/interfaces/innerkits/fs_manager/BUILD.gn
index e0ac82cc709901b2bc7e0101e94ae05698dec923..e0a93d2e707acc35130857bbf6114f90da355ae7 100755
--- a/interfaces/innerkits/fs_manager/BUILD.gn
+++ b/interfaces/innerkits/fs_manager/BUILD.gn
@@ -29,6 +29,8 @@ config("libfsmanager_exported_configs") {
ohos_static_library("libfsmanager_static") {
if (!defined(ohos_lite)) {
sources = [
+ "//base/startup/init/interfaces/innerkits/hookmgr/hookmgr.c",
+ "//base/startup/init/services/init/bootstagehooker.c",
"fstab.c",
"fstab_mount.c",
"switch_root/switch_root.c",
@@ -42,13 +44,20 @@ ohos_static_library("libfsmanager_static") {
"//base/startup/init/services/param/include",
]
defines = []
- external_deps = [ "bounds_checking_function:libsec_static" ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "cJSON:cjson",
+ ]
deps = [ "//base/startup/init/services/utils:libinit_utils" ]
if ((defined(global_parts_info) &&
defined(global_parts_info.startup_hvb)) ||
init_startup_feature_erofs_overlay) {
- sources += [ "libfs_dm/fs_dm.c" ]
+ sources += [
+ "libfs_dm/fs_dm.c",
+ "libfs_dm/fs_dm_linear.c",
+ "libfs_dm/fs_dm_snapshot.c",
+ ]
include_dirs += [
"//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include",
"//base/startup/init/ueventd/include",
@@ -91,6 +100,8 @@ ohos_static_library("libfsmanager_static") {
ohos_static_library("libfsmanager_static_real") {
if (!defined(ohos_lite)) {
sources = [
+ "//base/startup/init/interfaces/innerkits/hookmgr/hookmgr.c",
+ "//base/startup/init/services/init/bootstagehooker.c",
"fstab.c",
"fstab_mount.c",
"switch_root/switch_root.c",
@@ -103,12 +114,17 @@ ohos_static_library("libfsmanager_static_real") {
"//base/startup/init/services/log",
"//base/startup/init/services/param/include",
]
- external_deps = [ "bounds_checking_function:libsec_static" ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "cJSON:cjson_static",
+ ]
deps = [ "//base/startup/init/services/utils:libinit_utils" ]
if (defined(global_parts_info) && defined(global_parts_info.startup_hvb)) {
sources += [
"dm_verity/dm_verity.c",
"libfs_dm/fs_dm.c",
+ "libfs_dm/fs_dm_linear.c",
+ "libfs_dm/fs_dm_snapshot.c",
"libfs_hvb/fs_hvb.c",
"libfs_hvb/hvb_ops.c",
]
diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c
index da52dd2ee6ce858647555e3b65993df6718ddbb2..40b211163301692d11365208cd60b7049f2a2002 100644
--- a/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c
+++ b/interfaces/innerkits/fs_manager/erofs_overlay/erofs_remount_overlay.c
@@ -22,6 +22,17 @@
#include "fs_manager/fs_manager.h"
#include "erofs_remount_overlay.h"
+#define MODEM_DRIVER_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_driver"
+#define MODEM_VENDOR_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_vendor"
+#define MODEM_FW_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_fw"
+#define MODEM_DRIVER_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/driver_exchange"
+#define MODEM_VENDOR_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/vendor_exchange"
+#define MODEM_FW_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/fw_exchange"
+#define REMOUNT_RESULT_PATH STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/"
+#define REMOUNT_RESULT_FLAG STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/remount.result.done"
+#define DPA_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/communication/dpa"
+#define DPA_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/dpa_exchange"
+
int GetRemountResult(void)
{
int fd = open(REMOUNT_RESULT_FLAG, O_RDONLY);
@@ -140,6 +151,10 @@ void OverlayRemountVendorPre(void)
if (!stat(MODEM_FW_MNT_PATH, &statInfo)) {
Modem2Exchange(MODEM_FW_MNT_PATH, MODEM_FW_EXCHANGE_PATH);
}
+
+ if (!stat(DPA_MNT_PATH, &statInfo)) {
+ Modem2Exchange(DPA_MNT_PATH, DPA_EXCHANGE_PATH);
+ }
}
void OverlayRemountVendorPost()
@@ -147,6 +162,7 @@ void OverlayRemountVendorPost()
Exchange2Modem(MODEM_DRIVER_MNT_PATH, MODEM_DRIVER_EXCHANGE_PATH);
Exchange2Modem(MODEM_VENDOR_MNT_PATH, MODEM_VENDOR_EXCHANGE_PATH);
Exchange2Modem(MODEM_FW_MNT_PATH, MODEM_FW_EXCHANGE_PATH);
+ Exchange2Modem(DPA_MNT_PATH, DPA_EXCHANGE_PATH);
}
int MountOverlayOne(const char *mnt)
diff --git a/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h b/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h
index 99f6e3102fe947c38392bdb3e69598b3920ac538..8a34cf7925d00b5313d4d7db14b26c98cada4e14 100644
--- a/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h
+++ b/interfaces/innerkits/fs_manager/erofs_overlay/include/erofs_remount_overlay.h
@@ -24,15 +24,6 @@ extern "C" {
#endif
#endif
-#define MODEM_DRIVER_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_driver"
-#define MODEM_VENDOR_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_vendor"
-#define MODEM_FW_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_fw"
-#define MODEM_DRIVER_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/driver_exchange"
-#define MODEM_VENDOR_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/vendor_exchange"
-#define MODEM_FW_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/fw_exchange"
-#define REMOUNT_RESULT_PATH STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/"
-#define REMOUNT_RESULT_FLAG STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/remount.result.done"
-
#define REMOUNT_SUCC 0
#define REMOUNT_FAIL 1
diff --git a/interfaces/innerkits/fs_manager/fstab_mount.c b/interfaces/innerkits/fs_manager/fstab_mount.c
index 61cdeef875d04aa05ae2dc1578046a66f8ab0861..86aca2475f308a6e484752ad8521d92ad24cedb7 100755
--- a/interfaces/innerkits/fs_manager/fstab_mount.c
+++ b/interfaces/innerkits/fs_manager/fstab_mount.c
@@ -23,7 +23,10 @@
#include
#include
#include "beget_ext.h"
+#include "bootstage.h"
#include "fs_manager/fs_manager.h"
+#include "hookmgr.h"
+#include "list.h"
#include "init_utils.h"
#include "param/init_param.h"
#include "securec.h"
@@ -45,6 +48,8 @@ extern "C" {
#define FS_MANAGER_BUFFER_SIZE 512
#define BLOCK_SIZE_BUFFER (64)
#define RESIZE_BUFFER_SIZE 1024
+#define MAX_GCALLOWNANCE 100
+#define GCALLOWANCE_INCREACE 10
const off_t PARTITION_ACTIVE_SLOT_OFFSET = 1024;
const off_t PARTITION_ACTIVE_SLOT_SIZE = 4;
int g_bootSlots = -1;
@@ -64,6 +69,12 @@ __attribute__((weak)) bool NeedDoAllResize(const unsigned int fsManagerFlags)
return true;
}
+__attribute__((weak)) char *GetExtraFsckOption(void)
+{
+ BEGET_LOGW("get extra fsck option: static");
+ return NULL;
+}
+
static const SUPPORTED_FILE_SYSTEM supportedFileSystems[] = {
{ "ext4", 0 },
{ "f2fs", 1 },
@@ -278,7 +289,7 @@ MountStatus GetMountStatusForMountPoint(const char *mp)
return status;
}
-static int DoMountOneItem(FstabItem *item);
+INIT_STATIC int DoMountOneItem(FstabItem *item);
#define MAX_RESIZE_PARAM_NUM 20
static int DoResizeF2fs(FstabItem *item, const unsigned long long size)
{
@@ -334,16 +345,22 @@ static int DoResizeF2fs(FstabItem *item, const unsigned long long size)
return ExecCommand(argc, argv);
}
+#define MAX_FSCK_PARAM_NUM 5
static int DoFsckF2fs(const char* device)
{
char *file = "/system/bin/fsck.f2fs";
BEGET_ERROR_CHECK(access(file, F_OK) == 0, return -1, "fsck.f2fs is not exists.");
- char *cmd[] = {
- file, "-p1", (char *)device, NULL
- };
- int argc = ARRAY_LENGTH(cmd);
- char **argv = (char **)cmd;
+ char *argv[MAX_FSCK_PARAM_NUM] = {NULL};
+ int argc = 0;
+
+ argv[argc++] = file;
+ argv[argc++] = "-p1";
+ char *extraOpt = GetExtraFsckOption();
+ if (extraOpt) {
+ argv[argc++] = extraOpt;
+ }
+ argv[argc++] = (char *)device;
InitTimerControl(true);
int ret = ExecCommand(argc, argv);
InitTimerControl(false);
@@ -396,7 +413,7 @@ static int Mount(const char *source, const char *target, const char *fsType,
unsigned long flags, const char *data)
{
struct stat st = {};
- int rc = -1;
+ int rc = 0;
bool isTrue = source == NULL || target == NULL || fsType == NULL;
BEGET_ERROR_CHECK(!isTrue, return -1, "Invalid argument for mount.");
@@ -410,12 +427,52 @@ static int Mount(const char *source, const char *target, const char *fsType,
BEGET_ERROR_CHECK(errno == EEXIST, return -1, "Failed to create dir \" %s \", err = %d", target, errno);
}
errno = 0;
- if ((rc = mount(source, target, fsType, flags, data)) != 0) {
+ if (mount(source, target, fsType, flags, data) != 0) {
+ rc = errno;
BEGET_WARNING_CHECK(errno != EBUSY, rc = 0, "Mount %s to %s busy, ignore", source, target);
}
return rc;
}
+INIT_STATIC int MountWithCheckpoint(const char *source, const char *target, const char *fsType,
+ unsigned long flags, const char *data)
+{
+ struct stat st = {};
+ int rc = -1;
+
+ bool isTrue = source == NULL || target == NULL || fsType == NULL;
+ BEGET_ERROR_CHECK(!isTrue, return -1, "Invalid argument for mount.");
+
+ isTrue = stat(target, &st) != 0 && errno != ENOENT;
+ BEGET_ERROR_CHECK(!isTrue, return -1, "Cannot get stat of \" %s \", err = %d", target, errno);
+
+ BEGET_CHECK((st.st_mode & S_IFMT) != S_IFLNK, unlink(target)); // link, delete it.
+
+ if (mkdir(target, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+ BEGET_ERROR_CHECK(errno == EEXIST, return -1, "Failed to create dir \" %s \", err = %d", target, errno);
+ }
+
+ int gcAllowance = 0;
+ do {
+ char realData[FS_MANAGER_BUFFER_SIZE] = {0};
+ int bytes = snprintf_s(realData, FS_MANAGER_BUFFER_SIZE, FS_MANAGER_BUFFER_SIZE - 1, "%s,%s:%d%%",
+ data, "checkpoint=disable", gcAllowance);
+ if (bytes <= 0) {
+ BEGET_LOGE("build realData failed");
+ break;
+ }
+ rc = mount(source, target, fsType, flags, realData);
+ BEGET_LOGI("MountWithCheckpoint %s %d %d", realData, rc, errno);
+
+ if (rc != 0 && errno == EBUSY) {
+ rc = 0;
+ }
+ gcAllowance += GCALLOWANCE_INCREACE;
+ } while (rc != 0 && errno == EAGAIN && gcAllowance <= MAX_GCALLOWNANCE);
+
+ return rc;
+}
+
static int GetSlotInfoFromCmdLine(const char *slotInfoName)
{
char value[MAX_BUFFER_LEN] = {0};
@@ -466,19 +523,83 @@ int GetCurrentSlot(void)
return GetSlotInfoFromBootctrl(PARTITION_ACTIVE_SLOT_OFFSET, PARTITION_ACTIVE_SLOT_SIZE);
}
-static int DoMountOneItem(FstabItem *item)
+INIT_STATIC int GetDataWithoutCheckpoint(char *fsSpecificData, size_t fsSpecificDataSize,
+ char *checkpointData, size_t checkpointDataSize)
+{
+ if (fsSpecificData == NULL || strstr(fsSpecificData, "checkpoint=disable") == NULL) {
+ BEGET_LOGI("Not checkpoint Mount info");
+ return -1;
+ }
+ if (checkpointData == NULL) {
+ BEGET_LOGE("invalid outData");
+ return -1;
+ }
+ int flagCount = 0;
+ const int maxCount = 15;
+ char *splitStr = strdup(fsSpecificData);
+ if (splitStr == NULL) {
+ BEGET_LOGI("dump fsData failed");
+ return -1;
+ }
+ char **flagsVector = SplitStringExt(splitStr, ",", &flagCount, maxCount);
+ if (flagsVector == NULL || flagCount <= 0) {
+ free(splitStr);
+ BEGET_LOGE("split fsData failed");
+ return -1;
+ }
+ const char *disableCheckpoint = "checkpoint=disable";
+ int rc = 0;
+ for (int i = 0; i < flagCount; i++) {
+ char *p = flagsVector[i];
+ if (strncmp(p, disableCheckpoint, strlen(disableCheckpoint)) == 0) {
+ continue;
+ }
+ if (strcmp(checkpointData, "") != 0 &&
+ strncat_s(checkpointData, checkpointDataSize - 1, ",", 1) != EOK) {
+ BEGET_LOGW("failed to append comma.");
+ rc = -1;
+ break;
+ }
+ if (strncat_s(checkpointData, checkpointDataSize - 1, p, strlen(p)) != EOK) {
+ BEGET_LOGW("Failed to append mountflags \" %s \", ignore it.", p);
+ rc = -1;
+ break;
+ }
+ }
+ FreeStringVector(flagsVector, flagCount);
+ free(splitStr);
+ BEGET_LOGI("removeCheckpoint with fsData %s", fsSpecificData);
+ BEGET_LOGI("removeCheckpoint with resultData %s", checkpointData);
+ return rc;
+}
+
+INIT_STATIC int DoMountOneItem(FstabItem *item)
{
BEGET_LOGI("Mount device %s to %s", item->deviceName, item->mountPoint);
unsigned long mountFlags;
char fsSpecificData[FS_MANAGER_BUFFER_SIZE] = {0};
+ char checkpointData[FS_MANAGER_BUFFER_SIZE] = {0};
+ bool isCheckpoint = false;
mountFlags = GetMountFlags(item->mountOptions, fsSpecificData, sizeof(fsSpecificData),
item->mountPoint);
+
+ // 是否包含checkpoint + 文件系统类型
+ if (strcmp(item->fsType, "hmfs") == 0 && strstr(fsSpecificData, "checkpoint=disable") != NULL &&
+ GetDataWithoutCheckpoint(fsSpecificData, FS_MANAGER_BUFFER_SIZE,
+ checkpointData, FS_MANAGER_BUFFER_SIZE) == 0) {
+ isCheckpoint = true;
+ }
int retryCount = 3;
int rc = 0;
while (retryCount-- > 0) {
- rc = Mount(item->deviceName, item->mountPoint, item->fsType, mountFlags, fsSpecificData);
+ if (isCheckpoint) {
+ rc = MountWithCheckpoint(item->deviceName, item->mountPoint, item->fsType, mountFlags, checkpointData);
+ } else {
+ rc = Mount(item->deviceName, item->mountPoint, item->fsType, mountFlags, fsSpecificData);
+ }
+
if (rc == 0) {
return rc;
}
@@ -532,6 +653,16 @@ static int MountItemByFsType(FstabItem *item)
}
#endif
+static int ExecCheckpointHook(FstabItem *item)
+{
+ HOOK_EXEC_OPTIONS options;
+ options.flags = TRAVERSE_STOP_WHEN_ERROR;
+ options.postHook = NULL;
+ options.preHook = NULL;
+ int ret = HookMgrExecute(GetBootStageHookMgr(), INIT_DISABLE_CHECKPOINT, (void*)item, &options);
+ BEGET_LOGI("ExecCheckpointHook ret %d", ret);
+ return ret;
+}
int MountOneItem(FstabItem *item)
{
if (item == NULL) {
@@ -542,6 +673,7 @@ int MountOneItem(FstabItem *item)
WaitForFile(item->deviceName, WAIT_MAX_SECOND);
}
+ int disableCheckpointRet = -1;
if (strcmp(item->mountPoint, "/data") == 0 && IsSupportedDataType(item->fsType)) {
int ret = DoFsckF2fs(item->deviceName);
if (ret != 0) {
@@ -551,6 +683,7 @@ int MountOneItem(FstabItem *item)
if (ret != 0) {
BEGET_LOGE("Failed to resize.f2fs dir %s , ret = %d", item->deviceName, ret);
}
+ disableCheckpointRet = ExecCheckpointHook(item);
} else if (strcmp(item->fsType, "ext4") == 0 && strcmp(item->mountPoint, "/data") == 0) {
int ret = DoResizeExt(item->deviceName, 0);
if (ret != 0) {
@@ -571,6 +704,10 @@ int MountOneItem(FstabItem *item)
SwitchRoot("/usr");
}
#endif
+ if (disableCheckpointRet == 0 && rc == 0) {
+ BEGET_LOGI("start health check process");
+ HookMgrExecute(GetBootStageHookMgr(), INIT_HEALTH_CHECK_ACTIVE, NULL, NULL);
+ }
InitPostMount(item->mountPoint, rc);
if (rc != 0) {
if (FM_MANAGER_NOFAIL_ENABLED(item->fsManagerFlags)) {
@@ -781,6 +918,8 @@ int MountOneWithFstabFile(const char *fstabFile, const char *devName, bool requi
rc = HvbDmVerityinit(fstab);
if (rc != 0) {
BEGET_LOGE("set dm_verity init, ret = 0x%x", rc);
+ ReleaseFstab(fstab);
+ fstab = NULL;
return rc;
}
}
diff --git a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c
index 10b6c49f72f4b5f094397ebe573069cc4a369f02..011e90de71ead5544bb3ce734b15fc94c6f2bfd4 100755
--- a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c
+++ b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c
@@ -33,23 +33,9 @@ extern "C" {
#endif
#endif
-#define DM_VERSION0 (4)
-#define DM_VERSION1 (0)
-#define DM_VERSION2 (0)
-#define DM_ALIGN_MASK (7)
-#define DM_ALIGN(x) (((x) + DM_ALIGN_MASK) & ~DM_ALIGN_MASK)
-#define DEVICE_MAPPER_PATH "/dev/mapper/control"
-#define DM_DEVICE_PATH_PREFIX "/dev/block/dm-"
-
-#define FS_DM_RETURN_ERR_IF_NULL(__ptr) \
- do { \
- if ((__ptr) == NULL) { \
- BEGET_LOGE("error, %s is NULL\n", #__ptr); \
- return -1; \
- } \
- } while (0)
-
-static int InitDmIo(struct dm_ioctl *io, const char *devName)
+const char g_dmType[MAXNUMTYPE][MAX_WORDS_LEN] = {"verity", "linear", "snapshot", "snapshot-merge"};
+
+int InitDmIo(struct dm_ioctl *io, const char *devName)
{
errno_t err;
@@ -78,7 +64,7 @@ static int InitDmIo(struct dm_ioctl *io, const char *devName)
return 0;
}
-static int CreateDmDevice(int fd, const char *devName)
+int CreateDmDev(int fd, const char *devName)
{
int rc;
struct dm_ioctl io;
@@ -97,8 +83,7 @@ static int CreateDmDevice(int fd, const char *devName)
return 0;
}
-static int LoadDmDeviceTable(int fd, const char *devName,
- DmVerityTarget *target, bool needDmVerity)
+int LoadDmDeviceTable(int fd, const char *devName, DmVerityTarget *target, int dmTypeIdx)
{
int rc;
errno_t err;
@@ -110,6 +95,10 @@ static int LoadDmDeviceTable(int fd, const char *devName,
FS_DM_RETURN_ERR_IF_NULL(target);
FS_DM_RETURN_ERR_IF_NULL(target->paras);
+ if (dmTypeIdx >= MAXNUMTYPE || dmTypeIdx < 0) {
+ BEGET_LOGE("dmTypeIdx error dmTypeIdx %d", dmTypeIdx);
+ return -1;
+ }
parasTotalSize = DM_ALIGN(sizeof(*io) + sizeof(*ts) + target->paras_len + 1);
parasBuf = calloc(1, parasTotalSize);
@@ -132,19 +121,20 @@ static int LoadDmDeviceTable(int fd, const char *devName,
io->data_size = parasTotalSize;
io->data_start = sizeof(*io);
io->target_count = 1;
- io->flags |= DM_READONLY_FLAG;
+ if (dmTypeIdx != SNAPSHOT) {
+ io->flags |= DM_READONLY_FLAG;
+ }
ts->status = 0;
ts->sector_start = target->start;
ts->length = target->length;
- char *targetType = needDmVerity ? "verity" : "linear";
- err = strcpy_s(ts->target_type, sizeof(ts->target_type), targetType);
+ err = strcpy_s(ts->target_type, sizeof(ts->target_type), g_dmType[dmTypeIdx]);
if (err != EOK) {
rc = -1;
BEGET_LOGE("error 0x%x, cp target type", err);
break;
}
-
+ BEGET_LOGI("get target type is %s", ts->target_type);
err = strcpy_s(paras, target->paras_len + 1, target->paras);
if (err != EOK) {
rc = -1;
@@ -166,7 +156,7 @@ static int LoadDmDeviceTable(int fd, const char *devName,
return rc;
}
-static int ActiveDmDevice(int fd, const char *devName)
+int ActiveDmDevice(int fd, const char *devName)
{
int rc;
struct dm_ioctl io;
@@ -238,14 +228,14 @@ int FsDmCreateDevice(char **dmDevPath, const char *devName, DmVerityTarget *targ
return -1;
}
- rc = CreateDmDevice(fd, devName);
+ rc = CreateDmDev(fd, devName);
if (rc != 0) {
BEGET_LOGE("error 0x%x, create dm device fail", rc);
close(fd);
return rc;
}
- rc = LoadDmDeviceTable(fd, devName, target, true);
+ rc = LoadDmDeviceTable(fd, devName, target, VERIFY);
if (rc != 0) {
BEGET_LOGE("error 0x%x, load device table fail", rc);
close(fd);
@@ -296,8 +286,22 @@ int FsDmInitDmDev(char *devPath, bool useSocket)
return -1;
}
}
+ char **devices = (char **)calloc(1, sizeof(char *));
+ if (devices == NULL) {
+ BEGET_LOGE("Failed calloc err=%d", errno);
+ return -1;
+ }
- RetriggerUeventByPath(ueventSockFd, &dmDevPath[0]);
+ devices[0] = strdup(devPath);
+ if (devices[0] == NULL) {
+ BEGET_LOGE("Failed to strdup devPath");
+ free(devices);
+ return -1;
+ }
+ BEGET_LOGI("FsDmInitDmDev dmDevPath %s devices %s", &dmDevPath[0], devices[0]);
+ RetriggerDmUeventByPath(ueventSockFd, &dmDevPath[0], devices, 1);
+ free(devices[0]);
+ free(devices);
close(ueventSockFd);
@@ -336,7 +340,7 @@ int FsDmRemoveDevice(const char *devName)
return 0;
}
-static int DmGetDeviceName(int fd, const char *devName, char *outDevName, const uint64_t outDevNameLen)
+int DmGetDeviceName(int fd, const char *devName, char *outDevName, const uint64_t outDevNameLen)
{
int rc;
char *path = NULL;
@@ -389,7 +393,7 @@ int FsDmCreateLinearDevice(const char *devName, char *dmBlkName, uint64_t dmBlkN
return -1;
}
- rc = CreateDmDevice(fd, devName);
+ rc = CreateDmDev(fd, devName);
if (rc) {
BEGET_LOGE("create dm device failed");
close(fd);
@@ -403,7 +407,7 @@ int FsDmCreateLinearDevice(const char *devName, char *dmBlkName, uint64_t dmBlkN
return -1;
}
- rc = LoadDmDeviceTable(fd, devName, target, false);
+ rc = LoadDmDeviceTable(fd, devName, target, LINEAR);
if (rc) {
BEGET_LOGE("load dm device name failed");
close(fd);
@@ -421,6 +425,28 @@ int FsDmCreateLinearDevice(const char *devName, char *dmBlkName, uint64_t dmBlkN
return 0;
}
+bool GetDmStatusInfo(const char *name, struct dm_ioctl *io)
+{
+ int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ BEGET_LOGE("error 0x%x, open %s", errno, DEVICE_MAPPER_PATH);
+ return false;
+ }
+ int rc = InitDmIo(io, name);
+ if (rc != 0) {
+ close(fd);
+ return false;
+ }
+ if (ioctl(fd, DM_DEV_STATUS, io) != 0) {
+ BEGET_LOGE("DM_DEV_STATUS failed for %s\n", name);
+ close(fd);
+ return false;
+ }
+ close(fd);
+ return true;
+}
+
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c
new file mode 100644
index 0000000000000000000000000000000000000000..fe97cdee302ead9d29d63cc30b9808a72c703185
--- /dev/null
+++ b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c
@@ -0,0 +1,173 @@
+/*
+* Copyright (c) 2025 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
+#include
+#include
+#include
+#include
+#include
+
+#include "securec.h"
+#include "beget_ext.h"
+#include "fs_dm_linear.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+static int LoadDmLinearDeviceTable(int fd, const char *devName, DmLinearTarget *target, uint32_t targetNum)
+{
+ struct dm_ioctl *io = NULL;
+ struct dm_target_spec *ts = NULL;
+ size_t parasTotalSize = DM_ALIGN(sizeof(*io) + sizeof(*ts) * targetNum);
+ for (uint32_t index = 0; index < targetNum; index++) {
+ parasTotalSize += target[index].paras_len + 1;
+ }
+
+ char *parasBuf = calloc(1, parasTotalSize);
+ BEGET_ERROR_CHECK(parasBuf != NULL, return -1, "error, calloc dm table fail");
+ io = (struct dm_ioctl *)parasBuf;
+ int rc = InitDmIo(io, devName);
+ BEGET_ERROR_CHECK(rc == 0, free(parasBuf); return rc, "error %d, init dm io", rc);
+ io->data_size = parasTotalSize;
+ io->data_start = sizeof(*io);
+ io->target_count = targetNum;
+ uint32_t i = 0;
+ uint32_t len = 0;
+ char *paras = NULL;
+ do {
+ FS_DM_RETURN_ERR_IF_NULL(target[i].paras);
+ ts = (struct dm_target_spec *)(parasBuf + sizeof(*io) + len);
+ ts->status = 0;
+ ts->sector_start = target[i].start;
+ ts->length = target[i].length;
+
+ rc = strcpy_s(ts->target_type, sizeof(ts->target_type), "linear");
+ BEGET_ERROR_CHECK(rc == EOK, free(parasBuf); return -1, "error %d, cp target type", rc);
+ len += sizeof((*ts));
+ paras = parasBuf + sizeof(*io) + len;
+ rc = strcpy_s(paras, target[i].paras_len + 1, target[i].paras);
+ BEGET_ERROR_CHECK(rc == EOK, free(parasBuf); return -1, "error %d, cp target paras", rc);
+ BEGET_LOGI("linear target.paras = %s, ts->target_type = %s", target[i].paras, ts->target_type);
+ len += target[i].paras_len + 1;
+ ts->next = target[i].paras_len + 1 + sizeof((*ts));
+ i++;
+ } while (i < targetNum);
+
+ rc = ioctl(fd, DM_TABLE_LOAD, io);
+ if (rc != 0) {
+ BEGET_LOGE("error %d, DM_TABLE_LOAD failed for %s", rc, devName);
+ }
+ free(parasBuf);
+ BEGET_LOGI("LoadDmLinearDeviceTable end, dev is [%s] rc is [%d]", devName, rc);
+ return rc;
+}
+
+int FsDmCreateMultiTargetLinearDevice(const char *devName, char *dmDevPath, uint64_t dmDevPathLen,
+ DmLinearTarget *target, uint32_t targetNum)
+{
+ if (devName == NULL || dmDevPath == NULL || target == NULL) {
+ BEGET_LOGE("argc is null");
+ return -1;
+ }
+ if (targetNum == 0 || targetNum > MAX_TARGET_NUM) {
+ BEGET_LOGE("targetNum:%u is invalid", targetNum);
+ return -1;
+ }
+
+ int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ BEGET_LOGE("open mapper path failed errno %d", errno);
+ return -1;
+ }
+
+ int rc = 0;
+
+ do {
+ rc = CreateDmDev(fd, devName);
+ if (rc != 0) {
+ BEGET_LOGE("create dm device failed %d", rc);
+ break;
+ }
+ rc = DmGetDeviceName(fd, devName, dmDevPath, dmDevPathLen);
+ if (rc != 0) {
+ BEGET_LOGE("get dm device name failed");
+ break;
+ }
+ rc = LoadDmLinearDeviceTable(fd, devName, target, targetNum);
+ if (rc != 0) {
+ BEGET_LOGE("load dm device name failed");
+ break;
+ }
+
+ rc = ActiveDmDevice(fd, devName);
+ if (rc != 0) {
+ BEGET_LOGE("active dm device name failed");
+ break;
+ }
+
+ BEGET_LOGI("fs create linear device success, dev is [%s] dmDevPath is [%s]", devName, dmDevPath);
+ } while (0);
+
+ close(fd);
+ return rc;
+}
+
+int FsDmSwitchToLinearDevice(const char *devName, DmLinearTarget *target, uint32_t targetNum)
+{
+ if (devName == NULL || target == NULL) {
+ BEGET_LOGE("argc is null");
+ return -1;
+ }
+ if (targetNum == 0 || targetNum > MAX_TARGET_NUM) {
+ BEGET_LOGE("targetNum:%u is invalid", targetNum);
+ return -1;
+ }
+
+ int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ BEGET_LOGE("open mapper path failed errno %d", errno);
+ return -1;
+ }
+
+ int rc = 0;
+
+ do {
+ rc = LoadDmLinearDeviceTable(fd, devName, target, targetNum);
+ if (rc != 0) {
+ BEGET_LOGE("load dm device name failed");
+ break;
+ }
+ rc = ActiveDmDevice(fd, devName);
+ if (rc != 0) {
+ BEGET_LOGE("active dm device name failed");
+ break;
+ }
+
+ BEGET_LOGI("fs switch linear device success, dev is [%s]", devName);
+ } while (0);
+
+ close(fd);
+ return rc;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_snapshot.c b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_snapshot.c
new file mode 100644
index 0000000000000000000000000000000000000000..89f960fc7e46ece101092f8ed6f0536e29c809e0
--- /dev/null
+++ b/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_snapshot.c
@@ -0,0 +1,199 @@
+/*
+* Copyright (c) 2025 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
+#include
+#include
+#include
+#include
+#include
+
+#include "securec.h"
+#include "beget_ext.h"
+#include "fs_dm_snapshot.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+int FsDmCreateSnapshotDevice(const char *devName, char *dmDevPath, uint64_t dmDevPathLen, DmSnapshotTarget *target)
+{
+ if (devName == NULL || dmDevPath == NULL || target == NULL) {
+ BEGET_LOGE("argc is null");
+ return -1;
+ }
+ int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ BEGET_LOGE("error %d, open %s", errno, DEVICE_MAPPER_PATH);
+ return -1;
+ }
+ int rc = 0;
+ do {
+ rc = CreateDmDev(fd, devName);
+ if (rc != 0) {
+ BEGET_LOGE("error %d, create dm device fail", rc);
+ break;
+ }
+ rc = LoadDmDeviceTable(fd, devName, target, SNAPSHOT);
+ if (rc != 0) {
+ BEGET_LOGE("error %d, load device table fail", rc);
+ break;
+ }
+ rc = ActiveDmDevice(fd, devName);
+ if (rc != 0) {
+ BEGET_LOGE("error %d, active device fail", rc);
+ break;
+ }
+
+ rc = DmGetDeviceName(fd, devName, dmDevPath, dmDevPathLen);
+ if (rc != 0) {
+ BEGET_LOGE("get dm device name failed");
+ break;
+ }
+
+ BEGET_LOGI("fs create snapshot device success, dev is [%s] dmDevPath is [%s]", devName, dmDevPath);
+ } while (0);
+ close(fd);
+ return rc;
+}
+
+int FsDmSwitchToSnapshotMerge(const char *devName, DmSnapshotTarget *target)
+{
+ if (devName == NULL || target == NULL) {
+ BEGET_LOGE("argc is null");
+ return -1;
+ }
+ int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC);
+ if (fd < 0) {
+ BEGET_LOGE("error %d, open %s", errno, DEVICE_MAPPER_PATH);
+ return -1;
+ }
+ int rc = 0;
+ do {
+ rc = LoadDmDeviceTable(fd, devName, target, SNAPSHOTMERGE);
+ if (rc != 0) {
+ BEGET_LOGE("error %d, load device table fail", rc);
+ break;
+ }
+ rc = ActiveDmDevice(fd, devName);
+ if (rc != 0) {
+ BEGET_LOGE("error %d, active device fail", rc);
+ break;
+ }
+ BEGET_LOGI("fs switch snapshot merge success, dev is %s", devName);
+ } while (0);
+ close(fd);
+ return rc;
+}
+
+static bool ParseStatusText(char *data, StatusInfo *processInfo)
+{
+ BEGET_LOGI("ParseStatusText start \"%s\"", data);
+ int args = sscanf_s(data, "%lu %lu %lu", &processInfo->sectors_allocated,
+ &processInfo->total_sectors, &processInfo->metadata_sectors);
+ if (args == 3) { // 3 is parameters
+ BEGET_LOGI("ParseStatusText success. sectors_allocated %d total_sectors %d metadata_sectors %d",
+ processInfo->sectors_allocated, processInfo->total_sectors, processInfo->metadata_sectors);
+ return true;
+ }
+ if (strlen(data) >= sizeof(processInfo->error)) {
+ BEGET_LOGE("data len err, data is = %s", data);
+ return false;
+ }
+ if (strcpy_s(processInfo->error, sizeof(processInfo->error), data) != EOK) {
+ BEGET_LOGE("strcpy_s err, errno %d", errno);
+ return false;
+ }
+ if (strcmp(processInfo->error, "Invalid") == 0 ||
+ strcmp(processInfo->error, "Overflow") == 0 ||
+ strcmp(processInfo->error, "Merge failed") == 0 ||
+ strcmp(processInfo->error, "") == 0) {
+ BEGET_LOGW("processInfo->error is \"%s\"", processInfo->error);
+ return true;
+ }
+ BEGET_LOGE("could not parse snapshot processInfo \"%s\": wrong format", processInfo->error);
+ return false;
+}
+
+bool GetDmSnapshotStatus(const char *name, const char *targetType, StatusInfo *processInfo)
+{
+ if (name == NULL || targetType == NULL || processInfo == NULL) {
+ BEGET_LOGE("argc is null");
+ return false;
+ }
+ BEGET_LOGI("GetDmSnapshotStatus start, name %s, targetType %s", name, targetType);
+ size_t bufferLen = MAX_TABLE_LEN * sizeof(char);
+ int fd = open(DEVICE_MAPPER_PATH, O_RDWR | O_CLOEXEC);
+ BEGET_ERROR_CHECK(fd >= 0, return false, "open error %d", errno);
+ char *buffer = (char *)calloc(1, bufferLen);
+ BEGET_ERROR_CHECK(buffer != NULL, close(fd); return false, "calloc buffer err");
+ struct dm_ioctl *io = NULL;
+ bool ret = false;
+ do {
+ io = (struct dm_ioctl *)buffer;
+ int rc = InitDmIo(io, name);
+ BEGET_ERROR_CHECK(rc == 0, break, "error %d, init Dm io", rc);
+ io->data_size = bufferLen;
+ io->data_start = sizeof(*io);
+ io->flags = 0;
+ if (ioctl(fd, DM_TABLE_STATUS, io) != 0) {
+ BEGET_LOGE("DM_TABLE_STATUS failed for %s", name);
+ break;
+ }
+ if (io->flags & DM_BUFFER_FULL_FLAG) {
+ BEGET_LOGE("io flags err");
+ break;
+ }
+ size_t cursor = io->data_start;
+ struct dm_target_spec* spec = (struct dm_target_spec*)(&buffer[cursor]);
+ if (cursor + sizeof(struct dm_target_spec) > io->data_size) {
+ BEGET_LOGE("len err");
+ break;
+ }
+ size_t dataOffset = cursor + sizeof(struct dm_target_spec);
+ if ((size_t)spec->next <= sizeof(struct dm_target_spec)) {
+ BEGET_LOGE("spec->next = %u, len err, dataOffset = %zu", spec->next, dataOffset);
+ break;
+ }
+ size_t dataLen = (size_t)spec->next - sizeof(struct dm_target_spec);
+ char *data = (char *)calloc(1, dataLen + 1);
+ BEGET_ERROR_CHECK(data != NULL, break, "calloc dataLen = %zu err", dataLen);
+ rc = strncpy_s(data, dataLen, buffer + dataOffset, dataLen);
+ BEGET_ERROR_CHECK(rc == EOK, free(data); break, "strncpy_s err");
+ if (strcmp(spec->target_type, targetType) != 0 || !ParseStatusText(data, processInfo)) {
+ BEGET_LOGE("get snapshot status fail");
+ free(data);
+ break;
+ }
+ free(data);
+ ret = true;
+ } while (0);
+ BEGET_LOGI("GetDmSnapshotStatus end. ret %d", ret);
+ close(fd);
+ free(buffer);
+ return ret;
+}
+
+bool GetDmMergeProcess(const char *name, StatusInfo *processInfo)
+{
+ return GetDmSnapshotStatus(name, "snapshot-merge", processInfo);
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm.h b/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm.h
index 368275a0ef0272f8af3baebb1448962bbc4cb342..adafdd052ca8c9960e5bcc185cc3be922d375bd6 100755
--- a/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm.h
+++ b/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm.h
@@ -19,6 +19,9 @@
#include
#include
#include
+#include
+#include
+#include
#include "fs_manager.h"
#ifdef __cplusplus
@@ -26,6 +29,24 @@
extern "C" {
#endif
#endif
+#define MAX_PATH_LEN 256
+#define MAX_TABLE_LEN 4096
+#define MAX_WORDS_LEN 20
+#define DM_VERSION0 (4)
+#define DM_VERSION1 (0)
+#define DM_VERSION2 (0)
+#define DM_ALIGN_MASK (7)
+#define DM_ALIGN(x) (((x) + DM_ALIGN_MASK) & ~DM_ALIGN_MASK)
+#define DEVICE_MAPPER_PATH "/dev/mapper/control"
+#define DM_DEVICE_PATH_PREFIX "/dev/block/dm-"
+
+#define FS_DM_RETURN_ERR_IF_NULL(__ptr) \
+ do { \
+ if ((__ptr) == NULL) { \
+ BEGET_LOGE("error, %s is NULL\n", #__ptr); \
+ return -1; \
+ } \
+ } while (0)
typedef struct {
uint64_t start;
@@ -34,11 +55,34 @@ typedef struct {
uint64_t paras_len;
} DmVerityTarget;
+enum DmDeviceType {
+ VERIFY,
+ LINEAR,
+ SNAPSHOT,
+ SNAPSHOTMERGE,
+ MAXNUMTYPE
+};
+
+typedef struct {
+ uint64_t sectors_allocated;
+ uint64_t total_sectors;
+ uint64_t metadata_sectors;
+ char error[MAX_WORDS_LEN];
+} StatusInfo;
+
int FsDmInitDmDev(char *devPath, bool useSocket);
int FsDmCreateDevice(char **dmDevPath, const char *devName, DmVerityTarget *target);
int FsDmRemoveDevice(const char *devName);
-int FsDmCreateLinearDevice(const char *devName, char *dmBlkName, uint64_t dmBlkNameLen, DmVerityTarget *target);
+int FsDmCreateLinearDevice(const char *devName, char *dmBlkName,
+ uint64_t dmBlkNameLen, DmVerityTarget *target);
+int LoadDmDeviceTable(int fd, const char *devName, DmVerityTarget *target, int dmType);
+int DmGetDeviceName(int fd, const char *devName, char *outDevName, const uint64_t outDevNameLen);
+int ActiveDmDevice(int fd, const char *devName);
+int InitDmIo(struct dm_ioctl *io, const char *devName);
+int CreateDmDev(int fd, const char *devName);
+int GetDmDevPath(int fd, char **dmDevPath, const char *devName);
+bool GetDmStatusInfo(const char *name, struct dm_ioctl *io);
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm_linear.h b/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm_linear.h
new file mode 100644
index 0000000000000000000000000000000000000000..d72ff1ebbc9fb0a8e31d969106e0b0d21f6411a5
--- /dev/null
+++ b/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm_linear.h
@@ -0,0 +1,39 @@
+/*
+* Copyright (c) 2025 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_LIBFS_DM_LINEAR_H
+#define STARTUP_LIBFS_DM_LINEAR_H
+
+#include
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+#define MAX_TARGET_NUM 4096
+typedef DmVerityTarget DmLinearTarget;
+int FsDmCreateMultiTargetLinearDevice(const char *devName, char *dmDevPath, uint64_t dmDevPathLen,
+ DmLinearTarget *target, uint32_t targetNum);
+int FsDmSwitchToLinearDevice(const char *devName, DmLinearTarget *target, uint32_t targetNum);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif // STARTUP_LIBFS_DM_LINEAR_H
\ No newline at end of file
diff --git a/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm_snapshot.h b/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm_snapshot.h
new file mode 100644
index 0000000000000000000000000000000000000000..ea86b50aee52e37de5742766b9d40f807850d6a8
--- /dev/null
+++ b/interfaces/innerkits/fs_manager/libfs_dm/include/fs_dm_snapshot.h
@@ -0,0 +1,40 @@
+/*
+* Copyright (c) 2025 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_LIBFS_DM_SNAPSHOT_H
+#define STARTUP_LIBFS_DM_SNAPSHOT_H
+
+#include
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+typedef DmVerityTarget DmSnapshotTarget;
+int FsDmCreateSnapshotDevice(const char *devName, char *dmDevPath, uint64_t dmDevPathLen,
+ DmSnapshotTarget *target);
+int FsDmSwitchToSnapshotMerge(const char *devName, DmSnapshotTarget *target);
+bool GetDmMergeProcess(const char *name, StatusInfo *processInfo);
+bool GetDmSnapshotStatus(const char *name, const char *targetType, StatusInfo *processInfo);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+#endif // STARTUP_LIBFS_DM_SNAPSHOT_H
\ No newline at end of file
diff --git a/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c b/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c
index 4ec40a2070e5232c17217cd3c8b0a1425e169b16..0bf79cf38a04411e576e7c44d5887e7cf83fce75 100755
--- a/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c
+++ b/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c
@@ -25,6 +25,10 @@
#include
#include "hvb_sm2.h"
#include "hvb_sm3.h"
+#include "hookmgr.h"
+#include "bootstage.h"
+#include "fs_manager.h"
+#include "list.h"
#ifdef __cplusplus
#if __cplusplus
@@ -49,6 +53,7 @@ extern "C" {
#define FS_HVB_CMDLINE_PATH "/proc/cmdline"
#define FS_HVB_PARTITION_PREFIX "/dev/block/by-name/"
#define HVB_CMDLINE_EXT_CERT_DIGEST "ohos.boot.hvb.ext_rvt"
+#define FS_HVB_SNAPSHOT_PREFIX "/dev/block/"
#define HASH_ALGO_SHA256 0
#define HASH_ALGO_SHA256_STR "sha256"
@@ -314,6 +319,34 @@ int FsHvbInit(InitHvbType hvbType)
return 0;
}
+static int FsHvbFindVabPartition(const char *devName, HvbDeviceParam *devPara)
+{
+ int rc;
+ HOOK_EXEC_OPTIONS options;
+ if (devPara == NULL) {
+ BEGET_LOGE("error, get devPara");
+ return -1;
+ }
+ if (memcpy_s(devPara->partName, sizeof(devPara->partName), devName, strlen(devName)) != 0) {
+ BEGET_LOGE("error, fail to copy shapshot name");
+ return -1;
+ }
+ (void)memset_s(devPara->value, sizeof(devPara->value), 0, sizeof(devPara->value));
+ devPara->reverse = 1;
+ devPara->len = (int)sizeof(devPara->value);
+ options.flags = TRAVERSE_STOP_WHEN_ERROR;
+ options.preHook = NULL;
+ options.postHook = NULL;
+
+ rc = HookMgrExecute(GetBootStageHookMgr(), INIT_VAB_HVBCHECK, (void*)devPara, &options);
+ BEGET_LOGW("try find partition from snapshot path %s, ret = %d", devName, rc);
+ if (rc == 0) {
+ BEGET_LOGW("found partition %s, len=%d", devPara->value, devPara->len);
+ }
+
+ return rc;
+}
+
static int FsHvbGetCert(struct hvb_cert *cert, const char *devName, struct hvb_verified_data *vd)
{
enum hvb_errno hr;
@@ -321,6 +354,26 @@ static int FsHvbGetCert(struct hvb_cert *cert, const char *devName, struct hvb_v
struct hvb_cert_data *p = vd->certs;
struct hvb_cert_data *end = p + vd->num_loaded_certs;
+ // for virtual ab boot, find partition name with snapshot name
+ HvbDeviceParam devPara = {};
+ if (FsHvbFindVabPartition(devName, &devPara) == 0) {
+ devName = devPara.value;
+ devNameLen = strlen(devName);
+ }
+
+ int bootSlots = GetBootSlots();
+ if (bootSlots > 1) {
+ if (devNameLen <= FS_HVB_AB_SUFFIX_LEN) {
+ BEGET_LOGE("error, devname (%s) is invlaid, devnamelen = %u", devName, devNameLen);
+ return -1;
+ }
+ if (memcmp(devName + devNameLen - FS_HVB_AB_SUFFIX_LEN, "_a", FS_HVB_AB_SUFFIX_LEN) == 0 ||
+ memcmp(devName + devNameLen - FS_HVB_AB_SUFFIX_LEN, "_b", FS_HVB_AB_SUFFIX_LEN) == 0) {
+ BEGET_LOGI("remove ab suffix in %s to match in hvb certs", devName);
+ devNameLen -= FS_HVB_AB_SUFFIX_LEN;
+ }
+ }
+
for (; p < end; p++) {
if (devNameLen != strlen(p->partition_name)) {
continue;
@@ -502,6 +555,15 @@ static int FsHvbVerityTargetAddFecArgs(struct hvb_cert *cert, char *devPath, cha
return 0;
}
+static const char *FsHvbGetFsPrefix(const char *devName)
+{
+ HvbDeviceParam devPara = {};
+ if (FsHvbFindVabPartition(devName, &devPara) == 0) {
+ return FS_HVB_SNAPSHOT_PREFIX;
+ }
+ return FS_HVB_PARTITION_PREFIX;
+}
+
/*
* target->paras is verity table target, format as below;
*
@@ -532,7 +594,7 @@ int FsHvbConstructVerityTarget(DmVerityTarget *target, const char *devName, stru
}
if (snprintf_s(&devPath[0], sizeof(devPath), sizeof(devPath) - 1, "%s%s",
- ((strchr(devName, '/') == NULL) ? FS_HVB_PARTITION_PREFIX : ""), devName) == -1) {
+ ((strchr(devName, '/') == NULL) ? FsHvbGetFsPrefix(devName) : ""), devName) == -1) {
BEGET_LOGE("error, snprintf_s devPath");
return -1;
}
@@ -646,6 +708,7 @@ int FsHvbSetupHashtree(FstabItem *fsItem)
FS_HVB_RETURN_ERR_IF_NULL(g_vd);
// fsItem->deviceName is like /dev/block/platform/xxx/by-name/system
+ // for vab boot, is like /dev/block/dm-1
// we just basename system
devName = basename(fsItem->deviceName);
if (devName == NULL) {
@@ -668,6 +731,9 @@ int FsHvbSetupHashtree(FstabItem *fsItem)
rc = FsDmInitDmDev(dmDevPath, true);
if (rc != 0) {
BEGET_LOGE("error 0x%x, create init dm dev", rc);
+ if (dmDevPath != NULL) {
+ free(dmDevPath);
+ }
goto exit;
}
@@ -723,6 +789,9 @@ static int FsExtHvbSetupHashtree(const char *devName, const char *partition, cha
rc = FsDmInitDmDev(dmDevPath, true);
if (rc != 0) {
BEGET_LOGE("error 0x%x, create init dm dev", rc);
+ if (dmDevPath != NULL) {
+ free(dmDevPath);
+ }
goto exit;
}
diff --git a/interfaces/innerkits/fs_manager/libfs_hvb/hvb_ops.c b/interfaces/innerkits/fs_manager/libfs_hvb/hvb_ops.c
index 9673d8784b529b26050a3f295df68e3c83c43e7e..e801ae5d1ad0135c1a0a159bacedf5d945c6db41 100755
--- a/interfaces/innerkits/fs_manager/libfs_hvb/hvb_ops.c
+++ b/interfaces/innerkits/fs_manager/libfs_hvb/hvb_ops.c
@@ -23,6 +23,11 @@
#include "fs_dm.h"
#include "fs_hvb.h"
#include "securec.h"
+#include "init_utils.h"
+#include "hookmgr.h"
+#include "bootstage.h"
+#include "fs_manager.h"
+#include "list.h"
#ifdef __cplusplus
#if __cplusplus
@@ -31,6 +36,7 @@ extern "C" {
#endif
#define PARTITION_PATH_PREFIX "/dev/block/by-name/"
+#define SNAPSHOT_PATH_PREFIX "/dev/block/"
#define MAX_EXT_HVB_PARTITION_NUM 1
#define FS_HVB_LOCK_STATE_STR_MAX 32
@@ -122,6 +128,87 @@ static char *GetExtHvbVerifiedPath(size_t index)
return tmpPath;
}
+static char *HvbGetABPartitionPath(const size_t pathLen, const char *partition)
+{
+ /* Check if there are multiple partitions */
+ char *path = NULL;
+ int bootSlots = GetBootSlots();
+ if (bootSlots <= 1) {
+ BEGET_LOGE("invalid bootSlots: %d", bootSlots);
+ goto err;
+ }
+
+ /* Confirm partition information */
+ /* slot = 1 is partition a */
+ /* slot = 2 is partition b */
+ int slot = GetCurrentSlot();
+ if (slot <= 0 || slot > MAX_SLOT) {
+ BEGET_LOGW("invalid slot [%d], defaulting to 1", slot);
+ slot = 1;
+ }
+
+ size_t abPathLen = pathLen + FS_HVB_AB_SUFFIX_LEN;
+ path = calloc(1, abPathLen + 1);
+ if (path == NULL) {
+ BEGET_LOGE("error, calloc fail");
+ goto err;
+ }
+
+ /* Concatenate partition names */
+ const char suffix = 'a' + slot - 1;
+ int rc = snprintf_s(path, abPathLen + 1, abPathLen, "%s%s_%c",
+ PARTITION_PATH_PREFIX, partition, suffix);
+ if (rc < 0) {
+ BEGET_LOGE("snprintf_s fail, ret = %d", rc);
+ goto err;
+ }
+ if (access(path, F_OK) != 0) {
+ BEGET_LOGE("still can not access %s, abort verify", path);
+ goto err;
+ }
+
+ BEGET_LOGW("AB path generated: %s", path);
+ return path;
+
+err:
+ if (path != NULL) {
+ free(path);
+ }
+
+ return NULL;
+}
+
+static int HvbGetSnapshotPath(const char *partition, char *out, size_t outLen)
+{
+ int rc;
+ HvbDeviceParam devPara = {};
+ HOOK_EXEC_OPTIONS options = {};
+ if (memcpy_s(devPara.partName, sizeof(devPara.partName), partition, strlen(partition)) != 0) {
+ BEGET_LOGE("error, fail to copy partition");
+ return HVB_IO_ERROR_IO;
+ }
+ devPara.reverse = 0;
+ devPara.len = (int)sizeof(devPara.value);
+ options.flags = TRAVERSE_STOP_WHEN_ERROR;
+ options.preHook = NULL;
+ options.postHook = NULL;
+
+ rc = HookMgrExecute(GetBootStageHookMgr(), INIT_VAB_HVBCHECK, (void *)&devPara, &options);
+ BEGET_LOGW("check snapshot path for partition %s, ret = %d", partition, rc);
+ if (rc != 0) {
+ BEGET_LOGE("error 0x%x, trans vab for %s", rc, partition);
+ return rc;
+ }
+ BEGET_LOGW("snapshot path exists for partition %s", partition);
+ rc = snprintf_s(out, outLen, outLen - 1, "%s%s", SNAPSHOT_PATH_PREFIX,
+ devPara.value);
+ if (rc < 0) {
+ BEGET_LOGE("error, snprintf_s snapshot path fail, ret = %d", rc);
+ return rc;
+ }
+ return 0;
+}
+
static char *HvbGetPartitionPath(const char *partition)
{
int rc;
@@ -137,12 +224,17 @@ static char *HvbGetPartitionPath(const char *partition)
return GetExtHvbVerifiedPath(index);
}
- pathLen = strlen(PARTITION_PATH_PREFIX) + ptnLen;
+ pathLen = strlen(PARTITION_PATH_PREFIX) + HVB_MAX_PARTITION_NAME_LEN - 1;
path = calloc(1, pathLen + 1);
if (path == NULL) {
BEGET_LOGE("error, calloc fail");
return NULL;
}
+
+ if (HvbGetSnapshotPath(partition, path, pathLen) == 0) {
+ return path;
+ }
+
rc = snprintf_s(path, pathLen + 1, pathLen, "%s%s", PARTITION_PATH_PREFIX,
partition);
if (rc < 0) {
@@ -150,6 +242,13 @@ static char *HvbGetPartitionPath(const char *partition)
free(path);
return NULL;
}
+
+ if (access(path, F_OK) != 0) {
+ BEGET_LOGW("Adapting to AB partition");
+ free(path);
+ return HvbGetABPartitionPath(pathLen, partition);
+ }
+
return path;
}
diff --git a/interfaces/innerkits/fs_manager/libfs_hvb/include/fs_hvb.h b/interfaces/innerkits/fs_manager/libfs_hvb/include/fs_hvb.h
index 3aec80d214d7b0f38346dba6017ef926af0cc4e1..23d0719014526bae6e64f67c51f2ee37cd1f049d 100755
--- a/interfaces/innerkits/fs_manager/libfs_hvb/include/fs_hvb.h
+++ b/interfaces/innerkits/fs_manager/libfs_hvb/include/fs_hvb.h
@@ -42,11 +42,12 @@ extern "C" {
#define SZ_1KB (0x1 << 10)
#define SZ_1MB (0x1 << 20)
#define SZ_1GB (0x1 << 30)
-
+
#define SZ_2KB (2 * SZ_1KB)
#define SZ_4KB (4 * SZ_1KB)
#define FS_HVB_MAX_PATH_LEN 128
-
+#define FS_HVB_AB_SUFFIX_LEN 2
+
typedef struct {
uint32_t magicNumber;
uint16_t exthdrSize;
@@ -58,7 +59,7 @@ typedef enum InitHvbType {
MAIN_HVB = 0,
EXT_HVB
} InitHvbType;
-
+
typedef struct {
char *partitionName;
char *pathName;
diff --git a/interfaces/innerkits/include/fs_manager/fs_manager.h b/interfaces/innerkits/include/fs_manager/fs_manager.h
index de7d021bb7c64f6dacad18ef21d9ec08ea9d3be5..a77a3a34982f3c365385840d7ef1cfde519255fe 100644
--- a/interfaces/innerkits/include/fs_manager/fs_manager.h
+++ b/interfaces/innerkits/include/fs_manager/fs_manager.h
@@ -38,6 +38,7 @@ extern "C" {
#define FS_MANAGER_FORMATTABLE 0x00000200
#define NAME_SIZE 32
#define MAX_SLOT 2
+#define HVB_DEV_NAME_SIZE 64
#define VALID_FS_MANAGER_FLAGS (FS_MANAGER_CHECK | FS_MANAGER_WAIT | FS_MANAGER_REQUIRED)
#define FS_MANAGER_FLAGS_ENABLED(fsMgrFlags, flag) (((fsMgrFlags) & FS_MANAGER_##flag) != 0)
@@ -68,6 +69,13 @@ typedef struct {
struct FstabItem *tail;
} Fstab;
+typedef struct {
+ char partName[HVB_DEV_NAME_SIZE];
+ int reverse; // 0 :system->dm0 1:dm0->system
+ char value[HVB_DEV_NAME_SIZE];
+ int len;
+} HvbDeviceParam;
+
typedef enum SlotFlag {
UNBOOT = 0,
ACTIVE = 1,
diff --git a/interfaces/innerkits/include/init_utils.h b/interfaces/innerkits/include/init_utils.h
index a7d6c86e0e86f8d745aa99da2f270a4b1db527a2..87f350064c5b5cf764081455035b1f6cd083fe49 100644
--- a/interfaces/innerkits/include/init_utils.h
+++ b/interfaces/innerkits/include/init_utils.h
@@ -53,6 +53,11 @@ typedef struct {
#define DECIMAL_BASE 10
#define WAIT_MAX_SECOND 5
#define MAX_BUFFER_LEN 256
+#define REPAIR_MODE_LEN 256
+#define MAINTENANCE_RECOVERY "2"
+#define MAINTENANCE_RECOVERY_TYPE 2
+#define MAINTENANCE_RECOVERY_COMPLETE "3"
+#define MAINTENANCE_RECOVERY_COMPLETE_TYPE 3
#define CMDLINE_VALUE_LEN_MAX 512
#define STDERR_HANDLE 2
#define ARRAY_LENGTH(array) (sizeof((array)) / sizeof((array)[0]))
@@ -103,6 +108,8 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
void FreeStringVector(char **vector, int count);
int InUpdaterMode(void);
int InRescueMode(void);
+int InRepairMode(void);
+bool IsPenglaiMode(void);
int StringReplaceChr(char *strl, char oldChr, char newChr);
int OpenConsole(void);
diff --git a/interfaces/innerkits/include/param/init_param.h b/interfaces/innerkits/include/param/init_param.h
index de5fe5abf24471ff19559b91d154ac9d86334b43..4c63107aa5f5c892cd69a4c5c5a72cb6273580c9 100644
--- a/interfaces/innerkits/include/param/init_param.h
+++ b/interfaces/innerkits/include/param/init_param.h
@@ -27,7 +27,7 @@ extern "C" {
#endif
#define DEFAULT_PARAM_WAIT_TIMEOUT 30 // 30s
-#define DEFAULT_PARAM_SET_TIMEOUT 10 // 10s
+#define DEFAULT_PARAM_SET_TIMEOUT 15 // 10s
#ifndef PARAM_NAME_LEN_MAX
#define PARAM_CONST_VALUE_LEN_MAX 4096
@@ -72,6 +72,7 @@ typedef enum {
#define LOAD_PARAM_NORMAL 0x00
#define LOAD_PARAM_ONLY_ADD 0x01
#define LOAD_PARAM_PERSIST 0x02
+#define LOAD_PARAM_UPDATE_CONST 0x04
typedef uint32_t ParamHandle;
@@ -125,6 +126,15 @@ int LoadPrivatePersistParams(void);
*/
int SystemWriteParam(const char *name, const char *value);
+#ifndef OHOS_LITE
+/**
+ * Init 内部接口
+ * 更新只读参数,主要用于Init其他进程使用,通过管道更新只读参数。
+ *
+ */
+int SystemUpdateConstParam(const char *name, const char *value);
+#endif
+
#ifdef PARAM_SUPPORT_TRIGGER
/**
* 对外接口
diff --git a/interfaces/innerkits/include/service_control.h b/interfaces/innerkits/include/service_control.h
index ada09cbf0cc6174ef4c94652f224f5b961883266..e4121944e6bada05592ae9f6629bccfa022fa912 100644
--- a/interfaces/innerkits/include/service_control.h
+++ b/interfaces/innerkits/include/service_control.h
@@ -44,6 +44,8 @@ enum ServiceAction {
START = 0,
STOP = 1,
RESTART = 2,
+ TERM = 3,
+ SERVICE_ACTION_MAX,
};
int ServiceControlWithExtra(const char *serviceName, int action, const char *extArgv[], int extArgc);
diff --git a/interfaces/innerkits/include/syspara/parameter.h b/interfaces/innerkits/include/syspara/parameter.h
index ea220351a3b5addababf668d128a58804cdf3319..bb6671dedeb5d5420b851016b99ca74a333d5a85 100644
--- a/interfaces/innerkits/include/syspara/parameter.h
+++ b/interfaces/innerkits/include/syspara/parameter.h
@@ -28,6 +28,8 @@ extern "C" {
#define OS_FULL_NAME_LEN 128
#define VERSION_ID_MAX_LEN 256
#define PARAM_BUFFER_MAX (0x01 << 16)
+#define PERFORMANCE_CLASS_HIGH_LEVEL 0
+#define PERFORMANCE_CLASS_LOW_LEVEL 2
static const char EMPTY_STR[] = { "" };
@@ -139,6 +141,8 @@ const char *GetVersionId(void);
const char *GetBuildRootHash(void);
const char *GetOsReleaseType(void);
int GetSdkApiVersion(void);
+int GetSdkMinorApiVersion(void);
+int GetSdkPatchApiVersion(void);
const char *GetDeviceType(void);
const char *GetProductModel(void);
@@ -166,6 +170,8 @@ const char *AclGetSerial(void);
int AclGetDevUdid(char *udid, int size);
int AclGetDiskSN(char *diskSN, int size);
+int GetPerformanceClass(void);
+
/**
* @brief Obtains a system parameter matching the specified key.
*
diff --git a/interfaces/innerkits/include/systemcapability.h b/interfaces/innerkits/include/systemcapability.h
index b8d5fb0c86066cadb2329df1f50234180294722b..990878b640c1e11f3c213b841c89894142c4ad45 100644
--- a/interfaces/innerkits/include/systemcapability.h
+++ b/interfaces/innerkits/include/systemcapability.h
@@ -26,6 +26,7 @@ extern "C" {
bool HasSystemCapability(const char *cap);
+bool CheckApiVersionGreaterOrEqual(int majorVersion, int minorVersion, int patchVersion);
#ifdef __cplusplus
#if __cplusplus
diff --git a/interfaces/innerkits/init_module_engine/BUILD.gn b/interfaces/innerkits/init_module_engine/BUILD.gn
index da4f9db69cf4c7d93b4369ff34509f19f80ce720..b750941900c59891c6af895171190644eb7294b7 100644
--- a/interfaces/innerkits/init_module_engine/BUILD.gn
+++ b/interfaces/innerkits/init_module_engine/BUILD.gn
@@ -29,13 +29,8 @@ if (defined(ohos_lite)) {
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/services/init/include",
"//base/startup/init/services/log",
+ "//base/startup/init/interfaces/innerkits/init_module_engine/include",
]
- if (ohos_indep_compiler_enable) {
- include_dirs +=
- [ "//binarys/third_party/cJSON/innerapis/cjson_static/includes" ]
- } else {
- include_dirs += [ "//third_party/cJSON" ]
- }
}
#
diff --git a/interfaces/innerkits/init_module_engine/include/bootstage.h b/interfaces/innerkits/init_module_engine/include/bootstage.h
index 887c70c54be684257a9a0b22193efd41a1602335..c9aa37863ccd778835f71ffbd6f96f3c390e18b8 100755
--- a/interfaces/innerkits/init_module_engine/include/bootstage.h
+++ b/interfaces/innerkits/init_module_engine/include/bootstage.h
@@ -31,7 +31,11 @@ enum INIT_BOOTSTAGE {
INIT_MOUNT_STAGE = 3,
INIT_RESTORECON = 4,
INIT_POST_DATA_UNENCRYPT = 5,
+ INIT_SNAPSHOT_ACTIVE = 6,
+ INIT_DISABLE_CHECKPOINT = 7,
+ INIT_HEALTH_CHECK_ACTIVE = 8,
INIT_PRE_PARAM_SERVICE = 10,
+ INIT_VAB_HVBCHECK = 11,
INIT_PRE_PARAM_LOAD = 20,
INIT_PARAM_LOAD_FILTER = 25,
INIT_PRE_CFG_LOAD = 30,
diff --git a/interfaces/innerkits/init_module_engine/include/init_module_engine.h b/interfaces/innerkits/init_module_engine/include/init_module_engine.h
index 8a1bd582f3a7e9e7bd3a6960055231e5267239a1..c6d28d1fe4fe822ea4ab4b056bb3cfd80d37c83f 100755
--- a/interfaces/innerkits/init_module_engine/include/init_module_engine.h
+++ b/interfaces/innerkits/init_module_engine/include/init_module_engine.h
@@ -33,6 +33,8 @@ extern "C" {
int SystemWriteParam(const char *name, const char *value);
+int SystemUpdateConstParam(const char *name, const char *value);
+
int SystemReadParam(const char *name, char *value, unsigned int *len);
int LoadParamsFile(const char *fileName, bool onlyAdd);
diff --git a/interfaces/innerkits/init_module_engine/stub/libinit.stub.json b/interfaces/innerkits/init_module_engine/stub/libinit.stub.json
index b51c09d9009ef4744aacf3beb9ae87f21d4fccc6..69d05327b7787968f9ef6a7d3a87d3e7cac4d78b 100644
--- a/interfaces/innerkits/init_module_engine/stub/libinit.stub.json
+++ b/interfaces/innerkits/init_module_engine/stub/libinit.stub.json
@@ -1,5 +1,6 @@
[
{ "name": "SystemWriteParam" },
+ { "name": "SystemUpdateConstParam" },
{ "name": "SystemReadParam" },
{ "name": "LoadParamsFile" },
{ "name": "LoadPersistParams" },
diff --git a/interfaces/innerkits/libbegetutil.versionscript b/interfaces/innerkits/libbegetutil.versionscript
index a6762300ec8510b3f2b939742c06223f8197cdcc..2654833e415a69d9458f3c526e6ce541ae73acb4 100644
--- a/interfaces/innerkits/libbegetutil.versionscript
+++ b/interfaces/innerkits/libbegetutil.versionscript
@@ -121,7 +121,9 @@
GetProductModel;
GetProductModelAlias;
GetProductSeries;
- GetSdkApiVersion;
+ GetSdkApiVersion;
+ GetSdkMinorApiVersion;
+ GetSdkPatchApiVersion;
GetSecurityPatchTag;
GetSerial;
GetSoftwareModel;
@@ -140,6 +142,7 @@
StartServiceByTimer;
StopServiceTimer;
HasSystemCapability;
+ CheckApiVersionGreaterOrEqual;
GetBuildVersion;
GetFeatureVersion;
GetMajorVersion;
@@ -150,6 +153,7 @@
GetDistributionOSApiVersion;
GetDistributionOSApiName;
GetDistributionOSReleaseType;
+ GetPerformanceClass;
SaveParameters;
OH_StrArrayGetIndex;
OH_ExtendableStrArrayGetIndex;
diff --git a/interfaces/innerkits/seccomp/include/seccomp_policy.h b/interfaces/innerkits/seccomp/include/seccomp_policy.h
index cb968cbfff32e9730c75938798fb12258ed20993..11e162eadf5cdde54cb547f93cf9a5d8a18f07c3 100644
--- a/interfaces/innerkits/seccomp/include/seccomp_policy.h
+++ b/interfaces/innerkits/seccomp/include/seccomp_policy.h
@@ -33,6 +33,7 @@ extern "C" {
#define APP_PRIVILEGE "app_privilege"
#define APP_ATOMIC "app_atomic"
#define APP_CUSTOM "app_custom"
+#define APP_ALLOW_IOURING "app_allow_iouring"
typedef enum {
SYSTEM_SA, // system service process
diff --git a/interfaces/innerkits/service_control/service_control.c b/interfaces/innerkits/service_control/service_control.c
index 0c78d8da681cb444656b569f64e0cec4a05a0e8b..3aea4ed34b0633a9f3628ddd2d1d66bee500ede1 100644
--- a/interfaces/innerkits/service_control/service_control.c
+++ b/interfaces/innerkits/service_control/service_control.c
@@ -75,6 +75,12 @@ static int StopProcess(const char *serviceName)
return SystemSetParameter("ohos.ctl.stop", serviceName);
}
+static int TermProcess(const char *serviceName)
+{
+ BEGET_ERROR_CHECK(serviceName != NULL, return -1, "Service name is null.");
+ return SystemSetParameter("ohos.ctl.term", serviceName);
+}
+
static int GetCurrentServiceStatus(const char *serviceName, ServiceStatus *status)
{
char paramName[PARAM_NAME_LEN_MAX] = {0};
@@ -133,6 +139,9 @@ int ServiceControlWithExtra(const char *serviceName, int action, const char *ext
case RESTART:
ret = RestartProcess(serviceName, extArgv, extArgc);
break;
+ case TERM:
+ ret = TermProcess(serviceName);
+ break;
default:
BEGET_LOGE("Set service %s action %d error", serviceName, action);
ret = -1;
diff --git a/interfaces/innerkits/syscap/init_syscap.c b/interfaces/innerkits/syscap/init_syscap.c
index b5f85523ff29332ca7d7520f6c5ba30318b5e0fb..a88ba4ff78f877473195d6028fcb901a823681b3 100644
--- a/interfaces/innerkits/syscap/init_syscap.c
+++ b/interfaces/innerkits/syscap/init_syscap.c
@@ -17,7 +17,7 @@
#include
#include
#include
-
+#include "parameter.h"
#include "init_param.h"
#include "beget_ext.h"
#include "securec.h"
@@ -53,4 +53,31 @@ bool HasSystemCapability(const char *cap)
}
return true;
+}
+
+#define API_VERSION_MAX 999
+
+bool CheckApiVersionGreaterOrEqual(int majorVersion, int minorVersion, int patchVersion)
+{
+ if (majorVersion > API_VERSION_MAX || majorVersion < 1) {
+ return false;
+ }
+ if (minorVersion > API_VERSION_MAX || minorVersion < 0) {
+ return false;
+ }
+ if (patchVersion > API_VERSION_MAX || patchVersion < 0) {
+ return false;
+ }
+
+ const int osMajorVersion = GetSdkApiVersion();
+ if (majorVersion != osMajorVersion) {
+ return osMajorVersion > majorVersion;
+ }
+
+ const int osMinorVersion = GetSdkMinorApiVersion();
+ if (minorVersion != osMinorVersion) {
+ return osMinorVersion > minorVersion;
+ }
+
+ return GetSdkPatchApiVersion() >= patchVersion;
}
\ No newline at end of file
diff --git a/interfaces/innerkits/syspara/param_comm.c b/interfaces/innerkits/syspara/param_comm.c
index 9b4047e72fbd1fd27e70ffc57951864f81dcbd7f..017708a69bba7492d52b44972d01951db85ae896 100644
--- a/interfaces/innerkits/syspara/param_comm.c
+++ b/interfaces/innerkits/syspara/param_comm.c
@@ -77,7 +77,7 @@ INIT_LOCAL_API int GetParameter_(const char *key, const char *def, char *value,
if (def == NULL) {
return GetSystemError(ret);
}
- if (strlen(def) > len) {
+ if (strlen(def) >= len) {
return EC_INVALID;
}
ret = strcpy_s(value, len, def);
diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c
index 3ef6f0a122425756c9be4909fce8b8f285dee041..d4d8da6f1b7fe6bf0d8a5c22f887590f9f33dbbb 100644
--- a/interfaces/innerkits/syspara/parameter.c
+++ b/interfaces/innerkits/syspara/parameter.c
@@ -323,6 +323,26 @@ int GetSdkApiVersion(void)
return atoi(sdkApiVersion);
}
+int GetSdkMinorApiVersion(void)
+{
+ static const char *sdkApiMinorVersion = NULL;
+ GetProperty("const.ohos.apiminorversion", &sdkApiMinorVersion);
+ if (sdkApiMinorVersion == NULL) {
+ return -1;
+ }
+ return atoi(sdkApiMinorVersion);
+}
+
+int GetSdkPatchApiVersion(void)
+{
+ static const char *sdkApiPatchVersion = NULL;
+ GetProperty("const.ohos.apipatchversion", &sdkApiPatchVersion);
+ if (sdkApiPatchVersion == NULL) {
+ return -1;
+ }
+ return atoi(sdkApiPatchVersion);
+}
+
const char *GetSecurityPatchTag(void)
{
static const char *securityPatchTag = NULL;
@@ -421,3 +441,17 @@ const char *GetDistributionOSReleaseType(void)
}
return distributionOsReleaseType;
}
+
+int GetPerformanceClass(void)
+{
+ static const char *performanceClass = NULL;
+ GetProperty("const.sys.performance_class", &performanceClass);
+ if (performanceClass == NULL) {
+ return PERFORMANCE_CLASS_HIGH_LEVEL;
+ }
+ int performanceClassValue = atoi(performanceClass);
+ if (performanceClassValue < PERFORMANCE_CLASS_HIGH_LEVEL || performanceClassValue > PERFORMANCE_CLASS_LOW_LEVEL) {
+ return PERFORMANCE_CLASS_HIGH_LEVEL;
+ }
+ return performanceClassValue;
+}
diff --git a/interfaces/kits/cj/BUILD.gn b/interfaces/kits/cj/BUILD.gn
index 461cadd1d15d819e60ba35768ef9dd18e1a4f57a..21f38f9417ff6068de69c5cfd3651d45d04a9d36 100755
--- a/interfaces/kits/cj/BUILD.gn
+++ b/interfaces/kits/cj/BUILD.gn
@@ -42,10 +42,19 @@ ohos_shared_library("cj_device_info_ffi") {
external_deps = [
"bounds_checking_function:libsec_shared",
+ "bundle_framework:appexecfwk_core",
+ "c_utils:utils",
"hilog:libhilog",
"ipc:ipc_single",
"napi:cj_bind_ffi",
+ "samgr:samgr_proxy",
]
+
+ if (defined(global_parts_info) &&
+ defined(global_parts_info.bundlemanager_bundle_framework)) {
+ external_deps += [ "bundle_framework:appexecfwk_base" ]
+ defines += [ "DEPENDENT_APPEXECFWK_BASE" ]
+ }
} else {
defines += [ "PREVIEWER" ]
sources = [ "src_deviceinfo/device_info_mock.cpp" ]
diff --git a/interfaces/kits/cj/src_deviceinfo/device_info.cpp b/interfaces/kits/cj/src_deviceinfo/device_info.cpp
index 15aab5371a6cc2fc105029f8a0adb9f87105c692..f76fe67f830a2ba920590340f15208ce3e335b95 100755
--- a/interfaces/kits/cj/src_deviceinfo/device_info.cpp
+++ b/interfaces/kits/cj/src_deviceinfo/device_info.cpp
@@ -16,15 +16,34 @@
#include "parameter.h"
#include "sysversion.h"
#include "device_info.h"
+#ifdef DEPENDENT_APPEXECFWK_BASE
+#include "bundlemgr/bundle_mgr_proxy.h"
+#endif
+#include "iservice_registry.h"
+#include "if_system_ability_manager.h"
+#include "system_ability_definition.h"
+#include "beget_ext.h"
+#include "init_error.h"
+#include "securec.h"
+#include "log.h"
#include
#include
+#include
namespace OHOS {
namespace CJSystemapi {
namespace DeviceInfo {
const int UDID_LEN = 65;
+const int ODID_LEN = 37;
+
+typedef enum {
+ DEV_INFO_OK,
+ DEV_INFO_ENULLPTR,
+ DEV_INFO_EGETODID,
+ DEV_INFO_ESTRCOPY
+} DevInfoError;
const char* DeviceInfo::CjGetHardwareProfile()
{
@@ -205,6 +224,60 @@ const char* DeviceInfo::CjGetDistributionOSReleaseType()
return GetDistributionOSReleaseType();
}
+static DevInfoError CjAclGetDevOdid(char *odid, int size)
+{
+ DevInfoError ret = DEV_INFO_OK;
+ if (odid[0] != '\0') {
+ return DEV_INFO_OK;
+ }
+ auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ if (!systemAbilityManager) {
+ return DEV_INFO_ENULLPTR;
+ }
+
+ auto remoteObject = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
+ if (!remoteObject) {
+ return DEV_INFO_ENULLPTR;
+ }
+
+#ifdef DEPENDENT_APPEXECFWK_BASE
+ auto bundleMgrProxy = OHOS::iface_cast(remoteObject);
+ if (!bundleMgrProxy) {
+ return DEV_INFO_ENULLPTR;
+ }
+
+ std::string odidStr;
+ if (bundleMgrProxy->GetOdid(odidStr) != 0) {
+ return DEV_INFO_EGETODID;
+ }
+
+ if (strcpy_s(odid, size, odidStr.c_str()) != EOK) {
+ return DEV_INFO_ESTRCOPY;
+ }
+#else
+ LOGE("DEPENDENT_APPEXECFWK_BASE does not exist, The ODID could not be obtained");
+ ret = DEV_INFO_EGETODID;
+#endif
+
+ return ret;
+}
+
+const char* DeviceInfo::CjGetDevOdid()
+{
+ thread_local char odid[ODID_LEN] = {0};
+ DevInfoError ret = CjAclGetDevOdid(odid, ODID_LEN);
+ if (ret != DEV_INFO_OK) {
+ LOGE("GetDevOdid ret:%d", ret);
+ return "";
+ }
+ return odid;
+}
+
+const char* DeviceInfo::CjGetDistributionOSApiName()
+{
+ return GetDistributionOSApiName();
+}
+
} // DeviceInfo
} // CJSystemapi
} // OHOS
diff --git a/interfaces/kits/cj/src_deviceinfo/device_info.h b/interfaces/kits/cj/src_deviceinfo/device_info.h
index 648ca64caba4a3801dae82161ec83504104ed1de..0455c403f7169faaf65479192363d8d5037d7fb7 100644
--- a/interfaces/kits/cj/src_deviceinfo/device_info.h
+++ b/interfaces/kits/cj/src_deviceinfo/device_info.h
@@ -59,6 +59,8 @@ public:
static const char* CjGetDistributionOSVersion();
static int64_t CjGetDistributionOSApiVersion();
static const char* CjGetDistributionOSReleaseType();
+ static const char* CjGetDevOdid();
+ static const char* CjGetDistributionOSApiName();
};
} // DeviceInfo
diff --git a/interfaces/kits/cj/src_deviceinfo/device_info_ffi.cpp b/interfaces/kits/cj/src_deviceinfo/device_info_ffi.cpp
index 5d8098da752d33441120ec3beda0280b86517d10..c9732ede6e6c31121fff26b04997a75641be4371 100644
--- a/interfaces/kits/cj/src_deviceinfo/device_info_ffi.cpp
+++ b/interfaces/kits/cj/src_deviceinfo/device_info_ffi.cpp
@@ -225,6 +225,18 @@ const char* FfiOHOSDeviceInfoDistributionOSReleaseType()
LOGI("DeviceInfo::FfiOHOSDeviceInfoDistributionOSReleaseType");
return DeviceInfo::CjGetDistributionOSReleaseType();
}
+
+FFI_EXPORT const char* FfiOHOSDeviceInfoDevOdid()
+{
+ LOGI("DeviceInfo::FfiOHOSDeviceInfoDevOdid");
+ return DeviceInfo::CjGetDevOdid();
+}
+
+FFI_EXPORT const char* FfiOHOSDeviceInfoDistributionOSApiName()
+{
+ LOGI("DeviceInfo::FfiOHOSDeviceInfoDistributionOSApiName");
+ return DeviceInfo::CjGetDistributionOSApiName();
+}
}
} // DeviceInfo
diff --git a/interfaces/kits/jskits/src/native_deviceinfo_js.cpp b/interfaces/kits/jskits/src/native_deviceinfo_js.cpp
index c90418a22be2440294af9bf7c3d13a326f6069fe..e14503e073189018fb7b3a3ef0be03a8b7c3375a 100644
--- a/interfaces/kits/jskits/src/native_deviceinfo_js.cpp
+++ b/interfaces/kits/jskits/src/native_deviceinfo_js.cpp
@@ -18,6 +18,7 @@
#include "napi/native_api.h"
#include "napi/native_node_api.h"
+#include "napi/native_common.h"
#include "parameter.h"
#include "sysversion.h"
#ifdef DEPENDENT_APPEXECFWK_BASE
@@ -54,6 +55,12 @@ typedef enum {
DEV_INFO_ESTRCOPY
} DevInfoError;
+typedef enum {
+ CLASS_LEVEL_HIGH,
+ CLASS_LEVEL_MEDIUM,
+ CLASS_LEVEL_LOW
+} PerformanceClassLevel;
+
static napi_value GetDeviceType(napi_env env, napi_callback_info info)
{
napi_value deviceType = nullptr;
@@ -314,6 +321,22 @@ static napi_value GetSdkApiVersion(napi_env env, napi_callback_info info)
NAPI_CALL(env, napi_create_int32(env, sdkApiVersion, &napiValue));
return napiValue;
}
+static napi_value GetSdkMinorApiVersion(napi_env env, napi_callback_info info)
+{
+ napi_value napiValue = nullptr;
+ int sdkMinorApiVersion = GetSdkMinorApiVersion();
+
+ NAPI_CALL(env, napi_create_int32(env, sdkMinorApiVersion, &napiValue));
+ return napiValue;
+}
+static napi_value GetSdkPatchApiVersion(napi_env env, napi_callback_info info)
+{
+ napi_value napiValue = nullptr;
+ int sdkPatchApiVersion = GetSdkPatchApiVersion();
+
+ NAPI_CALL(env, napi_create_int32(env, sdkPatchApiVersion, &napiValue));
+ return napiValue;
+}
static napi_value GetFirstApiVersion(napi_env env, napi_callback_info info)
{
@@ -512,6 +535,87 @@ static napi_value GetDiskSN(napi_env env, napi_callback_info info)
return napiValue;
}
+static napi_value EnumLevelClassConstructor(napi_env env, napi_callback_info info)
+{
+ napi_value thisArg = nullptr;
+ void* data = nullptr;
+
+ napi_get_cb_info(env, info, nullptr, nullptr, &thisArg, &data);
+
+ napi_value global = nullptr;
+ napi_get_global(env, &global);
+
+ return thisArg;
+}
+
+static napi_value CreateEnumLevelState(napi_env env, napi_value exports)
+{
+ napi_value high = nullptr;
+ napi_value medium = nullptr;
+ napi_value low = nullptr;
+
+ napi_create_int32(env, (int32_t)PerformanceClassLevel::CLASS_LEVEL_HIGH, &high);
+ napi_create_int32(env, (int32_t)PerformanceClassLevel::CLASS_LEVEL_MEDIUM, &medium);
+ napi_create_int32(env, (int32_t)PerformanceClassLevel::CLASS_LEVEL_LOW, &low);
+
+ napi_property_descriptor desc[] = {
+ DECLARE_NAPI_STATIC_PROPERTY("CLASS_LEVEL_HIGH", high),
+ DECLARE_NAPI_STATIC_PROPERTY("CLASS_LEVEL_MEDIUM", medium),
+ DECLARE_NAPI_STATIC_PROPERTY("CLASS_LEVEL_LOW", low),
+ };
+
+ napi_value result = nullptr;
+ napi_define_class(env, "PerformanceClassLevel", NAPI_AUTO_LENGTH, EnumLevelClassConstructor, nullptr,
+ sizeof(desc) / sizeof(*desc), desc, &result);
+
+ napi_set_named_property(env, exports, "PerformanceClassLevel", result);
+
+ return exports;
+}
+
+static napi_value GetPerformanceClass(napi_env env, napi_callback_info info)
+{
+ napi_value napiValue = nullptr;
+ int performanceClass = GetPerformanceClass();
+
+ NAPI_CALL(env, napi_create_int32(env, performanceClass, &napiValue));
+ return napiValue;
+}
+
+static napi_value CreateDeviceTypes(napi_env env, napi_value exports)
+{
+ napi_value deviceTypes = nullptr;
+ napi_value typeDefault = nullptr;
+ napi_value typePhone = nullptr;
+ napi_value typeTablet = nullptr;
+ napi_value type2in1 = nullptr;
+ napi_value typeTv = nullptr;
+ napi_value typeWearable = nullptr;
+ napi_value typeCar = nullptr;
+
+ napi_create_object(env, &deviceTypes);
+
+ napi_create_string_utf8(env, "default", NAPI_AUTO_LENGTH, &typeDefault);
+ napi_create_string_utf8(env, "phone", NAPI_AUTO_LENGTH, &typePhone);
+ napi_create_string_utf8(env, "tablet", NAPI_AUTO_LENGTH, &typeTablet);
+ napi_create_string_utf8(env, "2in1", NAPI_AUTO_LENGTH, &type2in1);
+ napi_create_string_utf8(env, "tv", NAPI_AUTO_LENGTH, &typeTv);
+ napi_create_string_utf8(env, "wearable", NAPI_AUTO_LENGTH, &typeWearable);
+ napi_create_string_utf8(env, "car", NAPI_AUTO_LENGTH, &typeCar);
+
+ napi_set_named_property(env, deviceTypes, "TYPE_DEFAULT", typeDefault);
+ napi_set_named_property(env, deviceTypes, "TYPE_PHONE", typePhone);
+ napi_set_named_property(env, deviceTypes, "TYPE_TABLET", typeTablet);
+ napi_set_named_property(env, deviceTypes, "TYPE_2IN1", type2in1);
+ napi_set_named_property(env, deviceTypes, "TYPE_TV", typeTv);
+ napi_set_named_property(env, deviceTypes, "TYPE_WEARABLE", typeWearable);
+ napi_set_named_property(env, deviceTypes, "TYPE_CAR", typeCar);
+
+ napi_set_named_property(env, exports, "DeviceTypes", deviceTypes);
+
+ return exports;
+}
+
EXTERN_C_START
/*
* Module init
@@ -544,6 +648,8 @@ static napi_value Init(napi_env env, napi_value exports)
{"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},
+ {"sdkMinorApiVersion", nullptr, nullptr, GetSdkMinorApiVersion, nullptr, nullptr, napi_default, nullptr},
+ {"sdkPatchApiVersion", nullptr, nullptr, GetSdkPatchApiVersion, 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},
@@ -564,9 +670,13 @@ static napi_value Init(napi_env env, napi_value exports)
{"ODID", nullptr, nullptr, GetDevOdid, nullptr, nullptr, napi_default, nullptr},
{"productModelAlias", nullptr, nullptr, GetProductModelAlias, nullptr, nullptr, napi_default, nullptr},
{"diskSN", nullptr, nullptr, GetDiskSN, nullptr, nullptr, napi_default, nullptr},
+ {"performanceClass", nullptr, nullptr, GetPerformanceClass, nullptr, nullptr, napi_default, nullptr},
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc));
+ CreateEnumLevelState(env, exports);
+ CreateDeviceTypes(env, exports);
+
return exports;
}
EXTERN_C_END
diff --git a/interfaces/kits/jskits/src_enhance/native_parameters_js.cpp b/interfaces/kits/jskits/src_enhance/native_parameters_js.cpp
index b5cb18ecac4043221a8bafef18942fcb1e9571ac..9105ea0bb30ae49668c878a57164de304a6e1071 100644
--- a/interfaces/kits/jskits/src_enhance/native_parameters_js.cpp
+++ b/interfaces/kits/jskits/src_enhance/native_parameters_js.cpp
@@ -254,6 +254,7 @@ static napi_value GetSync(napi_env env, napi_callback_info info)
}
std::vector defValue(MAX_VALUE_LENGTH, 0);
size_t valueSize = 0;
+ int flag = 0;
if (argc == ARGC_NUMBER) {
if (valuetype1 == napi_undefined) {
valueSize = 0;
@@ -263,10 +264,11 @@ static napi_value GetSync(napi_env env, napi_callback_info info)
napi_throw(env, BusinessErrorCreate(env, SYSPARAM_INVALID_INPUT));
return nullptr;
}
+ flag = 1;
}
}
std::vector value(MAX_VALUE_LENGTH, 0);
- ret = GetParameter(keyBuf.data(), (valueSize == 0) ? nullptr : defValue.data(), value.data(), MAX_VALUE_LENGTH);
+ ret = GetParameter(keyBuf.data(), (flag == 0) ? nullptr : defValue.data(), value.data(), MAX_VALUE_LENGTH);
PARAM_JS_LOGV("JSApp get status: %d, key: '%s', value: '%s', defValue: '%s'.",
ret, keyBuf.data(), value.data(), defValue.data());
diff --git a/interfaces/kits/syscap/include/deviceinfo.h b/interfaces/kits/syscap/include/deviceinfo.h
index f0b71aba903ea72461144fe20b960b173ab373b6..df5065490cef8c2ba02f574f7069a342cf9b4383 100644
--- a/interfaces/kits/syscap/include/deviceinfo.h
+++ b/interfaces/kits/syscap/include/deviceinfo.h
@@ -156,13 +156,31 @@ const char *OH_GetOsReleaseType(void);
const char *OH_GetOSFullName(void);
/**
- * Obtains the SDK API version number.
+ * Obtains the SDK API major version number.
* @syscap SystemCapability.Startup.SystemInfo
* @return 0 - Not found the SDK API version number, or failed to invoke the internal interface.
* @since 10
*/
int OH_GetSdkApiVersion(void);
+/**
+ * Obtains the sdk minor api version number.
+ * @syscap SystemCapability.Startup.SystemInfo
+ * @return 0 ~ 999 - the sdk minor api version
+ * -1 - not found the sdk minor api version number, or failed to invoke the internal interface.
+ * @since 19
+ */
+int OH_GetSdkMinorApiVersion(void);
+
+/**
+ * Obtains the sdk patch api version number.
+ * @syscap SystemCapability.Startup.SystemInfo
+ * @return 0 ~ 999 - the sdk patch api version
+ * -1 - not found the sdk patch api version number, or failed to invoke the internal interface.
+ * @since 19
+ */
+int OH_GetSdkPatchApiVersion(void);
+
/**
* Obtains the first API version number.
* @syscap SystemCapability.Startup.SystemInfo
diff --git a/interfaces/kits/syscap/include/syscap_ndk.h b/interfaces/kits/syscap/include/syscap_ndk.h
index f9f712a6b25b7407ba45845187117bf3a1c32c48..35432c132bdd73d209cd9e198a8f4711b16391ae 100755
--- a/interfaces/kits/syscap/include/syscap_ndk.h
+++ b/interfaces/kits/syscap/include/syscap_ndk.h
@@ -31,6 +31,24 @@ extern "C" {
*/
bool canIUse(const char *cap);
+/**
+ * @brief determine whether the current operating system version is greater than or equal to the given value.
+ *
+ * @param majorVersion The major version number which betwen 1 and 999, such as 19 in api version 19.1.2
+ * @param minorVersion The minor version number which betwen 0 and 999, such as 1 in api version 19.1.2
+ * @param patchVersion The patch version number which betwen 0 and 999, such as 2 in api version 19.1.2
+ * @return true - operating system version is greater than or equal to the given value
+ * false - operating system version is less than the given value or invalid api version
+ * @since 19
+ * @example given version is "19.1"
+ * if (OH_IsApiVersionGreaterOrEqual(19, 1, 0)) {
+ * // Use 19.1 APIs.
+ * } else {
+ * // Alternative code for earlier versions.
+ * }
+ */
+bool OH_IsApiVersionGreaterOrEqual(int majorVersion, int minorVersion, int patchVersion);
+
#ifdef __cplusplus
#if __cplusplus
}
diff --git a/interfaces/kits/syscap/libdeviceinfo.ndk.json b/interfaces/kits/syscap/libdeviceinfo.ndk.json
index dfed9279629410bcd503cf146c361860ba288421..2ec458945b0713f7d1ae31af433bddd572b23a54 100644
--- a/interfaces/kits/syscap/libdeviceinfo.ndk.json
+++ b/interfaces/kits/syscap/libdeviceinfo.ndk.json
@@ -1,5 +1,9 @@
[
{"name": "canIUse"},
+ {
+ "first_introduced": "19",
+ "name": "OH_IsApiVersionGreaterOrEqual"
+ },
{"name": "OH_GetDeviceType"},
{"name": "OH_GetManufacture"},
{"name": "OH_GetBrand"},
@@ -16,6 +20,14 @@
{"name": "OH_GetOsReleaseType"},
{"name": "OH_GetOSFullName"},
{"name": "OH_GetSdkApiVersion"},
+ {
+ "first_introduced": "19",
+ "name": "OH_GetSdkMinorApiVersion"
+ },
+ {
+ "first_introduced": "19",
+ "name": "OH_GetSdkPatchApiVersion"
+ },
{"name": "OH_GetFirstApiVersion"},
{"name": "OH_GetVersionId"},
{"name": "OH_GetBuildType"},
diff --git a/interfaces/kits/syscap/src/deviceinfo.c b/interfaces/kits/syscap/src/deviceinfo.c
index ee37aa3ca9efcf7d6f8f69c237ee022c9e9233ab..90904181c966b426c05d44b948d35d52d67eac2c 100644
--- a/interfaces/kits/syscap/src/deviceinfo.c
+++ b/interfaces/kits/syscap/src/deviceinfo.c
@@ -99,6 +99,16 @@ int OH_GetSdkApiVersion(void)
return GetSdkApiVersion();
}
+int OH_GetSdkMinorApiVersion(void)
+{
+ return GetSdkMinorApiVersion();
+}
+
+int OH_GetSdkPatchApiVersion(void)
+{
+ return GetSdkPatchApiVersion();
+}
+
int OH_GetFirstApiVersion(void)
{
return GetFirstApiVersion();
diff --git a/interfaces/kits/syscap/src/syscap_ndk.c b/interfaces/kits/syscap/src/syscap_ndk.c
index ece8454723416e4bee6795d7e1b415b3c62f2f24..c86fdacf0510341661dbdc43659b3084f302c073 100644
--- a/interfaces/kits/syscap/src/syscap_ndk.c
+++ b/interfaces/kits/syscap/src/syscap_ndk.c
@@ -21,3 +21,9 @@ bool canIUse(const char *cap)
{
return HasSystemCapability(cap);
}
+
+bool OH_IsApiVersionGreaterOrEqual(int majorVersion, int minorVersion, int patchVersion)
+{
+ return CheckApiVersionGreaterOrEqual(majorVersion, minorVersion, patchVersion);
+}
+
diff --git a/interfaces/taihe/BUILD.gn b/interfaces/taihe/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..74433019dbd065ff61c2faca4df51814f04b56ba
--- /dev/null
+++ b/interfaces/taihe/BUILD.gn
@@ -0,0 +1,24 @@
+# Copyright (c) 2025 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")
+
+group("taihe_group") {
+ if (!defined(ohos_lite)) {
+ deps = [
+ "deviceInfo:deviceInfo_etc",
+ "deviceInfo:deviceInfo_taihe_native",
+ "systemParameterEnhance:systemParamterEnhance_etc",
+ "systemParameterEnhance:systemParameterEnhance_taihe_native",
+ ]
+ }
+}
diff --git a/interfaces/taihe/deviceInfo/BUILD.gn b/interfaces/taihe/deviceInfo/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..6c25be5fd25209fbe6636dfc5e7b50b7828e0e07
--- /dev/null
+++ b/interfaces/taihe/deviceInfo/BUILD.gn
@@ -0,0 +1,83 @@
+# Copyright (c) 2025 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import("//base/startup/init/begetd.gni")
+import("//build/config/components/ets_frontend/ets2abc_config.gni")
+import("//build/ohos.gni")
+import("//build/ohos/taihe_idl/taihe.gni")
+
+copy_taihe_idl("copy_deviceInfo") {
+ sources = [ "idl/ohos.deviceInfo.taihe" ]
+}
+subsystem_name = "startup"
+part_name = "init"
+taihe_generated_file_path_deviceInfo = "$taihe_file_path/out/$subsystem_name/$part_name/deviceInfo"
+
+ohos_taihe("run_taihe") {
+ taihe_generated_file_path = "${taihe_generated_file_path_deviceInfo}"
+ deps = [ ":copy_deviceInfo" ]
+ outputs = [
+ "$taihe_generated_file_path/src/ohos.deviceInfo.ani.cpp",
+ "$taihe_generated_file_path/src/ohos.deviceInfo.abi.c",
+ ]
+}
+
+taihe_shared_library("deviceInfo_taihe_native") {
+ sanitize = {
+ cfi = true
+ cfi_cross_dso = true
+ debug = false
+ }
+ taihe_generated_file_path = "${taihe_generated_file_path_deviceInfo}"
+ part_name = "$part_name"
+ subsystem_name = "$subsystem_name"
+ sources = get_target_outputs(":run_taihe")
+ sources += [
+ "src/ani_constructor.cpp",
+ "src/ohos.deviceInfo.impl.cpp",
+ ]
+ deps = [
+ ":run_taihe",
+ "${init_innerkits_path}:libbeget_proxy",
+ "${init_innerkits_path}:libbegetutil",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_shared",
+ "bundle_framework:appexecfwk_core",
+ "c_utils:utils",
+ "hilog:libhilog_base",
+ "ipc:ipc_single",
+ "runtime_core:ani",
+ "samgr:samgr_proxy",
+ ]
+ if (defined(global_parts_info) &&
+ defined(global_parts_info.bundlemanager_bundle_framework)) {
+ external_deps += [ "bundle_framework:appexecfwk_base" ]
+ defines = [ "DEPENDENT_APPEXECFWK_BASE" ]
+ }
+}
+
+generate_static_abc("deviceInfo") {
+ base_url = "$taihe_generated_file_path_deviceInfo"
+ files = [ "$taihe_generated_file_path_deviceInfo/@ohos.deviceInfo.ets" ]
+ is_boot_abc = "True"
+ device_dst_file = "/system/framework/deviceInfo.abc"
+ dependencies = [ ":run_taihe" ]
+}
+
+ohos_prebuilt_etc("deviceInfo_etc") {
+ source = "$target_out_dir/deviceInfo.abc"
+ module_install_dir = "framework"
+ part_name = "$part_name"
+ subsystem_name = "$subsystem_name"
+ deps = [ ":deviceInfo" ]
+}
diff --git a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe
new file mode 100644
index 0000000000000000000000000000000000000000..4315fe600877fd8ced910ab94a42dcd38aa886b6
--- /dev/null
+++ b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+@!namespace("@ohos.deviceInfo")
+
+@!sts_inject("""
+loadLibrary("deviceInfo_taihe_native.z")
+""")
+
+@class
+interface deviceInfo {
+}
+@static("deviceInfo") @get
+function getbrand(): String;
+@static("deviceInfo") @get
+function getdeviceType(): String;
+@static("deviceInfo") @get
+function getproductSeries(): String;
+@static("deviceInfo") @get
+function getproductModel(): String;
+@static("deviceInfo") @get("ODID")
+function getODID(): String;
+@static("deviceInfo") @get
+function getudid(): String;
+@static("deviceInfo") @get
+function getserial(): String;
+@static("deviceInfo") @get
+function getmanufacture(): String;
+@static("deviceInfo") @get
+function getmarketName(): String;
+@static("deviceInfo") @get
+function getproductModelAlias(): String;
+@static("deviceInfo") @get
+function getsoftwareModel(): String;
+@static("deviceInfo") @get
+function gethardwareModel(): String;
+@static("deviceInfo") @get
+function getbootloaderVersion(): String;
+@static("deviceInfo") @get
+function getabiList(): String;
+@static("deviceInfo") @get
+function getsecurityPatchTag(): String;
+@static("deviceInfo") @get
+function getdisplayVersion(): String;
+@static("deviceInfo") @get
+function getincrementalVersion(): String;
+@static("deviceInfo") @get
+function getosReleaseType(): String;
+@static("deviceInfo") @get
+function getosFullName(): String;
+@static("deviceInfo") @get
+function getversionId(): String;
+@static("deviceInfo") @get
+function getbuildType(): String;
+@static("deviceInfo") @get
+function getbuildUser(): String;
+@static("deviceInfo") @get
+function getbuildHost(): String;
+@static("deviceInfo") @get
+function getbuildTime(): String;
+@static("deviceInfo") @get
+function getbuildRootHash(): String;
+@static("deviceInfo") @get
+function getdistributionOSName(): String;
+@static("deviceInfo") @get
+function getdistributionOSVersion(): String;
+@static("deviceInfo") @get
+function getdistributionOSApiName(): String;
+@static("deviceInfo") @get
+function getdistributionOSReleaseType(): String;
+@static("deviceInfo") @get
+function getdiskSN(): String;
+
+@static("deviceInfo") @get
+function getsdkApiVersion(): i32;
+@static("deviceInfo") @get
+function getmajorVersion(): i32;
+@static("deviceInfo") @get
+function getseniorVersion(): i32;
+@static("deviceInfo") @get
+function getfeatureVersion(): i32;
+@static("deviceInfo") @get
+function getbuildVersion(): i32;
+@static("deviceInfo") @get
+function getfirstApiVersion(): i32;
+@static("deviceInfo") @get
+function getdistributionOSApiVersion(): i32;
\ No newline at end of file
diff --git a/interfaces/taihe/deviceInfo/src/ani_constructor.cpp b/interfaces/taihe/deviceInfo/src/ani_constructor.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9d44aac15ddebe14ae2b193eaf1b80622864fae0
--- /dev/null
+++ b/interfaces/taihe/deviceInfo/src/ani_constructor.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2025 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 "ohos.deviceInfo.ani.hpp"
+ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
+{
+ ani_env *env;
+ if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
+ return ANI_ERROR;
+ }
+ if (ANI_OK != ohos::deviceInfo::ANIRegister(env)) {
+ std::cerr << "Error from ohos::deviceInfo::ANIRegister" << std::endl;
+ return ANI_ERROR;
+ }
+ *result = ANI_VERSION_1;
+ return ANI_OK;
+}
diff --git a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b4a75a590dd4d690118aa7c23e1a9009a696110b
--- /dev/null
+++ b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp
@@ -0,0 +1,451 @@
+/*
+ * Copyright (c) 2025 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 "ohos.deviceInfo.proj.hpp"
+#include "ohos.deviceInfo.impl.hpp"
+#include "taihe/runtime.hpp"
+#include "stdexcept"
+
+#include "beget_ext.h"
+#include "parameter.h"
+#include "sysversion.h"
+#include "bundlemgr/bundle_mgr_proxy.h"
+#include "iservice_registry.h"
+#include "if_system_ability_manager.h"
+#include "system_ability_definition.h"
+#include "init_error.h"
+#include "securec.h"
+
+#ifndef DEVICEINFO_JS_DOMAIN
+#define DEVICEINFO_JS_DOMAIN (BASE_DOMAIN + 8)
+#endif
+
+#ifndef DINFO_TAG
+#define DINFO_TAG "DEVICEINFO_JS"
+#endif
+
+#define DEVINFO_LOGV(fmt, ...) STARTUP_LOGV(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
+#define DEVINFO_LOGI(fmt, ...) STARTUP_LOGI(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
+#define DEVINFO_LOGW(fmt, ...) STARTUP_LOGW(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
+#define DEVINFO_LOGE(fmt, ...) STARTUP_LOGE(DEVICEINFO_JS_DOMAIN, DINFO_TAG, fmt, ##__VA_ARGS__)
+
+constexpr int UDID_LEN = 65;
+constexpr int ODID_LEN = 37;
+constexpr int DISK_SN_LEN = 20;
+
+typedef enum {
+ DEV_INFO_OK,
+ DEV_INFO_ENULLPTR,
+ DEV_INFO_EGETODID,
+ DEV_INFO_ESTRCOPY
+} DevInfoError;
+
+using namespace taihe;
+// using namespace ohos::deviceInfo;
+
+namespace {
+// To be implemented.
+
+class deviceInfoImpl {
+public:
+ deviceInfoImpl() {
+ // Don't forget to implement the constructor.
+ }
+};
+
+string getbrand()
+{
+ const char *value = GetBrand();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getdeviceType()
+{
+ const char *value = GetDeviceType();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getproductSeries()
+{
+ const char *value = GetProductSeries();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getproductModel()
+{
+ const char *value = GetProductModel();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+static DevInfoError AclGetDevOdid(char *odid, int size)
+{
+ DevInfoError ret = DEV_INFO_OK;
+ if (odid[0] != '\0') {
+ return DEV_INFO_OK;
+ }
+ auto systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ if (!systemAbilityManager) {
+ return DEV_INFO_ENULLPTR;
+ }
+
+ auto remoteObject = systemAbilityManager->GetSystemAbility(OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
+ if (!remoteObject) {
+ return DEV_INFO_ENULLPTR;
+ }
+
+#ifdef DEPENDENT_APPEXECFWK_BASE
+ auto bundleMgrProxy = OHOS::iface_cast(remoteObject);
+ if (!bundleMgrProxy) {
+ return DEV_INFO_ENULLPTR;
+ }
+
+ std::string odidStr;
+ if (bundleMgrProxy->GetOdid(odidStr) != 0) {
+ return DEV_INFO_EGETODID;
+ }
+
+ if (strcpy_s(odid, size, odidStr.c_str()) != EOK) {
+ return DEV_INFO_ESTRCOPY;
+ }
+#else
+ DEVINFO_LOGE("DEPENDENT_APPEXECFWK_BASE does not exist, The ODID could not be obtained");
+ ret = DEV_INFO_EGETODID;
+#endif
+
+ return ret;
+}
+
+string getODID()
+{
+ static char value[ODID_LEN] = {0};
+ DevInfoError ret = AclGetDevOdid(value, ODID_LEN);
+ if (ret != DEV_INFO_OK) {
+ DEVINFO_LOGE("GetDevOdid ret:%d", ret);
+ }
+ return value;
+}
+
+string getudid()
+{
+ char value[UDID_LEN] = {0};
+ AclGetDevUdid(value, UDID_LEN);
+ return value;
+}
+
+string getserial()
+{
+ const char *value = AclGetSerial();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getmanufacture()
+{
+ const char *value = GetManufacture();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getmarketName()
+{
+ const char *value = GetMarketName();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getproductModelAlias()
+{
+ const char *value = GetProductModelAlias();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getsoftwareModel()
+{
+ const char *value = GetSoftwareModel();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string gethardwareModel()
+{
+ const char *value = GetHardwareModel();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getbootloaderVersion()
+{
+ const char *value = GetBootloaderVersion();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getabiList()
+{
+ const char *value = GetAbiList();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getsecurityPatchTag()
+{
+ const char *value = GetSecurityPatchTag();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getdisplayVersion()
+{
+ const char *value = GetDisplayVersion();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getincrementalVersion()
+{
+ const char *value = GetIncrementalVersion();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getosReleaseType()
+{
+ const char *value = GetOsReleaseType();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getosFullName()
+{
+ const char *value = GetOSFullName();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getversionId()
+{
+ const char *value = GetVersionId();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getbuildType()
+{
+ const char *value = GetBuildType();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getbuildUser()
+{
+ const char *value = GetBuildUser();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getbuildHost()
+{
+ const char *value = GetBuildHost();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getbuildTime()
+{
+ const char *value = GetBuildTime();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getbuildRootHash()
+{
+ const char *value = GetBuildRootHash();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getdistributionOSName()
+{
+ const char *value = GetDistributionOSName();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getdistributionOSVersion()
+{
+ const char *value = GetDistributionOSVersion();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getdistributionOSApiName()
+{
+ const char *value = GetDistributionOSApiName();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getdistributionOSReleaseType()
+{
+ const char *value = GetDistributionOSReleaseType();
+ if (value == nullptr) {
+ value = "";
+ }
+ return value;
+}
+
+string getdiskSN()
+{
+ static char value[DISK_SN_LEN] = {0};
+ AclGetDiskSN(value, DISK_SN_LEN);
+ return value;
+}
+
+int32_t getsdkApiVersion()
+{
+ int value = GetSdkApiVersion();
+ return value;
+}
+
+int32_t getmajorVersion()
+{
+ int value = GetMajorVersion();
+ return value;
+}
+
+int32_t getseniorVersion()
+{
+ int value = GetSeniorVersion();
+ return value;
+}
+
+int32_t getfeatureVersion()
+{
+ int value = GetFeatureVersion();
+ return value;
+}
+
+int32_t getbuildVersion()
+{
+ int value = GetBuildVersion();
+ return value;
+}
+
+int32_t getfirstApiVersion()
+{
+ int value = GetFirstApiVersion();
+ return value;
+}
+
+int32_t getdistributionOSApiVersion()
+{
+ int value = GetDistributionOSApiVersion();
+ return value;
+}
+} // namespace
+
+TH_EXPORT_CPP_API_getbrand(getbrand);
+TH_EXPORT_CPP_API_getdeviceType(getdeviceType);
+TH_EXPORT_CPP_API_getproductSeries(getproductSeries);
+TH_EXPORT_CPP_API_getproductModel(getproductModel);
+TH_EXPORT_CPP_API_getODID(getODID);
+TH_EXPORT_CPP_API_getudid(getudid);
+TH_EXPORT_CPP_API_getserial(getserial);
+TH_EXPORT_CPP_API_getmanufacture(getmanufacture);
+TH_EXPORT_CPP_API_getmarketName(getmarketName);
+TH_EXPORT_CPP_API_getproductModelAlias(getproductModelAlias);
+TH_EXPORT_CPP_API_getsoftwareModel(getsoftwareModel);
+TH_EXPORT_CPP_API_gethardwareModel(gethardwareModel);
+TH_EXPORT_CPP_API_getbootloaderVersion(getbootloaderVersion);
+TH_EXPORT_CPP_API_getabiList(getabiList);
+TH_EXPORT_CPP_API_getsecurityPatchTag(getsecurityPatchTag);
+TH_EXPORT_CPP_API_getdisplayVersion(getdisplayVersion);
+TH_EXPORT_CPP_API_getincrementalVersion(getincrementalVersion);
+TH_EXPORT_CPP_API_getosReleaseType(getosReleaseType);
+TH_EXPORT_CPP_API_getosFullName(getosFullName);
+TH_EXPORT_CPP_API_getversionId(getversionId);
+TH_EXPORT_CPP_API_getbuildType(getbuildType);
+TH_EXPORT_CPP_API_getbuildUser(getbuildUser);
+TH_EXPORT_CPP_API_getbuildHost(getbuildHost);
+TH_EXPORT_CPP_API_getbuildTime(getbuildTime);
+TH_EXPORT_CPP_API_getbuildRootHash(getbuildRootHash);
+TH_EXPORT_CPP_API_getdistributionOSName(getdistributionOSName);
+TH_EXPORT_CPP_API_getdistributionOSVersion(getdistributionOSVersion);
+TH_EXPORT_CPP_API_getdistributionOSApiName(getdistributionOSApiName);
+TH_EXPORT_CPP_API_getdiskSN(getdiskSN);
+TH_EXPORT_CPP_API_getdistributionOSReleaseType(getdistributionOSReleaseType);
+TH_EXPORT_CPP_API_getsdkApiVersion(getsdkApiVersion);
+TH_EXPORT_CPP_API_getmajorVersion(getmajorVersion);
+TH_EXPORT_CPP_API_getseniorVersion(getseniorVersion);
+TH_EXPORT_CPP_API_getfeatureVersion(getfeatureVersion);
+TH_EXPORT_CPP_API_getbuildVersion(getbuildVersion);
+TH_EXPORT_CPP_API_getfirstApiVersion(getfirstApiVersion);
+TH_EXPORT_CPP_API_getdistributionOSApiVersion(getdistributionOSApiVersion);
diff --git a/interfaces/taihe/systemParameterEnhance/BUILD.gn b/interfaces/taihe/systemParameterEnhance/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..0094822d76a4eb93a7709ac7bcce4a9e92e4d61a
--- /dev/null
+++ b/interfaces/taihe/systemParameterEnhance/BUILD.gn
@@ -0,0 +1,72 @@
+# Copyright (c) 2025 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import("//base/startup/init/begetd.gni")
+import("//build/config/components/ets_frontend/ets2abc_config.gni")
+import("//build/ohos.gni")
+import("//build/ohos/taihe_idl/taihe.gni")
+
+copy_taihe_idl("copy_systemParamterEnhance") {
+ sources = [ "idl/ohos.systemParameterEnhance.taihe" ]
+}
+subsystem_name = "startup"
+part_name = "init"
+taihe_generated_file_path_systemParameterEnhance = "$taihe_file_path/out/$subsystem_name/$part_name/systemParameterEnhance"
+
+ohos_taihe("run_taihe") {
+ taihe_generated_file_path = "${taihe_generated_file_path_systemParameterEnhance}"
+ deps = [ ":copy_systemParamterEnhance" ]
+ outputs = [
+ "$taihe_generated_file_path/src/ohos.systemParameterEnhance.ani.cpp",
+ "$taihe_generated_file_path/src/ohos.systemParameterEnhance.abi.c",
+ ]
+}
+
+taihe_shared_library("systemParameterEnhance_taihe_native") {
+ sanitize = {
+ cfi = true
+ cfi_cross_dso = true
+ debug = false
+ }
+ taihe_generated_file_path = "${taihe_generated_file_path_systemParameterEnhance}"
+ part_name = "$part_name"
+ subsystem_name = "$subsystem_name"
+ sources = get_target_outputs(":run_taihe")
+ sources += [
+ "src/ani_constructor.cpp",
+ "src/ohos.systemParameterEnhance.impl.cpp",
+ ]
+ deps = [
+ ":run_taihe",
+ "${init_innerkits_path}:libbeget_proxy",
+ "${init_innerkits_path}:libbegetutil",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_shared",
+ ]
+}
+
+generate_static_abc("systemParameterEnhance") {
+ base_url = "$taihe_generated_file_path_systemParameterEnhance"
+ files = [ "$taihe_generated_file_path_systemParameterEnhance/@ohos.systemParameterEnhance.ets" ]
+ is_boot_abc = "True"
+ device_dst_file = "/system/framework/systemParameterEnhance.abc"
+ dependencies = [ ":run_taihe" ]
+}
+
+ohos_prebuilt_etc("systemParamterEnhance_etc") {
+ source = "$target_out_dir/systemParameterEnhance.abc"
+ module_install_dir = "framework"
+ part_name = "$part_name"
+ subsystem_name = "$subsystem_name"
+ deps = [ ":systemParameterEnhance" ]
+}
diff --git a/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe
new file mode 100644
index 0000000000000000000000000000000000000000..fa60c6f39f69884621d2a13e04876e9d343f0b7b
--- /dev/null
+++ b/interfaces/taihe/systemParameterEnhance/idl/ohos.systemParameterEnhance.taihe
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+@!namespace("@ohos.systemParameterEnhance", "systemParameterEnhance")
+
+@!sts_inject("""
+static { loadLibrary("systemParameterEnhance_taihe_native.z") }
+""")
+
+function getSync(key: String, def: Optional): String;
+
+@gen_async("get")
+@gen_promise("get")
+function getParam(key: String, def: Optional): String;
+
+@gen_async("get")
+function getParamNodef(key: String): String;
+
+function setSync(key: String, value: String): void;
+
+@gen_async("set")
+@gen_promise("set")
+function setParam(key: String, value: String): void;
+
diff --git a/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp b/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f20e14f07dd70071a1e65d5db2aa7aa70fa958ef
--- /dev/null
+++ b/interfaces/taihe/systemParameterEnhance/src/ani_constructor.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2025 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 "ohos.systemParameterEnhance.ani.hpp"
+ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
+{
+ ani_env *env;
+ if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
+ return ANI_ERROR;
+ }
+ if (ANI_OK != ohos::systemParameterEnhance::ANIRegister(env)) {
+ std::cerr << "Error from ohos::systemParameterEnhance::ANIRegister" << std::endl;
+ return ANI_ERROR;
+ }
+ *result = ANI_VERSION_1;
+ return ANI_OK;
+}
diff --git a/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b685bfdf2dbff48faa45a3b99aded116701823fd
--- /dev/null
+++ b/interfaces/taihe/systemParameterEnhance/src/ohos.systemParameterEnhance.impl.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2025 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 "ohos.systemParameterEnhance.proj.hpp"
+#include "ohos.systemParameterEnhance.impl.hpp"
+#include "taihe/runtime.hpp"
+#include "stdexcept"
+
+#include "beget_ext.h"
+#include "parameter.h"
+#include "sysparam_errno.h"
+
+static constexpr int MAX_VALUE_LENGTH = PARAM_CONST_VALUE_LEN_MAX;
+
+using namespace taihe;
+// using namespace ohos::systemParameterEnhance::systemParameterEnhance;
+
+namespace {
+// To be implemented.
+string GetParam(std::string key, std::string def)
+{
+ if (key.empty()) {
+ taihe::set_business_error(SYSPARAM_INVALID_INPUT, "input is invalid");
+ }
+ char value[MAX_VALUE_LENGTH] = {0};
+ int result = GetParameter(key.c_str(), def.c_str(), value, MAX_VALUE_LENGTH);
+ if (result < 0) {
+ taihe::set_business_error(result, "getSync failed");
+ }
+ return value;
+}
+
+string getSync(string_view key, optional_view def)
+{
+ string defValue = def.value_or("");
+ return GetParam(std::string(key), std::string(defValue));
+}
+
+string getParam(string_view key, optional_view def)
+{
+ string defValue = def.value_or("");
+ return GetParam(std::string(key), std::string(defValue));
+}
+
+string getParamNodef(string_view key)
+{
+ return GetParam(std::string(key), nullptr);
+}
+
+void SetParam(std::string key, std::string value)
+{
+ if (key.empty() || value.empty()) {
+ taihe::set_business_error(SYSPARAM_INVALID_INPUT, "input is invalid");
+ }
+ if (value.size() >= MAX_VALUE_LENGTH) {
+ taihe::set_business_error(SYSPARAM_INVALID_VALUE, "input value is invalid");
+ }
+ int result = SetParameter(key.c_str(), value.c_str());
+ if (result < 0) {
+ taihe::set_business_error(result, "set failed");
+ }
+ return;
+}
+void setSync(string_view key, string_view value)
+{
+ SetParam(std::string(key), std::string(value));
+}
+
+void setParam(string_view key, string_view value)
+{
+ SetParam(std::string(key), std::string(value));
+}
+} // namespace
+
+TH_EXPORT_CPP_API_getSync(getSync);
+TH_EXPORT_CPP_API_getParam(getParam);
+TH_EXPORT_CPP_API_getParamNodef(getParamNodef);
+TH_EXPORT_CPP_API_setSync(setSync);
+TH_EXPORT_CPP_API_setParam(setParam);
diff --git a/remount/remount_overlay.c b/remount/remount_overlay.c
index a214d2a5a943dc6d2151a45d036290872d02b512..2aa41df25c587ce3d50fa556c888e98daf20b18b 100644
--- a/remount/remount_overlay.c
+++ b/remount/remount_overlay.c
@@ -122,7 +122,7 @@ INIT_STATIC int FormatExt4(const char *fsBlkDev, const char *fsMntPoint)
}
const char *mke2fsArgs[] = {
- "/system/bin/mke2fs", "-t", "ext4", "-b", "4096", fsBlkDev, blockSizeBuffer, NULL
+ "/system/bin/mke2fs", "-t", "ext4", "-b", "4096", "-E", "nodiscard", fsBlkDev, blockSizeBuffer, NULL
};
int mke2fsArgsLen = ARRAY_LENGTH(mke2fsArgs);
ret = ExecCommand(mke2fsArgsLen, (char **)mke2fsArgs);
diff --git a/services/begetctl/param_cmd.c b/services/begetctl/param_cmd.c
index 775b6852a69ca172ea9ac08dda4186ea8b897131..feb6c77141bfe909f429ec483621649abdc0f992 100644
--- a/services/begetctl/param_cmd.c
+++ b/services/begetctl/param_cmd.c
@@ -48,7 +48,9 @@ typedef struct {
#define STACK_SIZE (1024 * 1024 * 8)
#define MASK_LENGTH_MAX 4
pid_t g_shellPid = 0;
+#ifndef STARTUP_INIT_TEST
static struct termios g_terminalState;
+#endif
char g_isSetTerminal = 0;
void demoExit(void)
@@ -408,6 +410,7 @@ static int32_t BShellParamCmdPwd(BShellHandle shell, int32_t argc, char *argv[])
return 0;
}
+#ifndef STARTUP_INIT_TEST
static void GetUserInfo(ParamShellExecArgs *execArg, int32_t argc, char *argv[])
{
int32_t i = 0;
@@ -461,6 +464,7 @@ static pid_t ForkChild(int (*childFunc)(void *arg), void *args)
}
return pid;
}
+#endif
static int32_t BShellParamCmdShell(BShellHandle shell, int32_t argc, char *argv[])
{
diff --git a/services/begetctl/shell/shell_main.c b/services/begetctl/shell/shell_main.c
index 041e60ce0e79fb976d9dd74a7e2de4a06dd201ed..3f4a46c63364313b71d56eca30cdca2ac070a03c 100644
--- a/services/begetctl/shell/shell_main.c
+++ b/services/begetctl/shell/shell_main.c
@@ -23,11 +23,13 @@
static BShellHandle g_handle = NULL;
struct termios terminalState;
+#ifndef STARTUP_INIT_TEST
static void signalHandler(int signal)
{
demoExit();
exit(0);
}
+#endif
static int32_t ShellInput(char *data, int32_t len)
{
diff --git a/services/etc/BUILD.gn b/services/etc/BUILD.gn
index 5906d89f85eb02ef436366d76ab9148d01df37c1..897ab81dbcae414b63e9694739ece571c3b0806e 100755
--- a/services/etc/BUILD.gn
+++ b/services/etc/BUILD.gn
@@ -116,12 +116,6 @@ if (defined(ohos_lite)) {
subsystem_name = "startup"
}
- ohos_prebuilt_etc("profile") {
- source = "//base/startup/init/services/etc/profile"
- part_name = "init"
- subsystem_name = "startup"
- }
-
ohos_prebuilt_etc("init.usb.cfg") {
source = "//base/startup/init/services/etc/init.usb.cfg"
part_name = "init"
@@ -259,7 +253,6 @@ if (defined(ohos_lite)) {
":ohos.startup.para",
":ohos_const.para",
":passwd",
- ":profile",
":syscap.json",
":syscap.para",
":systemcapability.json",
diff --git a/services/etc/group b/services/etc/group
index a07f61fd8b078ae923791e12cb77f4b3411e2528..9de435b53f109512959c21b1fea21a07f4c34ef0 100644
--- a/services/etc/group
+++ b/services/etc/group
@@ -13,6 +13,7 @@ wifi:x:1010:
wifi_group:x:1011:wifi,wifi_host
media:x:1013:
dhcp:x:1014:
+font_manager:x:1015:
vpn:x:1016:
keystore:x:1017:
usb:x:1018:
@@ -23,6 +24,7 @@ media_rw:x:1023:
dsoftbus:x:1024:
nfc:x:1027:
sdcard_r:x:1028:
+nfc_tag:x:1029:
package_info:x:1032:
logd:x:1036:
shared_relro:x:1037:
@@ -56,6 +58,7 @@ usbfn_host:x:3024:
power_host:x:3025:
wifi_host:x:3026:
audio_hdi_server_host:x:3027:
+access_control_level_manager:x:3101:
audio_host:x:3127:
camera_host:x:3028:
input_user_host:x:3029:
@@ -170,3 +173,4 @@ app_domain_verify:x:3111:
compiler_service:x:5300:
sandbox_manager:x:3076:
app_fwk_update:x:3350:
+sysselection:x:1080:
diff --git a/services/etc/init.cfg b/services/etc/init.cfg
index 227db6e765e39ebe285aaf4929def8d576ebe060..9ca73fa6bff6b26bb17b21bcc8b66274ba785c69 100755
--- a/services/etc/init.cfg
+++ b/services/etc/init.cfg
@@ -13,7 +13,7 @@
"start ueventd",
"start watchdog_service",
"mkdir /data",
- "mount_fstab /vendor/etc/fstab.${ohos.boot.hardware}",
+ "mount_fstab_sp /vendor/etc/fstab.${ohos.boot.hardware}",
"restorecon /data --skip-ELX",
"chown system system /data",
"chmod 0771 /data",
@@ -27,8 +27,7 @@
"bootchart start",
"chown access_token access_token /dev/access_token_id",
"chmod 0666 /dev/access_token_id",
- "trigger init-hitrace",
- "chmod 0644 /system/etc/profile"
+ "trigger init-hitrace"
]
}, {
"name" : "init",
diff --git a/services/etc/init.without_two_stages.cfg b/services/etc/init.without_two_stages.cfg
index d60d763699650bc145aaa74e330cc505bafcb790..06b1e9d2bc0e7cd3651a472d54fb7ebc6582fb1d 100755
--- a/services/etc/init.without_two_stages.cfg
+++ b/services/etc/init.without_two_stages.cfg
@@ -11,7 +11,7 @@
"start ueventd",
"start watchdog_service",
"mkdir /data",
- "mount_fstab /vendor/etc/fstab.${ohos.boot.hardware}",
+ "mount_fstab_sp /vendor/etc/fstab.${ohos.boot.hardware}",
"chown system system /data",
"chmod 0771 /data",
"mkdir /data/service 0711 root root",
diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para
index e61c3e57d0f12a060b102009684d34386f001830..fa284cb6e5170c419e04247d6e7ec81373ab63b2 100755
--- a/services/etc/param/ohos.para
+++ b/services/etc/param/ohos.para
@@ -29,7 +29,7 @@ const.build.product=default
const.product.hardwareversion=default
const.product.bootloader.version=bootloader
const.product.cpu.abilist=default
-const.product.software.version=OpenHarmony 5.1.0.56
+const.product.software.version=OpenHarmony 6.0.0.43
const.product.incremental.version=default
const.product.firstapiversion=1
const.product.build.type=default
diff --git a/services/etc/param/ohos.para.size b/services/etc/param/ohos.para.size
index caf0bdca25e47e8fddd9a87eecc00b024d18e5b2..36174227de355f10b4d68a5f2cddda07495d130f 100755
--- a/services/etc/param/ohos.para.size
+++ b/services/etc/param/ohos.para.size
@@ -26,11 +26,12 @@ startup_appspawn_param=3145728
hiviewdfx_profiler_param=4096
ohos_boot_param = 8192
bluetooth_param = 8192
-hiviewdfx_hiview_param = 8192
+hiviewdfx_hiview_param = 40960
+develop_private_param = 128000
telephony_param = 20480
const_telephony_param = 4096
vendor_camera_param=6144
-edm_writable_param = 4096
+edm_writable_param = 20480
arkui_param = 2048
wireless_hid_accessory_manager_param = 8192
debug_param = 4096
@@ -40,8 +41,11 @@ media_library_param = 4096
samgr_perf_param = 4096
samgr_writable_param = 10240
ffrt_param = 4096
-developtools_hdc_auth_param = 4096
+developtools_hdc_auth_param = 4096
time_param = 2048
arkcompiler_param = 2048
useriam_fwkready_param = 2048
-custom_param = 2048
+custom_param = 4096
+persist_audio_param = 4096
+update_updater_param = 4096
+bms_param = 20480
diff --git a/services/etc/param/ohos_const/ohos.para b/services/etc/param/ohos_const/ohos.para
index b34e06fa118cdbb5d8a6ad932dc98cfce5d7db82..dd398935feaa992e279cfb605e94b084296bf828 100755
--- a/services/etc/param/ohos_const/ohos.para
+++ b/services/etc/param/ohos_const/ohos.para
@@ -10,7 +10,9 @@
# 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.
-const.ohos.version.security_patch=2025/03/01
+const.ohos.version.security_patch=2025/07/01
const.ohos.releasetype=Beta1
-const.ohos.apiversion=18
-const.ohos.fullname=OpenHarmony-5.1.0.56
\ No newline at end of file
+const.ohos.apiversion=20
+const.ohos.apiminorversion=0
+const.ohos.apipatchversion=0
+const.ohos.fullname=OpenHarmony-6.0.0.43
\ No newline at end of file
diff --git a/services/etc/passwd b/services/etc/passwd
index 4802b4ee987fed45aba14a503ae23b267a3daa1d..41d100045b166aa0a495688ef36f83ac43ea7449 100644
--- a/services/etc/passwd
+++ b/services/etc/passwd
@@ -12,6 +12,7 @@ dfs:x:1009:1009:::/bin/false
wifi:x:1010:1010:::/bin/false
media:x:1013:1013:::/bin/false
dhcp:x:1014:1014:::/bin/false
+font_manager:x:1015:1015:::/bin/false
vpn:x:1016:1016:::/bin/false
keystore:x:1017:1017:::/bin/false
usb:x:1018:1018:::/bin/false
@@ -22,6 +23,7 @@ media_rw:x:1023:1023:::/bin/false
dsoftbus:x:1024:1024:::/bin/false
nfc:x:1027:1027:::/bin/false
sdcard_r:x:1028:1028:::/bin/false
+nfc_tag:x:1029:1029:::/bin/false
package_info:x:1032:1032:::/bin/false
logd:x:1036:1036:::/bin/false
shared_relro:x:1037:1037:::/bin/false
@@ -51,6 +53,7 @@ usbfn_host:x:3024:3024:::/bin/false
power_host:x:3025:3025:::/bin/false
wifi_host:x:3026:3026:::/bin/false
audio_hdi_server_host:x:3027:3027:::/bin/false
+access_control_level_manager:x:3101:3101:::/bin/false
audio_host:x:3127:3127:::/bin/false
camera_host:x:3028:3028:::/bin/false
input_user_host:x:3029:3029:::/bin/false
@@ -163,3 +166,4 @@ app_domain_verify:x:3111:3111:::/bin/false
compiler_service:x:5300:5300:::/bin/false
sandbox_manager:x:3076:3076:::/bin/false
app_fwk_update:x:3350:3350:::/bin/false
+sysselection:x:1080:1080:::/bin/false
diff --git a/services/etc/profile b/services/etc/profile
deleted file mode 100644
index f1667334d0d04a18f9d61135e1f082bd0e91e47c..0000000000000000000000000000000000000000
--- a/services/etc/profile
+++ /dev/null
@@ -1 +0,0 @@
-# /etc/profile: Used to set system-level environment variables and shell configurations.
\ No newline at end of file
diff --git a/services/etc/ueventd.cfg b/services/etc/ueventd.cfg
index 68a1a5d6ddafd52ea6214aca8689a7b83301cbca..1fdff7f70932a65e6758f641d7798a2cde71c9de 100644
--- a/services/etc/ueventd.cfg
+++ b/services/etc/ueventd.cfg
@@ -19,7 +19,7 @@
"SOCK_NONBLOCK"
]
}],
- "caps" : ["DAC_OVERRIDE", "MKNOD", "CHOWN", "FOWNER"],
+ "caps" : ["DAC_OVERRIDE", "MKNOD", "CHOWN", "FOWNER", "CAP_SETGID"],
"ondemand" : true,
"sandbox" : 0,
"start-mode" : "condition",
diff --git a/services/etc_lite/param/ohos_const/ohos.para b/services/etc_lite/param/ohos_const/ohos.para
index f8bfe4c37fbc5dc14aa48c1dc4321fa0516c283a..5433502b0d14e00948dd22a1ea5013dc25a63436 100755
--- a/services/etc_lite/param/ohos_const/ohos.para
+++ b/services/etc_lite/param/ohos_const/ohos.para
@@ -12,6 +12,8 @@
# limitations under the License.
const.ohos.releasetype=Beta1
-const.ohos.apiversion=18
-const.ohos.version.security_patch=2025/03/01
-const.ohos.fullname=OpenHarmony-5.1.0.56
\ No newline at end of file
+const.ohos.apiversion=20
+const.ohos.apiminorversion=0
+const.ohos.apipatchversion=0
+const.ohos.version.security_patch=2025/07/01
+const.ohos.fullname=OpenHarmony-6.0.0.43
\ No newline at end of file
diff --git a/services/init/bootstagehooker.c b/services/init/bootstagehooker.c
index 9124886ed20f36ee9d2d5aa64a946e56a9648392..3cac2bf1d04dcf9e979da4cd53ab686627e3d649 100755
--- a/services/init/bootstagehooker.c
+++ b/services/init/bootstagehooker.c
@@ -17,7 +17,7 @@
#define INIT_BOOTSTAGE_HOOK_NAME "bootstage"
static HOOK_MGR *bootStageHookMgr = NULL;
-HOOK_MGR *GetBootStageHookMgr(void)
+__attribute__((noinline)) HOOK_MGR *GetBootStageHookMgr(void)
{
if (bootStageHookMgr != NULL) {
return bootStageHookMgr;
diff --git a/services/init/include/init.h b/services/init/include/init.h
index d2cc438ff0440fea71692fd2ebaf2a0ea7a9dc00..db75081595cb9e902caad09b3b528d44fb5ed8b3 100644
--- a/services/init/include/init.h
+++ b/services/init/include/init.h
@@ -51,7 +51,7 @@ void SystemConfig(const char *uptime);
void SystemRun(void);
void SystemExecuteRcs(void);
-void ParseInitCfgByPriority(void);
+int ParseCfgByPriority(const char *filePath);
int ParseInitCfg(const char *configFile, void *context);
void ReadConfig(void);
void SignalInit(void);
diff --git a/services/init/include/init_jobs_internal.h b/services/init/include/init_jobs_internal.h
index 775a23b024116cd8abdadc34afb231f6b03ba3f4..bd71ead8c2466323f2a460a497ad7ba6cffdafeb 100644
--- a/services/init/include/init_jobs_internal.h
+++ b/services/init/include/init_jobs_internal.h
@@ -38,10 +38,13 @@ void DumpAllJobs(void);
int DoJobNow(const char *jobName);
+#define INIT_CFG_FIEL_PATH "etc/init"
+#define PENGLAI_CFG_FILE_PATH "etc/penglai"
#define INIT_CONFIGURATION_FILE "/etc/init.cfg"
#define OTHER_CFG_PATH "/system/etc/init"
#define OTHER_CHARGE_PATH "/system/etc/charger"
#define INIT_RESCUE_MODE_PATH "/system/etc/rescue"
+#define MAINTENANCE_RECOVERY_PATH "/system/etc/maintenance_recovery"
#define MAX_PATH_ARGS_CNT 20
void ReadConfig(void);
diff --git a/services/init/include/init_service.h b/services/init/include/init_service.h
index ee353192f613ab1b8083c8801d59cd6cc015f478..0bc31254354b61eb70aa2104de82b7e567bbd4a0 100644
--- a/services/init/include/init_service.h
+++ b/services/init/include/init_service.h
@@ -163,6 +163,7 @@ typedef struct Service {
ServiceArgs capsArgs;
ServiceArgs permArgs;
ServiceArgs permAclsArgs;
+ char *kernelPerms;
Perms servPerm;
ServiceArgs pathArgs;
ServiceArgs writePidArgs;
@@ -184,6 +185,7 @@ Service *GetServiceByPid(pid_t pid);
Service *GetServiceByName(const char *servName);
int ServiceStart(Service *service, ServiceArgs *pathArgs);
int ServiceStop(Service *service);
+int ServiceTerm(Service *service);
void ServiceReap(Service *service);
void ReapService(Service *service);
diff --git a/services/init/include/init_service_manager.h b/services/init/include/init_service_manager.h
index b68272916efaba5d490af6a201708f6e3d94b5e5..7a273ded01db1a4d9625317dfe19ac71937b8526 100644
--- a/services/init/include/init_service_manager.h
+++ b/services/init/include/init_service_manager.h
@@ -56,6 +56,7 @@ extern ServiceSpace g_serviceSpace;
cJSON *GetArrayItem(const cJSON *fileRoot, int *arrSize, const char *arrName);
int ParseOneService(const cJSON *curItem, Service *service);
+void TermServiceByName(const char *serviceName);
void StartServiceByName(const char *serviceName);
void StopServiceByName(const char *serviceName);
void StopAllServices(int flags, const char **exclude, int size,
diff --git a/services/init/init_cgroup.c b/services/init/init_cgroup.c
index 288dd3e323dfc74f0c75ba3cb12778e6108abff0..7104ba25ecfba1858b8fba9174d40241f1b0519e 100644
--- a/services/init/init_cgroup.c
+++ b/services/init/init_cgroup.c
@@ -95,6 +95,7 @@ static void RmdirTimer(Service *service, uint64_t timeout)
serviceRmdir->pid = service->pid;
int strLen = strlen(service->name);
serviceRmdir->name = (char *)malloc(sizeof(char)*(strLen + 1));
+ INIT_ERROR_CHECK(serviceRmdir->name != NULL, free(serviceRmdir); return, "Failed to malloc for serviceRmdir->name");
int ret = strcpy_s(serviceRmdir->name, strLen + 1, service->name);
if (ret != 0) {
free(serviceRmdir->name);
@@ -120,7 +121,8 @@ static void RmdirTimer(Service *service, uint64_t timeout)
int ProcessServiceDied(Service *service)
{
INIT_CHECK_RETURN_VALUE(service != NULL, -1);
- INIT_CHECK_RETURN_VALUE(service->isCgroupEnabled, -1);
+ INIT_CHECK_RETURN_VALUE(service->pid != -1, 0);
+ INIT_CHECK_RETURN_VALUE(service->isCgroupEnabled, 0);
char path[PATH_MAX] = {};
INIT_LOGV("ProcessServiceDied %d to cgroup ", service->pid);
int ret = GetCgroupPath(service, path, sizeof(path));
@@ -135,7 +137,7 @@ int ProcessServiceDied(Service *service)
int ProcessServiceAdd(Service *service)
{
INIT_CHECK_RETURN_VALUE(service != NULL, -1);
- INIT_CHECK_RETURN_VALUE(service->isCgroupEnabled, -1);
+ INIT_CHECK_RETURN_VALUE(service->isCgroupEnabled, 0);
char path[PATH_MAX] = {};
INIT_LOGV("ProcessServiceAdd %d to cgroup ", service->pid);
int ret = GetCgroupPath(service, path, sizeof(path));
diff --git a/services/init/init_common_cmds.c b/services/init/init_common_cmds.c
index 51a6ac62700e5aece31958273c2127ae0c05dc30..f3b475bb7b0dca45ff6c74142db136d774e41935 100644
--- a/services/init/init_common_cmds.c
+++ b/services/init/init_common_cmds.c
@@ -230,6 +230,13 @@ static void DoStop(const struct CmdArgs *ctx)
return;
}
+static void DoTermService(const struct CmdArgs *ctx)
+{
+ INIT_LOGV("DoTermService %s", ctx->argv[0]);
+ TermServiceByName(ctx->argv[0]);
+ return;
+}
+
static void DoReset(const struct CmdArgs *ctx)
{
INIT_LOGV("DoReset %s", ctx->argv[0]);
@@ -590,6 +597,7 @@ static const struct CmdTable g_cmdTable[] = {
{ "rmdir ", 1, 1, 1, DoRmdir },
{ "write ", 2, 10, 1, DoWrite },
{ "stop ", 1, 1, 0, DoStop },
+ { "termservice ", 1, 1, 0, DoTermService },
{ "reset ", 1, 1, 0, DoReset },
{ "copy ", 2, 2, 1, DoCopy },
{ "reboot ", 0, 1, 0, DoRebootCmd },
diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c
index 5fc05b604816d5e4da12c7bb6c690fd5c6a0f749..83de46a88f940e7356a619dcc6d673279fb7769d 100644
--- a/services/init/init_common_service.c
+++ b/services/init/init_common_service.c
@@ -62,6 +62,10 @@
#define NWEBSPAWN_NAME ("nwebspawn")
#endif
+#ifdef CODE_SIGNATURE_ENABLE
+#include "code_sign_attr_utils.h"
+#endif
+
#ifndef TIOCSCTTY
#define TIOCSCTTY 0x540E
#endif
@@ -222,34 +226,8 @@ static void DropCapability(const Service *service)
#endif
}
-static int SetPerms(const Service *service)
+static int SetCapabilities(const Service *service)
{
-#if defined(ENABLE_HOOK_MGR)
- /*
- * service before setting Perms hooks
- */
- ServiceHookExecute(service->name, (const char *)service->pathArgs.argv[0], INIT_SERVICE_SET_PERMS_BEFORE);
-#endif
-
- INIT_ERROR_CHECK(KeepCapability(service) == 0, return INIT_EKEEPCAP,
- "Service error %d %s, failed to set keep capability.", errno, service->name);
-
- INIT_ERROR_CHECK(ServiceSetGid(service) == SERVICE_SUCCESS, return INIT_EGIDSET,
- "Service error %d %s, failed to set gid.", errno, service->name);
-
- // set seccomp policy before setuid
- INIT_ERROR_CHECK(SetSystemSeccompPolicy(service) == SERVICE_SUCCESS, return INIT_ESECCOMP,
- "Service error %d %s, failed to set system seccomp policy.", errno, service->name);
-
- if (service->servPerm.uID != 0) {
- INIT_ERROR_CHECK(setuid(service->servPerm.uID) == 0, return INIT_EUIDSET,
- "Service error %d %s, failed to set uid.", errno, service->name);
- } else {
- if (service->servPerm.capsCnt != 0) {
- DropCapability(service);
- }
- }
-
struct __user_cap_header_struct capHeader;
capHeader.version = _LINUX_CAPABILITY_VERSION_3;
capHeader.pid = 0;
@@ -280,6 +258,46 @@ static int SetPerms(const Service *service)
INIT_ERROR_CHECK(SetAmbientCapability(service->servPerm.caps[i]) == 0, return INIT_ECAP,
"Service error %d %s, failed to set ambient capability.", errno, service->name);
}
+ return 0;
+}
+static int SetPerms(const Service *service)
+{
+#if defined(ENABLE_HOOK_MGR)
+ /*
+ * service before setting Perms hooks
+ */
+ ServiceHookExecute(service->name, (const char *)service->pathArgs.argv[0], INIT_SERVICE_SET_PERMS_BEFORE);
+#endif
+#ifdef CODE_SIGNATURE_ENABLE
+ if (strcmp(service->name, "nwebspawn") == 0) {
+ INIT_LOGV("Set NWebspawn OwnerId");
+ // set nwebspawn OwnerId
+ (void)SetXpmOwnerId(PROCESS_OWNERID_NWEB, NULL);
+ }
+#endif
+
+ INIT_ERROR_CHECK(KeepCapability(service) == 0, return INIT_EKEEPCAP,
+ "Service error %d %s, failed to set keep capability.", errno, service->name);
+
+ INIT_ERROR_CHECK(ServiceSetGid(service) == SERVICE_SUCCESS, return INIT_EGIDSET,
+ "Service error %d %s, failed to set gid.", errno, service->name);
+
+ // set seccomp policy before setuid
+ INIT_ERROR_CHECK(SetSystemSeccompPolicy(service) == SERVICE_SUCCESS, return INIT_ESECCOMP,
+ "Service error %d %s, failed to set system seccomp policy.", errno, service->name);
+
+ if (service->servPerm.uID != 0) {
+ INIT_ERROR_CHECK(setuid(service->servPerm.uID) == 0, return INIT_EUIDSET,
+ "Service error %d %s, failed to set uid.", errno, service->name);
+ } else {
+ if (service->servPerm.capsCnt != 0) {
+ DropCapability(service);
+ }
+ }
+ int ret = SetCapabilities(service);
+ INIT_ERROR_CHECK(ret == 0, return ret,
+ "Service error %d %s, failed to set capabilities.", errno, service->name);
+
#if defined(ENABLE_HOOK_MGR)
/*
* service set Perms hooks
@@ -361,7 +379,7 @@ static int PublishHoldFds(Service *service)
continue;
}
ret = snprintf_s((char *)fdBuffer + pos, sizeof(fdBuffer) - pos, sizeof(fdBuffer) - 1, "%d ", fd);
- INIT_ERROR_CHECK(ret >= 0, return INIT_EFORMAT,
+ INIT_ERROR_CHECK(ret >= 0, close(fd); return INIT_EFORMAT,
"Service error %d %s, failed to format fd for publish", ret, service->name);
pos += (size_t)ret;
}
@@ -626,6 +644,8 @@ static void RunChildProcess(Service *service, ServiceArgs *pathArgs)
_exit(service->lastErrno);
}
+#define PATH_MAY_BE_NOT_EXISTS "/data/"
+
static int IsServiceInvalid(Service *service, ServiceArgs *pathArgs)
{
if (service->attribute & SERVICE_ATTR_INVALID) {
@@ -635,7 +655,9 @@ static int IsServiceInvalid(Service *service, ServiceArgs *pathArgs)
struct stat pathStat = { 0 };
service->attribute &= (~(SERVICE_ATTR_NEED_RESTART | SERVICE_ATTR_NEED_STOP));
if (stat(pathArgs->argv[0], &pathStat) != 0) {
- service->attribute |= SERVICE_ATTR_INVALID;
+ if (strncmp(pathArgs->argv[0], PATH_MAY_BE_NOT_EXISTS, sizeof(PATH_MAY_BE_NOT_EXISTS) - 1) != 0) {
+ service->attribute |= SERVICE_ATTR_INVALID;
+ }
service->lastErrno = INIT_EPATH;
INIT_LOGE("ServiceStart pathArgs invalid, please check %s,%s", service->name, service->pathArgs.argv[0]);
return SERVICE_FAILURE;
@@ -723,6 +745,43 @@ int ServiceStop(Service *service)
INIT_ERROR_CHECK(kill(service->pid, GetKillServiceSig(service->name)) == 0, return SERVICE_FAILURE,
"stop service %s pid %d failed! err %d.", service->name, service->pid, errno);
INIT_LOGI("stop service %s, pid %d.", service->name, service->pid);
+#ifndef OHOS_LITE
+ (void)ProcessServiceDied(service);
+#endif
+ service->pid = -1;
+ NotifyServiceChange(service, SERVICE_STOPPED);
+ return SERVICE_SUCCESS;
+}
+
+int ServiceTerm(Service *service)
+{
+ INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "stop service failed! null ptr.");
+ NotifyServiceChange(service, SERVICE_STOPPING);
+ if (service->serviceJobs.jobsName[JOB_ON_STOP] != NULL) {
+ DoJobNow(service->serviceJobs.jobsName[JOB_ON_STOP]);
+ }
+ service->attribute &= ~SERVICE_ATTR_NEED_RESTART;
+ service->attribute |= SERVICE_ATTR_NEED_STOP;
+ if (service->pid <= 0) {
+ return SERVICE_SUCCESS;
+ }
+ CloseServiceSocket(service);
+ CloseServiceFile(service->fileCfg);
+ // Service stop means service is killed by init or command(i.e stop_service) or system is rebooting
+ // There is no reason still to hold fds
+ if (service->fdCount != 0) {
+ CloseServiceFds(service, true);
+ }
+
+ if (IsServiceWithTimerEnabled(service)) {
+ ServiceStopTimer(service);
+ }
+ INIT_ERROR_CHECK(kill(service->pid, SIGTERM) == 0, return SERVICE_FAILURE,
+ "stop service %s pid %d failed! err %d.", service->name, service->pid, errno);
+ INIT_LOGI("stop service %s, pid %d.", service->name, service->pid);
+#ifndef OHOS_LITE
+ (void)ProcessServiceDied(service);
+#endif
service->pid = -1;
NotifyServiceChange(service, SERVICE_STOPPED);
return SERVICE_SUCCESS;
diff --git a/services/init/init_config.c b/services/init/init_config.c
index 59c3a21091830cfe38fec994537a6f92d3aa3597..7e55861ce160360440c217e322f72d4593a7f64d 100644
--- a/services/init/init_config.c
+++ b/services/init/init_config.c
@@ -107,18 +107,23 @@ void ReadConfig(void)
uint32_t len = sizeof(buffer);
SystemReadParam("ohos.boot.mode", buffer, &len);
INIT_LOGI("ohos.boot.mode %s", buffer);
+ int maintenance = InRepairMode();
if ((strcmp(buffer, "charger_mode") == 0) || (GetBootModeFromMisc() == GROUP_CHARGE)) {
ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL);
- ParseInitCfgByPriority();
+ ParseCfgByPriority(INIT_CFG_FIEL_PATH);
} else if (strcmp(buffer, "charger") == 0) {
ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL);
+ } else if (IsPenglaiMode()) {
+ INIT_LOGI("enter penglai mode");
+ ParseCfgByPriority(PENGLAI_CFG_FILE_PATH);
} else if (InRescueMode() == 0) {
- ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
ReadFileInDir(INIT_RESCUE_MODE_PATH, ".cfg", ParseInitCfg, NULL);
+ } else if (maintenance == MAINTENANCE_RECOVERY_TYPE || maintenance == MAINTENANCE_RECOVERY_COMPLETE_TYPE) {
+ ReadFileInDir(MAINTENANCE_RECOVERY_PATH, ".cfg", ParseInitCfg, NULL);
} else if (InUpdaterMode() == 0) {
ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
- ParseInitCfgByPriority();
+ ParseCfgByPriority(INIT_CFG_FIEL_PATH);
} else {
ReadFileInDir("/etc", ".cfg", ParseInitCfg, NULL);
}
diff --git a/services/init/init_service_manager.c b/services/init/init_service_manager.c
index 45e3b5c7de05542089afff2f83ddbd4e4afeb555..17e9d18c18579ff9a6b0791198caf8c72880d17f 100755
--- a/services/init/init_service_manager.c
+++ b/services/init/init_service_manager.c
@@ -42,6 +42,9 @@
#define VALUE_ATTR_CONSOLE 1
#define VALUE_ATTR_KMSG 2
+#define OHOS_KERNEL_PERM_COUNT_KEY "ohos.encaps.count"
+#define KERNEL_PERM_PRE "encaps"
+#define KERNEL_PERM_MAX_COUNT 64
// All service processes that init will fork+exec.
ServiceSpace g_serviceSpace = { 0 };
@@ -141,6 +144,14 @@ static void ExecuteServiceClear(Service *service)
#endif
}
+static void FreeServiceKernelPerm(Service *service)
+{
+ if (service->kernelPerms != NULL) {
+ free(service->kernelPerms);
+ service->kernelPerms = NULL;
+ }
+}
+
void ReleaseService(Service *service)
{
INIT_CHECK(service != NULL, return);
@@ -149,7 +160,7 @@ void ReleaseService(Service *service)
FreeServiceArg(&service->capsArgs);
FreeServiceArg(&service->permArgs);
FreeServiceArg(&service->permAclsArgs);
-
+ FreeServiceKernelPerm(service);
if (service->servPerm.caps != NULL) {
free(service->servPerm.caps);
service->servPerm.caps = NULL;
@@ -859,12 +870,77 @@ void SetServicePathWithAsan(Service *service)
}
#endif
+static bool AddPermissionItemToKernelPerm(cJSON *kernelPerm, cJSON *permissionItem)
+{
+ const char *key = permissionItem->string;
+ if (cJSON_IsNumber(permissionItem)) {
+ if (!cJSON_AddNumberToObject(kernelPerm, key, permissionItem->valueint)) {
+ INIT_LOGE("GetKernelPerm: add int value failed");
+ return false;
+ }
+ } else if (cJSON_IsBool(permissionItem)) {
+ if (!cJSON_AddBoolToObject(kernelPerm, key, permissionItem->valueint)) {
+ INIT_LOGE("GetKernelPerm: add bool value failed");
+ return false;
+ }
+ } else {
+ INIT_LOGE("GetKernelPerm: value type not supported");
+ return false;
+ }
+ return true;
+}
+
+static bool MakeKernelPerm(const cJSON *cJsonKernelPerms, int count, cJSON *root, cJSON *kernelPerm)
+{
+ INIT_ERROR_CHECK(cJSON_AddNumberToObject(kernelPerm, OHOS_KERNEL_PERM_COUNT_KEY, count) != NULL, \
+ return false, "MakeKernelPerm: failed to add kernelPerm count");
+ for (int i = 0; i < count; i++) {
+ cJSON *permission = cJSON_GetArrayItem(cJsonKernelPerms, i);
+ INIT_ERROR_CHECK(permission != NULL, return false, "MakeKernelPerm: failed to get permission");
+ INIT_ERROR_CHECK(AddPermissionItemToKernelPerm(kernelPerm, permission), return false, \
+ "MakeKernelPerm: failed to add permission");
+ }
+ INIT_ERROR_CHECK(cJSON_AddItemToObject(root, KERNEL_PERM_PRE, kernelPerm), return false, \
+ "MakeKernelPerm: failed to add kernelPerm to root");
+ return true;
+}
+
+static void GetKernelPerm(const cJSON *curItem, Service *service)
+{
+ service->kernelPerms = NULL;
+ cJSON *cJsonKernelPerms = cJSON_GetObjectItemCaseSensitive(curItem, "kernel_permission");
+ INIT_CHECK(cJsonKernelPerms != NULL, return);
+ INIT_LOGI("GetKernelPerm: build kernelPerm str");
+ int count = cJSON_GetArraySize(cJsonKernelPerms);
+ INIT_INFO_CHECK(count > 0, return, "GetKernelPerm: count is zero");
+ INIT_ERROR_CHECK(count < KERNEL_PERM_MAX_COUNT, return, "GetKernelPerm: too many kernelPerm");
+ cJSON *root = cJSON_CreateObject();
+ INIT_ERROR_CHECK(root != NULL, return, "GetKernelPerm: failed to create root");
+ cJSON *kernelPerm = cJSON_CreateObject();
+ if (kernelPerm == NULL) {
+ cJSON_Delete(root);
+ INIT_LOGE("GetKernelPerm: failed to create kernelPerm");
+ return;
+ }
+ if (MakeKernelPerm(cJsonKernelPerms, count, root, kernelPerm)) {
+ service->kernelPerms = cJSON_PrintUnformatted(root);
+ if (service->kernelPerms == NULL) {
+ INIT_LOGE("GetKernelPerm: failed to get kernelPerm str");
+ }
+ cJSON_Delete(root);
+ } else {
+ cJSON_Delete(root);
+ cJSON_Delete(kernelPerm);
+ }
+}
+
static void ParseOneServiceArgs(const cJSON *curItem, Service *service)
{
GetServiceArgs(curItem, "writepid", MAX_WRITEPID_FILES, &service->writePidArgs);
GetServiceArgs(curItem, D_CAPS_STR_IN_CFG, MAX_WRITEPID_FILES, &service->capsArgs);
GetServiceArgs(curItem, "permission", MAX_WRITEPID_FILES, &service->permArgs);
GetServiceArgs(curItem, "permission_acls", MAX_WRITEPID_FILES, &service->permAclsArgs);
+ GetKernelPerm(curItem, service);
size_t strLen = 0;
char *fieldStr = GetStringValue(curItem, APL_STR_IN_CFG, &strLen);
if (fieldStr != NULL) {
@@ -1083,7 +1159,7 @@ int WatchConsoleDevice(Service *service)
return -1;
}
- int fd = open("/dev/console", O_RDWR | O_NOCTTY);
+ int fd = open("/dev/console", O_RDWR | O_NOCTTY | O_CLOEXEC);
if (fd < 0) {
if (errno == ENOENT) {
INIT_LOGW("/dev/console is not exist, wait for it...");
@@ -1092,7 +1168,7 @@ int WatchConsoleDevice(Service *service)
INIT_LOGE("Failed to open /dev/console, err = %d", errno);
return -1;
}
- fd = open("/dev/console", O_RDWR | O_NOCTTY);
+ fd = open("/dev/console", O_RDWR | O_NOCTTY | O_CLOEXEC);
if (fd < 0) {
INIT_LOGW("Failed to open /dev/console after try 1 time, err = %d", errno);
return -1;
@@ -1241,6 +1317,16 @@ void StopServiceByName(const char *servName)
return;
}
+void TermServiceByName(const char *servName)
+{
+ Service *service = GetServiceByName(servName);
+ INIT_ERROR_CHECK(service != NULL, return, "Cannot find service %s.", servName);
+ if (ServiceTerm(service) != SERVICE_SUCCESS) {
+ INIT_LOGE("Service %s term failed!", servName);
+ }
+ return;
+}
+
void StopAllServices(int flags, const char **exclude, int size,
int (*filter)(const Service *service, const char **exclude, int size))
{
diff --git a/services/init/lite/init.c b/services/init/lite/init.c
index 9071b66d6fb0401c9041278fe8b8de463ac6c5de..3e990ac2eb40b3a563ff7d989e476bef30f91603 100644
--- a/services/init/lite/init.c
+++ b/services/init/lite/init.c
@@ -50,8 +50,9 @@ void SystemPrepare(long long uptime)
{
}
-void ParseInitCfgByPriority(void)
+int ParseCfgByPriority(const char *filePath)
{
+ UNUSED(filePath);
ReadFileInDir(OTHER_CFG_PATH, ".cfg", ParseInitCfg, NULL);
ReadFileInDir("/vendor/etc/init", ".cfg", ParseInitCfg, NULL);
}
diff --git a/services/init/standard/BUILD.gn b/services/init/standard/BUILD.gn
index 920c762c2e6cdaeda676c4d39a9445b2084f3d23..40ca304983b75ef2090c83cf698468a7e5038a5e 100644
--- a/services/init/standard/BUILD.gn
+++ b/services/init/standard/BUILD.gn
@@ -49,9 +49,9 @@ ohos_executable("init_early") {
"cJSON:cjson_static",
]
deps = [
- "//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static",
+ "//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static_real",
"//base/startup/init/services/log:init_log",
- "//base/startup/init/ueventd:libueventd_ramdisk_static",
+ "//base/startup/init/ueventd:libueventd_ramdisk_static_real",
]
if (init_extra_static_modules != "") {
deps += [ init_extra_static_modules ]
@@ -60,7 +60,7 @@ ohos_executable("init_early") {
if (is_asan) {
defines += [ "INIT_ASAN" ]
}
- if (asan_detector) {
+ if (asan_detector && init_feature_support_asan) {
defines += [ "ASAN_DETECTOR" ]
}
install_images = [ "ramdisk" ]
@@ -219,6 +219,13 @@ ohos_executable("init") {
defines += [ "SUPPORT_PROFILER_HIDEBUG" ]
external_deps += [ "hiprofiler:libhidebug_init" ]
}
+
+ if (defined(global_parts_info) &&
+ defined(global_parts_info.security_code_signature)) {
+ defines += [ "CODE_SIGNATURE_ENABLE" ]
+ external_deps += [ "code_signature:libcode_sign_attr_utils" ]
+ }
+
if (is_asan) {
defines += [ "INIT_ASAN" ]
}
diff --git a/services/init/standard/init.c b/services/init/standard/init.c
index f2606d9bd6219ec84a81bcd4a7168d906eef879e..c147bcc83857353c2a1979e3d3d79e1367d26364 100755
--- a/services/init/standard/init.c
+++ b/services/init/standard/init.c
@@ -259,9 +259,17 @@ INIT_STATIC void TriggerServices(int startMode)
}
}
-void ParseInitCfgByPriority(void)
+int ParseCfgByPriority(const char *filePath)
{
- CfgFiles *files = GetCfgFiles("etc/init");
+ if (filePath == NULL) {
+ INIT_LOGE("cfg path is null");
+ return -1;
+ }
+ CfgFiles *files = GetCfgFiles(filePath);
+ if (files == NULL) {
+ INIT_LOGE("get etc/init cfg failed");
+ return -1;
+ }
for (int i = 0; files && i < MAX_CFG_POLICY_DIRS_CNT; i++) {
if (files->paths[i]) {
if (ReadFileInDir(files->paths[i], ".cfg", ParseInitCfg, NULL) < 0) {
@@ -270,6 +278,7 @@ void ParseInitCfgByPriority(void)
}
}
FreeCfgFiles(files);
+ return 0;
}
void SystemConfig(const char *uptime)
@@ -306,6 +315,7 @@ void SystemConfig(const char *uptime)
// load SELinux context and policy
// Do not move position!
+ PluginExecCmdByName("preLoadSelinuxPolicy", "");
PluginExecCmdByName("loadSelinuxPolicy", "");
RecordInitBootEvent("init.prepare");
diff --git a/services/init/standard/init_cmds.c b/services/init/standard/init_cmds.c
index 49c5d421083be22625e93869e8a7cb5968d138aa..bdb282e5bd123a2cfde19305f1d8bf8ea186bd98 100755
--- a/services/init/standard/init_cmds.c
+++ b/services/init/standard/init_cmds.c
@@ -299,6 +299,26 @@ static void DoMakeDevice(const struct CmdArgs *ctx)
return;
}
+static void DoMountFstabFileSp(const struct CmdArgs *ctx)
+{
+ INIT_LOGI("Mount partitions from fstab file \" %s \"", ctx->argv[0]);
+ INIT_TIMING_STAT cmdTimer;
+ (void)clock_gettime(CLOCK_MONOTONIC, &cmdTimer.startTime);
+ int ret = MountAllWithFstabFile(ctx->argv[0], 0);
+ (void)clock_gettime(CLOCK_MONOTONIC, &cmdTimer.endTime);
+ long long diff = InitDiffTime(&cmdTimer);
+ INIT_LOGI("Mount partitions from fstab file \" %s \" finish ret %d", ctx->argv[0], ret);
+ HookMgrExecute(GetBootStageHookMgr(), INIT_MOUNT_STAGE, NULL, NULL);
+ char buffer[PARAM_VALUE_LEN_MAX] = {0};
+ ret = sprintf_s(buffer, PARAM_VALUE_LEN_MAX, "%lld", diff);
+ if (ret <= 0) {
+ INIT_LOGE("Failed to sprintf_s");
+ return;
+ }
+ ret = SystemWriteParam("boot.time.fstab", buffer);
+ INIT_ERROR_CHECK(ret == 0, return, "write param boot.time.fstab failed");
+}
+
static void DoMountFstabFile(const struct CmdArgs *ctx)
{
INIT_LOGI("Mount partitions from fstab file \" %s \"", ctx->argv[0]);
@@ -483,9 +503,11 @@ static bool InitFscryptPolicy(void)
{
char policy[FSCRYPT_POLICY_BUF_SIZE];
if (LoadFscryptPolicy(policy, FSCRYPT_POLICY_BUF_SIZE) == 0) {
+#ifndef STARTUP_INIT_TEST
if (SetFscryptSysparam(policy) == 0) {
return true;
}
+#endif
}
return false;
}
@@ -622,10 +644,11 @@ static const struct CmdTable g_cmdTable[] = {
{ "timer_stop", 1, 1, 0, DoTimerStop },
{ "init_global_key ", 1, 1, 0, DoInitGlobalKey },
{ "init_main_user ", 0, 1, 0, DoInitMainUser },
- { "mkswap", 1, 1, 0, DoMkswap},
- { "swapon", 1, 1, 0, DoSwapon},
- { "mksandbox", 1, 1, 0, DoMkSandbox},
- { "stop_feed_highdog", 0, 1, 0, DoStopFeedHighdog},
+ { "mkswap", 1, 1, 0, DoMkswap },
+ { "swapon", 1, 1, 0, DoSwapon },
+ { "mksandbox", 1, 1, 0, DoMkSandbox },
+ { "stop_feed_highdog", 0, 1, 0, DoStopFeedHighdog },
+ { "mount_fstab_sp ", 1, 1, 0, DoMountFstabFileSp },
};
const struct CmdTable *GetCmdTable(int *number)
@@ -647,5 +670,8 @@ int SetFileCryptPolicy(const char *dir)
INIT_LOGE("SetFileCryptPolicy:dir is null");
return -EINVAL;
}
- return FscryptPolicyEnable(dir);
+#ifndef STARTUP_INIT_TEST
+ return FscryptPolicyEnable(dir);
+#endif
+ return 0;
}
diff --git a/services/init/standard/init_firststage.c b/services/init/standard/init_firststage.c
index 4f285a822cb93a64d8c75f31d67080f79f7785b9..27e9f9d5e679569da1d43fb9902e848301f52573 100755
--- a/services/init/standard/init_firststage.c
+++ b/services/init/standard/init_firststage.c
@@ -33,6 +33,8 @@
#include "ueventd_socket.h"
#include "bootstage.h"
+#define SUPPORT_AB_PARTITION_UPDATE 2
+
static char **GetRequiredDevices(Fstab fstab, int *requiredNum)
{
int num = 0;
@@ -101,6 +103,11 @@ static void MountRequiredPartitions(void)
if (devices != NULL && requiredNum > 0) {
int ret = StartUeventd(devices, requiredNum);
if (ret == 0) {
+ if (GetBootSlots() >= SUPPORT_AB_PARTITION_UPDATE) {
+ int snapshotRet = HookMgrExecute(GetBootStageHookMgr(), INIT_SNAPSHOT_ACTIVE,
+ (void *)(fstab), NULL);
+ INIT_LOGI("active sanpshot ret = %d", snapshotRet);
+ }
ret = MountRequriedPartitions(fstab);
}
FreeStringVector(devices, requiredNum);
@@ -128,6 +135,10 @@ static void MountRequiredPartitions(void)
#ifdef ASAN_DETECTOR
static void ChekcAndRunAsanInit(char * const args[])
{
+#ifdef STARTUP_INIT_TEST
+ (void)args;
+ return;
+#else
const char* asanInitPath = "/system/asan/bin/init";
char rebootReason[MAX_BUFFER_LEN] = {0};
INIT_LOGI("ChekcAndRunAsan Begin");
@@ -148,16 +159,17 @@ static void ChekcAndRunAsanInit(char * const args[])
OpenKmsg();
setenv("ASAN_OPTIONS", "include=/system/etc/asan.options", 1);
- setenv("TSAN_OPTIONS", "include=/system/etc/asan.options", 1);
- setenv("UBSAN_OPTIONS", "include=/system/etc/asan.options", 1);
+ setenv("TSAN_OPTIONS", "include=/system/etc/tsan.options", 1);
+ setenv("UBSAN_OPTIONS", "print_stacktrace=1:print_module_map=2:log_exe_name=1", 1);
setenv("HWASAN_OPTIONS", "include=/system/etc/asan.options", 1);
INIT_LOGI("Execute %s, process id %d.", asanInitPath, getpid());
if (execv(asanInitPath, args) != 0) {
INIT_LOGE("Execute %s, execle failed! err %d.", asanInitPath, errno);
}
+#endif
}
#endif
-static void StartSecondStageInit(long long uptime)
+INIT_STATIC void StartSecondStageInit(long long uptime)
{
INIT_LOGI("Start init second stage.");
// It will panic if close stdio before execv("/bin/sh", NULL)
@@ -175,7 +187,9 @@ static void StartSecondStageInit(long long uptime)
NULL,
};
#ifdef ASAN_DETECTOR
- ChekcAndRunAsanInit(args);
+ if (access("/log/asanEnable", F_OK) == 0) {
+ ChekcAndRunAsanInit(args);
+ }
#endif
if (execv("/bin/init", args) != 0) {
INIT_LOGE("Failed to exec \"/bin/init\", err = %d", errno);
diff --git a/services/loopevent/socket/le_socket.c b/services/loopevent/socket/le_socket.c
index 39fe4c40d0cca6494e2f84a5355d5cfb75fba7c1..1f307783c4f3fe04dc96b2e2adb5d763ba60e11a 100644
--- a/services/loopevent/socket/le_socket.c
+++ b/services/loopevent/socket/le_socket.c
@@ -48,7 +48,8 @@ static int CreatePipeServerSocket_(const char *server, int maxClient, int public
LE_CHECK(listenfd > 0, return listenfd, "Failed to create socket errno %d", errno);
int ret = SetSocketTimeout(listenfd);
- LE_CHECK(ret == 0, return ret, "Failed to set socket timeout");
+ LE_CHECK(ret == 0, close(listenfd);
+ return ret, "Failed to set socket timeout");
unlink(server);
struct sockaddr_un serverAddr;
@@ -89,7 +90,8 @@ static int CreatePipeSocket_(const char *server)
LE_CHECK(ret == 0, return ret, "Failed to set socket option");
ret = SetSocketTimeout(fd);
- LE_CHECK(ret == 0, return ret, "Failed to set socket timeout");
+ LE_CHECK(ret == 0, close(fd);
+ return ret, "Failed to set socket timeout");
struct sockaddr_un serverAddr;
ret = memset_s(&serverAddr, sizeof(serverAddr), 0, sizeof(serverAddr));
diff --git a/services/modules/bootchart/BUILD.gn b/services/modules/bootchart/BUILD.gn
index ac9570a766547457d0a0eddfc09a2731a612ac99..22cba63d35840c57ef7b839770564c89e57d493b 100755
--- a/services/modules/bootchart/BUILD.gn
+++ b/services/modules/bootchart/BUILD.gn
@@ -49,4 +49,5 @@ ohos_source_set("libbootchart_static") {
sources = [ "bootchart_static.c" ]
public_configs = [ ":libbootchart_static_config" ]
public_configs += [ "//base/startup/init/interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
+ external_deps = [ "cJSON:cjson" ]
}
diff --git a/services/modules/bootevent/BUILD.gn b/services/modules/bootevent/BUILD.gn
index 6caa1f1aa9f72f5508d9c95eed602812c663953c..281d4adf9b700ebf3a2e2de7bfcf9e9bdee9b8fb 100755
--- a/services/modules/bootevent/BUILD.gn
+++ b/services/modules/bootevent/BUILD.gn
@@ -33,12 +33,13 @@ ohos_source_set("libbootevent_static") {
]
sources += [ "//base/startup/init/services/utils/init_utils.c" ]
public_configs = [ ":bootevent_static_config" ]
+ external_deps = [ "cJSON:cjson" ]
public_external_deps = [ "config_policy:configpolicy_util" ]
public_configs += [ "//base/startup/init/interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
public_external_deps += [ "bounds_checking_function:libsec_static" ]
if (build_selinux) {
include_dirs += [ "//base/startup/init/interfaces/innerkits/include/param" ]
- external_deps = [
+ external_deps += [
"selinux:libselinux",
"selinux_adapter:librestorecon",
]
diff --git a/services/modules/bootevent/bootevent.c b/services/modules/bootevent/bootevent.c
index 67b68e5c3e1f3a9238e6d6ab1176d41807bcb1ec..89b4e230cbf5e736b3793e4767c3ed71b2c60351 100755
--- a/services/modules/bootevent/bootevent.c
+++ b/services/modules/bootevent/bootevent.c
@@ -32,6 +32,9 @@
#ifdef WITH_SELINUX
#include
#endif
+#ifndef STARTUP_INIT_TEST
+static const int SLEPP_TIME = 100;
+#endif
static int GetBootSwitchEnable(const char *paramName)
{
@@ -315,6 +318,35 @@ static void WriteBooteventSysParam(const char *paramName)
SystemWriteParam(name, buf);
}
+#ifndef STARTUP_INIT_TEST
+static void DelayedHookMgrExecute(TimerHandle handler, void *context)
+{
+ UNUSED(context);
+ INIT_LOGI("Executing delayed HookMgrExecute after sleep");
+ HookMgrExecute(GetBootStageHookMgr(), INIT_BOOT_COMPLETE, NULL, NULL);
+ LE_StopTimer(LE_GetDefaultLoop(), handler);
+}
+
+static int ScheduleDelayedHookMgrExecute(void)
+{
+ TimerHandle timer;
+ LE_STATUS status = LE_CreateTimer(LE_GetDefaultLoop(), &timer, DelayedHookMgrExecute, NULL);
+ if (status != LE_SUCCESS) {
+ INIT_LOGE("Failed to create timer for delayed HookMgrExecute");
+ return -1;
+ }
+
+ status = LE_StartTimer(LE_GetDefaultLoop(), timer, SLEPP_TIME, 0);
+ if (status != LE_SUCCESS) {
+ LE_StopTimer(LE_GetDefaultLoop(), timer);
+ INIT_LOGE("Failed to start timer for delayed HookMgrExecute");
+ return -1;
+ }
+ return 0;
+}
+#endif
+
+
static int BootEventParaFireByName(const char *paramName)
{
BOOT_EVENT_PARAM_ITEM *found = NULL;
@@ -352,7 +384,10 @@ static int BootEventParaFireByName(const char *paramName)
ReportSysEvent();
BootCompleteClearAll();
#ifndef STARTUP_INIT_TEST
- HookMgrExecute(GetBootStageHookMgr(), INIT_BOOT_COMPLETE, NULL, NULL);
+ if (ScheduleDelayedHookMgrExecute() != 0) {
+ INIT_LOGE("Failed to schedule delayed HookMgrExecute, executing directly");
+ HookMgrExecute(GetBootStageHookMgr(), INIT_BOOT_COMPLETE, NULL, NULL);
+ }
#endif
RemoveCmdExecutor("bootevent", -1);
return 1;
diff --git a/services/modules/crashhandler/BUILD.gn b/services/modules/crashhandler/BUILD.gn
index 9ce86ba04af727a7f5435154a522b2733f693eff..66f19350dca250eb606dacadd83a900eaf666aa4 100644
--- a/services/modules/crashhandler/BUILD.gn
+++ b/services/modules/crashhandler/BUILD.gn
@@ -30,7 +30,7 @@ ohos_source_set("libcrashhandler") {
external_deps = [
"bounds_checking_function:libsec_shared",
- "libunwind:libunwind",
+ "cJSON:cjson",
]
public_configs += [ "../../../interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
diff --git a/services/modules/crashhandler/crash_handler.c b/services/modules/crashhandler/crash_handler.c
index 6d5d0f4a473b04481a026587573d9a10db22a332..5c2627a02f529c87d6c76b0da4fef2305c04b964 100644
--- a/services/modules/crashhandler/crash_handler.c
+++ b/services/modules/crashhandler/crash_handler.c
@@ -31,14 +31,13 @@
#include
#include
-#include
-
#include "beget_ext.h"
#include "securec.h"
#include "init_cmds.h"
#include "init_log.h"
#include "crash_handler.h"
+#define SLEEP_DURATION 2
static const SignalInfo g_platformSignals[] = {
{ SIGABRT, "SIGABRT" },
{ SIGBUS, "SIGBUS" },
@@ -56,7 +55,7 @@ static void SignalHandler(int sig, siginfo_t *si, void *context)
{
int32_t pid = getpid();
if (pid == 1) {
- sleep(2);
+ sleep(SLEEP_DURATION);
ExecReboot("panic");
} else {
exit(-1);
diff --git a/services/modules/encaps/encaps_static.c b/services/modules/encaps/encaps_static.c
index 7988bc61bd8056fd0b87c17ffa3218fa12a8037d..db5c3f18ec930187cecb082717626412f9edad0e 100644
--- a/services/modules/encaps/encaps_static.c
+++ b/services/modules/encaps/encaps_static.c
@@ -19,47 +19,62 @@
#include "bootstage.h"
#include "init_log.h"
#include "init_module_engine.h"
+#include "init_service.h"
#define SA_MAIN_PATH ("/system/bin/sa_main")
#define OH_ENCAPS_PROC_TYPE_BASE 0x18
+#define OH_ENCAPS_PERMISSION_TYPE_BASE 0x1A
#define OH_ENCAPS_MAGIC 'E'
#define OH_PROC_SYS 3
#define SET_PROC_TYPE_CMD _IOW(OH_ENCAPS_MAGIC, OH_ENCAPS_PROC_TYPE_BASE, uint32_t)
+#define SET_KERNEL_PERM_TYPE_CMD _IOW(OH_ENCAPS_MAGIC, OH_ENCAPS_PERMISSION_TYPE_BASE, char *)
-static void SetEncapsFlag(uint32_t flag)
+static void SetKernelPerm(SERVICE_INFO_CTX *serviceCtx)
{
int fd = 0;
int ret = 0;
+ int procType = OH_PROC_SYS;
fd = open("/dev/encaps", O_RDWR);
if (fd < 0) {
- INIT_LOGI("SetEncapsFlag open failed, maybe this device is not supported");
+ INIT_LOGI("SetKernelPerm open failed, maybe this device is not supported");
return;
}
- ret = ioctl(fd, SET_PROC_TYPE_CMD, &flag);
+ ret = ioctl(fd, SET_PROC_TYPE_CMD, &procType);
if (ret != 0) {
close(fd);
- INIT_LOGE("SetEncapsFlag ioctl failed");
+ INIT_LOGE("SetKernelPerm set flag failed %d", ret);
return;
}
-
+ Service *service = GetServiceByName(serviceCtx->serviceName);
+ if (service == NULL) {
+ close(fd);
+ INIT_LOGE("SetKernelPerm get service failed");
+ return;
+ }
+ if (service->kernelPerms != NULL) {
+ ret = ioctl(fd, SET_KERNEL_PERM_TYPE_CMD, service->kernelPerms);
+ if (ret != 0) {
+ INIT_LOGE("SetKernelPerm set encaps permission failed");
+ }
+ }
close(fd);
}
-static void SetEncapsProcType(SERVICE_INFO_CTX *serviceCtx)
+static void SetKernelPermForSa(SERVICE_INFO_CTX *serviceCtx)
{
if (serviceCtx->reserved == NULL) {
return;
}
if (strncmp(SA_MAIN_PATH, serviceCtx->reserved, strlen(SA_MAIN_PATH)) == 0) {
- SetEncapsFlag(OH_PROC_SYS);
+ SetKernelPerm(serviceCtx);
}
}
MODULE_CONSTRUCTOR(void)
{
- // Add hook to set encaps flag
- InitAddServiceHook(SetEncapsProcType, INIT_SERVICE_SET_PERMS_BEFORE);
+ // Add hook to set encaps
+ InitAddServiceHook(SetKernelPermForSa, INIT_SERVICE_SET_PERMS_BEFORE);
}
diff --git a/services/modules/init_context/BUILD.gn b/services/modules/init_context/BUILD.gn
index 17ad61a8f3a9836641d4489f8b55e87c20bbf0df..74e42f4dec38a44e47130d2602034c4eb958e1a0 100644
--- a/services/modules/init_context/BUILD.gn
+++ b/services/modules/init_context/BUILD.gn
@@ -44,6 +44,7 @@ ohos_shared_library("init_context") {
external_deps += [
"bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
"selinux:libselinux",
]
@@ -67,7 +68,10 @@ ohos_source_set("initcontext_static") {
defines = [ "INIT_SUPPORT_CHIPSET_INIT" ]
public_configs = [ ":initcontext_static_config" ]
public_configs += [ "../../../interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
- external_deps = [ "bounds_checking_function:libsec_shared" ]
+ external_deps = [
+ "bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
+ ]
part_name = "init"
subsystem_name = "startup"
}
diff --git a/services/modules/init_eng/BUILD.gn b/services/modules/init_eng/BUILD.gn
index f07f18e49930c1d28e2d4eff99d64f89df2f4955..9713831b652b1253a0b86d3e3b3b52b44099acdf 100644
--- a/services/modules/init_eng/BUILD.gn
+++ b/services/modules/init_eng/BUILD.gn
@@ -33,8 +33,10 @@ ohos_shared_library("init_eng") {
"${init_innerkits_path}/init_module_engine:libinit_module_engine",
]
- external_deps = [ "bounds_checking_function:libsec_shared" ]
-
+ external_deps = [
+ "bounds_checking_function:libsec_shared",
+ "cJSON:cjson"
+ ]
part_name = "init"
subsystem_name = "startup"
if (target_cpu == "arm64" || target_cpu == "x86_64" ||
@@ -56,4 +58,5 @@ ohos_source_set("libiniteng_static") {
public_configs += [ "../../../interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
part_name = "init"
subsystem_name = "startup"
+ external_deps = [ "cJSON:cjson" ]
}
diff --git a/services/modules/init_hook/param_hook.c b/services/modules/init_hook/param_hook.c
index dc0e8741d454dbc38bd860fc8f4a59838c498b4d..7e74860af4c4d041c78ba7fc8eb1e25495a66c07 100755
--- a/services/modules/init_hook/param_hook.c
+++ b/services/modules/init_hook/param_hook.c
@@ -53,6 +53,7 @@ const ParamCmdInfo *GetServiceStartCtrl(size_t *size)
static const ParamCmdInfo ctrlParam[] = {
{"ohos.ctl.start", "start", "start "},
{"ohos.ctl.stop", "stop", "stop "},
+ {"ohos.ctl.term", "term", "termservice "},
};
*size = ARRAY_LENGTH(ctrlParam);
return ctrlParam;
diff --git a/services/modules/module_update/BUILD.gn b/services/modules/module_update/BUILD.gn
index 3aaf3f01269f8c80b02d5743d41f1f4ec5f3b910..0ba4a2943615224864245a81c0e7df90aadb423e 100644
--- a/services/modules/module_update/BUILD.gn
+++ b/services/modules/module_update/BUILD.gn
@@ -22,7 +22,10 @@ ohos_shared_library("module_update_init") {
}
sources = [ "module_update_init.cpp" ]
deps = [ "${init_innerkits_path}/init_module_engine:libinit_module_engine" ]
- external_deps = [ "bounds_checking_function:libsec_shared" ]
+ external_deps = [
+ "bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
+ ]
relative_install_dir = "init/autorun"
part_name = "init"
subsystem_name = "startup"
diff --git a/services/modules/module_update/module_update_init.cpp b/services/modules/module_update/module_update_init.cpp
index a459fff2715cb9deab49975ece1457061313ccdb..4bc04ffa0c6027f1c78028e1a11ee79ebe7483eb 100644
--- a/services/modules/module_update/module_update_init.cpp
+++ b/services/modules/module_update/module_update_init.cpp
@@ -14,12 +14,19 @@
*/
#include
+#include
#include "bootstage.h"
#include "init_log.h"
#include "init_module_engine.h"
static void HandleModuleUpdate(void)
{
+ if (mount("tmpfs", "/module_update", "tmpfs", MS_NOEXEC | MS_NODEV | MS_NOSUID, "mode=0755") != 0) {
+ INIT_LOGE("mount module_update tmpfs fail, %s", strerror(errno));
+ }
+ if (mount(nullptr, "/module_update", nullptr, MS_SHARED, nullptr) != 0) {
+ INIT_LOGE("mount module_update shared fail, %s", strerror(errno));
+ }
pid_t pid = fork();
if (pid < 0) {
INIT_LOGE("HandleModuleUpdate, fork fail.");
diff --git a/services/modules/reboot/BUILD.gn b/services/modules/reboot/BUILD.gn
index db40e9bc7f7ebb745aa269aeaea9d1ad31808560..06553c849cf780a47df333e394cebaff2e296103 100644
--- a/services/modules/reboot/BUILD.gn
+++ b/services/modules/reboot/BUILD.gn
@@ -29,7 +29,10 @@ ohos_shared_library("rebootmodule") {
"//base/startup/init/services/utils:libinit_utils",
]
- external_deps = [ "bounds_checking_function:libsec_shared" ]
+ external_deps = [
+ "bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
+ ]
if (!defined(ohos_lite)) {
include_dirs += [ "//base/startup/init/services/modules/sysevent" ]
sources +=
@@ -64,6 +67,7 @@ ohos_source_set("libreboot_static") {
"../init_hook",
"//base/startup/init/interfaces/innerkits/include/param",
]
+ external_deps = [ "cJSON:cjson" ]
public_external_deps = [ "bounds_checking_function:libsec_static" ]
public_configs = [ "//base/startup/init/interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
}
diff --git a/services/modules/reboot/reboot.c b/services/modules/reboot/reboot.c
index a578c97be12b526d00b2daf11a047d3ad35af7cd..7410d765e00674dce227472277337e3fd8411310 100644
--- a/services/modules/reboot/reboot.c
+++ b/services/modules/reboot/reboot.c
@@ -185,6 +185,23 @@ static int DoRebootUpdater(int id, const char *name, int argc, const char **argv
return ret;
}
+static int DoRebootPenglai(int id, const char *name, int argc, const char **argv)
+{
+ UNUSED(id);
+ PLUGIN_LOGI("DoRebootPenglai argc %d %s", argc, name);
+ PLUGIN_CHECK(argc >= 1, return -1, "Invalid parameter");
+ PLUGIN_LOGI("DoRebootPenglai argv %s", argv[0]);
+#ifndef OHOS_LITE
+ ReportStartupReboot(argv[0]);
+#endif
+ ParseRebootReason(name, argc, argv);
+ int ret = UpdateMiscMessage(argv[0], "penglai", "penglai:", "boot_penglai");
+ if (ret == 0) {
+ return DoRoot_("reboot", RB_AUTOBOOT);
+ }
+ return ret;
+}
+
PLUGIN_STATIC int DoRebootFlashed(int id, const char *name, int argc, const char **argv)
{
UNUSED(id);
@@ -259,6 +276,7 @@ static void RebootAdpInit(void)
AddRebootCmdExecutor("charge", DoRebootCharge);
AddRebootCmdExecutor("suspend", DoRebootSuspend);
AddRebootCmdExecutor("panic", DoRebootPanic);
+ AddRebootCmdExecutor("penglai", DoRebootPenglai);
(void)AddCmdExecutor("panic", DoRebootPanic);
}
diff --git a/services/modules/seccomp/BUILD.gn b/services/modules/seccomp/BUILD.gn
index d70bbf4e2553d08396c2ac595d98b94187078910..8b61aacb58d841161e12325027b929001cc7492f 100755
--- a/services/modules/seccomp/BUILD.gn
+++ b/services/modules/seccomp/BUILD.gn
@@ -104,6 +104,20 @@ ohos_prebuilt_seccomp("app_atomic_filter") {
install_images = [ "system" ]
}
+ohos_prebuilt_seccomp("app_allow_iouring_filter") {
+ sources = [ "seccomp_policy/app_allow_iouring.seccomp.policy" ]
+
+ filtername = "app_allow_iouring"
+ process_type = "app"
+ uid_is_root = true
+
+ part_name = INIT_PART
+ subsystem_name = "startup"
+
+ install_enable = true
+ install_images = [ "system" ]
+}
+
ohos_prebuilt_seccomp("app_privilege_filter") {
sources = [ "seccomp_policy/app_privilege.seccomp.policy" ]
@@ -173,6 +187,7 @@ ohos_source_set("libseccomp_static") {
external_deps = [
"bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
"config_policy:configpolicy_util",
]
@@ -182,6 +197,7 @@ ohos_source_set("libseccomp_static") {
group("seccomp_filter") {
deps = [
+ ":app_allow_iouring_filter",
":app_atomic_filter",
":app_filter",
":system_filter",
diff --git a/services/modules/seccomp/seccomp_policy/app_allow_iouring.seccomp.policy b/services/modules/seccomp/seccomp_policy/app_allow_iouring.seccomp.policy
new file mode 100644
index 0000000000000000000000000000000000000000..bc09e70771a8242a49bca185ae2cf427e98b5f60
--- /dev/null
+++ b/services/modules/seccomp/seccomp_policy/app_allow_iouring.seccomp.policy
@@ -0,0 +1,335 @@
+# Copyright (c) 2025 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.
+
+# For now, it supports architechture of ['arm', 'arm64', 'riscv64'].
+
+@returnValue
+TRAP
+
+@headFiles
+
+
+
+@priority
+ioctl;all
+futex;all
+
+@allowList
+io_uring_setup;all
+io_uring_enter;all
+io_uring_register;all
+io_setup;all
+io_destroy;all
+io_submit;all
+io_cancel;all
+io_getevents;all
+setxattr;all
+lsetxattr;all
+fsetxattr;all
+getxattr;all
+lgetxattr;all
+fgetxattr;all
+listxattr;all
+llistxattr;all
+flistxattr;all
+removexattr;all
+lremovexattr;all
+fremovexattr;all
+getcwd;all
+eventfd2;all
+epoll_create1;all
+epoll_ctl;all
+epoll_pwait;all
+dup;all
+dup3;all
+fcntl;all
+inotify_init1;all
+inotify_add_watch;all
+inotify_rm_watch;all
+ioctl;all
+ioprio_set;arm64
+ioprio_set;riscv64
+ioprio_get;arm64
+ioprio_get;riscv64
+flock;all
+mknodat;all
+mkdirat;all
+unlinkat;all
+symlinkat;all
+linkat;all
+renameat;arm
+renameat;arm64
+pivot_root;riscv64
+statfs;arm64
+statfs;riscv64
+fstatfs;arm64
+fstatfs;riscv64
+truncate;all
+ftruncate;arm64
+ftruncate;riscv64
+fallocate;all
+faccessat;all
+chdir;all
+fchdir;all
+fchmod;all
+fchmodat;all
+fchownat;all
+fchown;arm64
+fchown;riscv64
+openat;all
+close;all
+pipe2;all
+quotactl;all
+getdents64;all
+lseek;all
+read;all
+write;all
+readv;all
+writev;all
+pread64;all
+pwrite64;all
+preadv;all
+pwritev;all
+sendfile;all
+pselect6;all
+ppoll;all
+signalfd4;all
+vmsplice;all
+splice;all
+tee;all
+readlinkat;all
+newfstatat;arm64
+newfstatat;riscv64
+fstat;arm64
+fstat;riscv64
+sync;all
+fsync;all
+fdatasync;all
+sync_file_range;arm64
+sync_file_range;riscv64
+timerfd_create;all
+timerfd_settime;all
+timerfd_gettime;all
+utimensat;all
+capget;all
+capset;all
+personality;all
+exit;all
+exit_group;all
+waitid;all
+set_tid_address;all
+futex;all
+nanosleep;all
+getitimer;all
+setitimer;all
+timer_create;all
+timer_gettime;all
+timer_getoverrun;all
+timer_settime;all
+timer_delete;all
+clock_gettime;all
+clock_getres;all
+clock_nanosleep;all
+ptrace;all
+sched_setparam;all
+sched_setscheduler;all
+sched_getscheduler;all
+sched_getparam;all
+sched_setaffinity;all
+sched_getaffinity;all
+sched_yield;all
+sched_get_priority_max;all
+sched_get_priority_min;all
+sched_rr_get_interval;all
+restart_syscall;all
+kill;all
+tkill;all
+tgkill;all
+sigaltstack;all
+rt_sigsuspend;all
+rt_sigaction;all
+rt_sigprocmask;all
+rt_sigpending;all
+rt_sigtimedwait;all
+rt_sigqueueinfo;all
+rt_sigreturn;all
+setpriority;all
+getpriority;all
+setresuid;arm64
+setresuid;riscv64
+getresuid;arm64
+getresuid;riscv64
+getresgid;arm64
+getresgid;riscv64
+times;all
+setpgid;all
+getpgid;all
+getsid;all
+setsid;all
+getgroups;arm64
+getgroups;riscv64
+uname;all
+getrlimit;arm64
+getrlimit;riscv64
+setrlimit;all
+getrusage;all
+umask;all
+prctl;all
+getcpu;all
+gettimeofday;all
+getpid;all
+getppid;all
+getuid;all
+geteuid;arm64
+geteuid;riscv64
+getgid;arm64
+getgid;riscv64
+getegid;arm64
+getegid;riscv64
+gettid;all
+sysinfo;all
+socket;all
+socketpair;all
+bind;all
+listen;all
+accept;all
+connect;all
+getsockname;all
+getpeername;all
+sendto;all
+recvfrom;all
+setsockopt;all
+getsockopt;all
+shutdown;all
+sendmsg;all
+recvmsg;all
+readahead;all
+brk;all
+munmap;all
+mremap;all
+execve;all
+mmap;arm64
+mmap;riscv64
+fadvise64;arm64
+fadvise64;riscv64
+mprotect;all
+msync;all
+mlock;all
+munlock;all
+mlockall;all
+munlockall;all
+mincore;all
+madvise;all
+rt_tgsigqueueinfo;all
+perf_event_open;all
+accept4;all
+recvmmsg;all
+wait4;all
+prlimit64;all
+syncfs;all
+sendmmsg;all
+process_vm_readv;all
+process_vm_writev;all
+sched_setattr;all
+sched_getattr;all
+renameat2;all
+seccomp;all
+getrandom;all
+memfd_create;all
+execveat;all
+userfaultfd;all
+membarrier;all
+mlock2;all
+copy_file_range;all
+preadv2;all
+pwritev2;all
+statx;all
+pidfd_send_signal;all
+pidfd_open;all
+pidfd_getfd;all
+faccessat2;all
+process_madvise;all
+set_robust_list;all
+fork;arm
+open;arm
+creat;arm
+link;arm
+unlink;arm
+chmod;arm
+access;arm
+rename;arm
+mkdir;arm
+rmdir;arm
+pipe;arm
+dup2;arm
+sigaction;arm
+symlink;arm
+readlink;arm
+sigreturn;arm
+_llseek;arm
+getdents;arm
+_newselect;arm
+poll;arm
+vfork;arm
+ugetrlimit;arm
+mmap2;arm
+truncate64;arm
+ftruncate64;arm
+stat64;arm
+lstat64;arm
+fstat64;arm
+lchown32;arm
+getuid32;arm
+getgid32;arm
+geteuid32;arm
+getegid32;arm
+getgroups32;arm
+fchown32;arm
+setresuid32;arm
+getresuid32;arm
+getresgid32;arm
+chown32;arm
+fcntl64;arm
+sendfile64;arm
+epoll_create;arm
+epoll_wait;arm
+remap_file_pages;arm
+statfs64;arm
+fstatfs64;arm
+fadvise64_64;arm
+inotify_init;arm
+fstatat64;arm
+sync_file_range2;arm
+eventfd;arm
+clock_gettime64;arm
+clock_settime64;arm
+clock_adjtime64;arm
+clock_getres_time64;arm
+clock_nanosleep_time64;arm
+timer_gettime64;arm
+timer_settime64;arm
+timerfd_gettime64;arm
+timerfd_settime64;arm
+utimensat_time64;arm
+pselect6_time64;arm
+ppoll_time64;arm
+recvmmsg_time64;arm
+semtimedop_time64;arm
+rt_sigtimedwait_time64;arm
+futex_time64;arm
+sched_rr_get_interval_time64;arm
+cacheflush;arm
+set_tls;arm
+
+@allowListWithArgs
+clone: if (arg0 & (CLONE_NEWNS | CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWCGROUP | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER)) == 0 ; return ALLOW; else return TRAP;all
diff --git a/services/modules/seccomp/seccomp_policy/app_custom.seccomp.policy b/services/modules/seccomp/seccomp_policy/app_custom.seccomp.policy
index e719262efddbf1845a48e32346d74547717995d5..8d130027d73d7291716cec3d9c0f34f223b87c09 100644
--- a/services/modules/seccomp/seccomp_policy/app_custom.seccomp.policy
+++ b/services/modules/seccomp/seccomp_policy/app_custom.seccomp.policy
@@ -257,6 +257,7 @@ pidfd_getfd;all
faccessat2;all
process_madvise;all
set_robust_list;all
+mbind;all
fork;arm
open;arm
creat;arm
@@ -327,6 +328,21 @@ futex_time64;arm
sched_rr_get_interval_time64;arm
cacheflush;arm
set_tls;arm
+setuid;arm64
+setuid32;arm
+setgid;arm64
+setgid32;arm
+setgroups;arm64
+setgroups32;arm
+setresgid;arm64
+setresgid32;arm
+settimeofday;all
+sethostname;all
+syslog;all
+io_uring_setup;all
+shmctl;all
+msgctl;all
+semctl;all
@allowListWithArgs
clone: if (arg0 & (CLONE_NEWNS | CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWCGROUP | CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER)) == 0 ; return ALLOW; else return TRAP;all
diff --git a/services/modules/seccomp/seccomp_policy/privileged_process.seccomp.policy b/services/modules/seccomp/seccomp_policy/privileged_process.seccomp.policy
index 76093ee2093f4532d438ed80192b529b46e34805..0c072c3d8d76933bbbb886ea5761a6dfdea263c1 100644
--- a/services/modules/seccomp/seccomp_policy/privileged_process.seccomp.policy
+++ b/services/modules/seccomp/seccomp_policy/privileged_process.seccomp.policy
@@ -12,3 +12,19 @@
# limitations under the License.
# For now, it supports architechture of ['arm', 'arm64', 'riscv64'].
+
+@privilegedProcessName
+app_custom
+
+@allowBlockList
+setuid;arm64
+setuid32;arm
+setgid;arm64
+setgid32;arm
+setgroups;arm64
+setgroups32;arm
+setresgid;arm64
+setresgid32;arm
+settimeofday;all
+sethostname;all
+syslog;all
diff --git a/services/modules/selinux/BUILD.gn b/services/modules/selinux/BUILD.gn
index 235ce5bc85ecc3e4eb36b30144f2488de65e42f5..788aa24a32f1ce88eb98c6a10ed832954b01348a 100755
--- a/services/modules/selinux/BUILD.gn
+++ b/services/modules/selinux/BUILD.gn
@@ -28,6 +28,7 @@ ohos_shared_library("selinuxadp") {
external_deps = [
"bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
"selinux:libselinux",
"selinux_adapter:libload_policy",
"selinux_adapter:librestorecon",
@@ -60,6 +61,7 @@ ohos_source_set("libselinuxadp_static") {
"../init_hook",
"//base/startup/init/interfaces/innerkits/include/param",
]
+ external_deps = [ "cJSON:cjson" ]
public_external_deps = [
"selinux:libselinux",
"selinux_adapter:libselinux_parameter_static",
diff --git a/services/modules/sysevent/BUILD.gn b/services/modules/sysevent/BUILD.gn
index 3b1a1af884d24268199f41a170b8f3e5514348c2..5832bb70c1634779cf1801d2a1cbcf50f31a4ac9 100644
--- a/services/modules/sysevent/BUILD.gn
+++ b/services/modules/sysevent/BUILD.gn
@@ -31,6 +31,7 @@ ohos_shared_library("eventmodule") {
external_deps = [
"bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
"hisysevent:libhisysevent",
]
diff --git a/services/modules/sysevent/startup_time_event.c b/services/modules/sysevent/startup_time_event.c
index ca1e32c3871edb4d12b15d8f15a9831ce304e64f..b0050071561ecb1d2d1218fd186627872b84833b 100644
--- a/services/modules/sysevent/startup_time_event.c
+++ b/services/modules/sysevent/startup_time_event.c
@@ -110,6 +110,18 @@ PLUGIN_STATIC void ReportBootEventComplete(ListNode *events)
}
InsertBootTimeParam(buffer, "kernel");
InsertBootTimeParam(buffer, "init");
+ char fdtabTime[MAX_BUFFER_FOR_EVENT] = {0};
+ char fdtabBuffer[PARAM_VALUE_LEN_MAX] = {0};
+ uint32_t fstabLen = PARAM_VALUE_LEN_MAX;
+ ret = SystemReadParam("boot.time.fstab", fdtabBuffer, &fstabLen);
+ if (ret == 0) {
+ ret = sprintf_s(fdtabTime, MAX_BUFFER_FOR_EVENT, ";fstab,0,%s", fdtabBuffer);
+ PLUGIN_CHECK((ret > 0) && (ret < MAX_BUFFER_FOR_EVENT), return, "Failed to sprintf_s");
+ ret = strcat_s(buffer, MAX_BUFFER_FOR_EVENT + PARAM_VALUE_LEN_MAX, fdtabTime);
+ PLUGIN_CHECK(ret == 0, return, "Failed to format boot time");
+ } else {
+ PLUGIN_LOGE("Failed to read boot.time.fstab");
+ }
StartupTimeEvent startupTime = {};
startupTime.event.type = STARTUP_TIME;
diff --git a/services/modules/trace/BUILD.gn b/services/modules/trace/BUILD.gn
index 35b5d66558d6740526c8731b0740f88b11274926..676d7d2e5e8fa567abde0bfa806d5c44b972b00c 100644
--- a/services/modules/trace/BUILD.gn
+++ b/services/modules/trace/BUILD.gn
@@ -55,4 +55,5 @@ ohos_source_set("inittrace_static") {
sources = [ "init_trace_static.c" ]
public_configs = [ ":inittrace_static_config" ]
public_configs += [ "//base/startup/init/interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
+ external_deps = [ "cJSON:cjson" ]
}
diff --git a/services/modules/udid/BUILD.gn b/services/modules/udid/BUILD.gn
index 6c7dbfb7829e8a46a61c8e0abdd2195d79cceb71..445d73dffcf891b03c997b804598f7b69b14a8b6 100644
--- a/services/modules/udid/BUILD.gn
+++ b/services/modules/udid/BUILD.gn
@@ -26,6 +26,12 @@ comm_include = [
if (defined(ohos_lite)) {
static_library("libudidcomm") {
+ if (board_toolchain_type == "clang") {
+ cflags = [
+ "-Wno-error=macro-redefined",
+ "-Wno-error=unknown-warning-option",
+ ]
+ }
defines = [
"_GNU_SOURCE",
"OHOS_LITE",
@@ -84,6 +90,7 @@ if (defined(ohos_lite)) {
external_deps = [
"bounds_checking_function:libsec_shared",
+ "cJSON:cjson",
"mbedtls:mbedtls_shared",
]
@@ -113,6 +120,7 @@ if (defined(ohos_lite)) {
public_configs += [ "../../../interfaces/innerkits/init_module_engine:init_module_engine_exported_config" ]
part_name = "init"
subsystem_name = "startup"
+ external_deps = [ "cJSON:cjson" ]
}
# for begetutil
diff --git a/services/param/adapter/param_persistadp.c b/services/param/adapter/param_persistadp.c
index 33fd9c58b9318c2053926a62e9eea155dab3ecfa..7c6fd149cbec40b829ebebdd21b0c5f4cc28743e 100644
--- a/services/param/adapter/param_persistadp.c
+++ b/services/param/adapter/param_persistadp.c
@@ -275,14 +275,15 @@ static int BatchSavePersistParam(PERSIST_SAVE_HANDLE handle[], const char *name,
static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle[])
{
- int ret = 0;
if (InUpdaterMode() == 1) {
FILE *fp = (FILE *)handle[0];
(void)fflush(fp);
(void)fsync(fileno(fp));
(void)fclose(fp);
unlink("/param/persist_parameters");
- ret = rename("/param/tmp_persist_parameters", "/param/persist_parameters");
+ if (rename("/param/tmp_persist_parameters", "/param/persist_parameters")) {
+ PARAM_LOGW("rename file persist_parameters fail error %d", errno);
+ }
ParamMutexPost(&g_saveMutex);
return;
}
@@ -302,7 +303,9 @@ static void BatchSavePersistParamEnd(PERSIST_SAVE_HANDLE handle[])
(void)fclose(fp);
}
unlink(path[i]);
- ret = rename(tmpPath[i], path[i]);
+ if (rename(tmpPath[i], path[i])) {
+ PARAM_LOGW("rename file %s fail error %d", path[i], errno);
+ }
}
ParamMutexPost(&g_saveMutex);
}
diff --git a/services/param/adapter/param_selinux.c b/services/param/adapter/param_selinux.c
index fdab03645e622d4f56bf4ef43bf38af8dbea8fb0..def449292f4de6286be72f856f1b047f533204f5 100644
--- a/services/param/adapter/param_selinux.c
+++ b/services/param/adapter/param_selinux.c
@@ -34,6 +34,7 @@
#endif
typedef int (*SelinuxSetParamCheck)(const char *paraName, const char *destContext, const SrcInfo *info);
+#if !(defined STARTUP_INIT_TEST || defined LOCAL_TEST)
static int InitSelinuxOpsForInit(SelinuxSpace *selinuxSpace)
{
if (selinuxSpace->selinuxHandle == NULL) {
@@ -80,6 +81,7 @@ static int InitSelinuxOpsForInit(SelinuxSpace *selinuxSpace)
}
return ret;
}
+#endif
static int InitLocalSecurityLabel(ParamSecurityLabel *security, int isInit)
{
diff --git a/services/param/base/param_base.c b/services/param/base/param_base.c
index 9f5e8790a6a6f1b24a70ba4f53762c3b7740f2e1..c3399107eaa110dc611f7d40bfb773243bc2bc4a 100644
--- a/services/param/base/param_base.c
+++ b/services/param/base/param_base.c
@@ -353,7 +353,7 @@ INIT_LOCAL_API int OpenWorkSpace(uint32_t index, int readOnly)
if (workSpace->area == NULL) {
ret = InitWorkSpace(workSpace, readOnly, workSpace->spaceSize);
if (ret != 0) {
- PARAM_LOGE("Forbid to open workspace for %s error %d", workSpace->fileName, errno);
+ PARAM_LOGV("open WS %s err %d", workSpace->fileName, errno);
}
#ifndef PARAM_SUPPORT_SELINUX
}
@@ -371,7 +371,7 @@ INIT_LOCAL_API int OpenWorkSpace(uint32_t index, int readOnly)
ret = 0;
} else {
ret = -1;
- PARAM_LOGE("Forbid to open workspace for %s error %d", workSpace->fileName, errno);
+ PARAM_LOGV("open WS %s err %d", workSpace->fileName, errno);
rwSpaceLock &= ~WORKSPACE_STATUS_VALID;
}
}
@@ -526,7 +526,7 @@ STATIC_INLINE int SelinuxCheckParamPermission(const ParamLabelIndex *labelIndex,
}
if (ret != 0) {
ret = SELINUX_RESULT_FORBIDED;
- PARAM_LOGE("Selinux check name %s in %s info [%d %d %d] failed!",
+ PARAM_LOGE("Selinux check name %s in %s [%d %d %d] failed",
name, GetSelinuxContent(name), srcLabel->cred.pid, srcLabel->cred.uid, srcLabel->cred.gid);
}
return ret;
diff --git a/services/param/base/param_base.h b/services/param/base/param_base.h
index aa95bba819f06f2152476861e003808dbc9b3035..50b46cbb86868953e2c9c544406e7e15fb379363 100644
--- a/services/param/base/param_base.h
+++ b/services/param/base/param_base.h
@@ -31,6 +31,7 @@ extern "C" {
#define WORKSPACE_STATUS_IN_PROCESS 0x01
#define WORKSPACE_STATUS_VALID 0x02
+#define READ_COMMIT_ID_LOOP_RETRY_TIME_WARNING 50
#ifndef PARAM_BASE
#define PARAM_SPRINTF(buffer, buffSize, format, ...) \
@@ -50,7 +51,9 @@ static inline uint32_t ReadCommitId(ParamNode *entry)
while (commitId & PARAM_FLAGS_MODIFY) {
futex_wait(&entry->commitId, commitId);
commitId = ATOMIC_LOAD_EXPLICIT(&entry->commitId, MEMORY_ORDER_ACQUIRE);
- retryTimes++;
+ if (retryTimes++ % READ_COMMIT_ID_LOOP_RETRY_TIME_WARNING == 0) {
+ break;
+ }
}
return commitId & PARAM_FLAGS_COMMITID;
}
diff --git a/services/param/include/param_osadp.h b/services/param/include/param_osadp.h
index 190ee44503b1c79b40ad7a110f5ba7a759f9e6c9..e636d7b772c32c560da7ee816a612d85020581f4 100755
--- a/services/param/include/param_osadp.h
+++ b/services/param/include/param_osadp.h
@@ -65,7 +65,7 @@ extern "C" {
#ifdef STARTUP_INIT_TEST
#define DAC_DEFAULT_MODE 0777
#define PARAM_WORKSPACE_DEF (1024 * 80)
-#define PARAM_WORKSPACE_MAX (1024 * 100)
+#define PARAM_WORKSPACE_MAX (1024 * 1024 * 10)
#define PARAM_WORKSPACE_SMALL PARAM_WORKSPACE_DEF
#else
diff --git a/services/param/linux/param_osadp.c b/services/param/linux/param_osadp.c
index b633f7080cda777ae4be3289228dfeb584afef92..0cb1077c3de476df772bcbfeae7bbdbf940281e0 100644
--- a/services/param/linux/param_osadp.c
+++ b/services/param/linux/param_osadp.c
@@ -92,7 +92,7 @@ INIT_LOCAL_API void *GetSharedMem(const char *fileName, MemHandle *handle, uint3
}
void *areaAddr = (void *)mmap(NULL, spaceSize, prot, MAP_SHARED, fd, 0);
PARAM_CHECK(areaAddr != MAP_FAILED && areaAddr != NULL, close(fd);
- return NULL, "Failed to map memory error %d fileName %s ", errno, fileName);
+ return NULL, "mmap err %d file %s ", errno, fileName);
close(fd);
return areaAddr;
}
diff --git a/services/param/linux/param_request.c b/services/param/linux/param_request.c
index d3f61c122b28e2400f19b9d874ca63c927a312e2..97f834a89bf50bd35b5cb15a1526a903317e55b3 100644
--- a/services/param/linux/param_request.c
+++ b/services/param/linux/param_request.c
@@ -205,7 +205,7 @@ static int SystemSetParameter_(const char *name, const char *value, int timeout)
break;
}
}
- PARAM_LOGI("SystemSetParameter name %s msgid:%d ret: %d ", name, request->id.msgId, ret);
+ PARAM_LOGI("SystemSetParameter name %s id:%d ret:%d ", name, request->id.msgId, ret);
pthread_mutex_unlock(&g_clientMutex);
free(request);
return ret;
@@ -291,7 +291,7 @@ int SystemWaitParameter(const char *name, const char *value, int32_t timeout)
ret = StartRequest(fd, request, timeout);
close(fd);
free(request);
- PARAM_LOGI("SystemWaitParameter %s value %s result %d ", name, value, ret);
+ PARAM_LOGI("SystemWaitParameter %s v %s ret %d", name, value, ret);
BEGET_CHECK_ONLY_ELOG(ret == 0, "SystemWaitParameter failed! name is:%s, the errNum is:%d", name, ret);
return ret;
}
@@ -323,7 +323,7 @@ void ResetParamSecurityLabel(void)
paramSpace->flags |= WORKSPACE_FLAGS_NEED_ACCESS;
#endif
#endif
- PARAM_LOGI("ResetParamSecurityLabel g_clientFd: %d ", g_clientFd);
+ PARAM_LOGI("ResetParamSecurityLabel Fd:%d ", g_clientFd);
pthread_mutex_lock(&g_clientMutex);
if (g_clientFd != INVALID_SOCKET) {
close(g_clientFd);
diff --git a/services/param/linux/param_service.c b/services/param/linux/param_service.c
index 8576ed9c656424d05a0124045229f7948edeb3b6..9332af772e72c2c43a30d465faf82b8715e0889c 100755
--- a/services/param/linux/param_service.c
+++ b/services/param/linux/param_service.c
@@ -158,6 +158,22 @@ static int SystemSetParam(const char *name, const char *value, const ParamSecuri
return ret;
}
+static int SystemUpdateConstParamter(const char *name, const char *value, const ParamSecurityLabel *srcLabel)
+{
+ PARAM_LOGV("SystemUpdateConstParam name %s value: %s", name, value);
+ uint32_t ctrlService = 0;
+ int ret = CheckParameterSet(name, value, srcLabel, (int *)&ctrlService);
+ PARAM_CHECK(ret == 0, return ret, "Forbid to set parameter %s", name);
+ PARAM_CHECK(IS_READY_ONLY(name), return PARAM_CODE_INVALID_NAME, "only update read only param: %s", name);
+ if ((ctrlService & PARAM_CTRL_SERVICE) != PARAM_CTRL_SERVICE) { // ctrl param
+ uint32_t dataIndex = 0;
+ ret = WriteParam(name, value, &dataIndex, LOAD_PARAM_UPDATE_CONST);
+ PARAM_CHECK(ret == 0, return ret, "Failed to update const param %d name %s %s", ret, name, value);
+ CheckAndSendTrigger(dataIndex, name, value);
+ }
+ return ret;
+}
+
static int HandleParamSet(const ParamTaskPtr worker, const ParamMessage *msg)
{
uint32_t offset = 0;
@@ -300,7 +316,7 @@ static int HandleParamWatcherAdd(const ParamTaskPtr worker, const ParamMessage *
PARAM_LOGE("Failed to add trigger for %s", msg->key);
return SendResponseMsg(worker, msg, -1);
}
- PARAM_LOGV("HandleParamWatcherAdd name %s watcher: %d", msg->key, msg->id.watcherId);
+ PARAM_LOGI("HandleParamWatcherAdd name %s watcher: %d", msg->key, msg->id.watcherId);
return SendResponseMsg(worker, msg, 0);
}
@@ -477,6 +493,11 @@ int SystemWriteParam(const char *name, const char *value)
return SystemSetParam(name, value, GetParamSecurityLabel());
}
+int SystemUpdateConstParam(const char *name, const char *value)
+{
+ return SystemUpdateConstParamter(name, value, GetParamSecurityLabel());
+}
+
#ifdef STARTUP_INIT_TEST
ParamService *GetParamService()
{
diff --git a/services/param/liteos/BUILD.gn b/services/param/liteos/BUILD.gn
index bffab2ad21caa1e808d6b2ed6bbef59f662c6751..ee7aaf6ac70b4daf844940c83a8ac5403083018e 100644
--- a/services/param/liteos/BUILD.gn
+++ b/services/param/liteos/BUILD.gn
@@ -109,6 +109,13 @@ static_library("param_init_lite") {
}
static_library("param_client_lite") {
+ if (board_toolchain_type == "clang") {
+ cflags = [
+ "-Wno-error=unused-but-set-variable",
+ "-Wno-error=macro-redefined",
+ "-Wno-error=unused-function",
+ ]
+ }
sources = base_sources
include_dirs = param_include_dirs
defines = param_build_defines
diff --git a/services/param/liteos/param_hal.c b/services/param/liteos/param_hal.c
index 6f54489ffad6fefdacc124f15b7373f81e06dc08..3d2349c5b7313d94afe14d0a675a757032f736a2 100644
--- a/services/param/liteos/param_hal.c
+++ b/services/param/liteos/param_hal.c
@@ -110,10 +110,29 @@ static void ParamFileSync(int ft)
static int LoadOnePersistParam_(const uint32_t *context, const char *name, const char *value)
{
- (void)context;
+ UNUSED(context);
+ PARAM_CHECK(name != NULL, return -1, "param is invalid");
+ PARAM_CHECK(value != NULL, return -1, "value is invalid");
+ if (strncmp(name, "persist", strlen("persist")) != 0) {
+ PARAM_LOGE("%s is not persist param, do not load", name);
+ return 0;
+ }
uint32_t dataIndex = 0;
- int ret = WriteParam(name, value, &dataIndex, 0);
- PARAM_CHECK(ret == 0, return ret, "Failed to write param %d name:%s %s", ret, name, value);
+ unsigned int mode = 0;
+ int result = 0;
+ char persetValue[PARAM_VALUE_LEN_MAX] = {0};
+ uint32_t len = PARAM_VALUE_LEN_MAX;
+ int ret = SystemReadParam(name, persetValue, &len);
+ if (ret != 0) {
+ mode |= LOAD_PARAM_PERSIST;
+ return WriteParam(name, value, &dataIndex, mode);
+ }
+
+ if (strcmp(persetValue, value) != 0) {
+ PARAM_LOGI("%s value is different, preset value is:%s, persist value is:%s", name, persetValue, value);
+ mode |= LOAD_PARAM_PERSIST;
+ return WriteParam(name, value, &dataIndex, mode);
+ }
return 0;
}
diff --git a/services/param/liteos/param_persistadp.c b/services/param/liteos/param_persistadp.c
index aa1897b5f6affeb4eaccb7375f769b44c8d5c30b..d1f3d8b146eec48088652941327754259185f067 100644
--- a/services/param/liteos/param_persistadp.c
+++ b/services/param/liteos/param_persistadp.c
@@ -28,8 +28,27 @@ static ParamMutex g_saveMutex = {};
static int LoadOnePersistParam_(const uint32_t *context, const char *name, const char *value)
{
UNUSED(context);
+ if (strncmp(name, "persist", strlen("persist")) != 0) {
+ PARAM_LOGE("%s is not persist param, do not load", name);
+ return 0;
+ }
uint32_t dataIndex = 0;
- return WriteParam(name, value, &dataIndex, 0);
+ unsigned int mode = 0;
+ int result = 0;
+ char persetValue[PARAM_VALUE_LEN_MAX] = {0};
+ uint32_t len = PARAM_VALUE_LEN_MAX;
+ int ret = SystemReadParam(name, persetValue, &len);
+ if (ret != 0) {
+ mode |= LOAD_PARAM_PERSIST;
+ return WriteParam(name, value, &dataIndex, mode);
+ }
+
+ if ((strcmp(persetValue, value) != 0)) {
+ PARAM_LOGI("%s value is different, preset value is:%s, persist value is:%s", name, persetValue, value);
+ mode |= LOAD_PARAM_PERSIST;
+ return WriteParam(name, value, &dataIndex, mode);
+ }
+ return 0;
}
static void LoadPersistParam_(const char *fileName, char *buffer, uint32_t buffSize)
diff --git a/services/param/manager/param_manager.c b/services/param/manager/param_manager.c
index 2af4302cfe5ff7c0e1fc01200038a96f40d182cc..31ed67ea0816a16a73b14a2d586a45d85159b98f 100644
--- a/services/param/manager/param_manager.c
+++ b/services/param/manager/param_manager.c
@@ -456,7 +456,12 @@ static int UpdateParam(const WorkSpace *workSpace, uint32_t *dataIndex, const ch
uint32_t valueLen = strlen(value);
uint32_t commitId = ATOMIC_LOAD_EXPLICIT(&entry->commitId, MEMORY_ORDER_RELAXED);
ATOMIC_STORE_EXPLICIT(&entry->commitId, commitId | PARAM_FLAGS_MODIFY, MEMORY_ORDER_RELAXED);
- if (entry->valueLength < PARAM_VALUE_LEN_MAX && valueLen < PARAM_VALUE_LEN_MAX) {
+ if ((((uint32_t)mode & LOAD_PARAM_UPDATE_CONST) == LOAD_PARAM_UPDATE_CONST) &&
+ (entry->valueLength < PARAM_CONST_VALUE_LEN_MAX && valueLen < PARAM_CONST_VALUE_LEN_MAX)) {
+ int ret = PARAM_MEMCPY(entry->data + entry->keyLength + 1, PARAM_CONST_VALUE_LEN_MAX, value, valueLen + 1);
+ PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_VALUE, "Failed to copy value");
+ entry->valueLength = valueLen;
+ } else if (entry->valueLength < PARAM_VALUE_LEN_MAX && valueLen < PARAM_VALUE_LEN_MAX) {
int ret = PARAM_MEMCPY(entry->data + entry->keyLength + 1, PARAM_VALUE_LEN_MAX, value, valueLen + 1);
PARAM_CHECK(ret == 0, return PARAM_CODE_INVALID_VALUE, "Failed to copy value");
entry->valueLength = valueLen;
@@ -508,13 +513,16 @@ INIT_LOCAL_API int WriteParam(const char *name, const char *value, uint32_t *dat
ParamNode *entry = (ParamNode *)GetTrieNode(workSpace, node->dataIndex);
PARAM_CHECK(entry != NULL, return PARAM_CODE_REACHED_MAX,
"Failed to update param value %s %u", name, node->dataIndex);
- // use save type to check value
- ret = CheckParamValue(node, name, value, entry->type);
+ ret = CheckParamValue((mode & LOAD_PARAM_UPDATE_CONST) == LOAD_PARAM_UPDATE_CONST ? NULL : node,
+ name, value, entry->type);
PARAM_CHECK(ret == 0, return ret, "Invalid param value param: %s=%s", name, value);
PARAMSPACE_AREA_RW_LOCK(workSpace);
ret = UpdateParam(workSpace, &node->dataIndex, name, value, mode);
PARAMSPACE_AREA_RW_UNLOCK(workSpace);
} else {
+ if ((mode & LOAD_PARAM_UPDATE_CONST) == LOAD_PARAM_UPDATE_CONST) {
+ return PARAM_CODE_INVALID_NAME;
+ }
uint8_t type = GetParamValueType(name);
ret = CheckParamValue(node, name, value, type);
PARAM_CHECK(ret == 0, return ret, "Invalid param value param: %s=%s", name, value);
@@ -603,7 +611,7 @@ INIT_LOCAL_API int CheckParamValue(const ParamTrieNode *node, const char *name,
}
} else {
PARAM_CHECK(strlen(value) < GetParamMaxLen(paramType),
- return PARAM_CODE_INVALID_VALUE, "Illegal param value %s length", value);
+ return PARAM_CODE_INVALID_VALUE, "Illegal param length %zu", strlen(value));
}
PARAM_CHECK(strstr(value, "\n") == NULL,
return PARAM_CODE_INVALID_VALUE, "Illegal param value %s for \\n", value);
@@ -687,7 +695,7 @@ static int CheckParamPermission_(WorkSpace **workspace, ParamTrieNode **node,
int ret = paramSpace->checkParamPermission(&labelIndex, srcLabel, name, mode);
PARAM_CHECK(ret == 0, return ret,
- "Forbid to access %s label %u %u", name, labelIndex.dacLabelIndex, labelIndex.selinuxLabelIndex);
+ "deny access %s label %u %u", name, labelIndex.dacLabelIndex, labelIndex.selinuxLabelIndex);
*workspace = labelIndex.workspace;
return ret;
}
@@ -738,7 +746,7 @@ int SystemReadParam(const char *name, char *value, uint32_t *len)
WorkSpace *workspace = NULL;
int ret = CheckParamPermission_(&workspace, &node, GetParamSecurityLabel(), name, DAC_READ);
if (ret != 0) {
- PARAM_LOGE("SystemReadParam failed! name is:%s, errNum is:%d!", name, ret);
+ PARAM_LOGE("SystemReadParam failed! name is:%s, err:%d!", name, ret);
return ret;
}
#ifdef PARAM_SUPPORT_SELINUX
diff --git a/services/param/watcher/agent/watcher_manager_kits.cpp b/services/param/watcher/agent/watcher_manager_kits.cpp
index cd678307665423cbc1a675260944feaef7e1ce84..d6acf5b55f492743944deccc22e14f08428b9048 100644
--- a/services/param/watcher/agent/watcher_manager_kits.cpp
+++ b/services/param/watcher/agent/watcher_manager_kits.cpp
@@ -36,26 +36,31 @@ WatcherManagerKits::~WatcherManagerKits(void) {}
void WatcherManagerKits::ResetService(const wptr &remote)
{
- WATCHER_LOGI("Remote is dead, reset service instance");
- std::lock_guard lock(lock_);
- if (watcherManager_ != nullptr) {
- sptr object = watcherManager_->AsObject();
- if ((object != nullptr) && (remote == object)) {
- object->RemoveDeathRecipient(deathRecipient_);
- watcherManager_ = nullptr;
- remoteWatcherId_ = 0;
- remoteWatcher_ = nullptr;
- if (threadForReWatch_ != nullptr) {
- WATCHER_LOGI("Thead exist, delete thread");
- stop_ = true;
- threadForReWatch_->join();
- delete threadForReWatch_;
+ {
+ WATCHER_LOGI("Remote is dead, reset service instance");
+ std::lock_guard lock(lock_);
+ if (watcherManager_ != nullptr) {
+ sptr object = watcherManager_->AsObject();
+ if ((object != nullptr) && (remote == object)) {
+ object->RemoveDeathRecipient(deathRecipient_);
+ watcherManager_ = nullptr;
+ remoteWatcherId_ = 0;
+ remoteWatcher_ = nullptr;
}
- stop_ = false;
- threadForReWatch_ = new (std::nothrow)std::thread([this] {this->ReAddWatcher();});
- WATCHER_CHECK(threadForReWatch_ != nullptr, return, "Failed to create thread");
}
}
+ {
+ std::lock_guard lock(threadlock_);
+ if (threadForReWatch_ != nullptr) {
+ WATCHER_LOGI("Thead exist, delete thread");
+ stop_ = true;
+ threadForReWatch_->join();
+ delete threadForReWatch_;
+ }
+ stop_ = false;
+ threadForReWatch_ = new (std::nothrow)std::thread([this] {this->ReAddWatcher();});
+ WATCHER_CHECK(threadForReWatch_ != nullptr, return, "Failed to create thread");
+ }
}
sptr WatcherManagerKits::GetService(void)
diff --git a/services/param/watcher/agent/watcher_manager_kits.h b/services/param/watcher/agent/watcher_manager_kits.h
index 48439f0e471d7bb149cff3e2abe948e10d1ff6e8..6140a6c23b3fd715c0db3b1babe6796fff7c4c87 100644
--- a/services/param/watcher/agent/watcher_manager_kits.h
+++ b/services/param/watcher/agent/watcher_manager_kits.h
@@ -113,6 +113,7 @@ private:
void ResetService(const wptr &remote);
sptr GetService(void);
std::mutex lock_;
+ std::mutex threadlock_;
sptr watcherManager_ {};
sptr deathRecipient_ {};
diff --git a/services/param/watcher/proxy/watcher_manager.cpp b/services/param/watcher/proxy/watcher_manager.cpp
index c14f6cee03f192fb558c5777942cbbe3fd0e6834..dbddbd8ba4dba681c5cccb8f04df78078e78023d 100644
--- a/services/param/watcher/proxy/watcher_manager.cpp
+++ b/services/param/watcher/proxy/watcher_manager.cpp
@@ -117,7 +117,8 @@ int32_t WatcherManager::CheckAppWatchPermission(const std::string &keyPrefix)
"accessibility.config.ready",
"sys.hiview.chr.fluchcache",
"web.render.dump",
- "web.debug.trace"
+ "web.debug.trace",
+ "sys.graphic.openTestModeTrace"
};
if (std::find(whitelist.begin(), whitelist.end(), keyPrefix) != whitelist.end()) {
@@ -153,6 +154,9 @@ int32_t WatcherManager::AddWatcher(const std::string &keyPrefix, uint32_t remote
if (newGroup) {
StartLoop();
SendMessage(group, MSG_ADD_WATCHER);
+ } else if (groupRealMap_.find(keyPrefix) == groupRealMap_.end()) {
+ SendMessage(group, MSG_ADD_WATCHER);
+ WATCHER_LOGI("Add watcher %s groupId %u again", keyPrefix.c_str(), group->GetGroupId());
}
}
SendLocalChange(keyPrefix, remoteWatcherId);
@@ -235,7 +239,10 @@ void WatcherGroup::ProcessParameterChange(
if (remoteWatcher == nullptr) {
return;
}
- WATCHER_LOGI("ProcessParameterChange key '%s' pid: %d", GetKeyPrefix().c_str(), remoteWatcher->GetAgentId());
+ if (strcmp("startup.service.ctl.*", GetKeyPrefix().c_str())!= 0) {
+ WATCHER_LOGI("ProcessParameterChange key '%s' pid: %d",
+ GetKeyPrefix().c_str(), remoteWatcher->GetAgentId());
+ }
remoteWatcher->ProcessParameterChange(GetKeyPrefix(), name, value);
});
}
@@ -251,9 +258,36 @@ static int FilterParam(const char *name, const std::string &keyPrefix)
return strcmp(name, keyPrefix.c_str()) == 0;
}
+void WatcherManager::AddRealWatcherGroup(const std::string &keyPrefix, int type)
+{
+ std::string key;
+ if (!keyPrefix.empty() && keyPrefix.back() == '.') {
+ key = keyPrefix + '*';
+ } else {
+ key = keyPrefix;
+ }
+ if (groupMap_.find(key) == groupMap_.end() && type != MSG_DEL_WATCHER) {
+ return;
+ }
+
+ if (type == MSG_ADD_WATCHER) {
+ groupRealMap_[key] = groupMap_[key]->GetGroupId();
+ WATCHER_LOGI("add key %s groupId %u success", key.c_str(), groupMap_[key]->GetGroupId());
+ } else if (type == MSG_DEL_WATCHER && groupRealMap_.find(key) != groupRealMap_.end()) {
+ groupRealMap_.erase(key);
+ WATCHER_LOGI("del key %s", key.c_str());
+ }
+}
+
void WatcherManager::ProcessWatcherMessage(const ParamMessage *msg)
{
uint32_t offset = 0;
+ if (msg->type == MSG_ADD_WATCHER || msg->type == MSG_DEL_WATCHER) {
+ std::lock_guard lock(watcherMutex_);
+ WATCHER_LOGV("ProcessWatcherMessage key %s, type %d", msg->key, msg->type);
+ AddRealWatcherGroup(msg->key, msg->type);
+ return;
+ }
if (msg->type != MSG_NOTIFY_PARAM) {
return;
}
@@ -430,8 +464,8 @@ void WatcherManager::OnStop()
OnRemoteDied(remoteWatcher);
});
}
- Clear();
StopLoop();
+ Clear();
}
void WatcherManager::OnRemoteDied(const wptr &remote)
diff --git a/services/param/watcher/proxy/watcher_manager.h b/services/param/watcher/proxy/watcher_manager.h
index 94c287751acd2d6e70a25bb521fd688e46ff60a4..93ba13f4ff58d88adf8d2b82a94f62d8d1fbba14 100644
--- a/services/param/watcher/proxy/watcher_manager.h
+++ b/services/param/watcher/proxy/watcher_manager.h
@@ -98,6 +98,7 @@ private:
void DelRemoteWatcher(RemoteWatcherPtr remoteWatcher);
// for group
WatcherGroupPtr AddWatcherGroup(const std::string &keyPrefix);
+ void AddRealWatcherGroup(const std::string &keyPrefix, int type);
WatcherGroupPtr GetWatcherGroup(const std::string &keyPrefix);
WatcherGroupPtr GetWatcherGroup(uint32_t groupId);
void DelWatcherGroup(WatcherGroupPtr group);
@@ -124,6 +125,7 @@ private:
std::thread *pRecvThread_ { nullptr };
std::atomic stop_ { false };
std::map groupMap_ {};
+ std::map groupRealMap_ {};
sptr deathRecipient_ {};
ParamWatcherListPtr watcherGroups_ {};
ParamWatcherListPtr remoteWatchers_ {};
diff --git a/services/sandbox/chipset-sandbox.json b/services/sandbox/chipset-sandbox.json
index 6dac4b4931a980a478a6be818254e47769a658d1..88a655b7d6f22455dc7015c49e01d5a7a2f81588 100644
--- a/services/sandbox/chipset-sandbox.json
+++ b/services/sandbox/chipset-sandbox.json
@@ -9,16 +9,8 @@
"sandbox-path" : "/system/etc/selinux",
"sandbox-flags" : [ "bind", "rec", "private" ]
}, {
- "src-path" : "/system/lib/chipset-pub-sdk",
- "sandbox-path" : "/system/lib/chipset-pub-sdk",
- "sandbox-flags" : [ "bind", "rec", "private" ]
- }, {
- "src-path" : "/system/lib/chipset-sdk",
- "sandbox-path" : "/system/lib/chipset-sdk",
- "sandbox-flags" : [ "bind", "rec", "private" ]
- }, {
- "src-path" : "/system/lib/ndk",
- "sandbox-path" : "/system/lib/ndk",
+ "src-path" : "/system/lib",
+ "sandbox-path" : "/system/lib",
"sandbox-flags" : [ "bind", "rec", "private" ]
}, {
"src-path" : "/vendor",
diff --git a/services/sandbox/sandbox.c b/services/sandbox/sandbox.c
index e54fe994178a96e768780d274ef425654d9b81bb..ea980270b805be3afbff867008a227e723be0e15 100755
--- a/services/sandbox/sandbox.c
+++ b/services/sandbox/sandbox.c
@@ -239,7 +239,8 @@ static int AddMountInfoToSandbox(sandbox_t *sandbox, cJSON *item, const char *ty
tmpMount->source = strdup(srcPath);
BEGET_ERROR_CHECK(tmpMount->source != NULL, free(tmpMount); return -1, "Failed to dup source");
tmpMount->target = strdup(dstPath);
- BEGET_ERROR_CHECK(tmpMount->target != NULL, free(tmpMount); return -1, "Failed to dup target");
+ BEGET_ERROR_CHECK(tmpMount->target != NULL, free(tmpMount->source); free(tmpMount); return -1,
+ "Failed to dup target");
for (int i = 0; i < count; i++) {
cJSON *item = cJSON_GetArrayItem(obj, i);
tmpMount->flags |= GetSandboxMountFlags(item);
@@ -277,7 +278,8 @@ static int AddSymbolLinksToSandbox(sandbox_t *sandbox, cJSON *item, const char *
tmpLink->target = strdup(target);
BEGET_ERROR_CHECK(tmpLink->target != NULL, free(tmpLink); return -1, "Failed to dup target");
tmpLink->linkName = strdup(name);
- BEGET_ERROR_CHECK(tmpLink->linkName != NULL, free(tmpLink); return -1, "Failed to dup linkName");
+ BEGET_ERROR_CHECK(tmpLink->linkName != NULL, free(tmpLink->target); free(tmpLink); return -1,
+ "Failed to dup linkName");
OH_ListInit(&tmpLink->node);
RemoveOldSandboxLinkListNode(&sandbox->linksHead, tmpLink->linkName);
OH_ListAddTail(&sandbox->linksHead, &tmpLink->node);
@@ -368,6 +370,7 @@ static int ParseInitSandboxConfigFile(sandbox_t *sandbox, const char *sandboxCon
return 0;
}
+#ifndef STARTUP_INIT_TEST
static void ParseInitSandboxConfigPath(sandbox_t *sandbox, const char *sandboxConfig, const char *name)
{
CfgFiles *files = GetCfgFiles(sandboxConfig);
@@ -381,6 +384,7 @@ static void ParseInitSandboxConfigPath(sandbox_t *sandbox, const char *sandboxCo
}
FreeCfgFiles(files);
}
+#endif
static void InitSandbox(sandbox_t *sandbox, const char *sandboxConfig, const char *name)
{
diff --git a/services/sandbox/system-sandbox.json b/services/sandbox/system-sandbox.json
index 5998732ddeded867a98923831a3db44529c3973b..2e447487b6a0e0c5484d4496458f868765f49b37 100644
--- a/services/sandbox/system-sandbox.json
+++ b/services/sandbox/system-sandbox.json
@@ -32,16 +32,12 @@
"sandbox-flags" : [ "bind", "rec", "private" ],
"ignore": 1
}, {
- "src-path" : "/system/resource",
+ "src-path" : "/system/resource",
"sandbox-path" : "/system/resource",
"sandbox-flags" : [ "bind", "rec", "private" ]
}, {
- "src-path" : "/vendor/lib/chipsetsdk",
- "sandbox-path" : "/vendor/lib/chipsetsdk",
- "sandbox-flags" : [ "bind", "rec", "private" ]
- }, {
- "src-path" : "/vendor/lib/chipset-sdk",
- "sandbox-path" : "/vendor/lib/chipset-sdk",
+ "src-path" : "/vendor/lib",
+ "sandbox-path" : "/vendor/lib",
"sandbox-flags" : [ "bind", "rec", "private" ]
}, {
"src-path" : "/dev",
@@ -84,6 +80,10 @@
"src-path" : "/chipset/etc",
"sandbox-path" : "/chipset/etc",
"sandbox-flags" : [ "bind", "rec", "private" ]
+ }, {
+ "src-path" : "/chip_prod/lib",
+ "sandbox-path" : "/chip_prod/lib",
+ "sandbox-flags" : [ "bind", "rec", "private" ]
}, {
"src-path" : "/chip_prod/etc",
"sandbox-path" : "/chip_prod/etc",
diff --git a/services/utils/BUILD.gn b/services/utils/BUILD.gn
index 00fddb9b4e1b664ef3def55dd81bbe079fd85cb4..28f58c4d55fdd6b6e661c7bfcfec74a9a4cc1633 100755
--- a/services/utils/BUILD.gn
+++ b/services/utils/BUILD.gn
@@ -21,6 +21,9 @@ config("exported_header_files") {
if (defined(ohos_lite)) {
static_library("libinit_utils") {
+ if (board_toolchain_type == "clang") {
+ cflags = [ "-Wno-error=unused-but-set-variable" ]
+ }
sources = [ "init_utils.c" ]
public_configs = [ ":exported_header_files" ]
include_dirs = [
diff --git a/services/utils/init_utils.c b/services/utils/init_utils.c
index 935cc3f74377c7a11e11675ade20b3a42fa05618..35b01b7367384ab244e254f11ca17e519868efeb 100644
--- a/services/utils/init_utils.c
+++ b/services/utils/init_utils.c
@@ -605,6 +605,21 @@ int InUpdaterMode(void)
#endif
}
+// Check if in penglai mode.
+bool IsPenglaiMode(void)
+{
+#ifdef OHOS_LITE
+ return false;
+#else
+ char value[MAX_BUFFER_LEN] = {0};
+ int ret = GetParameterFromCmdLine("ohos.boot.minisys.mode", value, MAX_BUFFER_LEN);
+ if (ret == 0 && strcmp(value, "penglai") == 0) {
+ return true;
+ }
+ return false;
+#endif
+}
+
// Check if in rescue mode.
int InRescueMode(void)
{
@@ -620,6 +635,25 @@ int InRescueMode(void)
#endif
}
+// Check if in repair mode
+int InRepairMode(void)
+{
+ char repair[REPAIR_MODE_LEN] = {0};
+ int ret = GetExactParameterFromCmdLine("repair_mode", repair, REPAIR_MODE_LEN);
+ if (ret != 0) {
+ return -1;
+ }
+
+ if (strcmp(repair, MAINTENANCE_RECOVERY) == 0) {
+ return MAINTENANCE_RECOVERY_TYPE;
+ }
+
+ if (strcmp(repair, MAINTENANCE_RECOVERY_COMPLETE) == 0) {
+ return MAINTENANCE_RECOVERY_COMPLETE_TYPE;
+ }
+ return -1;
+}
+
int StringReplaceChr(char *strl, char oldChr, char newChr)
{
INIT_ERROR_CHECK(strl != NULL, return -1, "Invalid parament");
@@ -870,26 +904,20 @@ int OH_StrArrayGetIndex(const char *strArray[], const char *target, int ignoreCa
void *OH_ExtendableStrDictGet(void **strDict, int dictSize, const char *target, int ignoreCase, void **extendStrDict)
{
- int i;
const char *pos;
str_compare cmp = strcmp;
-
if ((strDict == NULL) || dictSize < 0 || ((size_t)dictSize < sizeof(const char *)) ||
(target == NULL) || (target[0] == '\0')) {
return NULL;
}
-
if (ignoreCase) {
cmp = strcasecmp;
}
-
- i = 0;
pos = (const char *)strDict;
while (*(const char **)pos != NULL) {
if (cmp(*(const char **)pos, target) == 0) {
return (void *)pos;
}
- i++;
pos = pos + dictSize;
}
if (extendStrDict == NULL) {
@@ -900,7 +928,6 @@ void *OH_ExtendableStrDictGet(void **strDict, int dictSize, const char *target,
if (cmp(*(const char **)pos, target) == 0) {
return (void *)pos;
}
- i++;
pos = pos + dictSize;
}
return NULL;
diff --git a/test/BUILD.gn b/test/BUILD.gn
index d292b6b81939af8c56787726a1b3b009305714b5..b18aa1153269895e1a9e57b3e0a6662b649f30c5 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -24,6 +24,8 @@ group("testgroup") {
"unittest:init_dmverify_unittest",
"unittest:init_fshvb_unittest",
"unittest:init_unittest",
+ "unittest/single_test/init_firststage:init_firststage_unittest",
+ "unittest/single_test/fstab_mount:fstab_mount_unittest",
]
} else {
if (ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0200.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0200.json
new file mode 100644
index 0000000000000000000000000000000000000000..511a6941e5aef8e9a8188efda97777a248538e68
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0200.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_0200.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0200.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0200.py
new file mode 100644
index 0000000000000000000000000000000000000000..c109770d45de03943492a94c5e7307cdb598223d
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0200.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+
+#
+# Copyright (c) 2024 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 os
+import time
+import gzip
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+
+
+class SunStartupInitBase0200(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+
+ def process(self):
+ Step("清理/data/log/hilog目录")
+ self.driver.shell("rm -rf /data/log/hilog")
+
+ Step("重启设备")
+ self.driver.System.reboot()
+ self.driver.System.wait_for_boot_complete()
+
+ Step("解锁设备")
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.shell("power-shell timeout -o 86400000")
+
+ Step("拉取日志匹配关键字")
+ result = self.driver.shell('ls /data/log/hilog').split()
+ count = 0
+ path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
+ target_path = os.path.join(path, "testFile", "SUB_STARTUP_INIT_BASE")
+ self.driver.Assert.equal(count, 0)
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0300.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0300.json
new file mode 100644
index 0000000000000000000000000000000000000000..45767bdd10e30b40eacc8f79b7a0e4fc1320e1f8
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0300.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_0300.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0300.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0300.py
new file mode 100644
index 0000000000000000000000000000000000000000..c664aa0c429c453888fbba5a4e24fd1935b7fd63
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0300.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+
+#
+# Copyright (c) 2024 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 os
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+
+
+class SunStartupInitBase0300(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+
+ Step("解锁设备")
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.shell("power-shell timeout -o 86400000")
+
+ def process(self):
+ result1 = self.driver.shell("param get ohos.boot.time.init")
+ self.driver.Assert.equal(result1.split()[0].isdigit(), True)
+
+ result2 = self.driver.shell("param set persist.init.debug.loglevel 0")
+ self.driver.Assert.contains(result2, "Set parameter persist.init.debug.loglevel 0 success")
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0400.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0400.json
new file mode 100644
index 0000000000000000000000000000000000000000..e95c51d7ddf83595731fd922e3eeb029cd3cebc1
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0400.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_0400.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0400.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0400.py
new file mode 100644
index 0000000000000000000000000000000000000000..96085f63682e23334615cb18e6a10a6c50be9049
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_0400.py
@@ -0,0 +1,56 @@
+# -*- coding: utf-8 -*-
+
+#
+# Copyright (c) 2024 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 os
+import sys
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SunStartupInitBase0400(TestCase):
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+
+ def process(self):
+ result = self.driver.hdc("target mount")
+ self.driver.Assert.contains(result, "Mount finish")
+
+ txt_path = Common.sourcepath('test.txt', "SUB_STARTUP_INIT_BASE")
+ self.driver.push_file(txt_path, "/system")
+
+ has_file = self.driver.Storage.has_file("/system/test.txt")
+ self.driver.Assert.equal(has_file, True)
+ self.driver.shell("echo '123456' > /system/test.txt")
+
+ self.driver.System.reboot()
+ self.driver.System.wait_for_boot_complete()
+
+ content = self.driver.shell("cat /system/test.txt")
+ self.driver.Assert.contains(content, "123456")
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1600.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1600.json
new file mode 100644
index 0000000000000000000000000000000000000000..7ec4b0328739624a3a1373a407bec26335651165
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1600.json
@@ -0,0 +1,15 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device",
+ "label": "phone"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_1600.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1600.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1600.py
new file mode 100644
index 0000000000000000000000000000000000000000..e7538f40686ec7cc6d470275a0292210d91fd211
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1600.py
@@ -0,0 +1,86 @@
+#
+# Copyright (c) 2024 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 os
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBase1600(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("重命名系统文件param_watcher.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell(
+ "cp /etc/init/param_watcher.cfg /etc/init/param_watcher.cfg_bak")
+ Step("把系统文件param_watcher.cfg拉到本地..........................")
+ devpath = "/etc/init/param_watcher.cfg"
+ self.driver.pull_file(devpath, "testFile/SUB_STARTUP_INIT_BASE/param_watcher.cfg")
+ Step("修改本地系统文件..........................")
+ lines1 = []
+ path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
+ "testFile/SUB_STARTUP_INIT_BASE")
+ localpath = os.path.join(path2, "param_watcher.cfg")
+ with open(localpath, "r") as y:
+ for line in y:
+ lines1.append(line)
+ y.close()
+ Step(lines1)
+ line = lines1.index(' "services" : [{\n') + 1
+ d_caps_entry = '\t\t\t"importance" : -20,\n'
+ lines1.insert(line, d_caps_entry)
+ s = ''.join(lines1)
+ Step(s)
+ with open(localpath, "w") as z:
+ z.write(s)
+ z.close()
+ Step("上传修改后的本地系统文件..........................")
+ self.driver.push_file(localpath, devpath)
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
+ Step("执行启动服务命令begetctl start_service param_watcher..........................")
+ self.driver.shell('begetctl start_service param_watcher')
+ Step("查看服务状态ps -Al | grep param_watcher..........................")
+ result = self.driver.shell('ps -Al | grep param_watcher')
+ Step(result)
+ self.driver.Assert.contains(result, '-20')
+
+ def teardown(self):
+ Step("收尾工作.................")
+ Step("恢复系统文件useriam.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell("rm -rf /etc/init/param_watcher.cfg")
+ self.driver.shell(
+ "mv /etc/init/param_watcher.cfg_bak /etc/init/param_watcher.cfg")
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1700.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1700.json
new file mode 100644
index 0000000000000000000000000000000000000000..936c9dd0d0719406c130798aa43eca090bc56225
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1700.json
@@ -0,0 +1,15 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device",
+ "label": "phone"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_1700.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1700.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1700.py
new file mode 100644
index 0000000000000000000000000000000000000000..9a58476528dae704e22147c68ce7ad4f19018db5
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1700.py
@@ -0,0 +1,87 @@
+
+#
+# Copyright (c) 2024 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 os
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBase1700(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("重命名系统文件param_watcher.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell(
+ "cp /etc/init/param_watcher.cfg /etc/init/param_watcher.cfg_bak")
+ Step("把系统文件param_watcher.cfg拉到本地..........................")
+ devpath = "/etc/init/param_watcher.cfg"
+ self.driver.pull_file(devpath, "testFile/SUB_STARTUP_INIT_BASE/param_watcher.cfg")
+ Step("修改本地系统文件..........................")
+ lines1 = []
+ path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
+ "testFile/SUB_STARTUP_INIT_BASE")
+ localpath = os.path.join(path2, "param_watcher.cfg")
+ with open(localpath, "r") as y:
+ for line in y:
+ lines1.append(line)
+ y.close()
+ Step(lines1)
+ line = lines1.index(' "services" : [{\n') + 1
+ d_caps_entry = '\t\t\t"d-caps" : ["OHOS_DMS"],\n\t\t\t"apl" : "normal",\n'
+ lines1.insert(line, d_caps_entry)
+ s = ''.join(lines1)
+ Step(s)
+ with open(localpath, "w") as z:
+ z.write(s)
+ z.close()
+ Step("上传修改后的本地系统文件..........................")
+ self.driver.push_file(localpath, devpath)
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
+ Step("执行启动服务命令begetctl start_service param_watcher..........................")
+ self.driver.shell('begetctl start_service param_watcher')
+ Step("查看nativetoken.json..........................")
+ result = self.driver.shell('cat data/service/el0/access_token/nativetoken.json')
+ Step(result)
+ self.driver.Assert.contains(result, '"processName":"param_watcher","APL":1')
+
+ def teardown(self):
+ Step("收尾工作.................")
+ Step("恢复系统文件useriam.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell("rm -rf /etc/init/param_watcher.cfg")
+ self.driver.shell(
+ "mv /etc/init/param_watcher.cfg_bak /etc/init/param_watcher.cfg")
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1800.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1800.json
new file mode 100644
index 0000000000000000000000000000000000000000..7c41754f4fd4e2c88cc65f33ed316bb92d94a188
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1800.json
@@ -0,0 +1,15 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device",
+ "label": "phone"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_1800.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1800.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1800.py
new file mode 100644
index 0000000000000000000000000000000000000000..063389dd8988ccd8d4ebb7f0af604b0a98877fcb
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1800.py
@@ -0,0 +1,88 @@
+#
+# Copyright (c) 2024 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 os
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBase1800(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("重命名系统文件param_watcher.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell(
+ "cp /etc/init/param_watcher.cfg /etc/init/param_watcher.cfg_bak")
+ Step("把系统文件param_watcher.cfg拉到本地..........................")
+ devpath = "/etc/init/param_watcher.cfg"
+ self.driver.pull_file(devpath, "testFile/SUB_STARTUP_INIT_BASE/param_watcher.cfg")
+ Step("修改本地系统文件..........................")
+ lines1 = []
+ path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
+ "testFile/SUB_STARTUP_INIT_BASE")
+ localpath = os.path.join(path2, "param_watcher.cfg")
+ with open(localpath, "r") as y:
+ for line in y:
+ lines1.append(line)
+ y.close()
+ Step(lines1)
+ line = lines1.index(' "services" : [{\n') + 1
+ d_caps_entry = '\t\t\t"cpucore" : [0, 1],\n'
+ lines1.insert(line, d_caps_entry)
+ s = ''.join(lines1)
+ Step(s)
+ with open(localpath, "w") as z:
+ z.write(s)
+ z.close()
+ Step("上传修改后的本地系统文件..........................")
+ self.driver.push_file(localpath, devpath)
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
+ Step("执行启动服务命令begetctl start_service param_watcher..........................")
+ self.driver.shell('begetctl start_service param_watcher')
+ Step("查看param_watcher服务pid..........................")
+ pid = self.driver.System.get_pid('param_watcher')
+ Step("查看param_watcher服务的亲和力掩码..........................")
+ result = self.driver.shell('taskset -p ' + str(pid))
+ Step(result)
+ self.driver.Assert.contains(result, 'current affinity mask: 3')
+
+ def teardown(self):
+ Step("收尾工作.................")
+ Step("恢复系统文件useriam.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell("rm -rf /etc/init/param_watcher.cfg")
+ self.driver.shell(
+ "mv /etc/init/param_watcher.cfg_bak /etc/init/param_watcher.cfg")
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1900.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1900.json
new file mode 100644
index 0000000000000000000000000000000000000000..505fdab2b55fcf8f0345cf532d7082541cec10fc
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1900.json
@@ -0,0 +1,15 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device",
+ "label": "phone"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_1900.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1900.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1900.py
new file mode 100644
index 0000000000000000000000000000000000000000..85a6e5e87834b973eaa38aa3a4304504d8aa133d
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_1900.py
@@ -0,0 +1,88 @@
+#
+# Copyright (c) 2024 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 os
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBase1900(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("重命名系统文件param_watcher.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell(
+ "cp /etc/init/param_watcher.cfg /etc/init/param_watcher.cfg_bak")
+ Step("把系统文件param_watcher.cfg拉到本地..........................")
+ devpath = "/etc/init/param_watcher.cfg"
+ self.driver.pull_file(devpath, "testFile/SUB_STARTUP_INIT_BASE/param_watcher.cfg")
+ Step("修改本地系统文件..........................")
+ lines1 = []
+ path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
+ "testFile/SUB_STARTUP_INIT_BASE")
+ localpath = os.path.join(path2, "param_watcher.cfg")
+ with open(localpath, "r") as y:
+ for line in y:
+ lines1.append(line)
+ y.close()
+ Step(lines1)
+ line = lines1.index(' "services" : [{\n') + 1
+ d_caps_entry = '\t\t\t"cpucore" : [20],\n'
+ lines1.insert(line, d_caps_entry)
+ s = ''.join(lines1)
+ Step(s)
+ with open(localpath, "w") as z:
+ z.write(s)
+ z.close()
+ Step("上传修改后的本地系统文件..........................")
+ self.driver.push_file(localpath, devpath)
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
+ Step("执行启动服务命令begetctl start_service param_watcher..........................")
+ self.driver.shell('begetctl start_service param_watcher')
+ Step("查看param_watcher服务pid..........................")
+ pid = self.driver.System.get_pid('param_watcher')
+ Step("查看param_watcher服务的亲和力掩码..........................")
+ result = self.driver.shell('taskset -p ' + str(pid))
+ Step(result)
+ self.driver.Assert.contains(result, 'current affinity mask: ff')
+
+ def teardown(self):
+ Step("收尾工作.................")
+ Step("恢复系统文件useriam.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell("rm -rf /etc/init/param_watcher.cfg")
+ self.driver.shell(
+ "mv /etc/init/param_watcher.cfg_bak /etc/init/param_watcher.cfg")
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_2700.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_2700.json
new file mode 100644
index 0000000000000000000000000000000000000000..54ea375581a7db32f69393960c0236f82c414403
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_2700.json
@@ -0,0 +1,15 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device",
+ "label": "phone"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_2700.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_2700.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_2700.py
new file mode 100644
index 0000000000000000000000000000000000000000..fe92304d6b1cb0cb2d135e6f6e8da5362e1340fb
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_2700.py
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBase2700(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("执行启动服务命令begetctl start_service param_watcher..........................")
+ self.driver.shell('begetctl start_service param_watcher')
+ Step("查看param_watcher服务..........................")
+ result = self.driver.shell(' ps -AZ | grep param_watcher')
+ Step(result)
+ self.driver.Assert.contains(result, 'u:r:param_watcher:s0')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_3600.json b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_3600.json
new file mode 100644
index 0000000000000000000000000000000000000000..910048bd6507b7b1f986a77fe09d02ec8e462a86
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_3600.json
@@ -0,0 +1,15 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device",
+ "label": "phone"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BASE/Sub_Starup_Init_Base_3600.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_3600.py b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_3600.py
new file mode 100644
index 0000000000000000000000000000000000000000..527ffb1dccc102e7613c5bb0188e160614fe00b9
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BASE/sub_starup_init_base_3600.py
@@ -0,0 +1,51 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBase3600(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("执行命令begetctl..........................")
+ result_beg = self.driver.shell('begetctl')
+ Step(result_beg)
+ self.driver.Assert.contains(result_beg, 'dump_service loop')
+ Step("执行命令begetctl dump_service..........................")
+ result_beg_dump_ser = self.driver.shell('begetctl dump_service')
+ Step(result_beg_dump_ser)
+ self.driver.Assert.contains(result_beg_dump_ser, 'dump_service loop')
+ Step("执行命令begetctl dump_service loop..........................")
+ result_beg_dump_ser_loop = self.driver.shell('begetctl dump_service loop')
+ Step(result_beg_dump_ser_loop)
+ self.driver.Assert.contains(result_beg_dump_ser_loop, 'dump service info')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0100.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0100.json
new file mode 100644
index 0000000000000000000000000000000000000000..0b9d5c8d875ab6b24dfaa421067c59ec1c9fb5af
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0100.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0100.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0100.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0100.py
new file mode 100644
index 0000000000000000000000000000000000000000..8002cc82fb09628139a9327c7d0a9f6daf853ab3
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0100.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0100(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取appspawn的pid.................")
+ pid = self.driver.System.get_pid("appspawn")
+ Step(pid)
+ sleep(1)
+ Step("查看appspawn的memory.................")
+ result = self.driver.shell('begetctl display memory ' + str(pid))
+ Step("检查结果.................")
+ self.driver.Assert.contains(result, 'Total mem')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0200.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0200.json
new file mode 100644
index 0000000000000000000000000000000000000000..88415c076cc3eece5dd371a45cc07278eb2b9729
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0200.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0200.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0200.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0200.py
new file mode 100644
index 0000000000000000000000000000000000000000..ad812b017e7c0cde2e216b764d77ae8a7853d701
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0200.py
@@ -0,0 +1,74 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0200(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取param ls结果.................")
+ result_param_ls = self.driver.shell('begetctl param ls')
+ Step(result_param_ls)
+ Step("检查param ls结果.................")
+ self.driver.Assert.contains(result_param_ls, 'Parameter information:')
+ self.driver.Assert.contains(result_param_ls, 'selinux :')
+ self.driver.Assert.contains(result_param_ls, 'dac :')
+ sleep(1)
+ Step("获取param ls -r结果.................")
+ result_param_ls_r = self.driver.shell('begetctl param ls -r')
+ Step(result_param_ls_r)
+ Step("检查param ls -r结果.................")
+ self.driver.Assert.contains(result_param_ls_r, 'Parameter information:')
+ self.driver.Assert.contains(result_param_ls_r, 'selinux :')
+ self.driver.Assert.contains(result_param_ls_r, 'dac :')
+ self.driver.Assert.contains(result_param_ls_r, 'name :')
+ self.driver.Assert.contains(result_param_ls_r, 'value:')
+ sleep(1)
+ Step("获取param ls name结果.................")
+ result_param_ls_name = self.driver.shell('begetctl param ls const.cust.vendor')
+ Step(result_param_ls_name)
+ Step("检查param ls name结果.................")
+ self.driver.Assert.contains(result_param_ls_name, 'Parameter information:')
+ self.driver.Assert.contains(result_param_ls_name, 'selinux : u:object_r:default_param:s0')
+ self.driver.Assert.contains(result_param_ls_name, 'dac : root(rww) root(rww) (r--)')
+ self.driver.Assert.contains(result_param_ls_name, 'name : const.cust.vendor')
+ sleep(1)
+ Step("获取param ls -r name结果.................")
+ result_param_ls_r_name = self.driver.shell('begetctl param ls -r const.cust.vendor')
+ Step(result_param_ls_r_name)
+ Step("检查param ls -r name结果.................")
+ self.driver.Assert.contains(result_param_ls_r_name, 'Parameter information:')
+ self.driver.Assert.contains(result_param_ls_r_name, 'selinux : u:object_r:default_param:s0')
+ self.driver.Assert.contains(result_param_ls_r_name, 'dac : root(rww) root(rww) (r--)')
+ self.driver.Assert.contains(result_param_ls_r_name, 'name : const.cust.vendor')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0300.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0300.json
new file mode 100644
index 0000000000000000000000000000000000000000..814214a08c87d5e1731b647cabff09e6918dc95b
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0300.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0300.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0300.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0300.py
new file mode 100644
index 0000000000000000000000000000000000000000..f206c9a4745209c78c9f346b6309390e598eb88e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0300.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0300(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("设置参数.................")
+ result_set = self.driver.shell('begetctl param set test test.value')
+ Step(result_set)
+ Step("检查设置参数.................")
+ self.driver.Assert.contains(result_set, 'Set parameter test test.value success')
+ sleep(1)
+ Step("获取参数.................")
+ result_get = self.driver.shell('begetctl param get test')
+ Step(result_get)
+ Step("检查获取参数.................")
+ self.driver.Assert.contains(result_get, 'test.value')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0400.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0400.json
new file mode 100644
index 0000000000000000000000000000000000000000..9840a18016f040e282ba40ee3b9093c42a821e7a
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0400.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0400.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0400.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0400.py
new file mode 100644
index 0000000000000000000000000000000000000000..a4337dd2cd62800aa1b505e6b57a281c06846c75
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0400.py
@@ -0,0 +1,60 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0400(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取param wait name结果.................")
+ result_wait_name = self.driver.shell('begetctl param wait const.cust.vendor')
+ Step(result_wait_name)
+ Step("检查param wait name结果.................")
+ self.driver.Assert.contains(result_wait_name, 'Wait parameter const.cust.vendor success')
+ sleep(1)
+ Step("获取param wait name value结果.................")
+ result = self.driver.shell("begetctl param ls -r const.cust.vendor | grep value")
+ result = result.strip()
+ value = result.split("value:")[1]
+ result_wait_name_value = self.driver.shell('begetctl param wait const.cust.vendor %s' % value)
+ Step(result_wait_name_value)
+ Step("检查param wait name value结果.................")
+ self.driver.Assert.contains(result_wait_name_value, 'Wait parameter const.cust.vendor success')
+ sleep(1)
+ Step("获取param wait name value timeout结果.................")
+ result_wait_name_value_timeout = self.driver.shell('begetctl param wait const.cust.vendor %s 10' % value)
+ Step(result_wait_name_value_timeout)
+ Step("检查param wait name value timeout结果.................")
+ self.driver.Assert.contains(result_wait_name_value_timeout, 'Wait parameter const.cust.vendor success')
+ sleep(1)
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0500.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0500.json
new file mode 100644
index 0000000000000000000000000000000000000000..fe015c38707e555065ee1714a7a71892de644540
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0500.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0500.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0500.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0500.py
new file mode 100644
index 0000000000000000000000000000000000000000..8e02fb6a8de18e0fcb7865d2337d2ae86b83d6a2
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0500.py
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0500(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取param dump结果.................")
+ result = self.driver.shell('begetctl param dump')
+ Step(result)
+ Step("检查param dump结果.................")
+ self.driver.Assert.contains(result, 'Dump all parameters finish')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0600.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0600.json
new file mode 100644
index 0000000000000000000000000000000000000000..2a2afa4d35ccd3fb3dcb16a14d93e7eaaea0830e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0600.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0600.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0600.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0600.py
new file mode 100644
index 0000000000000000000000000000000000000000..08e684079a7c47cfe48831f93f40d4a58df9bec6
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0600.py
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0600(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取param save结果.................")
+ result = self.driver.shell('begetctl param save')
+ Step(result)
+ Step("检查param dump结果.................")
+ self.driver.Assert.contains(result, 'Save persist parameters success')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0700.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0700.json
new file mode 100644
index 0000000000000000000000000000000000000000..bd5aa4361abc725190eb308b8f1cb838a8d60d78
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0700.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0700.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0700.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0700.py
new file mode 100644
index 0000000000000000000000000000000000000000..ac981ca8bd42f41df3665e81a1855195e8fdd84f
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0700.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0700(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取dump api结果.................")
+ result = self.driver.shell('begetctl dump api')
+ Step(result)
+ Step("检查dump api结果.................")
+ self.driver.Assert.contains(result, 'DeviceType')
+ self.driver.Assert.contains(result, 'Manufacture')
+ self.driver.Assert.contains(result, 'Brand')
+ self.driver.Assert.contains(result, 'MarketName')
+ self.driver.Assert.contains(result, 'ProductSeries')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0800.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0800.json
new file mode 100644
index 0000000000000000000000000000000000000000..a601a5dc6e8ef8188dfc494312ea1ba30218bdb7
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0800.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0800.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0800.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0800.py
new file mode 100644
index 0000000000000000000000000000000000000000..b53655616e2edfce747983e09ed0717a5658b38a
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0800.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0800(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("设置日志级别.................")
+ result_set = self.driver.shell('begetctl setloglevel 1')
+ Step(result_set)
+ Step("检查设置日志级别.................")
+ self.driver.Assert.contains(result_set, 'Success to set log level by param "persist.init.debug.loglevel" 1')
+ sleep(1)
+ Step("获取日志级别.................")
+ result_get = self.driver.shell('begetctl getloglevel')
+ Step(result_get)
+ Step("检查获取日志级别.................")
+ self.driver.Assert.contains(result_get, 'Success to get init log level: 1 from param "persist.init.debug.loglevel"')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0900.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0900.json
new file mode 100644
index 0000000000000000000000000000000000000000..9f1b68a2d5f510d8cec8f7bae1c9139926e87d71
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0900.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_0900.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0900.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0900.py
new file mode 100644
index 0000000000000000000000000000000000000000..268008414a1944d2cdf845d8eef9ed9c4e43717b
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_0900.py
@@ -0,0 +1,53 @@
+#
+# Copyright (c) 2024 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 gzip
+import os
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl0900(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("执行begetctl命令")
+ service_list = ["begetctl timer_start media_service 10000", "begetctl stop_service media_service", "dmesg|grep media_service"]
+ for i in service_list:
+ self.driver.shell(i)
+ sleep(3)
+
+ Step("日志匹配")
+ result = self.driver.shell('ls /data/log/hilog').split()
+ count = 0
+ path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
+ log = os.path.join(path, "testFile", "Log")
+ self.driver.Assert.greater(count, 0)
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1000.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1000.json
new file mode 100644
index 0000000000000000000000000000000000000000..ad974d5f516a38f98c6a1853ec4c69fcf19c3937
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1000.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_1000.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1000.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1000.py
new file mode 100644
index 0000000000000000000000000000000000000000..2a525f05a7415183e67e4d860bfe0b94e32b08ed
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1000.py
@@ -0,0 +1,56 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl1000(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取hiview的pid.................")
+ pid = self.driver.System.get_pid("hiview")
+ Step(pid)
+ sleep(1)
+ Step("停止hiview服务.................")
+ self.driver.shell('begetctl stop_service hiview')
+ Step("获取hiview的pid.................")
+ pid1 = self.driver.System.get_pid("hiview")
+ Step(pid1)
+ sleep(1)
+ Step("启动hiview服务.................")
+ self.driver.shell('begetctl start_service hiview')
+ Step("获取hiview的pid.................")
+ pid2 = self.driver.System.get_pid("hiview")
+ Step(pid2)
+ if (!pid2)
+
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1100.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1100.json
new file mode 100644
index 0000000000000000000000000000000000000000..f300f969a07b0d298d7c1444c4e8127b06a7a295
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1100.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_1100.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1100.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1100.py
new file mode 100644
index 0000000000000000000000000000000000000000..6b6790beda1efcf7ed7cd90f606d7ef424ecc3e6
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1100.py
@@ -0,0 +1,54 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl1100(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("获取hiview的pid.................")
+ pid = self.driver.System.get_pid("hiview")
+ Step(pid)
+ sleep(1)
+ Step("停止hiview服务.................")
+ self.driver.shell('begetctl service_control stop hiview')
+ Step("获取hiview的pid.................")
+ pid1 = self.driver.System.get_pid("hiview")
+ Step(pid1)
+ sleep(1)
+ Step("启动hiview服务.................")
+ self.driver.shell('begetctl service_control start hiview')
+ Step("获取hiview的pid.................")
+ pid2 = self.driver.System.get_pid("hiview")
+ Step(pid2)
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1200.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1200.json
new file mode 100644
index 0000000000000000000000000000000000000000..6924c6fe2ee3d2ff64759163b452e2dd3aebd5c1
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1200.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_1200.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1200.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1200.py
new file mode 100644
index 0000000000000000000000000000000000000000..db35debee7d04c4a84cd8b52c267be8f544e9b63
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1200.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl1200(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("设置bootevent enable.................")
+ result_enable = self.driver.shell('begetctl bootevent enable')
+ Step(result_enable)
+ Step("检查bootevent enable结果.................")
+ self.driver.Assert.contains(result_enable, 'bootevent enabled')
+ sleep(1)
+ Step("设置bootevent disable.................")
+ result_disable = self.driver.shell('begetctl bootevent disable')
+ Step(result_disable)
+ Step("检查bootevent disable结果.................")
+ self.driver.Assert.contains(result_disable, 'bootevent disabled')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1300.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1300.json
new file mode 100644
index 0000000000000000000000000000000000000000..615b69c3eba92726dd1976762be6a7c2520152cb
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1300.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_1300.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1300.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1300.py
new file mode 100644
index 0000000000000000000000000000000000000000..bc72d9c777b3a757ac696e9be9960285d87155de
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1300.py
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl1300(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看system的uid.................")
+ result = self.driver.shell('begetctl dac uid system')
+ Step(result)
+ Step("检查system的uid结果.................")
+ self.driver.Assert.contains(result, 'getpwnam uid system : 1000')
+ self.driver.Assert.contains(result, 'getpwent uid system : 1000')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1400.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1400.json
new file mode 100644
index 0000000000000000000000000000000000000000..0e943ab0befd71de76b7509c09ec124d27e8104a
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1400.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl_1400.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1400.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1400.py
new file mode 100644
index 0000000000000000000000000000000000000000..841632e800d44774e9ecce5f7199a6fafcfac079
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1400.py
@@ -0,0 +1,44 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl1400(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看system的gid.................")
+ result = self.driver.shell('begetctl dac gid system')
+ Step(result)
+ Step("检查system的gid结果.................")
+ self.driver.Assert.contains(result, 'getgrnam gid system : 1000')
+ self.driver.Assert.contains(result, 'getgrent gid system : 1000')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1500.json b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1500.json
new file mode 100644
index 0000000000000000000000000000000000000000..91e0b45c7fd16783cfea785e7d0d23ff877c9aca
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1500.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BEGETCTL/Sub_Startup_Init_Begetctl1500.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1500.py b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1500.py
new file mode 100644
index 0000000000000000000000000000000000000000..db5b6229ee55a82fad82d182cbeec44a12b484e8
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BEGETCTL/sub_startup_init_begetctl_1500.py
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2024 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.
+#
+
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SunStartupInitBegetctl1500(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("设置日志级别.................")
+ result_set = self.driver.shell('begetctl set log level 1')
+ Step(result_set)
+ Step("检查设置日志级别.................")
+ self.driver.Assert.contains(result_set, 'Success to set log level INFO')
+ sleep(1)
+ Step("获取日志级别.................")
+ result_get = self.driver.shell('begetctl get log level')
+ Step(result_get)
+ Step("检查获取日志级别.................")
+ self.driver.Assert.contains(result_get, 'Init log level:')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BOOT/sub_startup_init_boot_0100.json b/test/autotest/testcases/SUB_STARTUP_INIT_BOOT/sub_startup_init_boot_0100.json
new file mode 100644
index 0000000000000000000000000000000000000000..2c287920a7640e166d2138aec90d40d03013086e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BOOT/sub_startup_init_boot_0100.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_BOOT/Sub_Startup_Init_Boot_0100.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_BOOT/sub_startup_init_boot_0100.py b/test/autotest/testcases/SUB_STARTUP_INIT_BOOT/sub_startup_init_boot_0100.py
new file mode 100644
index 0000000000000000000000000000000000000000..1abe895572776deadad7f4ea3694c140fca9ab3e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_BOOT/sub_startup_init_boot_0100.py
@@ -0,0 +1,96 @@
+#
+# Copyright (c) 2024 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 os
+# -*- coding: utf-8 -*-
+from time import sleep
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitBoot0100(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("重命名系统文件useriam.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell(
+ "cp /etc/init/useriam.cfg /etc/init/useriam.cfg_bak")
+ Step("把系统文件useriam.cfg拉到本地..........................")
+ devpath = "/etc/init/useriam.cfg"
+ self.driver.pull_file(devpath, "testFile/SUB_STARTUP_INIT_BOOT/useriam.cfg")
+ Step("修改本地系统文件..........................")
+ lines1 = []
+ path2 = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
+ "testFile/SUB_STARTUP_INIT_BOOT")
+ localpath = os.path.join(path2, "useriam.cfg")
+ with open(localpath, "r") as y:
+ for line in y:
+ lines1.append(line)
+ y.close()
+ Step(lines1)
+ line = lines1.index(' "services" : [{\n') + 1
+ d_caps_entry = '\t\t\t"bootevents" : ["bootevent.useriam.fwkready"],\n'
+ lines1.insert(line, d_caps_entry)
+ s = ''.join(lines1)
+ Step(s)
+ line = lines1.index('{\n') + 1
+ d_caps_entry = [
+ '\t],\n',
+ '\t\t}\n',
+ '\t\t\t"cmds" : ["mkdir /data/service/el1/public/userauth/ 0700 useriam useriam"]\n',
+ '\t\t\t"name" : "service:useriam",\n',
+ '\t"jobs" : [{\n'
+ ]
+ for i in d_caps_entry:
+ lines1.insert(line, i)
+ s = ''.join(lines1)
+ Step(s)
+ with open(localpath, "w") as z:
+ z.write(s)
+ z.close()
+ Step("上传修改后的本地系统文件..........................")
+ self.driver.push_file(localpath, devpath)
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
+ Step("执行命令param get bootevent.boot.completed..........................")
+ result = self.driver.shell('param get bootevent.boot.completed')
+ Step(result)
+ self.driver.Assert.contains(result, 'true')
+
+ def teardown(self):
+ Step("收尾工作.................")
+ Step("恢复系统文件useriam.cfg..........................")
+ self.driver.hdc("target mount")
+ self.driver.shell("rm -rf /etc/init/useriam.cfg")
+ self.driver.shell(
+ "mv /etc/init/useriam.cfg_bak /etc/init/useriam.cfg")
+ Step("执行重启..........................")
+ self.driver.System.reboot()
+ sleep(3)
+ self.driver.System.wait_for_boot_complete()
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0100.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0100.json
new file mode 100644
index 0000000000000000000000000000000000000000..a618f3d050d18beb5a6bbd35543842f6ffc166f0
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0100.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0100.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0100.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0100.py
new file mode 100644
index 0000000000000000000000000000000000000000..380645f0cd2de603430deb7cba09b2fa4c96fb45
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0100.py
@@ -0,0 +1,78 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0100(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[0])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[0])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ self.driver.Assert.contains(text_list, "can use SystemCapability.Ability.AbilityBase in normal")
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0200.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0200.json
new file mode 100644
index 0000000000000000000000000000000000000000..2dbaa59fce9069b765ee5f32fab4eded9fc6664d
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0200.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0200.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0200.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0200.py
new file mode 100644
index 0000000000000000000000000000000000000000..55867302e83e8c5a1a635fdc63a6248fc01fb412
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0200.py
@@ -0,0 +1,78 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0200(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[0])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[1])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ self.driver.Assert.contains(text_list, "can use SystemCapability.Location.Location.Core in normal")
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0300.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0300.json
new file mode 100644
index 0000000000000000000000000000000000000000..958496e71e1636da8caa1d939d6362a1f12b90bd
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0300.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0300.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0300.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0300.py
new file mode 100644
index 0000000000000000000000000000000000000000..5e84ed45611365cc7e10c3d01b3de6d5d3f4d7eb
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0300.py
@@ -0,0 +1,78 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0300(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[0])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[2])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ self.driver.Assert.contains(text_list, "can not use SystemCapability.Test.Invalid in normal")
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0400.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0400.json
new file mode 100644
index 0000000000000000000000000000000000000000..5573064210d0a412e34e0c52b5902d9d29268f73
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0400.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0400.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0400.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0400.py
new file mode 100644
index 0000000000000000000000000000000000000000..8f9aea15ed0bf06f721e3f426eeacde1a1c507ae
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0400.py
@@ -0,0 +1,78 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0400(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[1])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[0])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ self.driver.Assert.contains(text_list, "can use SystemCapability.Ability.AbilityBase in task_0 task_1 task_2 , There are 3 tasks in total")
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0500.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0500.json
new file mode 100644
index 0000000000000000000000000000000000000000..e5b5492edc50c37a8edc8e262a72959014f05e4a
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0500.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0500.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0500.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0500.py
new file mode 100644
index 0000000000000000000000000000000000000000..27529d8fd4a02a1d4eeb78d2187427a5763ae12f
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0500.py
@@ -0,0 +1,78 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0500(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[1])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[1])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ self.driver.Assert.contains(text_list, "can use SystemCapability.Location.Location.Core in task_0 task_1 task_2 , There are 3 tasks in total")
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0600.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0600.json
new file mode 100644
index 0000000000000000000000000000000000000000..992a3eea34bddc92fa45aafdb859504393c6255f
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0600.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0600.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0600.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0600.py
new file mode 100644
index 0000000000000000000000000000000000000000..584ce44cd4dfeb650fc2618e02a92771e7c9e1c8
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0600.py
@@ -0,0 +1,78 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0600(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[1])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[2])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ self.driver.Assert.contains(text_list, "can not use SystemCapability.Test.Invalid in task_pool")
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0700.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0700.json
new file mode 100644
index 0000000000000000000000000000000000000000..f921349213b5c526ff1933fbcfd1d5578b4e490d
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0700.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0700.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0700.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0700.py
new file mode 100644
index 0000000000000000000000000000000000000000..d3934eb7105d55447237f2306f2faa4affe3df53
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0700.py
@@ -0,0 +1,79 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0700(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[2])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[0])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ for i in range(1, 3):
+ self.driver.Assert.contains(text_list, "can use SystemCapability.Ability.AbilityBase in worker%d" % i)
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0800.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0800.json
new file mode 100644
index 0000000000000000000000000000000000000000..3ba56fd42ddef3beb37d7bfee9a6879958f06697
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0800.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0800.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0800.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0800.py
new file mode 100644
index 0000000000000000000000000000000000000000..cc5a733e0870c424baf4f935338656cc5bdea876
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0800.py
@@ -0,0 +1,79 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0800(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[2])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[1])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ for i in range(1, 3):
+ self.driver.Assert.contains(text_list, "can use SystemCapability.Location.Location.Core in worker%d" % i)
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0900.json b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0900.json
new file mode 100644
index 0000000000000000000000000000000000000000..020a3838df6b5ec9589c8bc06cfb34ee964d812b
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0900.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0900.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0900.py b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0900.py
new file mode 100644
index 0000000000000000000000000000000000000000..5e3b2158c5f59b947874857d8ccc1421458fb9d0
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_CANIUSE/SUB_STARTUP_INIT_CANIUSE_0900.py
@@ -0,0 +1,79 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+import time
+from devicetest.core.test_case import TestCase, Step
+from hypium import UiDriver
+from aw import Common
+
+
+class SubStartupInitCaniuse0900(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step(self.devices[0].device_id)
+ device = self.driver.shell("param get const.product.model")
+ device = device.replace("\n", "").replace(" ", "")
+ device = str(device)
+ Step(device)
+ # 解锁屏幕
+ wake = self.driver.Screen.is_on()
+ time.sleep(0.5)
+ if wake:
+ self.driver.ScreenLock.unlock()
+ else:
+ self.driver.Screen.wake_up()
+ self.driver.ScreenLock.unlock()
+ self.driver.Screen.enable_stay_awake()
+
+ def process(self):
+ Step("安装应用")
+ text_list = []
+ hap_path = Common.sourcepath('caniuse.hap', "SUB_STARTUP_INIT_CANIUSE")
+ bundle_name = "com.example.myapplication3"
+ hap = self.driver.AppManager.has_app(bundle_name)
+ if hap:
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
+ self.driver.AppManager.install_app(hap_path)
+ else:
+ self.driver.AppManager.install_app(hap_path)
+ self.driver.AppManager.start_app(bundle_name)
+
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[0])
+ comps2 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps2[2])
+ comps1 = self.driver.find_all_components(BY.type("Select"))
+ self.driver.touch(comps1[1])
+ comps3 = self.driver.find_all_components(BY.type("Option"))
+ self.driver.touch(comps3[2])
+ self.driver.touch(BY.text("click me"))
+ time.sleep(1)
+ comp4 = self.driver.find_all_components(BY.type("Text"))
+ for text in comp4:
+ text_list.append(text.getText())
+ for i in range(1, 3):
+ self.driver.Assert.contains(text_list, "can not use SystemCapability.Test.Invalid in worker%d" % i)
+
+ def teardown(self):
+ Step("收尾工作.................")
+ self.driver.AppManager.clear_app_data(bundle_name)
+ self.driver.AppManager.uninstall_app(bundle_name)
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0100.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0100.json
new file mode 100644
index 0000000000000000000000000000000000000000..9cefa33e6ef4375e7bd686bdb29a2a10ae115c2c
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0100.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0100.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0100.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0100.py
new file mode 100644
index 0000000000000000000000000000000000000000..9ebf0007e769c9fb1205a803193bb73515575a40
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0100.py
@@ -0,0 +1,48 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt0100(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep extra_free_kbytes')
+ Step(condition)
+ Step("条件包括sys.sysctl.extra_free_kbytes..........................")
+ self.driver.Assert.contains(condition, '"condition" : "sys.sysctl.extra_free_kbytes=*"')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('ls /proc/sys/vm/extra_free_kbytes')
+ Step(condition)
+ self.driver.Assert.contains(condition, 'ls: /proc/sys/vm/extra_free_kbytes: No such file or directory')
+
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0200.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0200.json
new file mode 100644
index 0000000000000000000000000000000000000000..ce45178126ac42a5aa15d73d369648ff97b4557e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0200.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0200.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0200.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0200.py
new file mode 100644
index 0000000000000000000000000000000000000000..49900567ee967896a7312231001fc3968f4ff60e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0200.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt0200(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.usb.cfg')
+ Step(condition)
+ Step("条件包括persist.sys.usb.config..........................")
+ self.driver.Assert.contains(condition, '"condition" : "boot && persist.sys.usb.config=*"')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('param get sys.usb.config')
+ Step(condition)
+ self.driver.Assert.contains(condition, 'hdc')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0600.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0600.json
new file mode 100644
index 0000000000000000000000000000000000000000..7c7cb35f8c662bb48114d0fcfad8e529e4d836a3
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0600.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0600.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0600.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0600.py
new file mode 100644
index 0000000000000000000000000000000000000000..22ca4578ddfadb4e528157ab412ad3faf4901e91
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0600.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt0600(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep chmod')
+ Step(condition)
+ Step("条件包括/dev/access_token_id..........................")
+ self.driver.Assert.contains(condition, 'chmod 0666 /dev/access_token_id')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('ls -l /dev/access_token_id')
+ Step(condition)
+ self.driver.Assert.contains(condition, 'crw-rw-rw-')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0700.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0700.json
new file mode 100644
index 0000000000000000000000000000000000000000..025e6db2f1c3d7d125d30bd3f43f5da494c9a34e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0700.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0700.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0700.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0700.py
new file mode 100644
index 0000000000000000000000000000000000000000..e3af7b4825ea3d57877dd1462dfbb38e9c4c541e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0700.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt0700(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep chown')
+ Step(condition)
+ Step("条件包括/dev/access_token_id..........................")
+ self.driver.Assert.contains(condition, 'chown access_token access_token /dev/access_token_id')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('ls -l /dev/access_token_id')
+ Step(condition)
+ self.driver.Assert.contains(condition, 'access_token access_token')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0800.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0800.json
new file mode 100644
index 0000000000000000000000000000000000000000..2036f07134bd16f76689d2ca23571152033b608c
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0800.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0800.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0800.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0800.py
new file mode 100644
index 0000000000000000000000000000000000000000..7e75eda6fd3fa9d88f7cf6e8858609b07d3f00ba
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0800.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt0800(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep copy')
+ Step(condition)
+ Step("条件包括/dev/urandom..........................")
+ self.driver.Assert.contains(condition, 'copy /proc/cmdline /dev/urandom')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('ls -l /dev/urandom')
+ Step(condition)
+ self.driver.Assert.contains(condition, '/dev/urandom')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0900.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0900.json
new file mode 100644
index 0000000000000000000000000000000000000000..181b6df2a9f5dd41a69091863723018f2d623cb6
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0900.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0900.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0900.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0900.py
new file mode 100644
index 0000000000000000000000000000000000000000..172512df295aef1d1c6e9f19fbfd0a0068497f11
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_0900.py
@@ -0,0 +1,48 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt0900(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep domainname')
+ Step(condition)
+ Step("条件包括domainname..........................")
+ self.driver.Assert.contains(condition, 'domainname localdomain')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('cat /proc/sys/kernel/domainname')
+ Step(condition)
+ if not condition:
+ raise AssertionError("条件未满足")
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1100.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1100.json
new file mode 100644
index 0000000000000000000000000000000000000000..eec966f51d79b9307d68c0eab2b7a37695fdfdb3
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1100.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1100.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1100.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1100.py
new file mode 100644
index 0000000000000000000000000000000000000000..6e6985c3f8d3bef22a6597e831fa4149a0f7019d
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1100.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt1100(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep export')
+ Step(condition)
+ Step("条件包括export..........................")
+ self.driver.Assert.contains(condition, 'export DOWNLOAD_CACHE /data/cache')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('echo $DOWNLOAD_CACHE')
+ Step(condition)
+ self.driver.Assert.contains(condition, '/data/cache')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1200.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1200.json
new file mode 100644
index 0000000000000000000000000000000000000000..038818282a6a46dc34264ad7732972240d328510
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1200.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1200.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1200.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1200.py
new file mode 100644
index 0000000000000000000000000000000000000000..53d2c69c42a8c1d451a8ba1669234379e9aaf04e
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1200.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt1200(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep hostname')
+ Step(condition)
+ Step("条件包括export..........................")
+ self.driver.Assert.contains(condition, 'hostname localhost')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('hostname')
+ Step(condition)
+ self.driver.Assert.contains(condition, 'localhost')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1300.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1300.json
new file mode 100644
index 0000000000000000000000000000000000000000..e547850c8bdb72018e30872ef16156f07bde709f
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1300.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1300.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1300.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1300.py
new file mode 100644
index 0000000000000000000000000000000000000000..6ad4e48074a56796e8fab64d10187da19c49e0da
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1300.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt1300(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep ifup')
+ Step(condition)
+ Step("条件包括export..........................")
+ self.driver.Assert.contains(condition, 'ifup lo')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('ifconfig')
+ Step(condition)
+ self.driver.Assert.contains(condition, 'inet addr:127.0.0.1 Mask:255.0.0.0')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1500.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1500.json
new file mode 100644
index 0000000000000000000000000000000000000000..73b3cb24a93d4f960e444eb06bec40e19e8e02d4
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1500.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1500.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1500.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1500.py
new file mode 100644
index 0000000000000000000000000000000000000000..53ce4c4a021daf13ba45c8c619b6a92ebeef186b
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1500.py
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt1500(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看是否存在watchdog服务..........................")
+ pid = self.driver.System.get_pid('watchdog')
+ Step(pid)
+ self.driver.Assert.equal(pid, None)
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1800.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1800.json
new file mode 100644
index 0000000000000000000000000000000000000000..3d0ab823f5bd4b5043fc651ad1f8678412a4c3d2
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1800.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1800.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1800.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1800.py
new file mode 100644
index 0000000000000000000000000000000000000000..1e1986f591219a86653f613c7386d32030b4e1f4
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_1800.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt1800(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep mkdir')
+ Step(condition)
+ Step("条件包括export..........................")
+ self.driver.Assert.contains(condition, 'mkdir /data')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('ls -ld /data')
+ Step(condition)
+ self.driver.Assert.contains(condition, '/data')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2500.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2500.json
new file mode 100644
index 0000000000000000000000000000000000000000..1aa6911707534dd49fcee9fa391cc8c3c16a1f14
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2500.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2500.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2500.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2500.py
new file mode 100644
index 0000000000000000000000000000000000000000..29ab2cf9e652afc2ca7894c6c0634a41a5aeefaa
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2500.py
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt2500(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep start')
+ Step(condition)
+ Step("条件包括export..........................")
+ self.driver.Assert.contains(condition, 'start ueventd')
+ Step("校验条件是否生效..........................")
+ Step("ueventd..........................")
+ pid = self.driver.System.get_pid('ueventd')
+ Step(pid)
+ if pid is None:
+ raise ValueError("pid is None, this should not happen")
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2700.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2700.json
new file mode 100644
index 0000000000000000000000000000000000000000..7f2b8bca0153c83e60b4ff7c28f358e33b7f2c10
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2700.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2700.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2700.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2700.py
new file mode 100644
index 0000000000000000000000000000000000000000..f1e8d2dec20873ca6d5caef24eba68ecb1bb0051
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2700.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt2700(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep symlink')
+ Step(condition)
+ Step("条件包括export..........................")
+ self.driver.Assert.contains(condition, 'symlink /proc/self/fd /dev/fd')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('ls -ld /dev/fd')
+ Step(condition)
+ self.driver.Assert.contains(condition, '/dev/fd -> /proc/self/fd')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2900.json b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2900.json
new file mode 100644
index 0000000000000000000000000000000000000000..1085681f7ddb7db0b84508d38f7df686f23856a2
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2900.json
@@ -0,0 +1,14 @@
+{
+ "description": "Config for OpenHarmony devicetest test cases",
+ "environment": [
+ {
+ "type": "device"
+ }
+ ],
+ "driver": {
+ "type": "DeviceTest",
+ "py_file": [
+ "SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2900.py"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2900.py b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2900.py
new file mode 100644
index 0000000000000000000000000000000000000000..20ec691db25e43a36e809d008341b0681522e6a5
--- /dev/null
+++ b/test/autotest/testcases/SUB_STARTUP_INIT_SHELLMGT/SUB_STARTUP_INIT_SHELLMGT_2900.py
@@ -0,0 +1,47 @@
+#
+# Copyright (c) 2025 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.
+#
+
+# -*- coding: utf-8 -*-
+from devicetest.core.test_case import Step, TestCase
+from hypium import UiDriver
+
+
+class SubStartupInitShellmgt2900(TestCase):
+
+ def __init__(self, controllers):
+ self.tag = self.__class__.__name__
+ self.tests = [
+ "test_step1"
+ ]
+ TestCase.__init__(self, self.tag, controllers)
+ self.driver = UiDriver(self.device1)
+
+ def setup(self):
+ Step("预置工作:初始化手机开始.................")
+ Step(self.devices[0].device_id)
+
+ def test_step1(self):
+ Step("查看条件..........................")
+ condition = self.driver.shell('cat /etc/init.cfg|grep write')
+ Step(condition)
+ Step("条件包括export..........................")
+ self.driver.Assert.contains(condition, 'write /proc/sys/kernel/dmesg_restrict 1')
+ Step("校验条件是否生效..........................")
+ condition = self.driver.shell('cat /proc/sys/kernel/dmesg_restrict')
+ Step(condition)
+ self.driver.Assert.contains(condition, '1')
+
+ def teardown(self):
+ Step("收尾工作.................")
diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn
index 94e8734c917315e9084bacb751caa4cd04943b29..7d9ac4bb529990d744d8b90048f4fb590436cdc8 100644
--- a/test/fuzztest/BUILD.gn
+++ b/test/fuzztest/BUILD.gn
@@ -450,12 +450,31 @@ ohos_fuzztest("WatchParameterFuzzTest") {
"//base/startup/init/interfaces/innerkits/include/param",
"//base/startup/init/services/init/include",
"//base/startup/init/test/fuzztest/utils/include",
+ "//base/startup/init/services/param/watcher/agent",
+ "//base/startup/init/services/param/watcher/include",
+ "//base/startup/init/services/log",
]
deps = [
"//base/startup/init/interfaces/innerkits:libbeget_proxy",
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//base/startup/init/test/fuzztest:libfuzz_utils",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_proxy",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ ]
+
+ include_dirs += [
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/services/param/watcher/proxy",
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/services/loopevent/include",
+ "//base/startup/init/services/param/linux",
+ ]
+
+ deps += [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ "//base/startup/init/services/log:agent_log",
]
external_deps = [
@@ -477,6 +496,7 @@ ohos_fuzztest("WatchParameterFuzzTest") {
defines = [ "STARTUP_INIT_TEST" ]
}
+
ohos_fuzztest("UmountAllWithFstabFileFuzzTest") {
module_out_path = module_output_path
fuzz_config_file =
@@ -2866,6 +2886,206 @@ ohos_fuzztest("GetFeatureVersionFuzzTest") {
defines = [ "STARTUP_INIT_TEST" ]
}
+ohos_fuzztest("MountOneWithFstabFileFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file =
+ "//base/startup/init/test/fuzztest/mountonewithfstabfile_fuzzer"
+
+ include_dirs = [
+ "//base/startup/init/interfaces/innerkits/fs_manager",
+ "//base/startup/init/interfaces/innerkits/include/fs_manager",
+ "//base/startup/init/test/fuzztest/utils/include",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static",]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "cJSON:cjson",
+ ]
+ external_deps += [ "hilog:libhilog" ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [
+ "mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp",
+ ]
+ defines = [ "STARTUP_INIT_TEST" ]
+}
+
+ohos_fuzztest("AddParamEntryFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file =
+ "//base/startup/init/test/fuzztest/addparamentry_fuzzer"
+
+ include_dirs = [
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/services/param:parameter",]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ ]
+ external_deps += [ "hilog:libhilog" ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [
+ "addparamentry_fuzzer/addparamentry_fuzzer.cpp",
+ ]
+ defines = [ "STARTUP_INIT_TEST" ]
+}
+
+ohos_fuzztest("InitWorkSpaceFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file =
+ "//base/startup/init/test/fuzztest/initworkspace_fuzzer"
+
+ include_dirs = [
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/services/param:parameter",]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ ]
+ external_deps += [ "hilog:libhilog" ]
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources = [
+ "initworkspace_fuzzer/initworkspace_fuzzer.cpp",
+ ]
+ defines = [ "STARTUP_INIT_TEST" ]
+}
+
+ohos_fuzztest("CheckAppWatchPermissionFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file = "//base/startup/init/test/fuzztest/checkappwatchpermission_fuzzer"
+
+ sources = [
+ "//base/startup/init/services/param/linux/param_message.c",
+ "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp",
+ ]
+ include_dirs = [
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ "//base/startup/init/services/param/watcher/proxy",
+ "//base/startup/init/services/param/watcher/include",
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/interfaces/innerkits/include/param",
+ "//base/startup/init/services/param/linux",
+ "//base/startup/init/services/loopevent/include",
+ "//base/startup/init/services/param/watcher/agent",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ "//base/startup/init/services/log:agent_log",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "c_utils:utils",
+ "hilog:libhilog",
+ "ipc:ipc_single",
+ "safwk:system_ability_fwk",
+ "samgr:samgr_proxy",
+ ]
+ if (init_paramwatcher_hicollie_enable) {
+ external_deps += [ "hicollie:libhicollie" ]
+ }
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources += [ "checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp" ]
+ defines = [ "STARTUP_INIT_TEST" ]
+ if (init_paramwatcher_hicollie_enable) {
+ defines += [ "HICOLLIE_ENABLE" ]
+ }
+}
+
+ohos_fuzztest("OnStopFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file = "//base/startup/init/test/fuzztest/onstop_fuzzer"
+
+ sources = [
+ "//base/startup/init/services/param/linux/param_message.c",
+ "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp",
+ ]
+ include_dirs = [
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ "//base/startup/init/services/param/watcher/proxy",
+ "//base/startup/init/services/param/watcher/include",
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/interfaces/innerkits/include/param",
+ "//base/startup/init/services/param/linux",
+ "//base/startup/init/services/loopevent/include",
+ "//base/startup/init/services/param/watcher/agent",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ "//base/startup/init/services/log:agent_log",
+ ]
+ sources += [
+ "//base/startup/init/services/param/watcher/agent/watcher.cpp",
+ "//base/startup/init/services/param/watcher/agent/watcher_manager_kits.cpp",
+ ]
+ deps += [
+ "//base/startup/init/interfaces/innerkits/:param_watcher_proxy",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "c_utils:utils",
+ "hilog:libhilog",
+ "ipc:ipc_single",
+ "safwk:system_ability_fwk",
+ "samgr:samgr_proxy",
+ ]
+ if (init_paramwatcher_hicollie_enable) {
+ external_deps += [ "hicollie:libhicollie" ]
+ }
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources += [ "onstop_fuzzer/onstop_fuzzer.cpp" ]
+ defines = [ "STARTUP_INIT_TEST" ]
+ if (init_paramwatcher_hicollie_enable) {
+ defines += [ "HICOLLIE_ENABLE" ]
+ }
+}
+
ohos_fuzztest("GetBuildVersionFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//base/startup/init/test/fuzztest/getbuildversion_fuzzer"
@@ -2985,6 +3205,14 @@ ohos_fuzztest("AddRemoteWatcherFuzzTest") {
"//base/startup/init/interfaces/innerkits/:param_watcher_stub",
"//base/startup/init/services/log:agent_log",
]
+ sources += [
+ "//base/startup/init/services/param/watcher/agent/watcher.cpp",
+ "//base/startup/init/services/param/watcher/agent/watcher_manager_kits.cpp",
+ ]
+ deps += [
+ "//base/startup/init/interfaces/innerkits/:param_watcher_proxy",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ ]
external_deps = [
"bounds_checking_function:libsec_static",
"c_utils:utils",
@@ -3095,6 +3323,30 @@ ohos_fuzztest("AddWatcherFuzzTest") {
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
+ sources += [
+ "//base/startup/init/services/param/watcher/agent/watcher.cpp",
+ "//base/startup/init/services/param/watcher/agent/watcher_manager_kits.cpp",
+ ]
+
+ deps += [
+ "//base/startup/init/interfaces/innerkits/:param_watcher_proxy",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ ]
+
+ external_deps += [
+ "bounds_checking_function:libsec_static",
+ "cJSON:cjson",
+ "c_utils:utils",
+ "config_policy:configpolicy_util_for_init_static",
+ "googletest:gmock",
+ "googletest:gtest",
+ "hilog:libhilog",
+ "hisysevent:libhisysevent",
+ "init:libinit_module_engine",
+ "mbedtls:mbedtls_shared",
+ "selinux:libselinux",
+ "zlib:libz",
+ ]
if (init_paramwatcher_hicollie_enable) {
external_deps += [ "hicollie:libhicollie" ]
}
@@ -3112,6 +3364,7 @@ ohos_fuzztest("AddWatcherFuzzTest") {
}
}
+
ohos_fuzztest("DelWatcherFuzzTest") {
module_out_path = module_output_path
fuzz_config_file = "//base/startup/init/test/fuzztest/delwatcher_fuzzer"
@@ -3590,6 +3843,229 @@ ohos_fuzztest("SplitStringFuzzTest") {
defines = [ "STARTUP_INIT_TEST" ]
}
+ohos_fuzztest("SendLocalChangeFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file = "//base/startup/init/test/fuzztest/sendlocalchange_fuzzer"
+
+ sources = [
+ "//base/startup/init/services/param/linux/param_message.c",
+ "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp",
+ ]
+ include_dirs = [
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ "//base/startup/init/services/param/watcher/proxy",
+ "//base/startup/init/services/param/watcher/include",
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/interfaces/innerkits/include/param",
+ "//base/startup/init/services/param/linux",
+ "//base/startup/init/services/loopevent/include",
+ "//base/startup/init/services/param/watcher/agent",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ "//base/startup/init/services/log:agent_log",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "c_utils:utils",
+ "hilog:libhilog",
+ "ipc:ipc_single",
+ "safwk:system_ability_fwk",
+ "samgr:samgr_proxy",
+ ]
+ if (init_paramwatcher_hicollie_enable) {
+ external_deps += [ "hicollie:libhicollie" ]
+ }
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources += [ "sendlocalchange_fuzzer/sendlocalchange_fuzzer.cpp" ]
+ defines = [ "STARTUP_INIT_TEST" ]
+ if (init_paramwatcher_hicollie_enable) {
+ defines += [ "HICOLLIE_ENABLE" ]
+ }
+}
+
+ohos_fuzztest("AddWatcherGroupFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file = "//base/startup/init/test/fuzztest/addwatchergroup_fuzzer"
+
+ sources = [
+ "//base/startup/init/services/param/linux/param_message.c",
+ "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp",
+ ]
+ include_dirs = [
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ "//base/startup/init/services/param/watcher/proxy",
+ "//base/startup/init/services/param/watcher/include",
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/interfaces/innerkits/include/param",
+ "//base/startup/init/services/param/linux",
+ "//base/startup/init/services/loopevent/include",
+ "//base/startup/init/services/param/watcher/agent",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ "//base/startup/init/services/log:agent_log",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "c_utils:utils",
+ "hilog:libhilog",
+ "ipc:ipc_single",
+ "safwk:system_ability_fwk",
+ "samgr:samgr_proxy",
+ ]
+ if (init_paramwatcher_hicollie_enable) {
+ external_deps += [ "hicollie:libhicollie" ]
+ }
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources += [ "addwatchergroup_fuzzer/addwatchergroup_fuzzer.cpp" ]
+ defines = [ "STARTUP_INIT_TEST" ]
+ if (init_paramwatcher_hicollie_enable) {
+ defines += [ "HICOLLIE_ENABLE" ]
+ }
+}
+
+ohos_fuzztest("DUMPFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file = "//base/startup/init/test/fuzztest/dump_fuzzer"
+
+ sources = [
+ "//base/startup/init/services/param/linux/param_message.c",
+ "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp",
+ ]
+ include_dirs = [
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ "//base/startup/init/services/param/watcher/proxy",
+ "//base/startup/init/services/param/watcher/include",
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/interfaces/innerkits/include/param",
+ "//base/startup/init/services/param/linux",
+ "//base/startup/init/services/loopevent/include",
+ "//base/startup/init/services/param/watcher/agent",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ "//base/startup/init/services/log:agent_log",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "c_utils:utils",
+ "hilog:libhilog",
+ "ipc:ipc_single",
+ "safwk:system_ability_fwk",
+ "samgr:samgr_proxy",
+ ]
+ if (init_paramwatcher_hicollie_enable) {
+ external_deps += [ "hicollie:libhicollie" ]
+ }
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources += [ "dump_fuzzer/dump_fuzzer.cpp" ]
+ defines = [ "STARTUP_INIT_TEST" ]
+ if (init_paramwatcher_hicollie_enable) {
+ defines += [ "HICOLLIE_ENABLE" ]
+ }
+}
+
+ohos_fuzztest("OnRemoteDiedFuzzTest") {
+ module_out_path = module_output_path
+ fuzz_config_file = "//base/startup/init/test/fuzztest/onremotedied_fuzzer"
+
+ sources = [
+ "//base/startup/init/services/param/linux/param_message.c",
+ "//base/startup/init/services/param/watcher/proxy/watcher_manager.cpp",
+ ]
+ include_dirs = [
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/test/fuzztest/utils/include",
+ "//base/startup/init/services/param/watcher/proxy",
+ "//base/startup/init/services/param/watcher/include",
+ "//base/startup/init/services/param/include",
+ "//base/startup/init/interfaces/innerkits/include/param",
+ "//base/startup/init/services/param/linux",
+ "//base/startup/init/services/loopevent/include",
+ "//base/startup/init/services/param/watcher/agent",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ "//base/startup/init/services/log:agent_log",
+ ]
+ sources += [
+ "//base/startup/init/services/param/watcher/agent/watcher.cpp",
+ "//base/startup/init/services/param/watcher/agent/watcher_manager_kits.cpp",
+ ]
+ deps += [
+ "//base/startup/init/interfaces/innerkits/:param_watcher_proxy",
+ "//base/startup/init/interfaces/innerkits/:param_watcher_stub",
+ ]
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "c_utils:utils",
+ "hilog:libhilog",
+ "ipc:ipc_single",
+ "safwk:system_ability_fwk",
+ "samgr:samgr_proxy",
+ ]
+ external_deps += [
+ "bounds_checking_function:libsec_static",
+ "cJSON:cjson",
+ "c_utils:utils",
+ "config_policy:configpolicy_util_for_init_static",
+ "googletest:gmock",
+ "googletest:gtest",
+ "hilog:libhilog",
+ "hisysevent:libhisysevent",
+ "init:libinit_module_engine",
+ "mbedtls:mbedtls_shared",
+ "selinux:libselinux",
+ "zlib:libz",
+ ]
+
+ if (init_paramwatcher_hicollie_enable) {
+ external_deps += [ "hicollie:libhicollie" ]
+ }
+
+ cflags = [
+ "-g",
+ "-O0",
+ "-Wno-unused-variable",
+ "-fno-omit-frame-pointer",
+ ]
+ sources += [ "onremotedied_fuzzer/onremotedied_fuzzer.cpp" ]
+ defines = [ "STARTUP_INIT_TEST" ]
+ if (init_paramwatcher_hicollie_enable) {
+ defines += [ "HICOLLIE_ENABLE" ]
+ }
+}
+
##############################################################################################
group("fuzztest") {
testonly = true
@@ -3599,10 +4075,13 @@ group("fuzztest") {
":AclGetDiskSNFuzzTest",
":AclGetSerialFuzzTest",
":AddRemoteWatcherFuzzTest",
+ ":AddParamEntryFuzzTest",
":AddWatcherFuzzTest",
+ ":AddWatcherGroupFuzzTest",
":BuildControlMessageFuzzTest",
":ChangeSysAttributePermissionsFuzzTest",
":CheckAndCreatFileFuzzTest",
+ ":CheckAppWatchPermissionFuzzTest",
":CmdClientInitFuzzTest",
":CmdServiceProcessDelClientFuzzTest",
":DecodeGidFuzzTest",
@@ -3610,6 +4089,7 @@ group("fuzztest") {
":DelRemoteWatcherFuzzTest",
":DelWatcherFuzzTest",
":DoFormatFuzzTest",
+ ":DUMPFuzzTest",
":FindFstabItemForMountPointFuzzTest",
":FindFstabItemForPathFuzzTest",
":FindParameterFuzzTest",
@@ -3678,6 +4158,7 @@ group("fuzztest") {
":HookMgrGetHooksCntFuzzTest",
":HookMgrGetStagesCntFuzzTest",
":HookMgrTraversalFuzzTest",
+ ":InitWorkSpaceFuzzTest",
":IsSupportedFilesystemFuzzTest",
":LoadFscryptPolicyFuzzTest",
":LoadFstabFromCommandLineFuzzTest",
@@ -3692,6 +4173,7 @@ group("fuzztest") {
":MountAllWithFstabFileFuzzTest",
":MountAllWithFstabFuzzTest",
":MountOneItemFuzzTest",
+ ":MountOneWithFstabFileFuzzTest",
":ParseFstabPerLineFuzzTest",
":ParseUeventConfigFuzzTest",
":ParseUeventdConfigFileFuzzTest",
@@ -3702,6 +4184,7 @@ group("fuzztest") {
":RefreshWatcherFuzzTest",
":ReleaseFstabFuzzTest",
":RemoveParameterWatcherFuzzTest",
+ ":SendLocalChangeFuzzTest",
":ServiceControlFuzzTest",
":ServiceControlStartFuzzTest",
":ServiceControlStopFuzzTest",
@@ -3725,6 +4208,8 @@ group("fuzztest") {
":WaitParameterFuzzTest",
":WatchParameterFuzzTest",
":WriteAllFuzzTest",
+ ":OnRemoteDiedFuzzTest",
+ ":OnStopFuzzTest",
]
}
###############################################################################
diff --git a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..700afbbb37e858f8c6c907029a582e37b34dc70a
--- /dev/null
+++ b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "addparamentry_fuzzer.h"
+#include
+#include
+#include "param_trie.h"
+#include "param_manager.h"
+#include "securec.h"
+constexpr int DATA_SIZE = 2;
+constexpr int INDEX_MAX = 1000;
+constexpr int TYPE_MAX = 5;
+
+namespace OHOS {
+ bool FuzzAddParamEntry(const uint8_t* data, size_t size)
+ {
+ if (size < sizeof(uint32_t)) {
+ return false;
+ }
+
+ size_t splitPos = size / DATA_SIZE;
+ if (splitPos == 0) {
+ splitPos = 1;
+ }
+
+ std::unique_ptr name(new char[splitPos + 1]);
+ if (memcpy_s(name.get(), splitPos + 1, data, splitPos) != 0) {
+ return false;
+ }
+ name[splitPos] = '\0';
+
+ size_t valueSize = size - splitPos;
+ std::unique_ptr value(new char[valueSize + 1]);
+ if (memcpy_s(value.get(), valueSize + 1, data + splitPos, valueSize) != 0) {
+ return false;
+ }
+ value[valueSize] = '\0';
+
+ uint32_t index = 0;
+ if (memcpy_s(&index, sizeof(uint32_t), data, sizeof(uint32_t)) != 0) {
+ index = 0;
+ }
+ index %= INDEX_MAX;
+
+ uint8_t type = 0;
+ if (size > 0) {
+ type = data[0] % TYPE_MAX;
+ }
+
+ return (AddParamEntry(index, type, name.get(), value.get()) == 0);
+ }
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ OHOS::FuzzAddParamEntry(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..72d69b470c74eac4ac96ff9f2ff4f56b4f700e8e
--- /dev/null
+++ b/test/fuzztest/addparamentry_fuzzer/addparamentry_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+#ifndef TEST_FUZZTEST_ADD_PARAM_ENTRY_H
+#define TEST_FUZZTEST_ADD_PARAM_ENTRY_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "addparamentry_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/addparamentry_fuzzer/corpus/init b/test/fuzztest/addparamentry_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5
--- /dev/null
+++ b/test/fuzztest/addparamentry_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/addparamentry_fuzzer/project.xml b/test/fuzztest/addparamentry_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a
--- /dev/null
+++ b/test/fuzztest/addparamentry_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp b/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp
index fff638a7345039756941b8939d0eec2997724994..dfbb6a330f4591ca93ebe05c079ee69d36067831 100644
--- a/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp
+++ b/test/fuzztest/addremotewatcher_fuzzer/addremotewatcher_fuzzer.cpp
@@ -13,21 +13,38 @@
* limitations under the License.
*/
+#include "watcher.h"
+#include "watcher_proxy.h"
#include "addremotewatcher_fuzzer.h"
#include
#include
+#include "watcher_utils.h"
+#define protected public
#include "watcher_manager.h"
-
+#undef protected
using namespace OHOS::init_param;
+
+class FuzzWatcher final : public Watcher {
+public:
+ FuzzWatcher() {}
+ ~FuzzWatcher() = default;
+ int32_t OnParameterChange(const std::string &prefix, const std::string &name, const std::string &value) override
+ {
+ return 0;
+ }
+};
namespace OHOS {
bool FuzzAddRemoteWatcher(const uint8_t* data, size_t size)
{
bool result = false;
+ sptr watcher = new FuzzWatcher();
std::unique_ptr watcherManager = std::make_unique(0, true);
uint32_t id = static_cast(*data);
uint32_t watcherId = 0;
- if (!watcherManager->AddRemoteWatcher(id, watcherId, nullptr)) {
+ watcherManager->OnStart();
+ if (!watcherManager->AddRemoteWatcher(id, watcherId, watcher)) {
result = true;
+ watcherManager->DelRemoteWatcher(watcherId);
};
return result;
}
diff --git a/test/fuzztest/addwatcher_fuzzer/addwatcher_fuzzer.cpp b/test/fuzztest/addwatcher_fuzzer/addwatcher_fuzzer.cpp
index 63651405bba3b8a86b766952971574b8fadeac12..283160f3fc4fc1c01c83fb7b9c6f66391e1e2461 100644
--- a/test/fuzztest/addwatcher_fuzzer/addwatcher_fuzzer.cpp
+++ b/test/fuzztest/addwatcher_fuzzer/addwatcher_fuzzer.cpp
@@ -14,22 +14,156 @@
*/
#include "addwatcher_fuzzer.h"
-#include
-#include
+#include "if_system_ability_manager.h"
+#include "iservice_registry.h"
+#include "iwatcher.h"
+#include "iwatcher_manager.h"
+#include "message_parcel.h"
+#include "param_message.h"
+#include "init_param.h"
+#include "param_utils.h"
+#include "parcel.h"
+#include "securec.h"
+#include "system_ability_definition.h"
+#include "string_ex.h"
+#include "watcher.h"
+#include "watcher_proxy.h"
+#include "watcher_utils.h"
+#define private public
+#define protected public
#include "watcher_manager.h"
+#undef protected
+#undef private
using namespace OHOS::init_param;
+using WatcherManagerPtr = WatcherManager *;
+class TestWatcher final : public Watcher {
+public:
+ TestWatcher() {}
+ ~TestWatcher() = default;
+
+ int32_t OnParameterChange(const std::string &prefix, const std::string &name, const std::string &value) override
+ {
+ printf("TestWatcher::OnParameterChange name %s %s \n", name.c_str(), value.c_str());
+ return 0;
+ }
+};
namespace OHOS {
+ WatcherManagerPtr GetWatcherManager()
+ {
+ static WatcherManagerPtr watcherManager_ = nullptr;
+ if (watcherManager_ == nullptr) {
+ watcherManager_ = new WatcherManager(0, true);
+ if (watcherManager_ == nullptr) {
+ return nullptr;
+ }
+ watcherManager_->OnStart();
+ }
+ return watcherManager_;
+ }
+
+ int FuzzTestAddRemoteWatcher(uint32_t agentId, uint32_t &watcherId)
+ {
+ WatcherManagerPtr watcherManager = GetWatcherManager();
+ WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager");
+ MessageParcel data;
+ MessageParcel reply;
+ MessageOption option;
+
+ data.WriteInterfaceToken(IWatcherManager::GetDescriptor());
+ data.WriteUint32(agentId);
+ sptr watcher = new TestWatcher();
+ bool ret = data.WriteRemoteObject(watcher->AsObject());
+
+ WATCHER_CHECK(ret, return 0, "Can not get remote");
+ watcherManager->OnRemoteRequest(
+ static_cast (IWatcherManagerIpcCode::COMMAND_ADD_REMOTE_WATCHER), data, reply, option);
+ reply.ReadInt32();
+ watcherId = reply.ReadUint32();
+
+ auto remoteWatcher = watcherManager->GetRemoteWatcher(watcherId);
+ if (remoteWatcher == nullptr) {
+ return -1;
+ }
+ return 0;
+ }
+
+ int FuzzTestAddWatcher(const std::string &keyPrefix, uint32_t watcherId)
+ {
+ WatcherManagerPtr watcherManager = GetWatcherManager();
+ WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager");
+ MessageParcel data;
+ MessageParcel reply;
+ MessageOption option;
+
+ data.WriteInterfaceToken(IWatcherManager::GetDescriptor());
+ data.WriteString16(Str8ToStr16(keyPrefix));
+ data.WriteUint32(watcherId);
+ watcherManager->OnRemoteRequest(
+ static_cast (IWatcherManagerIpcCode::COMMAND_ADD_WATCHER), data, reply, option);
+ return 0;
+ }
+
+ int FuzzTestWatchAgentDump(const std::string &keyPrefix)
+ {
+ WatcherManagerPtr watcherManager = GetWatcherManager();
+ std::vector args = {};
+ watcherManager->Dump(STDOUT_FILENO, args);
+ // dump parameter
+ args.push_back(Str8ToStr16("-h"));
+ watcherManager->Dump(STDOUT_FILENO, args);
+ args.clear();
+ args.push_back(Str8ToStr16("-k"));
+ args.push_back(Str8ToStr16(keyPrefix.c_str()));
+ watcherManager->Dump(STDOUT_FILENO, args);
+ return 0;
+ }
+
+ int FuzzTestDelWatcher(const std::string &keyPrefix, uint32_t watcherId)
+ {
+ WatcherManagerPtr watcherManager = GetWatcherManager();
+ WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to create manager");
+ MessageParcel data;
+ MessageParcel reply;
+ MessageOption option;
+ data.WriteInterfaceToken(IWatcherManager::GetDescriptor());
+ data.WriteString16(Str8ToStr16(keyPrefix));
+ data.WriteUint32(watcherId);
+ watcherManager->OnRemoteRequest(
+ static_cast (IWatcherManagerIpcCode::COMMAND_DEL_WATCHER), data, reply, option);
+ return 0;
+ }
+
bool FuzzAddWatcher(const uint8_t* data, size_t size)
{
- bool result = false;
+ if (size < sizeof(uint32_t)) {
+ return false;
+ }
std::unique_ptr watcherManager = std::make_unique(0, true);
std::string str(reinterpret_cast(data), size);
+ uint32_t watcherId = 0;
+
+ FuzzTestAddRemoteWatcher(getpid(), watcherId);
+ FuzzTestAddWatcher("test.permission.watcher.test1", 0);
+ FuzzTestAddWatcher("test.permission.watcher.test1", 0);
+ FuzzTestDelWatcher("test.permission.watcher.test1", 0);
+ watcherId = 1;
+ FuzzTestAddRemoteWatcher(getpid(), watcherId);
+ FuzzTestAddWatcher("test.permission.watcher.test1", 1);
+ FuzzTestWatchAgentDump("test.permission.watcher.test1");
+ FuzzTestDelWatcher("test.permission.watcher.test1", 1);
- if (!watcherManager->AddWatcher(str, 0)) {
- result = true;
+ uint32_t randomValue = 0;
+ errno_t ret = memcpy_s(&randomValue, sizeof(randomValue), data, sizeof(uint32_t));
+ if (ret != 0) {
+ return false;
+ }
+ if (!FuzzTestAddWatcher(str, randomValue)) {
+ FuzzTestWatchAgentDump(str);
+ FuzzTestDelWatcher(str, randomValue);
+ return true;
};
- return result;
+ return false;
}
}
diff --git a/test/fuzztest/addwatchergroup_fuzzer/addwatchergroup_fuzzer.cpp b/test/fuzztest/addwatchergroup_fuzzer/addwatchergroup_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..99c87a128d61b9b29cd7a4eaf72e478c2d62b84c
--- /dev/null
+++ b/test/fuzztest/addwatchergroup_fuzzer/addwatchergroup_fuzzer.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2025 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
+#include
+#include "addwatchergroup_fuzzer.h"
+#include "init_utils.h"
+#include "securec.h"
+#define private public
+#include "watcher_manager.h"
+#undef private
+using namespace OHOS::init_param;
+
+namespace OHOS {
+ bool FuzzAddWatcherGroup(const uint8_t* data, size_t size)
+ {
+ bool result = false;
+ std::unique_ptr watcherManager = std::make_unique(0, true);
+ std::string str(reinterpret_cast(data), size);
+
+ if (!watcherManager->AddWatcherGroup(str)) {
+ result = true;
+ auto group = watcherManager->GetWatcherGroup(str);
+ watcherManager->DelWatcherGroup(group);
+ };
+ return result;
+ }
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::FuzzAddWatcherGroup(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/addwatchergroup_fuzzer/addwatchergroup_fuzzer.h b/test/fuzztest/addwatchergroup_fuzzer/addwatchergroup_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..168a9d1aab347edac9c6d6fc623b4009971b162f
--- /dev/null
+++ b/test/fuzztest/addwatchergroup_fuzzer/addwatchergroup_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2025 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 TEST_FUZZTEST_ADD_WATCHER_GROUP_FUZZER_H
+#define TEST_FUZZTEST_ADD_WATCHER_GROUP_FUZZER_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "addwatchergroup_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/addwatchergroup_fuzzer/corpus/init b/test/fuzztest/addwatchergroup_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932
--- /dev/null
+++ b/test/fuzztest/addwatchergroup_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/addwatchergroup_fuzzer/project.xml b/test/fuzztest/addwatchergroup_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b39473f2f6776874287a2de22477705b1b60385c
--- /dev/null
+++ b/test/fuzztest/addwatchergroup_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5cb66cd2139201e04b0609560334786aa41817ff
--- /dev/null
+++ b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2024 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 "checkappwatchpermission_fuzzer.h"
+#include
+#include
+#include "init_utils.h"
+#define private public
+#include "watcher_manager.h"
+#undef private
+using namespace OHOS::init_param;
+
+namespace OHOS {
+bool FuzzCheckAppWatchPermission(const uint8_t* data, size_t size)
+ {
+ bool result = false;
+ std::string str(reinterpret_cast(data), size);
+ std::unique_ptr watcherManager = std::make_unique(0, true);
+ if (watcherManager->CheckAppWatchPermission(str)) {
+ result = true;
+ };
+ return result;
+ }
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::FuzzCheckAppWatchPermission(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.h b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..a75c318b3fe1106c04afab24471a9dadf54db2bd
--- /dev/null
+++ b/test/fuzztest/checkappwatchpermission_fuzzer/checkappwatchpermission_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2024 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 TEST_FUZZTEST_CHECK_APP_WATCH_PERMISSION_FUZZER_H
+#define TEST_FUZZTEST_CHECK_APP_WATCH_PERMISSION_FUZZER_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "checkappwatchpermission_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/corpus/init b/test/fuzztest/checkappwatchpermission_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5
--- /dev/null
+++ b/test/fuzztest/checkappwatchpermission_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/checkappwatchpermission_fuzzer/project.xml b/test/fuzztest/checkappwatchpermission_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..9e35ed57fbc05fcaac3016839def9debdf5b9d74
--- /dev/null
+++ b/test/fuzztest/checkappwatchpermission_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/dump_fuzzer/corpus/init b/test/fuzztest/dump_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932
--- /dev/null
+++ b/test/fuzztest/dump_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/dump_fuzzer/dump_fuzzer.cpp b/test/fuzztest/dump_fuzzer/dump_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..80954c6d69ad25fcc7cefaa2a616ffbe8fa69867
--- /dev/null
+++ b/test/fuzztest/dump_fuzzer/dump_fuzzer.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2025 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
+#include
+#include
+#include
+#include "dump_fuzzer.h"
+#include "init_utils.h"
+#include "securec.h"
+#define protected public
+#include "watcher_manager.h"
+#undef private
+using namespace OHOS::init_param;
+
+namespace OHOS {
+ std::vector ParseFuzzDataToArgs(const uint8_t* data, size_t size)
+ {
+ std::vector args;
+ if (size == 0) return args;
+
+ std::string input(reinterpret_cast(data), size);
+ size_t start = 0;
+ size_t end = input.find('\n');
+ while (end != std::string::npos) {
+ std::string token = input.substr(start, end - start);
+ if (!token.empty()) {
+ args.emplace_back(token.begin(), token.end());
+ }
+ start = end + 1;
+ end = input.find('\n', start);
+ }
+ if (start < input.size()) {
+ std::string token = input.substr(start);
+ args.emplace_back(token.begin(), token.end());
+ }
+ return args;
+ }
+
+ bool FuzzAddDUMP(const uint8_t* data, size_t size)
+ {
+ std::unique_ptr watcherManager = std::make_unique(0, true);
+ int fd = open("/dev/null", O_WRONLY);
+ std::vector args = ParseFuzzDataToArgs(data, size);
+ watcherManager->Dump(fd, args);
+ close(fd);
+ return true;
+ }
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::FuzzAddDUMP(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/dump_fuzzer/dump_fuzzer.h b/test/fuzztest/dump_fuzzer/dump_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..49b53db92360f35be0d5297b9f1556f7d033629f
--- /dev/null
+++ b/test/fuzztest/dump_fuzzer/dump_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2025 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 TEST_FUZZTEST_DUMP_FUZZER_H
+#define TEST_FUZZTEST_DUMP_FUZZER_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "dump_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/dump_fuzzer/project.xml b/test/fuzztest/dump_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b39473f2f6776874287a2de22477705b1b60385c
--- /dev/null
+++ b/test/fuzztest/dump_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/initworkspace_fuzzer/corpus/init b/test/fuzztest/initworkspace_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5
--- /dev/null
+++ b/test/fuzztest/initworkspace_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.cpp b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..88d1b4f639764554097884099e485dc232dc0e76
--- /dev/null
+++ b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "initworkspace_fuzzer.h"
+#include
+#include
+#include "param_trie.h"
+#include "param_manager.h"
+#include "securec.h"
+constexpr int DATA_SIZE = 2;
+
+namespace OHOS {
+ bool FuzzInitWorkSpace(const uint8_t* data, size_t size)
+ {
+ constexpr size_t minSize = sizeof(uint32_t) * DATA_SIZE;
+ if (size < minSize) {
+ return false;
+ }
+
+ uint32_t spaceSize = 0;
+ if (memcpy_s(&spaceSize, sizeof(uint32_t), data, sizeof(uint32_t)) != 0) {
+ return false;
+ }
+ data += sizeof(uint32_t);
+ size -= sizeof(uint32_t);
+
+ int onlyRead = 0;
+ if (memcpy_s(&onlyRead, sizeof(int), data, sizeof(int)) != 0) {
+ return false;
+ }
+ WorkSpace *workSpace = GetWorkSpace(0);
+
+ return (InitWorkSpace(workSpace, onlyRead, spaceSize) == 0);
+ }
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ OHOS::FuzzInitWorkSpace(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.h b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..19f5ca4c09129fe1ac2016792bbda93c0f13c0d5
--- /dev/null
+++ b/test/fuzztest/initworkspace_fuzzer/initworkspace_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+#ifndef TEST_FUZZTEST_INIT_WORK_SPACE_H
+#define TEST_FUZZTEST_INIT_WORK_SPACE_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "initworkspace_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/initworkspace_fuzzer/project.xml b/test/fuzztest/initworkspace_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a
--- /dev/null
+++ b/test/fuzztest/initworkspace_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/corpus/init b/test/fuzztest/mountonewithfstabfile_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5
--- /dev/null
+++ b/test/fuzztest/mountonewithfstabfile_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0573214b1a8a73fc3832ef3f7ad29650ebeaf280
--- /dev/null
+++ b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.cpp
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+#include "mountonewithfstabfile_fuzzer.h"
+#include "securec.h"
+#include
+#include
+#include
+#include "fs_manager.h"
+#include
+
+namespace OHOS {
+ bool FuzzMountOneWithFstabFile(const uint8_t* data, size_t size)
+ {
+ char fstabPath[] = "/tmp/fuzz_fstab_1";
+ int fd = mkstemp(fstabPath);
+ if (fd < 0) {
+ return false;
+ }
+
+ std::string str(reinterpret_cast(data), size);
+
+ int ret = MountOneWithFstabFile(fstabPath, str.c_str(), false);
+ unlink(fstabPath);
+ if (ret == 0) {
+ return true;
+ }
+ return false;
+ }
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ OHOS::FuzzMountOneWithFstabFile(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.h b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..fd3a697d3f76f54793cb3ec6aeac5addea8c125e
--- /dev/null
+++ b/test/fuzztest/mountonewithfstabfile_fuzzer/mountonewithfstabfile_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+#ifndef TEST_FUZZTEST_MOUNT_ONE_WITH_FSTABFILE_H
+#define TEST_FUZZTEST_MOUNT_ONE_WITH_FSTABFILE_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "mountoneWithfstabfile_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/mountonewithfstabfile_fuzzer/project.xml b/test/fuzztest/mountonewithfstabfile_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a
--- /dev/null
+++ b/test/fuzztest/mountonewithfstabfile_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/onremotedied_fuzzer/corpus/init b/test/fuzztest/onremotedied_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932
--- /dev/null
+++ b/test/fuzztest/onremotedied_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/onremotedied_fuzzer/onremotedied_fuzzer.cpp b/test/fuzztest/onremotedied_fuzzer/onremotedied_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8ab3537a5dac2b7dbaf197ec217accc28260604b
--- /dev/null
+++ b/test/fuzztest/onremotedied_fuzzer/onremotedied_fuzzer.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2025 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 "onremotedied_fuzzer.h"
+#include "if_system_ability_manager.h"
+#include "init_param.h"
+#include "iservice_registry.h"
+#include "iwatcher.h"
+#include "iwatcher_manager.h"
+#include "message_parcel.h"
+#include "parameter.h"
+#include "param_manager.h"
+#include "param_utils.h"
+#include "system_ability_definition.h"
+#include "watcher.h"
+#include "watcher_manager.h"
+#include "watcher_manager_proxy.h"
+#include "service_watcher.h"
+#define private public
+#define protected public
+#include "watcher_manager_kits.h"
+#undef protected
+#undef private
+using namespace OHOS::init_param;
+
+namespace OHOS {
+bool FuzzOnRemoteDied(const uint8_t* data, size_t size)
+ {
+ int value = 0;
+ if (data == nullptr || size < sizeof(int)) {
+ return false;
+ }
+ errno_t err = memcpy_s(&value, sizeof(int), data, sizeof(int));
+ if (err != 0) {
+ return false;
+ }
+ sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
+ WATCHER_CHECK(samgr != nullptr, return false, "Get samgr failed");
+ sptr object = samgr->GetSystemAbility(PARAM_WATCHER_DISTRIBUTED_SERVICE_ID);
+ WATCHER_CHECK(object != nullptr, return false, "Get watcher manager object from samgr failed");
+ OHOS::init_param::WatcherManagerKits &instance = OHOS::init_param::WatcherManagerKits::GetInstance();
+ instance.GetService();
+ if (instance.GetDeathRecipient() != nullptr) {
+ instance.GetDeathRecipient()->OnRemoteDied(object);
+ }
+ object = samgr->GetSystemAbility(value);
+ WATCHER_CHECK(object != nullptr, return false, "Get watcher manager object from samgr failed");
+ instance.GetService();
+ if (instance.GetDeathRecipient() != nullptr) {
+ instance.GetDeathRecipient()->OnRemoteDied(object);
+ }
+ return true;
+ }
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::FuzzOnRemoteDied(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/onremotedied_fuzzer/onremotedied_fuzzer.h b/test/fuzztest/onremotedied_fuzzer/onremotedied_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..d495d3356ba647b06fcb4ec8d372464954a53e9c
--- /dev/null
+++ b/test/fuzztest/onremotedied_fuzzer/onremotedied_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2025 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 TEST_FUZZTEST_ON_REMOTE_DIED_FUZZER_H
+#define TEST_FUZZTEST_ON_REMOTE_DIED_FUZZER_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "onremotedied_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/onremotedied_fuzzer/project.xml b/test/fuzztest/onremotedied_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b39473f2f6776874287a2de22477705b1b60385c
--- /dev/null
+++ b/test/fuzztest/onremotedied_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/onstop_fuzzer/corpus/init b/test/fuzztest/onstop_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5
--- /dev/null
+++ b/test/fuzztest/onstop_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7c818146a95e8d69f0348c0a41e84f0a15a985c0
--- /dev/null
+++ b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2024 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 "onstop_fuzzer.h"
+#include
+#include
+#include "watcher.h"
+#include "watcher_proxy.h"
+#include "init_utils.h"
+#define private public
+#define protected public
+#include "watcher_manager.h"
+#undef protected
+#undef private
+using namespace OHOS::init_param;
+
+class FuzzWatcher final : public Watcher {
+public:
+ FuzzWatcher() {}
+ ~FuzzWatcher() = default;
+
+ int32_t OnParameterChange(const std::string &prefix, const std::string &name, const std::string &value) override
+ {
+ return 0;
+ }
+};
+namespace OHOS {
+bool FuzzCheckAppWatchPermission(const uint8_t* data, size_t size)
+ {
+ std::unique_ptr watcherManager = std::make_unique(0, true);
+ uint32_t id = static_cast(*data);
+ uint32_t watcherId = 1;
+ sptr watcher = new FuzzWatcher();
+ watcherManager->AddRemoteWatcher(id, watcherId, watcher);
+ watcherManager->StartLoop();
+ watcherManager->OnStop();
+ return true;
+ }
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::FuzzCheckAppWatchPermission(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/onstop_fuzzer/onstop_fuzzer.h b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..28d288f46b104a0d5cb10adb6431b42f2bd7c624
--- /dev/null
+++ b/test/fuzztest/onstop_fuzzer/onstop_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2024 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 TEST_FUZZTEST_ON_STOP_FUZZER_H
+#define TEST_FUZZTEST_ON_STOP_FUZZER_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "onstop_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/onstop_fuzzer/project.xml b/test/fuzztest/onstop_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..949d03efd7477905377ac79f3b0bb374c8ac2e9a
--- /dev/null
+++ b/test/fuzztest/onstop_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/sendlocalchange_fuzzer/corpus/init b/test/fuzztest/sendlocalchange_fuzzer/corpus/init
new file mode 100644
index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932
--- /dev/null
+++ b/test/fuzztest/sendlocalchange_fuzzer/corpus/init
@@ -0,0 +1,16 @@
+/*
+ * Copyright (c) 2025 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.
+ */
+
+FUZZ
\ No newline at end of file
diff --git a/test/fuzztest/sendlocalchange_fuzzer/project.xml b/test/fuzztest/sendlocalchange_fuzzer/project.xml
new file mode 100644
index 0000000000000000000000000000000000000000..b39473f2f6776874287a2de22477705b1b60385c
--- /dev/null
+++ b/test/fuzztest/sendlocalchange_fuzzer/project.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 100
+
+ 30
+
+ 2048
+
+
diff --git a/test/fuzztest/sendlocalchange_fuzzer/sendlocalchange_fuzzer.cpp b/test/fuzztest/sendlocalchange_fuzzer/sendlocalchange_fuzzer.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..5d7a673d5d905562e1378a1152fd9630cd53cef7
--- /dev/null
+++ b/test/fuzztest/sendlocalchange_fuzzer/sendlocalchange_fuzzer.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2025 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
+#include
+#include "sendlocalchange_fuzzer.h"
+#include "init_utils.h"
+#include "securec.h"
+#define private public
+#include "watcher_manager.h"
+#undef private
+using namespace OHOS::init_param;
+
+namespace OHOS {
+ bool FuzzProcessSendLocalChange(const uint8_t* data, size_t size)
+ {
+ if (size < sizeof(uint32_t)) {
+ return false;
+ }
+ std::unique_ptr watcherManager = std::make_unique(0, true);
+ std::string str(reinterpret_cast(data), size);
+ uint32_t randomValue = 0;
+ errno_t ret = memcpy_s(&randomValue, sizeof(randomValue), data, sizeof(uint32_t));
+ if (ret != 0) {
+ return false;
+ }
+ watcherManager->SendLocalChange(str, randomValue);
+ return true;
+ }
+}
+
+/* Fuzzer entry point */
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ /* Run your code on data */
+ OHOS::FuzzProcessSendLocalChange(data, size);
+ return 0;
+}
\ No newline at end of file
diff --git a/test/fuzztest/sendlocalchange_fuzzer/sendlocalchange_fuzzer.h b/test/fuzztest/sendlocalchange_fuzzer/sendlocalchange_fuzzer.h
new file mode 100644
index 0000000000000000000000000000000000000000..052df34d2d8b708bb95a379b695a1ba2196992e5
--- /dev/null
+++ b/test/fuzztest/sendlocalchange_fuzzer/sendlocalchange_fuzzer.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2025 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 TEST_FUZZTEST_SEND_LOCAL_CHANGE_FUZZER_H
+#define TEST_FUZZTEST_SEND_LOCAL_CHANGE_FUZZER_H
+#include "fuzz_utils.h"
+#define FUZZ_PROJECT_NAME "sendloaclchange_fuzzer"
+#endif
\ No newline at end of file
diff --git a/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp b/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp
index 8889249d3e3c23f12a487235c357a1fd0aa2eb39..fcf52ef016fbed74540c6389729328197c46cab8 100644
--- a/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp
+++ b/test/fuzztest/watchparameter_fuzzer/watchparameter_fuzzer.cpp
@@ -33,6 +33,7 @@ namespace OHOS {
std::string str(reinterpret_cast(data), size);
CloseStdout();
if (!WatchParameter(str.c_str(), HandleParamChange, NULL)) {
+ WatchParameter(str.c_str(), NULL, NULL);
result = true;
}
return result;
diff --git a/test/moduletest/syspara.cpp b/test/moduletest/syspara.cpp
index bdae25c6ae0482216fd0d6378d4cf8298fcc9974..9aa733e5f2abd0f992fa5a1e11812f5b3070c1a8 100644
--- a/test/moduletest/syspara.cpp
+++ b/test/moduletest/syspara.cpp
@@ -24,35 +24,35 @@
#include "sysversion.h"
using SysParaInfoItem = struct {
- char *infoName;
+ const char *infoName;
const char *(*getInfoValue)(void);
};
static const SysParaInfoItem SYSPARA_LIST[] = {
- {(char *)"DeviceType", GetDeviceType},
- {(char *)"Manufacture", GetManufacture},
- {(char *)"Brand", GetBrand},
- {(char *)"MarketName", GetMarketName},
- {(char *)"ProductSeries", GetProductSeries},
- {(char *)"ProductModel", GetProductModel},
- {(char *)"ProductModelAlias", GetProductModel},
- {(char *)"SoftwareModel", GetSoftwareModel},
- {(char *)"HardwareModel", GetHardwareModel},
- {(char *)"Serial", GetSerial},
- {(char *)"OSFullName", GetOSFullName},
- {(char *)"DisplayVersion", GetDisplayVersion},
- {(char *)"BootloaderVersion", GetBootloaderVersion},
- {(char *)"GetSecurityPatchTag", GetSecurityPatchTag},
- {(char *)"AbiList", GetAbiList},
- {(char *)"IncrementalVersion", GetIncrementalVersion},
- {(char *)"VersionId", GetVersionId},
- {(char *)"BuildType", GetBuildType},
- {(char *)"BuildUser", GetBuildUser},
- {(char *)"BuildHost", GetBuildHost},
- {(char *)"BuildTime", GetBuildTime},
- {(char *)"BuildRootHash", GetBuildRootHash},
- {(char *)"GetOsReleaseType", GetOsReleaseType},
- {(char *)"GetHardwareProfile", GetHardwareProfile},
+ {"DeviceType", GetDeviceType},
+ {"Manufacture", GetManufacture},
+ {"Brand", GetBrand},
+ {"MarketName", GetMarketName},
+ {"ProductSeries", GetProductSeries},
+ {"ProductModel", GetProductModel},
+ {"ProductModelAlias", GetProductModel},
+ {"SoftwareModel", GetSoftwareModel},
+ {"HardwareModel", GetHardwareModel},
+ {"Serial", GetSerial},
+ {"OSFullName", GetOSFullName},
+ {"DisplayVersion", GetDisplayVersion},
+ {"BootloaderVersion", GetBootloaderVersion},
+ {"GetSecurityPatchTag", GetSecurityPatchTag},
+ {"AbiList", GetAbiList},
+ {"IncrementalVersion", GetIncrementalVersion},
+ {"VersionId", GetVersionId},
+ {"BuildType", GetBuildType},
+ {"BuildUser", GetBuildUser},
+ {"BuildHost", GetBuildHost},
+ {"BuildTime", GetBuildTime},
+ {"BuildRootHash", GetBuildRootHash},
+ {"GetOsReleaseType", GetOsReleaseType},
+ {"GetHardwareProfile", GetHardwareProfile},
};
static int32_t SysParaApiDumpCmd(BShellHandle shell, int32_t argc, char *argv[])
diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn
index 34ffab7b8cd6436f5812e38c476ec5993419901c..00e7d3bad317868a19446dce6a5ddc71fa983f42 100755
--- a/test/unittest/BUILD.gn
+++ b/test/unittest/BUILD.gn
@@ -37,10 +37,13 @@ config("utest_config") {
]
}
-FSCRYPT_PATH =
- "//foundation/filemanagement/storage_service/services/storage_daemon"
-
ohos_unittest("init_unittest") {
+ sanitize = {
+ cfi = true
+ cfi_cross_dso = true
+ debug = false
+ blocklist = "./init_unittest_blocklist.txt"
+ }
module_out_path = "init/init"
sources = [
"//base/startup/init/device_info/device_info.cpp",
@@ -123,6 +126,7 @@ ohos_unittest("init_unittest") {
"//base/startup/init/services/modules/udid/udid_adp.c",
"//base/startup/init/services/modules/udid/udid_comm.c",
"//base/startup/init/services/modules/udid/udid_static.c",
+ "//base/startup/init/services/modules/encaps/encaps_static.c",
"//base/startup/init/services/param/adapter/param_dac.c",
"//base/startup/init/services/param/adapter/param_persistadp.c",
"//base/startup/init/services/param/base/param_base.c",
@@ -154,13 +158,6 @@ ohos_unittest("init_unittest") {
deps = [ "//base/startup/init/interfaces/innerkits:deviceinfo_stub" ]
- sources += [
- "${FSCRYPT_PATH}/libfscrypt/src/fscrypt_control.c",
- "${FSCRYPT_PATH}/libfscrypt/src/fscrypt_utils.c",
- "${FSCRYPT_PATH}/libfscrypt/src/key_control.c",
- "${FSCRYPT_PATH}/libfscrypt/src/sysparam_static.c",
- ]
-
if (defined(build_selinux) && build_selinux) {
sources += [ "//base/startup/init/services/param/adapter/param_selinux.c" ]
}
@@ -186,6 +183,15 @@ ohos_unittest("init_unittest") {
]
defines = []
+ sources += [
+ "//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c",
+ "//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/fs_dm_linear.c",
+ ]
+ include_dirs += [
+ "//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm",
+ "//base/startup/init/interfaces/innerkits/include/fs_manager",
+ "//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include",
+ ]
if (defined(build_seccomp) && build_seccomp) {
sources += [
"../../services/modules/seccomp/seccomp_policy.c",
@@ -305,7 +311,6 @@ ohos_unittest("init_unittest") {
"//base/startup/init/services/sandbox/include",
"//base/startup/init/interfaces/innerkits/hals",
"//base/startup/init/interfaces/innerkits/include/param",
- "${FSCRYPT_PATH}/include/libfscrypt",
]
include_dirs += [ "//base/startup/init/services/modules/sysevent" ]
@@ -331,8 +336,7 @@ ohos_unittest("init_unittest") {
]
defines += [ "_GNU_SOURCE" ]
- if (target_cpu == "arm64" || target_cpu == "x86_64" ||
- target_cpu == "riscv64") {
+ if (target_cpu == "arm64" || target_cpu == "x86_64" ) {
defines += [ "SUPPORT_64BIT" ]
}
@@ -354,9 +358,9 @@ ohos_unittest("init_unittest") {
"hilog:libhilog",
"hisysevent:libhisysevent",
"init:libinit_module_engine",
- "libunwind:libunwind",
"mbedtls:mbedtls_shared",
"selinux:libselinux",
+ "storage_service:libfscryptutils_static",
"zlib:libz",
]
if (defined(global_parts_info) &&
@@ -465,25 +469,19 @@ ohos_unittest("init_unittest") {
ohos_unittest("init_dmverify_unittest") {
module_out_path = "init/init"
- sources = [
- "//base/startup/init/interfaces/innerkits/fs_manager/dm_verity/dm_verity.c",
- "//base/startup/init/services/log/init_commlog.c",
- "//base/startup/init/services/log/init_log.c",
- "//base/startup/init/test/mock/init/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c",
- "//base/startup/init/test/unittest/fs_manager/dm_verify/dm_verify_unittest.cpp",
- ]
-
include_dirs = [
"//base/startup/init/interfaces/innerkits/fs_manager/dm_verity/include",
"//base/startup/init/interfaces/innerkits/include",
- "//base/startup/hvb/libhvb/include",
"//base/startup/init/interfaces/innerkits/include/fs_manager",
- "//third_party/bounds_checking_function/include",
"//base/startup/init/interfaces/innerkits/fs_manager/libfs_hvb/include",
"//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include",
"//base/startup/init/services/log",
]
+ sources = [
+ "//base/startup/init/services/log/init_commlog.c",
+ "//base/startup/init/services/log/init_log.c",
+ ]
configs = [ "//base/startup/init/test/unittest:utest_config" ]
external_deps = [
@@ -492,47 +490,69 @@ ohos_unittest("init_dmverify_unittest") {
"hilog:libhilog",
]
+ defines = []
+ if (defined(global_parts_info) && defined(global_parts_info.startup_hvb)) {
+ external_deps += [ "hvb:libhvb_static" ]
+ sources += [
+ "//base/startup/init/test/mock/init/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c",
+ "//base/startup/init/interfaces/innerkits/fs_manager/dm_verity/dm_verity.c",
+ "//base/startup/init/test/unittest/fs_manager/dm_verify/dm_verify_unittest.cpp",
+ ]
+ }
+
cflags_cc = [ "-fexceptions" ]
}
ohos_unittest("init_fshvb_unittest") {
module_out_path = "init/init"
- sources = [
- "//base/startup/init/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c",
- "//base/startup/init/interfaces/innerkits/fs_manager/libfs_hvb/hvb_ops.c",
- "//base/startup/init/services/log/init_commlog.c",
- "//base/startup/init/services/utils/init_utils.c",
- "//base/startup/init/test/mock/hvb/libhvb/auth/hvb.c",
- "//base/startup/init/test/mock/hvb/libhvb/cert/hvb_cert.c",
- "//base/startup/init/test/mock/hvb/libhvb/crypto/hvb_hash_sha256.c",
- "//base/startup/init/test/mock/hvb/libhvb/crypto/hvb_sm3.c",
- "//base/startup/init/test/mock/init/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c",
- "//base/startup/init/test/mock/init/ueventd/ueventd.c",
- "//base/startup/init/test/mock/init/ueventd/ueventd_socket.c",
- "//base/startup/init/test/unittest/fs_manager/libfs_hvb_unittest.cpp",
- ]
-
include_dirs = [
"//base/startup/init/interfaces/innerkits/fs_manager/libfs_hvb/include",
- "//base/startup/hvb/libhvb/include",
"//base/startup/init/interfaces/innerkits/fs_manager/libfs_dm/include",
+ "//base/startup/init/interfaces/innerkits/fs_manager/switch_root/include",
+ "//base/startup/init/interfaces/innerkits/init_module_engine/include",
"//base/startup/init/interfaces/innerkits/include/fs_manager",
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/services/log",
"//base/startup/init/ueventd/include",
- "//base/startup/hvb/libhvb/src/crypto",
"//base/startup/init/interfaces/innerkits/include/param",
]
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static",
+ ]
+ sources = [
+ "//base/startup/init/interfaces/innerkits/fs_manager/fstab.c",
+ "//base/startup/init/interfaces/innerkits/fs_manager/fstab_mount.c",
+ "//base/startup/init/services/log/init_commlog.c",
+ "//base/startup/init/services/utils/init_utils.c",
+ "//base/startup/init/test/mock/init/interfaces/innerkits/fs_manager/libfs_dm/fs_dm.c",
+ "//base/startup/init/test/mock/init/ueventd/ueventd.c",
+ "//base/startup/init/test/mock/init/ueventd/ueventd_socket.c",
+ ]
+
defines = [ "STARTUP_INIT_UT_PATH =\"/data/init_ut\"" ]
configs = []
external_deps = [
+ "cJSON:cjson",
"c_utils:utils",
"googletest:gtest",
"hilog:libhilog",
]
+ if (defined(global_parts_info) && defined(global_parts_info.startup_hvb)) {
+ external_deps += [ "hvb:libhvb_static" ]
+ sources += [
+ "//base/startup/init/interfaces/innerkits/fs_manager/libfs_hvb/fs_hvb.c",
+ "//base/startup/init/interfaces/innerkits/fs_manager/libfs_hvb/hvb_ops.c",
+ "//base/startup/init/test/unittest/fs_manager/libfs_hvb_unittest.cpp",
+ "//base/startup/init/test/mock/hvb/libhvb/cert/hvb_cert.c",
+ "//base/startup/init/test/mock/hvb/libhvb/crypto/hvb_hash_sha256.c",
+ "//base/startup/init/test/mock/hvb/libhvb/auth/hvb.c",
+ "//base/startup/init/test/mock/hvb/libhvb/crypto/hvb_sm3.c",
+ ]
+ }
cflags_cc = [ "-fexceptions" ]
}
diff --git a/test/unittest/begetctl/begetctl_unittest.cpp b/test/unittest/begetctl/begetctl_unittest.cpp
index 6c7b7a4d0ce7bddae4387f3779621a690af9b5e5..8e69c75b2ed8ea4274011dbd77f3b83a071faf0d 100644
--- a/test/unittest/begetctl/begetctl_unittest.cpp
+++ b/test/unittest/begetctl/begetctl_unittest.cpp
@@ -32,428 +32,459 @@ public:
HWTEST_F(BegetctlUnitTest, Init_TestShellInit_001, TestSize.Level0)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), 1, const_cast(args));
+ char arg0[] = "param";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLs_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "ls"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "ls";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLsWithR_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "ls", "-r"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "ls";
+ char arg2[] = "-r";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLsGet_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "get"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "get";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellSet_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "set", "aaaaa", "1234567"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "set";
+ char arg2[] = "aaaaa";
+ char arg3[] = "1234567";
+ char* args[] = { arg0, arg1, arg2, arg3, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellGetWithKey_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "get", "aaaaa"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "get";
+ char arg2[] = "aaaaa";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellWait_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "wait", "aaaaa"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "wait";
+ char arg2[] = "aaaaa";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
+
HWTEST_F(BegetctlUnitTest, Init_TestShellWaitFalse_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "wait"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "wait";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellWaitWithKey_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "wait", "aaaaa", "12*", "30"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "wait";
+ char arg2[] = "aaaaa";
+ char arg3[] = "12*";
+ char arg4[] = "30";
+ char* args[] = { arg0, arg1, arg2, arg3, arg4, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
+
HWTEST_F(BegetctlUnitTest, Init_TestShellParamShell_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
- const char *args[] = {
- "param", "shell"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "shell";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
+
HWTEST_F(BegetctlUnitTest, Init_TestShellLsWithvalue_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
BShellEnvSetParam(GetShellHandle(), PARAM_REVERESD_NAME_CURR_PARAMETER, "..a", PARAM_STRING, (void *)"..a");
- const char *args[] = {
- "param", "ls", PARAM_REVERESD_NAME_CURR_PARAMETER
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "ls";
+ char arg2[] = PARAM_REVERESD_NAME_CURR_PARAMETER;
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
+
HWTEST_F(BegetctlUnitTest, Init_TestShellLsWithvalueExist_001, TestSize.Level1)
{
BShellParamCmdRegister(GetShellHandle(), 0);
BShellEnvSetParam(GetShellHandle(), PARAM_REVERESD_NAME_CURR_PARAMETER, "#", PARAM_STRING, (void *)"#");
- const char *args[] = {
- "param", "ls", "-r", PARAM_REVERESD_NAME_CURR_PARAMETER
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "param";
+ char arg1[] = "ls";
+ char arg2[] = "-r";
+ char arg3[] = PARAM_REVERESD_NAME_CURR_PARAMETER;
+ char* args[] = { arg0, arg1, arg2, arg3, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestPartitionSlot_001, TestSize.Level1)
{
- const char *args[] = {
- "partitionslot", "getslot"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "partitionslot";
+ char arg1[] = "getslot";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestPartitionSlot_002, TestSize.Level1)
{
- const char *args[] = {
- "partitionslot", "getsuffix", "1"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "partitionslot";
+ char arg1[] = "getsuffix";
+ char arg2[] = "1";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestPartitionSlot_003, TestSize.Level1)
{
- const char *args[] = {
- "partitionslot", "setactive", "1"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "partitionslot";
+ char arg1[] = "setactive";
+ char arg2[] = "1";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestPartitionSlot_004, TestSize.Level1)
{
- const char *args[] = {
- "partitionslot", "setunboot", "2"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "partitionslot";
+ char arg1[] = "setunboot";
+ char arg2[] = "2";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestPartitionSlot_005, TestSize.Level1)
{
- const char *args[] = {
- "partitionslot", "setactive"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "partitionslot";
+ char arg1[] = "setactive";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestPartitionSlot_006, TestSize.Level1)
{
- const char *args[] = {
- "partitionslot", "setunboot"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "partitionslot";
+ char arg1[] = "setunboot";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestPartitionSlot_007, TestSize.Level1)
{
- const char *args[] = {
- "partitionslot", "getsuffix"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "partitionslot";
+ char arg1[] = "getsuffix";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLog_001, TestSize.Level1)
{
- const char *args[] = {
- "set", "log", "level", "1"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "set";
+ char arg1[] = "log";
+ char arg2[] = "level";
+ char arg3[] = "1";
+ char* args[] = { arg0, arg1, arg2, arg3, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLog_002, TestSize.Level1)
{
- const char *args[] = {
- "get", "log", "level"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "get";
+ char arg1[] = "log";
+ char arg2[] = "level";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLog_003, TestSize.Level1)
{
- const char *args[] = {
- "set", "log", "level"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "set";
+ char arg1[] = "log";
+ char arg2[] = "level";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLog_004, TestSize.Level1)
{
- const char *args[] = {
- "set", "log", "level", "1000"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "set";
+ char arg1[] = "log";
+ char arg2[] = "level";
+ char arg3[] = "1000";
+ char* args[] = { arg0, arg1, arg2, arg3, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestShellLog_005, TestSize.Level1)
{
- const char *args[] = {
- "set", "log", "level", "a"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "set";
+ char arg1[] = "log";
+ char arg2[] = "level";
+ char arg3[] = "a";
+ char* args[] = { arg0, arg1, arg2, arg3, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestBootChart_001, TestSize.Level1)
{
- const char *args[] = {
- "bootchart", "enable"
- };
+ char arg0[] = "bootchart";
+ char arg1[] = "enable";
+ char* args[] = { arg0, arg1, nullptr };
SystemWriteParam("persist.init.bootchart.enabled", "1");
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestBootChart_002, TestSize.Level1)
{
- const char *args[] = {
- "bootchart", "start"
- };
-
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "bootchart";
+ char arg1[] = "start";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestBootChart_003, TestSize.Level1)
{
- const char *args[] = {
- "bootchart", "stop"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "bootchart";
+ char arg1[] = "stop";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestBootChart_004, TestSize.Level1)
{
- const char *args[] = {
- "bootchart", "disable"
- };
+ char arg0[] = "bootchart";
+ char arg1[] = "disable";
+ char* args[] = { arg0, arg1, nullptr };
SystemWriteParam("persist.init.bootchart.enabled", "0");
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestBootChart_005, TestSize.Level1)
{
- const char *args[] = {
- "bootchart"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "bootchart";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestDumpService_001, TestSize.Level1)
{
- const char *args[] = {
- "bootevent", "enable"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "bootevent";
+ char arg1[] = "enable";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestDumpService_002, TestSize.Level1)
{
- const char *args[] = {
- "bootevent", "disable"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "bootevent";
+ char arg1[] = "disable";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestDumpService_003, TestSize.Level1)
{
- const char *args[] = {
- "dump_service", "all"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dump_service";
+ char arg1[] = "all";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestDumpService_004, TestSize.Level1)
{
- const char *args[] = {
- "dump_service", "param_watcher"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dump_service";
+ char arg1[] = "param_watcher";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestDumpService_005, TestSize.Level1)
{
- const char *args[] = {
- "dump_service", "parameter-service", "trigger"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dump_service";
+ char arg1[] = "parameter-service";
+ char arg2[] = "trigger";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestDumpNwebSpawn_001, TestSize.Level1)
{
- const char *args[] = {
- "dump_nwebspawn", ""
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dump_nwebspawn";
+ char arg1[] = "";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestDumpAppspawn_001, TestSize.Level1)
{
- const char *args[] = {
- "dump_appspawn", ""
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dump_appspawn";
+ char arg1[] = "";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestMiscDaemon_001, TestSize.Level1)
{
- const char *args[] = {
- "misc_daemon", "--write_logo", BOOT_CMD_LINE
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "misc_daemon";
+ char arg1[] = "--write_logo";
+ char arg2[] = BOOT_CMD_LINE;
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestMiscDaemon_002, TestSize.Level1)
{
- const char *args[] = {
- "misc_daemon", "--write_logo1111", "test"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "misc_daemon";
+ char arg1[] = "--write_logo1111";
+ char arg2[] = "test";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestMiscDaemon_003, TestSize.Level1)
{
- const char *args[] = {
- "misc_daemon", "--write_logo", ""
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "misc_daemon";
+ char arg1[] = "--write_logo";
+ char arg2[] = "";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestMiscDaemon_004, TestSize.Level1)
{
- const char *args[] = {
- "misc_daemon", "--write_logo"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "misc_daemon";
+ char arg1[] = "--write_logo";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestMiscDaemon_005, TestSize.Level1)
{
// clear misc logo
- const char *args[] = {
- "misc_daemon", "--write_logo", "sssssssss"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "misc_daemon";
+ char arg1[] = "--write_logo";
+ char arg2[] = "sssssssss";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestModulectl_001, TestSize.Level1)
{
- const char *args[] = {
- "modulectl", "install", "testModule"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "modulectl";
+ char arg1[] = "install";
+ char arg2[] = "testModule";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestModulectl_002, TestSize.Level1)
{
- const char *args[] = {
- "modulectl", "uninstall", "testModule"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "modulectl";
+ char arg1[] = "uninstall";
+ char arg2[] = "testModule";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestModulectl_003, TestSize.Level1)
{
- const char *args[] = {
- "modulectl", "list", "testModule"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "modulectl";
+ char arg1[] = "list";
+ char arg2[] = "testModule";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestModulectl_004, TestSize.Level1)
{
- const char *args[] = {
- "modulectl", "install"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "modulectl";
+ char arg1[] = "install";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestModulectl_005, TestSize.Level1)
{
- const char *args[] = {
- "modulectl", "list"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "modulectl";
+ char arg1[] = "list";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
@@ -465,271 +496,281 @@ HWTEST_F(BegetctlUnitTest, Init_TestModulectl_006, TestSize.Level1)
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_001, TestSize.Level1)
{
- const char *args[] = {
- "service_control", "stop", "test"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "service_control";
+ char arg1[] = "stop";
+ char arg2[] = "test";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_002, TestSize.Level1)
{
- const char *args[] = {
- "service_control", "start", "test"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "service_control";
+ char arg1[] = "start";
+ char arg2[] = "test";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_003, TestSize.Level1)
{
- const char *args[] = {
- "stop_service", "test"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "stop_service";
+ char arg1[] = "test";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_004, TestSize.Level1)
{
- const char *args[] = {
- "start_service", "test"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "start_service";
+ char arg1[] = "test";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_005, TestSize.Level1)
{
- const char *args[] = {
- "timer_stop", "test"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "timer_stop";
+ char arg1[] = "test";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_006, TestSize.Level1)
{
- const char *args[] = {
- "timer_stop"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "timer_stop";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_007, TestSize.Level1)
{
- const char *args[] = {
- "timer_start", "test-service", "10"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "timer_start";
+ char arg1[] = "test-service";
+ char arg2[] = "10";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_008, TestSize.Level1)
{
- const char *args[] = {
- "timer_start", "test-service",
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "timer_start";
+ char arg1[] = "test-service";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_009, TestSize.Level1)
{
- const char *args[] = {
- "timer_start", "test-service", "ww"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "timer_start";
+ char arg1[] = "test-service";
+ char arg2[] = "ww";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestServiceControl_010, TestSize.Level1)
{
- const char *args[] = {
- "xxxxxxxxxxxxxx", "test-service", "ww"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "xxxxxxxxxxxxxx";
+ char arg1[] = "test-service";
+ char arg2[] = "ww";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestSetLogLevel_001, TestSize.Level1)
{
- const char *args[] = {
- "setloglevel", "1"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "setloglevel";
+ char arg1[] = "1";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestSetLogLevel_002, TestSize.Level1)
{
- const char *args[] = {
- "getloglevel"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "getloglevel";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestSetLogLevel_003, TestSize.Level1)
{
- const char *args[] = {
- "setloglevel", "a"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "setloglevel";
+ char arg1[] = "a";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestSetLogLevel_004, TestSize.Level1)
{
- const char *args[] = {
- "setloglevel"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "setloglevel";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestSetLogLevel_005, TestSize.Level1)
{
- const char *args[] = {
- "setloglevel"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), 0, const_cast(args));
+ char arg0[] = "setloglevel";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), 0, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestSandbox_001, TestSize.Level1)
{
- const char *args[] = {
- "sandbox", "-s", "test", "-n", "test2", "-p", "test3", "-h", "?"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "sandbox";
+ char arg1[] = "-s";
+ char arg2[] = "test";
+ char arg3[] = "-n";
+ char arg4[] = "test2";
+ char arg5[] = "-p";
+ char arg6[] = "test3";
+ char arg7[] = "-h";
+ char arg8[] = "?";
+ char* args[] = { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestSandbox_002, TestSize.Level1)
{
- const char *args[] = {
- "sandbox", "-b", "1008"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "sandbox";
+ char arg1[] = "-b";
+ char arg2[] = "1008";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_001, TestSize.Level1)
{
- const char *args[] = {
- "reboot"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_002, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "shutdown"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "shutdown";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_003, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "charge"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "charge";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_004, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "updater"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "updater";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_005, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "updater:aaaaaaa"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "updater:aaaaaaa";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_006, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "flashd:aaaaaaa"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "flashd:aaaaaaa";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_007, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "flashd"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "flashd";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_008, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "suspend"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "suspend";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestReboot_009, TestSize.Level1)
{
- const char *args[] = {
- "reboot", "222222222"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "reboot";
+ char arg1[] = "222222222";
+ char* args[] = { arg0, arg1, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestGid_001, TestSize.Level1)
{
- const char *args[] = {
- "dac", "gid", "logd"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dac";
+ char arg1[] = "gid";
+ char arg2[] = "logd";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestGid_002, TestSize.Level1)
{
- const char *args[] = {
- "dac"
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dac";
+ char* args[] = { arg0, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestUid_001, TestSize.Level1)
{
- const char *args[] = {
- "dac", "uid", ""
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dac";
+ char arg1[] = "uid";
+ char arg2[] = "";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
HWTEST_F(BegetctlUnitTest, Init_TestUid_002, TestSize.Level1)
{
- const char *args[] = {
- "dac", "uid", ""
- };
- int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]), const_cast(args));
+ char arg0[] = "dac";
+ char arg1[] = "uid";
+ char arg2[] = "";
+ char* args[] = { arg0, arg1, arg2, nullptr };
+ int ret = BShellEnvDirectExecute(GetShellHandle(), sizeof(args) / sizeof(args[0]) - 1, args);
EXPECT_EQ(ret, 0);
}
} // namespace init_ut
diff --git a/test/unittest/deviceinfo/DeviceInfoUnittest.cpp b/test/unittest/deviceinfo/DeviceInfoUnittest.cpp
index a01be7ccf70a8d031085880d95b66a81acaf3790..67b251ed7fbab6844c7c981760ee31143835f0d9 100644
--- a/test/unittest/deviceinfo/DeviceInfoUnittest.cpp
+++ b/test/unittest/deviceinfo/DeviceInfoUnittest.cpp
@@ -258,4 +258,19 @@ HWTEST_F(DeviceInfoUnittest, Init_TestDeviceInfoProxy_002, TestSize.Level1)
std::string diskSN;
proxy->GetDiskSN(diskSN);
}
+
+HWTEST_F(DeviceInfoUnittest, Init_TestDevicekits_001, TestSize.Level1)
+{
+ OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
+ std::unique_lock lock(instance.lock_);
+ EXPECT_NE(nullptr, instance.RetryGetService(lock));
+}
+
+HWTEST_F(DeviceInfoUnittest, Init_TestDevicekits_002, TestSize.Level1)
+{
+ OHOS::device_info::DeviceInfoKits &instance = OHOS::device_info::DeviceInfoKits::GetInstance();
+ instance.deviceInfoService_ = nullptr;
+ std::unique_lock lock(instance.lock_);
+ EXPECT_NE(nullptr, instance.RetryGetService(lock));
+}
} // namespace init_ut
diff --git a/test/unittest/fs_manager/dm_verify/dm_verify_unittest.cpp b/test/unittest/fs_manager/dm_verify/dm_verify_unittest.cpp
index 8288cdc4915c251202d136c45d7ef71362c29787..83c1a0d87b445bf63a2f4b9d0e876938dcea84af 100644
--- a/test/unittest/fs_manager/dm_verify/dm_verify_unittest.cpp
+++ b/test/unittest/fs_manager/dm_verify/dm_verify_unittest.cpp
@@ -24,8 +24,6 @@ class DmVerifyUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
- void SetUp(void) {};
- void TearDown(void) {};
};
static int TestHvbDmVerityFinal(void)
@@ -37,8 +35,14 @@ static int TestHvbDmVerityFinal(void)
HWTEST_F(DmVerifyUnitTest, HvbDmVerityinit_001, TestSize.Level0)
{
int ret;
- FstabItem fstabitem = {(char *)"deviceName", (char *)"mountPoint",
- (char *)"fsType", (char *)"mountOptions", 1, nullptr};
+ FstabItem fstabitem;
+ char testStr[10] = "testStr";
+ fstabitem.deviceName = testStr;
+ fstabitem.mountPoint = testStr;
+ fstabitem.fsType = testStr;
+ fstabitem.mountOptions = testStr;
+ fstabitem.fsManagerFlags = 1;
+ fstabitem.next = nullptr;
Fstab fstab = {&fstabitem};
ret = HvbDmVerityinit(&fstab);
@@ -70,8 +74,14 @@ HWTEST_F(DmVerifyUnitTest, HvbDmVerityinit_001, TestSize.Level0)
HWTEST_F(DmVerifyUnitTest, HvbDmVerityinit_002, TestSize.Level0)
{
int ret;
- FstabItem fstabitem = {(char *)"deviceName", (char *)"mountPoint",
- (char *)"fsType", (char *)"mountOptions", 1, nullptr};
+ FstabItem fstabitem;
+ char testStr[10] = "testStr";
+ fstabitem.deviceName = testStr;
+ fstabitem.mountPoint = testStr;
+ fstabitem.fsType = testStr;
+ fstabitem.mountOptions = testStr;
+ fstabitem.fsManagerFlags = 1;
+ fstabitem.next = nullptr;
Fstab fstab = {&fstabitem};
ret = HvbDmVerityinit(&fstab);
@@ -96,8 +106,14 @@ HWTEST_F(DmVerifyUnitTest, HvbDmVerityinit_002, TestSize.Level0)
HWTEST_F(DmVerifyUnitTest, HvbDmVeritySetUp_001, TestSize.Level0)
{
int ret;
- FstabItem fstabitem = {(char *)"deviceName", (char *)"mountPoint",
- (char *)"fsType", (char *)"mountOptions", 1, nullptr};
+ FstabItem fstabitem;
+ char testStr[10] = "testStr";
+ fstabitem.deviceName = testStr;
+ fstabitem.mountPoint = testStr;
+ fstabitem.fsType = testStr;
+ fstabitem.mountOptions = testStr;
+ fstabitem.fsManagerFlags = 1;
+ fstabitem.next = nullptr;
ret = HvbDmVeritySetUp(&fstabitem);
EXPECT_EQ(ret, 0);
diff --git a/test/unittest/fs_manager/erofs/erofs_common_unittest.cpp b/test/unittest/fs_manager/erofs/erofs_common_unittest.cpp
index 615ebb25d7e150144f3aeb63daf0b6320ced8029..f01abbf43d06858842dd43ed25f9113182473b3b 100644
--- a/test/unittest/fs_manager/erofs/erofs_common_unittest.cpp
+++ b/test/unittest/fs_manager/erofs/erofs_common_unittest.cpp
@@ -13,11 +13,13 @@
* limitations under the License.
*/
+#include
#include "erofs_overlay_common.h"
-#include "securec.h"
#include "param_stub.h"
+
using namespace std;
using namespace testing::ext;
+
namespace init_ut {
class ErofsCommonOverlayUnitTest : public testing::Test {
public:
@@ -53,7 +55,7 @@ HWTEST_F(ErofsCommonOverlayUnitTest, Init_IsOverlayEnable_001, TestSize.Level0)
CreateTestFile(BOOT_CMD_LINE, cmdLine);
ret = IsOverlayEnable();
EXPECT_EQ(ret, true);
- int ret2 = remove(BOOT_CMD_LINE);
+ remove(BOOT_CMD_LINE);
PrepareCmdLineData();
}
diff --git a/test/unittest/fs_manager/erofs/erofs_mount_unittest.cpp b/test/unittest/fs_manager/erofs/erofs_mount_unittest.cpp
index 585d71504645e528dbf038933d4bab7c7e40823a..1187e534dbee60120abcb92fc932b12bd97af87f 100644
--- a/test/unittest/fs_manager/erofs/erofs_mount_unittest.cpp
+++ b/test/unittest/fs_manager/erofs/erofs_mount_unittest.cpp
@@ -12,12 +12,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
+#include
#include "erofs_mount_overlay.h"
-#include "securec.h"
#include "param_stub.h"
#include "init_utils.h"
+
using namespace std;
using namespace testing::ext;
+
namespace init_ut {
class ErofsMountUnitTest : public testing::Test {
public:
@@ -26,14 +29,17 @@ public:
void SetUp(void) {};
void TearDown(void) {};
};
+
HWTEST_F(ErofsMountUnitTest, Init_AllocDmName_001, TestSize.Level0)
{
char nameExt4[MAX_BUFFER_LEN] = {0};
char nameRofs[MAX_BUFFER_LEN] = {0};
const char *devName = STARTUP_INIT_UT_PATH"/data/erofs/mount/rofs";
AllocDmName(devName, nameRofs, MAX_BUFFER_LEN, nameExt4, MAX_BUFFER_LEN);
- EXPECT_STRNE(nameExt4, nameRofs);
+ EXPECT_STREQ("_data_init_ut_data_erofs_mount_rofs_erofs", nameRofs);
+ EXPECT_STREQ("_data_init_ut_data_erofs_mount_rofs_ext4", nameExt4);
}
+
HWTEST_F(ErofsMountUnitTest, Init_LookupErofsEnd_001, TestSize.Level0)
{
const char *devMount = STARTUP_INIT_UT_PATH"/data/erofs/mount/lookup";
@@ -65,5 +71,4 @@ HWTEST_F(ErofsMountUnitTest, Init_LookupErofsEnd_001, TestSize.Level0)
EXPECT_NE(ret, 0);
remove(devMount);
}
-
}
\ No newline at end of file
diff --git a/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp b/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp
index 5aa78a53eba2a0a0087c1686d365e2f34269f9b4..6b5c6018b4a741ed0afdd225d2104e09e5d92734 100644
--- a/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp
+++ b/test/unittest/fs_manager/erofs/erofs_remount_unittest.cpp
@@ -13,12 +13,25 @@
* limitations under the License.
*/
+#include
#include "erofs_remount_overlay.h"
-#include "securec.h"
#include "param_stub.h"
#include "fs_manager.h"
+
+#define MODEM_DRIVER_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_driver"
+#define MODEM_VENDOR_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_vendor"
+#define MODEM_FW_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/modem/modem_fw"
+#define MODEM_DRIVER_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/driver_exchange"
+#define MODEM_VENDOR_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/vendor_exchange"
+#define MODEM_FW_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/fw_exchange"
+#define REMOUNT_RESULT_PATH STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/"
+#define REMOUNT_RESULT_FLAG STARTUP_INIT_UT_PATH"/data/service/el1/startup/remount/remount.result.done"
+#define DPA_MNT_PATH STARTUP_INIT_UT_PATH"/vendor/communication/dpa"
+#define DPA_EXCHANGE_PATH STARTUP_INIT_UT_PATH"/mnt/dpa_exchange"
+
using namespace std;
using namespace testing::ext;
+
namespace init_ut {
class ErofsRemountUnitTest : public testing::Test {
public:
@@ -30,12 +43,11 @@ public:
HWTEST_F(ErofsRemountUnitTest, Init_GetRemountResult_001, TestSize.Level0)
{
- const char *cmdLine;
rmdir(REMOUNT_RESULT_PATH);
+ RemountOverlay();
SetRemountResultFlag();
-
- CheckAndCreateDir(REMOUNT_RESULT_FLAG);
- SetRemountResultFlag();
+ int ret = GetRemountResult();
+ EXPECT_EQ(ret, 0);
rmdir(REMOUNT_RESULT_PATH);
}
@@ -89,20 +101,23 @@ HWTEST_F(ErofsRemountUnitTest, Init_ExchangeToMode_001, TestSize.Level0)
HWTEST_F(ErofsRemountUnitTest, Init_OverlayRemountVendorPre_001, TestSize.Level0)
{
- CheckAndCreateDir(MODEM_DRIVER_MNT_PATH);
- CheckAndCreateDir(MODEM_VENDOR_MNT_PATH);
- CheckAndCreateDir(MODEM_FW_MNT_PATH);
+ CheckAndCreateDir(MODEM_DRIVER_MNT_PATH"/");
+ CheckAndCreateDir(MODEM_VENDOR_MNT_PATH"/");
+ CheckAndCreateDir(MODEM_FW_MNT_PATH"/");
+ CheckAndCreateDir(DPA_MNT_PATH"/");
+ CheckAndCreateDir(STARTUP_INIT_UT_PATH"/mnt/");
+
OverlayRemountVendorPre();
+ EXPECT_EQ(access(MODEM_DRIVER_MNT_PATH, F_OK), 0);
+ EXPECT_EQ(access(MODEM_DRIVER_EXCHANGE_PATH, F_OK), 0);
+ OverlayRemountVendorPost();
+
rmdir(MODEM_DRIVER_MNT_PATH);
rmdir(MODEM_VENDOR_MNT_PATH);
rmdir(MODEM_FW_MNT_PATH);
-
- OverlayRemountVendorPost();
-}
-
-HWTEST_F(ErofsRemountUnitTest, Init_RemountOverlayTest_001, TestSize.Level0)
-{
- int ret = RemountOverlay();
- EXPECT_EQ(ret, 0);
+ rmdir(MODEM_DRIVER_EXCHANGE_PATH);
+ rmdir(MODEM_VENDOR_EXCHANGE_PATH);
+ rmdir(MODEM_FW_EXCHANGE_PATH);
+ rmdir(DPA_EXCHANGE_PATH);
}
}
\ No newline at end of file
diff --git a/test/unittest/fs_manager/libfs_hvb_unittest.cpp b/test/unittest/fs_manager/libfs_hvb_unittest.cpp
index ecc821a08f4892b7ee324b5f63677e81b9071c5f..d0ad7b07c487b644e0fbb402cceb0f54ec81ae78 100644
--- a/test/unittest/fs_manager/libfs_hvb_unittest.cpp
+++ b/test/unittest/fs_manager/libfs_hvb_unittest.cpp
@@ -29,8 +29,6 @@ class FsHvbUnitTest : public testing::Test {
public:
static void SetUpTestCase(void) {};
static void TearDownTestCase(void) {};
- void SetUp(void) {};
- void TearDown(void) {};
};
void CreateTestFile(const char *fileName, const char *data)
diff --git a/test/unittest/init/init_unittest.cpp b/test/unittest/init/init_unittest.cpp
index 04395b05612c8cec85506fec1179f2593912d093..30db2bcbee187bad72389abea02aa70f1eb296e8 100644
--- a/test/unittest/init/init_unittest.cpp
+++ b/test/unittest/init/init_unittest.cpp
@@ -37,6 +37,7 @@
#include "fd_holder_service.h"
#include "bootstage.h"
#include "parameter.h"
+#include "fs_dm_linear.h"
using namespace testing::ext;
using namespace std;
@@ -156,4 +157,37 @@ HWTEST_F(InitUnitTest, TestInitLog, TestSize.Level1)
ret = GetInitLogLevel();
EXPECT_EQ(ret, INIT_INFO);
}
+
+HWTEST_F(InitUnitTest, TestParseCfgByPriority, TestSize.Level1)
+{
+ int ret = 0;
+ ret = ParseCfgByPriority(NULL);
+ EXPECT_EQ(ret, -1);
+ ret = ParseCfgByPriority("etc/init");
+ EXPECT_EQ(ret, 0);
+}
+
+HWTEST_F(InitUnitTest, FsDmCreateMultiTargetLinearDevice, TestSize.Level1)
+{
+ const char *devName = "testDevice";
+ char dmDevPath[256] = "/dev/mapper/testDevice";
+ uint64_t dmDevPathLen = sizeof(dmDevPath);
+
+ DmLinearTarget targets[2];
+ uint32_t targetNum = 2;
+
+ targets[0].start = 0;
+ targets[0].length = 100;
+ targets[0].paras_len = strlen("linear /dev/sda 0") + 1;
+ targets[0].paras = const_cast("linear /dev/sda 0");
+
+ targets[1].start = 100;
+ targets[1].length = 200;
+ targets[1].paras_len = strlen("linear /dev/sdb 0") + 1;
+
+ int fd = open("/dev/null", O_RDWR);
+ int rc = FsDmCreateMultiTargetLinearDevice(devName, dmDevPath, dmDevPathLen, targets, targetNum);
+ EXPECT_EQ(rc, -1);
+ close(fd);
+}
}
diff --git a/test/unittest/init/service_unittest.cpp b/test/unittest/init/service_unittest.cpp
index e4fb1fbe010f9149ef7d4764c504bbc5491724c3..53ad4ee7572683388c6ad7814848ea0b0ec3796e 100644
--- a/test/unittest/init/service_unittest.cpp
+++ b/test/unittest/init/service_unittest.cpp
@@ -516,4 +516,144 @@ HWTEST_F(ServiceUnitTest, TestServiceCGroup2, TestSize.Level1)
ReleaseService(service);
cJSON_Delete(jobItem);
}
+
+HWTEST_F(ServiceUnitTest, TestKernelPermAllRight, TestSize.Level1)
+{
+ const char *jsonStr = "{\"services\":{\"name\":\"test_service1\",\"path\":[\"/system/bin/sa_main\"],"
+ "\"importance\":-20,\"uid\":\"system\",\"writepid\":[\"/dev/test_service\"],\"console\":1,"
+ "\"gid\":[\"system\"],\"caps\":[\"\"],\"kernel_permission\":{\"ohos.filesystem.dfs\":345,"
+ "\"ohos.permission.kernel.ALLOW_WRITABLE_CODE_MEMORY\":true}}}";
+ const char *kernelPermStr = "{\"encaps\":{\"ohos.encaps.count\":2,\"ohos.filesystem.dfs\":345,"
+ "\"ohos.permission.kernel.ALLOW_WRITABLE_CODE_MEMORY\":true}}";
+ cJSON* jobItem = cJSON_Parse(jsonStr);
+ ASSERT_NE(nullptr, jobItem);
+ cJSON *serviceItem = cJSON_GetObjectItem(jobItem, "services");
+ ASSERT_NE(nullptr, serviceItem);
+ const char serviceName[] = "test_service1";
+ Service *service = AddService(serviceName);
+ ASSERT_NE(nullptr, service);
+ int ret = ParseOneService(serviceItem, service);
+ EXPECT_EQ(ret, 0);
+ ret = strcmp(service->kernelPerms, kernelPermStr);
+ EXPECT_EQ(ret, 0);
+
+ SERVICE_INFO_CTX context;
+ context.serviceName = service->name;
+ context.reserved = (const char*)service->pathArgs.argv[0];
+ HookMgrExecute(GetBootStageHookMgr(), INIT_GLOBAL_INIT, nullptr, nullptr);
+ (void)HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_SET_PERMS_BEFORE, (void *)(&context), NULL);
+
+ ReleaseService(service);
+ cJSON_Delete(jobItem);
+}
+
+HWTEST_F(ServiceUnitTest, TestKernelPermValueNotSupport, TestSize.Level1)
+{
+ const char *jsonStr = "{\"services\":{\"name\":\"test_service1\",\"path\":[\"/system/bin/sa_main\"],"
+ "\"importance\":-20,\"uid\":\"system\",\"writepid\":[\"/dev/test_service\"],\"console\":1,"
+ "\"gid\":[\"system\"],\"caps\":[\"\"],\"kernel_permission\":{\"ohos.filesystem.dfs\":[345,678],"
+ "\"ohos.permission.kernel.ALLOW_WRITABLE_CODE_MEMORY\":true}}}";
+
+ cJSON* jobItem = cJSON_Parse(jsonStr);
+ ASSERT_NE(nullptr, jobItem);
+ cJSON *serviceItem = cJSON_GetObjectItem(jobItem, "services");
+ ASSERT_NE(nullptr, serviceItem);
+ const char serviceName[] = "test_service1";
+ Service *service = AddService(serviceName);
+ ASSERT_NE(nullptr, service);
+ int ret = ParseOneService(serviceItem, service);
+ EXPECT_EQ(ret, 0);
+ EXPECT_TRUE(service->kernelPerms == nullptr);
+
+ SERVICE_INFO_CTX context;
+ context.serviceName = service->name;
+ context.reserved = (const char*)service->pathArgs.argv[0];
+ HookMgrExecute(GetBootStageHookMgr(), INIT_GLOBAL_INIT, nullptr, nullptr);
+ (void)HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_SET_PERMS_BEFORE, (void *)(&context), NULL);
+
+ ReleaseService(service);
+ cJSON_Delete(jobItem);
+}
+
+HWTEST_F(ServiceUnitTest, TestKernelPermNotSa, TestSize.Level1)
+{
+ const char *jsonStr = "{\"services\":{\"name\":\"test_service1\",\"path\":[\"/system/bin\"],"
+ "\"importance\":-20,\"uid\":\"system\",\"writepid\":[\"/dev/test_service\"],\"console\":1,"
+ "\"gid\":[\"system\"],\"caps\":[\"\"],\"kernel_permission\":{\"ohos.filesystem.dfs\":[345,678],"
+ "\"ohos.permission.kernel.ALLOW_WRITABLE_CODE_MEMORY\":true}}}";
+
+ cJSON* jobItem = cJSON_Parse(jsonStr);
+ ASSERT_NE(nullptr, jobItem);
+ cJSON *serviceItem = cJSON_GetObjectItem(jobItem, "services");
+ ASSERT_NE(nullptr, serviceItem);
+ const char serviceName[] = "test_service1";
+ Service *service = AddService(serviceName);
+ ASSERT_NE(nullptr, service);
+ int ret = ParseOneService(serviceItem, service);
+ EXPECT_EQ(ret, 0);
+ EXPECT_TRUE(service->kernelPerms == nullptr);
+
+ SERVICE_INFO_CTX context;
+ context.serviceName = service->name;
+ context.reserved = (const char*)service->pathArgs.argv[0];
+ HookMgrExecute(GetBootStageHookMgr(), INIT_GLOBAL_INIT, nullptr, nullptr);
+ (void)HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_SET_PERMS_BEFORE, (void *)(&context), NULL);
+
+ ReleaseService(service);
+ cJSON_Delete(jobItem);
+}
+
+HWTEST_F(ServiceUnitTest, TestKernelPermPermissionError, TestSize.Level1)
+{
+ const char *jsonStr = "{\"services\":{\"name\":\"test_service1\",\"path\":[\"/system/bin/sa_main\"],"
+ "\"importance\":-20,\"uid\":\"system\",\"writepid\":[\"/dev/test_service\"],\"console\":1,"
+ "\"gid\":[\"system\"],\"caps\":[\"\"],\"kernel_permission\":{\"ohos.filesystem.dfsxxx\":1,"
+ "\"ohos.permission.kernel.ALLOW_WRITABLE_CODE_MEMORY\":true}}}";
+
+ cJSON* jobItem = cJSON_Parse(jsonStr);
+ ASSERT_NE(nullptr, jobItem);
+ cJSON *serviceItem = cJSON_GetObjectItem(jobItem, "services");
+ ASSERT_NE(nullptr, serviceItem);
+ const char serviceName[] = "test_service1";
+ Service *service = AddService(serviceName);
+ ASSERT_NE(nullptr, service);
+ int ret = ParseOneService(serviceItem, service);
+ EXPECT_EQ(ret, 0);
+
+ SERVICE_INFO_CTX context;
+ context.serviceName = service->name;
+ context.reserved = (const char*)service->pathArgs.argv[0];
+ HookMgrExecute(GetBootStageHookMgr(), INIT_GLOBAL_INIT, nullptr, nullptr);
+ (void)HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_SET_PERMS_BEFORE, (void *)(&context), NULL);
+
+ ReleaseService(service);
+ cJSON_Delete(jobItem);
+}
+
+HWTEST_F(ServiceUnitTest, TestKernelPermServiceNameError, TestSize.Level1)
+{
+ const char *jsonStr = "{\"services\":{\"name\":\"test_service1\",\"path\":[\"/system/bin/sa_main\"],"
+ "\"importance\":-20,\"uid\":\"system\",\"writepid\":[\"/dev/test_service\"],\"console\":1,"
+ "\"gid\":[\"system\"],\"caps\":[\"\"],\"kernel_permission\":{\"ohos.filesystem.dfs\":1,"
+ "\"ohos.permission.kernel.ALLOW_WRITABLE_CODE_MEMORY\":true}}}";
+
+ cJSON* jobItem = cJSON_Parse(jsonStr);
+ ASSERT_NE(nullptr, jobItem);
+ cJSON *serviceItem = cJSON_GetObjectItem(jobItem, "services");
+ ASSERT_NE(nullptr, serviceItem);
+ const char serviceName[] = "test_service1";
+ Service *service = AddService(serviceName);
+ ASSERT_NE(nullptr, service);
+ int ret = ParseOneService(serviceItem, service);
+ EXPECT_EQ(ret, 0);
+
+ SERVICE_INFO_CTX context;
+ context.serviceName = "wrongServiceName";
+ context.reserved = (const char*)service->pathArgs.argv[0];
+ HookMgrExecute(GetBootStageHookMgr(), INIT_GLOBAL_INIT, nullptr, nullptr);
+ (void)HookMgrExecute(GetBootStageHookMgr(), INIT_SERVICE_SET_PERMS_BEFORE, (void *)(&context), NULL);
+
+ ReleaseService(service);
+ cJSON_Delete(jobItem);
+}
} // namespace init_ut
diff --git a/test/unittest/init_unittest_blocklist.txt b/test/unittest/init_unittest_blocklist.txt
new file mode 100644
index 0000000000000000000000000000000000000000..a6d594134cfdbae552e48d9d8dab985aeb8850a1
--- /dev/null
+++ b/test/unittest/init_unittest_blocklist.txt
@@ -0,0 +1,17 @@
+# Copyright (c) 2025 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.
+
+
+ [cfi]
+ type:*OHOS::init_param::RemoteWatcher*
+ src:*base/startup/init/services/param/watcher/proxy/*
diff --git a/test/unittest/innerkits/innerkits_unittest.cpp b/test/unittest/innerkits/innerkits_unittest.cpp
index 9103eb1deec0f7ce44e9f7e78c82634ad66c0a3b..5c80af6b625d1d4326d145bf97505c2460b29722 100644
--- a/test/unittest/innerkits/innerkits_unittest.cpp
+++ b/test/unittest/innerkits/innerkits_unittest.cpp
@@ -20,6 +20,7 @@
#include "init_param.h"
#include "param_stub.h"
#include "securec.h"
+#include "parameter.h"
#include "systemcapability.h"
#include "service_control.h"
#include "control_fd.h"
@@ -292,6 +293,74 @@ HWTEST_F(InnerkitsUnitTest, Init_InnerkitsTest_TestSysCap001, TestSize.Level1)
free(wrongName);
}
+#define API_VERSION_MAX 999
+// TestIsApiVersionGreaterOrEqual
+HWTEST_F(InnerkitsUnitTest, Init_InnerkitsTest_TestIsApiVersionGreaterOrEqual001, TestSize.Level1)
+{
+ // 验证非法版本
+ bool ret = CheckApiVersionGreaterOrEqual(0, 0, 0);
+ EXPECT_EQ(ret, false);
+ ret = CheckApiVersionGreaterOrEqual(API_VERSION_MAX + 1, 0, 0);
+ EXPECT_EQ(ret, false);
+ ret = CheckApiVersionGreaterOrEqual(1, -1, 0);
+ EXPECT_EQ(ret, false);
+ ret = CheckApiVersionGreaterOrEqual(1, API_VERSION_MAX + 1, 0);
+ EXPECT_EQ(ret, false);
+ ret = CheckApiVersionGreaterOrEqual(1, 0, -1);
+ EXPECT_EQ(ret, false);
+ ret = CheckApiVersionGreaterOrEqual(1, 0, API_VERSION_MAX + 1);
+ EXPECT_EQ(ret, false);
+
+ // 获取设备api版本号
+ int majorApiVersion = GetSdkApiVersion();
+ int minorApiVersion = GetSdkMinorApiVersion();
+ int patchApiVersion = GetSdkPatchApiVersion();
+ printf("IsApiVersionGreaterOrEqual, major:%d, minor:%d, patch:%d\n", majorApiVersion,
+ minorApiVersion, patchApiVersion);
+ // 设备版本号异常校验
+ if (majorApiVersion < 1 || majorApiVersion > API_VERSION_MAX ||
+ minorApiVersion < -1 || minorApiVersion > API_VERSION_MAX ||
+ patchApiVersion < -1 || minorApiVersion > API_VERSION_MAX) {
+ EXPECT_EQ(ret, true);
+ } else {
+ // 验证传参等于系统版本时返回true
+ ret = CheckApiVersionGreaterOrEqual(majorApiVersion, minorApiVersion, patchApiVersion);
+ EXPECT_EQ(ret, true);
+ majorApiVersion += 1;
+ ret = CheckApiVersionGreaterOrEqual(majorApiVersion, minorApiVersion, patchApiVersion);
+ EXPECT_EQ(ret, false);
+ majorApiVersion -= 2;
+ ret = CheckApiVersionGreaterOrEqual(majorApiVersion, minorApiVersion, patchApiVersion);
+ if (majorApiVersion > API_VERSION_MAX || majorApiVersion < 1) {
+ EXPECT_EQ(ret, false);
+ } else {
+ EXPECT_EQ(ret, true);
+ }
+ majorApiVersion += 1;
+ minorApiVersion += 1;
+ ret = CheckApiVersionGreaterOrEqual(majorApiVersion, minorApiVersion, patchApiVersion);
+ EXPECT_EQ(ret, false);
+ minorApiVersion -= 2;
+ ret = CheckApiVersionGreaterOrEqual(majorApiVersion, minorApiVersion, patchApiVersion);
+ if (minorApiVersion > API_VERSION_MAX || minorApiVersion < 0) {
+ EXPECT_EQ(ret, false);
+ } else {
+ EXPECT_EQ(ret, true);
+ }
+ minorApiVersion += 1;
+ patchApiVersion += 1;
+ ret = CheckApiVersionGreaterOrEqual(majorApiVersion, minorApiVersion, patchApiVersion);
+ EXPECT_EQ(ret, false);
+ patchApiVersion -= 2;
+ ret = CheckApiVersionGreaterOrEqual(majorApiVersion, minorApiVersion, patchApiVersion);
+ if (patchApiVersion > API_VERSION_MAX || patchApiVersion < 0) {
+ EXPECT_EQ(ret, false);
+ } else {
+ EXPECT_EQ(ret, true);
+ }
+ }
+}
+
// TestControlService
HWTEST_F(InnerkitsUnitTest, Init_InnerkitsTest_ControlService001, TestSize.Level1)
{
@@ -306,9 +375,9 @@ HWTEST_F(InnerkitsUnitTest, Init_InnerkitsTest_ControlService001, TestSize.Level
const char *argv[] = {"testArg"};
ServiceControlWithExtra("deviceinfoservice", RESTART, argv, 1);
ServiceControlWithExtra(nullptr, RESTART, argv, 1);
- ServiceControlWithExtra(nullptr, 3, argv, 1); // 3 is action
+ ServiceControlWithExtra(nullptr, SERVICE_ACTION_MAX, argv, 1); // 3 is action
ServiceControlWithExtra("notservie", RESTART, argv, 1);
- ServiceControlWithExtra("deviceinfoservice", 3, argv, 1); // 3 is action
+ ServiceControlWithExtra("deviceinfoservice", SERVICE_ACTION_MAX, argv, 1); // 3 is action
ServiceSetReady("deviceinfoservice");
ServiceSetReady(nullptr);
ServiceWaitForStatus("deviceinfoservice", SERVICE_READY, 1);
@@ -318,6 +387,7 @@ HWTEST_F(InnerkitsUnitTest, Init_InnerkitsTest_ControlService001, TestSize.Level
StartServiceByTimer("deviceinfoservice", 0);
StartServiceByTimer(nullptr, 0);
StopServiceTimer("deviceinfoservice");
+ ServiceControlWithExtra("deviceinfoservice", TERM, argv, 1);
}
static int TestIncommingConnect(const LoopHandle loop, const TaskHandle server)
diff --git a/test/unittest/lite/BUILD.gn b/test/unittest/lite/BUILD.gn
index 1f92813719f0480b5cf98804245d68cefbbd1fc7..2df7abe93765bbb48794fbbca8112f0d3cda9efe 100755
--- a/test/unittest/lite/BUILD.gn
+++ b/test/unittest/lite/BUILD.gn
@@ -248,7 +248,7 @@ if (defined(ohos_lite)) {
"//base/startup/init/services/loopevent:loopevent",
"//build/lite/config/component/cJSON:cjson_static",
]
- external_deps += [ "mbedtls:mbedtls_static" ]
+ external_deps += [ "mbedtls:mbedtls_shared" ]
}
}
}
diff --git a/test/unittest/loopevent/loopevent_unittest.cpp b/test/unittest/loopevent/loopevent_unittest.cpp
index 6c5c59898738e4aefc2d4a20c8df0608f6006eac..3fd8e52235fe35ab959604b796e53a7890a34fd6 100644
--- a/test/unittest/loopevent/loopevent_unittest.cpp
+++ b/test/unittest/loopevent/loopevent_unittest.cpp
@@ -275,17 +275,6 @@ HWTEST_F(LoopEventUnittest, Init_TestProcessWatcherTask_001, TestSize.Level1)
EXPECT_EQ(ret, 0);
}
-static LoopHandle g_loop = nullptr;
-static int g_timeCount = 0;
-static void Test_ProcessTimer(const TimerHandle taskHandle, void *context)
-{
- g_timeCount++;
- printf("Test_ProcessTimer %d\n", g_timeCount);
- if (g_timeCount > 1) {
- LE_StopLoop(g_loop);
- }
-}
-
HWTEST_F(LoopEventUnittest, Init_TestLoopAbnormal_001, TestSize.Level1)
{
int ret = LE_StartWatcher(nullptr, nullptr, nullptr, nullptr);
diff --git a/test/unittest/loopevent/loopserver_unittest.cpp b/test/unittest/loopevent/loopserver_unittest.cpp
index c4335eb31b0055f489831b24aa4429f845b118cc..7674e88949897ee13509d5d5ba9d4b961c4164fc 100644
--- a/test/unittest/loopevent/loopserver_unittest.cpp
+++ b/test/unittest/loopevent/loopserver_unittest.cpp
@@ -86,11 +86,6 @@ static void TestOnClose(const TaskHandle taskHandle)
{
}
-static LE_STATUS TestHandleTaskEvent(const LoopHandle loop, const TaskHandle task, uint32_t oper)
-{
- return LE_SUCCESS;
-}
-
static void TestOnReceiveRequest(const TaskHandle task, const uint8_t *buffer, uint32_t nread)
{
EXPECT_NE(buffer, nullptr);
@@ -117,14 +112,6 @@ static void TestClientOnReceiveRequest(const TaskHandle task, const uint8_t *buf
}
}
-static void ProcessAsyncEvent(const TaskHandle taskHandle, uint64_t eventId, const uint8_t *buffer, uint32_t buffLen)
-{
- UNUSED(taskHandle);
- UNUSED(eventId);
- UNUSED(buffer);
- UNUSED(buffLen);
-}
-
static void TestSendMessageComplete(const TaskHandle taskHandle, BufferHandle handle)
{
printf("SendMessage result %d \n", LE_GetSendResult(handle));
diff --git a/test/unittest/loopevent/looptimer_unittest.cpp b/test/unittest/loopevent/looptimer_unittest.cpp
index 54d3c371af60c78d64f0548a9f3a06aa0cbef340..f8e3acc1c26c329ee92981a16a905d8b5a691ea3 100644
--- a/test/unittest/loopevent/looptimer_unittest.cpp
+++ b/test/unittest/loopevent/looptimer_unittest.cpp
@@ -45,12 +45,6 @@ static void Test_ProcessTimer(const TimerHandle taskHandle, void *context)
printf("WaitTimeout count %d\n", g_maxCount);
}
-static void TimeoutCancel(const TimerHandle taskHandle, void *context)
-{
- printf("TimeoutCancel count %d", g_maxCount);
- LE_StopTimer(LE_GetDefaultLoop(), taskHandle);
-}
-
HWTEST_F(LoopTimerUnitTest, Init_Timer_001, TestSize.Level0)
{
EXPECT_EQ(LE_CreateLoop(&g_loop), 0);
diff --git a/test/unittest/param/client_unittest.cpp b/test/unittest/param/client_unittest.cpp
index 8303612750c609cb046404c911b787df3862d718..52810840d88eb9c53b5479cd870d51baa09a9d32 100644
--- a/test/unittest/param/client_unittest.cpp
+++ b/test/unittest/param/client_unittest.cpp
@@ -270,4 +270,5 @@ HWTEST_F(ClientUnitTest, Init_TestClient_006, TestSize.Level0)
EXPECT_EQ(ret, PARAM_CODE_NOT_FOUND);
#endif
}
+
} // namespace init_ut
\ No newline at end of file
diff --git a/test/unittest/param/param_stub.cpp b/test/unittest/param/param_stub.cpp
index 7c7b18cf40cdb14c26cc416c172e11d8b262fdb4..0f654d112a095c33087d5b1d48edd24f0492750b 100644
--- a/test/unittest/param/param_stub.cpp
+++ b/test/unittest/param/param_stub.cpp
@@ -308,38 +308,7 @@ static void PrepareGroupTestCfg()
CreateTestFile(GROUP_DEFAULT_PATH "/subsystem.xxx13.group.cfg", xxx13);
CreateTestFile(GROUP_DEFAULT_PATH "/subsystem.xxx14.group.cfg", xxx14);
}
-static bool IsDir(const std::string &path)
-{
- struct stat st {};
- if (stat(path.c_str(), &st) < 0) {
- return false;
- }
- return S_ISDIR(st.st_mode);
-}
-static bool DeleteDir(const std::string &path)
-{
- auto pDir = std::unique_ptr(opendir(path.c_str()), closedir);
- if (pDir == nullptr) {
- return false;
- }
- struct dirent *dp = nullptr;
- while ((dp = readdir(pDir.get())) != nullptr) {
- std::string currentName(dp->d_name);
- if (currentName[0] != '.') {
- std::string tmpName(path);
- tmpName.append("/" + currentName);
- if (IsDir(tmpName)) {
- DeleteDir(tmpName);
- }
- remove(tmpName.c_str());
- }
- }
- if (remove(path.c_str()) != 0) {
- return false;
- }
- return true;
-}
static void LoadParamFromCfg(void)
{
#ifdef PARAM_LOAD_CFG_FROM_CODE
diff --git a/test/unittest/param/watcher_agent_unittest.cpp b/test/unittest/param/watcher_agent_unittest.cpp
index 95bee11f4d571854ce29b0fe14c8afa42c6d2c46..f4bf3dbba62bdf007f7f3022bfd1edeab471ab7a 100644
--- a/test/unittest/param/watcher_agent_unittest.cpp
+++ b/test/unittest/param/watcher_agent_unittest.cpp
@@ -297,6 +297,7 @@ HWTEST_F(WatcherAgentUnitTest, Init_TestResetService_001, TestSize.Level0)
{
WatcherAgentUnitTest test;
test.TestResetService();
+ test.TestResetService();
}
HWTEST_F(WatcherAgentUnitTest, Init_TestWatcherService_001, TestSize.Level0)
diff --git a/test/unittest/param/watcher_proxy_unittest.cpp b/test/unittest/param/watcher_proxy_unittest.cpp
index 83624aeb37f76aa8c348780a265cbde73cc16e97..08534aa316c9d25f04f4462bad4e1d9ae6d70d49 100644
--- a/test/unittest/param/watcher_proxy_unittest.cpp
+++ b/test/unittest/param/watcher_proxy_unittest.cpp
@@ -254,7 +254,6 @@ public:
WatcherManagerPtr watcherManager = GetWatcherManager();
WATCHER_CHECK(watcherManager != nullptr, return -1, "Failed to get manager");
watcherManager->OnStop();
- watcherManager->Clear();
return 0;
}
@@ -373,8 +372,6 @@ HWTEST_F(WatcherProxyUnitTest, Init_TestStop_001, TestSize.Level0)
{
WatcherProxyUnitTest test;
uint32_t watcherId = 0;
- fdsan_set_error_level(FDSAN_ERROR_LEVEL_DISABLED);
-
test.TestAddRemoteWatcher(getpid(), watcherId);
test.TestAddWatcher("test.permission.watcher.stop", watcherId);
test.TestStop();
diff --git a/test/unittest/remount/remount_overlay_unittest.cpp b/test/unittest/remount/remount_overlay_unittest.cpp
index 0178fe4211e2979c9a3ab4384b94dcfb415e2258..c43ac08f15c82ea7d2abb301ceca21f88b64bed0 100644
--- a/test/unittest/remount/remount_overlay_unittest.cpp
+++ b/test/unittest/remount/remount_overlay_unittest.cpp
@@ -13,12 +13,14 @@
* limitations under the License.
*/
+#include
#include "remount_overlay.h"
-#include "securec.h"
#include "param_stub.h"
#include "mntent.h"
+
using namespace std;
using namespace testing::ext;
+
namespace init_ut {
class RemountOverlayUnitTest : public testing::Test {
public:
@@ -30,11 +32,11 @@ public:
HWTEST_F(RemountOverlayUnitTest, Init_MntNeedRemountTest_001, TestSize.Level0)
{
- char *path = "/test";
+ const char *path = "/test";
bool ret = MntNeedRemount(path);
EXPECT_EQ(ret, false);
- char *path2 = "/";
+ const char *path2 = "/";
ret = MntNeedRemount(path2);
EXPECT_EQ(ret, true);
}
@@ -45,25 +47,32 @@ HWTEST_F(RemountOverlayUnitTest, Init_IsSkipRemountTest_001, TestSize.Level0)
bool ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
- mentry.mnt_type = "ufs";
- mentry.mnt_dir = "test";
+ char ufs[] = "ufs";
+ char test[] = "test";
+ mentry.mnt_type = ufs;
+ mentry.mnt_dir = test;
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
- mentry.mnt_dir = "/";
+ char root[] = "/";
+ mentry.mnt_dir = root;
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
- mentry.mnt_type = "er11ofs";
+ char erofs1[] = "er11ofs";
+ mentry.mnt_type = erofs1;
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
- mentry.mnt_type = "erofs";
- mentry.mnt_fsname = "/dev/block/ndm-";
+ char erofs[] = "erofs";
+ char ndm[] = "/dev/block/ndm-";
+ mentry.mnt_type = erofs;
+ mentry.mnt_fsname = ndm;
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, true);
- mentry.mnt_fsname = "/dev/block/dm-1";
+ char dm1[] = "/dev/block/dm-1";
+ mentry.mnt_fsname = dm1;
ret = IsSkipRemount(mentry);
EXPECT_EQ(ret, false);
}
@@ -74,11 +83,13 @@ HWTEST_F(RemountOverlayUnitTest, Init_ExecCommand_001, TestSize.Level0)
int result = ExecCommand(0, nullArgv);
EXPECT_NE(result, 0); // Expect success
- char *validArgv[] = {"/bin/ls", NULL}; // A valid command
+ const char *valid = "/bin/ls";
+ char *validArgv[] = {const_cast(valid), NULL}; // A valid command
result = ExecCommand(1, validArgv);
EXPECT_NE(result, 0); // Expect success
- char *invalidArgv[] = {"/notexit/ls", NULL}; // A valid command
+ const char *invalid = "/notexit/ls";
+ char *invalidArgv[] = {const_cast(invalid), NULL}; // A valid command
result = ExecCommand(1, invalidArgv);
EXPECT_NE(result, 0); // Expect success
}
@@ -98,6 +109,7 @@ HWTEST_F(RemountOverlayUnitTest, Init_GetDevSizeTest_001, TestSize.Level0)
EXPECT_NE(ret, 0);
remove(fileName);
}
+
HWTEST_F(RemountOverlayUnitTest, Init_FormatExt4Test_001, TestSize.Level0)
{
const char *fileName = "";
@@ -113,5 +125,4 @@ HWTEST_F(RemountOverlayUnitTest, Init_FormatExt4Test_001, TestSize.Level0)
EXPECT_NE(ret, 0);
remove(fileName);
}
-
}
\ No newline at end of file
diff --git a/test/unittest/seccomp/seccomp_unittest.cpp b/test/unittest/seccomp/seccomp_unittest.cpp
index 393e73fe04fa75b14fa68a3d534510cc7db695f4..91ff298f00488d2a18cadf90bf8a0bda618b5c18 100644
--- a/test/unittest/seccomp/seccomp_unittest.cpp
+++ b/test/unittest/seccomp/seccomp_unittest.cpp
@@ -397,6 +397,45 @@ public:
EXPECT_EQ(ret, 0);
}
+ static bool CheckIoUringFlag1()
+ {
+ (void)syscall(SYS_io_uring_setup, 0, nullptr);
+ return true;
+ }
+
+ static bool CheckIoUringFlag2()
+ {
+ (void)syscall(SYS_io_uring_enter, 0, nullptr, 0, 0, nullptr);
+ return true;
+ }
+
+ static bool CheckIoUringFlag3()
+ {
+ (void)syscall(SYS_io_uring_register, 0, "example", 0);
+ return true;
+ }
+
+ void TestAppAllowIoUringSyscall()
+ {
+ int ret = CheckSyscall(APP, APP_ALLOW_IOURING, CheckIoUringFlag1, true);
+ EXPECT_EQ(ret, 0);
+
+ ret = CheckSyscall(APP, APP_NAME, CheckIoUringFlag1, false);
+ EXPECT_EQ(ret, 0);
+
+ ret = CheckSyscall(APP, APP_ALLOW_IOURING, CheckIoUringFlag2, true);
+ EXPECT_EQ(ret, 0);
+
+ ret = CheckSyscall(APP, APP_NAME, CheckIoUringFlag2, false);
+ EXPECT_EQ(ret, 0);
+
+ ret = CheckSyscall(APP, APP_ALLOW_IOURING, CheckIoUringFlag3, true);
+ EXPECT_EQ(ret, 0);
+
+ ret = CheckSyscall(APP, APP_NAME, CheckIoUringFlag3, false);
+ EXPECT_EQ(ret, 0);
+ }
+
#if defined __aarch64__
static bool CheckMqOpen()
{
@@ -716,11 +755,11 @@ public:
void TestSeccompCustomSyscall()
{
// app custom allowlist
- ret = CheckSyscall(APP, APP_CUSTOM, CheckGetpid, true);
+ int ret = CheckSyscall(APP, APP_CUSTOM, CheckGetpid, true);
EXPECT_EQ(ret, 0);
- // app custom blocklist
- int ret = CheckSyscall(APP, APP_CUSTOM, CheckSetuid, false);
+ // app custom allow blocklist
+ ret = CheckSyscall(APP, APP_CUSTOM, CheckSetuid, true);
EXPECT_EQ(ret, 0);
}
#endif
@@ -1324,6 +1363,18 @@ HWTEST_F(SeccompUnitTest, Init_Seccomp_AppSycall002, TestSize.Level1)
test.TestAppAtomicSyscallForIoctl();
}
+/**
+ * @tc.name: TestAppIoUringSycall
+ * @tc.desc: Verify the app seccomp policy with io uring.
+ * @tc.type: FUNC
+ * @tc.require: issueI5MUXD
+ */
+HWTEST_F(SeccompUnitTest, Init_Seccomp_AppSycall003, TestSize.Level1)
+{
+ SeccompUnitTest test;
+ test.TestAppAllowIoUringSyscall();
+}
+
/**
* @tc.name: TestSystemSyscallForUidFilter
* @tc.desc: Verify the system seccomp policy.
diff --git a/test/unittest/single_test/fstab_mount/BUILD.gn b/test/unittest/single_test/fstab_mount/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..8edf40317a163eb640db77fb1edb59fc42c135d1
--- /dev/null
+++ b/test/unittest/single_test/fstab_mount/BUILD.gn
@@ -0,0 +1,66 @@
+# Copyright (c) 2025 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import("//base/startup/init/begetd.gni")
+import("//build/test.gni")
+
+ohos_unittest("fstab_mount_unittest") {
+ module_out_path = "init/init"
+ include_dirs = [
+ "//base/startup/init/test/unittest/single_test/fstab_mount/include",
+ "//base/startup/init/services/init/include",
+ "//base/startup/init/services/log",
+ "//base/startup/init/services/init/standard",
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/ueventd/include",
+ "//base/startup/init/interfaces/innerkits/fs_manager/switch_root/include",
+ "//base/startup/init/interfaces/innerkits/init_module_engine/include",
+ "//base/startup/init/test/mock/libc/include"
+ ]
+
+ sources = [
+ "//base/startup/init/interfaces/innerkits/fs_manager/fstab_mount.c",
+ "//base/startup/init/test/unittest/single_test/fstab_mount/src/fstab_mount_test.cpp",
+ "//base/startup/init/test/unittest/single_test/fstab_mount/src/func_wrapper.cpp",
+ ]
+
+ cflags_cc = [ "-fexceptions" ]
+ ldflags = [
+ "-Wl,--wrap=strdup",
+ "-Wl,--wrap=stat",
+ "-Wl,--wrap=mount",
+ "-Wl,--wrap=mkdir",
+ "-Wl,--wrap=malloc",
+ "-Wl,--wrap=strncat_s",
+ "-Wl,--wrap=snprintf_s",
+ ]
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static",
+ ]
+
+ defines = [
+ "STARTUP_INIT_UT_PATH =\"/data/init_ut\"",
+ "ASAN_DETECTOR",
+ "STARTUP_INIT_TEST",
+ ]
+
+ configs = []
+
+ external_deps = [
+ "bounds_checking_function:libsec_static",
+ "cJSON:cjson",
+ "c_utils:utils",
+ "googletest:gtest",
+ "hilog:libhilog",
+ ]
+}
diff --git a/test/unittest/single_test/fstab_mount/include/fstab_mount_test.h b/test/unittest/single_test/fstab_mount/include/fstab_mount_test.h
new file mode 100644
index 0000000000000000000000000000000000000000..72b16634a11d130afc2d9d7109504316f1789d80
--- /dev/null
+++ b/test/unittest/single_test/fstab_mount/include/fstab_mount_test.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2025 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 INIT_FSTAB_MOUNT_TEST_H
+#define INIT_FSTAB_MOUNT_TEST_H
+#include "fs_manager/fs_manager.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int MountWithCheckpoint(const char *source, const char *target,
+ const char *fsType, unsigned long flags, const char *data);
+
+int GetDataWithoutCheckpoint(char *fsSpecificData, size_t fsSpecificDataSize,
+ char *checkpointData, size_t checkpointDataSize);
+
+int DoMountOneItem(FstabItem *item);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/test/unittest/single_test/fstab_mount/include/func_wrapper.h b/test/unittest/single_test/fstab_mount/include/func_wrapper.h
new file mode 100644
index 0000000000000000000000000000000000000000..477c53eb5a5072d2d4ac113d3b50d93bb5fbe229
--- /dev/null
+++ b/test/unittest/single_test/fstab_mount/include/func_wrapper.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2025 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 TEST_WRAPPER_H
+#define TEST_WRAPPER_H
+#include
+#include
+#include
+#include
+#include
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+// for wrapper strdup;
+char* __real_strdup(const char* string);
+typedef char* (*StrdupFunc)(const char* string);
+void UpdateStrdupFunc(StrdupFunc func);
+
+// for wrapper malloc;
+void* __real_malloc(size_t size);
+typedef void* (*MallocFunc)(size_t size);
+void UpdateMallocFunc(MallocFunc func);
+
+// for wrapper strncat_s;
+int __real_strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
+typedef int (*StrncatSFunc)(char *strDest, size_t destMax, const char *strSrc, size_t count);
+void UpdateStrncatSFunc(StrncatSFunc func);
+
+// for wrapper mkdir;
+int __real_mkdir(const char *path, mode_t mode);
+typedef int (*MkdirFunc)(const char *path, mode_t mode);
+void UpdateMkdirFunc(MkdirFunc func);
+
+// for wrapper mount;
+int __real_mount(const char *source, const char *target, const char *fsType, unsigned long flags, const void *data);
+typedef int (*MountFunc)(const char *source, const char *target,
+ const char *fsType, unsigned long flags, const void *data);
+void UpdateMountFunc(MountFunc func);
+
+// for wrapper stat;
+int __real_stat(const char *pathname, struct stat *buf);
+typedef int (*StatFunc)(const char *pathname, struct stat *buf);
+void UpdateStatFunc(StatFunc func);
+
+// for wrapper snprintf_s;
+size_t __real_snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, ...);
+typedef size_t (*SnprintfSFunc)(char *strDest, size_t destMax, size_t count, const char *format, ...);
+void UpdateSnprintfSFunc(SnprintfSFunc func);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+#endif // TEST_WRAPPER_H
\ No newline at end of file
diff --git a/test/unittest/single_test/fstab_mount/src/fstab_mount_test.cpp b/test/unittest/single_test/fstab_mount/src/fstab_mount_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..dc1975374e3895ec6edfda6c5a8dc0231db23f5d
--- /dev/null
+++ b/test/unittest/single_test/fstab_mount/src/fstab_mount_test.cpp
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 2025 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 "fstab_mount_test.h"
+#include
+#include "func_wrapper.h"
+#include
+#include
+#include "init_utils.h"
+#include "securec.h"
+using namespace testing;
+using namespace testing::ext;
+#define STRSIZE 64
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+size_t SnprintfSReturnZero(char *strDest, size_t destMax, size_t count, const char *format, ...)
+{
+ return 0;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
+
+
+namespace OHOS {
+class FstabMountTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void FstabMountTest::SetUpTestCase()
+{
+ GTEST_LOG_(INFO) << "FstabMountTest SetUpTestCase";
+}
+
+void FstabMountTest::TearDownTestCase()
+{
+ GTEST_LOG_(INFO) << "FstabMountTest TearDownTestCase";
+}
+
+void FstabMountTest::SetUp()
+{
+ GTEST_LOG_(INFO) << "FstabMountTest SetUp";
+}
+
+void FstabMountTest::TearDown()
+{
+ GTEST_LOG_(INFO) << "FstabMountTest TearDown";
+}
+
+HWTEST_F(FstabMountTest, DoOneMountItem_001, TestSize.Level0)
+{
+ char deviceName[STRSIZE] = "deviceName";
+ char mountPoint[STRSIZE] = "mountPoint";
+ char fsType[STRSIZE] = "fstype";
+ char mountOptions[STRSIZE] = "op1,op2,op3,op4,op5";
+ unsigned int fsManagerFlags = 0;
+
+ FstabItem item = {
+ .deviceName = deviceName,
+ .mountPoint = mountPoint,
+ .fsType = fsType,
+ .mountOptions = mountOptions,
+ .fsManagerFlags = fsManagerFlags,
+ .next = NULL,
+ };
+
+ int rc = DoMountOneItem(&item);
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, DoOneMountItem_002, TestSize.Level0)
+{
+ char deviceName[STRSIZE] = "deviceName";
+ char mountPoint[STRSIZE] = "mountPoint";
+ char fsType[STRSIZE] = "hmfs";
+ char mountOptions[STRSIZE] = "op1,op2,op3,op4,op5,checkpoint=disable";
+ unsigned int fsManagerFlags = 0;
+
+ FstabItem item = {
+ .deviceName = deviceName,
+ .mountPoint = mountPoint,
+ .fsType = fsType,
+ .mountOptions = mountOptions,
+ .fsManagerFlags = fsManagerFlags,
+ .next = NULL,
+ };
+
+ int rc = DoMountOneItem(&item);
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, GetDataWithoutCheckpoint_001, TestSize.Level0)
+{
+ int rc = GetDataWithoutCheckpoint(nullptr, 0, nullptr, 0);
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, GetDataWithoutCheckpoint_002, TestSize.Level0)
+{
+ char fsData[STRSIZE] = "checkpoint=disable,op1,op2,op3";
+ int rc = GetDataWithoutCheckpoint(fsData, STRSIZE, nullptr, 0);
+ EXPECT_EQ(rc, -1);
+
+ char result[STRSIZE] = {0};
+ rc = GetDataWithoutCheckpoint(fsData, STRSIZE, result, STRSIZE);
+ EXPECT_EQ(rc, 0);
+}
+
+HWTEST_F(FstabMountTest, GetDataWithoutCheckpoint_003, TestSize.Level0)
+{
+ char fsData[STRSIZE] = "checkpoint=disable,op1,op2,op3,op4,op5";
+ char result[STRSIZE] = {0};
+ StrdupFunc func = [](const char *path) -> char *
+ {
+ return nullptr;
+ };
+ UpdateStrdupFunc(func);
+ int rc = GetDataWithoutCheckpoint(fsData, STRSIZE, result, STRSIZE);
+ UpdateStrdupFunc(nullptr);
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, GetDataWithoutCheckpoint_004, TestSize.Level0)
+{
+ char fsData[STRSIZE] = "checkpoint=disable,op1,op2,op3,op4,op5";
+ char result[STRSIZE] = {0};
+ MallocFunc func = [](size_t size) -> void* {
+ return nullptr;
+ };
+ UpdateMallocFunc(func);
+ int rc = GetDataWithoutCheckpoint(fsData, STRSIZE, result, STRSIZE);
+ UpdateMallocFunc(nullptr);
+ EXPECT_EQ(rc, -1);
+}
+
+
+HWTEST_F(FstabMountTest, GetDataWithoutCheckpoint_005, TestSize.Level0)
+{
+ char fsData[STRSIZE] = "checkpoint=disable,op1,op2,op3,op4,op5";
+ char result[STRSIZE] = {0};
+ StrncatSFunc func = [](char * strDest, size_t destMax, const char * strSrc, size_t count) -> int {
+ if (strcmp(strSrc, ",") == 0) {
+ return -1;
+ }
+ return __real_strncat_s(strDest, destMax, strSrc, count);
+ };
+ UpdateStrncatSFunc(func);
+ int rc = GetDataWithoutCheckpoint(fsData, STRSIZE, result, STRSIZE);
+ UpdateStrncatSFunc(nullptr);
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, GetDataWithoutCheckpoint_006, TestSize.Level0)
+{
+ char fsData[STRSIZE] = "checkpoint=disable,op1,op2,op3,op4,op5";
+ char result[STRSIZE] = {0};
+ StrncatSFunc func = [](char *, size_t, const char *, size_t) -> int {
+ return -1;
+ };
+ UpdateStrncatSFunc(func);
+ int rc = GetDataWithoutCheckpoint(fsData, STRSIZE, result, STRSIZE);
+ UpdateStrncatSFunc(nullptr);
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, MountWithCheckpoint_001, TestSize.Level0)
+{
+ StatFunc func = [](const char* path, struct stat *) -> int {
+ return 0;
+ };
+ UpdateStatFunc(func);
+ int rc = MountWithCheckpoint("/source", "/target", "fsType", 0, "op1,op2,op3,op4,op5");
+ UpdateStatFunc(nullptr);
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, MountWithCheckpoint_002, TestSize.Level0)
+{
+ StatFunc func = [](const char* path, struct stat *) -> int {
+ return 0;
+ };
+ UpdateStatFunc(func);
+
+ MkdirFunc mkdirFunc = [](const char*, mode_t) -> int {
+ return 0;
+ };
+ UpdateMkdirFunc(mkdirFunc);
+ UpdateSnprintfSFunc(SnprintfSReturnZero);
+
+ int rc = MountWithCheckpoint("/source", "/target", "fsType", 0, "op1,op2,op3,op4,op5");
+ UpdateStatFunc(nullptr);
+ UpdateMkdirFunc(nullptr);
+ UpdateSnprintfSFunc(nullptr);
+
+ EXPECT_EQ(rc, -1);
+}
+
+HWTEST_F(FstabMountTest, MountWithCheckpoint_003, TestSize.Level0)
+{
+ StatFunc func = [](const char* path, struct stat *) -> int {
+ return 0;
+ };
+ UpdateStatFunc(func);
+
+ MkdirFunc mkdirFunc = [](const char*, mode_t) -> int {
+ return 0;
+ };
+ UpdateMkdirFunc(mkdirFunc);
+
+ MountFunc mountFunc = [](const char *, const char *, const char *, unsigned long, const void *) -> int {
+ errno = EBUSY;
+ return -1;
+ };
+ UpdateMountFunc(mountFunc);
+
+ int rc = MountWithCheckpoint("/source", "/target", "fsType", 0, "op1,op2,op3,op4,op5");
+ UpdateStatFunc(nullptr);
+ UpdateMkdirFunc(nullptr);
+ UpdateMountFunc(nullptr);
+
+ EXPECT_EQ(rc, 0);
+}
+
+}
\ No newline at end of file
diff --git a/test/unittest/single_test/fstab_mount/src/func_wrapper.cpp b/test/unittest/single_test/fstab_mount/src/func_wrapper.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..91180944195fc4ccb30f62b821c05fdda759183f
--- /dev/null
+++ b/test/unittest/single_test/fstab_mount/src/func_wrapper.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2025 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 "func_wrapper.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif
+#endif
+
+// start wrap strdup
+static StrdupFunc g_strdup = NULL;
+void UpdateStrdupFunc(StrdupFunc func)
+{
+ g_strdup = func;
+}
+char* __wrap_strdup(const char* string)
+{
+ if (g_strdup) {
+ return g_strdup(string);
+ } else {
+ return __real_strdup(string);
+ }
+}
+
+// start wrap malloc
+static MallocFunc g_malloc = NULL;
+void UpdateMallocFunc(MallocFunc func)
+{
+ g_malloc = func;
+}
+void* __wrap_malloc(size_t size)
+{
+ if (g_malloc) {
+ return g_malloc(size);
+ } else {
+ return __real_malloc(size);
+ }
+}
+
+// start wrap strncat_s
+static StrncatSFunc g_strncat_s = NULL;
+void UpdateStrncatSFunc(StrncatSFunc func)
+{
+ g_strncat_s = func;
+}
+int __wrap_strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count)
+{
+ if (g_strncat_s) {
+ return g_strncat_s(strDest, destMax, strSrc, count);
+ } else {
+ return __real_strncat_s(strDest, destMax, strSrc, count);
+ }
+}
+
+// start wrap mkdir
+static MkdirFunc g_mkdir = NULL;
+void UpdateMkdirFunc(MkdirFunc func)
+{
+ g_mkdir = func;
+}
+int __wrap_mkdir(const char *path, mode_t mode)
+{
+ if (g_mkdir) {
+ return g_mkdir(path, mode);
+ } else {
+ return __real_mkdir(path, mode);
+ }
+}
+
+// start wrap mount
+static MountFunc g_mount = NULL;
+void UpdateMountFunc(MountFunc func)
+{
+ g_mount = func;
+}
+int __wrap_mount(const char *source, const char *target,
+ const char *fsType, unsigned long flags, const void *data)
+{
+ if (g_mount) {
+ return g_mount(source, target, fsType, flags, data);
+ } else {
+ return __real_mount(source, target, fsType, flags, data);
+ }
+}
+
+// start wrap stat
+static StatFunc g_stat = NULL;
+void UpdateStatFunc(StatFunc func)
+{
+ g_stat = func;
+}
+int __wrap_stat(const char *pathname, struct stat *buf)
+{
+ if (g_stat) {
+ return g_stat(pathname, buf);
+ } else {
+ return __real_stat(pathname, buf);
+ }
+}
+
+// start wrap snprintf_s
+static SnprintfSFunc g_snprintf_s = NULL;
+void UpdateSnprintfSFunc(SnprintfSFunc func)
+{
+ g_snprintf_s = func;
+}
+size_t __wrap_snprintf_s(char *strDest, size_t destMax, size_t count, const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ size_t rc;
+ if (g_snprintf_s) {
+ rc = g_snprintf_s(strDest, destMax, count, format, args);
+ } else {
+ rc = __real_snprintf_s(strDest, destMax, count, format, args);
+ }
+ va_end(args);
+ return rc;
+}
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif
+#endif
diff --git a/test/unittest/single_test/init_firststage/BUILD.gn b/test/unittest/single_test/init_firststage/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..985ed1eb204f1837887487f761f643e52143f6a6
--- /dev/null
+++ b/test/unittest/single_test/init_firststage/BUILD.gn
@@ -0,0 +1,60 @@
+# Copyright (c) 2025 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import("//base/startup/init/begetd.gni")
+import("//build/test.gni")
+
+ohos_unittest("init_firststage_unittest") {
+ module_out_path = "init/init"
+ include_dirs = [
+ "//base/startup/init/test/unittest/single_test/init_firststage/include",
+ "//base/startup/init/services/init/include",
+ "//base/startup/init/services/log",
+ "//base/startup/init/services/init/standard",
+ "//base/startup/init/interfaces/innerkits/include",
+ "//base/startup/init/ueventd/include",
+ "//base/startup/init/interfaces/innerkits/fs_manager/switch_root/include",
+ "//base/startup/init/interfaces/innerkits/init_module_engine/include",
+ ]
+
+ sources = [
+ "//base/startup/init/services/init/standard/init_firststage.c",
+ "//base/startup/init/test/unittest/single_test/init_firststage/src/init_firststage_test.cpp",
+ ]
+
+ cflags_cc = [ "-fexceptions" ]
+ cflags = [
+ "-Dexecv=ExecvStub",
+ "-DCloseStdio=CloseStdioStub",
+ "-Daccess=AccessStub",
+ ]
+
+ deps = [
+ "//base/startup/init/interfaces/innerkits:libbegetutil",
+ "//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static",
+ ]
+
+ defines = [
+ "STARTUP_INIT_UT_PATH =\"/data/init_ut\"",
+ "ASAN_DETECTOR",
+ "STARTUP_INIT_TEST",
+ ]
+
+ configs = []
+
+ external_deps = [
+ "cJSON:cjson",
+ "c_utils:utils",
+ "googletest:gtest",
+ "hilog:libhilog",
+ ]
+}
diff --git a/test/unittest/single_test/init_firststage/include/init_firststage_test.h b/test/unittest/single_test/init_firststage/include/init_firststage_test.h
new file mode 100644
index 0000000000000000000000000000000000000000..9d82a5655a5e5f6fe5b3eed201899199686136f9
--- /dev/null
+++ b/test/unittest/single_test/init_firststage/include/init_firststage_test.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2025 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 INIT_FIRSTSTAGE_TEST_H
+#define INIT_FIRSTSTAGE_TEST_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void StartSecondStageInit(long long uptime);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
\ No newline at end of file
diff --git a/test/unittest/single_test/init_firststage/src/init_firststage_test.cpp b/test/unittest/single_test/init_firststage/src/init_firststage_test.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c8746dccc3cf87318e70573ae972907a073002a6
--- /dev/null
+++ b/test/unittest/single_test/init_firststage/src/init_firststage_test.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "init_firststage_test.h"
+#include
+
+#include
+
+using namespace testing;
+using namespace testing::ext;
+static int g_access = 0;
+
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+int ExecvStub(const char *pathname, char *const argv[])
+{
+ printf("do execv %s \n", pathname);
+ return 0;
+}
+
+int CreateTestFile(const char *fileName, const char *data)
+{
+ FILE *tmpFile = fopen(fileName, "wr");
+ if (tmpFile != nullptr) {
+ fprintf(tmpFile, "%s", data);
+ (void)fflush(tmpFile);
+ fclose(tmpFile);
+ }
+ return tmpFile != nullptr;
+}
+
+int AccessStub(const char *pathname, int mode)
+{
+ printf("access %s \n", pathname);
+ return g_access;
+}
+
+void CloseStdioStub(void)
+{
+ printf("close stdio \n");
+}
+
+#ifdef __cplusplus
+ }
+#endif
+
+namespace OHOS {
+class InitFirststageTest : public testing::Test {
+public:
+ static void SetUpTestCase();
+ static void TearDownTestCase();
+ void SetUp();
+ void TearDown();
+};
+
+void InitFirststageTest::SetUpTestCase()
+{
+ GTEST_LOG_(INFO) << "InitFirststageTest SetUpTestCase";
+}
+
+void InitFirststageTest::TearDownTestCase()
+{
+ GTEST_LOG_(INFO) << "InitFirststageTest TearDownTestCase";
+}
+
+void InitFirststageTest::SetUp()
+{
+ GTEST_LOG_(INFO) << "InitFirststageTest SetUp";
+}
+
+void InitFirststageTest::TearDown()
+{
+ GTEST_LOG_(INFO) << "InitFirststageTest TearDown";
+}
+
+HWTEST_F(InitFirststageTest, AsanTest_001, TestSize.Level0)
+{
+ int ret = CreateTestFile("/log/asanTest", "test");
+ StartSecondStageInit(0);
+ g_access = -1;
+ StartSecondStageInit(0);
+ EXPECT_TRUE(ret);
+}
+
+}
\ No newline at end of file
diff --git a/test/unittest/syspara/syspara_unittest.cpp b/test/unittest/syspara/syspara_unittest.cpp
index 883d2109817e19b49536c05d1bf1a3a007739b4e..aef246ede8f5168ad11efc168d3cef25a9ab36a4 100644
--- a/test/unittest/syspara/syspara_unittest.cpp
+++ b/test/unittest/syspara/syspara_unittest.cpp
@@ -108,6 +108,12 @@ HWTEST_F(SysparaUnitTest, parameterTest001_1, TestSize.Level0)
int sdkApiVersion = GetSdkApiVersion();
printf("SDK api version =%d\n", sdkApiVersion);
EXPECT_NE(sdkApiVersion, -1);
+ int sdkMinorApiVersion = GetSdkMinorApiVersion();
+ printf("SDK MinorApi version =%d\n", sdkMinorApiVersion);
+ EXPECT_EQ((sdkMinorApiVersion >= -1), true);
+ int sdkPatchApiVersion = GetSdkPatchApiVersion();
+ printf("SDK PatchApi version =%d\n", sdkPatchApiVersion);
+ EXPECT_EQ((sdkPatchApiVersion >= -1), true);
const char *incrementalVersion = GetIncrementalVersion();
printf("Incremental version = %s\n", incrementalVersion);
EXPECT_STRNE(incrementalVersion, nullptr);
@@ -442,7 +448,10 @@ HWTEST_F(SysparaUnitTest, parameterTest0017, TestSize.Level0)
EXPECT_GT(GetDistributionOSApiVersion(), 0);
printf("distributionOS name =%s\n", GetDistributionOSReleaseType());
EXPECT_STRNE(GetDistributionOSReleaseType(), nullptr);
- printf("distributionOS name =%s\n", GetDistributionOSApiName());
+ printf("distributionOS api name =%s\n", GetDistributionOSApiName());
+ printf("PerformanceClassLevel =%d\n", GetPerformanceClass());
+ EXPECT_GE(GetPerformanceClass(), 0);
+ EXPECT_LE(GetPerformanceClass(), 2);
}
#endif
@@ -459,4 +468,23 @@ HWTEST_F(SysparaUnitTest, parameterTest0018, TestSize.Level0)
ret = SaveParameters();
EXPECT_EQ(ret, 0);
}
+
+#ifndef OHOS_LITE
+HWTEST_F(SysparaUnitTest, parameterTest0019, TestSize.Level0)
+{
+ char key1[] = "const.test.for_update_test";
+ char key2[] = "persist.test.for_update_test";
+ char value1[] = "initSet";
+ char value2[] = "initUpdate";
+
+ int ret = SystemUpdateConstParam(key1, value2);
+ EXPECT_EQ(ret, PARAM_CODE_INVALID_NAME);
+ ret = SystemWriteParam(key1, value1);
+ EXPECT_EQ(ret, 0);
+ ret = SystemUpdateConstParam(key1, value2);
+ EXPECT_EQ(ret, 0);
+ ret = SystemUpdateConstParam(key2, value2);
+ EXPECT_EQ(ret, PARAM_CODE_INVALID_NAME);
+}
+#endif
} // namespace OHOS
diff --git a/test/unittest/ueventd/ueventd_event_unittest.cpp b/test/unittest/ueventd/ueventd_event_unittest.cpp
index 831814c917f36e4bce4d13ef4d662be46974a62d..465ca7ac380aefa18d66988c7f65338a10344ee7 100644
--- a/test/unittest/ueventd/ueventd_event_unittest.cpp
+++ b/test/unittest/ueventd/ueventd_event_unittest.cpp
@@ -247,6 +247,27 @@ static int TestRetriggerUeventByPath(int sockFd, char *path)
return 0;
}
+static int RetriggerSpecialUevent(int sockFd, char *path, CompareUevent compare, struct Uevent *event)
+{
+ if (event == NULL || compare == NULL) {
+ return -1;
+ }
+ return compare(event);
+}
+
+static int TestRetriggerSpecialUevent(int sockFd, char *path, CompareUevent compare, struct Uevent *event)
+{
+ return RetriggerSpecialUevent(sockFd, path, compare, event);
+}
+
+static int CompareUserData(struct Uevent *uevent)
+{
+ if (uevent == nullptr) {
+ return -1;
+ }
+ return strcmp(uevent->partitionName, "userdata");
+}
+
HWTEST_F(UeventdEventUnitTest, Init_UeventdEventUnitTest_ParseUeventdEvent001, TestSize.Level1)
{
struct Uevent uevent = {
@@ -516,6 +537,11 @@ HWTEST_F(UeventdEventUnitTest, Init_UeventdEventUnitTest_Handle001, TestSize.Lev
char path[] = {"/data/ueventd"};
int ret = TestRetriggerUeventByPath(g_oldRootFd, path);
EXPECT_EQ(ret, 0);
+ struct Uevent uevent = {
+ .partitionName = "userdata",
+ };
+ ret = TestRetriggerSpecialUevent(g_oldRootFd, path, CompareUserData, &uevent);
+ EXPECT_EQ(ret, 0);
}
HWTEST_F(UeventdEventUnitTest, Init_UeventdEventUnitTest_FirmwareUevent001, TestSize.Level1)
diff --git a/ueventd/BUILD.gn b/ueventd/BUILD.gn
index aa7b8c1d4ed400242147784abd02219fab5c0ddf..ff1fe68212c1151cd72af86fe2b367d93e6869e7 100644
--- a/ueventd/BUILD.gn
+++ b/ueventd/BUILD.gn
@@ -13,6 +13,9 @@
import("//base/startup/init/begetd.gni")
if (defined(ohos_lite)) {
+ group("libueventd_ramdisk_static_real") {
+
+ }
if (ohos_kernel_type == "linux") {
service_ueventd_deps = [
"//base/startup/init/interfaces/innerkits/socket:libsocket",
diff --git a/ueventd/etc/ueventd.config b/ueventd/etc/ueventd.config
index 2d25859130e7de10f6bd307cafc6379f85b90c4c..8c284da87427f00dbbc5686df39e521ab153b1c7 100644
--- a/ueventd/etc/ueventd.config
+++ b/ueventd/etc/ueventd.config
@@ -85,3 +85,4 @@
/dev/video* 0660 clearplay_host clearplay_host
/dev/hidraw* 0666 0 input
/dev/sg* 0660 usb_host usb_host
+/dev/signal_hub 0660 radio radio
diff --git a/ueventd/include/ueventd.h b/ueventd/include/ueventd.h
index 880c75d4392b7635a168cdbff39ef7c55e155db9..017486112dfce1899f9082f304669d2d7a8fdaae 100644
--- a/ueventd/include/ueventd.h
+++ b/ueventd/include/ueventd.h
@@ -71,12 +71,14 @@ typedef enum SUBYSTEM {
#define UEVENTD_FLAG "/dev/.ueventd_trigger_done"
extern char bootDevice[CMDLINE_VALUE_LEN_MAX];
-
+typedef int (* CompareUevent)(struct Uevent *uevent);
const char *ActionString(ACTION action);
void ParseUeventMessage(const char *buffer, ssize_t length, struct Uevent *uevent);
void RetriggerUevent(int sockFd, char **devices, int num);
void RetriggerUeventByPath(int sockFd, char *path);
-void ProcessUevent(int sockFd, char **devices, int num);
+void RetriggerDmUeventByPath(int sockFd, char *path, char **devices, int num);
+void RetriggerSpecialUevent(int sockFd, char *path, char **devices, int num, CompareUevent compare);
+void ProcessUevent(int sockFd, char **devices, int num, CompareUevent compare);
void CloseUeventConfig(void);
#ifdef __cplusplus
#if __cplusplus
diff --git a/ueventd/standard/ueventd_parameter.c b/ueventd/standard/ueventd_parameter.c
index 4145c80d4e5644a2bea8073f71175415d3a04b5c..1de8f8e8a893ce8703913077c01332e13ea3fbf5 100644
--- a/ueventd/standard/ueventd_parameter.c
+++ b/ueventd/standard/ueventd_parameter.c
@@ -78,6 +78,7 @@ static void *ThreadRun(void *data)
pthread_cond_timedwait(&(parameterCtrl->hasData), &(parameterCtrl->lock), &abstime);
}
if (parameterCtrl->shutdown) {
+ pthread_mutex_unlock(&(parameterCtrl->lock));
break;
}
pthread_mutex_unlock(&(parameterCtrl->lock));
diff --git a/ueventd/ueventd.c b/ueventd/ueventd.c
index 3b065dbf227be026dd0beb32e69697f32654c22b..5c8f78e33847e11afc8ed711481615e470034a2e 100644
--- a/ueventd/ueventd.c
+++ b/ueventd/ueventd.c
@@ -144,7 +144,7 @@ static void HandleRequiredDynamicDeviceNodes(const struct Uevent *uevent)
mode_t mask;
size_t idx = 0;
- if (uevent->deviceName == NULL) {
+ if (uevent->deviceName == NULL || uevent->major < 0 || uevent->minor < 0) {
return;
}
@@ -171,6 +171,11 @@ static void HandleRequiredDynamicDeviceNodes(const struct Uevent *uevent)
}
}
+static bool IsPatchPartitionName(const char *partitionName)
+{
+ return strcmp(partitionName, "patch_a") == 0 || strcmp(partitionName, "patch_b") == 0;
+}
+
static void HandleRequiredBlockDeviceNodes(const struct Uevent *uevent, char **devices, int num)
{
for (int i = 0; i < num; i++) {
@@ -188,8 +193,8 @@ static void HandleRequiredBlockDeviceNodes(const struct Uevent *uevent, char **d
strstr(uevent->partitionName, "ramdisk") != NULL ||
strstr(uevent->partitionName, "rvt") != NULL ||
strstr(uevent->partitionName, "dtbo") != NULL ||
- strstr(uevent->partitionName, "fw_hifi") != NULL ||
- strstr(uevent->partitionName, "modem") != NULL) {
+ strstr(uevent->partitionName, "modem_driver") != NULL ||
+ IsPatchPartitionName(uevent->partitionName)) {
INIT_LOGI("Handle required partitionName %s", uevent->partitionName);
HandleBlockDeviceEvent(uevent);
return;
@@ -248,7 +253,7 @@ static void AddUevent(struct Uevent *uevent, const char *event, size_t len)
INIT_LOGV("got uevent message:\n"
"subsystem: %s\n"
"parition: %s:%d\n"
- "action: %s\n"
+ "action: %d\n"
"devpath: %s\n"
"devname: %s\n"
"devnode: %d:%d\n"
@@ -288,7 +293,7 @@ void ParseUeventMessage(const char *buffer, ssize_t length, struct Uevent *ueven
}
}
-void ProcessUevent(int sockFd, char **devices, int num)
+void ProcessUevent(int sockFd, char **devices, int num, CompareUevent compare)
{
// One more bytes for '\0'
char ueventBuffer[UEVENT_BUFFER_SIZE] = {};
@@ -300,6 +305,11 @@ void ProcessUevent(int sockFd, char **devices, int num)
INIT_LOGV("Ignore unexpected uevent");
return;
}
+ if (compare != NULL) {
+ INIT_LOGV("find compare and do it");
+ int ret = compare(&uevent);
+ INIT_CHECK(ret == 0, return);
+ }
if (devices != NULL && num > 0) {
HandleUeventRequired(&uevent, devices, num);
} else {
@@ -308,7 +318,7 @@ void ProcessUevent(int sockFd, char **devices, int num)
}
}
-static void DoTrigger(const char *ueventPath, int sockFd, char **devices, int num)
+static void DoTrigger(const char *ueventPath, int sockFd, char **devices, int num, CompareUevent compare)
{
if (ueventPath == NULL || ueventPath[0] == '\0') {
return;
@@ -331,11 +341,11 @@ static void DoTrigger(const char *ueventPath, int sockFd, char **devices, int nu
// uevent triggered, now handle it.
if (sockFd >= 0) {
- ProcessUevent(sockFd, devices, num);
+ ProcessUevent(sockFd, devices, num, compare);
}
}
-static void Trigger(const char *path, int sockFd, char **devices, int num)
+static void Trigger(const char *path, int sockFd, char **devices, int num, CompareUevent compare)
{
if (path == NULL) {
return;
@@ -354,7 +364,7 @@ static void Trigger(const char *path, int sockFd, char **devices, int num)
if (snprintf_s(pathBuffer, PATH_MAX, PATH_MAX - 1, "%s/%s", path, dirent->d_name) == -1) {
continue;
}
- Trigger(pathBuffer, sockFd, devices, num);
+ Trigger(pathBuffer, sockFd, devices, num, compare);
} else {
if (strcmp(dirent->d_name, "uevent") != 0) {
continue;
@@ -364,7 +374,7 @@ static void Trigger(const char *path, int sockFd, char **devices, int num)
INIT_LOGW("Cannot build uevent path under %s", path);
continue;
}
- DoTrigger(ueventBuffer, sockFd, devices, num);
+ DoTrigger(ueventBuffer, sockFd, devices, num, compare);
}
}
closedir(dir);
@@ -372,14 +382,24 @@ static void Trigger(const char *path, int sockFd, char **devices, int num)
void RetriggerUeventByPath(int sockFd, char *path)
{
- Trigger(path, sockFd, NULL, 0);
+ Trigger(path, sockFd, NULL, 0, NULL);
+}
+
+void RetriggerDmUeventByPath(int sockFd, char *path, char **devices, int num)
+{
+ Trigger(path, sockFd, devices, num, NULL);
+}
+
+void RetriggerSpecialUevent(int sockFd, char *path, char **devices, int num, CompareUevent compare)
+{
+ Trigger(path, sockFd, devices, num, compare);
}
void RetriggerUevent(int sockFd, char **devices, int num)
{
int ret = GetParameterFromCmdLine("default_boot_device", bootDevice, CMDLINE_VALUE_LEN_MAX);
INIT_CHECK_ONLY_ELOG(ret == 0, "Failed get default_boot_device value from cmdline");
- Trigger("/sys/block", sockFd, devices, num);
- Trigger("/sys/class", sockFd, devices, num);
- Trigger("/sys/devices", sockFd, devices, num);
+ Trigger("/sys/block", sockFd, devices, num, NULL);
+ Trigger("/sys/class", sockFd, devices, num, NULL);
+ Trigger("/sys/devices", sockFd, devices, num, NULL);
}
diff --git a/ueventd/ueventd_device_handler.c b/ueventd/ueventd_device_handler.c
index 7dee269143195c0a3f2b2052201f41d74deea260..ec63752d658ecee800b3358f3e87fa8df2154d09 100644
--- a/ueventd/ueventd_device_handler.c
+++ b/ueventd/ueventd_device_handler.c
@@ -145,15 +145,35 @@ static void SetDeviceLable(const char *path, char **symLinks)
}
#endif
-static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, char **symLinks, bool isBlock)
+static int CreateDeviceNodeWithPermissions(const struct Uevent *uevent, const char *deviceNode, bool isBlock)
{
- int rc = -1;
int major = uevent->major;
int minor = uevent->minor;
uid_t uid = uevent->ug.uid;
gid_t gid = uevent->ug.gid;
mode_t mode = DEVMODE;
+ (void)GetDeviceNodePermissions(deviceNode, &uid, &gid, &mode);
+ mode |= isBlock ? S_IFBLK : S_IFCHR;
+ dev_t dev = makedev((unsigned int)major, (unsigned int)minor);
+
+ (void)setegid(gid);
+ mode_t originalMask = umask(000);
+ int rc = mknod(deviceNode, mode, dev);
+ (void)umask(originalMask);
+ if (rc < 0 && errno != EEXIST) {
+ INIT_LOGE("Create device node[%s %d, %d] failed. %d", deviceNode, major, minor, errno);
+ return rc;
+ }
+ AdjustDeviceNodePermissions(deviceNode, uid, gid, mode);
+ (void)setegid(0);
+ return 0;
+}
+
+static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, char **symLinks, bool isBlock)
+{
+ int rc = -1;
+
if (deviceNode == NULL || *deviceNode == '\0') {
INIT_LOGE("Invalid device file");
return rc;
@@ -177,18 +197,10 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode,
return rc;
}
- (void)GetDeviceNodePermissions(deviceNode, &uid, &gid, &mode);
- mode |= isBlock ? S_IFBLK : S_IFCHR;
- dev_t dev = makedev((unsigned int)major, (unsigned int)minor);
- setegid(0);
- rc = mknod(deviceNode, mode, dev);
+ rc = CreateDeviceNodeWithPermissions(uevent, deviceNode, isBlock);
if (rc < 0) {
- if (errno != EEXIST) {
- INIT_LOGE("Create device node[%s %d, %d] failed. %d", deviceNode, major, minor, errno);
- return rc;
- }
+ return rc;
}
- AdjustDeviceNodePermissions(deviceNode, uid, gid, mode);
if (symLinks != NULL) {
CreateSymbolLinks(deviceNode, symLinks);
}
diff --git a/ueventd/ueventd_main.c b/ueventd/ueventd_main.c
index eb7c9eec26e3119e950036103f33bc2018cbcf63..ba3f2f7e77b40b4b2bb1ed4b666c64b9b77fbc37 100644
--- a/ueventd/ueventd_main.c
+++ b/ueventd/ueventd_main.c
@@ -67,14 +67,15 @@ static void PollUeventdSocketTimeout(int ueventSockFd, bool ondemand)
return;
}
if (pfd.revents & (POLLIN | POLLERR)) {
- ProcessUevent(ueventSockFd, NULL, 0); // Not require boot devices
+ ProcessUevent(ueventSockFd, NULL, 0, NULL); // Not require boot devices
}
}
}
static int UeventdRetrigger(void)
{
- const char *ueventdConfigs[] = {"/etc/ueventd.config", "/vendor/etc/ueventd.config", NULL};
+ const char *ueventdConfigs[] = {"/etc/ueventd.config", "/vendor/etc/ueventd.config",
+ "/vendor/etc/ueventd_factory.config", NULL};
int i = 0;
while (ueventdConfigs[i] != NULL) {
ParseUeventdConfigFile(ueventdConfigs[i++]);
@@ -92,7 +93,8 @@ static int UeventdDaemon(int listen_only)
{
// start log
EnableInitLog(INIT_INFO);
- const char *ueventdConfigs[] = {"/etc/ueventd.config", "/vendor/etc/ueventd.config", NULL};
+ const char *ueventdConfigs[] = {"/etc/ueventd.config", "/vendor/etc/ueventd.config",
+ "/vendor/etc/ueventd_factory.config", NULL};
int i = 0;
while (ueventdConfigs[i] != NULL) {
ParseUeventdConfigFile(ueventdConfigs[i++]);
@@ -119,7 +121,7 @@ static int UeventdDaemon(int listen_only)
(void)close(fd);
} else {
INIT_LOGI("ueventd start to process uevent message");
- ProcessUevent(ueventSockFd, NULL, 0); // Not require boot devices
+ ProcessUevent(ueventSockFd, NULL, 0, NULL); // Not require boot devices
}
PollUeventdSocketTimeout(ueventSockFd, ondemand);
CloseUeventConfig();
diff --git a/watchdog/init_watchdog.c b/watchdog/init_watchdog.c
index 6aef64d408193a81f15ba4b38acbd53a51c66b09..5189f994a58838fc95387af10b8c6b81de5ced0d 100644
--- a/watchdog/init_watchdog.c
+++ b/watchdog/init_watchdog.c
@@ -83,7 +83,7 @@ int main(int argc, const char *argv[])
{
EnableInitLog(INIT_INFO);
WaitAtStartup("/dev/watchdog");
- int fd = open("/dev/watchdog", O_RDWR);
+ int fd = open("/dev/watchdog", O_RDWR | O_CLOEXEC);
if (fd == -1) {
INIT_LOGE("Can't open /dev/watchdog.");
return 1;