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 "call_ability_callback.h"
17
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Telephony {
CallAbilityCallback()23 CallAbilityCallback::CallAbilityCallback() : callbackPtr_(nullptr) {}
24
~CallAbilityCallback()25 CallAbilityCallback::~CallAbilityCallback() {}
26
SetProcessCallback(std::unique_ptr<CallManagerCallback> callback)27 int32_t CallAbilityCallback::SetProcessCallback(std::unique_ptr<CallManagerCallback> callback)
28 {
29 std::lock_guard<std::mutex> lock(mutex_);
30 if (callback == nullptr) {
31 callbackPtr_ = nullptr;
32 return TELEPHONY_SUCCESS;
33 }
34 callbackPtr_ = std::move(callback);
35 return TELEPHONY_SUCCESS;
36 }
37
OnCallDetailsChange(const CallAttributeInfo & info)38 int32_t CallAbilityCallback::OnCallDetailsChange(const CallAttributeInfo &info)
39 {
40 std::lock_guard<std::mutex> lock(mutex_);
41 if (callbackPtr_ != nullptr) {
42 return callbackPtr_->OnCallDetailsChange(info);
43 }
44 return TELEPHONY_SUCCESS;
45 }
46
OnCallEventChange(const CallEventInfo & info)47 int32_t CallAbilityCallback::OnCallEventChange(const CallEventInfo &info)
48 {
49 std::lock_guard<std::mutex> lock(mutex_);
50 if (callbackPtr_ != nullptr) {
51 return callbackPtr_->OnCallEventChange(info);
52 }
53 return TELEPHONY_SUCCESS;
54 }
55
OnCallDisconnectedCause(const DisconnectedDetails & details)56 int32_t CallAbilityCallback::OnCallDisconnectedCause(const DisconnectedDetails &details)
57 {
58 std::lock_guard<std::mutex> lock(mutex_);
59 if (callbackPtr_ != nullptr) {
60 return callbackPtr_->OnCallDisconnectedCause(details);
61 }
62 return TELEPHONY_SUCCESS;
63 }
64
OnReportAsyncResults(CallResultReportId reportId,AppExecFwk::PacMap & resultInfo)65 int32_t CallAbilityCallback::OnReportAsyncResults(CallResultReportId reportId, AppExecFwk::PacMap &resultInfo)
66 {
67 std::lock_guard<std::mutex> lock(mutex_);
68 if (callbackPtr_ != nullptr) {
69 return callbackPtr_->OnReportAsyncResults(reportId, resultInfo);
70 }
71 return TELEPHONY_SUCCESS;
72 }
73
OnReportMmiCodeResult(const MmiCodeInfo & info)74 int32_t CallAbilityCallback::OnReportMmiCodeResult(const MmiCodeInfo &info)
75 {
76 std::lock_guard<std::mutex> lock(mutex_);
77 if (callbackPtr_ != nullptr) {
78 return callbackPtr_->OnReportMmiCodeResult(info);
79 }
80 return TELEPHONY_SUCCESS;
81 }
82
OnOttCallRequest(OttCallRequestId requestId,AppExecFwk::PacMap & info)83 int32_t CallAbilityCallback::OnOttCallRequest(OttCallRequestId requestId, AppExecFwk::PacMap &info)
84 {
85 std::lock_guard<std::mutex> lock(mutex_);
86 if (callbackPtr_ != nullptr) {
87 return callbackPtr_->OnOttCallRequest(requestId, info);
88 }
89 return TELEPHONY_SUCCESS;
90 }
91 } // namespace Telephony
92 } // namespace OHOS
93