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