2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file CallTelephonyManager.h
19 * @brief This is the header file for the %TelephonyManager class.
21 * This header file contains the declarations for %TelephonyManager class.
23 #ifndef _PHN_TELEPHONY_MANAGER_H_
24 #define _PHN_TELEPHONY_MANAGER_H_
28 #include <FTelephony.h>
29 #include "ITapiCall.h"
30 #include "TapiUtility.h"
31 #include "CallITelephonyEventListener.h"
32 #include "CallSoundManager.h"
33 #include "CalllogManager.h"
36 class SettingsManager;
39 * @class TelephonyManager
40 * @brief TelephonyManager is a singleton class used to intialize TAPI library.
41 * And register to telephony events, interact with TAPI library.
43 class TelephonyManager
44 : public Tizen::Telephony::ITelephonyNetworkEventListener
47 //Get singleton instance
48 static TelephonyManager* GetInstance(ITelephonyEventListener* pEventListener);
49 //Function to initiate (dial) an outgoing call.
50 ErrorCodes SetupMoCall(Tizen::Base::String& contactNumber, bool isEmergency);
51 //Function to end a call
52 result EndActiveCall(Tizen::Base::Long callHandle);
53 result EndDialingCall(Tizen::Base::String& contactNumber);
54 //Function to accept/reject an incoming call
55 result AnswerCall(int callHandle, bool acceptCall);
57 result AnswerAutoRejectCall(int callHandle);
58 //Function to accept call with the given options
59 result AcceptCall(CallAnsweringOptions answerOptions,int callHandle);
60 //Function to end a conference call
61 result EndConferenceCall(void);
62 //Function to hold/retrieve a conference call
63 result HoldConferenceCall(bool holdCall);
64 //Function to join active and held call to conference
65 result JoinCall(void);
66 //Function to hold/unhold the call
67 result HoldCall(Tizen::Base::Long callHandle, bool holdCall);
68 //Function to swap the active and held call
69 result SwapCalls(void);
70 //Function to send DTMF strings
71 result SendCallDTMF(Tizen::Base::String& textToBeSent);
72 //Function to end a single call from the conference
73 result EndFromConference(int callHandle);
74 //Function to split a single call from the conference
75 result SplitFromConference(int callHandle);
76 //Function to set the mute status
77 result SetMuteStatus(bool setMute);
78 //Function to get the mute Status
79 bool IsCallMuted(void);
80 //Function to set the speaker status
81 result SetSpeakerStatus(bool setSpeaker);
82 //Function to get the speaker status
83 bool IsSpeakerOn(void);
84 //Function to check if split operation is allowed from the conference
85 bool IsSplitAllowed(void);
86 //Function to get the conference call info
87 AppCallInfo* GetConferenceCallInfoN(void);
88 //Get the current call list
89 Tizen::Base::Collection::IListT<AppCallInfo>* GetCallListN(void);
90 //Get the current call count
91 int GetCurrentCallCount(void);
92 //Start the alert in case of incoming call
93 void StartAlert(AppCallInfo& incomingCallInfo);
94 //Stop the alert in case of incoming call
96 //Main Callback function used while registering to TAPI
97 static void HandleCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData);
98 //Dummy callback function used when nothing is to be done on response
99 static void HandleCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
100 //callback function for dial operation
101 static void HandleDialCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
102 //callback function for the join operation
103 static void HandleJoinCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
104 //callback function for the reject call operation
105 static void HandleRejectCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
106 //callback function for the swap calls operation
107 static void HandleSwapCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
108 //callback function for the End from conference operation
109 static void HandleEndFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
110 //callback function for the split from conference operation
111 static void HandleSplitFromConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
112 //callback function for Ending conference call
113 static void HandleEndConferenceCallbackResponse(TapiHandle* pHandle, int callBackResult, void* pData, void* pUserData);
114 //Check if MOCall is emergency number and returns true. Otherwise, false.
115 bool CheckIfMOCallIsEmergency(const Tizen::Base::String& contactNumber, bool isSimInitialized);
116 //Check is modem and sim are initialised successfully and MO call can be made.
117 result CheckIfMOCallIsPossible();
118 //Gets the contact for the given phonenumber.returns null if not present.
119 Tizen::Social::Contact* GetContactN(const Tizen::Base::String& phoneNumber);
120 //This function make a synchronus API call to TAPI to fetch active/waiting incoming calls.
121 AppCallInfo* FetchIncomingCallHandleN(const Tizen::Base::String& callHandle, const Tizen::Base::String& contactNumber);
122 //This callback function is called by TAPI each time for every single call.
123 static void HandleIncomingCallStatusCallBack(TelCallStatus_t* pCallStatus, void* pUserData);
124 //function used to process incoming call and decide whether to reject call based on call settings.
125 //Rejects the call and returns true, Else returns false.
126 bool CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo);
128 void EndAllCalls(void);
129 //From ITelephonyNetworkEventListener
130 virtual void OnTelephonyNetworkStatusChanged(const Tizen::Telephony::NetworkStatus& networkStatus);
133 //function to handle the idle callback(received when call is ended)
134 void HandleIdleCallBack(void* pData);
135 //function used to handle events for normal call disconnected.
136 bool HandleEndNormalActiveCall(AppCallInfo& endCallInfo);
137 //function to handle the active callback(received when call is connected)
138 void HandleActiveCallBack(void* pData);
139 //function to handle call connected successfully
140 void HandleCallConnected(unsigned int connectedCallHandle);
141 //function to handle the dial call callback
142 void HandleDialingCallBack(void* pData);
143 //function to handle ending of single participant in conference call.
144 bool HandleParticipantEndedFromConference(unsigned int participantCallHandle, AppCallInfo& conferenceCall);
147 //create a singleton instance
148 static void CreateInstance(ITelephonyEventListener* pEventListener);
149 //used to destroy 'TelephonyManager' instance at application exit.
150 static void DestroyInstance(void);
152 virtual ~TelephonyManager(void);
153 TelephonyManager(ITelephonyEventListener* pEventListener);
154 TelephonyManager(TelephonyManager& manager);
155 TelephonyManager& operator =(TelephonyManager& manager);
156 //perform 2nd phase initialisation
157 result Initialize(void);
158 //initialise the TAPI library
159 result InitializeTelephonyLibrary(void);
160 //register for the TAPI events
161 int RegisterEvents(void);
162 //unregister from the TAPI events
163 void UnregisterEvents(void);
164 //internal function to hold an active call
165 result HoldActiveCall(AppCallInfo* pActiveCallInfo, bool holdCall);
166 //internal function to make a call
167 result DialOutgoingCall(Tizen::Base::String& contactNumber, bool isEmergency);
168 //internal function to handle waiting call options when single call is present
169 result AcceptSecondCall(CallAnsweringOptions answerOptions, const int incomingCallHandle);
170 //internal function to handle waiting call options when multiple calls are present
171 result AcceptMultipleCall(CallAnsweringOptions answerOptions, const int incomingCallHandle);
172 //internal function to End Call
173 result EndCall(AppCallInfo& endCallInfo);
175 * This function is internally used to fetch contact person details -
176 * display name & photo id from AddressBook for the given phone number.
178 * @param[in] phoneNumber - The substring of the phoneNumber to search
179 * @return E_SUCCESS, if found else E_FAILURE.
181 result FetchContactInfoForNumber(const Tizen::Base::String& phoneNumberStr);
182 //check if given contact number is valid and returns 'E_SUCCESS', else 'E_FAILURE'.
183 result CheckValidTelePhoneNumber(const Tizen::Base::String& contactNumber);
184 //Used to save ended call Log info to Logs database.
185 void SaveCallInfoToLogsDb(AppCallInfo& endCallInfo);
188 static TelephonyManager* __pManager;
191 AppCallInfo* __pDialedCall;
193 AppCallInfo* __pIncomingCall;
194 //Active Calls - only 2 active calls at any time
195 //can hold both Single or Conf. Calls
196 //mapping of "Call handle" to "CallInfo"
197 Tizen::Base::Collection::HashMapT<long, AppCallInfo>* __pActiveCallList;
199 //Listener for telephony events
200 ITelephonyEventListener* __pEventListener;
202 SettingsManager* __pSettingsManager;
204 //handle to Telephony API
205 TapiHandle* __pTapiHandle;
206 //used to connect to Address Book APIs.
207 Tizen::Social::Addressbook* __pAddressBook;
208 //used to store previously fetched contact.
209 Tizen::Social::Contact* __pCachedContact;
214 SoundManager* __pSoundManager;
215 CallLogManager* __pCalllogMgr;
216 Tizen::Telephony::NetworkManager* __pNetworkManager;
219 #endif // _PHN_TELEPHONY_MANAGER_H_