• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2023 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 "report_call_info_handler.h"
17 
18 #include "call_manager_errors.h"
19 #include "call_manager_hisysevent.h"
20 #include "ims_call.h"
21 #include "telephony_log_wrapper.h"
22 #include "thread"
23 
24 namespace OHOS {
25 namespace Telephony {
26 
ReportCallInfoHandler()27 ReportCallInfoHandler::ReportCallInfoHandler() {}
28 
~ReportCallInfoHandler()29 ReportCallInfoHandler::~ReportCallInfoHandler() {}
30 
Init()31 void ReportCallInfoHandler::Init()
32 {
33     callStatusManagerPtr_ = std::make_shared<CallStatusManager>();
34     callStatusManagerPtr_->Init();
35     return;
36 }
37 
UpdateCallReportInfo(const CallDetailInfo & info)38 int32_t ReportCallInfoHandler::UpdateCallReportInfo(const CallDetailInfo &info)
39 {
40     if (callStatusManagerPtr_ == nullptr) {
41         TELEPHONY_LOGE("callStatusManagerPtr_ is null");
42         return TELEPHONY_ERR_LOCAL_PTR_NULL;
43     }
44     CallDetailInfo callDetailInfo = info;
45     std::weak_ptr<CallStatusManager> callStatusManagerPtr = callStatusManagerPtr_;
46     Submit("UpdateCallReportInfo", [callStatusManagerPtr, callDetailInfo]() {
47         std::shared_ptr<CallStatusManager> managerPtr = callStatusManagerPtr.lock();
48         if (managerPtr == nullptr) {
49             TELEPHONY_LOGE("managerPtr is null");
50             return;
51         }
52         auto ret = managerPtr->HandleCallReportInfo(callDetailInfo);
53         if (ret != TELEPHONY_SUCCESS) {
54             TELEPHONY_LOGE("HandleCallReportInfo failed! ret:%{public}d", ret);
55         }
56     });
57     return TELEPHONY_SUCCESS;
58 }
59 
BuildCallDetailsInfo(CallDetailsInfo & info,CallDetailsInfo & callDetailsInfo)60 void ReportCallInfoHandler::BuildCallDetailsInfo(CallDetailsInfo &info, CallDetailsInfo &callDetailsInfo)
61 {
62     CallDetailInfo callDetailInfo;
63     std::vector<CallDetailInfo>::iterator iter = info.callVec.begin();
64     for (; iter != info.callVec.end(); ++iter) {
65         callDetailInfo.callType = (*iter).callType;
66         callDetailInfo.accountId = (*iter).accountId;
67         callDetailInfo.state = (*iter).state;
68         callDetailInfo.callMode = (*iter).callMode;
69         callDetailInfo.index = (*iter).index;
70         callDetailInfo.voiceDomain = (*iter).voiceDomain;
71         callDetailInfo.mpty = (*iter).mpty;
72         callDetailInfo.crsType = (*iter).crsType;
73         callDetailInfo.originalCallType = (*iter).originalCallType;
74         (void)memcpy_s(callDetailInfo.phoneNum, kMaxNumberLen, (*iter).phoneNum, kMaxNumberLen);
75         (void)memcpy_s(callDetailInfo.bundleName, kMaxBundleNameLen, (*iter).bundleName, kMaxBundleNameLen);
76         callDetailsInfo.callVec.push_back(callDetailInfo);
77     }
78 }
79 
UpdateCallsReportInfo(CallDetailsInfo & info)80 int32_t ReportCallInfoHandler::UpdateCallsReportInfo(CallDetailsInfo &info)
81 {
82     if (callStatusManagerPtr_ == nullptr) {
83         TELEPHONY_LOGE("callStatusManagerPtr_ is null");
84         return TELEPHONY_ERR_LOCAL_PTR_NULL;
85     }
86     CallDetailsInfo callDetailsInfo;
87     callDetailsInfo.slotId = info.slotId;
88     (void)memcpy_s(callDetailsInfo.bundleName, kMaxBundleNameLen, info.bundleName, kMaxBundleNameLen);
89     BuildCallDetailsInfo(info, callDetailsInfo);
90     std::weak_ptr<CallStatusManager> callStatusManagerPtr = callStatusManagerPtr_;
91     Submit("UpdateCallsReportInfo", [callStatusManagerPtr, callDetailsInfo]() {
92         std::shared_ptr<CallStatusManager> managerPtr = callStatusManagerPtr.lock();
93         if (managerPtr == nullptr) {
94             TELEPHONY_LOGE("managerPtr is null");
95             return;
96         }
97         int32_t ret = managerPtr->HandleCallsReportInfo(callDetailsInfo);
98         if (ret != TELEPHONY_SUCCESS) {
99             TELEPHONY_LOGE("HandleCallsReportInfo failed! ret:%{public}d", ret);
100         }
101     });
102 
103     CallDetailInfo detailInfo;
104     detailInfo.state = TelCallState::CALL_STATUS_UNKNOWN;
105     std::vector<CallDetailInfo>::iterator it = info.callVec.begin();
106     for (; it != info.callVec.end(); ++it) {
107         detailInfo.callType = (*it).callType;
108         detailInfo.accountId = (*it).accountId;
109         detailInfo.state = (*it).state;
110         detailInfo.callMode = (*it).callMode;
111     }
112     if (detailInfo.state == TelCallState::CALL_STATUS_INCOMING) {
113         CallManagerHisysevent::WriteIncomingCallFaultEvent(info.slotId, static_cast<int32_t>(detailInfo.callType),
114             static_cast<int32_t>(detailInfo.callMode), CALL_ERR_SYSTEM_EVENT_HANDLE_FAILURE,
115             "ID HANDLER_UPDATE_CALL_INFO_LIST");
116     }
117     return TELEPHONY_SUCCESS;
118 }
119 
UpdateDisconnectedCause(const DisconnectedDetails & details)120 int32_t ReportCallInfoHandler::UpdateDisconnectedCause(const DisconnectedDetails &details)
121 {
122     if (callStatusManagerPtr_ == nullptr) {
123         TELEPHONY_LOGE("callStatusManagerPtr_ is null");
124         return TELEPHONY_ERR_LOCAL_PTR_NULL;
125     }
126     DisconnectedDetails disconnectedDetails = details;
127     std::weak_ptr<CallStatusManager> callStatusManagerPtr = callStatusManagerPtr_;
128     Submit("UpdateDisconnectedCause", [callStatusManagerPtr, disconnectedDetails]() {
129         std::shared_ptr<CallStatusManager> managerPtr = callStatusManagerPtr.lock();
130         if (managerPtr == nullptr) {
131             TELEPHONY_LOGE("managerPtr is null");
132             return;
133         }
134         int32_t ret = managerPtr->HandleDisconnectedCause(disconnectedDetails);
135         if (ret != TELEPHONY_SUCCESS) {
136             TELEPHONY_LOGE("HandleDisconnectedCause failed! ret:%{public}d", ret);
137         }
138     });
139 
140     return TELEPHONY_SUCCESS;
141 }
142 
UpdateEventResultInfo(const CellularCallEventInfo & info)143 int32_t ReportCallInfoHandler::UpdateEventResultInfo(const CellularCallEventInfo &info)
144 {
145     if (callStatusManagerPtr_ == nullptr) {
146         TELEPHONY_LOGE("callStatusManagerPtr_ is null");
147         return TELEPHONY_ERR_LOCAL_PTR_NULL;
148     }
149     std::weak_ptr<CallStatusManager> callStatusManagerPtr = callStatusManagerPtr_;
150     Submit("UpdateEventResultInfo", [callStatusManagerPtr, info]() {
151         std::shared_ptr<CallStatusManager> managerPtr = callStatusManagerPtr.lock();
152         if (managerPtr == nullptr) {
153             TELEPHONY_LOGE("managerPtr is null");
154             return;
155         }
156         int32_t ret = managerPtr->HandleEventResultReportInfo(info);
157         if (ret != TELEPHONY_SUCCESS) {
158             TELEPHONY_LOGE("HandleEventResultReportInfo failed! ret:%{public}d", ret);
159         }
160     });
161 
162     return TELEPHONY_SUCCESS;
163 }
164 
UpdateOttEventInfo(const OttCallEventInfo & info)165 int32_t ReportCallInfoHandler::UpdateOttEventInfo(const OttCallEventInfo &info)
166 {
167     if (callStatusManagerPtr_ == nullptr) {
168         TELEPHONY_LOGE("callStatusManagerPtr_ is null");
169         return TELEPHONY_ERR_LOCAL_PTR_NULL;
170     }
171     OttCallEventInfo ottCallEventInfo = info;
172     std::weak_ptr<CallStatusManager> callStatusManagerPtr = callStatusManagerPtr_;
173     Submit("UpdateOttEventInfo", [callStatusManagerPtr, ottCallEventInfo]() {
174         std::shared_ptr<CallStatusManager> managerPtr = callStatusManagerPtr.lock();
175         if (managerPtr == nullptr) {
176             TELEPHONY_LOGE("managerPtr is null");
177             return;
178         }
179         int32_t ret = managerPtr->HandleOttEventReportInfo(ottCallEventInfo);
180         if (ret != TELEPHONY_SUCCESS) {
181             TELEPHONY_LOGE("HandleOttEventReportInfo failed! ret:%{public}d", ret);
182         }
183     });
184 
185     return TELEPHONY_SUCCESS;
186 }
187 
ReceiveImsCallModeRequest(const CallModeReportInfo & response)188 int32_t ReportCallInfoHandler::ReceiveImsCallModeRequest(const CallModeReportInfo &response)
189 {
190     Submit("ReceiveImsCallModeRequest", [response]() {
191         CallModeReportInfo reportInfo = response;
192         sptr<CallBase> call = CallObjectManager::GetOneCallObjectByIndex(response.callIndex);
193         if (call == nullptr) {
194             TELEPHONY_LOGE("call not exists");
195             return;
196         }
197         if (call->GetCallType() == CallType::TYPE_IMS) {
198             sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
199             imsCall->RecieveUpdateCallMediaModeRequest(reportInfo);
200         }
201     });
202     return TELEPHONY_SUCCESS;
203 }
204 
ReceiveImsCallModeResponse(const CallModeReportInfo & response)205 int32_t ReportCallInfoHandler::ReceiveImsCallModeResponse(const CallModeReportInfo &response)
206 {
207     Submit("ReceiveImsCallModeResponse", [response]() {
208         CallModeReportInfo reportInfo = response;
209         sptr<CallBase> call = CallObjectManager::GetOneCallObjectByIndex(response.callIndex);
210         if (call == nullptr) {
211             TELEPHONY_LOGE("call not exists");
212             return;
213         }
214         if (call->GetCallType() == CallType::TYPE_IMS) {
215             sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
216             imsCall->ReceiveUpdateCallMediaModeResponse(reportInfo);
217         }
218     });
219     return TELEPHONY_SUCCESS;
220 }
221 
222 template<typename Function>
Submit(const std::string & taskName,Function && func)223 void ReportCallInfoHandler::Submit(const std::string &taskName, Function &&func)
224 {
225     TELEPHONY_LOGI("Submit task : %{public}s", taskName.c_str());
226     std::thread t([this, taskName = std::string(taskName), func = std::move(func)]() {
227         TELEPHONY_LOGI("Submit task enter: %{public}s", taskName.c_str());
228         std::lock_guard<std::mutex> lock(mtx);
229         func();
230         TELEPHONY_LOGI("Submit task end: %{public}s", taskName.c_str());
231     });
232     pthread_setname_np(t.native_handle(), taskName.c_str());
233     t.detach();
234 }
235 
236 } // namespace Telephony
237 } // namespace OHOS
238