From d6155550f44ecf9ee07d0452546068a7cc0e767c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 16:59:18 +0800 Subject: [PATCH 01/11] services/src/telephony_state_registry_service.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SigneallEx Signed-off-by: 邵夷恺 --- .../js/napi/include/event_listener_handler.h | 1 + .../js/napi/include/napi_state_registry.h | 34 +++++++++++++ .../js/napi/include/napi_telephony_observer.h | 1 + .../include/telephony_callback_event_id.h | 1 + .../include/telephony_update_event_type.h | 1 + frameworks/js/napi/include/update_contexts.h | 9 ++++ frameworks/js/napi/include/update_infos.h | 6 +++ .../js/napi/src/event_listener_handler.cpp | 49 ++++++++++++++++++- .../js/napi/src/napi_state_registry.cpp | 22 ++++++--- .../js/napi/src/napi_telephony_observer.cpp | 13 +++++ .../include/telephony_observer_proxy.h | 2 + .../observer/src/telephony_observer.cpp | 12 +++++ .../observer/src/telephony_observer_proxy.cpp | 24 +++++++++ .../innerkits/observer/telephony_observer.h | 10 ++++ .../telephony_state_registry_dump_helper.cpp | 2 + .../src/telephony_state_registry_service.cpp | 16 +++++- 16 files changed, 194 insertions(+), 9 deletions(-) diff --git a/frameworks/js/napi/include/event_listener_handler.h b/frameworks/js/napi/include/event_listener_handler.h index 0992768..b38466b 100644 --- a/frameworks/js/napi/include/event_listener_handler.h +++ b/frameworks/js/napi/include/event_listener_handler.h @@ -77,6 +77,7 @@ private: TelephonyUpdateEventType curEventType, int32_t eventSlotId, int32_t curSlotId); static void WorkCallStateUpdated(uv_work_t *work, std::unique_lock &lock); + static void WorkCallStateExUpdated(uv_work_t *work, std::unique_lock &lock); static void WorkSignalUpdated(uv_work_t *work, std::unique_lock &lock); static void WorkNetworkStateUpdated(uv_work_t *work, std::unique_lock &lock); static void WorkSimStateUpdated(uv_work_t *work, std::unique_lock &lock); diff --git a/frameworks/js/napi/include/napi_state_registry.h b/frameworks/js/napi/include/napi_state_registry.h index 8fc2427..e8f6159 100644 --- a/frameworks/js/napi/include/napi_state_registry.h +++ b/frameworks/js/napi/include/napi_state_registry.h @@ -68,6 +68,40 @@ enum class CallState : int32_t { CALL_STATE_ANSWERED = 3 }; +enum class TelCallState : int32_t { + /** + * Indicates an invalid state, which is used when the call state fails to be + * obtained. + */ + TEL_CALL_STATE_UNKNOWN = -1, + + /** + * Indicates that there is no ongoing call. + */ + TEL_CALL_STATE_IDLE = 0, + + /** + * Indicates that an incoming call is ringing or waiting. + */ + TEL_CALL_STATE_RINGING = 1, + + /** + * Indicates that a least one call is in the dialing,and there is no new + * incoming call ringing or waiting. + */ + TEL_CALL_STATE_OFFHOOK = 2, + + /** + * Indicates that an incoming call is answered. + */ + TEL_CALL_STATE_ANSWERED = 3, + + /** + * Indicates that an outgoing call is active, or hold state. + */ + TEL_CALL_STATE_CONNECTED = 4 +}; + struct ObserverContext : BaseContext { int32_t slotId = DEFAULT_SIM_SLOT_ID; TelephonyUpdateEventType eventType = TelephonyUpdateEventType::NONE_EVENT_TYPE; diff --git a/frameworks/js/napi/include/napi_telephony_observer.h b/frameworks/js/napi/include/napi_telephony_observer.h index e69a15a..cb80722 100644 --- a/frameworks/js/napi/include/napi_telephony_observer.h +++ b/frameworks/js/napi/include/napi_telephony_observer.h @@ -28,6 +28,7 @@ namespace Telephony { class NapiTelephonyObserver : public TelephonyObserver { public: void OnCallStateUpdated(int32_t slotId, int32_t callState, const std::u16string &phoneNumber) override; + void OnCallStateUpdatedEx(int32_t slotId, int32_t callState) override; void OnSignalInfoUpdated(int32_t slotId, const std::vector> &vec) override; void OnNetworkStateUpdated(int32_t slotId, const sptr &networkState) override; void OnSimStateUpdated(int32_t slotId, CardType type, SimState state, LockReason reason) override; diff --git a/frameworks/js/napi/include/telephony_callback_event_id.h b/frameworks/js/napi/include/telephony_callback_event_id.h index 74eaf1e..4c4e71f 100644 --- a/frameworks/js/napi/include/telephony_callback_event_id.h +++ b/frameworks/js/napi/include/telephony_callback_event_id.h @@ -30,6 +30,7 @@ enum class TelephonyCallbackEventId : uint32_t { EVENT_ON_CFU_INDICATOR_UPDATE = 8, EVENT_ON_VOICE_MAIL_MSG_INDICATOR_UPDATE = 9, EVENT_ON_ICC_ACCOUNT_UPDATE = 10, + EVENT_ON_CALL_STATE_EX_UPDATE = 11, }; template diff --git a/frameworks/js/napi/include/telephony_update_event_type.h b/frameworks/js/napi/include/telephony_update_event_type.h index 10c4c2b..86a39a1 100644 --- a/frameworks/js/napi/include/telephony_update_event_type.h +++ b/frameworks/js/napi/include/telephony_update_event_type.h @@ -33,6 +33,7 @@ enum class TelephonyUpdateEventType { EVENT_CFU_INDICATOR_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_CFU_INDICATOR, EVENT_VOICE_MAIL_MSG_INDICATOR_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_VOICE_MAIL_MSG_INDICATOR, EVENT_ICC_ACCOUNT_CHANGE = TelephonyObserverBroker::OBSERVER_MASK_ICC_ACCOUNT, + EVENT_CALL_STATE_EX_UPDATE = TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE_EX, }; const std::set ENABLE_ON_DEFAULT_DATA_EVENT_SET { diff --git a/frameworks/js/napi/include/update_contexts.h b/frameworks/js/napi/include/update_contexts.h index dd20ddf..9f8a213 100644 --- a/frameworks/js/napi/include/update_contexts.h +++ b/frameworks/js/napi/include/update_contexts.h @@ -38,6 +38,15 @@ struct CallStateContext : EventListener { } }; +struct CallStateExContext : EventListener { + int32_t callStateEx; + CallStateExContext &operator=(const CallStateExUpdateInfo &info) + { + callStateEx = info.callStateEx_; + return *this; + } +}; + struct SignalListContext : EventListener { std::vector> signalInfoList; SignalListContext &operator=(SignalUpdateInfo &info) diff --git a/frameworks/js/napi/include/update_infos.h b/frameworks/js/napi/include/update_infos.h index e9982df..4101df4 100644 --- a/frameworks/js/napi/include/update_infos.h +++ b/frameworks/js/napi/include/update_infos.h @@ -40,6 +40,12 @@ struct CallStateUpdateInfo : public UpdateInfo { : UpdateInfo(slotId), callState_(callStateParam), phoneNumber_(phoneNumberParam) {} }; +struct CallStateExUpdateInfo : public UpdateInfo { + int32_t callStateEx_ = 0; + CallStateExUpdateInfo(int32_t slotId, int32_t callStateExParam): + UpdateInfo(slotId),callStateEx_(callStateExParam) {} +}; + struct SignalUpdateInfo : public UpdateInfo { std::vector> signalInfoList_ {}; SignalUpdateInfo(int32_t slotId, std::vector> infoList) diff --git a/frameworks/js/napi/src/event_listener_handler.cpp b/frameworks/js/napi/src/event_listener_handler.cpp index 82d86a6..70b1e92 100644 --- a/frameworks/js/napi/src/event_listener_handler.cpp +++ b/frameworks/js/napi/src/event_listener_handler.cpp @@ -78,6 +78,29 @@ int32_t WrapCallState(int32_t callState) } } +int32_t WrapCallStateEx(int32_t callState) +{ + switch (callState) { + case (int32_t)Telephony::CallStatus::CALL_STATUS_ACTIVE: + case (int32_t)Telephony::CallStatus::CALL_STATUS_HOLDING: + return static_cast(TelCallState::TEL_CALL_STATE_CONNECTED); + case (int32_t)Telephony::CallStatus::CALL_STATUS_DIALING: + case (int32_t)Telephony::CallStatus::CALL_STATUS_ALERTING: + return static_cast(TelCallState::TEL_CALL_STATE_OFFHOOK); + case (int32_t)Telephony::CallStatus::CALL_STATUS_WAITING: + case (int32_t)Telephony::CallStatus::CALL_STATUS_INCOMING: + return static_cast(TelCallState::TEL_CALL_STATE_RINGING); + case (int32_t)Telephony::CallStatus::CALL_STATUS_DISCONNECTING: + case (int32_t)Telephony::CallStatus::CALL_STATUS_DISCONNECTED: + case (int32_t)Telephony::CallStatus::CALL_STATUS_IDLE: + return static_cast(TelCallState::TEL_CALL_STATE_IDLE); + case (int32_t)Telephony::CallStatus::CALL_STATUS_ANSWERED: + return static_cast(TelCallState::TEL_CALL_STATE_ANSWERED); + default: + return static_cast(TelCallState::TEL_CALL_STATE_UNKNOWN); + } +} + int32_t WrapNetworkType(SignalInformation::NetworkType nativeNetworkType) { NetworkType jsNetworkType = NetworkType::NETWORK_TYPE_UNKNOWN; @@ -338,6 +361,11 @@ void EventListenerHandler::AddBasicHandlerToMap() [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleCallbackVoidUpdate(event); }; + handleFuncMap_[TelephonyCallbackEventId::EVENT_ON_CALL_STATE_EX_UPDATE] = + [this](const AppExecFwk::InnerEvent::Pointer &event) { + HandleCallbackInfoUpdate(event); + }; } void EventListenerHandler::AddNetworkHandlerToMap() @@ -362,6 +390,7 @@ void EventListenerHandler::AddNetworkHandlerToMap() void EventListenerHandler::AddWorkFuncToMap() { workFuncMap_[TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE] = &EventListenerHandler::WorkCallStateUpdated; + workFuncMap_[TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE] = &EventListenerHandler::WorkCallStateExUpdated; workFuncMap_[TelephonyUpdateEventType::EVENT_SIGNAL_STRENGTHS_UPDATE] = &EventListenerHandler::WorkSignalUpdated; workFuncMap_[TelephonyUpdateEventType::EVENT_NETWORK_STATE_UPDATE] = &EventListenerHandler::WorkNetworkStateUpdated; workFuncMap_[TelephonyUpdateEventType::EVENT_SIM_STATE_UPDATE] = &EventListenerHandler::WorkSimStateUpdated; @@ -430,7 +459,8 @@ int32_t EventListenerHandler::RegisterEventListener(EventListener &eventListener return TELEPHONY_ERR_LOCAL_PTR_NULL; } bool isUpdate = (eventListener.eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE || - eventListener.eventType == TelephonyUpdateEventType::EVENT_SIM_STATE_UPDATE); + eventListener.eventType == TelephonyUpdateEventType::EVENT_SIM_STATE_UPDATE || + eventListener.eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE); int32_t addResult = TelephonyStateManager::AddStateObserver( observer, eventListener.slotId, ToUint32t(eventListener.eventType), isUpdate); if (addResult != TELEPHONY_SUCCESS) { @@ -734,6 +764,23 @@ void EventListenerHandler::WorkCallStateUpdated(uv_work_t *work, std::unique_loc napi_close_handle_scope(env, scope); } +void EventListenerHandler::WorkCallStateExUpdated(uv_work_t *work, std::unique_lock &lock) +{ + std::unique_ptr callStateExInfo(static_cast(work->data)); + const napi_env &env = callStateExInfo->env; + napi_handle_scope scope = nullptr; + napi_open_handle_scope(env, &scope); + if (scope == nullptr) { + TELEPHONY_LOGE("scope is nullptr"); + } + napi_value callbackValue = nullptr; + napi_create_object(callStateExInfo->env, &callbackValue); + int32_t wrappedCallStateEx = WrapCallStateEx(callStateExInfo->callStateEx); + SetPropertyToNapiObject(callStateInfo->env, callbackValue, "state", wrappedCallStateEx); + NapiReturnToJS(callStateExInfo->env, callStateExInfo->callbackRef, callbackValue, lock); + napi_close_handle_scope(env, scope); +} + void EventListenerHandler::WorkSignalUpdated(uv_work_t *work, std::unique_lock &lock) { napi_handle_scope scope = nullptr; diff --git a/frameworks/js/napi/src/napi_state_registry.cpp b/frameworks/js/napi/src/napi_state_registry.cpp index 16a603e..d4fa752 100644 --- a/frameworks/js/napi/src/napi_state_registry.cpp +++ b/frameworks/js/napi/src/napi_state_registry.cpp @@ -48,6 +48,7 @@ const std::map eventMap { { "cfuIndicatorChange", TelephonyUpdateEventType::EVENT_CFU_INDICATOR_UPDATE }, { "voiceMailMsgIndicatorChange", TelephonyUpdateEventType::EVENT_VOICE_MAIL_MSG_INDICATOR_UPDATE }, { "iccAccountInfoChange", TelephonyUpdateEventType::EVENT_ICC_ACCOUNT_CHANGE }, + { "callStateChangeEx", TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE }, }; TelephonyUpdateEventType GetEventType(std::string_view event) @@ -60,7 +61,8 @@ TelephonyUpdateEventType GetEventType(std::string_view event) static inline bool IsValidSlotIdEx(TelephonyUpdateEventType eventType, int32_t slotId) { int32_t defaultSlotId = DEFAULT_SIM_SLOT_ID; - if (eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE) { + if (eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE || + eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { defaultSlotId = -1; } // One more slot for VSim. @@ -76,7 +78,8 @@ static void NativeOn(napi_env env, void *data) return; } ObserverContext *asyncContext = static_cast(data); - if (SIM_SLOT_COUNT == 0 && (asyncContext->eventType != TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE)) { + if (SIM_SLOT_COUNT == 0 && (asyncContext->eventType != TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE) && + (asyncContext->eventType != TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE)) { TELEPHONY_LOGE("The device is not support sim card."); asyncContext->resolved = true; return; @@ -114,7 +117,11 @@ static void OnCallback(napi_env env, void *data) if (asyncContext->errorCode == TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED) { NapiUtil::ThrowError(env, JS_ERROR_TELEPHONY_PERMISSION_DENIED, OBSERVER_JS_PERMISSION_ERROR_STRING); } else if (asyncContext->errorCode != TELEPHONY_ERR_CALLBACK_ALREADY_REGISTERED) { - JsError error = NapiUtil::ConverErrorMessageForJs(asyncContext->errorCode); + if (asyncContext->eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { + JsError error = NapiUtil::ConverErrorMessageCallStateExForJs(asyncContext->errorCode); + } else { + JsError error = NapiUtil::ConverErrorMessageForJs(asyncContext->errorCode); + } NapiUtil::ThrowError(env, error.errorCode, error.errorMessage); } if (env != nullptr && asyncContext->callbackRef != nullptr) { @@ -154,7 +161,9 @@ static napi_value On(napi_env env, napi_callback_info info) } else { auto paraTuple = std::make_tuple(std::data(eventType), &asyncContext->callbackRef); errCode = MatchParameters(env, parameters, parameterCount, paraTuple); - if (GetEventType(eventType.data()) == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE) { + TelephonyUpdateEventType registerEventType = GetEventType(eventType.data()); + if (registerEventType == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE || + registerEventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { TELEPHONY_LOGI("state registry observer has no slotId"); asyncContext->slotId = -1; } else if (ENABLE_ON_DEFAULT_DATA_EVENT_SET.find(GetEventType(eventType.data())) != @@ -162,13 +171,11 @@ static napi_value On(napi_env env, napi_callback_info info) asyncContext->slotId = SIM_SLOT_ID_FOR_DEFAULT_CONN_EVENT; } } - if (errCode.has_value()) { TELEPHONY_LOGE("On parameter matching failed."); NapiUtil::ThrowParameterError(env); return nullptr; } - ObserverContext *observerContext = asyncContext.release(); observerContext->eventType = GetEventType(eventType.data()); if (observerContext->eventType != TelephonyUpdateEventType::NONE_EVENT_TYPE) { @@ -221,6 +228,9 @@ static void OffCallback(napi_env env, void *data) TELEPHONY_LOGE("OffCallback error by remove observer failed"); if (asyncContext->errorCode == TELEPHONY_STATE_REGISTRY_PERMISSION_DENIED) { NapiUtil::ThrowError(env, JS_ERROR_TELEPHONY_PERMISSION_DENIED, OBSERVER_JS_PERMISSION_ERROR_STRING); + } else if (asyncContext->eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { + JsError error = NapiUtil::ConverErrorMessageCallStateExForJs(asyncContext->errorCode); + NapiUtil::ThrowError(env, error.errorCode, error.errorMessage); } else { JsError error = NapiUtil::ConverErrorMessageForJs(asyncContext->errorCode); NapiUtil::ThrowError(env, error.errorCode, error.errorMessage); diff --git a/frameworks/js/napi/src/napi_telephony_observer.cpp b/frameworks/js/napi/src/napi_telephony_observer.cpp index 265eef3..772969f 100644 --- a/frameworks/js/napi/src/napi_telephony_observer.cpp +++ b/frameworks/js/napi/src/napi_telephony_observer.cpp @@ -33,6 +33,19 @@ void NapiTelephonyObserver::OnCallStateUpdated(int32_t slotId, int32_t callState EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_CALL_STATE_UPDATE), callStateInfo); } +void NapiTelephonyObserver::OnCallStateUpdatedEx(int32_t slotId, int32_t callState) +{ + TELEPHONY_LOGI("OnCallStateUpdatedEx slotId = %{public}d, callState = %{public}d", slotId, callState); + std::unique_ptr callStateExInfo = + std::make_unique(slotId, callStateEx); + if (callStateExInfo == nullptr) { + TELEPHONY_LOGE("callStateExInfo is nullptr!"); + return; + } + EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_CALL_STATE_EX_UPDATE), + callStateExInfo); +} + void NapiTelephonyObserver::OnSignalInfoUpdated( int32_t slotId, const std::vector> &signalInfoList) { diff --git a/frameworks/native/observer/include/telephony_observer_proxy.h b/frameworks/native/observer/include/telephony_observer_proxy.h index 9cbe410..8d6df48 100644 --- a/frameworks/native/observer/include/telephony_observer_proxy.h +++ b/frameworks/native/observer/include/telephony_observer_proxy.h @@ -29,6 +29,8 @@ public: virtual ~TelephonyObserverProxy() = default; void OnCallStateUpdated( int32_t slotId, int32_t callState, const std::u16string &phoneNumber); + void OnCallStateUpdatedEx( + int32_t slotId, int32_t callStateEx); void OnSignalInfoUpdated( int32_t slotId, const std::vector> &vec); void OnNetworkStateUpdated( diff --git a/frameworks/native/observer/src/telephony_observer.cpp b/frameworks/native/observer/src/telephony_observer.cpp index 7e860e8..e2f4c80 100644 --- a/frameworks/native/observer/src/telephony_observer.cpp +++ b/frameworks/native/observer/src/telephony_observer.cpp @@ -47,6 +47,8 @@ void TelephonyObserver::OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voic void TelephonyObserver::OnIccAccountUpdated() {} +void TelephonyObserver::OnCallStateUpdatedEx(int32_t slotId, int32_t callStateEx) {} + TelephonyObserver::TelephonyObserver() { memberFuncMap_[static_cast(ObserverBrokerCode::ON_CALL_STATE_UPDATED)] = @@ -69,6 +71,8 @@ TelephonyObserver::TelephonyObserver() [this](MessageParcel &data, MessageParcel &reply) { OnVoiceMailMsgIndicatorUpdatedInner(data, reply); }; memberFuncMap_[static_cast(ObserverBrokerCode::ON_ICC_ACCOUNT_UPDATED)] = [this](MessageParcel &data, MessageParcel &reply) { OnIccAccountUpdatedInner(data, reply); }; + memberFuncMap_[static_cast(ObserverBrokerCode::ON_CALL_STATE_EX_UPDATED)] = + [this](MessageParcel &data, MessageParcel &reply) { OnCallStateUpdatedExInner(data, reply); }; } TelephonyObserver::~TelephonyObserver() {} @@ -175,6 +179,14 @@ void TelephonyObserver::OnIccAccountUpdatedInner(MessageParcel &data, MessagePar OnIccAccountUpdated(); } +void TelephonyObserver::OnCallStateUpdatedExInner( + MessageParcel &data, MessageParcel &reply) +{ + int32_t slotId = data.ReadInt32(); + int32_t callStateEx = data.ReadInt32(); + OnCallStateUpdatedEx(slotId, callStateEx); +} + void TelephonyObserver::ConvertSignalInfoList( MessageParcel &data, std::vector> &result) { diff --git a/frameworks/native/observer/src/telephony_observer_proxy.cpp b/frameworks/native/observer/src/telephony_observer_proxy.cpp index 52318dd..c44e606 100644 --- a/frameworks/native/observer/src/telephony_observer_proxy.cpp +++ b/frameworks/native/observer/src/telephony_observer_proxy.cpp @@ -49,6 +49,30 @@ void TelephonyObserverProxy::OnCallStateUpdated( TELEPHONY_LOGD("TelephonyObserverProxy::OnCallStateUpdated end ##error: %{public}d", code); }; +void TelephonyObserverProxy::OnCallStateUpdatedEx( + int32_t slotId, int32_t callStateEx) +{ + MessageParcel dataParcel; + MessageParcel replyParcel; + MessageOption option; + option.SetFlags(MessageOption::TF_ASYNC); + if (!dataParcel.WriteInterfaceToken(GetDescriptor())) { + TELEPHONY_LOGE("TelephonyObserverProxy::OnCallStateUpdatedEx WriteInterfaceToken failed!"); + return; + } + dataParcel.WriteInt32(slotId); + dataParcel.WriteInt32(callStateEx); + sptr remote = Remote(); + if (remote == nullptr) { + TELEPHONY_LOGE("TelephonyObserverProxy::OnCallStateUpdatedEx remote is null!"); + return; + } + int code = remote->SendRequest( + static_cast(ObserverBrokerCode::ON_CALL_STATE_EX_UPDATED), + dataParcel, replyParcel, option); + TELEPHONY_LOGD("TelephonyObserverProxy::OnCallStateUpdatedEx end ##error: %{public}d", code); +}; + void TelephonyObserverProxy::OnSimStateUpdated( int32_t slotId, CardType type, SimState state, LockReason reason) { diff --git a/interfaces/innerkits/observer/telephony_observer.h b/interfaces/innerkits/observer/telephony_observer.h index fc64a21..84ca909 100644 --- a/interfaces/innerkits/observer/telephony_observer.h +++ b/interfaces/innerkits/observer/telephony_observer.h @@ -120,6 +120,15 @@ public: uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; virtual void OnIccAccountUpdated() override; + /** + * @brief Called when tel call state is updated. + * + * @param slotId Indicates the slot identification. + * @param callState Indicates the tel call state. + */ + void OnCallStateUpdatedEx( + int32_t slotId, int32_t callStateEx) override; + private: using TelephonyObserverFunc = std::function; @@ -137,6 +146,7 @@ private: void OnCfuIndicatorUpdatedInner(MessageParcel &data, MessageParcel &reply); void OnVoiceMailMsgIndicatorUpdatedInner(MessageParcel &data, MessageParcel &reply); void OnIccAccountUpdatedInner(MessageParcel &data, MessageParcel &reply); + void OnCallStateUpdatedInner(MessageParcel &data, MessageParcel &reply); static constexpr int32_t CELL_NUM_MAX = 100; static constexpr int32_t SIGNAL_NUM_MAX = 100; std::map memberFuncMap_; diff --git a/services/src/telephony_state_registry_dump_helper.cpp b/services/src/telephony_state_registry_dump_helper.cpp index 6a8f38e..5cd02f8 100644 --- a/services/src/telephony_state_registry_dump_helper.cpp +++ b/services/src/telephony_state_registry_dump_helper.cpp @@ -58,6 +58,8 @@ bool TelephonyStateRegistryDumpHelper::ShowTelephonyStateRegistryInfo( result.append("CellInfo Register: "); } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_NETWORK_STATE)) { result.append("NetworkState Register: "); + } else if (item.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE_EX)) { + result.append("CallStateEx Register: "); } else { result.append("Unknown Subscriber: "); } diff --git a/services/src/telephony_state_registry_service.cpp b/services/src/telephony_state_registry_service.cpp index 116c81b..e6c2c70 100644 --- a/services/src/telephony_state_registry_service.cpp +++ b/services/src/telephony_state_registry_service.cpp @@ -203,7 +203,11 @@ int32_t TelephonyStateRegistryService::UpdateCallState(int32_t callState, const } record.telephonyObserver_->OnCallStateUpdated(record.slotId_, callState, phoneNumber); result = TELEPHONY_SUCCESS; - } + } else if (record.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE_EX) && + (record.slotId_ == -1) && record.telephonyObserver_ != nullptr) [ + record.telephonyObserver_->OnCallStateUpdatedEx(record.slotId_, callState); + result = TELEPHONY_SUCCESS; + ] } SendCallStateChanged(-1, callState); SendCallStateChangedAsUserMultiplePermission(-1, callState, number); @@ -232,6 +236,10 @@ int32_t TelephonyStateRegistryService::UpdateCallStateForSlotId( std::u16string phoneNumber = GetCallIncomingNumberForSlotId(record, slotId); record.telephonyObserver_->OnCallStateUpdated(slotId, callState, phoneNumber); result = TELEPHONY_SUCCESS; + } else if (record.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE_EX) && + (record.slotId_ == slotId) && record.telephonyObserver_ != nullptr) { + record.telephonyObserver_->OnCallStateUpdatedEx(slotId, callState); + result = TELEPHONY_SUCCESS; } } SendCallStateChanged(slotId, callState); @@ -493,7 +501,7 @@ int32_t TelephonyStateRegistryService::RegisterStateChange( record.telephonyObserver_ = telephonyObserver; stateRecords_.push_back(record); } - + TELEPHONY_LOGI("RegisterStateChange mask %{public}d", record.mask_); if (isUpdate) { UpdateData(record); } @@ -607,6 +615,10 @@ void TelephonyStateRegistryService::UpdateData(const TelephonyStateRegistryRecor TELEPHONY_LOGI("RegisterStateChange##Notify-OBSERVER_MASK_ICC_ACCOUNT"); record.telephonyObserver_->OnIccAccountUpdated(); } + if ((record.mask_ & TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE_EX) != 0) { + TELEPHONY_LOGI("RegisterStateChange##Notify-OBSERVER_MASK_CALL_STATE_EX"); + record.telephonyObserver_->OnCallStateUpdatedEx(record.slotId_, callState_[record.slotId_]); + } } bool TelephonyStateRegistryService::PublishCommonEvent( -- Gitee From c449636d22f57b1ca8fa8ebf9e961e21a0ef3b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 16:59:18 +0800 Subject: [PATCH 02/11] services/src/telephony_state_registry_service.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SigneallEx Signed-off-by: 邵夷恺 --- services/include/telephony_state_registry_service.h | 1 + services/src/telephony_state_registry_service.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/services/include/telephony_state_registry_service.h b/services/include/telephony_state_registry_service.h index f3f1562..4f98e31 100644 --- a/services/include/telephony_state_registry_service.h +++ b/services/include/telephony_state_registry_service.h @@ -72,6 +72,7 @@ public: private: void Finalize(); void UpdateData(const TelephonyStateRegistryRecord &record); + void UpdateDataEx(const TelephonyStateRegistryRecord &record); private: bool CheckCallerIsSystemApp(uint32_t mask); diff --git a/services/src/telephony_state_registry_service.cpp b/services/src/telephony_state_registry_service.cpp index e6c2c70..813bf0c 100644 --- a/services/src/telephony_state_registry_service.cpp +++ b/services/src/telephony_state_registry_service.cpp @@ -570,7 +570,7 @@ std::u16string TelephonyStateRegistryService::GetCallIncomingNumberForSlotId( void TelephonyStateRegistryService::UpdateData(const TelephonyStateRegistryRecord &record) { if (record.telephonyObserver_ == nullptr) { - TELEPHONY_LOGE("record.telephonyObserver_ is nullptr"); + TELEPHONY_LOGE("record.telephonyObserver_ is nullptr"); return; } if ((record.mask_ & TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE) != 0) { @@ -615,6 +615,15 @@ void TelephonyStateRegistryService::UpdateData(const TelephonyStateRegistryRecor TELEPHONY_LOGI("RegisterStateChange##Notify-OBSERVER_MASK_ICC_ACCOUNT"); record.telephonyObserver_->OnIccAccountUpdated(); } + UpdateDataEx(record); +} + +void TelephonyStateRegistryService::UpdateDataEx(const TelephonyStateRegistryRecord &record) +{ + if (record.telephonyObserver_ == nullptr) { + TELEPHONY_LOGE("record.telephonyObserver_ is nullptr"); + return; + } if ((record.mask_ & TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE_EX) != 0) { TELEPHONY_LOGI("RegisterStateChange##Notify-OBSERVER_MASK_CALL_STATE_EX"); record.telephonyObserver_->OnCallStateUpdatedEx(record.slotId_, callState_[record.slotId_]); -- Gitee From 2c9fb44ab2817e09389ab7b7c16f3d18f851c8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 16:59:18 +0800 Subject: [PATCH 03/11] updatecallex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- frameworks/js/napi/include/napi_state_registry.h | 2 +- frameworks/js/napi/include/update_infos.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/js/napi/include/napi_state_registry.h b/frameworks/js/napi/include/napi_state_registry.h index e8f6159..ad32699 100644 --- a/frameworks/js/napi/include/napi_state_registry.h +++ b/frameworks/js/napi/include/napi_state_registry.h @@ -86,7 +86,7 @@ enum class TelCallState : int32_t { TEL_CALL_STATE_RINGING = 1, /** - * Indicates that a least one call is in the dialing,and there is no new + * Indicates that a least one call is in the dialing,and there is no new * incoming call ringing or waiting. */ TEL_CALL_STATE_OFFHOOK = 2, diff --git a/frameworks/js/napi/include/update_infos.h b/frameworks/js/napi/include/update_infos.h index 4101df4..2368a21 100644 --- a/frameworks/js/napi/include/update_infos.h +++ b/frameworks/js/napi/include/update_infos.h @@ -42,8 +42,8 @@ struct CallStateUpdateInfo : public UpdateInfo { struct CallStateExUpdateInfo : public UpdateInfo { int32_t callStateEx_ = 0; - CallStateExUpdateInfo(int32_t slotId, int32_t callStateExParam): - UpdateInfo(slotId),callStateEx_(callStateExParam) {} + CallStateExUpdateInfo(int32_t slotId, int32_t callStateExParam) + : UpdateInfo(slotId), callStateEx_(callStateExParam) {} }; struct SignalUpdateInfo : public UpdateInfo { -- Gitee From 19519f475e38e80a9e8ae58f1cda0e1adcfb5d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 21:22:40 +0800 Subject: [PATCH 04/11] updatecallex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- frameworks/js/napi/src/napi_state_registry.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frameworks/js/napi/src/napi_state_registry.cpp b/frameworks/js/napi/src/napi_state_registry.cpp index d4fa752..09e2a1f 100644 --- a/frameworks/js/napi/src/napi_state_registry.cpp +++ b/frameworks/js/napi/src/napi_state_registry.cpp @@ -154,8 +154,7 @@ static napi_value On(napi_env env, napi_callback_info info) napi_value slotId = NapiUtil::GetNamedProperty(env, object, "slotId"); if (slotId) { NapiValueToCppValue(env, slotId, napi_number, &asyncContext->slotId); - TELEPHONY_LOGI("state registry on slotId = %{public}d, eventType = %{public}d", asyncContext->slotId, - asyncContext->eventType); + TELEPHONY_LOGI("state registry on eventType = %{public}d", asyncContext->eventType); } } } else { @@ -164,7 +163,6 @@ static napi_value On(napi_env env, napi_callback_info info) TelephonyUpdateEventType registerEventType = GetEventType(eventType.data()); if (registerEventType == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE || registerEventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { - TELEPHONY_LOGI("state registry observer has no slotId"); asyncContext->slotId = -1; } else if (ENABLE_ON_DEFAULT_DATA_EVENT_SET.find(GetEventType(eventType.data())) != ENABLE_ON_DEFAULT_DATA_EVENT_SET.end()) { @@ -172,7 +170,6 @@ static napi_value On(napi_env env, napi_callback_info info) } } if (errCode.has_value()) { - TELEPHONY_LOGE("On parameter matching failed."); NapiUtil::ThrowParameterError(env); return nullptr; } -- Gitee From 1fd7eeff53f0880c6426d56630030bf5729b0bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 14:29:39 +0000 Subject: [PATCH 05/11] update interfaces/innerkits/observer/telephony_observer.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- interfaces/innerkits/observer/telephony_observer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/observer/telephony_observer.h b/interfaces/innerkits/observer/telephony_observer.h index 84ca909..7a8f0b0 100644 --- a/interfaces/innerkits/observer/telephony_observer.h +++ b/interfaces/innerkits/observer/telephony_observer.h @@ -146,7 +146,7 @@ private: void OnCfuIndicatorUpdatedInner(MessageParcel &data, MessageParcel &reply); void OnVoiceMailMsgIndicatorUpdatedInner(MessageParcel &data, MessageParcel &reply); void OnIccAccountUpdatedInner(MessageParcel &data, MessageParcel &reply); - void OnCallStateUpdatedInner(MessageParcel &data, MessageParcel &reply); + void OnCallStateUpdatedExInner(MessageParcel &data, MessageParcel &reply); static constexpr int32_t CELL_NUM_MAX = 100; static constexpr int32_t SIGNAL_NUM_MAX = 100; std::map memberFuncMap_; -- Gitee From 0ee48d4e3069bd8c748c093689920569587066c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 14:33:16 +0000 Subject: [PATCH 06/11] update frameworks/js/napi/src/napi_state_registry.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- frameworks/js/napi/src/napi_state_registry.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/napi_state_registry.cpp b/frameworks/js/napi/src/napi_state_registry.cpp index 09e2a1f..e3e33cf 100644 --- a/frameworks/js/napi/src/napi_state_registry.cpp +++ b/frameworks/js/napi/src/napi_state_registry.cpp @@ -119,10 +119,11 @@ static void OnCallback(napi_env env, void *data) } else if (asyncContext->errorCode != TELEPHONY_ERR_CALLBACK_ALREADY_REGISTERED) { if (asyncContext->eventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { JsError error = NapiUtil::ConverErrorMessageCallStateExForJs(asyncContext->errorCode); + NapiUtil::ThrowError(env, error.errorCode, error.errorMessage); } else { JsError error = NapiUtil::ConverErrorMessageForJs(asyncContext->errorCode); + NapiUtil::ThrowError(env, error.errorCode, error.errorMessage); } - NapiUtil::ThrowError(env, error.errorCode, error.errorMessage); } if (env != nullptr && asyncContext->callbackRef != nullptr) { napi_delete_reference(env, asyncContext->callbackRef); -- Gitee From 2e303cd471b3724f32adf0396daff1be6c4fff2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 14:51:18 +0000 Subject: [PATCH 07/11] update frameworks/js/napi/include/napi_telephony_observer.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- frameworks/js/napi/include/napi_telephony_observer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/include/napi_telephony_observer.h b/frameworks/js/napi/include/napi_telephony_observer.h index cb80722..6f223c2 100644 --- a/frameworks/js/napi/include/napi_telephony_observer.h +++ b/frameworks/js/napi/include/napi_telephony_observer.h @@ -28,7 +28,7 @@ namespace Telephony { class NapiTelephonyObserver : public TelephonyObserver { public: void OnCallStateUpdated(int32_t slotId, int32_t callState, const std::u16string &phoneNumber) override; - void OnCallStateUpdatedEx(int32_t slotId, int32_t callState) override; + void OnCallStateUpdatedEx(int32_t slotId, int32_t callStateEx) override; void OnSignalInfoUpdated(int32_t slotId, const std::vector> &vec) override; void OnNetworkStateUpdated(int32_t slotId, const sptr &networkState) override; void OnSimStateUpdated(int32_t slotId, CardType type, SimState state, LockReason reason) override; -- Gitee From a4d9c0bac0fb2fb72bc35ae83c5a3312dc0572b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 15:11:22 +0000 Subject: [PATCH 08/11] update frameworks/js/napi/src/napi_telephony_observer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- frameworks/js/napi/src/napi_telephony_observer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/src/napi_telephony_observer.cpp b/frameworks/js/napi/src/napi_telephony_observer.cpp index 772969f..13e97b7 100644 --- a/frameworks/js/napi/src/napi_telephony_observer.cpp +++ b/frameworks/js/napi/src/napi_telephony_observer.cpp @@ -33,9 +33,9 @@ void NapiTelephonyObserver::OnCallStateUpdated(int32_t slotId, int32_t callState EventListenerManager::SendEvent(ToUint32t(TelephonyCallbackEventId::EVENT_ON_CALL_STATE_UPDATE), callStateInfo); } -void NapiTelephonyObserver::OnCallStateUpdatedEx(int32_t slotId, int32_t callState) +void NapiTelephonyObserver::OnCallStateUpdatedEx(int32_t slotId, int32_t callStateEx) { - TELEPHONY_LOGI("OnCallStateUpdatedEx slotId = %{public}d, callState = %{public}d", slotId, callState); + TELEPHONY_LOGI("OnCallStateUpdatedEx slotId = %{public}d, callState = %{public}d", slotId, callStateEx); std::unique_ptr callStateExInfo = std::make_unique(slotId, callStateEx); if (callStateExInfo == nullptr) { -- Gitee From f085a62eeaf9f9fb56351f544867b41102e318f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Tue, 9 Sep 2025 15:32:24 +0000 Subject: [PATCH 09/11] update frameworks/js/napi/src/event_listener_handler.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- frameworks/js/napi/src/event_listener_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/event_listener_handler.cpp b/frameworks/js/napi/src/event_listener_handler.cpp index 70b1e92..7b61056 100644 --- a/frameworks/js/napi/src/event_listener_handler.cpp +++ b/frameworks/js/napi/src/event_listener_handler.cpp @@ -776,7 +776,7 @@ void EventListenerHandler::WorkCallStateExUpdated(uv_work_t *work, std::unique_l napi_value callbackValue = nullptr; napi_create_object(callStateExInfo->env, &callbackValue); int32_t wrappedCallStateEx = WrapCallStateEx(callStateExInfo->callStateEx); - SetPropertyToNapiObject(callStateInfo->env, callbackValue, "state", wrappedCallStateEx); + SetPropertyToNapiObject(callStateExInfo->env, callbackValue, "state", wrappedCallStateEx); NapiReturnToJS(callStateExInfo->env, callStateExInfo->callbackRef, callbackValue, lock); napi_close_handle_scope(env, scope); } -- Gitee From 4b7e2141bcb4891b2e3e8234ddd085cd08760bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Wed, 10 Sep 2025 02:00:09 +0000 Subject: [PATCH 10/11] update services/src/telephony_state_registry_service.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- services/src/telephony_state_registry_service.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/src/telephony_state_registry_service.cpp b/services/src/telephony_state_registry_service.cpp index 813bf0c..ff5ef61 100644 --- a/services/src/telephony_state_registry_service.cpp +++ b/services/src/telephony_state_registry_service.cpp @@ -204,10 +204,10 @@ int32_t TelephonyStateRegistryService::UpdateCallState(int32_t callState, const record.telephonyObserver_->OnCallStateUpdated(record.slotId_, callState, phoneNumber); result = TELEPHONY_SUCCESS; } else if (record.IsExistStateListener(TelephonyObserverBroker::OBSERVER_MASK_CALL_STATE_EX) && - (record.slotId_ == -1) && record.telephonyObserver_ != nullptr) [ + (record.slotId_ == -1) && record.telephonyObserver_ != nullptr) { record.telephonyObserver_->OnCallStateUpdatedEx(record.slotId_, callState); result = TELEPHONY_SUCCESS; - ] + } } SendCallStateChanged(-1, callState); SendCallStateChangedAsUserMultiplePermission(-1, callState, number); -- Gitee From 37990d5f2ddc9e3e24bbd3502d7b0dbef1452af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B5=E5=A4=B7=E6=81=BA?= Date: Thu, 11 Sep 2025 11:35:53 +0000 Subject: [PATCH 11/11] update frameworks/js/napi/src/napi_state_registry.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 邵夷恺 --- .../js/napi/src/napi_state_registry.cpp | 70 +++++++++++++------ 1 file changed, 50 insertions(+), 20 deletions(-) diff --git a/frameworks/js/napi/src/napi_state_registry.cpp b/frameworks/js/napi/src/napi_state_registry.cpp index e3e33cf..cfcb3aa 100644 --- a/frameworks/js/napi/src/napi_state_registry.cpp +++ b/frameworks/js/napi/src/napi_state_registry.cpp @@ -133,12 +133,57 @@ static void OnCallback(napi_env env, void *data) delete asyncContext; } +static std::optional MatchParametersWithObject(napi_env env, napi_value* parameters, + std::array& eventType, napi_value& object, std::unique_ptr&asyncContext) +{ + napi_valuetype valueTypeTemp = napi_undefined; + size_t parameterCount = PARAMETER_COUNT_THREE; + napi_value parametersValue[] = { parameters[0], parameters[1], parameters[2] }; + napi_typeof(env, parameters[parameterCount - 1], &valueTypeTemp); + std::optional errCode; + if (valueTypeTemp == napi_object) { + auto paraTuple = std::make_tuple(std::data(eventType), &asyncContext->callbackRef, &object); + errCode = MatchParameters(env, parametersValue, parameterCount, paraTuple); + } else { + auto paraTuple = std::make_tuple(std::data(eventType), &object, &asyncContext->callbackRef); + errCode = MatchParameters(env, parametersValue, parameterCount, paraTuple); + } + if (!errCode.has_value()) { + napi_value slotId = NapiUtil::GetNamedProperty(env, object, "slotId"); + if (slotId) { + NapiValueToCppValue(env, slotId, napi_number, &asyncContext->slotId); + TELEPHONY_LOGI("state registry on slotId = %{public}d, eventType = %{public}d", + asyncContext->slotId, asyncContext->eventType); + } + } + return errCode; +} + +static std::optional MatchParametersWithoutObject(napi_env env, napi_value* parameters, + size_t parameterCount, std::array& eventType, std::unique_ptr& asyncContext) +{ + napi_value parametersValue[] = { parameters[0], parameters[1], parameters[2] }; + auto paraTuple = std::make_tuple(std::data(eventType), &asyncContext->callbackRef); + std::optional errCode = MatchParameters(env, parametersValue, parameterCount, paraTuple); + if (!errCode.has_value()) { + TelephonyUpdateEventType registType = GetEventType(eventType.data()); + if (registType == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE || + registType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { + TELEPHONY_LOGI("state registry observer has no slotId"); + asyncContext->slotId = -1; + } else if (ENABLE_ON_DEFAULT_DATA_EVENT_SET.find(GetEventType(eventType.data())) != + ENABLE_ON_DEFAULT_DATA_EVENT_SET.end()) { + asyncContext->slotId = SIM_SLOT_ID_FOR_DEFAULT_CONN_EVENT; + } + } + return errCode; +} + static napi_value On(napi_env env, napi_callback_info info) { size_t parameterCount = PARAMETER_COUNT_THREE; napi_value parameters[] = { nullptr, nullptr, nullptr }; napi_get_cb_info(env, info, ¶meterCount, parameters, nullptr, nullptr); - std::unique_ptr asyncContext = std::make_unique(); if (asyncContext == nullptr) { TELEPHONY_LOGE("On asyncContext is nullptr."); @@ -149,28 +194,13 @@ static napi_value On(napi_env env, napi_callback_info info) napi_value object = NapiUtil::CreateUndefined(env); std::optional errCode; if (parameterCount == std::size(parameters)) { - auto paraTuple = std::make_tuple(std::data(eventType), &object, &asyncContext->callbackRef); - errCode = MatchParameters(env, parameters, parameterCount, paraTuple); - if (!errCode.has_value()) { - napi_value slotId = NapiUtil::GetNamedProperty(env, object, "slotId"); - if (slotId) { - NapiValueToCppValue(env, slotId, napi_number, &asyncContext->slotId); - TELEPHONY_LOGI("state registry on eventType = %{public}d", asyncContext->eventType); - } - } + errCode = MatchParametersWithObject(env, parameters, eventType, object, asyncContext); } else { - auto paraTuple = std::make_tuple(std::data(eventType), &asyncContext->callbackRef); - errCode = MatchParameters(env, parameters, parameterCount, paraTuple); - TelephonyUpdateEventType registerEventType = GetEventType(eventType.data()); - if (registerEventType == TelephonyUpdateEventType::EVENT_CALL_STATE_UPDATE || - registerEventType == TelephonyUpdateEventType::EVENT_CALL_STATE_EX_UPDATE) { - asyncContext->slotId = -1; - } else if (ENABLE_ON_DEFAULT_DATA_EVENT_SET.find(GetEventType(eventType.data())) != - ENABLE_ON_DEFAULT_DATA_EVENT_SET.end()) { - asyncContext->slotId = SIM_SLOT_ID_FOR_DEFAULT_CONN_EVENT; - } + errCode = MatchParametersWithoutObject(env, parameters, parameterCount, eventType, asyncContext); } + if (errCode.has_value()) { + TELEPHONY_LOGE("On parameter matching failed."); NapiUtil::ThrowParameterError(env); return nullptr; } -- Gitee