• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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 
23 namespace OHOS {
24 namespace Telephony {
ReportCallInfoHandler(const std::shared_ptr<AppExecFwk::EventRunner> & runner)25 ReportCallInfoHandler::ReportCallInfoHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner)
26     : AppExecFwk::EventHandler(runner)
27 {
28     memberFuncMap_[ReportCallInfoHandlerService::HANDLER_UPDATE_CELLULAR_CALL_INFO] =
29         &ReportCallInfoHandler::ReportCallInfo;
30     memberFuncMap_[ReportCallInfoHandlerService::HANDLER_UPDATE_CALL_INFO_LIST] =
31         &ReportCallInfoHandler::ReportCallsInfo;
32     memberFuncMap_[ReportCallInfoHandlerService::HANDLER_UPDATE_DISCONNECTED_CAUSE] =
33         &ReportCallInfoHandler::ReportDisconnectedCause;
34     memberFuncMap_[ReportCallInfoHandlerService::HANDLER_UPDATE_CELLULAR_EVENT_RESULT_INFO] =
35         &ReportCallInfoHandler::ReportEventInfo;
36     memberFuncMap_[ReportCallInfoHandlerService::HANDLER_UPDATE_OTT_EVENT_RESULT_INFO] =
37         &ReportCallInfoHandler::ReportOttEvent;
38     memberFuncMap_[ReportCallInfoHandlerService::HANDLE_UPDATE_MEDIA_MODE_RESPONSE] =
39         &ReportCallInfoHandler::OnUpdateMediaModeResponse;
40 }
41 
~ReportCallInfoHandler()42 ReportCallInfoHandler::~ReportCallInfoHandler()
43 {
44     if (callStatusManagerPtr_) {
45         callStatusManagerPtr_ = nullptr;
46     }
47 }
48 
Init()49 void ReportCallInfoHandler::Init()
50 {
51     callStatusManagerPtr_ = std::make_unique<CallStatusManager>();
52     if (callStatusManagerPtr_ == nullptr) {
53         TELEPHONY_LOGE("callStatusManagerPtr_ is null");
54         return;
55     }
56     callStatusManagerPtr_->Init();
57 }
58 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)59 void ReportCallInfoHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
60 {
61     if (event == nullptr) {
62         TELEPHONY_LOGE("ReportCallInfoHandler::ProcessEvent parameter error");
63         return;
64     }
65     TELEPHONY_LOGI("ReportCallInfoHandler::ProcessEvent inner event id: %{public}u.", event->GetInnerEventId());
66     auto itFunc = memberFuncMap_.find(event->GetInnerEventId());
67     if (itFunc != memberFuncMap_.end()) {
68         auto memberFunc = itFunc->second;
69         if (memberFunc != nullptr) {
70             return (this->*memberFunc)(event);
71         }
72     }
73 }
74 
ReportCallInfo(const AppExecFwk::InnerEvent::Pointer & event)75 void ReportCallInfoHandler::ReportCallInfo(const AppExecFwk::InnerEvent::Pointer &event)
76 {
77     auto object = event->GetUniqueObject<CallDetailInfo>();
78     if (object == nullptr) {
79         TELEPHONY_LOGE("object is nullptr!");
80         return;
81     }
82     CallDetailInfo info = *object;
83     if (callStatusManagerPtr_ == nullptr) {
84         TELEPHONY_LOGE("callStatusManagerPtr_ is nullptr");
85         return;
86     }
87     int32_t ret = callStatusManagerPtr_->HandleCallReportInfo(info);
88     if (ret != TELEPHONY_SUCCESS) {
89         TELEPHONY_LOGE("HandleCallReportInfo failed! ret:%{public}d", ret);
90         return;
91     }
92     TELEPHONY_LOGI("HandleCallReportInfo success!");
93 }
94 
ReportCallsInfo(const AppExecFwk::InnerEvent::Pointer & event)95 void ReportCallInfoHandler::ReportCallsInfo(const AppExecFwk::InnerEvent::Pointer &event)
96 {
97     auto object = event->GetUniqueObject<CallDetailsInfo>();
98     if (object == nullptr) {
99         TELEPHONY_LOGE("object is nullptr!");
100         return;
101     }
102     CallDetailsInfo info = *object;
103     if (callStatusManagerPtr_ == nullptr) {
104         TELEPHONY_LOGE("callStatusManagerPtr_ is nullptr");
105         return;
106     }
107     int32_t ret = callStatusManagerPtr_->HandleCallsReportInfo(info);
108     if (ret != TELEPHONY_SUCCESS) {
109         TELEPHONY_LOGE("HandleCallsReportInfo failed! ret:%{public}d", ret);
110         return;
111     }
112     TELEPHONY_LOGI("HandleCallsReportInfo success!");
113 }
114 
ReportDisconnectedCause(const AppExecFwk::InnerEvent::Pointer & event)115 void ReportCallInfoHandler::ReportDisconnectedCause(const AppExecFwk::InnerEvent::Pointer &event)
116 {
117     auto object = event->GetUniqueObject<DisconnectedDetails>();
118     if (object == nullptr) {
119         TELEPHONY_LOGE("object is nullptr!");
120         return;
121     }
122     if (callStatusManagerPtr_ == nullptr) {
123         TELEPHONY_LOGE("callStatusManagerPtr_ is nullptr");
124         return;
125     }
126 
127     int32_t ret = callStatusManagerPtr_->HandleDisconnectedCause(*object);
128     if (ret != TELEPHONY_SUCCESS) {
129         TELEPHONY_LOGE("HandleDisconnectedCause failed! ret:%{public}d", ret);
130         return;
131     }
132     TELEPHONY_LOGI("HandleDisconnectedCause success!");
133 }
134 
ReportEventInfo(const AppExecFwk::InnerEvent::Pointer & event)135 void ReportCallInfoHandler::ReportEventInfo(const AppExecFwk::InnerEvent::Pointer &event)
136 {
137     auto object = event->GetUniqueObject<CellularCallEventInfo>();
138     if (object == nullptr) {
139         TELEPHONY_LOGE("object is nullptr!");
140         return;
141     }
142     CellularCallEventInfo info = *object;
143     if (callStatusManagerPtr_ == nullptr) {
144         TELEPHONY_LOGE("callStatusManagerPtr_ is nullptr");
145         return;
146     }
147     int32_t ret = callStatusManagerPtr_->HandleEventResultReportInfo(info);
148     if (ret != TELEPHONY_SUCCESS) {
149         TELEPHONY_LOGE("HandleEventResultReportInfo failed! ret:%{public}d", ret);
150         return;
151     }
152     TELEPHONY_LOGI("HandleEventResultReportInfo success!");
153 }
154 
ReportOttEvent(const AppExecFwk::InnerEvent::Pointer & event)155 void ReportCallInfoHandler::ReportOttEvent(const AppExecFwk::InnerEvent::Pointer &event)
156 {
157     auto object = event->GetUniqueObject<OttCallEventInfo>();
158     if (object == nullptr) {
159         TELEPHONY_LOGE("object is nullptr!");
160         return;
161     }
162     OttCallEventInfo info = *object;
163     if (callStatusManagerPtr_ == nullptr) {
164         TELEPHONY_LOGE("callStatusManagerPtr_ is nullptr");
165         return;
166     }
167     int32_t ret = callStatusManagerPtr_->HandleOttEventReportInfo(info);
168     if (ret != TELEPHONY_SUCCESS) {
169         TELEPHONY_LOGE("HandleOttEventReportInfo failed! ret:%{public}d", ret);
170         return;
171     }
172     TELEPHONY_LOGI("HandleOttEventReportInfo success!");
173 }
174 
OnUpdateMediaModeResponse(const AppExecFwk::InnerEvent::Pointer & event)175 void ReportCallInfoHandler::OnUpdateMediaModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
176 {
177     auto object = event->GetUniqueObject<CallMediaModeResponse>();
178     if (object == nullptr) {
179         TELEPHONY_LOGE("object is nullptr!");
180         return;
181     }
182 
183     sptr<CallBase> call = CallObjectManager::GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
184     if (call == nullptr) {
185         TELEPHONY_LOGE("call not exists");
186         return;
187     }
188     if (call->GetCallType() == CallType::TYPE_IMS) {
189         sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
190         imsCall->ReceiveUpdateCallMediaModeResponse(*object);
191     }
192     return;
193 }
194 
ReportCallInfoHandlerService()195 ReportCallInfoHandlerService::ReportCallInfoHandlerService() : eventLoop_(nullptr), handler_(nullptr) {}
196 
~ReportCallInfoHandlerService()197 ReportCallInfoHandlerService::~ReportCallInfoHandlerService()
198 {
199     if (eventLoop_ != nullptr) {
200         eventLoop_->Stop();
201         eventLoop_ = nullptr;
202     }
203     handler_ = nullptr;
204 }
205 
Start()206 void ReportCallInfoHandlerService::Start()
207 {
208     eventLoop_ = AppExecFwk::EventRunner::Create("ReportCallInfoHandlerService");
209     if (eventLoop_.get() == nullptr) {
210         TELEPHONY_LOGE("failed to create EventRunner");
211         return;
212     }
213     handler_ = std::make_shared<ReportCallInfoHandler>(eventLoop_);
214     if (handler_.get() == nullptr) {
215         TELEPHONY_LOGE("failed to create ReportCallInfoHandler");
216         return;
217     }
218     handler_->Init();
219     eventLoop_->Run();
220     return;
221 }
222 
UpdateCallReportInfo(const CallDetailInfo & info)223 int32_t ReportCallInfoHandlerService::UpdateCallReportInfo(const CallDetailInfo &info)
224 {
225     if (handler_.get() == nullptr) {
226         TELEPHONY_LOGE("handler_ is nullptr");
227         return TELEPHONY_ERR_LOCAL_PTR_NULL;
228     }
229     std::unique_ptr<CallDetailInfo> para = std::make_unique<CallDetailInfo>();
230     if (para.get() == nullptr) {
231         TELEPHONY_LOGE("make_unique CallDetailInfo failed!");
232         return TELEPHONY_ERR_LOCAL_PTR_NULL;
233     }
234     *para = info;
235     bool ret = handler_->SendEvent(HANDLER_UPDATE_CELLULAR_CALL_INFO, std::move(para));
236     if (!ret) {
237         TELEPHONY_LOGE("SendEvent failed! status update failed, state:%{public}d", info.state);
238     }
239     return TELEPHONY_SUCCESS;
240 }
241 
UpdateCallsReportInfo(CallDetailsInfo & info)242 int32_t ReportCallInfoHandlerService::UpdateCallsReportInfo(CallDetailsInfo &info)
243 {
244     if (handler_.get() == nullptr) {
245         TELEPHONY_LOGE("handler_ is nullptr");
246         return TELEPHONY_ERR_LOCAL_PTR_NULL;
247     }
248     std::unique_ptr<CallDetailsInfo> para = std::make_unique<CallDetailsInfo>();
249     if (para.get() == nullptr) {
250         TELEPHONY_LOGE("make_unique CallDetailsInfo failed!");
251         return TELEPHONY_ERR_LOCAL_PTR_NULL;
252     }
253     *para = info;
254     bool ret = handler_->SendEvent(HANDLER_UPDATE_CALL_INFO_LIST, std::move(para));
255     if (!ret) {
256         TELEPHONY_LOGE("SendEvent failed! status update failed, slotId:%{public}d", info.slotId);
257         CallDetailInfo detailInfo;
258         detailInfo.state = TelCallState::CALL_STATUS_UNKNOWN;
259         std::vector<CallDetailInfo>::iterator it = info.callVec.begin();
260         for (; it != info.callVec.end(); ++it) {
261             detailInfo.callType = (*it).callType;
262             detailInfo.accountId = (*it).accountId;
263             detailInfo.state = (*it).state;
264             detailInfo.callMode = (*it).callMode;
265         }
266         if (detailInfo.state == TelCallState::CALL_STATUS_INCOMING) {
267             CallManagerHisysevent::WriteIncomingCallFaultEvent(info.slotId, static_cast<int32_t>(detailInfo.callType),
268                 static_cast<int32_t>(detailInfo.callMode), CALL_ERR_SYSTEM_EVENT_HANDLE_FAILURE,
269                 "ID HANDLER_UPDATE_CALL_INFO_LIST");
270         }
271     }
272     return TELEPHONY_SUCCESS;
273 }
274 
UpdateDisconnectedCause(const DisconnectedDetails & details)275 int32_t ReportCallInfoHandlerService::UpdateDisconnectedCause(const DisconnectedDetails &details)
276 {
277     if (handler_.get() == nullptr) {
278         TELEPHONY_LOGE("handler_ is nullptr");
279         return TELEPHONY_ERR_LOCAL_PTR_NULL;
280     }
281     std::unique_ptr<DisconnectedDetails> para = std::make_unique<DisconnectedDetails>();
282     if (para.get() == nullptr) {
283         TELEPHONY_LOGE("make_unique int32_t failed!");
284         return TELEPHONY_ERR_LOCAL_PTR_NULL;
285     }
286     para->reason = details.reason;
287     if (details.message.empty()) {
288         para->message = "";
289     } else {
290         para->message = details.message;
291     }
292     bool ret = handler_->SendEvent(HANDLER_UPDATE_DISCONNECTED_CAUSE, std::move(para));
293     if (!ret) {
294         TELEPHONY_LOGE("SendEvent failed! DisconnectedDetails:%{public}d", details.reason);
295     }
296     return TELEPHONY_SUCCESS;
297 }
298 
UpdateEventResultInfo(const CellularCallEventInfo & info)299 int32_t ReportCallInfoHandlerService::UpdateEventResultInfo(const CellularCallEventInfo &info)
300 {
301     if (handler_.get() == nullptr) {
302         TELEPHONY_LOGE("handler_ is nullptr");
303         return TELEPHONY_ERR_LOCAL_PTR_NULL;
304     }
305     std::unique_ptr<CellularCallEventInfo> para = std::make_unique<CellularCallEventInfo>();
306     if (para.get() == nullptr) {
307         TELEPHONY_LOGE("make_unique CellularCallEventInfo failed!");
308         return TELEPHONY_ERR_LOCAL_PTR_NULL;
309     }
310     *para = info;
311     bool ret = handler_->SendEvent(HANDLER_UPDATE_CELLULAR_EVENT_RESULT_INFO, std::move(para));
312     if (!ret) {
313         TELEPHONY_LOGE("SendEvent failed! eventType:%{public}d, eventId:%{public}d", info.eventType, info.eventId);
314     }
315     return TELEPHONY_SUCCESS;
316 }
317 
UpdateOttEventInfo(const OttCallEventInfo & info)318 int32_t ReportCallInfoHandlerService::UpdateOttEventInfo(const OttCallEventInfo &info)
319 {
320     if (handler_.get() == nullptr) {
321         TELEPHONY_LOGE("handler_ is nullptr");
322         return TELEPHONY_ERR_LOCAL_PTR_NULL;
323     }
324     std::unique_ptr<OttCallEventInfo> para = std::make_unique<OttCallEventInfo>();
325     if (para.get() == nullptr) {
326         TELEPHONY_LOGE("make_unique OttCallEventInfo failed!");
327         return TELEPHONY_ERR_LOCAL_PTR_NULL;
328     }
329     if (memcpy_s(para->bundleName, kMaxBundleNameLen, 0, kMaxBundleNameLen) != EOK) {
330         TELEPHONY_LOGE("memcpy_s para->phoneNum failed!");
331         return TELEPHONY_ERR_MEMSET_FAIL;
332     }
333     para->ottCallEventId = info.ottCallEventId;
334     bool ret = handler_->SendEvent(HANDLER_UPDATE_OTT_EVENT_RESULT_INFO, std::move(para));
335     if (!ret) {
336         TELEPHONY_LOGE("SendEvent failed! eventId:%{public}d", info.ottCallEventId);
337     }
338     return TELEPHONY_SUCCESS;
339 }
340 
UpdateMediaModeResponse(const CallMediaModeResponse & response)341 int32_t ReportCallInfoHandlerService::UpdateMediaModeResponse(const CallMediaModeResponse &response)
342 {
343     if (handler_.get() == nullptr) {
344         TELEPHONY_LOGE("handler_ is nullptr");
345         return TELEPHONY_ERR_LOCAL_PTR_NULL;
346     }
347     std::unique_ptr<CallMediaModeResponse> para = std::make_unique<CallMediaModeResponse>();
348     if (para.get() == nullptr) {
349         TELEPHONY_LOGE("make_unique CellularCallEventInfo failed!");
350         return TELEPHONY_ERR_LOCAL_PTR_NULL;
351     }
352     if (memcpy_s(para->phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
353         TELEPHONY_LOGE("memcpy_s para->phoneNum failed!");
354         return TELEPHONY_ERR_MEMSET_FAIL;
355     }
356     para->result = response.result;
357     bool ret = handler_->SendEvent(HANDLE_UPDATE_MEDIA_MODE_RESPONSE, std::move(para));
358     if (!ret) {
359         TELEPHONY_LOGE("SendEvent failed! errno: %{public}d", ret);
360     }
361     return TELEPHONY_SUCCESS;
362 }
363 } // namespace Telephony
364 } // namespace OHOS
365