1 /*
2  * Copyright (C) 2021 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 "base_connection.h"
17 
18 #include "securec.h"
19 #include "standardize_utils.h"
20 
21 namespace OHOS {
22 namespace Telephony {
BaseConnection()23 BaseConnection::BaseConnection()
24 {
25     if (memset_s(&callReportInfo_, sizeof(CallReportInfo), 0, sizeof(callReportInfo_)) != EOK) {
26         TELEPHONY_LOGE("return, memset_s error.");
27     }
28 }
29 
SetOrUpdateCallReportInfo(CallReportInfo &callReportInfo)30 void BaseConnection::SetOrUpdateCallReportInfo(CallReportInfo &callReportInfo)
31 {
32     callReportInfo_ = callReportInfo;
33 }
34 
GetCallReportInfo()35 CallReportInfo BaseConnection::GetCallReportInfo()
36 {
37     return callReportInfo_;
38 }
39 
SetStatus(TelCallState state)40 void BaseConnection::SetStatus(TelCallState state)
41 {
42     callReportInfo_.state = state;
43 }
44 
GetStatus() const45 TelCallState BaseConnection::GetStatus() const
46 {
47     return callReportInfo_.state;
48 }
49 
IsRingingState() const50 bool BaseConnection::IsRingingState() const
51 {
52     return this->GetStatus() == TelCallState::CALL_STATUS_INCOMING ||
53         this->GetStatus() == TelCallState::CALL_STATUS_WAITING ||
54         this->GetStatus() == TelCallState::CALL_STATUS_ALERTING;
55 }
56 
SetFlag(bool flag)57 void BaseConnection::SetFlag(bool flag)
58 {
59     flag_ = flag;
60 }
61 
GetFlag() const62 bool BaseConnection::GetFlag() const
63 {
64     return flag_;
65 }
66 
SetIndex(int32_t index)67 void BaseConnection::SetIndex(int32_t index)
68 {
69     index_ = index;
70 }
71 
GetIndex() const72 int32_t BaseConnection::GetIndex() const
73 {
74     return index_;
75 }
76 
SetNumber(const std::string &number)77 void BaseConnection::SetNumber(const std::string &number)
78 {
79     number_ = number;
80 }
81 
GetNumber() const82 std::string BaseConnection::GetNumber() const
83 {
84     return number_;
85 }
86 
ProcessNextChar(int32_t slotId, char &c)87 PostDialCallState BaseConnection::ProcessNextChar(int32_t slotId, char &c)
88 {
89     if (postDialCalltate_ == PostDialCallState::POST_DIAL_CALL_CANCELED) {
90         return PostDialCallState::POST_DIAL_CALL_CANCELED;
91     }
92     if (postDialCallString_.empty() || postDialCallString_.length() <= static_cast<size_t>(nextPostDialCallCode_)) {
93         SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_COMPLETE);
94         return PostDialCallState::POST_DIAL_CALL_COMPLETE;
95     } else {
96         SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_STARTED);
97         c = postDialCallString_.at(nextPostDialCallCode_++);
98         ProcessPostDialCallChar(slotId, c);
99     }
100     return postDialCalltate_;
101 }
102 
SetPostDialCallState(PostDialCallState s)103 void BaseConnection::SetPostDialCallState(PostDialCallState s)
104 {
105     postDialCalltate_ = s;
106 }
107 
UpdateCallNumber(std::string phoneNum)108 void BaseConnection::UpdateCallNumber(std::string phoneNum)
109 {
110     StandardizeUtils standardizeUtils;
111     standardizeUtils.ExtractAddressAndPostDial(phoneNum, phoneNumber_, postDialCallString_);
112 }
113 
GetLeftPostDialCallString()114 std::string BaseConnection::GetLeftPostDialCallString()
115 {
116     if (postDialCallString_.empty() || postDialCallString_.length() <= static_cast<size_t>(nextPostDialCallCode_)) {
117         return "";
118     }
119     return postDialCallString_.substr(nextPostDialCallCode_);
120 }
121 
ProcessPostDialCallChar(int32_t slotId, char c)122 int32_t BaseConnection::ProcessPostDialCallChar(int32_t slotId, char c)
123 {
124     return TELEPHONY_SUCCESS;
125 }
126 
UpdatePendingHoldFlag(bool isPendingHold)127 void BaseConnection::UpdatePendingHoldFlag(bool isPendingHold)
128 {
129     callReportInfo_.isPendingHold = isPendingHold;
130 }
131 } // namespace Telephony
132 } // namespace OHOS