diff --git a/BUILD.gn b/BUILD.gn index 8029a02d09bb9c83c5be29f81b9bf9efc6e23fc1..103ee5a70e69c1309143f9098d8f0df71bab2161 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -18,7 +18,6 @@ if (defined(ohos_lite)) { "utils:devicemanagerutils", "services/devicemanagerservice:devicemanagerservice", "interfaces/inner_kits/native_cpp:devicemanagersdk", - "interfaces/kits/js:devicemanager", ] } } diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 45ccf822ca66f0a9e066f898cd811e975b753bf5..076a2c007a8ec3456cd1d5b2f6341f0e0527477d 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -21,7 +21,7 @@ #include "dm_app_image_info.h" #define DM_MAX_DEVICE_ID_LEN (96) -#define DM_MAX_DEVICE_NAME_LEN (65) +#define DM_MAX_DEVICE_NAME_LEN (128) namespace OHOS { namespace DistributedHardware { 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..b500aebb246b669759422f50635686075bcd00ef 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); + 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..bd67cd215b5b3f1849ed7d7ff4f6c11f99a055bd 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 @@ -186,7 +186,7 @@ ON_IPC_READ_RESPONSE(CHECK_AUTHENTICATION, IpcIo &reply, std::shared_ptr return DEVICEMANAGER_OK; } -ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply) { size_t len = 0; std::string pkgName = (const char *)IpcIoPopString(&reply, &len); @@ -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,10 +211,9 @@ 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) +ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply) { size_t len = 0; std::string pkgName = (const char *)IpcIoPopString(&reply, &len); @@ -224,14 +222,12 @@ 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) +ON_IPC_CMD(SERVER_DISCOVER_FINISH, IpcIo &reply) { size_t len = 0; std::string pkgName = (const char *)IpcIoPopString(&reply, &len); @@ -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,10 +243,9 @@ 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) +ON_IPC_CMD(SERVER_AUTH_RESULT, IpcIo &reply) { size_t len = 0; std::string pkgName = (const char *)IpcIoPopString(&reply, &len); @@ -263,14 +257,12 @@ 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) +ON_IPC_CMD(SERVER_CHECK_AUTH_RESULT, IpcIo &reply) { size_t len = 0; std::string pkgName = (const char *)IpcIoPopString(&reply, &len); @@ -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, @@ -355,15 +345,13 @@ ON_IPC_READ_RESPONSE(SERVER_USER_AUTHORIZATION_OPERATION, IpcIo& reply, std::sha return DEVICEMANAGER_OK; } -ON_IPC_CMD(SERVER_DEVICEMANAGER_FA_NOTIFY, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +ON_IPC_CMD(SERVER_DEVICEMANAGER_FA_NOTIFY, IpcIo &reply) { size_t len = 0; std::string packagename = (const char *)IpcIoPopString(&reply, &len); size_t jsonLen = 0; std::string paramJson = (const char *)IpcIoPopString(&reply, &jsonLen); DeviceManagerNotify::GetInstance().OnFaCall(packagename, paramJson); - IpcIoPushInt32(&reply, DEVICEMANAGER_OK); - FreeBuffer(&ctx, ipcMsg); } } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index b82cf50ab0c1d97895fad10b1e26d8bcd3635dc4..5c67772074611715ef11ffe03784a1318d1b537c 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -11,115 +11,58 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (defined(ohos_lite)) { - import("//build/lite/config/component/lite_component.gni") -} else { - import("//build/ohos.gni") -} +import("//build/ohos.gni") import("//foundation/distributedhardware/devicemanager/devicemanager.gni") -if (defined(ohos_lite)) { - shared_library("devicemanager") { - include_dirs = [ - "//third_party/node/src", - "//third_party/json/include", - "${common_path}/include", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/interfaces/kits", - "//utils/native/base/include", - "include", - "${utils_path}/include/log", - "${common_path}/include/ipc", - "${common_path}/include/ipc/model", - "${common_path}/include/ipc/lite", - "${innerkits_path}/native_cpp/include", - ] - include_dirs += [ - "//utils/native/lite/include", - "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/hilog", - "//third_party/bounds_checking_function/include", - "//foundation/communication/ipc_lite/interfaces/kits", - "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - ] - - sources = [ - "src/dm_native_event.cpp", - "src/native_devicemanager_js.cpp", - ] - - deps = [ - "${utils_path}:devicemanagerutils", - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//foundation/communication/ipc_lite:liteipc_adapter", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//foundation/distributedschedule/samgr_lite/samgr:samgr", - "//third_party/bounds_checking_function:libsec_shared", - "//utils/native/lite:utils", - ] +ohos_shared_library("devicemanager") { + include_dirs = [ + "//third_party/node/src", + "//third_party/json/include", + "${common_path}/include", + "//foundation/ace/napi/native_engine", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "include", + "${utils_path}/include/log", + "${common_path}/include/ipc", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/standard", + ] - cflags_cc = build_flags + sources = [ + "src/dm_native_event.cpp", + "src/native_devicemanager_js.cpp", + ] - defines = [ - "LITE_DEVICE", - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerkit_js\"", - "LOG_DOMAIN=0xD004100", - ] - } - group("devicemanager_native_js") { - deps = [ ":devicemanager" ] - } -} else { - ohos_shared_library("devicemanager") { - include_dirs = [ - "//third_party/node/src", - "//third_party/json/include", - "${common_path}/include", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/interfaces/kits", - "//utils/native/base/include", - "include", - "${utils_path}/include/log", - "${common_path}/include/ipc", - "${innerkits_path}/native_cpp/include", - "${innerkits_path}/native_cpp/include/standard", - ] + deps = [ + "${utils_path}:devicemanagerutils", + "//foundation/ace/napi:ace_napi", + "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", + "//utils/native/base:utils", + ] - sources = [ - "src/dm_native_event.cpp", - "src/native_devicemanager_js.cpp", - ] + cflags_cc = build_flags - deps = [ - "${utils_path}:devicemanagerutils", - "//foundation/ace/napi:ace_napi", - "//foundation/distributedhardware/devicemanager/interfaces/inner_kits/native_cpp:devicemanagersdk", - "//utils/native/base:utils", - ] + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerkit_js\"", + "LOG_DOMAIN=0xD004100", + ] - cflags_cc = build_flags + external_deps = [ + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + ] - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"devicemanagerkit_js\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "appexecfwk_standard:appexecfwk_base", - "appexecfwk_standard:appexecfwk_core", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_L2:samgr_proxy", - ] - - subsystem_name = "distributedhardware" - relative_install_dir = "module/distributedhardware" - part_name = "device_manager_base" - } + subsystem_name = "distributedhardware" + relative_install_dir = "module/distributedhardware" + part_name = "device_manager_base" +} - group("devicemanager_native_js") { - deps = [ ":devicemanager" ] - } +group("devicemanager_native_js") { + deps = [ ":devicemanager" ] } 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..24bfb9bbaaabdacd2e1a5ffbfcbec8fc5f325178 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}; @@ -110,22 +107,18 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) 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,7 +131,7 @@ int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) return DEVICEMANAGER_FAILED; } - CommonSvcId svcId = {0}; + CommonSvcId svcId; if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DEVICEMANAGER_OK) { DMLOG(DM_LOG_ERROR, "not found listener by package name."); return DEVICEMANAGER_FAILED; @@ -148,14 +141,13 @@ int32_t UnRegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) #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) diff --git a/utils/include/ipc/lite/ipc_cmd_register.h b/utils/include/ipc/lite/ipc_cmd_register.h index 6b52515aa332d2e63c2a66fe1f071b3cfd58a902..36c20961f2fa659fdcc9c6e403d199484f853803 100644 --- a/utils/include/ipc/lite/ipc_cmd_register.h +++ b/utils/include/ipc/lite/ipc_cmd_register.h @@ -49,8 +49,8 @@ namespace DistributedHardware { IpcRegisterReadResponseFunc##cmdCode g_IpcRegisterReadResponseFunc##cmdCode; \ static int32_t IpcReadResponse##cmdCode(paraA, paraB) \ -#define ON_IPC_CMD(cmdCode, paraA, paraB, paraC) \ - static void IpcCmdProcess##cmdCode(paraA, paraB, paraC); \ +#define ON_IPC_CMD(cmdCode, paraA) \ + static void IpcCmdProcess##cmdCode(paraA); \ struct IpcRegisterCmdProcessFunc##cmdCode { \ IpcRegisterCmdProcessFunc##cmdCode() \ { \ @@ -58,7 +58,7 @@ namespace DistributedHardware { } \ }; \ IpcRegisterCmdProcessFunc##cmdCode g_IpcRegisterCmdProcessFunc##cmdCode; \ - static void IpcCmdProcess##cmdCode(paraA, paraB, paraC) \ + static void IpcCmdProcess##cmdCode(paraA) \ #define ON_IPC_SERVER_CMD(cmdCode, paraA, paraB) \ static void IpcServerCmdProcess##cmdCode(paraA, paraB); \ @@ -75,7 +75,7 @@ namespace DistributedHardware { using SetIpcRequestFunc = int32_t (*)(std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t bufferLen); using ReadResponseFunc = int32_t (*)(IpcIo &reply, std::shared_ptr pBaseRsp); -using OnIpcCmdFunc = void (*)(IpcIo &reply, const IpcContext &ctx, void *ipcMsg); +using OnIpcCmdFunc = void (*)(IpcIo &reply); using OnIpcServerCmdFunc = void (*)(IpcIo &req, IpcIo &reply); class IpcCmdRegister { @@ -100,7 +100,7 @@ public: int32_t SetRequest(int32_t cmdCode, std::shared_ptr pBaseReq, IpcIo &request, uint8_t *buffer, size_t buffLen); int32_t ReadResponse(int32_t cmdCode, IpcIo &reply, std::shared_ptr pBaseRsp); - int32_t OnIpcCmd(int32_t cmdCode, IpcIo &reply, const IpcContext &ctx, void *ipcMsg); + int32_t OnIpcCmd(int32_t cmdCode, IpcIo &reply); int32_t OnIpcServerCmd(int32_t cmdCode, IpcIo &req, IpcIo &reply); private: std::unordered_map setIpcRequestFuncMap_; diff --git a/utils/src/ipc/lite/ipc_cmd_register.cpp b/utils/src/ipc/lite/ipc_cmd_register.cpp index 8faa2a22bf2e70fcb9473c2235a9ad4ca12085a9..4fbab5a16f3cca12e26327734274f41df837f76d 100644 --- a/utils/src/ipc/lite/ipc_cmd_register.cpp +++ b/utils/src/ipc/lite/ipc_cmd_register.cpp @@ -43,14 +43,14 @@ int32_t IpcCmdRegister::ReadResponse(int32_t cmdCode, IpcIo &reply, std::shared_ return (readResponseMapIter->second)(reply, pBaseRsp); } -int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, IpcIo &reply, const IpcContext &ctx, void *ipcMsg) +int32_t IpcCmdRegister::OnIpcCmd(int32_t cmdCode, IpcIo &reply) { auto onIpcCmdMapIter = onIpcCmdFuncMap_.find(cmdCode); if (onIpcCmdMapIter == onIpcCmdFuncMap_.end()) { DMLOG(DM_LOG_ERROR, "cmdCode:%d not register OnIpcCmdFunc", cmdCode); return DEVICEMANAGER_IPC_NOT_REGISTER_FUNC; } - (onIpcCmdMapIter->second)(reply, ctx, ipcMsg); + (onIpcCmdMapIter->second)(reply); return DEVICEMANAGER_OK; }