From 29a0eef3136679cc009d31c7a27eb34cb7624400 Mon Sep 17 00:00:00 2001 From: amunra03 Date: Thu, 7 Nov 2024 21:13:29 +0800 Subject: [PATCH] add nfc event Signed-off-by: amunra03 --- interfaces/inner_api/common/inci_nfcc_interface.h | 4 +--- interfaces/inner_api/common/nfc_sdk_common.h | 10 ++++++++++ services/include/nfc_service.h | 1 + services/src/card_emulation/ce_service.cpp | 11 +++++++---- services/src/external_deps/nfc_param_util.cpp | 2 +- .../include/nci_nfcc_impl_default.h | 2 +- .../src/nci_nfcc_impl_default.cpp | 2 +- services/src/nci_adapter/nci_nfcc_proxy.cpp | 2 +- services/src/nci_adapter/nci_nfcc_proxy.h | 2 +- services/src/nfc_polling_manager.cpp | 8 ++++---- services/src/nfc_service.cpp | 13 +++++++++++++ services/src/tag/tag_dispatcher.cpp | 2 ++ 12 files changed, 43 insertions(+), 16 deletions(-) diff --git a/interfaces/inner_api/common/inci_nfcc_interface.h b/interfaces/inner_api/common/inci_nfcc_interface.h index b586e0a4..187a427a 100644 --- a/interfaces/inner_api/common/inci_nfcc_interface.h +++ b/interfaces/inner_api/common/inci_nfcc_interface.h @@ -19,8 +19,6 @@ namespace OHOS { namespace NFC { namespace NCI { -const std::string FOREGROUND_APP_KEY = "foreground"; -const std::string READERMODE_APP_KEY = "readermode"; class INciNfccInterface { public: virtual ~INciNfccInterface() = default; @@ -82,7 +80,7 @@ public: /** * @brief Send a custom message to vendor */ - virtual void NotifyMessageToVendor(const std::string& key, const std::string& value) = 0; + virtual void NotifyMessageToVendor(int key, const std::string& value) = 0; }; } // namespace NCI } // namespace NFC diff --git a/interfaces/inner_api/common/nfc_sdk_common.h b/interfaces/inner_api/common/nfc_sdk_common.h index 24ce0fff..0cb4ed73 100644 --- a/interfaces/inner_api/common/nfc_sdk_common.h +++ b/interfaces/inner_api/common/nfc_sdk_common.h @@ -160,6 +160,16 @@ enum EmNfcForumType { ICODE_SLI = 102 }; +enum NotifyVendorEvent : int { + DEF_PAYMENT_APP_CHANGE_KEY = 1114, + TAG_DISPATCH_KEY = 1115, + READERMODE_APP_KEY = 1120, + FOREGROUND_APP_KEY = 1121, + NFC_SWITCH_KEY = 1122, + DEF_PAYMENT_APP_REMOVED_KEY = 1124, + DEF_PAYMENT_APP_ADDED_KEY = 1125, +}; + class NfcSdkCommon final { public: static const int SHIFT_SIZE = 8; diff --git a/services/include/nfc_service.h b/services/include/nfc_service.h index b22733b5..8bcf0ca0 100644 --- a/services/include/nfc_service.h +++ b/services/include/nfc_service.h @@ -74,6 +74,7 @@ public: std::string GetSimVendorBundleName() override; std::weak_ptr GetTagDispatcher() override; + void NotifyMessageToVendor(int key, const std::string &value); private: bool IsNfcTaskReady(std::future& future) const; diff --git a/services/src/card_emulation/ce_service.cpp b/services/src/card_emulation/ce_service.cpp index a6a72685..89686cc4 100644 --- a/services/src/card_emulation/ce_service.cpp +++ b/services/src/card_emulation/ce_service.cpp @@ -246,6 +246,7 @@ void CeService::OnDefaultPaymentServiceChange() ErrorLog("NFC not enabled, should not happen.The default payment app is be set when nfc is enabled."); return; } + nfcService_.lock()->NotifyMessageToVendor(KITS::DEF_PAYMENT_APP_CHANGE_KEY, newElement.GetBundleName()); ExternalDepsProxy::GetInstance().WriteDefaultPaymentAppChangeHiSysEvent(defaultPaymentElement_.GetBundleName(), newElement.GetBundleName()); UpdateDefaultPaymentElement(newElement); @@ -269,11 +270,16 @@ void CeService::OnAppAddOrChangeOrRemove(std::shared_ptrNotifyMessageToVendor(KITS::DEF_PAYMENT_APP_REMOVED_KEY, bundleName); } if (bundleName == defaultPaymentElement_.GetBundleName() && @@ -281,12 +287,9 @@ void CeService::OnAppAddOrChangeOrRemove(std::shared_ptrNotifyMessageToVendor(KITS::DEF_PAYMENT_APP_ADDED_KEY, bundleName); } - if (nfcService_.expired()) { - ErrorLog("nfcService_ is nullptr."); - return; - } if (!nfcService_.lock()->IsNfcEnabled()) { ErrorLog(" NFC not enabled, not need to update routing entry "); return; diff --git a/services/src/external_deps/nfc_param_util.cpp b/services/src/external_deps/nfc_param_util.cpp index 9dfdfa9d..a86bd2dd 100644 --- a/services/src/external_deps/nfc_param_util.cpp +++ b/services/src/external_deps/nfc_param_util.cpp @@ -41,7 +41,7 @@ int NfcParamUtil::GetNfcStateFromParam() ErrorLog("failed to get nfc switch state, errCode[%{public}d]", errCode); return 0; // return invalid nfc state } - InfoLog("GetNfcStateFromParam, nfc state[%{publib}d]", nfcState); + InfoLog("GetNfcStateFromParam, nfc state[%{public}s]", nfcState); errno = 0; char *endptr = nullptr; long int num = std::strtol(nfcState, &endptr, DECIMAL_NOTATION); diff --git a/services/src/nci_adapter/nci_native_default/include/nci_nfcc_impl_default.h b/services/src/nci_adapter/nci_native_default/include/nci_nfcc_impl_default.h index 9dae1aa3..7804e075 100644 --- a/services/src/nci_adapter/nci_native_default/include/nci_nfcc_impl_default.h +++ b/services/src/nci_adapter/nci_native_default/include/nci_nfcc_impl_default.h @@ -33,7 +33,7 @@ public: void Abort() override; void FactoryReset() override; void Shutdown() override; - void NotifyMessageToVendor(const std::string& key, const std::string& value) override; + void NotifyMessageToVendor(int key, const std::string& value) override; }; } // namespace NCI } // namespace NFC diff --git a/services/src/nci_adapter/nci_native_default/src/nci_nfcc_impl_default.cpp b/services/src/nci_adapter/nci_native_default/src/nci_nfcc_impl_default.cpp index b3a227a9..a72d7f32 100644 --- a/services/src/nci_adapter/nci_native_default/src/nci_nfcc_impl_default.cpp +++ b/services/src/nci_adapter/nci_native_default/src/nci_nfcc_impl_default.cpp @@ -65,7 +65,7 @@ void NciNfccImplDefault::Shutdown() NfccNciAdapter::GetInstance().Shutdown(); } -void NciNfccImplDefault::NotifyMessageToVendor(const std::string& key, const std::string& value) +void NciNfccImplDefault::NotifyMessageToVendor(int key, const std::string& value) { } } // namespace NCI diff --git a/services/src/nci_adapter/nci_nfcc_proxy.cpp b/services/src/nci_adapter/nci_nfcc_proxy.cpp index b601db8d..6dc4d0ad 100644 --- a/services/src/nci_adapter/nci_nfcc_proxy.cpp +++ b/services/src/nci_adapter/nci_nfcc_proxy.cpp @@ -129,7 +129,7 @@ void NciNfccProxy::Shutdown() /** * @brief Send a custom message to vendor */ -void NciNfccProxy::NotifyMessageToVendor(const std::string& key, const std::string& value) +void NciNfccProxy::NotifyMessageToVendor(int key, const std::string& value) { if (nfccInterface_) { return nfccInterface_->NotifyMessageToVendor(key, value); diff --git a/services/src/nci_adapter/nci_nfcc_proxy.h b/services/src/nci_adapter/nci_nfcc_proxy.h index 14323a73..a29e60d0 100644 --- a/services/src/nci_adapter/nci_nfcc_proxy.h +++ b/services/src/nci_adapter/nci_nfcc_proxy.h @@ -80,7 +80,7 @@ public: /** * @brief Send a custom message to vendor */ - void NotifyMessageToVendor(const std::string& key, const std::string& value) override; + void NotifyMessageToVendor(int key, const std::string& value) override; private: std::shared_ptr nfccInterface_; }; diff --git a/services/src/nfc_polling_manager.cpp b/services/src/nfc_polling_manager.cpp index be7ce5ad..5e8399e9 100644 --- a/services/src/nfc_polling_manager.cpp +++ b/services/src/nfc_polling_manager.cpp @@ -169,7 +169,7 @@ bool NfcPollingManager::EnableForegroundDispatch(AppExecFwk::ElementName &elemen foregroundData_->techMask_ = nciTagProxy_.lock()->GetTechMaskFromTechList(discTech); foregroundData_->element_ = element; foregroundData_->callback_ = callback; - nciNfccProxy_.lock()->NotifyMessageToVendor(NCI::FOREGROUND_APP_KEY, element.GetBundleName()); + nciNfccProxy_.lock()->NotifyMessageToVendor(KITS::FOREGROUND_APP_KEY, element.GetBundleName()); } return true; } @@ -186,7 +186,7 @@ bool NfcPollingManager::DisableForegroundDispatch(const AppExecFwk::ElementName ErrorLog("DisableForegroundDispatch: nciNfccProxy_ is nullptr."); return false; } - nciNfccProxy_.lock()->NotifyMessageToVendor(NCI::FOREGROUND_APP_KEY, ""); + nciNfccProxy_.lock()->NotifyMessageToVendor(KITS::FOREGROUND_APP_KEY, ""); return true; } @@ -233,7 +233,7 @@ bool NfcPollingManager::EnableReaderMode(AppExecFwk::ElementName &element, std:: readerModeData_->techMask_ = nciTagProxy_.lock()->GetTechMaskFromTechList(discTech); readerModeData_->element_ = element; readerModeData_->callback_ = callback; - nciNfccProxy_.lock()->NotifyMessageToVendor(NCI::READERMODE_APP_KEY, element.GetBundleName()); + nciNfccProxy_.lock()->NotifyMessageToVendor(KITS::READERMODE_APP_KEY, element.GetBundleName()); } nciTagProxy_.lock()->StopFieldChecking(); StartPollingLoop(true); @@ -250,7 +250,7 @@ bool NfcPollingManager::DisableReaderMode(AppExecFwk::ElementName &element) readerModeData_->callback_ = nullptr; nciTagProxy_.lock()->StopFieldChecking(); StartPollingLoop(true); - nciNfccProxy_.lock()->NotifyMessageToVendor(NCI::READERMODE_APP_KEY, ""); + nciNfccProxy_.lock()->NotifyMessageToVendor(KITS::READERMODE_APP_KEY, ""); return true; } diff --git a/services/src/nfc_service.cpp b/services/src/nfc_service.cpp index b800dee4..005d9f70 100644 --- a/services/src/nfc_service.cpp +++ b/services/src/nfc_service.cpp @@ -292,6 +292,7 @@ bool NfcService::DoTurnOn() CancelUnloadNfcSaTimer(); UpdateNfcState(KITS::STATE_TURNING_ON); + NotifyMessageToVendor(KITS::NFC_SWITCH_KEY, std::to_string(KITS::STATE_TURNING_ON)); NfcWatchDog nfcWatchDog("DoTurnOn", WAIT_MS_INIT, nciNfccProxy_); nfcWatchDog.Run(); // Routing WakeLock acquire @@ -306,6 +307,7 @@ bool NfcService::DoTurnOn() // Record failed event ExternalDepsProxy::GetInstance().WriteNfcFailedHiSysEvent(MainErrorCode::NFC_OPEN_FAILED, SubErrorCode::NCI_RESP_ERROR); + NotifyMessageToVendor(KITS::NFC_SWITCH_KEY, std::to_string(KITS::STATE_OFF)); return false; } // Routing Wake Lock release @@ -334,6 +336,7 @@ bool NfcService::DoTurnOn() // Record success event ExternalDepsProxy::GetInstance().WriteNfcFailedHiSysEvent( MainErrorCode::NFC_OPEN_SUCCEED, SubErrorCode::DEFAULT_ERR_DEF); + NotifyMessageToVendor(KITS::NFC_SWITCH_KEY, std::to_string(KITS::STATE_ON)); return true; } @@ -341,6 +344,7 @@ bool NfcService::DoTurnOff() { InfoLog("Nfc do turn off: current state %{public}d", nfcState_); UpdateNfcState(KITS::STATE_TURNING_OFF); + NotifyMessageToVendor(KITS::NFC_SWITCH_KEY, std::to_string(KITS::STATE_TURNING_OFF)); /* WatchDog to monitor for Deinitialize failed */ NfcWatchDog nfcWatchDog("DoTurnOff", WAIT_MS_SET_ROUTE, nciNfccProxy_); @@ -360,6 +364,7 @@ bool NfcService::DoTurnOff() // Record success event ExternalDepsProxy::GetInstance().WriteNfcFailedHiSysEvent( MainErrorCode::NFC_CLOSE_SUCCEED, SubErrorCode::DEFAULT_ERR_DEF); + NotifyMessageToVendor(KITS::NFC_SWITCH_KEY, std::to_string(KITS::STATE_OFF)); return result; } @@ -544,5 +549,13 @@ void NfcService::CancelUnloadNfcSaTimer() } } +void NfcService::NotifyMessageToVendor(int key, const std::string &value) +{ + if (nciNfccProxy_ == nullptr) { + ErrorLog("nciNfccProxy_ nullptr."); + return; + } + nciNfccProxy_->NotifyMessageToVendor(key, value); +} } // namespace NFC } // namespace OHOS diff --git a/services/src/tag/tag_dispatcher.cpp b/services/src/tag/tag_dispatcher.cpp index dcdaec7b..f8671fe9 100644 --- a/services/src/tag/tag_dispatcher.cpp +++ b/services/src/tag/tag_dispatcher.cpp @@ -267,6 +267,7 @@ void TagDispatcher::OnNotificationButtonClicked(int notificationId) // start application ability for tag found. if (nfcService_) { ExternalDepsProxy::GetInstance().DispatchTagAbility(tagInfo_, nfcService_->GetTagServiceIface()); + nfcService_->NotifyMessageToVendor(KITS::TAG_DISPATCH_KEY, ""); } break; } @@ -290,6 +291,7 @@ void TagDispatcher::OnNotificationButtonClicked(int notificationId) // start application ability for tag found. if (nfcService_) { ExternalDepsProxy::GetInstance().DispatchTagAbility(tagInfo_, nfcService_->GetTagServiceIface()); + nfcService_->NotifyMessageToVendor(KITS::TAG_DISPATCH_KEY, ""); } break; case NFC_BROWSER_NOTIFICATION_ID: -- Gitee