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 #ifndef CALL_BASE_H
17 #define CALL_BASE_H
18 
19 #include <unistd.h>
20 #include <cstring>
21 #include <memory>
22 #include <mutex>
23 
24 #include "refbase.h"
25 #include "pac_map.h"
26 
27 #include "common_type.h"
28 #include "conference_base.h"
29 #include "call_manager_info.h"
30 
31 /**
32  * @ClassName: CallBase
33  * @Description: an abstraction  of telephone calls, provide basic call ops interfaces
34  */
35 namespace OHOS {
36 namespace Telephony {
37 class CallBase : public virtual RefBase {
38 public:
39     explicit CallBase(DialParaInfo &info);
40     CallBase(DialParaInfo &info, AppExecFwk::PacMap &extras);
41     virtual ~CallBase();
42 
43     virtual int32_t DialingProcess() = 0;
44     virtual int32_t AnswerCall(int32_t videoState) = 0;
45     virtual int32_t RejectCall() = 0;
46     virtual int32_t HangUpCall() = 0;
47     virtual int32_t HoldCall() = 0;
48     virtual int32_t UnHoldCall() = 0;
49     virtual int32_t SwitchCall() = 0;
50     virtual void GetCallAttributeInfo(CallAttributeInfo &info) = 0;
51     virtual bool GetEmergencyState() = 0;
52     virtual int32_t StartDtmf(char str) = 0;
53     virtual int32_t StopDtmf() = 0;
54     virtual int32_t PostDialProceed(bool proceed) = 0;
55     virtual int32_t GetSlotId() = 0;
56     virtual int32_t CombineConference() = 0;
57     virtual void HandleCombineConferenceFailEvent() = 0;
58     virtual int32_t SeparateConference() = 0;
59     virtual int32_t KickOutFromConference() = 0;
60     virtual int32_t CanCombineConference() = 0;
61     virtual int32_t CanSeparateConference() = 0;
62     virtual int32_t CanKickOutFromConference() = 0;
63     virtual int32_t LaunchConference() = 0;
64     virtual int32_t ExitConference() = 0;
65     virtual int32_t HoldConference() = 0;
66     virtual int32_t GetMainCallId(int32_t &mainCallId) = 0;
67     virtual int32_t GetSubCallIdList(std::vector<std::u16string> &callIdList) = 0;
68     virtual int32_t GetCallIdListForConference(std::vector<std::u16string> &callIdList) = 0;
69     virtual int32_t IsSupportConferenceable() = 0;
70     virtual int32_t SetMute(int32_t mute, int32_t slotId) = 0;
71     int32_t DialCallBase();
72     int32_t IncomingCallBase();
73     int32_t AnswerCallBase();
74     int32_t RejectCallBase();
75     void GetCallAttributeBaseInfo(CallAttributeInfo &info);
76     int32_t GetCallID();
77     CallType GetCallType();
78     CallRunningState GetCallRunningState();
79     int32_t SetTelCallState(TelCallState nextState);
80     TelCallState GetTelCallState();
81     void SetTelConferenceState(TelConferenceState state);
82     TelConferenceState GetTelConferenceState();
83     VideoStateType GetVideoStateType();
84     void SetVideoStateType(VideoStateType mediaType);
85     void SetPolicyFlag(PolicyFlag flag);
86     uint64_t GetPolicyFlag();
87     ContactInfo GetCallerInfo();
88     void SetCallerInfo(const ContactInfo &contactInfo);
89     NumberMarkInfo GetNumberMarkInfo();
90     void SetNumberMarkInfo(const NumberMarkInfo &numberMarkInfo);
91     void SetBlockReason(const int32_t &blockReason);
92     void SetCallRunningState(CallRunningState callRunningState);
93     void SetStartTime(int64_t startTime);
94     void SetCallBeginTime(time_t callBeginTime);
95     void SetCallCreateTime(time_t callCreateTime);
96     void SetCallEndTime(time_t callEndTime);
97     void SetRingBeginTime(time_t ringBeginTime);
98     void SetRingEndTime(time_t ringEndTime);
99     void SetAnswerType(CallAnswerType answerType);
100     CallEndedType GetCallEndedType();
101     int32_t SetCallEndedType(CallEndedType callEndedType);
102     void SetCallId(int32_t callId);
103     bool IsSpeakerphoneEnabled();
104     bool IsCurrentRinging();
105     std::string GetAccountNumber();
106     void SetAccountNumber(const std::string accountNumber);
107     int32_t SetSpeakerphoneOn(bool speakerphoneOn);
108     bool IsSpeakerphoneOn();
109     void SetAutoAnswerState(bool flag);
110     bool GetAutoAnswerState();
111     void SetAnswerVideoState(int32_t videoState);
112     int32_t GetAnswerVideoState();
113     void SetCanUnHoldState(bool flag);
114     bool GetCanUnHoldState();
115     void SetCanSwitchCallState(bool flag);
116     bool GetCanSwitchCallState();
117     bool CheckVoicemailNumber(std::string phoneNumber);
118     bool IsAliveState();
119     void SetBundleName(const char *bundleName);
120     void SetCallType(CallType callType);
121     void SetCrsType(int32_t crsType);
122     int32_t GetCrsType();
123     void SetOriginalCallType(int32_t originalCallType);
124     int32_t GetOriginalCallType();
125     void SetNumberLocation(std::string numberLocation);
126     std::string GetNumberLocation();
SetSlotId(int32_t slotId)127     virtual void SetSlotId(int32_t slotId) {}
SetCallIndex(int32_t index)128     virtual void SetCallIndex(int32_t index) {}
GetCallIndex()129     virtual int32_t GetCallIndex() {return 0;}
130     int32_t SetMicPhoneState(bool isMuted);
131     bool IsMuted();
132     void SetIsEccContact(bool isEccContact);
133     void SetCeliaCallType(int32_t celiaCallType);
134     int32_t GetAccountId();
135 
136 protected:
137     int32_t callId_;
138     CallType callType_;
139     VideoStateType videoState_;
140     std::string accountNumber_;
141     std::string bundleName_;
142 
143 private:
144     void StateChangesToDialing();
145     void StateChangesToIncoming();
146     void StateChangesToWaiting();
147     void StateChangesToActive();
148     void StateChangesToHolding();
149     void StateChangesToDisconnected();
150     void StateChangesToDisconnecting();
151     void StateChangesToAlerting();
152     void HangUpVoipCall();
153 
154     CallRunningState callRunningState_;
155     TelConferenceState conferenceState_;
156     int64_t startTime_; // Call start time
157     CallDirection direction_;
158     uint64_t policyFlag_;
159     TelCallState callState_;
160     bool autoAnswerState_;
161     bool canUnHoldState_;
162     bool canSwitchCallState_;
163     int32_t answerVideoState_;
164     bool isSpeakerphoneOn_;
165     CallEndedType callEndedType_;
166     ContactInfo contactInfo_;
167     time_t callBeginTime_;
168     time_t callCreateTime_;
169     time_t callEndTime_;
170     time_t ringBeginTime_;
171     time_t ringEndTime_;
172     CallAnswerType answerType_;
173     int32_t accountId_;
174     int32_t crsType_;
175     int32_t originalCallType_;
176     bool isMuted_;
177     std::mutex mutex_;
178     std::string numberLocation_;
179     NumberMarkInfo numberMarkInfo_;
180     int32_t blockReason_;
181     bool isEccContact_;
182     int32_t celiaCallType_;
183 };
184 } // namespace Telephony
185 } // namespace OHOS
186 
187 #endif // CALL_BASE_H
188