diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp index 9ae99e19ad64562299b40306c2629e6927d14cdd..c24231546ac2c9e70a85d6dead2751dcdec04a64 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_client_stub.cpp @@ -36,8 +36,12 @@ static int32_t ClientIpcInterfaceMsgHandle(const IpcContext *ctx, void *ipcMsg, uint32_t code = 0; GetCode(ipcMsg, &code); - DMLOG(DM_LOG_INFO, "receive ipc transact code(%u)", code); - return IpcCmdRegister::GetInstance().OnIpcCmd(code, *io, *ctx, ipcMsg); + int32_t errCode = DEVICEMANAGER_OK; + + errCode = IpcCmdRegister::GetInstance().OnIpcCmd(code, *io, *ctx, ipcMsg); + DMLOG(DM_LOG_INFO, "receive ipc transact code:%u, retCode=%d", code, errCode); + FreeBuffer(ctx, ipcMsg); + return errCode; } int32_t IpcClientStub::Init() diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index 2178b0644304a7eeffd87b97f785f35919d1b11e..1ae50f777fa1dc15205c1fdb49d1ee5821b4bf30 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -195,7 +195,6 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size); if (pkgName == "" || len == 0 || deviceInfo == NULL) { DMLOG(DM_LOG_ERROR, "OnDeviceOnline, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } switch (deviceState) { @@ -212,7 +211,6 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void DMLOG(DM_LOG_ERROR, "unknown device state:%d", deviceState); break; } - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -224,11 +222,9 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply, const IpcContext &ctx, void *ipcMs const DmDeviceInfo *deviceInfo = (const DmDeviceInfo*)IpcIoPopFlatObj(&reply, &size); if (pkgName == "" || len == 0 || deviceInfo == NULL) { DMLOG(DM_LOG_ERROR, "OnDeviceChanged, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, *deviceInfo); - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -240,7 +236,6 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ip if (pkgName == "" || len == 0) { DMLOG(DM_LOG_ERROR, "OnDiscoverySuccess, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } if (failedReason == DEVICEMANAGER_OK) { @@ -248,7 +243,6 @@ ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply, const IpcContext &ctx, void *ip } else { DeviceManagerNotify::GetInstance().OnDiscoverFailed(pkgName, subscribeId, failedReason); } - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -263,11 +257,9 @@ ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) { DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, pinToken, status, reason); - FreeBuffer(&ctx, ipcMsg); } ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) @@ -281,11 +273,9 @@ ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply, const IpcContext &ctx, void * if (pkgName == "" || len == 0 || deviceId == "" || devIdLen == 0) { DMLOG(DM_LOG_ERROR, "OnAuthResult, get para failed"); - FreeBuffer(&ctx, ipcMsg); return; } DeviceManagerNotify::GetInstance().OnCheckAuthResult(pkgName, deviceId, resultCode, flag); - FreeBuffer(&ctx, ipcMsg); } ON_IPC_SET_REQUEST(SERVER_GET_AUTHENTCATION_INFO, std::shared_ptr pBaseReq, IpcIo& request, diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp index 45dc5a86259ba02020b57379c5024278a98e4f34..b71b3edfd6f95e21d45cdc533a3ddd9024f23eff 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_cmd_parser.cpp @@ -161,12 +161,14 @@ ON_IPC_SERVER_CMD(GET_TRUST_DEVICE_LIST, IpcIo &req, IpcIo &reply) ON_IPC_SERVER_CMD(REGISTER_DEVICE_MANAGER_LISTENER, IpcIo &req, IpcIo &reply) { - RegisterDeviceManagerListener(&req, &reply); + int32_t errCode = RegisterDeviceManagerListener(&req, &reply); + IpcIoPushInt32(&reply, errCode); } ON_IPC_SERVER_CMD(UNREGISTER_DEVICE_MANAGER_LISTENER, IpcIo &req, IpcIo &reply) { - UnRegisterDeviceManagerListener(&req, &reply); + int32_t errCode = UnRegisterDeviceManagerListener(&req, &reply); + IpcIoPushInt32(&reply, errCode); } ON_IPC_SERVER_CMD(START_DEVICE_DISCOVER, IpcIo &req, IpcIo &reply) diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp index 775245f592f02b38ba945b9cae2b319024d530e3..1cb044337f0a9fd37d5e9b333e8352fb62f7ff4d 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp @@ -77,7 +77,6 @@ static int32_t DeathCb(const IpcContext *context, void *ipcMsg, IpcIo *data, voi sid.token = svcId.token; sid.cookie = svcId.cookie; UnregisterDeathCallback(sid, svcId.cbId); - return DEVICEMANAGER_OK; } @@ -85,13 +84,11 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) { DMLOG(DM_LOG_INFO, "register service listener."); size_t len = 0; - int32_t ret = DEVICEMANAGER_OK; uint8_t *name = IpcIoPopString(req, &len); SvcIdentity *svc = IpcIoPopSvc(req); if (name == NULL || svc == NULL || len == 0) { DMLOG(DM_LOG_ERROR, "get para failed"); - IpcIoPushInt32(reply, ret); - return DEVICEMANAGER_OK; + return DEVICEMANAGER_INVALID_PARAM; } CommonSvcId svcId = {0}; @@ -106,26 +103,21 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) free(svc); svc = NULL; #endif - char *pkgName = (char *)malloc(len + 1); if (pkgName == NULL) { DMLOG(DM_LOG_ERROR, "malloc failed!"); - IpcIoPushInt32(reply, DEVICEMANAGER_FAILED); - return DEVICEMANAGER_FAILED; + return DEVICEMANAGER_MALLOC_ERROR; } if (strcpy_s(pkgName, len + 1, (const char *)name) != DEVICEMANAGER_OK) { DMLOG(DM_LOG_ERROR, "strcpy_s failed!"); free(pkgName); - IpcIoPushInt32(reply, DEVICEMANAGER_FAILED); - return DEVICEMANAGER_FAILED; + return DEVICEMANAGER_COPY_FAILED; } uint32_t cbId = 0; RegisterDeathCallback(NULL, sid, DeathCb, pkgName, &cbId); svcId.cbId = cbId; std::string strPkgName = (const char *)name; - ret = IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId); - IpcIoPushInt32(reply, ret); - return DEVICEMANAGER_OK; + return IpcServerListenermgr::GetInstance().RegisterListener(strPkgName, &svcId); } int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) @@ -138,24 +130,23 @@ int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) return DEVICEMANAGER_FAILED; } - CommonSvcId svcId = {0}; - if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) { - DMLOG(DM_LOG_ERROR, "not found listener by package name."); - return DEVICEMANAGER_FAILED; - } int32_t ret = IpcServerListenermgr::GetInstance().UnregisterListener(pkgName); if (ret == DEVICEMANAGER_OK) { + CommonSvcId svcId; + if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) { + DMLOG(DM_LOG_ERROR, "not found listener by package name."); + return DEVICEMANAGER_FAILED; + } #ifdef __LINUX__ BinderRelease(svcId.ipcCtx, svcId.handle); #endif - SvcIdentity sid = {0}; + SvcIdentity sid; sid.handle = svcId.handle; sid.token = svcId.token; sid.cookie = svcId.cookie; ret = UnregisterDeathCallback(sid, svcId.cbId); } - IpcIoPushInt32(reply, ret); - return DEVICEMANAGER_OK; + return ret; } static const char *GetName(Service *service)