phoneapp/phoneuiqtviewadapter/src/phonevisibilityhandler.cpp
changeset 76 cfea66083b62
parent 65 2a5d4ab426d3
child 78 baacf668fe89
--- a/phoneapp/phoneuiqtviewadapter/src/phonevisibilityhandler.cpp	Fri Sep 17 17:09:12 2010 +0300
+++ b/phoneapp/phoneuiqtviewadapter/src/phonevisibilityhandler.cpp	Mon Oct 04 16:06:10 2010 +0300
@@ -88,8 +88,6 @@
         m_view.bringToForeground();
         adjustVisibility(BringForwards);
     }
-    
-
 }
 
 /*!
@@ -107,6 +105,7 @@
  */
 bool PhoneVisibilityHandler::phoneVisible()
 {
+    PHONE_TRACE
     // Should we check if there is phone's devicedialogs visible?
     return (m_eikonEnv->RootWin().OrdinalPosition() == 0);
 }
@@ -116,8 +115,9 @@
  */
 void PhoneVisibilityHandler::sendToBackground(bool homeScreenForeground)
 {
-    PHONE_TRACE2(": homeScreenForeground =", homeScreenForeground);
-    PHONE_TRACE2(": m_carModeEnabled =", m_carModeEnabled);
+    PHONE_TRACE4(": homeScreenForeground =", homeScreenForeground, 
+        ", m_carModeEnabled =", m_carModeEnabled);
+    
     if(m_carModeEnabled) {
         // Don't bring homescreen to foreground
         return;
@@ -125,11 +125,12 @@
     
     enableKeyGuard();
     
+    bool setHsToForeground = homeScreenForeground && phoneVisible();
     // Send phone back on WSERV stack
     adjustVisibility(SendToBack);
     
     // Fetch homescreen to foreground if needed
-    if (homeScreenForeground) {
+    if (setHsToForeground) {
         _LIT(KPhoneHsAppName,"hsapplication");
         TApaTaskList taskList(m_eikonEnv->WsSession());
         TApaTask task = taskList.FindApp(KPhoneHsAppName);
@@ -159,6 +160,7 @@
  */
 bool PhoneVisibilityHandler::disableKeyGuard()
 {
+    PHONE_TRACE
     TRAP_IGNORE(
         CKeyguardAccessApi* keyguardAccess = CKeyguardAccessApi::NewL( );
         if (!m_keyguardOnBeforeForeground) {
@@ -178,6 +180,7 @@
  */
 void PhoneVisibilityHandler::enableKeyGuard()
 {
+    PHONE_TRACE
     if (phoneVisible() && m_keyguardOnBeforeForeground) {
         // If phone is visible return to previous keyguard status
         TRAP_IGNORE(
@@ -186,7 +189,6 @@
             delete keyguardAccess;
             );
     }
-    
     m_keyguardOnBeforeForeground = false;
 }
 
@@ -220,10 +222,7 @@
  */
 void PhoneVisibilityHandler::adjustVisibility(AdjustAction action)
 {
-    PHONE_TRACE1(": START");
-    int ordinalPos = m_eikonEnv->RootWin().OrdinalPosition();
-    PHONE_TRACE2(": current pos:", ordinalPos);
-
+    PHONE_TRACE
     if (m_carModeEnabled || (action == SendToBack)) {
         PHONE_TRACE1(": SendPhoneToBackground");
         m_eikonEnv->RootWin().SetOrdinalPosition(-1, ECoeWinPriorityNeverAtFront);
@@ -252,13 +251,13 @@
     } else {
         // Normalize visiblity after ie. device lock
         PHONE_TRACE1(": Normalize");
+        int ordinalPos = m_eikonEnv->RootWin().OrdinalPosition();
+        
         m_eikonEnv->RootWin().SetOrdinalPosition(ordinalPos, ECoeWinPriorityNormal);
         // Flush is needed here, because otherwise launching an application may fail
         // if done same time with normalization.
         m_eikonEnv->WsSession().Flush();        
     }
-
-    PHONE_TRACE1(": END");
 }
 
 void PhoneVisibilityHandler::carModeChanged()