diff --git a/interfaces/innerkits/include/param/init_param.h b/interfaces/innerkits/include/param/init_param.h index 65a1a2756e90d9679683d5da43d817ce63eca4df..60797fe78a078d9881c9350ddf3b3d15ddb5dfba 100644 --- a/interfaces/innerkits/include/param/init_param.h +++ b/interfaces/innerkits/include/param/init_param.h @@ -126,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 /** * 对外接口 @@ -173,15 +182,6 @@ void SystemDumpTriggers(int verbose, int (*dump)(const char *fmt, ...)); */ int SystemSetParameter(const char *name, const char *value); -#ifndef OHOS_LITE -/** - * 对外接口 - * 更新只读参数,主要用于其他进程使用,通过管道更新只读参数。 - * - */ -int SystemUpdateConstParameter(const char *name, const char *value); -#endif - /** * 对外接口 * 保存共享内存中的所有持久化参数 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 3b24f5814a13941392e46e1264acc52ca40905c0..2654833e415a69d9458f3c526e6ce541ae73acb4 100644 --- a/interfaces/innerkits/libbegetutil.versionscript +++ b/interfaces/innerkits/libbegetutil.versionscript @@ -132,7 +132,6 @@ *GetIntParameter*; *GetDeviceType*; *GetParameter*; - *UpdateConstParameter*; *GetUintParameter*; *SetParameter*; *GetBoolParameter*; diff --git a/services/param/linux/param_message.h b/services/param/linux/param_message.h index 0da672f98da298b5296064c7f57b0e5d70186bd4..706129bb2c2ee30b4290dd6265d07770ab7ef4d8 100755 --- a/services/param/linux/param_message.h +++ b/services/param/linux/param_message.h @@ -36,7 +36,6 @@ typedef enum { MSG_ADD_WATCHER, MSG_DEL_WATCHER, MSG_NOTIFY_PARAM, - MSG_UPDATE_CONST_PARAM, MSG_SAVE_PARAM } ParamMsgType; diff --git a/services/param/linux/param_request.c b/services/param/linux/param_request.c index a95267f974e14214118ea21b6b73c6b051f6746f..97f834a89bf50bd35b5cb15a1526a903317e55b3 100644 --- a/services/param/linux/param_request.c +++ b/services/param/linux/param_request.c @@ -75,7 +75,6 @@ static int ProcessRecvMsg(const ParamMessage *recvMsg) int result = PARAM_CODE_INVALID_PARAM; switch (recvMsg->type) { case MSG_SET_PARAM: - case MSG_UPDATE_CONST_PARAM: case MSG_SAVE_PARAM: result = ((ParamResponseMessage *)recvMsg)->result; break; @@ -219,62 +218,6 @@ int SystemSetParameter(const char *name, const char *value) return ret; } -static int SystemUpdateConstParameter_(const char *name, const char *value, int timeout) -{ - PARAM_LOGV("SystemUpdateConstParameter_ start"); - PARAM_CHECK(name != NULL && value != NULL, return -1, "Invalid name or value"); - int ret = CheckParamName(name, 0); - PARAM_CHECK(ret == 0, return ret, "Illegal param name %s", name); - PARAM_CHECK(IS_READY_ONLY(name), return PARAM_CODE_INVALID_NAME, "only update read only param: %s", name); - ret = CheckParamValue(NULL, name, value, GetParamValueType(name)); - PARAM_CHECK(ret == 0, return ret, "Illegal param value %s", value); - - size_t msgSize = sizeof(ParamMsgContent); - msgSize = (msgSize < RECV_BUFFER_MAX) ? RECV_BUFFER_MAX : msgSize; - - ParamMessage *request = (ParamMessage *)CreateParamMessage(MSG_UPDATE_CONST_PARAM, name, msgSize); - PARAM_CHECK(request != NULL, return PARAM_CODE_ERROR, "Failed to create Param Message"); - uint32_t offset = 0; - ret = FillParamMsgContent(request, &offset, PARAM_VALUE, value, strlen(value)); - PARAM_CHECK(ret == 0, free(request); - return PARAM_CODE_ERROR, "Failed to fill value"); - request->msgSize = offset + sizeof(ParamMessage); - request->id.msgId = ATOMIC_SYNC_ADD_AND_FETCH(&g_requestId, 1, MEMORY_ORDER_RELAXED); - - pthread_mutex_lock(&g_clientMutex); - int retryCount = 0; - while (retryCount < 2) { // max retry 2 - if (g_clientFd == INVALID_SOCKET) { - g_clientFd = GetClientSocket(DEFAULT_PARAM_SET_TIMEOUT); - } - - if (g_clientFd < 0) { - ret = PARAM_CODE_FAIL_CONNECT; - PARAM_LOGE("connect param server failed!"); - break; - } - ret = StartRequest(g_clientFd, request, timeout); - if (ret == PARAM_CODE_IPC_ERROR) { - close(g_clientFd); - g_clientFd = INVALID_SOCKET; - retryCount++; - } else { - break; - } - } - PARAM_LOGI("SystemUpdateConstParameter name %s id:%u ret:%d ", name, request->id.msgId, ret); - pthread_mutex_unlock(&g_clientMutex); - free(request); - return ret; -} - -int SystemUpdateConstParameter(const char *name, const char *value) -{ - int ret = SystemUpdateConstParameter_(name, value, DEFAULT_PARAM_SET_TIMEOUT); - BEGET_CHECK_ONLY_ELOG(ret == 0, "SystemUpdateConstParameter failed! name is :%s, the errNum is:%d", name, ret); - return ret; -} - int SystemSetParameterNoWait(const char *name, const char *value) { int ret = SystemSetParameter_(name, value, 0); diff --git a/services/param/linux/param_service.c b/services/param/linux/param_service.c index 9c62ff6d031c3a1d412bd1bc7e48295855353150..3591e73b853bcd3a6f8cf7f4f8dfdf3aadc889b7 100755 --- a/services/param/linux/param_service.c +++ b/services/param/linux/param_service.c @@ -158,7 +158,7 @@ static int SystemSetParam(const char *name, const char *value, const ParamSecuri return ret; } -static int SystemUpdateConstParam(const char *name, const char *value, const ParamSecurityLabel *srcLabel) +static int SystemUpdateConstParamter(const char *name, const char *value, const ParamSecurityLabel *srcLabel) { PARAM_LOGV("SystemUpdateConstParam name %s value: %s", name, value); int ctrlService = 0; @@ -168,37 +168,12 @@ static int SystemUpdateConstParam(const char *name, const char *value, const Par 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 set param %d name %s %s", ret, name, value); + 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 HandleConstParamUpdate(const ParamTaskPtr worker, const ParamMessage *msg) -{ - PARAM_LOGV("HandleConstParamUpdate start"); - uint32_t offset = 0; - ParamMsgContent *valueContent = GetNextContent(msg, &offset); - PARAM_CHECK(valueContent != NULL, return -1, "Invalid msg for %s", msg->key); - ParamSecurityLabel srcLabel = {0}; - struct ucred cr = {-1, -1, -1}; - socklen_t crSize = sizeof(cr); - if (getsockopt(LE_GetSocketFd(worker), SOL_SOCKET, SO_PEERCRED, &cr, &crSize) < 0) { - PARAM_LOGE("Failed to get opt %d", errno); -#ifndef STARTUP_INIT_TEST - return SendResponseMsg(worker, msg, -1); -#endif - } - srcLabel.sockFd = LE_GetSocketFd(worker); - srcLabel.cred.uid = cr.uid; - srcLabel.cred.pid = cr.pid; - srcLabel.cred.gid = cr.gid; - PARAM_LOGI("Handle update const param msgId %u pid %d key: %s", msg->id.msgId, cr.pid, msg->key); - int ret = SystemUpdateConstParam(msg->key, valueContent->content, &srcLabel); - return SendResponseMsg(worker, msg, ret); -} - - static int HandleParamSet(const ParamTaskPtr worker, const ParamMessage *msg) { uint32_t offset = 0; @@ -392,9 +367,6 @@ PARAM_STATIC int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *m case MSG_SAVE_PARAM: ret = HandleParamSave(worker, msg); break; - case MSG_UPDATE_CONST_PARAM: - ret = HandleConstParamUpdate(worker, msg); - break; default: break; } @@ -521,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/manager/param_manager.c b/services/param/manager/param_manager.c index a979c3b6bf8b078ae1bef051e793868aed37b36b..77ac8f2d78f77c161b47786f7e355a1924b3b1f8 100644 --- a/services/param/manager/param_manager.c +++ b/services/param/manager/param_manager.c @@ -456,8 +456,8 @@ 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 ((((mode & LOAD_PARAM_UPDATE_CONST) == LOAD_PARAM_UPDATE_CONST) && - (entry->valueLength < PARAM_CONST_VALUE_LEN_MAX && valueLen < PARAM_CONST_VALUE_LEN_MAX))) { + if (((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; diff --git a/test/unittest/param/client_unittest.cpp b/test/unittest/param/client_unittest.cpp index 26283fd1c7ccfae6e58b0344078796f1ebf7c771..2b9959d46d156e85aef69e91cfcbe67bf633f5a9 100644 --- a/test/unittest/param/client_unittest.cpp +++ b/test/unittest/param/client_unittest.cpp @@ -274,13 +274,18 @@ HWTEST_F(ClientUnitTest, Init_TestClient_006, TestSize.Level0) #ifndef OHOS_LITE HWTEST_F(ClientUnitTest, Init_TestClient_007, TestSize.Level0) { - int ret = SystemUpdateConstParameter("const.test.for_update_test1", "initUpdate"); + 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 = SystemUpdateConstParameter("const.global.region", "US"); + ret = SystemWriteParam(key1, value1); EXPECT_EQ(ret, 0); - ret = SystemUpdateConstParameter("const.global.region", "CN"); + ret = SystemUpdateConstParam(key1, value2); EXPECT_EQ(ret, 0); - ret = SystemUpdateConstParameter("persist.cota.update.opkey.version.enable", "initUpdate"); + ret = SystemUpdateConstParam(key2, value2); EXPECT_EQ(ret, PARAM_CODE_INVALID_NAME); } #endif diff --git a/test/unittest/param/paramservice_unittest.cpp b/test/unittest/param/paramservice_unittest.cpp index 398097cb2e12fecf2774db88033e881ade54f06e..78441d112812299015b9ae9bafb40f5db3e2a718 100644 --- a/test/unittest/param/paramservice_unittest.cpp +++ b/test/unittest/param/paramservice_unittest.cpp @@ -333,30 +333,6 @@ public: return 0; } -#ifndef OHOS_LITE - int TestServiceUpdateProcessMessage(const char *name, const char *value) - { - if (g_worker == nullptr) { - g_worker = CreateAndGetStreamTask(); - } - if (g_worker == nullptr) { - return 0; - } - uint32_t msgSize = sizeof(ParamMessage) + sizeof(ParamMsgContent) + PARAM_ALIGN(strlen(value) + 1); - ParamMessage *request = (ParamMessage *)CreateParamMessage(MSG_UPDATE_CONST_PARAM, name, msgSize); - PARAM_CHECK(request != nullptr, return -1, "Failed to malloc for connect"); - do { - request->type = MSG_UPDATE_CONST_PARAM; - uint32_t offset = 0; - int ret = FillParamMsgContent(request, &offset, PARAM_VALUE, value, strlen(value)); - PARAM_CHECK(ret == 0, break, "Failed to fill value"); - ProcessMessage((const ParamTaskPtr)g_worker, (const ParamMessage *)request); - } while (0); - free(request); - return 0; - } -#endif - int AddWatch(int type, const char *name, const char *value) { if (g_worker == nullptr) { @@ -527,23 +503,6 @@ HWTEST_F(ParamServiceUnitTest, Init_TestServiceProcessMessage_001, TestSize.Leve EXPECT_EQ(ret, 0); } -#ifndef OHOS_LITE -HWTEST_F(ParamServiceUnitTest, Init_TestServiceUpdateProcessMessage_001, TestSize.Level0) -{ - ParamServiceUnitTest test; - int ret = test.TestServiceUpdateProcessMessage("wertt.qqqq.wwww.rrrr", "wwww.eeeee"); - EXPECT_EQ(ret, 0); - ret = test.TestServiceUpdateProcessMessage("const.test.for_update_test", "test"); - EXPECT_EQ(ret, 0); - ret = test.TestServiceUpdateProcessMessage("const.test.for_update_test", "testUpdate"); - EXPECT_EQ(ret, 0); - ret = test.TestServiceUpdateProcessMessage("const.global.region", "US"); - EXPECT_EQ(ret, 0); - ret = test.TestServiceUpdateProcessMessage("const.global.region", "CN"); - EXPECT_EQ(ret, 0); -} -#endif - HWTEST_F(ParamServiceUnitTest, Init_TestAddParamWait_001, TestSize.Level0) { ParamServiceUnitTest test; diff --git a/test/unittest/syspara/syspara_unittest.cpp b/test/unittest/syspara/syspara_unittest.cpp index 05fe8b62e06068b119be5e20801b43dad600a36f..a7735c558ec1a8ed846f6478811a2bb5474d492a 100644 --- a/test/unittest/syspara/syspara_unittest.cpp +++ b/test/unittest/syspara/syspara_unittest.cpp @@ -472,13 +472,18 @@ HWTEST_F(SysparaUnitTest, parameterTest0018, TestSize.Level0) #ifndef OHOS_LITE HWTEST_F(SysparaUnitTest, parameterTest0019, TestSize.Level0) { - int ret = SystemUpdateConstParameter("const.test.for_update_test1", "initUpdate"); + 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 = SystemUpdateConstParameter("const.global.region", "US"); + ret = SystemWriteParam(key1, value1); EXPECT_EQ(ret, 0); - ret = SystemUpdateConstParameter("const.global.region", "CN"); + ret = SystemUpdateConstParam(key1, value2); EXPECT_EQ(ret, 0); - ret = SystemUpdateConstParameter("persist.cota.update.opkey.version.enable", "initUpdate"); + ret = SystemUpdateConstParam(key2, value2); EXPECT_EQ(ret, PARAM_CODE_INVALID_NAME); } #endif