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);
53 CallApp::OnAppInitialized(void)
59 CallAppFrame* pCallAppFrame = new CallAppFrame();
60 pCallAppFrame->Construct();
61 pCallAppFrame->SetName(L"CallApp");
62 AddFrame(*pCallAppFrame);
64 //Check if there is no initial scene, then exit application.
65 //This case will normally come when invalid AppControl request has come,
66 //or incoming call is coming from unknown number and "reject unknown number" settings is enabled.
67 if (GetInitialScene().IsEmpty() == true)
76 CallApp::OnAppWillTerminate(void)
84 CallApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
87 // Deallocate resources allocated by this App for termination.
88 // The App's permanent data and context can be saved via appRegistry.
93 CallApp::OnForeground(void)
95 IEnumerator* pEnum = __listenerList.GetEnumeratorN();
96 while (pEnum->MoveNext() == E_SUCCESS)
98 IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
99 if (pInterface == null)
105 pInterface->OnForeground();
111 CallApp::OnBackground(void)
114 // Stop drawing when the application is moved to the background.
118 CallApp::OnLowMemory(void)
121 // Free unused resources or close the application.
125 CallApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
128 // Handle any changes in battery level here.
129 // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
133 CallApp::OnScreenOn(void)
136 // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
140 CallApp::OnScreenOff(void)
143 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
144 // to enter the sleep mode to save the battery.
145 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
146 // callback before the device enters the sleep mode.
147 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
151 CallApp::GetInitialScene(void)
153 return __initialSceneId;
157 CallApp::GetAppLaunchArguments(void)
159 return __pLaunchArgs;
163 CallApp::AddAppStateChangeListener(const IAppStateChangeListener& listener)
165 __listenerList.Add(listener);
169 CallApp::RemoveAppStateChangeListener(const IAppStateChangeListener& listener)
171 __listenerList.Remove(listener);
175 CallApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData,
176 const String* pMimeType, const IMap* pExtraData)
178 AppLogDebug("Enter ");
181 AppLogDebug("%ls ",pUriData->GetPointer());
184 if(pExtraData == null && pUriData != null)
186 //The request is from web app
187 AppLogDebug("%ls",pUriData->GetPointer());
188 ProcessWebAppControlRequest(reqId, operationId, pUriData);
192 //process AppControl parameters
193 ProcessAppControlRequest(reqId, operationId, pExtraData,pUriData);
199 CallApp::ProcessWebAppControlRequest(RequestId reqId, const String& operationId,const String* pUriData)
201 //Construct map from string
202 String delim(DELIMITER);
203 StringTokenizer st(*pUriData,delim);
206 extraData.Construct();
207 while(st.HasMoreTokens())
211 st.GetNextToken(token);
214 if(st.HasMoreTokens())
217 st.GetNextToken(token);
221 extraData.Add(new (std::nothrow) String(key), new (std::nothrow) String(value));
224 //Adding this explicitly as there no other way to invoke call from webapp
225 extraData.Add(new (std::nothrow) String(PARAM_CALL_TYPE), new (std::nothrow) String(PARAM_CALL_VALUE_VOICE));
227 ProcessAppControlRequest(reqId,operationId,&extraData);
229 extraData.RemoveAll(true);
233 CallApp::ProcessAppControlRequest(RequestId reqId, const String& operationId,const IMap* pArgsMap,const String* pUriData)
235 AppLogDebug("Enter %ls",operationId.GetPointer());
236 __pLaunchArgs = null;
237 if(operationId.Equals(OPERATION_ID_CALL,true) == true)
239 AppLogDebug("OPERATION_ID_CALL");
242 bool isIncomingCallRequest = false;
243 String* pKey = new (std::nothrow) String(LAUNCHTYPE);
244 if (pArgsMap->ContainsKey(*pKey) == true)
246 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
247 if ((pValue != null) && (pValue->Equals(PARAM_ORIGIN_MT, true) == true))
249 isIncomingCallRequest = true;
252 //Check if incoming call request or outgoing call request
253 if(isIncomingCallRequest == true)
255 HandleIncomingCallAppControlRequest(reqId, pArgsMap);
259 HandleDialCallAppControlRequest(reqId, pArgsMap,pUriData);
264 AppLogDebug("pArgsMap == null");
270 CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
272 AppLogDebug("Enter");
273 SceneManager* pSceneManager = SceneManager::GetInstance();
275 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
278 String callHandle(L"");
279 String* pKey = new (std::nothrow) String(CALL_HANDLE);
280 if (pArgsMap->ContainsKey(*pKey) == true)
282 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
285 callHandle.Append(*pValue);
290 String contactNumber(L"");
291 pKey = new (std::nothrow) String(CONTACT_NUMBER);
292 if (pArgsMap->ContainsKey(*pKey) == true)
294 const String* pContactValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
295 if (pContactValue != null)
297 contactNumber.Append(*pContactValue);
298 AppLogDebug("%ls",contactNumber.GetPointer());
304 //Fetch incoming call details
305 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
306 AppCallInfo* pIncomingCall = pCallPresentor->FetchIncomingCallDetailsN(callHandle, contactNumber);
307 if(pIncomingCall != null)
309 bool isCallRejected = pCallPresentor->CheckIncomingCallToBeRejected(pIncomingCall);
310 if(isCallRejected == false)
312 //save app launch argument list
313 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
314 __pLaunchArgs->Construct(1);
315 __pLaunchArgs->Add(pIncomingCall);
316 if(__initialSceneId.IsEmpty() == true)
318 __initialSceneId = IDSCN_SCENE_INCOMINGCALL;
322 //App already initialized, goto incoming call form
323 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), __pLaunchArgs);
324 __pLaunchArgs = null;
329 //Show messageBox showing automatic call rejection
330 /* MessageBox callRejectedInoMsgBox;
331 String msg(L"Call From ");
332 msg.Append(contactNumber);
333 msg.Append(L" Rejected.");
334 callRejectedInoMsgBox.Construct(L"Call Rejected", msg, MSGBOX_STYLE_NONE,1000);
336 // Calls ShowAndWait() : Draws and Shows itself and processes events
337 callRejectedInoMsgBox.ShowAndWait(modalResult);*/
339 //go back to previous scene if App was already running, else exit application.
340 if(__initialSceneId.IsEmpty() == true)
342 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
343 AppLog("Terminate Phone Application");
348 //set success message
349 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
353 appControlResult = APP_CTRL_RESULT_FAILED;
355 AppLogDebug("Exiting %d",appControlResult);
356 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
360 CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,const String* pUriData)
363 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
365 if (pArgsMap != null)
367 String callType(L"");
368 String phoneNumber(L"");
370 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
371 if(pArgsMap->ContainsKey(*pKey) == true)
373 const String* pPhoneValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
374 if(pPhoneValue != null)
376 AppLogDebug("%ls",pPhoneValue->GetPointer());
377 phoneNumber.Append(*pPhoneValue);
382 AppLogDebug("PARAM_PHONE_NUMBER not present");
383 //Now check if tel uri is present
386 AppLogDebug("pUriData is present %ls",pUriData->GetPointer());
387 phoneNumber.Append(*pUriData);
388 if(phoneNumber.Contains(PARAM_PHONE_NUMBER))
390 phoneNumber.Replace(PARAM_PHONE_NUMBER,L"");
391 if(phoneNumber.Contains(DELIMITER))
393 phoneNumber.Replace(DELIMITER,L"");
394 AppLogDebug("%ls",phoneNumber.GetPointer());
397 AppLogDebug("%ls",phoneNumber.GetPointer());
401 //Check if its a valid number
402 if(CheckNumberIsValid(phoneNumber) == false)
404 //go back to previous scene if App was already running, else exit application.
405 if(__initialSceneId.IsEmpty() == true)
407 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
408 AppLog("Terminate Phone Application");
409 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
416 pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
417 if(pArgsMap->ContainsKey(*pKey) == true)
419 const String* pCallTypeValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
420 if(pCallTypeValue != null)
422 callType.Append(*pCallTypeValue);
428 //Fetch currently active call count
429 if (callType.IsEmpty() == false
430 && callType.Equals(PARAM_CALL_VALUE_VOICE, false) == true
431 && phoneNumber.IsEmpty() == false)
433 SceneManager* pSceneManager = SceneManager::GetInstance();
434 //check if there is already a call in dialing mode, then dont accept any other dialing request.
435 if (pSceneManager->GetCurrentSceneId() == IDSCN_SCENE_OUTCALL
436 || pSceneManager->GetCurrentSceneId()
437 == IDSCN_SCENE_OUT_EMERGENCYCALL)
440 appControlResult = APP_CTRL_RESULT_CANCELED;
441 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
444 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
445 int currentActiveCallCount = pCallPresentor->GetCurrentCallCount();
446 if(currentActiveCallCount <= 1)
448 //make an outgoing call with given number
449 String* contactTxt = new (std::nothrow) String(phoneNumber);
450 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
451 __pLaunchArgs->Construct();
452 __pLaunchArgs->Add(contactTxt);
453 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
455 SceneId nextScene = IDSCN_SCENE_OUTCALL;
458 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
460 //Check if app was already running
461 if(__initialSceneId.IsEmpty() == true)
463 //phone App is not already launched
464 __initialSceneId = nextScene;
468 AppLog("Outgoing call");
469 pSceneManager->GoForward( ForwardSceneTransition( nextScene), __pLaunchArgs);
471 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
475 //already 2 active calls, 3rd call not allowed
476 appControlResult = APP_CTRL_RESULT_CANCELED;
481 appControlResult = APP_CTRL_RESULT_FAILED;
484 //send response message
485 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
489 CallApp::CheckNumberIsValid(String phoneNumber)
491 //Pattern to compare all characters except 0-9 * # P ; , +
492 String phoneNumberPattern(L"[^0-9*#P,+;]");
493 RegularExpression checkPhoneNumber;
494 checkPhoneNumber.Construct(phoneNumberPattern);
495 //If there is any character other than these listed above then display invalid number
496 bool resultMatch = checkPhoneNumber.Match(phoneNumber,false);
497 //return false for patterns other than 0-9 * # P ; , +
503 CallApp::SetTopMostWindow(bool bTopMost)
505 AppLogDebug("bTopMost = %d",bTopMost);
506 result res = E_FAILURE;
507 //ToDO: Need to see if there is better way to handle
512 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_HIGHEST);
513 if(PowerManager::IsScreenOn() == false)
515 AppLogDebug("TurnScreenOn");
516 res = PowerManager::TurnScreenOn();
517 AppLogDebug("TurnScreenOn %d",res);
519 AppManager::GetInstance()->AddActiveAppEventListener(*this);
524 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_NORMAL);
525 PowerManager::KeepScreenOnState(false);
526 AppManager::GetInstance()->RemoveActiveAppEventListener(*this);
528 //Unlock the phone if its locked
529 /* if(LockManager::GetInstance()->IsLocked())
531 AppLogDebug("Phone Locked");
532 LockManager::GetInstance()->Unlock();
537 CallApp::OnActiveAppChanged(const String& appId)
539 AppLogDebug("Enter %ls",appId.GetPointer());
540 if(GetAppId().Equals(appId) == true)
542 result res = PowerManager::KeepScreenOnState(true,false);
543 AppLogDebug("KeepScreenOnState %d",res);