Fix for N_SE-48378 N_SE-48015
[apps/osp/Call.git] / src / CallApp.cpp
index 31f7f52..0b39b9b 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,15 +38,26 @@ using namespace Tizen::Ui::Scenes;
 using namespace Tizen::Base::Utility;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
+using namespace Tizen::Shell;
+
+static const int FONT_SIZE_AUTOREJECT_POPUP_TEXT = 36;
 
 
 CallApp::CallApp(void):__initialSceneId(L""), __pLaunchArgs(null)
 {
        __listenerList.Construct();
+       __pCallRejectedIonPopup = null;
+       __pCallAppTimer = null;
+       __callTicks = 0;
 }
 
 CallApp::~CallApp(void)
 {
+       if(__pCallRejectedIonPopup != null)
+       {
+               delete __pCallRejectedIonPopup;
+               __pCallRejectedIonPopup=null;
+       }
 }
 
 UiApp*
@@ -47,6 +73,7 @@ CallApp::OnAppInitializing(AppRegistry& appRegistry)
        AppControlProviderManager* pProviderMgr = AppControlProviderManager::GetInstance();
        pProviderMgr->SetAppControlProviderEventListener(this);
        PowerManager::AddScreenEventListener(*this);
+       __callRejectedIontimer.Construct(*this);
        return true;
 }
 
@@ -70,6 +97,17 @@ CallApp::OnAppInitialized(void)
                return false;
        }
 
+       if (__pCallAppTimer == null)
+       {
+               __pCallAppTimer = new (std::nothrow) Tizen::Base::Runtime::Timer();
+               __pCallAppTimer->Construct(*this);
+               long long currTime = 0;
+               SystemTime::GetTicks(currTime);
+               __callTicks = currTime;
+               __pCallAppTimer->StartAsRepeatable(TimeSpan::NUM_OF_TICKS_IN_SECOND);
+       }
+
+
        return true;
 }
 
@@ -88,6 +126,12 @@ CallApp::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
        // Deallocate resources allocated by this App for termination.
        // The App's permanent data and context can be saved via appRegistry.
        PowerManager::RemoveScreenEventListener(*this);
+       if (__pCallAppTimer != null)
+       {
+               __pCallAppTimer->Cancel();
+               delete __pCallAppTimer;
+       }
+
        return true;
 }
 
@@ -314,17 +358,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);
@@ -336,9 +388,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_KEEP), __pLaunchArgs);
                                __pLaunchArgs = null;
                        }
+
+
                }
                else
                {
@@ -351,7 +406,6 @@ CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMa
                        int modalResult = 0;
                        // Calls ShowAndWait() : Draws and Shows itself and processes events
                        callRejectedInoMsgBox.ShowAndWait(modalResult);*/
-
                        //go back to previous scene if App was already running, else exit application.
                        if(__initialSceneId.IsEmpty() == true)
                        {
@@ -359,6 +413,10 @@ CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMa
                                AppLog("Terminate Phone Application");
                                Terminate();
                        }
+                       else
+                       {
+                               ShowAutoRejectPopup(contactNumber);
+                       }
                }
                //set success message
                appControlResult = APP_CTRL_RESULT_SUCCEEDED;
@@ -372,6 +430,50 @@ CallApp::HandleIncomingCallAppControlRequest(RequestId reqId,const IMap* pArgsMa
 }
 
 void
