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