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 AppLogDebug("Enter");
180 if(pExtraData == null && pUriData != null)
182 //The request is from web app
183 AppLogDebug("%ls",pUriData->GetPointer());
184 ProcessWebAppControlRequest(reqId, operationId, pUriData);
188 //process AppControl parameters
189 ProcessAppControlRequest(reqId, operationId, pExtraData);
195 CallApp::ProcessWebAppControlRequest(RequestId reqId, const String& operationId,const String* pUriData)
197 //Construct map from string
198 String delim(DELIMITER);
199 StringTokenizer st(*pUriData,delim);
202 extraData.Construct();
203 while(st.HasMoreTokens())
207 st.GetNextToken(token);
210 if(st.HasMoreTokens())
213 st.GetNextToken(token);
217 extraData.Add(new (std::nothrow) String(key), new (std::nothrow) String(value));
220 //Adding this explicitly as there no other way to invoke call from webapp
221 extraData.Add(new (std::nothrow) String(PARAM_CALL_TYPE), new (std::nothrow) String(PARAM_CALL_VALUE_VOICE));
223 ProcessAppControlRequest(reqId,operationId,&extraData);
225 extraData.RemoveAll(true);
229 CallApp::ProcessAppControlRequest(RequestId reqId, const String& operationId,const IMap* pArgsMap)
231 AppLogDebug("Enter %ls",operationId.GetPointer());
232 __pLaunchArgs = null;
233 if(operationId.Equals(OPERATION_ID_CALL,true) == true)
235 AppLogDebug("OPERATION_ID_CALL");
238 bool isIncomingCallRequest = false;
239 String* pKey = new (std::nothrow) String(LAUNCHTYPE);
240 if (pArgsMap->ContainsKey(*pKey) == true)
242 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
243 if ((pValue != null) && (pValue->Equals(PARAM_ORIGIN_MT, true) == true))
245 isIncomingCallRequest = true;
248 //Check if incoming call request or outgoing call request
249 if(isIncomingCallRequest == true)
251 HandleIncomingCallAppControlRequest(reqId, pArgsMap);
255 HandleDialCallAppControlRequest(reqId, pArgsMap);
260 AppLogDebug("pArgsMap == null");
266 CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
268 AppLogDebug("Enter");
269 SceneManager* pSceneManager = SceneManager::GetInstance();
271 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
274 String callHandle(L"");
275 String* pKey = new (std::nothrow) String(CALL_HANDLE);
276 if (pArgsMap->ContainsKey(*pKey) == true)
278 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
281 callHandle.Append(*pValue);
286 String contactNumber(L"");
287 pKey = new (std::nothrow) String(CONTACT_NUMBER);
288 if (pArgsMap->ContainsKey(*pKey) == true)
290 const String* pContactValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
291 if (pContactValue != null)
293 contactNumber.Append(*pContactValue);
294 AppLogDebug("%ls",contactNumber.GetPointer());
300 //Fetch incoming call details
301 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
302 AppCallInfo* pIncomingCall = pCallPresentor->FetchIncomingCallDetailsN(callHandle, contactNumber);
303 if(pIncomingCall != null)
305 bool isCallRejected = pCallPresentor->CheckIncomingCallToBeRejected(pIncomingCall);
306 if(isCallRejected == false)
308 //save app launch argument list
309 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
310 __pLaunchArgs->Construct(1);
311 __pLaunchArgs->Add(pIncomingCall);
312 if(__initialSceneId.IsEmpty() == true)
314 __initialSceneId = IDSCN_SCENE_INCOMINGCALL;
318 //App already initialized, goto incoming call form
319 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), __pLaunchArgs);
320 __pLaunchArgs = null;
325 //Show messageBox showing automatic call rejection
326 MessageBox callRejectedInoMsgBox;
327 String msg(L"Call From ");
328 msg.Append(contactNumber);
329 msg.Append(L" Rejected.");
330 callRejectedInoMsgBox.Construct(L"Call Rejected", msg, MSGBOX_STYLE_NONE,1000);
332 // Calls ShowAndWait() : Draws and Shows itself and processes events
333 callRejectedInoMsgBox.ShowAndWait(modalResult);
335 //go back to previous scene if App was already running, else exit application.
336 if(__initialSceneId.IsEmpty() == true)
338 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
339 AppLog("Terminate Phone Application");
344 //set success message
345 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
349 appControlResult = APP_CTRL_RESULT_FAILED;
351 AppLogDebug("Exiting %d",appControlResult);
352 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
356 CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
359 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
361 if (pArgsMap != null)
363 String callType(L"");
364 String phoneNumber(L"");
366 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
367 if(pArgsMap->ContainsKey(*pKey) == true)
369 const String* pPhoneValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
370 if(pPhoneValue != null)
372 AppLogDebug("%ls",pPhoneValue->GetPointer());
373 phoneNumber.Append(*pPhoneValue);
378 AppLogDebug("PARAM_PHONE_NUMBER not present");
381 //Check if its a valid number
382 if(CheckNumberIsValid(phoneNumber) == false)
384 //Show messageBox showing automatic call rejection
385 MessageBox InvalidNumberMsgBox;
386 InvalidNumberMsgBox.Construct(AppUtility::GetResourceString(IDS_INVALID_NUMBER), L"",MSGBOX_STYLE_NONE,1000);
388 // Calls ShowAndWait() : Draws and Shows itself and processes events
389 InvalidNumberMsgBox.ShowAndWait(modalResult);
391 //go back to previous scene if App was already running, else exit application.
392 if(__initialSceneId.IsEmpty() == true)
394 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
395 AppLog("Terminate Phone Application");
396 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
403 pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
404 if(pArgsMap->ContainsKey(*pKey) == true)
406 const String* pCallTypeValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
407 if(pCallTypeValue != null)
409 callType.Append(*pCallTypeValue);
415 //Fetch currently active call count
416 if (callType.IsEmpty() == false
417 && callType.Equals(PARAM_CALL_VALUE_VOICE, false) == true
418 && phoneNumber.IsEmpty() == false)
420 SceneManager* pSceneManager = SceneManager::GetInstance();
421 //check if there is already a call in dialing mode, then dont accept any other dialing request.
422 if (pSceneManager->GetCurrentSceneId() == IDSCN_SCENE_OUTCALL
423 || pSceneManager->GetCurrentSceneId()
424 == IDSCN_SCENE_OUT_EMERGENCYCALL)
427 appControlResult = APP_CTRL_RESULT_CANCELED;
428 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
431 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
432 int currentActiveCallCount = pCallPresentor->GetCurrentCallCount();
433 if(currentActiveCallCount <= 1)
435 //make an outgoing call with given number
436 String* contactTxt = new (std::nothrow) String(phoneNumber);
437 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
438 __pLaunchArgs->Construct();
439 __pLaunchArgs->Add(contactTxt);
440 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
442 SceneId nextScene = IDSCN_SCENE_OUTCALL;
445 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
447 //Check if app was already running
448 if(__initialSceneId.IsEmpty() == true)
450 //phone App is not already launched
451 __initialSceneId = nextScene;
455 AppLog("Outgoing call");
456 pSceneManager->GoForward( ForwardSceneTransition( nextScene), __pLaunchArgs);
458 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
462 //already 2 active calls, 3rd call not allowed
463 appControlResult = APP_CTRL_RESULT_CANCELED;
468 appControlResult = APP_CTRL_RESULT_FAILED;
471 //send response message
472 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
476 CallApp::CheckNumberIsValid(String phoneNumber)
478 //Pattern to compare all characters except 0-9 * # P ; , +
479 String phoneNumberPattern(L"[^0-9*#P,+;]");
480 RegularExpression checkPhoneNumber;
481 checkPhoneNumber.Construct(phoneNumberPattern);
482 //If there is any character other than these listed above then display invalid number
483 bool resultMatch = checkPhoneNumber.Match(phoneNumber,false);
484 //return false for patterns other than 0-9 * # P ; , +
490 CallApp::SetTopMostWindow(bool bTopMost)
492 AppLogDebug("bTopMost = %d",bTopMost);
493 result res = E_FAILURE;
494 //ToDO: Need to see if there is better way to handle
499 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_HIGHEST);
500 if(PowerManager::IsScreenOn() == false)
502 res = PowerManager::TurnScreenOn();
504 res = PowerManager::KeepScreenOnState(true,false);
509 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_NORMAL);
510 PowerManager::KeepScreenOnState(false);
512 //Unlock the phone if its locked
513 if(LockManager::GetInstance()->IsLocked())
515 LockManager::GetInstance()->Unlock();