11 #include "CallAppFrame.h"
12 #include "CallPresentationModel.h"
13 #include "CallTypes.h"
14 #include "CallAppUtility.h"
15 #include "CallIAppStateChangeListner.h"
17 using namespace Tizen::App;
18 using namespace Tizen::Base;
19 using namespace Tizen::System;
20 using namespace Tizen::Ui;
21 using namespace Tizen::Ui::Controls;
22 using namespace Tizen::Ui::Scenes;
23 using namespace Tizen::Base::Utility;
24 using namespace Tizen::Base::Collection;
25 using namespace Tizen::Base::Utility;
28 CallApp::CallApp(void):__initialSceneId(L""), __pLaunchArgs(null)
30 __listenerList.Construct();
33 CallApp::~CallApp(void)
38 CallApp::CreateInstance(void)
40 // Create the instance through the constructor.
45 CallApp::OnAppInitializing(AppRegistry& appRegistry)
47 AppControlProviderManager* pProviderMgr = AppControlProviderManager::GetInstance();
48 pProviderMgr->SetAppControlProviderEventListener(this);
49 PowerManager::AddScreenEventListener(*this);
54 CallApp::OnAppInitialized(void)
60 CallAppFrame* pCallAppFrame = new CallAppFrame();
61 pCallAppFrame->Construct();
62 pCallAppFrame->SetName(L"CallApp");
63 AddFrame(*pCallAppFrame);
65 //Check if there is no initial scene, then exit application.
66 //This case will normally come when invalid AppControl request has come,
67 //or incoming call is coming from unknown number and "reject unknown number" settings is enabled.
68 if (GetInitialScene().IsEmpty() == true)
77 CallApp::OnAppWillTerminate(void)
85 CallApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
88 // Deallocate resources allocated by this App for termination.
89 // The App's permanent data and context can be saved via appRegistry.
90 PowerManager::RemoveScreenEventListener(*this);
95 CallApp::OnForeground(void)
97 IEnumerator* pEnum = __listenerList.GetEnumeratorN();
98 while (pEnum->MoveNext() == E_SUCCESS)
100 IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
101 if (pInterface == null)
107 pInterface->OnForeground();
113 CallApp::OnBackground(void)
116 // Stop drawing when the application is moved to the background.
120 CallApp::OnLowMemory(void)
123 // Free unused resources or close the application.
127 CallApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
130 // Handle any changes in battery level here.
131 // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
135 CallApp::OnScreenOn(void)
138 // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
142 CallApp::OnScreenOff(void)
144 AppLogDebug("Enter");
145 IEnumerator* pEnum = __listenerList.GetEnumeratorN();
146 while (pEnum->MoveNext() == E_SUCCESS)
148 IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
149 if (pInterface == null)
155 pInterface->OnScreenOff();
162 CallApp::GetInitialScene(void)
164 return __initialSceneId;
168 CallApp::GetAppLaunchArguments(void)
170 return __pLaunchArgs;
174 CallApp::AddAppStateChangeListener(const IAppStateChangeListener& listener)
176 __listenerList.Add(listener);
180 CallApp::RemoveAppStateChangeListener(const IAppStateChangeListener& listener)
182 __listenerList.Remove(listener);
186 CallApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData,
187 const String* pMimeType, const IMap* pExtraData)
189 AppLogDebug("Enter ");
192 AppLogDebug("%ls ",pUriData->GetPointer());
195 if(pExtraData == null && pUriData != null)
197 //The request is from web app
198 AppLogDebug("%ls",pUriData->GetPointer());
199 ProcessWebAppControlRequest(reqId, operationId, pUriData);
203 //process AppControl parameters
204 ProcessAppControlRequest(reqId, operationId, pExtraData,pUriData);
210 CallApp::ProcessWebAppControlRequest(RequestId reqId, const String& operationId,const String* pUriData)
212 //Construct map from string
213 String delim(DELIMITER);
214 StringTokenizer st(*pUriData,delim);
217 extraData.Construct();
218 while(st.HasMoreTokens())
222 st.GetNextToken(token);
225 if(st.HasMoreTokens())
228 st.GetNextToken(token);
232 extraData.Add(new (std::nothrow) String(key), new (std::nothrow) String(value));
235 //Adding this explicitly as there no other way to invoke call from webapp
236 extraData.Add(new (std::nothrow) String(PARAM_CALL_TYPE), new (std::nothrow) String(PARAM_CALL_VALUE_VOICE));
238 ProcessAppControlRequest(reqId,operationId,&extraData);
240 extraData.RemoveAll(true);
244 CallApp::ProcessAppControlRequest(RequestId reqId, const String& operationId,const IMap* pArgsMap,const String* pUriData)
246 AppLogDebug("Enter %ls",operationId.GetPointer());
247 __pLaunchArgs = null;
248 if(operationId.Equals(OPERATION_ID_CALL,true) == true)
250 AppLogDebug("OPERATION_ID_CALL");
253 bool isIncomingCallRequest = false;
254 String* pKey = new (std::nothrow) String(LAUNCHTYPE);
255 if (pArgsMap->ContainsKey(*pKey) == true)
257 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
258 if ((pValue != null) && (pValue->Equals(PARAM_ORIGIN_MT, true) == true))
260 isIncomingCallRequest = true;
263 //Check if incoming call request or outgoing call request
264 if(isIncomingCallRequest == true)
266 HandleIncomingCallAppControlRequest(reqId, pArgsMap);
270 HandleDialCallAppControlRequest(reqId, pArgsMap,pUriData);
275 AppLogDebug("pArgsMap == null");
281 CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
283 AppLogDebug("Enter");
284 SceneManager* pSceneManager = SceneManager::GetInstance();
286 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
289 String callHandle(L"");
290 String* pKey = new (std::nothrow) String(CALL_HANDLE);
291 if (pArgsMap->ContainsKey(*pKey) == true)
293 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
296 callHandle.Append(*pValue);
301 String contactNumber(L"");
302 pKey = new (std::nothrow) String(CONTACT_NUMBER);
303 if (pArgsMap->ContainsKey(*pKey) == true)
305 const String* pContactValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
306 if (pContactValue != null)
308 contactNumber.Append(*pContactValue);
309 AppLogDebug("%ls",contactNumber.GetPointer());
315 //Fetch incoming call details
316 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
317 AppCallInfo* pIncomingCall = pCallPresentor->FetchIncomingCallDetailsN(callHandle, contactNumber);
318 if(pIncomingCall != null)
320 bool isCallRejected = pCallPresentor->CheckIncomingCallToBeRejected(pIncomingCall);
321 if(isCallRejected == false)
323 //Abort any AppControl Request running already to show incoming call screen
324 if (pCallPresentor->IsAppControlRunning() == true)
326 pCallPresentor->AbortAppControlRequest();
328 //save app launch argument list
329 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
330 __pLaunchArgs->Construct(1);
331 __pLaunchArgs->Add(pIncomingCall);
332 if(__initialSceneId.IsEmpty() == true)
334 __initialSceneId = IDSCN_SCENE_INCOMINGCALL;
338 //App already initialized, goto incoming call form
339 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), __pLaunchArgs);
340 __pLaunchArgs = null;
345 //Show messageBox showing automatic call rejection
346 /*MessageBox callRejectedInoMsgBox;
347 String msg(L"Call From ");
348 msg.Append(contactNumber);
349 msg.Append(L" Rejected.");
350 callRejectedInoMsgBox.Construct(L"Call Rejected", msg, MSGBOX_STYLE_NONE,1000);
352 // Calls ShowAndWait() : Draws and Shows itself and processes events
353 callRejectedInoMsgBox.ShowAndWait(modalResult);*/
355 //go back to previous scene if App was already running, else exit application.
356 if(__initialSceneId.IsEmpty() == true)
358 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
359 AppLog("Terminate Phone Application");
363 //set success message
364 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
368 appControlResult = APP_CTRL_RESULT_FAILED;
370 AppLogDebug("Exiting %d",appControlResult);
371 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
375 CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,const String* pUriData)
378 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
380 if (pArgsMap != null)
382 String callType(L"");
383 String phoneNumber(L"");
385 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
386 if(pArgsMap->ContainsKey(*pKey) == true)
388 const String* pPhoneValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
389 if(pPhoneValue != null)
391 AppLogDebug("%ls",pPhoneValue->GetPointer());
392 phoneNumber.Append(*pPhoneValue);
397 AppLogDebug("PARAM_PHONE_NUMBER not present");
398 //Now check if tel uri is present
401 AppLogDebug("pUriData is present %ls",pUriData->GetPointer());
402 phoneNumber.Append(*pUriData);
403 if(phoneNumber.Contains(PARAM_PHONE_NUMBER))
405 phoneNumber.Replace(PARAM_PHONE_NUMBER,L"");
406 if(phoneNumber.Contains(DELIMITER))
408 phoneNumber.Replace(DELIMITER,L"");
409 AppLogDebug("%ls",phoneNumber.GetPointer());
412 AppLogDebug("%ls",phoneNumber.GetPointer());
416 //Check if its a valid number
417 if(CheckNumberIsValid(phoneNumber) == false)
419 //go back to previous scene if App was already running, else exit application.
420 if(__initialSceneId.IsEmpty() == true)
422 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
423 AppLog("Terminate Phone Application");
424 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
430 pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
431 if(pArgsMap->ContainsKey(*pKey) == true)
433 const String* pCallTypeValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
434 if(pCallTypeValue != null)
436 callType.Append(*pCallTypeValue);
442 //Fetch currently active call count
443 if (callType.IsEmpty() == false
444 && callType.Equals(PARAM_CALL_VALUE_VOICE, false) == true
445 && phoneNumber.IsEmpty() == false)
447 SceneManager* pSceneManager = SceneManager::GetInstance();
448 //check if there is already a call in dialing mode, then dont accept any other dialing request.
449 if (pSceneManager->GetCurrentSceneId() == IDSCN_SCENE_OUTCALL
450 || pSceneManager->GetCurrentSceneId()
451 == IDSCN_SCENE_OUT_EMERGENCYCALL)
454 appControlResult = APP_CTRL_RESULT_CANCELED;
455 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
458 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
459 int currentActiveCallCount = pCallPresentor->GetCurrentCallCount();
460 if(currentActiveCallCount <= 1)
462 //Abort any AppControl Request running already to show incoming call screen
463 if (pCallPresentor->IsAppControlRunning() == true)
465 pCallPresentor->AbortAppControlRequest();
467 //make an outgoing call with given number
468 String* contactTxt = new (std::nothrow) String(phoneNumber);
469 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
470 __pLaunchArgs->Construct();
471 __pLaunchArgs->Add(contactTxt);
472 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
474 SceneId nextScene = IDSCN_SCENE_OUTCALL;
477 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
479 //Check if app was already running
480 if(__initialSceneId.IsEmpty() == true)
482 //phone App is not already launched
483 __initialSceneId = nextScene;
487 AppLog("Outgoing call");
488 pSceneManager->GoForward( ForwardSceneTransition( nextScene), __pLaunchArgs);
490 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
494 //already 2 active calls, 3rd call not allowed
495 appControlResult = APP_CTRL_RESULT_CANCELED;
500 appControlResult = APP_CTRL_RESULT_FAILED;
503 //send response message
504 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
508 CallApp::CheckNumberIsValid(String phoneNumber)
510 //Pattern to compare all characters except 0-9 * # P ; , +
511 String phoneNumberPattern(L"[^0-9*#P,p+;]");
512 String phoneNumberEndingWithHash(L"#$");
513 RegularExpression checkPhoneNumber,checkHash;
514 checkPhoneNumber.Construct(phoneNumberPattern);
515 checkHash.Construct(phoneNumberEndingWithHash);
516 //If there is any character other than these listed above then display invalid number
517 bool resultMatch = checkPhoneNumber.Match(phoneNumber,false);
518 //return false for patterns other than 0-9 * # P ; , +
519 bool endsWithHash = checkHash.Match(phoneNumber,false);
520 //returns false for any numbers that end with Hash
521 if(resultMatch == true || endsWithHash == true)
523 //return phone number is invalid
532 CallApp::SetTopMostWindow(bool bTopMost)
534 AppLogDebug("bTopMost = %d",bTopMost);
535 result res = E_FAILURE;
536 //ToDO: Need to see if there is better way to handle
541 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_HIGHEST);
542 if(PowerManager::IsScreenOn() == false)
544 AppLogDebug("TurnScreenOn");
545 res = PowerManager::TurnScreenOn();
546 AppLogDebug("TurnScreenOn %d",res);
548 AppManager::GetInstance()->AddActiveAppEventListener(*this);
553 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_NORMAL);
554 PowerManager::KeepScreenOnState(false);
555 AppManager::GetInstance()->RemoveActiveAppEventListener(*this);
557 //Unlock the phone if its locked
558 /* if(LockManager::GetInstance()->IsLocked())
560 AppLogDebug("Phone Locked");
561 LockManager::GetInstance()->Unlock();
566 CallApp::OnActiveAppChanged(const String& appId)
568 AppLogDebug("Enter %ls",appId.GetPointer());
569 if(GetAppId().Equals(appId) == true)
571 result res = PowerManager::KeepScreenOnState(true,false);
572 AppLogDebug("KeepScreenOnState %d",res);