10 #include "CallAppFrame.h"
11 #include "CallPresentationModel.h"
12 #include "CallTypes.h"
13 #include "CallAppUtility.h"
14 #include "CallIAppStateChangeListner.h"
16 using namespace Tizen::App;
17 using namespace Tizen::Base;
18 using namespace Tizen::System;
19 using namespace Tizen::Ui;
20 using namespace Tizen::Ui::Controls;
21 using namespace Tizen::Ui::Scenes;
22 using namespace Tizen::Base::Utility;
23 using namespace Tizen::Base::Collection;
24 using namespace Tizen::Base::Utility;
27 CallApp::CallApp(void):__initialSceneId(L""), __pLaunchArgs(null)
29 __listenerList.Construct();
32 CallApp::~CallApp(void)
37 CallApp::CreateInstance(void)
39 // Create the instance through the constructor.
44 CallApp::OnAppInitializing(AppRegistry& appRegistry)
46 AppControlProviderManager* pProviderMgr = AppControlProviderManager::GetInstance();
47 pProviderMgr->SetAppControlProviderEventListener(this);
52 CallApp::OnAppInitialized(void)
58 CallAppFrame* pCallAppFrame = new CallAppFrame();
59 pCallAppFrame->Construct();
60 pCallAppFrame->SetName(L"CallApp");
61 AddFrame(*pCallAppFrame);
63 //Check if there is no initial scene, then exit application.
64 //This case will normally come when invalid AppControl request has come,
65 //or incoming call is coming from unknown number and "reject unknown number" settings is enabled.
66 if (GetInitialScene().IsEmpty() == true)
75 CallApp::OnAppWillTerminate(void)
83 CallApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
86 // Deallocate resources allocated by this App for termination.
87 // The App's permanent data and context can be saved via appRegistry.
92 CallApp::OnForeground(void)
94 IEnumerator* pEnum = __listenerList.GetEnumeratorN();
95 while (pEnum->MoveNext() == E_SUCCESS)
97 IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
98 if (pInterface == null)
104 pInterface->OnForeground();
110 CallApp::OnBackground(void)
113 // Stop drawing when the application is moved to the background.
117 CallApp::OnLowMemory(void)
120 // Free unused resources or close the application.
124 CallApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
127 // Handle any changes in battery level here.
128 // Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
132 CallApp::OnScreenOn(void)
135 // Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
139 CallApp::OnScreenOff(void)
142 // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
143 // to enter the sleep mode to save the battery.
144 // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
145 // callback before the device enters the sleep mode.
146 // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
150 CallApp::GetInitialScene(void)
152 return __initialSceneId;
156 CallApp::GetAppLaunchArguments(void)
158 return __pLaunchArgs;
162 CallApp::AddAppStateChangeListener(const IAppStateChangeListener& listener)
164 __listenerList.Add(listener);
168 CallApp::RemoveAppStateChangeListener(const IAppStateChangeListener& listener)
170 __listenerList.Remove(listener);
174 CallApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData,
175 const String* pMimeType, const IMap* pExtraData)
177 AppLogDebug("ENTER");
178 //process AppControl parameters
179 ProcessAppControlRequest(reqId, operationId, pExtraData);
184 CallApp::ProcessAppControlRequest(RequestId reqId, const String& operationId,const IMap* pArgsMap)
186 AppLogDebug("Enter %ls",operationId.GetPointer());
187 __pLaunchArgs = null;
188 if(operationId.Equals(OPERATION_ID_CALL,true) == true)
190 AppLogDebug("OPERATION_ID_CALL");
193 bool isIncomingCallRequest = false;
194 String* pKey = new (std::nothrow) String(LAUNCHTYPE);
195 if (pArgsMap->ContainsKey(*pKey) == true)
197 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
198 if ((pValue != null) && (pValue->Equals(PARAM_ORIGIN_MT, true) == true))
200 isIncomingCallRequest = true;
203 //Check if incoming call request or outgoing call request
204 if(isIncomingCallRequest == true)
206 HandleIncomingCallAppControlRequest(reqId, pArgsMap);
210 HandleDialCallAppControlRequest(reqId, pArgsMap);
215 AppLogDebug("pArgsMap == null");
221 CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
223 AppLogDebug("Enter");
224 SceneManager* pSceneManager = SceneManager::GetInstance();
226 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
229 String callHandle(L"");
230 String* pKey = new (std::nothrow) String(CALL_HANDLE);
231 if (pArgsMap->ContainsKey(*pKey) == true)
233 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
236 callHandle.Append(*pValue);
241 String contactNumber(L"");
242 pKey = new (std::nothrow) String(CONTACT_NUMBER);
243 if (pArgsMap->ContainsKey(*pKey) == true)
245 const String* pContactValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
246 if (pContactValue != null)
248 contactNumber.Append(*pContactValue);
249 AppLogDebug("%ls",contactNumber.GetPointer());
255 //Fetch incoming call details
256 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
257 CallInfo* pIncomingCall = pCallPresentor->FetchIncomingCallDetailsN(callHandle, contactNumber);
258 if(pIncomingCall != null)
260 bool isCallRejected = pCallPresentor->CheckIncomingCallToBeRejected(pIncomingCall);
261 if(isCallRejected == false)
263 //save app launch argument list
264 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
265 __pLaunchArgs->Construct(1);
266 __pLaunchArgs->Add(pIncomingCall);
267 if(__initialSceneId.IsEmpty() == true)
269 __initialSceneId = IDSCN_SCENE_INCOMINGCALL;
273 //App already initialized, goto incoming call form
274 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), __pLaunchArgs);
275 __pLaunchArgs = null;
280 //Show messageBox showing automatic call rejection
281 MessageBox callRejectedInoMsgBox;
282 String msg(L"Call From ");
283 msg.Append(contactNumber);
284 msg.Append(L" Rejected.");
285 callRejectedInoMsgBox.Construct(L"Call Rejected", msg, MSGBOX_STYLE_NONE,1000);
287 // Calls ShowAndWait() : Draws and Shows itself and processes events
288 callRejectedInoMsgBox.ShowAndWait(modalResult);
290 //go back to previous scene if App was already running, else exit application.
291 if(__initialSceneId.IsEmpty() == true)
293 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
294 AppLog("Terminate Phone Application");
299 //set success message
300 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
304 appControlResult = APP_CTRL_RESULT_FAILED;
306 AppLogDebug("Exiting %d",appControlResult);
307 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
311 CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
314 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
316 if (pArgsMap != null)
318 String callType(L"");
319 String phoneNumber(L"");
321 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
322 if(pArgsMap->ContainsKey(*pKey) == true)
324 const String* pPhoneValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
325 if(pPhoneValue != null)
327 AppLogDebug("%ls",pPhoneValue->GetPointer());
328 phoneNumber.Append(*pPhoneValue);
333 AppLogDebug("PARAM_PHONE_NUMBER not present");
336 //Check if its a valid number
337 if(CheckNumberIsValid(phoneNumber) == false)
339 //Show messageBox showing automatic call rejection
340 MessageBox InvalidNumberMsgBox;
341 InvalidNumberMsgBox.Construct(AppUtility::GetResourceString(IDS_INVALID_NUMBER), L"",MSGBOX_STYLE_NONE,1000);
343 // Calls ShowAndWait() : Draws and Shows itself and processes events
344 InvalidNumberMsgBox.ShowAndWait(modalResult);
346 //go back to previous scene if App was already running, else exit application.
347 if(__initialSceneId.IsEmpty() == true)
349 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
350 AppLog("Terminate Phone Application");
351 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
358 pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
359 if(pArgsMap->ContainsKey(*pKey) == true)
361 const String* pCallTypeValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
362 if(pCallTypeValue != null)
364 callType.Append(*pCallTypeValue);
370 //Fetch currently active call count
371 if (callType.IsEmpty() == false
372 && callType.Equals(PARAM_CALL_VALUE_VOICE, false) == true
373 && phoneNumber.IsEmpty() == false)
375 SceneManager* pSceneManager = SceneManager::GetInstance();
376 //check if there is already a call in dialing mode, then dont accept any other dialing request.
377 if (pSceneManager->GetCurrentSceneId() == IDSCN_SCENE_OUTCALL
378 || pSceneManager->GetCurrentSceneId()
379 == IDSCN_SCENE_OUT_EMERGENCYCALL)
382 appControlResult = APP_CTRL_RESULT_CANCELED;
383 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
386 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
387 int currentActiveCallCount = pCallPresentor->GetCurrentCallCount();
388 if(currentActiveCallCount <= 1)
390 //make an outgoing call with given number
391 String* contactTxt = new (std::nothrow) String(phoneNumber);
392 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
393 __pLaunchArgs->Construct();
394 __pLaunchArgs->Add(contactTxt);
395 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
397 SceneId nextScene = IDSCN_SCENE_OUTCALL;
400 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
402 //Check if app was already running
403 if(__initialSceneId.IsEmpty() == true)
405 //phone App is not already launched
406 __initialSceneId = nextScene;
410 AppLog("Outgoing call");
411 pSceneManager->GoForward( ForwardSceneTransition( nextScene), __pLaunchArgs);
413 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
417 //already 2 active calls, 3rd call not allowed
418 appControlResult = APP_CTRL_RESULT_CANCELED;
423 appControlResult = APP_CTRL_RESULT_FAILED;
426 //send response message
427 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
431 CallApp::CheckNumberIsValid(String phoneNumber)
433 //Pattern to compare all characters except 0-9 * # P ; , +
434 String phoneNumberPattern(L"[^0-9*#P,+]");
435 RegularExpression checkPhoneNumber;
436 checkPhoneNumber.Construct(phoneNumberPattern);
437 //If there is any character other than these listed above then display invalid number
438 bool resultMatch = checkPhoneNumber.Match(phoneNumber,false);
439 //return false for patterns other than 0-9 * # P ; , +
445 CallApp::SetTopMostWindow(bool bTopMost)
447 AppLogDebug("bTopMost = %d",bTopMost);
448 result res = E_FAILURE;
449 //ToDO: Need to see if there is better way to handle
453 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_HIGH);
454 if(PowerManager::IsScreenOn() == false)
456 res = PowerManager::TurnScreenOn();
458 res = PowerManager::KeepScreenOnState(true,false);
463 GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_NORMAL);
464 PowerManager::KeepScreenOnState(false);