From 48bbdcfb5416ce38f8e5f93645cb6b60ce508bfd Mon Sep 17 00:00:00 2001 From: zhangweilei Date: Mon, 8 Sep 2025 20:06:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E8=A1=A8=E6=94=B6=E5=88=B0=E7=9C=9F?= =?UTF-8?q?=E5=AE=9E=E8=93=9D=E7=89=99=E9=80=9A=E8=AF=9D=E5=8D=A1=E6=A0=87?= =?UTF-8?q?=E6=89=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangweilei --- .../include/call_records_manager.h | 1 - .../src/call_records_manager.cpp | 15 +++-------- services/call/include/call_base.h | 3 +++ services/call/src/call_base.cpp | 12 +++++++++ .../include/call_ability_report_proxy.h | 1 + .../src/call_ability_report_proxy.cpp | 21 ++++++++++++++- .../include/interoperable_client_manager.h | 2 +- .../interoperable_communication_manager.h | 1 + .../include/interoperable_data_controller.h | 8 ++++-- .../src/interoperable_client_manager.cpp | 7 +++++ .../interoperable_communication_manager.cpp | 10 +++++++ .../src/interoperable_data_controller.cpp | 16 ++++++++++++ .../src/zero_branch6_test.cpp | 26 +++++++++++++++++++ ...teroperable_communication_manager_test.cpp | 16 ++++++++++++ .../interoperable_data_controller_test.cpp | 19 ++++++++++++++ 15 files changed, 141 insertions(+), 17 deletions(-) diff --git a/services/call/call_state_observer/include/call_records_manager.h b/services/call/call_state_observer/include/call_records_manager.h index cc93f92b..c2fd7aed 100644 --- a/services/call/call_state_observer/include/call_records_manager.h +++ b/services/call/call_state_observer/include/call_records_manager.h @@ -70,7 +70,6 @@ public: void CallStateUpdated(sptr &callObjectPtr, TelCallState priorState, TelCallState nextState) override; void AddOneCallRecord(CallAttributeInfo &info); void CopyCallInfoToRecord(CallAttributeInfo &info, CallRecordInfo &data); - void AddOneCallRecord(sptr call, CallAnswerType answerType); int32_t RemoveMissedIncomingCallNotification(); int32_t GetCallFeatures(int32_t videoState); bool IsVideoCall(int32_t videoState); diff --git a/services/call/call_state_observer/src/call_records_manager.cpp b/services/call/call_state_observer/src/call_records_manager.cpp index 34168fb4..0899e1f2 100644 --- a/services/call/call_state_observer/src/call_records_manager.cpp +++ b/services/call/call_state_observer/src/call_records_manager.cpp @@ -125,6 +125,9 @@ void CallRecordsManager::CallStateUpdated( } (void)memset_s(&info, sizeof(CallAttributeInfo), 0, sizeof(CallAttributeInfo)); callObjectPtr->GetCallAttributeBaseInfo(info); + if (info.callType == CallType::TYPE_BLUETOOTH && callObjectPtr->GetBtCallSlotId() == BT_CALL_INVALID_SLOT) { + info.accountId = BT_CALL_INVALID_SLOT; + } ContactInfo contactInfo = callObjectPtr->GetCallerInfo(); if (contactInfo.name.empty() && !info.name.empty()) { info.namePresentation = 1; @@ -149,18 +152,6 @@ void CallRecordsManager::CallStateUpdated( AddOneCallRecord(info); } -void CallRecordsManager::AddOneCallRecord(sptr call, CallAnswerType answerType) -{ - CallAttributeInfo info; - (void)memset_s(&info, sizeof(CallAttributeInfo), 0, sizeof(CallAttributeInfo)); - call->GetCallAttributeBaseInfo(info); - if (info.numberMarkInfo.markType == MarkType::MARK_TYPE_DEFAULT) { - TELEPHONY_LOGI("markType is default."); - info.numberMarkInfo.markType = MarkType::MARK_TYPE_NONE; - } - AddOneCallRecord(info); -} - void CallRecordsManager::AddOneCallRecord(CallAttributeInfo &info) { CallRecordInfo data; diff --git a/services/call/include/call_base.h b/services/call/include/call_base.h index 4dfcfe19..b6636c22 100644 --- a/services/call/include/call_base.h +++ b/services/call/include/call_base.h @@ -154,6 +154,8 @@ public: void SetIsAnsweredByPhone(bool isAnsweredByPhone); void SetNewCallUseBox(int32_t newCallUseBox); int32_t GetNewCallUseBox(); + int32_t GetBtCallSlotId(); + void SetBtCallSlotId(int32_t slotId); protected: int32_t callId_; @@ -210,6 +212,7 @@ private: bool isForcedReportVoiceCall_{false}; bool isAnsweredByPhone_{false}; int32_t newCallUseBox_ = 0; + int32_t btCallSlotId_{BT_CALL_INVALID_SLOT}; }; } // namespace Telephony } // namespace OHOS diff --git a/services/call/src/call_base.cpp b/services/call/src/call_base.cpp index abe949ea..4af80b87 100644 --- a/services/call/src/call_base.cpp +++ b/services/call/src/call_base.cpp @@ -764,5 +764,17 @@ int32_t CallBase::GetNewCallUseBox() { return newCallUseBox_; } + +int32_t CallBase::GetBtCallSlotId() +{ + std::lock_guard lock(mutex_); + return btCallSlotId_; +} + +void CallBase::SetBtCallSlotId(int32_t slotId) +{ + std::lock_guard lock(mutex_); + btCallSlotId_ = slotId; +} } // namespace Telephony } // namespace OHOS diff --git a/services/call_report/include/call_ability_report_proxy.h b/services/call_report/include/call_ability_report_proxy.h index 4f0366bc..9a70d796 100644 --- a/services/call_report/include/call_ability_report_proxy.h +++ b/services/call_report/include/call_ability_report_proxy.h @@ -55,6 +55,7 @@ public: private: int32_t ReportCallEvent(const CallEventInfo &info); + void UpdateBtCallSlotId(CallAttributeInfo &newInfo); private: std::list> callbackPtrList_; diff --git a/services/call_report/src/call_ability_report_proxy.cpp b/services/call_report/src/call_ability_report_proxy.cpp index 0031d43a..66c19cba 100644 --- a/services/call_report/src/call_ability_report_proxy.cpp +++ b/services/call_report/src/call_ability_report_proxy.cpp @@ -26,6 +26,8 @@ #include "system_ability.h" #include "system_ability_definition.h" #include "telephony_log_wrapper.h" +#include "call_object_manager.h" +#include "interoperable_communication_manager.h" namespace OHOS { namespace Telephony { @@ -168,12 +170,14 @@ int32_t CallAbilityReportProxy::ReportCallStateInfo(const CallAttributeInfo &inf { int32_t ret = TELEPHONY_ERR_FAIL; std::string bundleInfo = ""; + CallAttributeInfo newInfo = info; + UpdateBtCallSlotId(newInfo); std::lock_guard lock(mutex_); std::list>::iterator it = callbackPtrList_.begin(); for (; it != callbackPtrList_.end(); ++it) { if ((*it)) { bundleInfo = (*it)->GetBundleInfo(); - ret = (*it)->OnCallDetailsChange(info); + ret = (*it)->OnCallDetailsChange(newInfo); if (ret != TELEPHONY_SUCCESS) { TELEPHONY_LOGD( "OnCallDetailsChange failed, errcode:%{public}d, bundleInfo:%{public}s", ret, bundleInfo.c_str()); @@ -466,5 +470,20 @@ int32_t CallAbilityReportProxy::ReportPhoneStateChange(int32_t numActive, int32_ TELEPHONY_LOGI("ReportPhoneStateChange success"); return ret; } + +void CallAbilityReportProxy::UpdateBtCallSlotId(CallAttributeInfo &info) +{ + auto callPtr = CallObjectManager::GetOneCallObject(info.callId); + if (callPtr == nullptr || callPtr->GetCallType() != CallType::TYPE_BLUETOOTH) { + return; + } + if (callPtr->GetBtCallSlotId() == BT_CALL_INVALID_SLOT && + !DelayedSingleton::GetInstance()->IsSlotIdVisible()) { + info.accountId = BT_CALL_INVALID_SLOT; + } else { + callPtr->SetBtCallSlotId(callPtr->GetAccountId()); + } +} + } // namespace Telephony } // namespace OHOS diff --git a/services/interoperable_call/include/interoperable_client_manager.h b/services/interoperable_call/include/interoperable_client_manager.h index a31a01b7..42e1a7ca 100644 --- a/services/interoperable_call/include/interoperable_client_manager.h +++ b/services/interoperable_call/include/interoperable_client_manager.h @@ -28,7 +28,7 @@ public: InteroperableClientManager() = default; ~InteroperableClientManager() override = default; void OnDeviceOnline(const std::string &networkId, const std::string &devName, uint16_t devType) override {} - void OnDeviceOffline(const std::string &networkId, const std::string &devName, uint16_t devType) override {} + void OnDeviceOffline(const std::string &networkId, const std::string &devName, uint16_t devType) override; void OnConnected() override; void OnCallCreated(const sptr &call, const std::string &networkId) override; void OnCallDestroyed() override; diff --git a/services/interoperable_call/include/interoperable_communication_manager.h b/services/interoperable_call/include/interoperable_communication_manager.h index f2abcae9..f9491da0 100644 --- a/services/interoperable_call/include/interoperable_communication_manager.h +++ b/services/interoperable_call/include/interoperable_communication_manager.h @@ -42,6 +42,7 @@ public: void NewCallCreated(sptr &call) override; void CallDestroyed(const DisconnectedDetails &details) override {} int32_t GetBtCallSlotId(const std::string &phoneNum); + bool IsSlotIdVisible(); private: ffrt::mutex mutex_{}; diff --git a/services/interoperable_call/include/interoperable_data_controller.h b/services/interoperable_call/include/interoperable_data_controller.h index 409a78cb..372c7435 100644 --- a/services/interoperable_call/include/interoperable_data_controller.h +++ b/services/interoperable_call/include/interoperable_data_controller.h @@ -52,7 +52,9 @@ public: void DeleteBtSlotIdByPhoneNumber(const std::string &phoneNum); void WaitForBtSlotId(const std::string &phoneNum); int32_t GetBtSlotIdByPhoneNumber(const std::string &phoneNum); - + bool IsSlotIdVisible(); + void SetIsSlotIdVisible(bool isVisible); + virtual void OnCallCreated(const sptr &call, const std::string &networkId) = 0; virtual void OnCallDestroyed() = 0; virtual void HandleSpecificMsg(int32_t msgType, const cJSON *msg) = 0; @@ -65,8 +67,10 @@ protected: std::string CreateQueryRequisitesDataMsg(InteroperableMsgType msgType, const std::string &phoneNum); void ClearBtSlotId(); +protected: std::shared_ptr session_{nullptr}; - + std::atomic isSlotIdVisible_{false}; + private: void HandleMuted(const cJSON *msg); void HandleMuteRinger(); diff --git a/services/interoperable_call/src/interoperable_client_manager.cpp b/services/interoperable_call/src/interoperable_client_manager.cpp index 792d07f4..698250bb 100644 --- a/services/interoperable_call/src/interoperable_client_manager.cpp +++ b/services/interoperable_call/src/interoperable_client_manager.cpp @@ -86,5 +86,12 @@ void InteroperableClientManager::CallCreated(const sptr &call, const s SendRequisiteDataQueryToPeer(call->GetAccountNumber()); // multi-call } } + +void InteroperableClientManager::OnDeviceOffline(const std::string &networkId, + const std::string &devName, uint16_t devType) +{ + TELEPHONY_LOGI("client offline, set false"); + SetIsSlotIdVisible(false); +} } // namespace Telephony } // namespace OHOS \ No newline at end of file diff --git a/services/interoperable_call/src/interoperable_communication_manager.cpp b/services/interoperable_call/src/interoperable_communication_manager.cpp index f358d6ba..09fe03ab 100644 --- a/services/interoperable_call/src/interoperable_communication_manager.cpp +++ b/services/interoperable_call/src/interoperable_communication_manager.cpp @@ -174,5 +174,15 @@ int32_t InteroperableCommunicationManager::GetBtCallSlotId(const std::string &ph dataController_->DeleteBtSlotIdByPhoneNumber(phoneNum); // delete after query return btCallSlot; } + +bool InteroperableCommunicationManager::IsSlotIdVisible() +{ + std::lock_guard lock(mutex_); + if (dataController_ == nullptr) { + TELEPHONY_LOGE("dataController is nullptr"); + return false; + } + return dataController_->IsSlotIdVisible(); +} } } diff --git a/services/interoperable_call/src/interoperable_data_controller.cpp b/services/interoperable_call/src/interoperable_data_controller.cpp index f9462ab8..a681acf6 100644 --- a/services/interoperable_call/src/interoperable_data_controller.cpp +++ b/services/interoperable_call/src/interoperable_data_controller.cpp @@ -225,6 +225,8 @@ void InteroperableDataController::HandleRequisitesData(const cJSON *msg) slotIdCv_.notify_all(); return; } + TELEPHONY_LOGI("recv slotId, set true"); + SetIsSlotIdVisible(true); CallAttributeInfo info; callPtr->SetAccountId(slotId); callPtr->GetCallAttributeBaseInfo(info); @@ -329,5 +331,19 @@ int32_t InteroperableDataController::GetBtSlotIdByPhoneNumber(const std::string } return BT_CALL_INVALID_SLOT; } + +bool InteroperableDataController::IsSlotIdVisible() +{ + if (session_ == nullptr || !session_->IsReady()) { + TELEPHONY_LOGE("session invalid"); + return false; + } + return isSlotIdVisible_.load(); +} + +void InteroperableDataController::SetIsSlotIdVisible(bool isVisible) +{ + isSlotIdVisible_.store(isVisible); +} } } \ No newline at end of file diff --git a/test/unittest/call_manager_zero_gtest/src/zero_branch6_test.cpp b/test/unittest/call_manager_zero_gtest/src/zero_branch6_test.cpp index c8847798..1125fc6a 100644 --- a/test/unittest/call_manager_zero_gtest/src/zero_branch6_test.cpp +++ b/test/unittest/call_manager_zero_gtest/src/zero_branch6_test.cpp @@ -550,6 +550,32 @@ HWTEST_F(ZeroBranch5Test, Telephony_CallAbilityReportProxy_003, TestSize.Level0) EXPECT_EQ(callAbilityReportProxy->ReportMeeTimeStateInfo(callAttributeInfo), TELEPHONY_ERR_FAIL); } +/** + * @tc.number Telephony_CallAbilityReportProxy_004 + * @tc.name test update bt call slotId + * @tc.desc Function test + */ +HWTEST_F(ZeroBranch5Test, Telephony_CallAbilityReportProxy_004, TestSize.Level0) +{ + std::shared_ptr callAbilityReportProxy = std::make_shared(); + CallAttributeInfo info; + info.callId = -1; + callAbilityReportProxy->UpdateBtCallSlotId(info); + + DialParaInfo dialParaInfo; + dialParaInfo.callType = CallType::TYPE_IMS; + dialParaInfo.callId = 1; + sptr call = new IMSCall(dialParaInfo); + info.callId = 1; + call->SetBtCallSlotId(BT_CALL_INVALID_SLOT); + auto tempSize = CallObjectManager::callObjectPtrList_.size(); + CallObjectManager::callObjectPtrList_.push_back(call); + callAbilityReportProxy->UpdateBtCallSlotId(info); + call->SetBtCallSlotId(BT_CALL_INVALID_SLOT + 1); + callAbilityReportProxy->UpdateBtCallSlotId(info); + EXPECT_EQ(tempSize + 1, CallObjectManager::callObjectPtrList_.size()); +} + /** * @tc.number Telephony_CallAbilityConnectCallback_001 * @tc.name test error branch diff --git a/test/unittest/distributed_communication_test/src/interoperable_communication_manager_test.cpp b/test/unittest/distributed_communication_test/src/interoperable_communication_manager_test.cpp index a3ce1f2c..9d66b5b2 100644 --- a/test/unittest/distributed_communication_test/src/interoperable_communication_manager_test.cpp +++ b/test/unittest/distributed_communication_test/src/interoperable_communication_manager_test.cpp @@ -121,5 +121,21 @@ HWTEST_F(InteroperableCommunicationManagerTest, EXPECT_NO_THROW(dcManager->NewCallCreated(call)); dcManager->peerDevices_.clear(); } + +/** + * @tc.number Telephony_InteroperableCommunicationManagerTest_004 + * @tc.name test dc manager is slot id visible + * @tc.desc Function test + */ +HWTEST_F(InteroperableCommunicationManagerTest, + Telephony_InteroperableCommunicationManagerTest_004, Function | MediumTest | Level1) +{ + auto dcManager = DelayedSingleton::GetInstance(); + dcManager->dataController_ = nullptr; + EXPECT_FALSE(dcManager->IsSlotIdVisible()); + dcManager->dataController_ = std::make_shared(); + dcManager->dataController_->session_ = nullptr; + EXPECT_FALSE(dcManager->IsSlotIdVisible()); +} } // namespace Telephony } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/distributed_communication_test/src/interoperable_data_controller_test.cpp b/test/unittest/distributed_communication_test/src/interoperable_data_controller_test.cpp index b80f1713..b21a0488 100644 --- a/test/unittest/distributed_communication_test/src/interoperable_data_controller_test.cpp +++ b/test/unittest/distributed_communication_test/src/interoperable_data_controller_test.cpp @@ -150,5 +150,24 @@ Function | MediumTest | Level1) CallObjectManager::callObjectPtrList_.clear(); cJSON_Delete(msg); } + +/** + * @tc.number Telephony_InteroperableDataControllerTest_005 + * @tc.name test data controller is slot id visible + * @tc.desc Function test + */ +HWTEST_F(InteroperableClientManagerTest, Telephony_InteroperableDataControllerTest_005, +Function | MediumTest | Level1) +{ + std::shared_ptr dataController = std::make_shared(); + std::shared_ptr callback = std::make_shared(); + auto session = std::make_shared(callback); + EXPECT_NO_THROW(dataController->SetIsSlotIdVisible(true)); + dataController->session_ = session; + dataController->session_->socket_ = INVALID_SOCKET_ID; + EXPECT_FALSE(dataController->IsSlotIdVisible()); + dataController->session_->socket_ = INVALID_SOCKET_ID + 1; + EXPECT_TRUE(dataController->IsSlotIdVisible()); +} } // namespace Telephony } // namespace OHOS \ No newline at end of file -- Gitee