From 1e19de96c6526935d96ec6fdc20a727263a6cfba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B9=BE=E9=98=B3=E7=86=A0?= Date: Thu, 28 Aug 2025 14:53:11 +0800 Subject: [PATCH] Signed-off-by: qianyangyi update --- .../innerkits/include/syspara/parameter.h | 2 ++ .../innerkits/libbegetutil.versionscript | 2 ++ interfaces/innerkits/syspara/parameter.c | 11 ++++++++++ .../kits/jskits/src/native_deviceinfo_js.cpp | 22 +++++++++++++++++++ .../deviceInfo/idl/ohos.deviceInfo.taihe | 6 ++++- .../deviceInfo/src/ohos.deviceInfo.impl.cpp | 17 ++++++++++++++ services/etc/param/ohos.para | 1 + services/modules/bootevent/bootevent.c | 20 +++++++++++++++++ services/modules/bootevent/bootevent.h | 1 + services/param/adapter/param_persistadp.c | 2 +- test/unittest/modules/sysevent_unittest.cpp | 16 ++++++++++++++ test/unittest/syspara/syspara_unittest.cpp | 2 ++ 12 files changed, 100 insertions(+), 2 deletions(-) diff --git a/interfaces/innerkits/include/syspara/parameter.h b/interfaces/innerkits/include/syspara/parameter.h index bb6671ded..916776cf8 100644 --- a/interfaces/innerkits/include/syspara/parameter.h +++ b/interfaces/innerkits/include/syspara/parameter.h @@ -192,6 +192,8 @@ long long GetSystemCommitId(void); int32_t GetIntParameter(const char *key, int32_t def); uint32_t GetUintParameter(const char *key, uint32_t def); +const char *GetChipType(void); +int GetBootCount(void); const char *GetDistributionOSName(void); const char *GetDistributionOSVersion(void); int GetDistributionOSApiVersion(void); diff --git a/interfaces/innerkits/libbegetutil.versionscript b/interfaces/innerkits/libbegetutil.versionscript index 2654833e4..a5c356c66 100644 --- a/interfaces/innerkits/libbegetutil.versionscript +++ b/interfaces/innerkits/libbegetutil.versionscript @@ -98,6 +98,7 @@ *GetStringParameter*; FindParameter; GetAbiList; + GetBootCount; GetBootloaderVersion; GetBrand; GetBuildHost; @@ -105,6 +106,7 @@ GetBuildTime; GetBuildType; GetBuildUser; + GetChipType; GetDevUdid; GetDisplayVersion; GetFirstApiVersion; diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c index 6d0940407..ec6e0d8a5 100644 --- a/interfaces/innerkits/syspara/parameter.c +++ b/interfaces/innerkits/syspara/parameter.c @@ -463,3 +463,14 @@ int GetPerformanceClass(void) } return performanceClassValue; } + +const char *GetChipType(void) +{ + static const char *chiptype = NULL; + return GetProperty("ohos.boot.hardware", &chiptype); +} + +int GetBootCount(void) +{ + return GetIntParameter("persist.startup.bootcount", -1); +} \ No newline at end of file diff --git a/interfaces/kits/jskits/src/native_deviceinfo_js.cpp b/interfaces/kits/jskits/src/native_deviceinfo_js.cpp index bc917fd62..6e97462e4 100644 --- a/interfaces/kits/jskits/src/native_deviceinfo_js.cpp +++ b/interfaces/kits/jskits/src/native_deviceinfo_js.cpp @@ -419,6 +419,26 @@ static napi_value GetBuildRootHash(napi_env env, napi_callback_info info) return napiValue; } +static napi_value GetBootCount(napi_env env, napi_callback_info info) +{ + napi_value napiValue = nullptr; + int bootCount = GetBootCount(); + NAPI_CALL(env, napi_create_int32(env, bootCount, &napiValue)); + return napiValue; +} + +static napi_value GetChipType(napi_env env, napi_callback_info info) +{ + napi_value napiValue = nullptr; + const char *chipType = GetChipType(); + if (chipType == nullptr) { + chipType = ""; + } + + NAPI_CALL(env, napi_create_string_utf8(env, chipType, strlen(chipType), &napiValue)); + return napiValue; +} + static napi_value GetDevUdid(napi_env env, napi_callback_info info) { napi_value napiValue = nullptr; @@ -671,6 +691,8 @@ static napi_value Init(napi_env env, napi_value exports) {"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}, + {"chipType", nullptr, nullptr, GetChipType, nullptr, nullptr, napi_default, nullptr}, + {"bootCount", nullptr, nullptr, GetBootCount, nullptr, nullptr, napi_default, nullptr}, }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc)); diff --git a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe index 4315fe600..df8e87eec 100644 --- a/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe +++ b/interfaces/taihe/deviceInfo/idl/ohos.deviceInfo.taihe @@ -81,6 +81,8 @@ function getdistributionOSApiName(): String; function getdistributionOSReleaseType(): String; @static("deviceInfo") @get function getdiskSN(): String; +@static("deviceInfo") @get +function getchipType(): String; @static("deviceInfo") @get function getsdkApiVersion(): i32; @@ -95,4 +97,6 @@ function getbuildVersion(): i32; @static("deviceInfo") @get function getfirstApiVersion(): i32; @static("deviceInfo") @get -function getdistributionOSApiVersion(): i32; \ No newline at end of file +function getdistributionOSApiVersion(): i32; +@static("deviceInfo") @get +function getbootCount(): i32; \ No newline at end of file diff --git a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp index b4a75a590..16bb09cbf 100644 --- a/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp +++ b/interfaces/taihe/deviceInfo/src/ohos.deviceInfo.impl.cpp @@ -369,6 +369,15 @@ string getdiskSN() return value; } +string getchipType() +{ + const char *value = GetChipType(); + if (value == nullptr) { + value = ""; + } + return value; +} + int32_t getsdkApiVersion() { int value = GetSdkApiVersion(); @@ -410,6 +419,12 @@ int32_t getdistributionOSApiVersion() int value = GetDistributionOSApiVersion(); return value; } + +int32_t getbootCount() +{ + int value = GetBootCount(); + return value; +} } // namespace TH_EXPORT_CPP_API_getbrand(getbrand); @@ -449,3 +464,5 @@ TH_EXPORT_CPP_API_getfeatureVersion(getfeatureVersion); TH_EXPORT_CPP_API_getbuildVersion(getbuildVersion); TH_EXPORT_CPP_API_getfirstApiVersion(getfirstApiVersion); TH_EXPORT_CPP_API_getdistributionOSApiVersion(getdistributionOSApiVersion); +TH_EXPORT_CPP_API_getbootCount(getbootCount); +TH_EXPORT_CPP_API_getchipType(getchipType); \ No newline at end of file diff --git a/services/etc/param/ohos.para b/services/etc/param/ohos.para index 74e9c562e..0717f1497 100755 --- a/services/etc/param/ohos.para +++ b/services/etc/param/ohos.para @@ -38,3 +38,4 @@ const.product.build.host=default const.product.build.date=default const.product.hardwareprofile=default const.ohos.buildroothash=default +persist.startup.bootcount=0 diff --git a/services/modules/bootevent/bootevent.c b/services/modules/bootevent/bootevent.c index 89b4e230c..c896169ba 100755 --- a/services/modules/bootevent/bootevent.c +++ b/services/modules/bootevent/bootevent.c @@ -346,6 +346,25 @@ static int ScheduleDelayedHookMgrExecute(void) } #endif +void UpdateBootCount() +{ + char timevalue[MAX_BUFFER_LEN] = {0}; + uint32_t size = sizeof(timevalue); + int ret = SystemReadParam("ohos.boot.time.boot.completed", timevalue, &size); + INIT_INFO_CHECK (ret != 0, return, "already boot, not add count"); + char value[MAX_INT_LEN] = {0}; + size = sizeof(value); + ret = SystemReadParam("persist.startup.bootcount", value, &size); + INIT_ERROR_CHECK (ret == 0, return, "Failed to read bootcount"); + int bootCount = StringToInt(value, -1); + INIT_ERROR_CHECK (bootCount != -1, return, "StringToInt failed"); + bootCount++; + char buffer[32] = { 0 }; + ret = sprintf_s(buffer, sizeof(buffer), "%d", bootCount); + INIT_ERROR_CHECK (ret > 0, return, "Failed copy bootcount"); + ret = SystemWriteParam("persist.startup.bootcount", buffer); + INIT_CHECK_ONLY_ELOG(ret == 0, "Failed to update bootcount"); +} static int BootEventParaFireByName(const char *paramName) { @@ -377,6 +396,7 @@ static int BootEventParaFireByName(const char *paramName) } // All parameters are fired, set boot completed now ... INIT_LOGI("All boot events are fired, boot complete now ..."); + UpdateBootCount(); SystemWriteParam(BOOT_EVENT_BOOT_COMPLETED, "true"); SetBootCompleted(true); SaveServiceBootEvent(); diff --git a/services/modules/bootevent/bootevent.h b/services/modules/bootevent/bootevent.h index 9bce4b7d7..a427d735a 100755 --- a/services/modules/bootevent/bootevent.h +++ b/services/modules/bootevent/bootevent.h @@ -54,6 +54,7 @@ typedef struct tagBOOT_EVENT_PARAM_ITEM { } BOOT_EVENT_PARAM_ITEM; ListNode *GetBootEventList(void); +void UpdateBootCount(void); #ifdef __cplusplus #if __cplusplus diff --git a/services/param/adapter/param_persistadp.c b/services/param/adapter/param_persistadp.c index ef75bf6bc..dc5da1145 100644 --- a/services/param/adapter/param_persistadp.c +++ b/services/param/adapter/param_persistadp.c @@ -95,7 +95,7 @@ static bool IsPublicParam(const char *param) "persist.sys.usb.config", "persist.sys.xlog.debug", "persist.telephony", "persist.time", "persist.uiAppearance.first_initialization", "persist.update", - "persist.wifi", "persist.init.trace.enabled", + "persist.wifi", "persist.init.trace.enabled", "persist.startup.bootcount", }; int size = sizeof(publicPersistParams) / sizeof(char*); for (int i = 0; i < size; i++) { diff --git a/test/unittest/modules/sysevent_unittest.cpp b/test/unittest/modules/sysevent_unittest.cpp index fbd7aae08..51c8ab359 100644 --- a/test/unittest/modules/sysevent_unittest.cpp +++ b/test/unittest/modules/sysevent_unittest.cpp @@ -17,6 +17,7 @@ #include #include "bootevent.h" +#include "parameter.h" #include "init_param.h" #include "init_utils.h" #include "list.h" @@ -153,4 +154,19 @@ HWTEST_F(SysEventUnitTest, SysEventTest_007, TestSize.Level1) EXPECT_EQ(ret, 0); printf("SysEventTest_007:%d\n", ret); } + +HWTEST_F(SysEventUnitTest, SysEventTest_008, TestSize.Level1) +{ + char key1[] = "persist.startup.bootcount"; + char value1[32] = {0}; + char value2[32] = {0}; + char defValue1[] = "value of key not exist..."; + int ret = GetParameter(key1, defValue1, value1, 32); + EXPECT_NE(ret, static_cast(strlen(defValue1))); + UpdateBootCount(); + ret = GetParameter(key1, defValue1, value2, 32); + printf("value1: '%s'\n", value1); + printf("value2: '%s'\n", value2); + EXPECT_NE(0, strcmp(value1, value2)); +} } // namespace init_ut diff --git a/test/unittest/syspara/syspara_unittest.cpp b/test/unittest/syspara/syspara_unittest.cpp index 9cc6b76dd..48e013a6e 100644 --- a/test/unittest/syspara/syspara_unittest.cpp +++ b/test/unittest/syspara/syspara_unittest.cpp @@ -169,6 +169,8 @@ HWTEST_F(SysparaUnitTest, parameterTest001_3, TestSize.Level0) EXPECT_STRNE(GetBuildHost(), nullptr); EXPECT_STRNE(GetBuildTime(), nullptr); EXPECT_STRNE(GetBuildRootHash(), nullptr); + EXPECT_STRNE(GetChipType(), nullptr); + EXPECT_GT(GetBootCount(), -1); } HWTEST_F(SysparaUnitTest, parameterTest002, TestSize.Level0) -- Gitee