diff --git a/interfaces/innerkits/include/syspara/parameter.h b/interfaces/innerkits/include/syspara/parameter.h index bb6671dedeb5d5420b851016b99ca74a333d5a85..916776cf83b894f5989665c4bb47b9ab9fd5ba16 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 2654833e415a69d9458f3c526e6ce541ae73acb4..a5c356c66eaa59dc1afabd0168d23d31ae91e836 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 6d0940407f69e6711471a2a0d209f82b028363e1..ec6e0d8a5dd46456ce546350179192866b485de8 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 bc917fd62f2aa5a21e60ea90d5a6b89903c604f3..6e97462e438df1b74f9c502d9e90f856d47ea755 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 4315fe600877fd8ced910ab94a42dcd38aa886b6..df8e87eecf09d75f54d60e78dec18a87ddb8312d 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 b4a75a590dd4d690118aa7c23e1a9009a696110b..16bb09cbf74c7484f1f04cd4d2dfb69eebf4f475 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 74e9c562e4c1674f6d558cca78d43e55ab77f9fa..0717f14975841cd9c344bc8d8a9bc000515d2dec 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 89b4e230cbf5e736b3793e4767c3ed71b2c60351..c896169baacc9e56433fc02c46ffcd9c6b9cf70c 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 9bce4b7d783015292b869561c3f267cb120fbaad..a427d735a1f3b0d9c612c407caa741644519c659 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 ef75bf6bcee31aa2ad538b194688c98ef564df31..dc5da1145fbe63af485cc20ffadae0e803c6e714 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 fbd7aae0817c4bb5f70c21e85b9c5a392dfbd1c2..51c8ab359f729b67363283eec568b7f4ca979f5a 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 9cc6b76dd2999a39ee7ce267fe6c2fc91b443db9..48e013a6ebfca2137375d7bfd0dae72812230bae 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)