diff --git a/frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp index 08429a9ba9950a3ad52c2ffc451d3e652105afb6..9cebc3cd26683ce676d7a85c4e4d9adffe5707cf 100644 --- a/frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp +++ b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp @@ -166,7 +166,6 @@ void NetEapPostBackCallback::EventNotify(const std::shared_ptr & NETMANAGER_EXT_LOGE("asyncEvent is null!"); return; } - NETMANAGER_EXT_LOGI("Enter eap postback event notify, msgId: %{public}d", asyncEvent->msgId_); auto sendTask = std::bind(&NetEapPostBackCallback::SendTask, this, asyncEvent); if (napi_status::napi_ok != napi_send_event(asyncEvent->env_, sendTask, napi_eprio_immediate)) { NETMANAGER_EXT_LOGE("%{public}s, Failed to SendEvent", __func__); @@ -177,23 +176,18 @@ void NetManagerNapiAbilityStatusChange::OnAddSystemAbility(int32_t systemAbility { NETMANAGER_EXT_LOGI("NetManagerNapiAbilityStatusChange OnAddSystemAbility systemAbilityId:%{public}d", systemAbilityId); - std::vector event; switch (systemAbilityId) { case WIFI_DEVICE_SA_ID: - case COMM_ETHERNET_MANAGER_SYS_ABILITY_ID: { + case COMM_ETHERNET_MANAGER_SYS_ABILITY_ID: EapEventMgr::GetInstance().RegCustomEapHandler(NetType::WLAN0, RegTriggerMode::SA_LAUNCH); break; - } default: - NETMANAGER_EXT_LOGI("OnAddSystemAbility unhandled sysabilityId:%{public}d", systemAbilityId); return; } } void NetManagerNapiAbilityStatusChange::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { - NETMANAGER_EXT_LOGI("NetManagerNapiAbilityStatusChange OnRemoveSystemAbility systemAbilityId:%{public}d", - systemAbilityId); } EapEventMgr &EapEventMgr::GetInstance() @@ -236,8 +230,8 @@ int32_t EapEventMgr::RegCustomEapHandler(napi_env env, NetType netType, uint32_t if (netTypeMapIter == eventRegisterInfo_.end()) { NETMANAGER_EXT_LOGI("%{public}s, new netType!", __func__); TypeMapRegObj mapObj; - mapObj[composeParam] = std::vector{regObj}; - eventRegisterInfo_[netType] = mapObj; + mapObj.emplace(composeParam, std::vector{regObj}); + eventRegisterInfo_.emplace(netType, mapObj); } else { NETMANAGER_EXT_LOGI("%{public}s, exist netType!", __func__); TypeMapRegObj mapObj = netTypeMapIter->second; @@ -249,7 +243,7 @@ int32_t EapEventMgr::RegCustomEapHandler(napi_env env, NetType netType, uint32_t NETMANAGER_EXT_LOGE("%{public}s, RegisterInfo Exceeding the maximum value!", __func__); return EAP_ERRCODE_INTERNAL_ERROR; } - mapObj[composeParam] = std::vector{regObj}; + mapObj.emplace(composeParam, std::vector{regObj}); eventRegisterInfo_[netType] = mapObj; } else { auto vecIter = std::find_if(iter->second.begin(), iter->second.end(), @@ -345,7 +339,7 @@ int32_t EapEventMgr::ReplyCustomEapData(CustomResult result, const sptr eapData); } -std::map EapEventMgr::GetRegisterInfoMap() +std::map& EapEventMgr::GetRegisterInfoMap() { return eventRegisterInfo_; } diff --git a/frameworks/js/napi/ethernet/customeap/eap_event_mgr.h b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.h index 584712c8130d6075b40b0dd54f5fb738180bb22c..2874e2744fdacc12561749183127d0fd051b770f 100644 --- a/frameworks/js/napi/ethernet/customeap/eap_event_mgr.h +++ b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.h @@ -131,7 +131,7 @@ public: int32_t ReplyCustomEapData(CustomResult result, const sptr &eapData); int32_t RegCustomEapHandler(NetType netType, RegTriggerMode triggerMode); int32_t UnRegCustomEapHandler(NetType netType); - std::map GetRegisterInfoMap(); + std::map& GetRegisterInfoMap(); private: sptr eapPostBackCallback_ = nullptr; diff --git a/frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp b/frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp index fa206b87f96850924f9a7e760a67243fdd53e666..0ac3250e6820968ed577524180e35e76ac953e3f 100644 --- a/frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp +++ b/frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp @@ -18,7 +18,8 @@ namespace OHOS { namespace NetManagerStandard { - + +static std::mutex g_mutex; namespace { #ifdef NET_EXTENSIBLE_AUTHENTICATION @@ -207,11 +208,8 @@ napi_value ReplyCustomEapData(napi_env env, napi_callback_info info) return EapNapiReturn(env, false, EAP_ERRCODE_INVALID_RESULT); } CustomResult customResult = static_cast(replyResult); - sptr eapData = new (std::nothrow) EapData(); - if (eapData == nullptr) { - NETMANAGER_EXT_LOGE("%{public}s, eapData is nullptr", __func__); - return EapNapiReturn(env, false, EAP_ERRCODE_INTERNAL_ERROR); - } + std::unique_lock lock(g_mutex); + sptr eapData = sptr::MakeSptr(); eapData->msgId = NapiUtils::GetInt32Property(env, argv[ARG_INDEX_1], "msgId"); eapData->bufferLen = NapiUtils::GetInt32Property(env, argv[ARG_INDEX_1], "bufferLen"); NapiUtils::GetVectorUint8Property(env, argv[ARG_INDEX_1], "eapBuffer", eapData->eapBuffer); @@ -224,10 +222,8 @@ napi_value ReplyCustomEapData(napi_env env, napi_callback_info info) NETMANAGER_EXT_LOGE("bufferLen is mismatch buffer size."); return EapNapiReturn(env, false, EAP_ERRCODE_INVALID_SIZE_OF_EAPDATA); } - NETMANAGER_EXT_LOGI("%{public}s, result:%{public}d, msgId:%{public}d, bufferLen:%{public}d, buffsize:%{public}zu, " - "eapCode:%{public}d, eapType:%{public}d ", - __func__, static_cast(customResult), eapData->msgId, eapData->bufferLen, eapData->eapBuffer.size(), - eapData->eapCode, eapData->eapType); + NETMANAGER_EXT_LOGI("%{public}s, result:%{public}d, msgId:%{public}d, bufferLen:%{public}d, buffsize:%{public}zu", + __func__, static_cast(customResult), eapData->msgId, eapData->bufferLen, eapData->eapBuffer.size()); int32_t ret = EapEventMgr::GetInstance().ReplyCustomEapData(customResult, eapData); return EapNapiReturn(env, ret == EAP_ERRCODE_SUCCESS, ret); #endif diff --git a/frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp b/frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp index 66981c5be59ff85cd6832d3691db2b5cead5bd6d..64d84c58660b87f0460aca856f09a1effed86250 100644 --- a/frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp +++ b/frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp @@ -29,6 +29,7 @@ NetEapPostbackCallbackStub::NetEapPostbackCallbackStub() int32_t NetEapPostbackCallbackStub::OnEapSupplicantResult(MessageParcel &data, MessageParcel &reply) { + std::unique_lock lock(postbackMtx_); int32_t netType = 0; if (!data.ReadInt32(netType)) { return NETMANAGER_ERR_READ_DATA_FAIL; @@ -131,6 +132,7 @@ int32_t NetRegisterEapCallbackStub::OnRegisterCustomEapCallback(MessageParcel &d int32_t NetRegisterEapCallbackStub::OnReplyCustomEapDataEvent(MessageParcel &data, MessageParcel &reply) { + std::unique_lock lock(replyMtx_); int32_t result = -1; if (!data.ReadInt32(result)) { return NETMANAGER_ERR_READ_DATA_FAIL; @@ -142,11 +144,7 @@ int32_t NetRegisterEapCallbackStub::OnReplyCustomEapDataEvent(MessageParcel &dat return NETMANAGER_ERR_LOCAL_PTR_NULL; } - int32_t ret = OnReplyCustomEapDataEvent(result, eapData); - if (!reply.WriteInt32(ret)) { - NETMGR_EXT_LOG_E("Write parcel failed"); - return ret; - } + OnReplyCustomEapDataEvent(result, eapData); return NETMANAGER_SUCCESS; } diff --git a/interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h b/interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h index c617eb3ffadf3e2a591e6b867b22900e137afab6..0095f473a13c833c775f451a50b9dd9891ff771a 100644 --- a/interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h +++ b/interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h @@ -39,6 +39,7 @@ private: private: std::map memberFuncMap_; + std::mutex postbackMtx_; }; class NetRegisterEapCallbackStub : public IRemoteStub { @@ -59,6 +60,7 @@ private: private: std::map memberFuncMap_; + std::mutex replyMtx_; }; } // namespace NetManagerStandard diff --git a/services/ethernetmanager/include/net_eap_handler.h b/services/ethernetmanager/include/net_eap_handler.h index 9dff9c33d6709e2a85a5dd55f53b834641c226d3..366caf808b7a65ae15714ab261880c779c07695e 100644 --- a/services/ethernetmanager/include/net_eap_handler.h +++ b/services/ethernetmanager/include/net_eap_handler.h @@ -54,7 +54,7 @@ private: private: std::map nTMapMsgId_; std::map> regEapCallBack_; - sptr postbackCallback_; + sptr postbackCallback_ = nullptr; std::mutex callbackMutex_; std::mutex mutex_; #ifdef NET_EXTENSIBLE_AUTHENTICATION