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;
26 using namespace Tizen::Shell;
29 CallApp::CallApp(void):__initialSceneId(L""), __pLaunchArgs(null)
31 __listenerList.Construct();
34 CallApp::~CallApp(void)
39 CallApp::CreateInstance(void)
41 // Create the instance through the constructor.
46 CallApp::OnAppInitializing(AppRegistry& appRegistry)
48 AppControlProviderManager* pProviderMgr = AppControlProviderManager::GetInstance();
49 pProviderMgr->SetAppControlProviderEventListener(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.
94 CallApp::OnForeground(void)
96 IEnumerator* pEnum = __listenerList.GetEnumeratorN();
97 while (pEnum->MoveNext() == E_SUCCESS)
99 IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
100 if (pInterface == null)
106 pInterface->OnForeground();
112 CallApp::OnBackground(void)
115 // Stop drawing when the application is moved to the background.
119 CallApp::OnLowMemory(void)
122 // Free unused resources or close the application.
126 CallApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
129 // Handle any changes in battery level here.
130 // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
134 CallApp::OnScreenOn(void)
137 // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
141 CallApp::OnScreenOff(void)
144 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
145 // to enter the sleep mode to save the battery.
146 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
147 // callback before the device enters the sleep mode.
148 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
152 CallApp::GetInitialScene(void)
154 return __initialSceneId;
158 CallApp::GetAppLaunchArguments(void)
160 return __pLaunchArgs;
164 CallApp::AddAppStateChangeListener(const IAppStateChangeListener& listener)
166 __listenerList.Add(listener);
170 CallApp::RemoveAppStateChangeListener(const IAppStateChangeListener& listener)
172 __listenerList.Remove(listener);
176 CallApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData,
177 const String* pMimeType, const IMap* pExtraData)
179 if(pExtraData == null && pUriData != null)
181 //The request is from web app
182 AppLogDebug("%ls",pUriData->GetPointer());
183 ProcessWebAppControlRequest(reqId, operationId, pUriData);
187 //process AppControl parameters
188 ProcessAppControlRequest(reqId, operationId, pExtraData);
194 CallApp::ProcessWebAppControlRequest(RequestId reqId, const String& operationId,const String* pUriData)
196 //Construct map from string
197 String delim(DELIMITER);
198 StringTokenizer st(*pUriData,delim);
201 extraData.Construct();
202 while(st.HasMoreTokens())
206 st.GetNextToken(token);
209 if(st.HasMoreTokens())
212 st.GetNextToken(token);
216 extraData.Add(new (std::nothrow) String(key), new (std::nothrow) String(value));
219 //Adding this explicitly as there no other way to invoke call from webapp
220 extraData.Add(new (std::nothrow) String(PARAM_CALL_TYPE), new (std::nothrow) String(PARAM_CALL_VALUE_VOICE));
222 ProcessAppControlRequest(reqId,operationId,&extraData);
224 extraData.RemoveAll(true);
228 CallApp::ProcessAppControlRequest(RequestId reqId, const String& operationId,const IMap* pArgsMap)
230 AppLogDebug("Enter %ls",operationId.GetPointer());
231 __pLaunchArgs = null;
232 if(operationId.Equals(OPERATION_ID_CALL,true) == true)
234 AppLogDebug("OPERATION_ID_CALL");
237 bool isIncomingCallRequest = false;
238 String* pKey = new (std::nothrow) String(LAUNCHTYPE);
239 if (pArgsMap->ContainsKey(*pKey) == true)
241 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
242 if ((pValue != null) && (pValue->Equals(PARAM_ORIGIN_MT, true) == true))
244 isIncomingCallRequest = true;
247 //Check if incoming call request or outgoing call request
248 if(isIncomingCallRequest == true)
250 HandleIncomingCallAppControlRequest(reqId, pArgsMap);
254 HandleDialCallAppControlRequest(reqId, pArgsMap);
259 AppLogDebug("pArgsMap == null");
265 CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
267 AppLogDebug("Enter");
268 SceneManager* pSceneManager = SceneManager::GetInstance();
270 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
273 String callHandle(L"");
274 String* pKey = new (std::nothrow) String(CALL_HANDLE);
275 if (pArgsMap->ContainsKey(*pKey) == true)
277 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
280 callHandle.Append(*pValue);
285 String contactNumber(L"");
286 pKey = new (std::nothrow) String(CONTACT_NUMBER);
287 if (pArgsMap->ContainsKey(*pKey) == true)
289 const String* pContactValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
290 if (pContactValue != null)
292 contactNumber.Append(*pContactValue);
293 AppLogDebug("%ls",contactNumber.GetPointer());
299 //Fetch incoming call details
300 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
301 CallInfo* pIncomingCall = pCallPresentor->FetchIncomingCallDetailsN(callHandle, contactNumber);
302 if(pIncomingCall != null)
304 bool isCallRejected = pCallPresentor->CheckIncomingCallToBeRejected(pIncomingCall);
305 if(isCallRejected == false)
307 //save app launch argument list
308 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
309 __pLaunchArgs->Construct(1);
310 __pLaunchArgs->Add(pIncomingCall);
311 if(__initialSceneId.IsEmpty() == true)
313 __initialSceneId = IDSCN_SCENE_INCOMINGCALL;
317 //App already initialized, goto incoming call form
318 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), __pLaunchArgs);
319 __pLaunchArgs = null;
324 //Show messageBox showing automatic call rejection
325 MessageBox callRejectedInoMsgBox;
326 String msg(L"Call From ");
327 msg.Append(contactNumber);
328 msg.Append(L" Rejected.");
329 callRejectedInoMsgBox.Construct(L"Call Rejected", msg, MSGBOX_STYLE_NONE,1000);
331 // Calls ShowAndWait() : Draws and Shows itself and processes events
332 callRejectedInoMsgBox.ShowAndWait(modalResult);
334 //go back to previous scene if App was already running, else exit application.
335 if(__initialSceneId.IsEmpty() == true)
337 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
338 AppLog("Terminate Phone Application");
343 //set success message
344 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
348 appControlResult = APP_CTRL_RESULT_FAILED;
350 AppLogDebug("Exiting %d",appControlResult);
351 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
355 CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
358 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
360 if (pArgsMap != null)
362 String callType(L"");
363 String phoneNumber(L"");
365 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
366 if(pArgsMap->ContainsKey(*pKey) == true)
368 const String* pPhoneValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
369 if(pPhoneValue != null)
371 AppLogDebug("%ls",pPhoneValue->GetPointer());
372 phoneNumber.Append(*pPhoneValue);
377 AppLogDebug("PARAM_PHONE_NUMBER not present");
380 //Check if its a valid number
381 if(CheckNumberIsValid(phoneNumber) == false)
383 //Show messageBox showing automatic call rejection
384 MessageBox InvalidNumberMsgBox;
385 InvalidNumberMsgBox.Construct(AppUtility::GetResourceString(IDS_INVALID_NUMBER), L"",MSGBOX_STYLE_NONE,1000);
387 // Calls ShowAndWait() : Draws and Shows itself and processes events
388 InvalidNumberMsgBox.ShowAndWait(modalResult);
390 //go back to previous scene if App was already running, else exit application.
391 if(__initialSceneId.IsEmpty() == true)
393 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
394 AppLog("Terminate Phone Application");
395 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
402 pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
403 if(pArgsMap->ContainsKey(*pKey) == true)
405 const String* pCallTypeValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
406 if(pCallTypeValue != null)
408 callType.Append(*pCallTypeValue);
414 //Fetch currently active call count
415 if (callType.IsEmpty() == false
416 && callType.Equals(PARAM_CALL_VALUE_VOICE, false) == true
417 && phoneNumber.IsEmpty() == false)
419 SceneManager* pSceneManager = SceneManager::GetInstance();
420 //check if there is already a call in dialing mode, then dont accept any other dialing request.
421 if (pSceneManager->GetCurrentSceneId() == IDSCN_SCENE_OUTCALL
422 || pSceneManager->GetCurrentSceneId()
423 == IDSCN_SCENE_OUT_EMERGENCYCALL)
426 appControlResult = APP_CTRL_RESULT_CANCELED;
427 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
430 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
431 int currentActiveCallCount = pCallPresentor->GetCurrentCallCount();
432 if(currentActiveCallCount <= 1)
434 //make an outgoing call with given number
435 String* contactTxt = new (std::nothrow) String(phoneNumber);
436 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
437 __pLaunchArgs->Construct();
438 __pLaunchArgs->Add(contactTxt);
439 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
441 SceneId nextScene = IDSCN_SCENE_OUTCALL;
444 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
446 //Check if app was already running
447 if(__initialSceneId.IsEmpty() == true)
449 //phone App is not already launched
450 __initialSceneId = nextScene;
454 AppLog("Outgoing call");
455 pSceneManager->GoForward( ForwardSceneTransition( nextScene), __pLaunchArgs);
457 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
461 //already 2 active calls, 3rd call not allowed
462 appControlResult = APP_CTRL_RESULT_CANCELED;
467 appControlResult = APP_CTRL_RESULT_FAILED;
470 //send response message
471 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
475 CallApp::CheckNumberIsValid(String phoneNumber)
477 //Pattern to compare all characters except 0-9 * # P ; , +
478 String phoneNumberPattern(L"[^0-9*#P,+]");
479 RegularExpression checkPhoneNumber;
480 checkPhoneNumber.Construct(phoneNumberPattern);
481 //If there is any character other than these listed above then display invalid number
482 bool resultMatch = checkPhoneNumber.Match(phoneNumber,false);
483 //return false for patterns other than 0-9 * # P ; , +
489 CallApp::SetTopMostWindow(bool bTopMost)
491 AppLogDebug("bTopMost = %d",bTopMost);
492 result res = E_FAILURE;
493 //ToDO: Need to see if there is better way to handle
497 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_HIGHEST);
498 if(PowerManager::IsScreenOn() == false)
500 res = PowerManager::TurnScreenOn();
502 res = PowerManager::KeepScreenOnState(true,false);
507 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_NORMAL);
508 PowerManager::KeepScreenOnState(false);