1 /*
2 * Copyright (C) 2025-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "interoperable_server_manager.h"
17 #include "interoperable_device_observer.h"
18 #include "telephony_log_wrapper.h"
19 #include "transmission_manager.h"
20 #include "call_object_manager.h"
21 #include "call_control_manager.h"
22
23 namespace OHOS {
24 namespace Telephony {
25 constexpr const char* SOFTNET_SESSION_NAME = "ohos.telephony.callmanager.interoperable_communication";
26
OnDeviceOnline(const std::string & networkId,const std::string & devName,uint16_t devType)27 void InteroperableServerManager::OnDeviceOnline(const std::string &networkId, const std::string &devName,
28 uint16_t devType)
29 {
30 TELEPHONY_LOGI("server session manager OnDeviceOnline");
31 if (session_ != nullptr) {
32 return;
33 }
34 auto transMgr = DelayedSingleton<TransmissionManager>::GetInstance();
35 session_ = transMgr->CreateServerSession(shared_from_this());
36 if (session_ != nullptr) {
37 session_->Create(SOFTNET_SESSION_NAME, QOS_BW_BT);
38 }
39 }
40
OnDeviceOffline(const std::string & networkId,const std::string & devName,uint16_t devType)41 void InteroperableServerManager::OnDeviceOffline(const std::string &networkId, const std::string &devName,
42 uint16_t devType)
43 {
44 TELEPHONY_LOGI("server session manager OnDeviceOffline");
45 if (session_ == nullptr) {
46 return;
47 }
48 session_->Destroy();
49 session_.reset();
50 session_ = nullptr;
51 }
52
HandleSpecificMsg(int32_t msgType,const cJSON * msg)53 void InteroperableServerManager::HandleSpecificMsg(int32_t msgType, const cJSON *msg)
54 {
55 if (msg == nullptr) {
56 return;
57 }
58 switch (msgType) {
59 case static_cast<int32_t>(InteroperableMsgType::DATA_TYPE_QUERY_REQUISITES_DATA):
60 OnQueryRequisitesDataMsgReceived(msg);
61 break;
62 default:
63 break;
64 }
65 }
66
OnQueryRequisitesDataMsgReceived(const cJSON * msg)67 void InteroperableServerManager::OnQueryRequisitesDataMsgReceived(const cJSON *msg)
68 {
69 std::string phoneNum = "";
70 sptr<CallBase> callPtr = nullptr;
71 if (!GetStringValue(msg, INTEROPERABLE_ITEM_PHONE_NUMBER, phoneNum)) {
72 TELEPHONY_LOGE("bt call remote query dara, parse data failed");
73 return;
74 }
75
76 callPtr = CallObjectManager::GetOneCallObject(phoneNum);
77 if (callPtr == nullptr) {
78 TELEPHONY_LOGE("query call failed!");
79 return;
80 }
81 SendRequisiteDataToPeer(callPtr->GetAccountId(), callPtr->GetAccountNumber());
82 }
83
OnCallDestroyed()84 void InteroperableServerManager::OnCallDestroyed()
85 {
86 ClearBtSlotId();
87 }
88
CallCreated(const sptr<CallBase> & call,const std::string & networkId)89 void InteroperableServerManager::CallCreated(const sptr<CallBase> &call, const std::string &networkId)
90 {
91 TELEPHONY_LOGI("server manager call create");
92 if (call != nullptr) {
93 SendRequisiteDataToPeer(call->GetAccountId(), call->GetAccountNumber());
94 }
95 }
96 }
97 }