2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file PhnPhoneApp.cpp
19 * @brief Phone Application UiApp file
22 #include "PhnCallInfo.h"
23 #include "PhnCallPresentationModel.h"
24 #include "PhnPhoneAppFrame.h"
25 #include "PhnPhoneApp.h"
26 #include "PhnSceneRegister.h"
27 #include "PhnSettingsPresentationModel.h"
29 #include "PhnIAppStateChangeListner.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Base::Utility;
35 using namespace Tizen::System;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
40 PhoneApp::PhoneApp(void) : __isOpenAsAppControl(false), __pLaunchArgs(null)
41 , __initialSceneId(L"")
43 __listenerList.Construct();
46 PhoneApp::~PhoneApp(void)
51 PhoneApp::CreateInstance(void)
53 return new (std::nothrow) PhoneApp();
57 PhoneApp::OnAppInitializing(AppRegistry& appRegistry)
59 AppControlProviderManager* pProviderMgr = AppControlProviderManager::GetInstance();
60 pProviderMgr->SetAppControlProviderEventListener(this);
65 PhoneApp::OnAppInitialized(void)
69 //Check if PhoneApp is opened as AppControl
70 if(__isOpenAsAppControl == false)
72 //by default, initial scene is DIALER view
73 __initialSceneId = IDSCN_DIALER;
77 // Initialize Frame and App specific data.
78 PhoneAppFrame* pPhoneAppFrame = new (std::nothrow) PhoneAppFrame();
79 pPhoneAppFrame->Construct();
80 pPhoneAppFrame->SetName(L"Phone");
81 r = AddFrame(*pPhoneAppFrame);
83 return (!IsFailed(r));
87 PhoneApp::OnAppWillTerminate(void)
93 PhoneApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
99 PhoneApp::OnForeground(void)
101 IEnumerator* pEnum = __listenerList.GetEnumeratorN();
102 while (pEnum->MoveNext() == E_SUCCESS)
104 IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
105 if (pInterface == null)
111 pInterface->OnForeground();
117 PhoneApp::OnBackground(void)
119 IEnumerator* pEnum = __listenerList.GetEnumeratorN();
120 while (pEnum->MoveNext() == E_SUCCESS)
122 IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
123 if (pInterface == null)
129 pInterface->OnBackground();
135 PhoneApp::OnLowMemory(void)
140 PhoneApp::OnBatteryLevelChanged(BatteryLevel batteryLevel)
145 PhoneApp::OnScreenOn(void)
150 PhoneApp::OnScreenOff(void)
155 PhoneApp::IsOpenAsAppControl(void)
157 return __isOpenAsAppControl;
161 PhoneApp::GetInitialScene(void)
163 return __initialSceneId;
167 PhoneApp::SetInitialScene(SceneId initialSceneId)
169 __initialSceneId = initialSceneId;
173 PhoneApp::GetAppLaunchArguments(void)
175 return __pLaunchArgs;
179 PhoneApp::OnAppControlRequestReceived(RequestId reqId, const String& operationId, const String* pUriData,
180 const String* pMimeType, const IMap* pExtraData)
182 AppLogDebug("ENTER");
183 //process AppControl parameters
184 ProcessAppControlRequest(reqId, operationId, pExtraData);
189 PhoneApp::ProcessAppControlRequest(RequestId reqId, const String& operationId,const IMap* pArgsMap)
191 __pLaunchArgs = null;
192 if(operationId.Equals(OPERATION_ID_CALL,true))
194 __isOpenAsAppControl = true;
197 bool isIncomingCallRequest = false;
198 String* pKey = new (std::nothrow) String(LAUNCHTYPE);
199 if (pArgsMap->ContainsKey(*pKey) == true)
201 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
202 if ((pValue != null) && (pValue->Equals(PARAM_ORIGIN_MT, true) == true))
204 isIncomingCallRequest = true;
207 //Check if incoming call request or outgoing call request
208 if(isIncomingCallRequest == true)
210 HandleIncomingCallAppControlRequest(reqId, pArgsMap);
214 HandleDialCallAppControlRequest(reqId, pArgsMap);
218 else if(operationId.Equals(OPERATION_ID_DIAL,true))
220 __isOpenAsAppControl = true;
221 HandleDialerAppControlRequest(reqId, pArgsMap);
223 else if (operationId.Equals(OPERATION_ID_CONFIGURE, true))
225 __isOpenAsAppControl = true;
226 HandleSettingsAppControlRequest(reqId, pArgsMap);
231 PhoneApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
233 SceneManager* pSceneManager = SceneManager::GetInstance();
235 AppCtrlResult appControlResult = APP_CTRL_RESULT_FAILED;
238 String callHandle(L"");
239 String* pKey = new (std::nothrow) String(CALL_HANDLE);
240 if (pArgsMap->ContainsKey(*pKey) == true)
242 const String* pValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
245 callHandle.Append(*pValue);
250 String contactNumber(L"");
251 pKey = new (std::nothrow) String(CONTACT_NUMBER);
252 if (pArgsMap->ContainsKey(*pKey) == true)
254 const String* pContactValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
255 if (pContactValue != null)
257 contactNumber.Append(*pContactValue);
263 //Fetch incoming call details
264 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
265 CallInfo* pIncomingCall = pCallPresentor->FetchIncomingCallDetailsN(callHandle, contactNumber);
266 if(pIncomingCall != null)
268 bool isCallRejected = pCallPresentor->CheckIncomingCallToBeRejected(pIncomingCall);
269 if(isCallRejected == false)
271 //save app launch argument list
272 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
273 __pLaunchArgs->Construct(1);
274 __pLaunchArgs->Add(pIncomingCall);
275 if(__initialSceneId.IsEmpty() == true)
277 __initialSceneId = IDSCN_SCENE_INCOMINGCALL;
281 //App already initialized, goto incoming call form
282 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), __pLaunchArgs);
283 __pLaunchArgs = null;
288 //Show messageBox showing automatic call rejection
289 MessageBox callRejectedInoMsgBox;
290 String msg(L"Call From ");
291 msg.Append(contactNumber);
292 msg.Append(L" Rejected.");
293 callRejectedInoMsgBox.Construct(L"Call Rejected", msg, MSGBOX_STYLE_NONE,1000);
295 // Calls ShowAndWait() : Draws and Shows itself and processes events
296 callRejectedInoMsgBox.ShowAndWait(modalResult);
298 //go back to previous scene if App was already running, else exit application.
299 if(__initialSceneId.IsEmpty() == true)
301 //KEEP "__initialSceneId" as empty and return false from "OnAppInitialized()"
302 AppLog("Terminate Phone Application");
304 else if (pCallPresentor->GetCurrentCallCount() == 0)
306 // NOTE: Let the user remain on whatever screen he/she is,
307 // but the framework will bring PhoneApp to foreground.
308 /*pSceneManager->GoForward(ForwardSceneTransition(__initialSceneId), null);*/
311 //set success message
312 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
316 __isOpenAsAppControl = false;
317 appControlResult = APP_CTRL_RESULT_FAILED;
319 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
323 PhoneApp::HandleDialerAppControlRequest(RequestId reqId,const IMap* pArgsMap)
326 if (pArgsMap != null)
328 String* pKey = new (std::nothrow) String(PARAM_PHONE_NUMBER);
329 if (pArgsMap->ContainsKey(*pKey) == true)
331 const String* pPhoneValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
332 if (pPhoneValue != null)
334 String* tmpStr = new (std::nothrow) String(*pPhoneValue);
335 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
336 __pLaunchArgs->Construct();
337 __pLaunchArgs->Add(tmpStr);
343 //Check if app is already launched
344 if(__initialSceneId.IsEmpty() == true)
346 __initialSceneId = IDSCN_DIALER;
350 SceneManager* pSceneManager = SceneManager::GetInstance();
351 pSceneManager->GoForward( ForwardSceneTransition(IDSCN_DIALER, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
352 SCENE_HISTORY_OPTION_NO_HISTORY),__pLaunchArgs);
353 __pLaunchArgs = null;
356 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, null);
360 PhoneApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap)
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 phoneNumber.Append(*pPhoneValue);
381 pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
382 if(pArgsMap->ContainsKey(*pKey) == true)
384 const String* pCallTypeValue = static_cast<const String*>(pArgsMap->GetValue(*pKey));
385 if(pCallTypeValue != null)
387 callType.Append(*pCallTypeValue);
393 //Fetch currently active call count
394 if (callType.IsEmpty() == false
395 && callType.Equals(PARAM_CALL_VALUE_VOICE, false) == true
396 && phoneNumber.IsEmpty() == false)
398 CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
399 int currentActiveCallCount = pCallPresentor->GetCurrentCallCount();
400 if(currentActiveCallCount <= 1)
402 //make an outgoing call with given number
403 String* contactTxt = new (std::nothrow) String(phoneNumber);
404 __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
405 __pLaunchArgs->Construct();
406 __pLaunchArgs->Add(contactTxt);
407 bool isEmergencyCall = pCallPresentor->IsEmergencyNumber(*contactTxt, true);
409 SceneId nextScene = IDSCN_SCENE_OUTCALL;
412 nextScene = IDSCN_SCENE_OUT_EMERGENCYCALL;
415 //Check if app was already running
416 if(__initialSceneId.IsEmpty() == true)
418 //phone App is not already launched
419 __initialSceneId = nextScene;
423 SceneManager* pSceneManager = SceneManager::GetInstance();
424 pSceneManager->GoForward( ForwardSceneTransition( nextScene), __pLaunchArgs);
426 appControlResult = APP_CTRL_RESULT_SUCCEEDED;
430 //already 2 active calls, 3rd call not allowed
431 appControlResult = APP_CTRL_RESULT_CANCELED;
436 appControlResult = APP_CTRL_RESULT_FAILED;
439 //send response message
440 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
444 PhoneApp::HandleSettingsAppControlRequest(RequestId reqId,const IMap* pArgsMap)
446 if(__initialSceneId.IsEmpty() == true)
448 __initialSceneId = IDSCN_SCENE_MAIN_SETTING_MENU;
452 SceneManager* pSceneManager = SceneManager::GetInstance();
453 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_MAIN_SETTING_MENU), null);
455 //send response message
456 AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_SUCCEEDED, null);
460 PhoneApp::AddAppStateChangeListener(const IAppStateChangeListener& listener)
462 __listenerList.Add(listener);
466 PhoneApp::RemoveAppStateChangeListener(const IAppStateChangeListener& listener)
468 __listenerList.Remove(listener);