890bddf577fd57a524588f7e2d40357510d2a6dd
[apps/osp/Call.git] / src / CallPresentationModel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file        CallCallPresentationModel.cpp
19  * @brief       Call Presentation model class
20  */
21 #include <FApp.h>
22 #include <FUi.h>
23 #include <FMedia.h>
24 #include "CallApp.h"
25 #include "CallAppControlRequestMgr.h"
26 #include "CallActiveCallForm.h"
27 #include "CallInfo.h"
28 #include "CallPresentationModel.h"
29 #include "CallSettingsPresentationModel.h"
30 #include "CallConfCallerListForm.h"
31 #include "CallTelephonyManager.h"
32 #include "CallSceneRegister.h"
33 #include "CallTypes.h"
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::App;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Media;
40 using namespace Tizen::Social;
41 using namespace Tizen::Ui::Scenes;
42 using namespace Tizen::Telephony;
43 using namespace Tizen::Base::Utility;
44 using namespace Tizen::Messaging;
45
46 CallPresentationModel* CallPresentationModel::__pInstance = null;
47
48 CallPresentationModel::CallPresentationModel(void)
49 {
50         __pTelephonyMgr = null;
51         __pTelEventListener = null;
52         __pSettingsPresentor = null;
53         __isMessageAppControlRunning = false;
54         __isDialAppControlRunning = false;
55         __pAppControlMgr = null;
56         __pNetworkManager = null;
57         __psimStateManager = null;
58         __psimInfo = null;
59         __pSmsManager = null;
60         __isMessageSendInProgress = false;
61 }
62
63 CallPresentationModel::~CallPresentationModel(void)
64 {
65         __pTelephonyMgr = null;
66         __pSettingsPresentor = null;
67         __pAppControlMgr =null;
68         if(__pNetworkManager != null)
69         {
70                 delete __pNetworkManager;
71                 __pNetworkManager = null;
72         }
73         if(__psimStateManager != null)
74         {
75                 delete __psimStateManager;
76                 __psimStateManager = null;
77         }
78         if(__psimInfo != null)
79         {
80                 delete __psimInfo;
81                 __psimInfo = null;
82         }
83         if(__pSmsManager != null)
84         {
85                 delete __pSmsManager;
86                 __pSmsManager = null;
87         }
88 }
89
90 void
91 CallPresentationModel::CreateInstance(void)
92 {
93         __pInstance = new (std::nothrow) CallPresentationModel();
94         result r = __pInstance->Construct();
95         if(IsFailed(r))
96         {
97                 delete __pInstance;
98                 __pInstance = null;
99                 return;
100         }
101
102         std::atexit(DestroyInstance);
103 }
104
105 CallPresentationModel*
106 CallPresentationModel::GetInstance(void)
107 {
108         if (__pInstance == null)
109         {
110                 CreateInstance();
111         }
112         return __pInstance;
113 }
114
115 void
116 CallPresentationModel::DestroyInstance(void)
117 {
118         if (__pInstance != null)
119         {
120                 delete __pInstance;
121                 __pInstance = null;
122         }
123 }
124
125 result
126 CallPresentationModel::Construct(void)
127 {
128         //Fetch Telephony Manager
129         __pTelephonyMgr = TelephonyManager::GetInstance(this);
130         __pSettingsPresentor = SettingsPresentationModel::GetInstance();
131         __pAppControlMgr = CallAppControlRequestMgr::GetInstance();
132         __pNetworkManager = new (std::nothrow)NetworkManager();
133         __pNetworkManager->Construct(null);
134         GetSimInfo();
135         return E_SUCCESS;
136 }
137
138 void
139 CallPresentationModel::SetTelEventListener(ITelephonyEventListener* pTelEventListener)
140 {
141         //set form as telephony event listener
142         __pTelEventListener = pTelEventListener;
143 }
144
145 bool
146 CallPresentationModel::IfNumberEndsWithHash(Tizen::Base::String& phoneNumber)
147 {
148         String phoneNumberEndingWithHash(L"#$");
149         RegularExpression checkHash;
150         checkHash.Construct(phoneNumberEndingWithHash);
151         bool endsWithHash = checkHash.Match(phoneNumber,false);
152         if(endsWithHash == true)
153         {
154                 return true;
155         }
156         return false;
157 }
158
159 void
160 CallPresentationModel::DialCall(String& contactNumber, bool isEmergency)
161 {
162         int errorCode = ERROR_NONE;
163         bool isCallServiceAvailable = false;
164         bool numberEndsWithHash = false;
165         NetworkStatus networkStatus;
166         result r;
167         //Check if Telephony Manager is initialized
168         TryCatch(__pTelephonyMgr != null, (errorCode = ERROR_TAPI_INIT_FAILED), "TAPI initialization failed");
169
170         //check if phone is in flight mode
171         if(__pSettingsPresentor != null && __pSettingsPresentor->GetFlightModeStatus() == true)
172         {
173                 __pTelEventListener->HandleTelephonyError(ERROR_FLIGHT_MODE_SET);
174                 return;
175         }
176         //Check if dialing a call is possible - Check if sim is available
177         if (IsSimAvailable() == false)
178         {
179                 __pTelEventListener->HandleTelephonyError(ERROR_CODE_SIM_INITIALIZATION_FAILED);
180                 return ;
181         }
182
183         //fetch call service status
184         if(__pNetworkManager != null)
185         {
186                 r = __pNetworkManager->GetNetworkStatus(networkStatus);
187                 if (r == E_SUCCESS)
188                 {
189                         isCallServiceAvailable = networkStatus.IsCallServiceAvailable();
190                 }
191         }
192
193
194         if (isCallServiceAvailable == false)
195         {
196                 __pTelEventListener->HandleTelephonyError(ERROR_DIAL_FAILED);
197                 return ;
198         }
199         // check if GPRS number
200         numberEndsWithHash = IfNumberEndsWithHash(contactNumber);
201         if(numberEndsWithHash == true)
202         {
203                 __pTelEventListener->HandleTelephonyError(ERROR_GPRS_NUMBER);
204                 return ;
205         }
206
207         //setup outgoing call
208         errorCode = __pTelephonyMgr->SetupMoCall(contactNumber, isEmergency);
209         TryCatch(errorCode == ERROR_NONE,,"Error occurred while setup MO call");
210         if(__pSettingsPresentor != null)
211         {
212                 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
213         }
214         return;
215
216 CATCH:
217         __pTelEventListener->HandleTelephonyError(errorCode);
218 }
219
220 void
221 CallPresentationModel::EndActiveCall(Long callHandle)
222 {
223         if(__pTelephonyMgr != null)
224         {
225                 __pTelephonyMgr->EndActiveCall(callHandle);
226         }
227 }
228
229 void
230 CallPresentationModel::EndDialingCall(String& contactNumber)
231 {
232         if(__pTelephonyMgr != null)
233         {
234                 __pTelephonyMgr->EndDialingCall(contactNumber);
235         }
236 }
237
238 bool
239 CallPresentationModel::EndConferenceCall(void)
240 {
241         result r = __pTelephonyMgr->EndConferenceCall();
242         if (IsFailed(r))
243         {
244                 //TODO: send proper error code
245                 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
246                 return false;
247         }
248         return true;
249 }
250
251 void
252 CallPresentationModel::EndAllCall(void)
253 {
254         if(__pTelephonyMgr != null)
255         {
256                 __pTelephonyMgr->EndAllCalls();
257         }
258 }
259 bool
260 CallPresentationModel::HoldCall(Tizen::Base::Long callHandle)
261 {
262         result r = __pTelephonyMgr->HoldCall(callHandle, true);
263         return (!IsFailed(r));
264 }
265
266 bool
267 CallPresentationModel::UnHoldCall(Tizen::Base::Long callHandle)
268 {
269         result r = __pTelephonyMgr->HoldCall(callHandle, false);
270         return (!IsFailed(r));
271 }
272
273 bool
274 CallPresentationModel::HoldConferenceCall(void)
275 {
276         result r = __pTelephonyMgr->HoldConferenceCall(true);
277         return (!IsFailed(r));
278 }
279
280 bool
281 CallPresentationModel::ActivateConferenceCall(void)
282 {
283         result r = __pTelephonyMgr->HoldConferenceCall(false);
284         return (!IsFailed(r));
285 }
286
287 void
288 CallPresentationModel::JoinCall(void)
289 {
290         result r = __pTelephonyMgr->JoinCall();
291         if (IsFailed(r))
292         {
293                 __pTelEventListener->HandleTelephonyError(ERROR_JOIN_FAILED);
294         }
295 }
296
297 void
298 CallPresentationModel::SwapCalls(void)
299 {
300         result r = __pTelephonyMgr->SwapCalls();
301         if (IsFailed(r))
302         {
303                 __pTelEventListener->HandleTelephonyError(ERROR_SWAP_FAILED);
304         }
305 }
306
307 bool
308 CallPresentationModel::SetMuteStatus(bool setMute)
309 {
310         result r = __pTelephonyMgr->SetMuteStatus(setMute);
311         return (!IsFailed(r));
312 }
313
314 bool
315 CallPresentationModel::IsCallMuted(void)
316 {
317         return __pTelephonyMgr->IsCallMuted();
318 }
319
320 bool
321 CallPresentationModel::SetSpeakerStatus(bool setSpeaker)
322 {
323         result r = __pTelephonyMgr->SetSpeakerStatus(setSpeaker);
324         return (!IsFailed(r));
325 }
326
327 bool
328 CallPresentationModel::IsSpeakerOn(void)
329 {
330         return __pTelephonyMgr->IsSpeakerOn();
331 }
332 void
333 CallPresentationModel::SendDTMFSignal(String& textToBeSent)
334 {
335         __pTelephonyMgr->SendCallDTMF(textToBeSent);
336 }
337
338 AppCallInfo*
339 CallPresentationModel::GetConferenceCallInfoN(void)
340 {
341         return __pTelephonyMgr->GetConferenceCallInfoN();
342 }
343
344 bool
345 CallPresentationModel::SplitFromConference(SplitConfCallerCmdIds splitCallerCmdId, IListT<AppCallInfo>* pConfCallList)
346 {
347         int callIndex = -1;
348         AppCallInfo callToBeSpli;
349         switch (splitCallerCmdId)
350         {
351         case IDA_SPLIT_CALLER1:
352                 callIndex = 0;
353                 break;
354
355         case IDA_SPLIT_CALLER2:
356                 callIndex = 1;
357                 break;
358
359         case IDA_SPLIT_CALLER3:
360                 callIndex = 2;
361                 break;
362
363         case IDA_SPLIT_CALLER4:
364                 callIndex = 3;
365                 break;
366
367         case IDA_SPLIT_CALLER5:
368                 callIndex = 4;
369                 break;
370
371         default:
372         break;
373         }
374
375         result r = pConfCallList->GetAt(callIndex, callToBeSpli);
376         TryCatch(r == E_SUCCESS,,"conf. call list corrupted");
377         //split single call from conference
378         r = __pTelephonyMgr->SplitFromConference(callToBeSpli.GetCallHandle()->ToLong());
379         TryCatch(r == E_SUCCESS,,"Split from conf. call failed");
380         return true;
381
382 CATCH:
383         __pTelEventListener->HandleTelephonyError(ERROR_SPLIT_FROM_CONFERENCE_FAILED);
384         return false;
385 }
386
387 void
388 CallPresentationModel::EndCallFromConference(EndConfCallerCmdIds endCallerCmdId, IListT<AppCallInfo>* pConfCallList)
389 {
390         int callIndex = -1;
391         AppCallInfo callToBeEnded;
392         switch (endCallerCmdId)
393         {
394         case IDA_END_CALLER1:
395                 callIndex = 0;
396                 break;
397
398         case IDA_END_CALLER2:
399                 callIndex = 1;
400                 break;
401
402         case IDA_END_CALLER3:
403                 callIndex = 2;
404                 break;
405
406         case IDA_END_CALLER4:
407                 callIndex = 3;
408                 break;
409
410         case IDA_END_CALLER5:
411                 callIndex = 4;
412                 break;
413
414         default:
415         break;
416         }
417
418         result r = pConfCallList->GetAt(callIndex, callToBeEnded);
419         TryCatch(r == E_SUCCESS,,"conference call list corrupted");
420         //end single call
421         r = __pTelephonyMgr->EndFromConference(callToBeEnded.GetCallHandle()->ToLong());
422         TryCatch(r == E_SUCCESS,,"End single call from conference call failed");
423
424         return;
425
426 CATCH:
427         __pTelEventListener->HandleTelephonyError(ERROR_END_CALL_FAILED);
428         return;
429 }
430
431 bool
432 CallPresentationModel::IsSplitAllowed(void)
433 {
434         return __pTelephonyMgr->IsSplitAllowed();
435 }
436
437 void
438 CallPresentationModel::AcceptIncomingCall(CallAnsweringOptions answerOptions,int callHandle)
439 {
440         result r = E_FAILURE;
441         if (answerOptions == ANSERWING_OPTION_ACCEPT_CALL)
442         {
443                 r = __pTelephonyMgr->AnswerCall(callHandle, true);
444         }
445         else
446         {
447                 r = __pTelephonyMgr->AcceptCall(answerOptions,callHandle);
448         }
449         if (IsFailed(r))
450         {
451                 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
452         }
453 }
454
455 IListT<AppCallInfo>*
456 CallPresentationModel::GetCallListN(void)
457 {
458         return __pTelephonyMgr->GetCallListN();
459 }
460
461
462 bool
463 CallPresentationModel::RejectCall(int callHandle, bool sendMsg, const String& contactNumber)
464 {
465         AppLogDebug("Enter");
466         if (sendMsg == true && __pAppControlMgr != null)
467         {
468                 //launch compose message AppControl
469                 __isMessageAppControlRunning = __pAppControlMgr->LaunchComposeMessageAppControl(*(const_cast<String*>(&contactNumber)), this);
470         }
471         result r = __pTelephonyMgr->AnswerCall(callHandle, false);
472         if (IsFailed(r))
473         {
474                 __pTelEventListener->HandleTelephonyError(ERROR_GENERAL);
475                 return false;
476         }
477
478
479         AppLogDebug("Exit");
480         return true;
481 }
482
483 void CallPresentationModel::OnAppForeground(void)
484 {
485         AppLogDebug("Enter %d %d",__isDialAppControlRunning ,__isMessageAppControlRunning);
486         if (__isDialAppControlRunning == true)
487         {
488                 //This comes here, when Dialer AppControl is finished working.
489                 __isDialAppControlRunning = false;
490                 __pAppControlMgr->AppControlRequestCompleted();
491         }
492         if (__isMessageAppControlRunning == true)
493         {
494                 //This comes here, when Message AppControl is finished working.
495                 __isMessageAppControlRunning = false;
496                 __pAppControlMgr->AppControlRequestCompleted();
497                 //Check if this was the last call, then terminate application.
498                 //And if any calls are active, then those cases are already handled from Other places.
499                 if( GetCurrentCallCount() == 0 && IsIncomingorDialingCallPresent() == false)
500                 {
501                         CallApp* pCallApp = static_cast<CallApp*>(UiApp::GetInstance());
502                         pCallApp->Terminate();
503                 }
504         }
505 }
506
507 void
508 CallPresentationModel::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
509 {
510         AppLogDebug("Enter");
511         if (__isMessageAppControlRunning == true)
512         {
513                 //This comes here, when Message AppControl is finished working.
514                 __isMessageAppControlRunning = false;
515                 __pAppControlMgr->AppControlRequestCompleted();
516                 //Check if this was the last call, then terminate application.
517                 //And if any calls are active, then those cases are already handled from Other places.
518                 if( GetCurrentCallCount() == 0)
519                 {
520                         CallApp* pPhoneApp = static_cast<CallApp*>(UiApp::GetInstance());
521                         pPhoneApp->Terminate();
522                 }
523         }
524         if(appId.Equals(PROVIDER_ID_PHONE,false) == true &&  operationId.Equals(OPERATION_ID_DIAL,false) == true)
525         {
526                 __isDialAppControlRunning = false;
527
528                 __pAppControlMgr->AppControlRequestCompleted();
529                 if(appControlResult == APP_CTRL_RESULT_SUCCEEDED)
530                 {
531                         String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
532                         if (pExtraData->ContainsKey(*pKey) == true)
533                         {
534                                 const String* pPhoneNumber = static_cast<const String*>(pExtraData->GetValue(*pKey));
535                                 if(pPhoneNumber != null && pPhoneNumber->IsEmpty() == false)
536                                 {
537                                         AddCall(*pPhoneNumber);
538                                 }
539
540                         }
541
542                 }
543
544         }
545 }
546
547 void
548 CallPresentationModel::AddCall(const String& phoneNumber)
549 {
550         ArrayList* pLaunchArgs = null;
551         SceneManager* pSceneManager = SceneManager::GetInstance();
552         int currentActiveCallCount = GetCurrentCallCount();
553         if(currentActiveCallCount <= 1 && IsIncomingorDialingCallPresent() == false)
554         {
555                 //make an outgoing call with given number
556                 String* contactTxt = new (std::nothrow) String(phoneNumber);
557                 pLaunchArgs =  new (std::nothrow) ArrayList(SingleObjectDeleter);
558                 pLaunchArgs->Construct();
559                 pLaunchArgs->Add(contactTxt);
560                 bool isEmergencyCall = IsEmergencyNumber(*contactTxt, true);
561
562                 SceneId nextScene = IDSCN_SCENE_OUTCALL;
563                 if (isEmergencyCall)
564                 {
565                         nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
566                 }
567                 pSceneManager->GoForward( ForwardSceneTransition( nextScene,
568                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE, SCENE_HISTORY_OPTION_NO_HISTORY,SCENE_DESTROY_OPTION_DESTROY), pLaunchArgs);
569
570         }
571 }
572
573 int
574 CallPresentationModel::GetCurrentCallCount(void)
575 {
576         return __pTelephonyMgr->GetCurrentCallCount();
577 }
578
579 bool
580 CallPresentationModel::CheckSimInitializationIsCompleted()
581 {
582         result r = E_FAILURE;
583         if(__pTelephonyMgr != null)
584         {
585                 r = __pTelephonyMgr->CheckIfMOCallIsPossible();
586         }
587         return (!IsFailed(r));
588 }
589
590 bool
591 CallPresentationModel::IsEmergencyNumber(const Tizen::Base::String& phoneNumber, bool isSimInitialized)
592 {
593         return __pTelephonyMgr->CheckIfMOCallIsEmergency(phoneNumber, isSimInitialized);
594 }
595
596 void
597 CallPresentationModel::StartAlert(AppCallInfo& incomingCallInfo)
598 {
599         //Adding incoming call sate setting here
600         if(__pSettingsPresentor != null)
601         {
602                 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_CONNECTING);
603         }
604         __pTelephonyMgr->StartAlert(incomingCallInfo);
605 }
606
607 void
608 CallPresentationModel::StopAlert(void)
609 {
610         __pTelephonyMgr->StopAlert();
611 }
612
613 Contact*
614 CallPresentationModel::GetContactN(const String& phoneNumber)
615 {
616         return __pTelephonyMgr->GetContactN(phoneNumber);
617 }
618
619 AppCallInfo*
620 CallPresentationModel::FetchIncomingCallDetailsN(const String& callHandle, const String& contactNumber)
621 {
622
623         return __pTelephonyMgr->FetchIncomingCallHandleN(callHandle, contactNumber);
624 }
625
626 bool
627 CallPresentationModel::CheckIncomingCallToBeRejected(AppCallInfo* pIncomingCallInfo)
628 {
629         return __pTelephonyMgr->CheckIncomingCallToBeRejected(pIncomingCallInfo);
630 }
631
632 /////////////////////////////////////////////////////////////////
633 /////  Event Listener methods from ITelephonyEventListener  /////
634 /////////////////////////////////////////////////////////////////
635 void
636 CallPresentationModel::HandleCallConnected(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
637 {
638         if (__pTelEventListener != null)
639         {
640                 __pTelEventListener->HandleCallConnected(pCallList);
641         }
642         if(__pSettingsPresentor != null)
643         {
644                 __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
645         }
646 }
647
648 void
649 CallPresentationModel::HandleCallDisconnected(bool isLastCall, Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
650 {
651         AppLogDebug("Enter");
652         if (isLastCall == true)
653         {
654                 SetSpeakerStatus(false);
655                 SetMuteStatus(false);
656                 if(__pSettingsPresentor != null)
657                 {
658                         __pSettingsPresentor->SetCallState(CALL_STATE_CALL_OFF);
659                 }
660         }
661         else
662         {
663                 if(__pSettingsPresentor != null)
664                 {
665                         __pSettingsPresentor->SetCallState(CALL_STATE_CALL_VOICE_ACTIVE);
666                 }
667         }
668         //1) Defer from sending call disconnected event to form, in case Msg AppControl is running,
669         //to avoid PhoneApp from going to EndCall form, where it shows for 3 sec. and automatically closes.
670         //2) Do not send call disconnected event to any form, in case an incoming call or dialing call is present.
671         if (__pTelEventListener != null /*&& __isMessageAppControlRunning == false*/ )
672         {
673                 __pTelEventListener->HandleCallDisconnected(isLastCall, pCallList);
674         }
675 }
676
677 void
678 CallPresentationModel::HandleConferenceCall(AppCallInfo& pCallInfo)
679 {
680         if (__pTelEventListener != null)
681         {
682                 __pTelEventListener->HandleConferenceCall(pCallInfo);
683         }
684 }
685
686 void
687 CallPresentationModel::HandleIncomingCall(AppCallInfo& pCallInfo)
688 {
689         AppLogDebug("Error - This will never come here. Since, now we are getting incoming call event through AppControl!!");
690 }
691
692 void
693 CallPresentationModel::HandleCallSwapOccured(Tizen::Base::Collection::IListT<AppCallInfo>& pCallList)
694 {
695         if (__pTelEventListener != null)
696         {
697                 __pTelEventListener->HandleCallSwapOccured(pCallList);
698         }
699 }
700
701 void
702 CallPresentationModel::HandleConferenceChange(void)
703 {
704         //1) Do not send conf. call changed event to any form, in case an incoming call or dialing call is present.
705         if (__pTelEventListener != null)
706         {
707                 __pTelEventListener->HandleConferenceChange();
708         }
709 }
710
711 void
712 CallPresentationModel::HandleTelephonyError(int errorCode)
713 {
714         if (__pTelEventListener != null)
715         {
716                 __pTelEventListener->HandleTelephonyError(errorCode);
717         }
718 }
719
720 void
721 CallPresentationModel::LaunchDialAppControl()
722 {
723
724         if(__isDialAppControlRunning == true)
725         {
726                 AppLogDebug("__isDialAppControlRunning == true");
727                 //Do not allow another app control if already running
728                 return;
729         }
730
731         //Launch dialer AppControl
732         if (__pAppControlMgr != null)
733         {
734                 __isDialAppControlRunning = __pAppControlMgr->LaunchDialerAppControl(this);
735         }
736
737 }
738
739 bool
740 CallPresentationModel::IsEnableJoinCallButton(void)
741 {
742         //Check if conf. call has maximum participants
743         AppCallInfo* pConfCallInfo = GetConferenceCallInfoN();
744         if(pConfCallInfo != null && pConfCallInfo->GetCallerListCount() >= IDI_MAX_CONF_CALL_PARTICIPANTS)
745         {
746                 return false;
747         }
748
749         //check if either of the caller is same or present in conf call.
750         IListT<AppCallInfo>* pActiveCallList = GetCallListN();
751         if ( pActiveCallList != null && pActiveCallList->GetCount() == IDI_MAX_ACTIVE_CALLS)
752         {
753                 AppCallInfo firstCall;
754                 AppCallInfo secondCall;
755                 pActiveCallList->GetAt(0, firstCall);
756                 pActiveCallList->GetAt(1, secondCall);
757
758                 if (firstCall.IsConferenceCall() == true)
759                 {
760                         IListT<AppCallInfo>* pConfMemberList = firstCall.GetCallerList();
761                         for (int index = 0; index < pConfMemberList->GetCount(); index++)
762                         {
763                                 AppCallInfo singleConfMember;
764                                 pConfMemberList->GetAt(index, singleConfMember);
765                                 if (secondCall.GetContactNumber().IsEmpty() == false && secondCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
766                                 {
767                                         return false;
768                                 }
769                         }
770                 }
771                 else if (secondCall.IsConferenceCall() == true)
772                 {
773                         IListT<AppCallInfo>* pConfMemberList = secondCall.GetCallerList();
774                         for (int index = 0; index < pConfMemberList->GetCount(); index++)
775                         {
776                                 AppCallInfo singleConfMember;
777                                 pConfMemberList->GetAt(index, singleConfMember);
778                                 if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(singleConfMember.GetContactNumber()) == true)
779                                 {
780                                         return false;
781                                 }
782                         }
783                 }
784                 else
785                 {
786                         //Now, we definitely know that both are single active calls.
787                         if (firstCall.GetContactNumber().IsEmpty() == false && firstCall.GetContactNumber().Equals(secondCall.GetContactNumber()) == true)
788                         {
789                                 return false;
790                         }
791                 }
792         }
793         delete pConfCallInfo;
794         pConfCallInfo = null;
795         return true;
796 }
797
798 bool
799 CallPresentationModel::IsIncomingorDialingCallPresent(void)
800 {
801         //returns false, if incoming call or dialed call is present.
802         return __pTelephonyMgr->IsIncomingorDialingCallPresent();
803 }
804
805 bool
806 CallPresentationModel::LaunchComposeMessageAppControl(String& contactNumber, IAppControlResponseListener* pListener)
807 {
808         if (__pAppControlMgr != null)
809         {
810                 return __pAppControlMgr->LaunchComposeMessageAppControl(contactNumber, pListener);
811         }
812         return false;
813 }
814
815 bool
816 CallPresentationModel::LaunchViewContactAppControl(String& contactId, IAppControlResponseListener* pListener)
817 {
818         if (__pAppControlMgr != null)
819         {
820                 return __pAppControlMgr->LaunchViewContactAppControl(contactId, pListener);
821         }
822         return false;
823 }
824
825 bool
826 CallPresentationModel::LaunchAddContactAppControl(Tizen::Base::String& contactNumber, Tizen::App::IAppControlResponseListener* pListener)
827 {
828         if (__pAppControlMgr != null)
829         {
830                 return __pAppControlMgr->LaunchAddContactAppControl(contactNumber, pListener);
831         }
832         return false;
833 }
834
835 bool
836 CallPresentationModel::IsAppControlRunning(void)
837 {
838         if (__pAppControlMgr != null)
839         {
840                 return __pAppControlMgr->IsAppControlRunning();
841         }
842         return false;
843 }
844
845 void
846 CallPresentationModel::AbortAppControlRequest(void)
847 {
848         if (__pAppControlMgr != null)
849         {
850                 __pAppControlMgr->AbortAppControlRequest();
851         }
852 }
853
854 void
855 CallPresentationModel::AppControlRequestCompleted(void)
856 {
857         if (__pAppControlMgr != null)
858         {
859                 __pAppControlMgr->AppControlRequestCompleted();
860         }
861 }
862
863 result
864 CallPresentationModel::GetSimInfo(void)
865 {
866         __psimStateManager = new (std::nothrow)SimStateManager();
867         result r = __psimStateManager->Construct();
868         if (IsFailed(r))
869         {
870                 delete __psimStateManager;
871                 __psimStateManager = null;
872                 return E_FAILURE;
873         }
874         __psimStateManager->SetSimEventListener(this);
875
876         __psimInfo = new (std::nothrow)SimInfo();
877         r = __psimStateManager->GetSimInfo(*__psimInfo);
878         if (IsFailed(r))
879         {
880                 delete __psimStateManager;
881                 __psimStateManager = null;
882                 delete __psimInfo;
883                 __psimInfo = null;
884                 return E_FAILURE;
885         }
886         return E_SUCCESS;
887 }
888
889 void
890 CallPresentationModel::OnTelephonyNetworkStatusChanged(const NetworkStatus& networkStatus)
891 {
892
893 }
894
895 void
896 CallPresentationModel::OnTelephonySimStateChanged(Tizen::Telephony::SimState state)
897 {
898         if(__psimStateManager != null)
899         {
900                 delete __psimStateManager;
901                 __psimStateManager =null;
902         }
903         if(__psimInfo != null)
904         {
905                 delete __psimInfo;
906                 __psimInfo = null;
907         }
908
909         __psimStateManager = new SimStateManager();
910         result r = __psimStateManager->Construct();
911         if (IsFailed(r))
912         {
913                 delete __psimStateManager;
914                 __psimStateManager = null;
915                 return ;
916         }
917
918         __psimInfo = new SimInfo();
919         r = __psimStateManager->GetSimInfo(*__psimInfo);
920         if (IsFailed(r))
921         {
922                 delete __psimStateManager;
923                 __psimStateManager = null;
924                 delete __psimInfo;
925                 __psimInfo = null;
926                 return ;
927         }
928
929 }
930
931 bool
932 CallPresentationModel::IsSimAvailable(void)
933 {
934         if(__psimInfo != null)
935         {
936                 return __psimInfo->IsAvailable();
937         }
938         else
939         {
940                 return false;
941         }
942
943
944 }
945
946 void
947 CallPresentationModel::SendMessage(String& strMsg,String& recpientNum)
948 {
949         AppLogDebug("Enter");
950         result r;
951         if(__pSmsManager == null)
952         {
953                 __pSmsManager = new (std::nothrow) SmsManager();
954                 result r = __pSmsManager->Construct(*this);
955                 if (IsFailed(r) == true)
956                 {
957                         delete __pSmsManager;
958                         __pSmsManager = null;
959                         return;
960                 }
961
962         }
963         RecipientList recipient;
964         recipient.Add(RECIPIENT_TYPE_TO,recpientNum);
965         SmsMessage smsMessage;
966         r = smsMessage.SetText(strMsg);
967         if (IsFailed(r) == false)
968         {
969                 r = __pSmsManager->Send(smsMessage,recipient,true);
970                 if (IsFailed(r) == false)
971                 {
972                         __isMessageSendInProgress = true;
973                 }
974
975         }
976
977 }
978
979 bool
980 CallPresentationModel::IsMessageSendingInProgress(void)
981 {
982         AppLogDebug("Enter %d",__isMessageSendInProgress);
983         return __isMessageSendInProgress;
984 }
985
986 void
987 CallPresentationModel::OnSmsMessageSent(result r)
988 {
989         AppLogDebug("Enter");
990         __isMessageSendInProgress = false;
991
992 }