tizen2.1 code merge
[apps/osp/Call.git] / src / CallApp.cpp
index b9f46b6..e790d96 100644 (file)
@@ -1,3 +1,18 @@
+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Flora License, Version 1.1 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://floralicense.org/license/
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an AS IS BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
 /**
  * Name        : CallApp
  * Version     :
@@ -23,6 +38,7 @@ using namespace Tizen::Ui::Scenes;
 using namespace Tizen::Base::Utility;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
+using namespace Tizen::Shell;
 
 
 CallApp::CallApp(void):__initialSceneId(L""), __pLaunchArgs(null)
@@ -46,6 +62,7 @@ CallApp::OnAppInitializing(AppRegistry& appRegistry)
 {
        AppControlProviderManager* pProviderMgr = AppControlProviderManager::GetInstance();
        pProviderMgr->SetAppControlProviderEventListener(this);
+       PowerManager::AddScreenEventListener(*this);
        return true;
 }
 
@@ -86,6 +103,7 @@ CallApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
        // TODO:
        // Deallocate resources allocated by this App for termination.
        // The App's permanent data and context can be saved via appRegistry.
+       PowerManager::RemoveScreenEventListener(*this);
        return true;
 }
 
@@ -139,12 +157,21 @@ CallApp::OnScreenOn(void)
 void
 CallApp::OnScreenOff(void)
 {
-       // TODO:
-       // Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
-       // to enter the sleep mode to save the battery.
-       // Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
-       // callback before the device enters the sleep mode.
-       // Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
+       AppLogDebug("Enter");
+       IEnumerator* pEnum = __listenerList.GetEnumeratorN();
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               IAppStateChangeListener* pInterface = static_cast<IAppStateChangeListener*>(pEnum->GetCurrent());
+               if (pInterface == null)
+               {
+                       delete pEnum;
+
+                       return;
+               }
+               pInterface->OnScreenOff();
+       }
+       delete pEnum;
+
 }
 
 SceneId
@@ -303,17 +330,25 @@ CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMa
 
        //Fetch incoming call details
        CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
+       //Check if there is already a dial call present .This can happen in some
+       //race conditions N_SE-39531
+       if(pCallPresentor->IsIncomingorDialingCallPresent())
+       {
+               int incomingHandle;
+               Integer::Parse(callHandle,incomingHandle);
+               pCallPresentor->RejectCall(incomingHandle,false,contactNumber);
+               AppLog("Cancelled already an incoming call present");
+               appControlResult = APP_CTRL_RESULT_CANCELED;
+               AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
+               return;
+       }
+
        AppCallInfo* pIncomingCall = pCallPresentor->FetchIncomingCallDetailsN(callHandle, contactNumber);
        if(pIncomingCall != null)
        {
                bool isCallRejected = pCallPresentor->CheckIncomingCallToBeRejected(pIncomingCall);
                if(isCallRejected == false)
                {
-                       //Abort any AppControl Request running already to show incoming call screen
-                       if (pCallPresentor->IsAppControlRunning() == true)
-                       {
-                               pCallPresentor->AbortAppControlRequest();
-                       }
                        //save app launch argument list
                        __pLaunchArgs = new (std::nothrow) ArrayList(SingleObjectDeleter);
                        __pLaunchArgs->Construct(1);
@@ -325,9 +360,12 @@ CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMa
                        else
                        {
                                //App already initialized, goto incoming call form
-                               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL), __pLaunchArgs);
+                               pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_INCOMINGCALL, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
+                                                SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), __pLaunchArgs);
                                __pLaunchArgs = null;
                        }
+
+
                }
                else
                {
@@ -414,6 +452,12 @@ CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,co
                                Terminate();
                                return;
                        }
+                       else
+                       {
+                               //invalid phone number.always return, but App will come to foreground
+                               //and show current screen, if any calls is present.
+                               return;
+                       }
                }
                //call type
                pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
@@ -444,7 +488,17 @@ CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,co
                                AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
                                return;
                        }
+
                        CallPresentationModel* pCallPresentor = CallPresentationModel::GetInstance();
+                       //Check if there is already an incoming call
+                       //this can  happen in some race conditions N_SE-39531
+                       if(pCallPresentor->IsIncomingorDialingCallPresent() == true)
+                       {
+                               AppLog("Cancelled already an incoming call present");
+                               appControlResult = APP_CTRL_RESULT_CANCELED;
+                               AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, appControlResult, null);
+                               return;
+                       }
                        int currentActiveCallCount = pCallPresentor->GetCurrentCallCount();
                        if(currentActiveCallCount <= 1)
                        {
@@ -474,7 +528,8 @@ CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,co
                                else
                                {
                                        AppLog("Outgoing call");
-                                       pSceneManager->GoForward( ForwardSceneTransition( nextScene), __pLaunchArgs);
+                                       pSceneManager->GoForward( ForwardSceneTransition( nextScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE,
+                                                        SCENE_HISTORY_OPTION_NO_HISTORY, SCENE_DESTROY_OPTION_DESTROY), __pLaunchArgs);
                                }
                                appControlResult = APP_CTRL_RESULT_SUCCEEDED;
                        }
@@ -498,16 +553,12 @@ CallApp::CheckNumberIsValid(String phoneNumber)
 {
        //Pattern to compare all characters except 0-9 * # P ; , +
        String phoneNumberPattern(L"[^0-9*#P,p+;]");
-       String phoneNumberEndingWithHash(L"#$");
-       RegularExpression checkPhoneNumber,checkHash;
+       RegularExpression checkPhoneNumber;
        checkPhoneNumber.Construct(phoneNumberPattern);
-       checkHash.Construct(phoneNumberEndingWithHash);
        //If there is any character other than these listed above then display invalid number
        bool resultMatch = checkPhoneNumber.Match(phoneNumber,false);
        //return false for patterns other than 0-9 * # P ; , +
-       bool endsWithHash = checkHash.Match(phoneNumber,false);
-       //returns false for any numbers that end with Hash
-       if(resultMatch == true || endsWithHash == true)
+       if(resultMatch == true)
        {
                //return phone number is invalid
                return false;
@@ -528,13 +579,13 @@ CallApp::SetTopMostWindow(bool bTopMost)
        if(bTopMost == true)
        {
                GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_HIGHEST);
-               if(PowerManager::IsScreenOn() == false)
+               AppManager::GetInstance()->AddActiveAppEventListener(*this);
+               /*if(PowerManager::IsScreenOn() == false)
                {
                        AppLogDebug("TurnScreenOn");
                        res = PowerManager::TurnScreenOn();
                        AppLogDebug("TurnScreenOn %d",res);
-               }
-               AppManager::GetInstance()->AddActiveAppEventListener(*this);
+               }*/
 
        }
        else
@@ -543,12 +594,12 @@ CallApp::SetTopMostWindow(bool bTopMost)
                PowerManager::KeepScreenOnState(false);
                AppManager::GetInstance()->RemoveActiveAppEventListener(*this);
        }
-       //Unlock the phone if its locked
-/*     if(LockManager::GetInstance()->IsLocked())
+
+       if(LockManager::GetInstance()->IsLocked())
        {
                AppLogDebug("Phone Locked");
                LockManager::GetInstance()->Unlock();
-       }*/
+       }
 
 }
 void
@@ -560,7 +611,6 @@ CallApp::OnActiveAppChanged(const String& appId)
                result res = PowerManager::KeepScreenOnState(true,false);
                AppLogDebug("KeepScreenOnState %d",res);
 
-
        }
 
 }