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 */
35namespace OHOS {
36namespace Telephony {
37class CallBase : public virtual RefBase {
38public:
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();
127    virtual void SetSlotId(int32_t slotId) {}
128    virtual void SetCallIndex(int32_t index) {}
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    void SetCallDirection(CallDirection direction);
135    CallDirection GetCallDirection();
136    int32_t GetAccountId();
137    void SetExtraParams(AAFwk::WantParams extraParams);
138    bool IsAnsweredCall();
139    void SetAnsweredCall(bool isAnswered);
140
141protected:
142    int32_t callId_;
143    CallType callType_;
144    VideoStateType videoState_;
145    std::string accountNumber_;
146    std::string bundleName_;
147
148private:
149    void StateChangesToDialing();
150    void StateChangesToIncoming();
151    void StateChangesToWaiting();
152    void StateChangesToActive();
153    void StateChangesToHolding();
154    void StateChangesToDisconnected();
155    void StateChangesToDisconnecting();
156    void StateChangesToAlerting();
157    void HangUpVoipCall();
158
159    CallRunningState callRunningState_;
160    TelConferenceState conferenceState_;
161    int64_t startTime_; // Call start time
162    CallDirection direction_;
163    uint64_t policyFlag_;
164    TelCallState callState_;
165    bool autoAnswerState_;
166    bool canUnHoldState_;
167    bool canSwitchCallState_;
168    int32_t answerVideoState_;
169    bool isSpeakerphoneOn_;
170    CallEndedType callEndedType_;
171    ContactInfo contactInfo_;
172    time_t callBeginTime_;
173    time_t callCreateTime_;
174    time_t callEndTime_;
175    time_t ringBeginTime_;
176    time_t ringEndTime_;
177    CallAnswerType answerType_;
178    int32_t accountId_;
179    int32_t crsType_;
180    int32_t originalCallType_;
181    bool isMuted_;
182    std::mutex mutex_;
183    std::string numberLocation_;
184    NumberMarkInfo numberMarkInfo_;
185    int32_t blockReason_;
186    bool isEccContact_;
187    int32_t celiaCallType_;
188    AAFwk::WantParams extraParams_;
189    bool isAnswered_;
190};
191} // namespace Telephony
192} // namespace OHOS
193
194#endif // CALL_BASE_H
195