1 /*
2  * Copyright (C) 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 "cellular_call_connection_satellite.h"
17 
18 #include "cellular_call_hisysevent.h"
19 #include "cellular_call_service.h"
20 #include "radio_event.h"
21 #include "satellite_call_client.h"
22 #include "satellite_call_types.h"
23 #include "securec.h"
24 #include "standardize_utils.h"
25 
26 namespace OHOS {
27 namespace Telephony {
DialRequest(int32_t slotId,const DialRequestStruct & dialRequest)28 int32_t CellularCallConnectionSatellite::DialRequest(int32_t slotId, const DialRequestStruct &dialRequest)
29 {
30     TELEPHONY_LOGI("call satellite service");
31     SatelliteCallInfo callInfo;
32     if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
33         TELEPHONY_LOGE("return, memset_s error.");
34         CellularCallHiSysEvent::WriteDialCallFaultEvent(
35             slotId, INVALID_PARAMETER, INVALID_PARAMETER, TELEPHONY_ERR_MEMSET_FAIL, "memset_s error");
36         return TELEPHONY_ERR_MEMSET_FAIL;
37     }
38     UpdateCallNumber(dialRequest.phoneNum);
39     size_t cpyLen = strlen(phoneNumber_.c_str()) + 1;
40     if (cpyLen > static_cast<size_t>(kMaxNumberLength)) {
41         phoneNumber_.clear();
42         return TELEPHONY_ERR_STRCPY_FAIL;
43     }
44     if (strcpy_s(callInfo.phoneNum, cpyLen, phoneNumber_.c_str()) != EOK) {
45         TELEPHONY_LOGE("return, strcpy_s fail.");
46         phoneNumber_.clear();
47         CellularCallHiSysEvent::WriteDialCallFaultEvent(
48             slotId, INVALID_PARAMETER, INVALID_PARAMETER, TELEPHONY_ERR_STRCPY_FAIL, "strcpy_s fail");
49         return TELEPHONY_ERR_STRCPY_FAIL;
50     }
51     phoneNumber_.clear();
52     callInfo.slotId = slotId;
53     if (DelayedSingleton<SatelliteCallClient>::GetInstance() == nullptr) {
54         TELEPHONY_LOGE("return, SatelliteCallClient is nullptr.");
55         CellularCallHiSysEvent::WriteDialCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
56             CALL_ERR_RESOURCE_UNAVAILABLE, "satellite vendor service does not exist");
57         return CALL_ERR_RESOURCE_UNAVAILABLE;
58     }
59     return DelayedSingleton<SatelliteCallClient>::GetInstance()->Dial(callInfo, dialRequest.clirMode);
60 }
61 
HangUpRequest(int32_t slotId)62 int32_t CellularCallConnectionSatellite::HangUpRequest(int32_t slotId)
63 {
64     TELEPHONY_LOGI("call satellite service");
65     if (DelayedSingleton<SatelliteCallClient>::GetInstance() == nullptr) {
66         TELEPHONY_LOGE("return, SatelliteCallClient is nullptr.");
67         return CALL_ERR_RESOURCE_UNAVAILABLE;
68     }
69     int32_t index = GetIndex();
70     return DelayedSingleton<SatelliteCallClient>::GetInstance()->HangUp(slotId, index);
71 }
72 
AnswerRequest(int32_t slotId)73 int32_t CellularCallConnectionSatellite::AnswerRequest(int32_t slotId)
74 {
75     TELEPHONY_LOGI("call satellite service");
76     if (DelayedSingleton<SatelliteCallClient>::GetInstance() == nullptr) {
77         TELEPHONY_LOGE("return, SatelliteCallClient is nullptr.");
78         return CALL_ERR_RESOURCE_UNAVAILABLE;
79     }
80     return DelayedSingleton<SatelliteCallClient>::GetInstance()->Answer(slotId);
81 }
82 
RejectRequest(int32_t slotId)83 int32_t CellularCallConnectionSatellite::RejectRequest(int32_t slotId)
84 {
85     TELEPHONY_LOGI("call satellite service");
86     if (DelayedSingleton<SatelliteCallClient>::GetInstance() == nullptr) {
87         TELEPHONY_LOGE("return, SatelliteCallClient is nullptr.");
88         return CALL_ERR_RESOURCE_UNAVAILABLE;
89     }
90     return DelayedSingleton<SatelliteCallClient>::GetInstance()->Reject(slotId);
91 }
92 
GetSatelliteCallsDataRequest(int32_t slotId,int64_t lastCallsDataFlag)93 int32_t CellularCallConnectionSatellite::GetSatelliteCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag)
94 {
95     TELEPHONY_LOGI("call satellite service");
96     if (DelayedSingleton<SatelliteCallClient>::GetInstance() == nullptr) {
97         TELEPHONY_LOGE("return, SatelliteCallClient is nullptr.");
98         return CALL_ERR_RESOURCE_UNAVAILABLE;
99     }
100     return DelayedSingleton<SatelliteCallClient>::GetInstance()->GetSatelliteCallsDataRequest(
101         slotId, lastCallsDataFlag);
102 }
103 
GetCallFailReasonRequest(int32_t slotId) const104 int32_t CellularCallConnectionSatellite::GetCallFailReasonRequest(int32_t slotId) const
105 {
106     return CALL_ERR_RESOURCE_UNAVAILABLE;
107 }
108 
RegisterHandler()109 void CellularCallConnectionSatellite::RegisterHandler()
110 {
111     DelayedSingleton<CellularCallService>::GetInstance()->RegisterHandler();
112 }
113 
SendDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const114 int32_t CellularCallConnectionSatellite::SendDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
115 {
116     TELEPHONY_LOGI("CellularCallConnectionSatellite::SendDtmfRequest start.");
117     if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
118         TELEPHONY_LOGE("SendDtmfRequest return, error type: GetInstance() is nullptr.");
119         return CALL_ERR_RESOURCE_UNAVAILABLE;
120     }
121     auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
122     if (handle == nullptr) {
123         TELEPHONY_LOGE("SendDtmfRequest return, error type: handle is nullptr.");
124         return CALL_ERR_RESOURCE_UNAVAILABLE;
125     }
126     CoreManagerInner::GetInstance().SendDTMF(slotId, RadioEvent::RADIO_SEND_DTMF, cDtmfCode, index, handle);
127     return TELEPHONY_SUCCESS;
128 }
129 
StartDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const130 int32_t CellularCallConnectionSatellite::StartDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
131 {
132     TELEPHONY_LOGD("CellularCallConnectionSatellite::StartDtmfRequest start.");
133     if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
134         TELEPHONY_LOGE("StartDtmfRequest return, error type: GetInstance() is nullptr.");
135         return CALL_ERR_RESOURCE_UNAVAILABLE;
136     }
137     auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
138     if (handle == nullptr) {
139         TELEPHONY_LOGE("StartDtmfRequest return, error type: handle is nullptr.");
140         return CALL_ERR_RESOURCE_UNAVAILABLE;
141     }
142     CoreManagerInner::GetInstance().StartDTMF(slotId, RadioEvent::RADIO_START_DTMF, cDtmfCode, index, handle);
143     return TELEPHONY_SUCCESS;
144 }
145 
StopDtmfRequest(int32_t slotId,int32_t index) const146 int32_t CellularCallConnectionSatellite::StopDtmfRequest(int32_t slotId, int32_t index) const
147 {
148     TELEPHONY_LOGI("CellularCallConnectionSatellite::StopDtmfRequest start.");
149     if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
150         TELEPHONY_LOGE("StopDtmfRequest return, error type: GetInstance() is nullptr.");
151         return CALL_ERR_RESOURCE_UNAVAILABLE;
152     }
153     auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
154     if (handle == nullptr) {
155         TELEPHONY_LOGE("StopDtmfRequest return, error type: handle is nullptr.");
156         return CALL_ERR_RESOURCE_UNAVAILABLE;
157     }
158     CoreManagerInner::GetInstance().StopDTMF(slotId, RadioEvent::RADIO_STOP_DTMF, index, handle);
159     return TELEPHONY_SUCCESS;
160 }
161 
ProcessPostDialCallChar(int32_t slotId,char c)162 int32_t CellularCallConnectionSatellite::ProcessPostDialCallChar(int32_t slotId, char c)
163 {
164     if (StandardizeUtils::IsDtmfKey(c)) {
165         SendDtmfRequest(slotId, c, GetIndex());
166     } else if (StandardizeUtils::IsPauseKey(c)) {
167         SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_PAUSE);
168         auto cellularCallHandle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
169         if (cellularCallHandle == nullptr) {
170             TELEPHONY_LOGE("SendDtmfRequest return, error type: handle is nullptr.");
171             return CALL_ERR_RESOURCE_UNAVAILABLE;
172         }
173         std::shared_ptr<PostDialData> postDial = std::make_shared<PostDialData>();
174         postDial->callId = GetIndex();
175         postDial->isIms = false;
176         cellularCallHandle->SendEvent(EVENT_EXECUTE_POST_DIAL, postDial, PAUSE_DELAY_TIME);
177     } else if (StandardizeUtils::IsWaitKey(c)) {
178         SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_DELAY);
179     }
180     return TELEPHONY_SUCCESS;
181 }
182 } // namespace Telephony
183 } // namespace OHOS
184