+CallApp::ShowAutoRejectPopup(Tizen::Base::String contactNumber)
+{
+       String msg(AppUtility::GetResourceString(IDS_CALL_REJECT_FROM_STRING));
+       msg.Append(L" ");
+       msg.Append(contactNumber);
+       if(__pCallRejectedIonPopup != null)
+       {
+               delete __pCallRejectedIonPopup;
+               __pCallRejectedIonPopup = null;
+       }
+       __pCallRejectedIonPopup = new (std::nothrow) Popup();
+       Tizen::Graphics::Dimension dim(600,200);
+       __pCallRejectedIonPopup->Construct(true, dim);
+       __pCallRejectedIonPopup->SetTitleText(AppUtility::GetResourceString(IDS_CALL_REJECTED_TITLE_STRING));
+       Label* pLabelText = new (std::nothrow) Label();
+       pLabelText->Construct(Tizen::Graphics::Rectangle(0, 0, dim.width, dim.height-100), msg);
+       pLabelText->SetTextConfig(FONT_SIZE_AUTOREJECT_POPUP_TEXT, LABEL_TEXT_STYLE_NORMAL);
+       pLabelText->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
+       pLabelText->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
+       __pCallRejectedIonPopup->AddControl(pLabelText);
+       __pCallRejectedIonPopup->Show();
+       __pCallRejectedIonPopup->SetShowState(true);
+       __callRejectedIontimer.Start(3000);
+}
+
+void
+CallApp::OnTimerExpired(Tizen::Base::Runtime::Timer &timer)
+{
+       if (__callRejectedIontimer.Equals(timer))
+       {
+               if(__pCallRejectedIonPopup != null)
+               {
+                       delete __pCallRejectedIonPopup;
+                       __pCallRejectedIonPopup = null;
+               }
+       }
+
+       if(__pCallAppTimer->Equals(timer))
+       {
+               __callTicks += 1000;
+       }
+}
+
+void
 CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,const String* pUriData)
 {
        //response message
@@ -414,7 +516,7 @@ CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,co
                }
                delete pKey;
                //Check if its a valid number
-               if(CheckNumberIsValid(phoneNumber) == false)
+       /*      if(CheckNumberIsValid(phoneNumber) == false)
                {
                        //go back to previous scene if App was already running, else exit application.
                        if(__initialSceneId.IsEmpty() == true)
@@ -431,7 +533,7 @@ CallApp::HandleDialCallAppControlRequest(RequestId reqId,const IMap* pArgsMap,co
                                //and show current screen, if any calls is present.
                                return;
                        }
-               }
+               }*/
                //call type
                pKey = new (std::nothrow) String(PARAM_CALL_TYPE);
                if(pArgsMap->ContainsKey(*pKey) == true)
@@ -461,7 +563,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)
                        {
@@ -491,7 +603,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_KEEP), __pLaunchArgs);
                                }
                                appControlResult = APP_CTRL_RESULT_SUCCEEDED;
                        }
@@ -515,16 +628,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;
@@ -538,6 +647,7 @@ void
 CallApp::SetTopMostWindow(bool bTopMost)
 {
        AppLogDebug("bTopMost = %d",bTopMost);
+       result res = E_FAILURE;
        //ToDO: Need to see if there is better way to handle
        //this case
 
@@ -545,6 +655,12 @@ CallApp::SetTopMostWindow(bool bTopMost)
        {
                GetAppFrame()->GetFrame()->SetZOrderGroup(WINDOW_Z_ORDER_GROUP_HIGHEST);
                AppManager::GetInstance()->AddActiveAppEventListener(*this);
+               /*if(PowerManager::IsScreenOn() == false)
+               {
+                       AppLogDebug("TurnScreenOn");
+                       res = PowerManager::TurnScreenOn();
+                       AppLogDebug("TurnScreenOn %d",res);
+               }*/
 
        }
        else
@@ -554,25 +670,28 @@ CallApp::SetTopMostWindow(bool bTopMost)
                AppManager::GetInstance()->RemoveActiveAppEventListener(*this);
        }
 
+       if(LockManager::GetInstance()->IsLocked())
+       {
+               AppLogDebug("Phone Locked");
+               LockManager::GetInstance()->Unlock();
+       }
 
 }
 void
 CallApp::OnActiveAppChanged(const String& appId)
 {
-       result res = E_FAILURE;
        AppLogDebug("Enter %ls",appId.GetPointer());
        if(GetAppId().Equals(appId) == true)
        {
-               if(PowerManager::IsScreenOn() == false)
-               {
-                       AppLogDebug("TurnScreenOn");
-                       res = PowerManager::TurnScreenOn();
-                       AppLogDebug("TurnScreenOn %d",res);
-               }
                result res = PowerManager::KeepScreenOnState(true,false);
                AppLogDebug("KeepScreenOnState %d",res);
 
-
        }
 
 }
+
+long long
+CallApp::GetCallAppTicks(void)
+{
+       return __callTicks;
+}