Revision: 201031 RCL_3
authorDremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 19 Aug 2010 10:45:23 +0300
branchRCL_3
changeset 20 63339781d179
parent 19 94b923fa11ed
child 21 09b1ac925e3f
Revision: 201031 Kit: 201033
pkiutilities/CTSecurityDialogs/NotifSrc/CTSecurityDialogsAO.cpp
securitydialogs/Autolock/group/Autolock.mmp
securitydialogs/Autolock/inc/AutolockAppUiInterface.h
securitydialogs/Autolock/inc/AutolockAppUiPS.h
securitydialogs/Autolock/src/AutoKeyguardObserver.cpp
securitydialogs/Autolock/src/AutoLockValueObserver.cpp
securitydialogs/Autolock/src/AutolockAppUi.cpp
securitydialogs/Autolock/src/AutolockContainer.cpp
securitydialogs/Autolock/src/AutolockGripStatusObserver.cpp
securitydialogs/SecUi/Src/SecUiSecurityHandler.cpp
securitydialogs/Securitynotifier/Src/SecurityNotifier.cpp
securitydialogs/simlockui/inc/SimLockUIBackgroundControl.h
securitydialogs/simlockui/src/SimLockUIAppui.cpp
securitydialogs/simlockui/src/SimLockUIBackgroundControl.cpp
wim/Scard/inc/ScardConnector.h
wim/Scard/src/ScardConnectionRegistry.cpp
wim/Scard/src/ScardConnector.cpp
wim/WimPlugin/src/WimCertStore.cpp
wim/WimServer/src/WimServer.cpp
wim/WimServer/src/WimTrustSettingsStore.cpp
--- a/pkiutilities/CTSecurityDialogs/NotifSrc/CTSecurityDialogsAO.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/pkiutilities/CTSecurityDialogs/NotifSrc/CTSecurityDialogsAO.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -1478,7 +1478,7 @@
     // certificate dialog would be displayed on top of possible lock code query.
     TInt value = 0;
     TInt err = RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, value );
-    if( !err && value > EAutolockOff )
+    if( !err && value != EAutolockOff )
         {
         iRetValue = EServerCertNotAccepted;
         iStatus = KRequestPending;
--- a/securitydialogs/Autolock/group/Autolock.mmp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/group/Autolock.mmp	Thu Aug 19 10:45:23 2010 +0300
@@ -90,6 +90,7 @@
 LIBRARY gdi.lib
 LIBRARY aknnotify.lib
 LIBRARY     customapi.lib
+LIBRARY		   keylockpolicyapi.lib
 
 
 SMPSAFE
--- a/securitydialogs/Autolock/inc/AutolockAppUiInterface.h	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/inc/AutolockAppUiInterface.h	Thu Aug 19 10:45:23 2010 +0300
@@ -24,6 +24,7 @@
         virtual TInt DeviceLockQueryStatus() = 0;
         virtual TInt DeviceLockStatus() = 0;
         virtual void CancelDeviceLockQuery() = 0;
+        virtual void ForceOrientation(TInt value) = 0;
     };
 
 #endif // AUTOLOCKAPPUIINTERFACE_H
--- a/securitydialogs/Autolock/inc/AutolockAppUiPS.h	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/inc/AutolockAppUiPS.h	Thu Aug 19 10:45:23 2010 +0300
@@ -119,7 +119,7 @@
         TBool DeviceLockStatus();
 
         void CancelDeviceLockQuery();
-        
+        void ForceOrientation(TInt value);
         /**
          * From MAutolockFpsStatusObserver
          */
--- a/securitydialogs/Autolock/src/AutoKeyguardObserver.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/src/AutoKeyguardObserver.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -368,6 +368,20 @@
     RProperty::Get(KPSUidScreenSaver, KScreenSaverActivatedFromIdle, value);
     screenSaverStertedFromIdle = (value == KSsStartedFromIdle);
     
+    // See if SIM is accepted
+    if(idle)
+    	{
+	    value = 0;
+	    RProperty::Get(KPSUidStartup, KPSSimStatus, value);
+	    // automatic lock can't get enabled if SIM-locked.
+	    if(value == ESimNotReady)
+	    	idle = EFalse;
+	    #if defined(_DEBUG)
+	    RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() KPSSimStatus state: %d"), value);
+	    RDebug::Print(_L("(AUTOLOCK)CAutoKeyguardObserver::LockKeysL() ESimUsable: %d"), ESimUsable);
+	    #endif
+	  	}
+
     //See if all the startup related queries and graphics has been displayed
     value = 0;
     RProperty::Get(KPSUidStartup, KPSStartupUiPhase, value);
--- a/securitydialogs/Autolock/src/AutoLockValueObserver.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/src/AutoLockValueObserver.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -23,7 +23,8 @@
 #include <ctsydomainpskeys.h>
 #include	"AutolockAppUiPS.h"
 #include	"AutoLockValueObserverPS.h"
-
+#include <coreapplicationuisdomainpskeys.h>
+#include <startupdomainpskeys.h>
 
 // ================= MEMBER FUNCTIONS =======================
 //
@@ -64,6 +65,9 @@
     iProperty.Attach(KPSUidCtsyCallInformation, KCTsyCallState); 
     iProperty.Subscribe(iStatus);
     SetActive();
+    #if defined(_DEBUG)
+    RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
+		#endif
     return KErrNone;
     }
 //
@@ -74,6 +78,9 @@
 //
 void CValueObserver::Stop()
 	{
+	#if defined(_DEBUG)
+	RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
+	#endif
 	Cancel();
 	}
 //
@@ -83,7 +90,10 @@
 // ----------------------------------------------------------
 // 
 CValueObserver::CValueObserver(CAutolockAppUi* aAppUi) : CActive(0), iAppUi(aAppUi)
-	{                            
+	{               
+		#if defined(_DEBUG)     
+		RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
+    #endif
     }
 //
 // ----------------------------------------------------------
@@ -94,6 +104,9 @@
 void CValueObserver::ConstructL()
     {
     // Add this active object to the scheduler.
+    #if defined(_DEBUG)
+    RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
+		#endif
 	CActiveScheduler::Add(this);	
     }
 //
@@ -104,15 +117,82 @@
 // 
 void CValueObserver::RunL()
 	{
+		#if defined(_DEBUG)
+		RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
+		#endif
+    TInt atForeground = iAppUi->IsForeground();
+		TInt value(EStartupUiPhaseUninitialized);
+		RProperty::Get(KPSUidStartup, KPSStartupUiPhase, value);
     TInt callState;
     iProperty.Get( callState );
-    if (callState == EPSCTsyCallStateNone && !iAppUi->IsForeground())
+    #if defined(_DEBUG)
+		RDebug::Printf( "%s %s (%u) callState=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, callState );
+		RDebug::Printf( "%s %s (%u) EPSCTsyCallStateNone=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EPSCTsyCallStateNone );
+		RDebug::Printf( "%s %s (%u) EPSCTsyCallStateUninitialized=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EPSCTsyCallStateUninitialized );
+		RDebug::Printf( "%s %s (%u) atForeground=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, atForeground );
+		RDebug::Printf( "%s %s (%u) KPSStartupUiPhase value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, value );
+		RDebug::Printf( "%s %s (%u) EStartupUiPhaseSystemWelcomeDone=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EStartupUiPhaseSystemWelcomeDone );
+		#endif
+
+
+    if (callState == EPSCTsyCallStateNone && !atForeground)
         {
-		// app back to foreground
-		iAppUi->BringAppToForegroundL();
+			if( value<EStartupUiPhaseSystemWelcomeDone )
+					{
+					#if defined(_DEBUG)
+					RDebug::Printf( "%s %s (%u) re-start=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
+					#endif
+					Start();
+					}
+			else
+				{
+						// app back to foreground
+				TInt iAppUi_Locked = iAppUi->Locked();
+				TInt alocked = RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, value);
+				#if defined(_DEBUG)
+				RDebug::Printf( "%s %s (%u) alocked=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, alocked );
+				RDebug::Printf( "%s %s (%u) iAppUi_Locked=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iAppUi_Locked );
+				#endif
+				if(iAppUi_Locked)
+					{
+					#if defined(_DEBUG)
+					RDebug::Printf( "%s %s (%u) BringAppToForegroundL=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
+					#endif
+					iAppUi->BringAppToForegroundL();
+					}
+			}
 		}
     else
 		{
+				{
+				if( value<EStartupUiPhaseSystemWelcomeDone )
+					{
+					#if defined(_DEBUG)
+					RDebug::Printf( "%s %s (%u) 1=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
+					#endif
+					if( callState != EPSCTsyCallStateNone && callState != EPSCTsyCallStateUninitialized && !atForeground)
+						{
+						#if defined(_DEBUG)
+						RDebug::Printf( "%s %s (%u) 2=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 2 );
+						#endif
+						iAppUi->BringAppToForegroundL();
+						}
+					else if( (callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized) && atForeground)
+						{
+						#if defined(_DEBUG)
+						RDebug::Printf( "%s %s (%u) calling BringAppToForegroundL=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
+						#endif
+						iAppUi->BringAppToForegroundL();
+						#if defined(_DEBUG)
+						RDebug::Printf( "%s %s (%u) calling SwitchToPreviousAppL=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 2 );
+						#endif
+						iAppUi->SwitchToPreviousAppL();
+						#if defined(_DEBUG)
+						RDebug::Printf( "%s %s (%u) done=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 3 );
+						#endif
+						}
+					}
+				}
 		Start();
 		}
 	
--- a/securitydialogs/Autolock/src/AutolockAppUi.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/src/AutolockAppUi.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -58,6 +58,8 @@
 #include <AknCapServerDefs.h>
 #include <apgtask.h>
 
+#include <keylockpolicyapi.h>
+
 //  LOCAL CONSTANTS AND MACROS  
 #define KSysApUid TUid::Uid(0x100058F3)
 #define KPhoneAppUid TUid::Uid(0x100058B3)
@@ -77,52 +79,63 @@
 //
 void CAutolockAppUi::ConstructL()
     {
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL"));
     #endif
     
     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknDisableAnimationBackground );
     
     //Disable priority control so that Autolock process priority isn't set to "background" by 
-	//window server when it is not active.
-	iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled ); 
-	RThread().SetProcessPriority( EPriorityHigh );
+  //window server when it is not active.
+  iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled ); 
+  RThread().SetProcessPriority( EPriorityHigh );
 
     FeatureManager::InitializeLibL();
 
-	RTelServer::TPhoneInfo PhoneInfo;
-	// prevent autolock shutdown
-	iEikonEnv->SetSystem( ETrue ); 
+  RTelServer::TPhoneInfo PhoneInfo;
+  // prevent autolock shutdown
+  iEikonEnv->SetSystem( ETrue ); 
 
-	iSideKey1 = 0;
-	iSideKey2 = 0;
-	iAppKey = 0;
+	CKeyLockPolicyApi* iCKeyLockPolicyApi = CKeyLockPolicyApi::NewL( EPolicyActivateKeyguard );
+	TBool keyguardAllowed = iCKeyLockPolicyApi->KeyguardAllowed();
+  #if defined(_DEBUG)
+	RDebug::Printf( "%s %s (%u) keyguardAllowed=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, keyguardAllowed );
+  #endif
+	keyguardAllowed = iCKeyLockPolicyApi->EnableKeyguardFeature();
+  #if defined(_DEBUG)
+	RDebug::Printf( "%s %s (%u) new keyguardAllowed=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, keyguardAllowed );
+  #endif
+  delete iCKeyLockPolicyApi;
 
-	aCallButtonRect = TRect (0,0,0,0);
-	iGotEventDownDuringCall = -1;
-	//connect to ETel
+  iSideKey1 = 0;
+  iSideKey2 = 0;
+  iAppKey = 0;
 
-	TInt err( KErrGeneral );
+  aCallButtonRect = TRect (0,0,0,0);
+  iGotEventDownDuringCall = -1;
+  //connect to ETel
+
+  TInt err( KErrGeneral );
     TInt thisTry( 0 );
     
-	/*All server connections are tried to be made KTiesToConnectServer times because occasional
+  /*All server connections are tried to be made KTiesToConnectServer times because occasional
     fails on connections are possible at least on some servers*/
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() connect to etel server"));
     #endif
-	// connect etel server
-	while ( ( err = iServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
+  // connect etel server
+  while ( ( err = iServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
         {
         User::After( KTimeBeforeRetryingServerConnection );
         }
     User::LeaveIfError( err );
 
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() load tsy"));
     #endif
     // load tsy
     err = iServer.LoadPhoneModule( KMmTsyModuleName );
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() load tsy ERROR: %d"), err);
     #endif
     if ( err != KErrAlreadyExists )
@@ -132,47 +145,49 @@
         // not an error.
         User::LeaveIfError( err );
         }
-	
-	thisTry = 0;
-	#if defined(_DEBUG)
+  
+  thisTry = 0;
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() open phone"));
     #endif
-	//open phone
-	User::LeaveIfError(iServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended));
-	User::LeaveIfError(iServer.GetPhoneInfo(PhoneIndex, PhoneInfo));
-	User::LeaveIfError(iPhone.Open(iServer,PhoneInfo.iName));
+  //open phone
+  User::LeaveIfError(iServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended));
+  User::LeaveIfError(iServer.GetPhoneInfo(PhoneIndex, PhoneInfo));
+  User::LeaveIfError(iPhone.Open(iServer,PhoneInfo.iName));
     User::LeaveIfError(iCustomPhone.Open(iPhone));
- 	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() phone opened"));
     #endif
 
   TBool systemLocked = EFalse;
-	TBool phoneLocked = EFalse;
+  TBool phoneLocked = EFalse;
 
     iWait = NULL;
     iWait = CWait::NewL();
 
-	#ifndef __WINS__
-
-
-	/*****************************************************
-	*	Series 60 Customer / ETEL
-	*	Series 60 ETEL API
-	*****************************************************/
-
-	// set autolock period to 0, if lock is disabled in DOS side
-	#if defined(_DEBUG)
-    RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() set autolock period to 0"));
-    #endif
 	RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
 	RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
 	RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
+	TInt cRresult = KErrNone;
+
+  #ifndef __WINS__
+
+
+  /*****************************************************
+  * Series 60 Customer / ETEL
+  * Series 60 ETEL API
+  *****************************************************/
+
+  // set autolock period to 0, if lock is disabled in DOS side
+  #if defined(_DEBUG)
+    RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() set autolock period to 0"));
+    #endif
     
-	iWait->SetRequestType(EMobilePhoneGetLockInfo);
-	iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
-	TInt res = iWait->WaitForRequestL();
-	User::LeaveIfError(res);
-	    
+  iWait->SetRequestType(EMobilePhoneGetLockInfo);
+  iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
+  TInt res = iWait->WaitForRequestL();
+  User::LeaveIfError(res);
+      
   // Eventhough we might lock the device on boot-up (systemLocked == ETrue), we
   // want to hide the app until the handshake is done. StartUp application will
   // active the app when it is finished.   
@@ -180,11 +195,11 @@
   self.SetWgId(iCoeEnv->RootWin().Identifier());
   self.SendToBackground();
   // flush
-  iCoeEnv->WsSession().Flush();	    
-		    
+  iCoeEnv->WsSession().Flush();     
+        
     TInt lockValue = 0;
     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings);
-    TInt cRresult = repository->Get(KSettingsAutolockStatus, lockValue);
+    cRresult = repository->Get(KSettingsAutolockStatus, lockValue);
     TBool hiddenReset = HiddenReset();
     #if defined(_DEBUG)
     if(hiddenReset)
@@ -192,9 +207,11 @@
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() CR get result: %d"), cRresult);
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() CR lock value: %d"), lockValue);
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() CR lockInfo.iSetting: %d"), lockInfo.iSetting);    
+    RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() RMobilePhone::ELockSetEnabled: %d"), RMobilePhone::ELockSetEnabled);    
+    RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() RMobilePhone::ELockSetDisabled: %d"), RMobilePhone::ELockSetDisabled);    
     #endif
-	  if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
-		{
+    if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
+    {
         repository->Set(KSettingsAutoLockTime, 0);
         if ( FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) )
             {
@@ -215,16 +232,16 @@
         #endif
         phoneLocked = ETrue;
         }             
- 	
+  
      
     delete repository;
-	#endif   //__WINS__
+  #endif   //__WINS__
 
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() Enable emergency call support"));
     #endif
-	
-	#if defined(_DEBUG)
+  
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() Autolock view"));
     #endif
     
@@ -238,48 +255,48 @@
     iEcsNote->ConstructSleepingNoteL(R_AVKON_EMERGENCY_CALL_NOTE);
     iEcsNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(0,2);
     
-    if (AknLayoutUtils::PenEnabled())	// on touch devices, if Autolock is activated from IdleScreen in landscape, the buttons need to be drawn.
-	{
-	iEcsNote->ButtonGroupContainer().SetCommandL( 0, _L("") );	// as keyboard is locked, these buttons do nothing. Better to hide their labels.
-  	iEcsNote->ButtonGroupContainer().SetCommandL( EAknSoftkeyCancel, _L("") );
-	iEcsNote->ButtonGroupContainer().ButtonGroup()->AsControl()->MakeVisible(ETrue);
-  	}
+    if (AknLayoutUtils::PenEnabled()) // on touch devices, if Autolock is activated from IdleScreen in landscape, the buttons need to be drawn.
+  {
+  iEcsNote->ButtonGroupContainer().SetCommandL( 0, _L("") );  // as keyboard is locked, these buttons do nothing. Better to hide their labels.
+    iEcsNote->ButtonGroupContainer().SetCommandL( EAknSoftkeyCancel, _L("") );
+  iEcsNote->ButtonGroupContainer().ButtonGroup()->AsControl()->MakeVisible(ETrue);
+    }
 
-	// Emergency call support
+  // Emergency call support
     iEcsDetector = CAknEcsDetector::NewL();
     iEcsDetector->SetObserver( this );
-	iEmergencySupportReady = ETrue;
+  iEmergencySupportReady = ETrue;
     // -------------------------------------------------------------------------------------------------------------
         
 
-	// Autolock view	
-	CAutolockView* lockView = new(ELeave) CAutolockView;
+  // Autolock view  
+  CAutolockView* lockView = new(ELeave) CAutolockView;
     CleanupStack::PushL(lockView);
     lockView->ConstructL();
-    CleanupStack::Pop();	// lockView
+    CleanupStack::Pop();  // lockView
     AddViewL(lockView);    // transfer ownership to CAknViewAppUi
-	SetDefaultViewL(*lockView);
+  SetDefaultViewL(*lockView);
 
-	// start autolock timer
-	iModel = CAutoLockModel::NewL(this, phoneLocked);	
+  // start autolock timer
+  iModel = CAutoLockModel::NewL(this, phoneLocked); 
 
-	// phone event observer
-	iPhoneObserver = CValueObserver::NewL(this);
-	//call bubble
-	iIncallBubble = CAknIncallBubble::NewL();
+  // phone event observer
+  iPhoneObserver = CValueObserver::NewL(this);
+  //call bubble
+  iIncallBubble = CAknIncallBubble::NewL();
 
-	//Autokeyguard Period observer
-	#ifdef RD_AUTO_KEYGUARD
-	iKeyguardObserver = CAutoKeyguardObserver::NewL(this);
-	#else //!RD_AUTO_KEYGUARD
-	iKeyguardObserver = NULL;
-	#endif //RD_AUTO_KEYGUARD
+  //Autokeyguard Period observer
+  #ifdef RD_AUTO_KEYGUARD
+  iKeyguardObserver = CAutoKeyguardObserver::NewL(this);
+  #else //!RD_AUTO_KEYGUARD
+  iKeyguardObserver = NULL;
+  #endif //RD_AUTO_KEYGUARD
     // Create the write policy. Also processes with write device data can write the value.
     TSecurityPolicy writePolicy( ECapabilityWriteDeviceData ); 
-	// Create the read policy. Also processes with read device data can read the value.	
-	TSecurityPolicy readPolicy( ECapabilityReadDeviceData ); 
-	
-	TInt tRet = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, RProperty::EInt, readPolicy, writePolicy );
+  // Create the read policy. Also processes with read device data can read the value. 
+  TSecurityPolicy readPolicy( ECapabilityReadDeviceData ); 
+  
+  TInt tRet = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, RProperty::EInt, readPolicy, writePolicy );
         
     if ( tRet != KErrNone )
         {
@@ -287,7 +304,7 @@
         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
             FAILED to define the SECUI query Flag: %d"), tRet);
         #endif
-        }	
+        } 
     
     tRet = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, RProperty::EInt, readPolicy, writePolicy );
     if ( tRet != KErrNone )
@@ -320,21 +337,57 @@
     RSCPClient scpClient;
     if ( scpClient.Connect() == KErrNone )
         {
-        TInt confStatus = scpClient.CheckConfiguration( KSCPInitial );
-        
+        TInt confStatus = KErrNone;
+        // check whether this is normal or exceptional boot. This solves the issue when PIN is requested, Autolock starts, and scpClient.CheckConfiguration verifies the internal lock code
+        TInt startupReason(ENormalStartup);
+    		RProperty::Get(KPSUidStartup, KPSStartupReason, startupReason);
+
+				TInt secQueryStatus = ESecurityQueryUninitialized;
+				TInt tRet = RProperty::Get(KPSUidStartup, KStartupSecurityCodeQueryStatus, secQueryStatus);
+				#if defined(_DEBUG)
+				RDebug::Printf( "%s %s (%u) startupReason=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, startupReason );
+				RDebug::Printf( "%s %s (%u) secQueryStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, secQueryStatus );
+				RDebug::Printf( "%s %s (%u) cRresult=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, cRresult );
+				RDebug::Printf( "%s %s (%u) lockInfo.iSetting=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, lockInfo.iSetting );
+				RDebug::Printf( "%s %s (%u) tRet=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, tRet );
+				#endif
+
+				TInt simStatusValue;
+				tRet = RProperty::Get(KPSUidStartup, KPSSimStatus, simStatusValue);
+				#if defined(_DEBUG)
+				RDebug::Printf( "%s %s (%u) tRet=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, tRet );
+				RDebug::Printf( "%s %s (%u) simStatusValue=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, simStatusValue );
+				RDebug::Printf( "%s %s (%u) ESimReadable=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, ESimReadable );
+				#endif
+					
+        if( simStatusValue==ESimReadable && secQueryStatus==ESecurityQueryActive)
+        	{	// query during SIM-query. This should not happen because check on CSecurityNotifier::GetParamsL  iEvent != RMobilePhone::EPin1Required
+					#if defined(_DEBUG)
+					RDebug::Printf( "%s %s (%u) tRet=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, tRet );
+					#endif
+        	confStatus = KErrNone;	// the best thing to do is to skip CheckConfiguration, because it might secretly accept the lock-code
+        	}
+        else
+        	confStatus = scpClient.CheckConfiguration( KSCPInitial );
+        #if defined(_DEBUG)
+				RDebug::Printf( "%s %s (%u) confStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, confStatus );
+				RDebug::Printf( "%s %s (%u) KErrAccessDenied=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KErrAccessDenied );
+				#endif
         if ( confStatus == KErrAccessDenied )
             {
             #ifndef __WINS__            
-            if ( ( lockInfo.iSetting == RMobilePhone::ELockSetDisabled ) )    
+            if ( 1 )    // Previously was ( lockInfo.iSetting == RMobilePhone::ELockSetDisabled )   but now it needs to handle scenarios : ISA_format without drive format, and the opposite
             #else // __WINS__                    
             if ( 1 ) // DOS lock is never active in WINS            
             #endif // __WINS__     
-		        {					
-		        // DOS lock is not active. Note that if DOS is locked, checking the code here will
-		        // mess up the query sequence. On initial startup DOS is not locked.		                
+            {         
+            // DOS lock is not active. Note that if DOS is locked, checking the code here will
+            // mess up the query sequence. On initial startup DOS is not locked.                    
                 
                 TInt finalConfStatus = scpClient.CheckConfiguration( KSCPComplete );
-                
+                #if defined(_DEBUG)
+								RDebug::Printf( "%s %s (%u) finalConfStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, finalConfStatus );
+                #endif
                 if ( finalConfStatus == KErrAccessDenied )
                     {                
                     #ifdef __WINS__   
@@ -346,7 +399,7 @@
 
                     // The SCP server is out of sync and Autolock is not active. (c-drive formatted)
                     // We must ask the security code. ( Note that it is very rare that this is executed )
-	                #if defined(_DEBUG)
+                  #if defined(_DEBUG)
                     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
                         Lock setting disabled, calling setlocksetting"));
                     #endif
@@ -369,25 +422,25 @@
                 
                     // Just change the lock setting again to disabled to request the security code.
                     // Set the TARM flag so SecUi knows it should display the "login" query.
-	                TInt tarmFlag=0;
-	                tRet = RProperty::Get( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
-	                if ( tRet == KErrNone )
-    	                {
-	                    tarmFlag |= KSCPFlagResyncQuery;
-	                    tRet = RProperty::Set( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
-	                    }
-	            
-	                if ( tRet != KErrNone )
+                  TInt tarmFlag=0;
+                  tRet = RProperty::Get( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
+                  if ( tRet == KErrNone )
+                      {
+                      tarmFlag |= KSCPFlagResyncQuery;
+                      tRet = RProperty::Set( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
+                      }
+              
+                  if ( tRet != KErrNone )
                         {
                         #if defined(_DEBUG)
                         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
                             FAILED to set TARM Admin Flag"));
                         #endif
                         }
-	            
-    	            RMobilePhone::TMobilePhoneLockSetting lockChange;
-	                lockChange = RMobilePhone::ELockSetDisabled;
-	                iWait->SetRequestType(EMobilePhoneSetLockSetting);
+              
+                  RMobilePhone::TMobilePhoneLockSetting lockChange;
+                  lockChange = RMobilePhone::ELockSetDisabled;
+                  iWait->SetRequestType(EMobilePhoneSetLockSetting);
                     iPhone.SetLockSetting(iWait->iStatus, lockType, lockChange);
                 
                     res = iWait->WaitForRequestL();
@@ -405,8 +458,26 @@
     // Eventhough we might lock the device on boot-up (systemLocked == ETrue), we
     // want to hide the app until the handshake is done. StartUp application will
     // active the app when it is finished.
+    #if defined(_DEBUG)
+		RDebug::Printf( "%s %s (%u) systemLocked=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, systemLocked );
+		RDebug::Printf( "%s %s (%u) phoneLocked=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, phoneLocked );
+		#endif
     if( !systemLocked )
-        {// app to background
+        {
+        // incoming call on boot
+				TInt value(EStartupUiPhaseUninitialized);
+				RProperty::Get(KPSUidStartup, KPSStartupUiPhase, value);
+				#if defined(_DEBUG)
+				RDebug::Printf( "%s %s (%u) KPSStartupUiPhase value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, value );
+				#endif
+        if( value<EStartupUiPhaseSystemWelcomeDone )
+        	{
+        	TInt err=iPhoneObserver->Start();
+        	#if defined(_DEBUG)
+					RDebug::Printf( "%s %s (%u) err=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, err );
+					#endif
+					}
+        // app to background
         #if defined(_DEBUG)
         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() app to background"));
         #endif
@@ -424,10 +495,10 @@
         TInt lockState = 0;
         
         #ifdef RD_REMOTELOCK
-	    lockState = EManualLocked; 	    
-	    #else //!RD_REMOTELOCK	    
-	    lockState = EAutolockOn; 	    
-	    #endif//RD_REMOTELOCK
+      lockState = EManualLocked;      
+      #else //!RD_REMOTELOCK      
+      lockState = EAutolockOn;      
+      #endif//RD_REMOTELOCK
         iModel->LockSystemL(lockState);  
         }
         
@@ -437,7 +508,7 @@
     #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL()  END"));
     #endif
-	}
+  }
 // ----------------------------------------------------
 // CAutolockAppUi::~CAutolockAppUi()
 // Destructor
@@ -456,8 +527,8 @@
         if(iWait->IsActive())
             {
             #if defined(_DEBUG)
-	        RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::~CAutolockAppUi() CANCEL REQ"));
-	        #endif
+          RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::~CAutolockAppUi() CANCEL REQ"));
+          #endif
             iPhone.CancelAsyncRequest(iWait->GetRequestType());
             }
         }
@@ -466,18 +537,18 @@
         iCustomPhone.Close();
     
     if (iPhone.SubSessionHandle())
-    	iPhone.Close();
+      iPhone.Close();
     
     if (iServer.Handle())
         {           
         iServer.UnloadPhoneModule(KMmTsyModuleName);
         iServer.Close();
         }
-	delete iModel;
-	delete iPhoneObserver;
-	delete iIncallBubble;
+  delete iModel;
+  delete iPhoneObserver;
+  delete iIncallBubble;
 #ifdef RD_AUTO_KEYGUARD
-	delete iKeyguardObserver;
+  delete iKeyguardObserver;
 #endif
 
     delete iEcsDetector;
@@ -489,102 +560,130 @@
     #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::~CAutolockAppUi() END"));
     #endif
-	}
+  }
 // ----------------------------------------------------
 // CAutolockAppUi::HandleForegroundEventL()
 // Handles foreground event.
 // ----------------------------------------------------
 //
 void CAutolockAppUi::HandleForegroundEventL(TBool aForeground)
-	{
-	#if defined(_DEBUG)
+  {
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleForegroundEventL()"));
     #endif
-	if (aForeground )
-		{
-		if (iLocked)
-			{
-			// lock voice key 
-			LockSideKeyL();	
-			CAknView* view = View(KAutoLockViewId);
-			if(view)
-				{	
-		  		TRect aInitialRect;
-				STATIC_CAST(CAutolockView*, view)->HandleCall(0x15, aInitialRect);
-				}
-		
-			}
-		else
-			{
-			// app back to background
-			TApaTask self(iCoeEnv->WsSession());
-			self.SetWgId(iCoeEnv->RootWin().Identifier());
-			self.SendToBackground();
-			}
-		}
+  if (aForeground )
+    {
+    if (iLocked)
+      {
+      // lock voice key 
+      LockSideKeyL(); 
+      CAknView* view = View(KAutoLockViewId);
+      if(view)
+        { 
+          TRect aInitialRect;
+        STATIC_CAST(CAutolockView*, view)->HandleCall(0x15, aInitialRect);
+        }
+    
+      }
+    else
+      {
+      // app back to background
+      TApaTask self(iCoeEnv->WsSession());
+      self.SetWgId(iCoeEnv->RootWin().Identifier());
+      self.SendToBackground();
+      }
+    }
 
-	if (!aForeground && iLocked)
-		{
+  if (!aForeground && iLocked)
+    {
         TInt callState=0;
         TInt simStatus=0;
         RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callState );
         RProperty::Get(KPSUidStartup, KPSSimStatus, simStatus);
 
         if (callState == EPSCTsyCallStateNone && simStatus != ESimNotPresent)
-			{	
-			// try put autolock back to foreground
-			CAknView* view = View(KAutoLockViewId);
-			if(view)
-				{	
-				TRect aInitialRect;
-				STATIC_CAST(CAutolockView*, view)->HandleCall(0x19, aInitialRect);
-				}
-			TApaTask self(iCoeEnv->WsSession());
-			self.SetWgId(iCoeEnv->RootWin().Identifier());
-			self.BringToForeground();		
-			}
-		else
-			{
-			// unlock voice key while there is active call
-			UnLockSideKey();
-			CAknView* view = View(KAutoLockViewId);
-			if(view)
-				{	
-			  	TRect aInitialRect;
-				STATIC_CAST(CAutolockView*, view)->HandleCall(0x16, aInitialRect);
-				}
-			}
-		}
+      { 
+      // try put autolock back to foreground
+      CAknView* view = View(KAutoLockViewId);
+      if(view)
+        { 
+        TRect aInitialRect;
+        STATIC_CAST(CAutolockView*, view)->HandleCall(0x19, aInitialRect);
+        }
+      TApaTask self(iCoeEnv->WsSession());
+      self.SetWgId(iCoeEnv->RootWin().Identifier());
+      self.BringToForeground();   
+      }
+    else
+      {
+      // unlock voice key while there is active call
+      UnLockSideKey();
+      CAknView* view = View(KAutoLockViewId);
+      if(view)
+        { 
+          TRect aInitialRect;
+        STATIC_CAST(CAutolockView*, view)->HandleCall(0x16, aInitialRect);
+        }
+      }
+    }
 
-	CAknAppUi::HandleForegroundEventL(aForeground);
-	
-	}
-	
+  CAknAppUi::HandleForegroundEventL(aForeground);
+  
+  }
+
+
+// ----------------------------------------------------
+// HideSoftNotification()
+// dismiss all the pending notes just before asking the unlocking code
+// ----------------------------------------------------
+//
+void HideSoftNotification()
+    {
+    #if defined(_DEBUG)
+    RDebug::Print(_L("(AUTOLOCK)HideSoftNotification"));
+    #endif
+    CAknSoftNotifier *softNotifier = NULL;
+    TRAPD (err, {
+            softNotifier = CAknSoftNotifier::NewL();
+            softNotifier->AddNotificationL(ESetIdleState, 0);
+    };)
+    delete softNotifier;
+    }
+// CAutolockAppUi::HandleCommandL(TInt aCommand)
+// ----------------------------------------------------  
+
 
 // ----------------------------------------------------
 // CAutolockAppUi::HandleMessageL
 //
 // Handles the TARM command to unlock the phone.
 // ----------------------------------------------------
-//	
+//  
 MCoeMessageObserver::TMessageResponse CAutolockAppUi::HandleMessageL( 
                                 TUint32 aClientHandleOfTargetWindowGroup, 
                                 TUid aMessageUid, 
                                 const TDesC8& aMessageParameters 
                                )
     {
-    	
-    	if(!FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))  
-    	{
-    		User::Leave(KErrNotSupported);
-    	}
+      
+      if(!FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))  
+      {
+        User::Leave(KErrNotSupported);
+      }
     #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleMessageL()"));
     #endif
     
     MCoeMessageObserver::TMessageResponse messageResponse( EMessageHandled );
     
-    if ( aMessageUid.iUid == SCP_CMDUID_UNLOCK )
+    if ( aMessageUid.iUid == SCP_CMDUID_UNLOCK+1 )
+        {
+        #if defined(_DEBUG)
+        RDebug::Printf( "%s %s (%u) calling CancelDeviceLockQuery=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
+        #endif
+        CancelDeviceLockQuery();
+        }
+    else if ( aMessageUid.iUid == SCP_CMDUID_UNLOCK )
         {        
         // For security reasons we must check from the SCP server did this 
         // command originate from it.                                
@@ -611,15 +710,16 @@
                 else
                     {
                     iLocked = EFalse;
-                  DisableWGListChangeEventListening();  
-	                UnLockKeys();
-	                iModel->SetLockedL(EFalse);
-			// Disable keyguard after remote unlock
-	                RAknKeyLock iKeyLock;
-	                TInt tempResult = iKeyLock.Connect();
-	                iKeyLock.DisableKeyLock();
-	                // end Disable keyguard after remote unlock
-	                SwitchToPreviousAppL();
+                    HideSoftNotification(); // dismiss all the pending notes                    
+                    DisableWGListChangeEventListening();  
+                    UnLockKeys();
+                    iModel->SetLockedL(EFalse);
+                    // Disable keyguard after remote unlock
+                    RAknKeyLock iKeyLock;
+                    TInt tempResult = iKeyLock.Connect();
+                    iKeyLock.DisableKeyLock();
+                  // end Disable keyguard after remote unlock
+                    SwitchToPreviousAppL();
                     }   
                 }           
             else
@@ -651,8 +751,8 @@
     
     return messageResponse;
     }
-    	 	
- 	
+        
+  
 // ------------------------------------------------------------------------------
 // CAutolockAppUi::::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
 //  This function is called by the UIKON framework just before it displays
@@ -668,8 +768,10 @@
 
 void CAutolockAppUi::HandlePointerEventL(const TPointerEvent& aPointerEvent)
     {
+	#if defined(_DEBUG)
     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
-		}
+	#endif
+    }
 // ----------------------------------------------------
 // CAutolockAppUi::HandleKeyEventL(
 //     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
@@ -680,11 +782,11 @@
     {
         
     if ( aKeyEvent.iCode == EKeyBell || (aType == EEventKeyUp && aKeyEvent.iScanCode == EStdKeyDeviceF)  || (aKeyEvent.iCode == EKeyDeviceF) )
-		{
-		if(iLocked)    
- 		    HandleCommandL(ESecUiCmdUnlock);
- 		return EKeyWasConsumed; 
- 		}
+    {
+    if(iLocked)    
+        HandleCommandL(ESecUiCmdUnlock);
+    return EKeyWasConsumed; 
+    }
 
     TBool featureNoPowerkey = FeatureManager::FeatureSupported( KFeatureIdNoPowerkey );
     // If power key pressed, tell SysAp about if
@@ -714,87 +816,68 @@
         }
     }
 
-// ----------------------------------------------------
-// HideSoftNotification()
-// dismiss all the pending notes just before asking the unlocking code
-// ----------------------------------------------------
-//
-void HideSoftNotification()
-    {
-    #if defined(_DEBUG)
-    RDebug::Print(_L("(AUTOLOCK)HideSoftNotification"));
-    #endif
-    CAknSoftNotifier *softNotifier = NULL;
-    TRAPD (err, {
-            softNotifier = CAknSoftNotifier::NewL();
-            softNotifier->AddNotificationL(ESetIdleState, 0);
-    };)
-    delete softNotifier;
-    }
-// CAutolockAppUi::HandleCommandL(TInt aCommand)
-// ----------------------------------------------------
-//
+
 void CAutolockAppUi::HandleCommandL(TInt aCommand)
     {
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleCommandL()"));
     #endif
-	switch ( aCommand )
+  switch ( aCommand )
         {
         case EEikCmdExit:
-			{
-			#if defined(_DEBUG)
-			RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleCommandL() EEikCmdExit"));
-			#endif
+      {
+      #if defined(_DEBUG)
+      RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleCommandL() EEikCmdExit"));
+      #endif
             Exit();
             break;
-			}
+      }
         case ESecUiCmdUnlock:
-			{
-			#if defined(_DEBUG)
-			RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleCommandL() ESecUiCmdUnlock"));
-			#endif
-			// stop observing emergency call event
-			iEmergencySupportReady = EFalse;
-			iEcsDetector->Reset(); // Ecs queue is cleared; keys up til here are forgotten
-			// ask secuity code
-			CSecurityHandler* handler = new (ELeave) CSecurityHandler(iPhone);
-			CleanupStack::PushL(handler);
-			TSecUi::InitializeLibL();	
-	        
-	        // Put the lights on when security query is shown
-	        SendMessageToSysAp( EEikSecurityQueryLights );
-	        HideSoftNotification();	// dismiss all the pending notes just before asking the unlocking code
-	        
+      {
+      #if defined(_DEBUG)
+      RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleCommandL() ESecUiCmdUnlock"));
+      #endif
+      // stop observing emergency call event
+      iEmergencySupportReady = EFalse;
+      iEcsDetector->Reset(); // Ecs queue is cleared; keys up til here are forgotten
+      // ask secuity code
+      CSecurityHandler* handler = new (ELeave) CSecurityHandler(iPhone);
+      CleanupStack::PushL(handler);
+      TSecUi::InitializeLibL(); 
+          
+          // Put the lights on when security query is shown
+          SendMessageToSysAp( EEikSecurityQueryLights );
+          HideSoftNotification(); // dismiss all the pending notes just before asking the unlocking code
+          
             TRAPD(err,
-			{
-			iDeviceLockQueryStatus = ETrue;
-			if(handler->AskSecCodeInAutoLockL())
-				{		
-				iLocked = EFalse;
-				DisableWGListChangeEventListening();
-				iDeviceLockQueryStatus = EFalse;
-				UnLockKeys();
-				iModel->SetLockedL(EFalse);
-				SwitchToPreviousAppL();
-				}
+      {
+      iDeviceLockQueryStatus = ETrue;
+      if(handler->AskSecCodeInAutoLockL())
+        {   
+        iLocked = EFalse;
+        DisableWGListChangeEventListening();
+        iDeviceLockQueryStatus = EFalse;
+        UnLockKeys();
+        iModel->SetLockedL(EFalse);
+        SwitchToPreviousAppL();
+        }
             else
-				{  // make sure that we will be topmost still
-				    iDeviceLockQueryStatus = EFalse;
+        {  // make sure that we will be topmost still
+            iDeviceLockQueryStatus = EFalse;
                     TInt callState;
                     RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
                 if ( callState == EPSCTsyCallStateNone &&
                      !FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) )
                     {
-				    TApaTask self(CCoeEnv::Static()->WsSession());
-				    self.SetWgId(CCoeEnv::Static()->RootWin().Identifier());
-				    self.BringToForeground();
+            TApaTask self(CCoeEnv::Static()->WsSession());
+            self.SetWgId(CCoeEnv::Static()->RootWin().Identifier());
+            self.BringToForeground();
                     TBool featureNoPowerkey = FeatureManager::FeatureSupported( KFeatureIdNoPowerkey );
                     if ( featureNoPowerkey )
                         {//set lights on in case user pressed "red button". If he pressed cancel the lights are on anyway so it doesn't matter.
                         SendMessageToSysAp(EEikKeyLockLightsOnRequest);              
                         }
-				    // we don't want enable lock if call in progress    
+            // we don't want enable lock if call in progress    
                     RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
                     TInt keyguardDisableState(ECoreAppUIsDisableKeyguardUninitialized);
                     //If there is alarm on the keyguard status is set to disabled. In that case don't enable keyguard as it will be done by SysAp 
@@ -802,26 +885,26 @@
                     RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, keyguardDisableState );
                     if ((callState == EPSCTsyCallStateNone) && (keyguardDisableState != ECoreAppUIsDisableKeyguard))
                         {   
-				    	RAknKeyLock keylock;
-					    if ( keylock.Connect() == KErrNone )
-						    {
-						    keylock.EnableAutoLockEmulation();
-						    keylock.Close();
-						    }
-					    }
+              RAknKeyLock keylock;
+              if ( keylock.Connect() == KErrNone )
+                {
+                keylock.EnableAutoLockEmulation();
+                keylock.Close();
+                }
+              }
                     }
                 }
-			};)
+      };)
 
-			// start observing emergency call event
-			iEmergencySupportReady = ETrue;
-			CleanupStack::PopAndDestroy(handler); // handler
-			TSecUi::UnInitializeLib();  // secui 		
-			
-			User::LeaveIfError(err);
+      // start observing emergency call event
+      iEmergencySupportReady = ETrue;
+      CleanupStack::PopAndDestroy(handler); // handler
+      TSecUi::UnInitializeLib();  // secui    
+      
+      User::LeaveIfError(err);
 
-			break;
-			}
+      break;
+      }
         default:
             break;      
         } 
@@ -833,43 +916,43 @@
 //----------------------------------------------------
 //
 void CAutolockAppUi::SwitchToPreviousAppL()
-	{
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::SwitchToPreviousAppL()"));
-	#endif
-	iEcsDetector->Reset(); // Ecs queue is cleared; keys up til here are forgotten
-	// stop observing phone events
-	iPhoneObserver->Stop();
-	CAknView* view = View(KAutoLockViewId);
-	if(view)
-	  {
-	  STATIC_CAST(CAutolockView*, view)->MakeVisible(EFalse);
-	  }
-	else
-	  {
-	  #if defined(_DEBUG)
-	  RDebug::Printf( "%s %s (%u) no view ????=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, view );
-	  #endif
-	  }
-	// app to background
-	TApaTask self(iCoeEnv->WsSession());
-	self.SetWgId(iCoeEnv->RootWin().Identifier());
-	self.SendToBackground();
-	// flush
-	iCoeEnv->WsSession().Flush();
-	}
+  {
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::SwitchToPreviousAppL()"));
+  #endif
+  iEcsDetector->Reset(); // Ecs queue is cleared; keys up til here are forgotten
+  // stop observing phone events
+  iPhoneObserver->Stop();
+  CAknView* view = View(KAutoLockViewId);
+  if(view)
+    {
+    STATIC_CAST(CAutolockView*, view)->MakeVisible(EFalse);
+    }
+  else
+    {
+    #if defined(_DEBUG)
+    RDebug::Printf( "%s %s (%u) no view ????=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, view );
+    #endif
+    }
+  // app to background
+  TApaTask self(iCoeEnv->WsSession());
+  self.SetWgId(iCoeEnv->RootWin().Identifier());
+  self.SendToBackground();
+  // flush
+  iCoeEnv->WsSession().Flush();
+  }
 // ----------------------------------------------------
 // CAutolockAppUi::BringAppToForegroundL()
 // Activates autolock app
 //----------------------------------------------------
 //
 void CAutolockAppUi::BringAppToForegroundL()
-	{
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::BringAppToForegroundL()"));
-	#endif
-	TBool tarmAdminFlag(EFalse);
-	TBool remotelockState(EFalse);
+  {
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::BringAppToForegroundL()"));
+  #endif
+  TBool tarmAdminFlag(EFalse);
+  TBool remotelockState(EFalse);
 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))
 {
     tarmAdminFlag = TarmState();
@@ -881,37 +964,67 @@
         remotelockState = (autolockState == ERemoteLocked);           
 #endif//RD_REMOTELOCK
 	// If TARM admin flag is set, bring Autolock to foreground regardless of call state.
+
+
 	if(!tarmAdminFlag)
 	{   //If phone has been remote locked bring Autolock to foreground regardless of call state.
 	    if(!remotelockState)
 	    {   // check if there is active call
-    	    TInt callState;
-    	    RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
+				TInt callState;
+				RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
+				#if defined(_DEBUG)
+				RDebug::Printf( "%s %s (%u) callState=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, callState );
+				#endif
+
+				TInt value(EStartupUiPhaseUninitialized);
+				RProperty::Get(KPSUidStartup, KPSStartupUiPhase, value);
+				#if defined(_DEBUG)
+				RDebug::Printf( "%s %s (%u) KPSStartupUiPhase value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, value );
+				RDebug::Printf( "%s %s (%u) EStartupUiPhaseSystemWelcomeDone=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EStartupUiPhaseSystemWelcomeDone );
+				#endif
+				if(value<EStartupUiPhaseSystemWelcomeDone && callState == EPSCTsyCallStateNone)
+					{
+					callState = EPSCTsyCallStateNone+1;	// so that is unlocks
+					iLocked = EFalse;
+					#if defined(_DEBUG)
+					RDebug::Printf( "%s %s (%u) iLocked=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLocked );
+					#endif
+					}
+				else if(value<EStartupUiPhaseSystemWelcomeDone && callState > EPSCTsyCallStateNone)
+					{
+					callState = EPSCTsyCallStateNone+0;	// so that is locks
+					#if defined(_DEBUG)
+					RDebug::Printf( "%s %s (%u) new+0 callState=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, callState );
+					#endif
+					}
             if (callState != EPSCTsyCallStateNone )
                 {
-    		    iModel->SetLockedL(EFalse);
-    		    iModel->ResetInactivityTimeout();
-    		    UnLockKeys();
-    		    return;
-    		    }   
+               	#if defined(_DEBUG)
+								RDebug::Printf( "%s %s (%u) 1=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
+								#endif
+		    		    UnLockKeys();
+		    		    iModel->SetLockedL(EFalse);
+		    		    iModel->ResetInactivityTimeout();
+		    		    return;
+		    		    }   
 	    }
 	    
 	}
          		
 
-	#ifndef __WINS__
+  #ifndef __WINS__
 
-	#ifndef __NO_DOS__
+  #ifndef __NO_DOS__
 
-		/*****************************************************
-		*	Series 60 Customer / ETEL
-		*	Series 60 ETEL API
-		*****************************************************/
+    /*****************************************************
+    * Series 60 Customer / ETEL
+    * Series 60 ETEL API
+    *****************************************************/
 
-	// check that device locked in DOS side too
-	RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
-	RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
-	RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
+  // check that device locked in DOS side too
+  RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
+  RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
+  RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
 
 	#if defined(_DEBUG)
 	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::BringAppToForegroundL() GetLockInfo"));
@@ -925,6 +1038,8 @@
 		// if not don't lock ui either
 		#if defined(_DEBUG)
 		RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::BringAppToForegroundL() KErrNone"));
+		RDebug::Printf( "%s %s (%u) lockInfo.iSetting=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, lockInfo.iSetting );
+		RDebug::Printf( "%s %s (%u) RMobilePhone::ELockSetDisabled=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, RMobilePhone::ELockSetDisabled );
 		#endif
 		if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
 			{
@@ -935,46 +1050,49 @@
 		}
 	#endif
 
-	#endif
+  #endif
 
-	// in case Telephone-app is topmost, then the user is confused because he sees but can't use it.
-	// therefore it's required to hide it, by sending to background. ETMA-7M8A2Y 20090105
-	if ( AknLayoutUtils::PenEnabled() )
-     	{ 		
-   			TApaTaskList apaTaskList(CCoeEnv::Static()->WsSession());
+  // in case Telephone-app is topmost, then the user is confused because he sees but can't use it.
+  // therefore it's required to hide it, by sending to background. ETMA-7M8A2Y 20090105
+  if ( AknLayoutUtils::PenEnabled() )
+      {     
+        TApaTaskList apaTaskList(CCoeEnv::Static()->WsSession());
 
-   			TApaTask apaTask = apaTaskList.FindApp(KPhoneAppUid);
-   			if (apaTask.Exists())
-       	{
-			 		#if defined(_DEBUG)
-			 			RDebug::Print(_L("(AUTOLOCK)CAknKeyLockControl::EnableKeylock() Bring phone to background"));
-			 		#endif
-       		// Bring phone to background
-       		apaTask.SendToBackground();
-       	}
-			}	
-	
-	iPhoneObserver->Start();
-	iLocked = ETrue;
-	// app to foreground	
-	TApaTask self(iCoeEnv->WsSession());
-	self.SetWgId(iCoeEnv->RootWin().Identifier());
-	self.BringToForeground();
-	ActivateLocalViewL(KAutoLockViewId);
-	CAknView* view = View(KAutoLockViewId);
-	if(view)
-	  {
-	  TRect aInitialRect;
+        TApaTask apaTask = apaTaskList.FindApp(KPhoneAppUid);
+        if (apaTask.Exists())
+        {
+          #if defined(_DEBUG)
+            RDebug::Print(_L("(AUTOLOCK)CAknKeyLockControl::EnableKeylock() Bring phone to background"));
+          #endif
+          // Bring phone to background
+          apaTask.SendToBackground();
+        }
+      } 
+	#if defined(_DEBUG)
+	RDebug::Printf( "%s %s (%u) iPhoneObserver->Start=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
+	#endif
+  
+  iPhoneObserver->Start();
+  iLocked = ETrue;
+  // app to foreground  
+  TApaTask self(iCoeEnv->WsSession());
+  self.SetWgId(iCoeEnv->RootWin().Identifier());
+  self.BringToForeground();
+  ActivateLocalViewL(KAutoLockViewId);
+  CAknView* view = View(KAutoLockViewId);
+  if(view)
+    {
+    TRect aInitialRect;
       STATIC_CAST(CAutolockView*, view)->HandleCall(0x17, aInitialRect);
-	  STATIC_CAST(CAutolockView*, view)->MakeVisible(ETrue);
-	  }
-	else
-	  {
-	  #if defined(_DEBUG)
-	  RDebug::Printf( "%s %s (%u) no view ????=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, view );
-	  #endif
-	  }
-	}
+    STATIC_CAST(CAutolockView*, view)->MakeVisible(ETrue);
+    }
+  else
+    {
+    #if defined(_DEBUG)
+    RDebug::Printf( "%s %s (%u) no view ????=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, view );
+    #endif
+    }
+  }
 
 // ----------------------------------------------------
 // CAutolockAppUi::LockKeysL()
@@ -982,61 +1100,66 @@
 //----------------------------------------------------
 //
 void CAutolockAppUi::LockKeysL()
-	{
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::LockKeysL()"));
-	#endif
-	// capture appkey & volume key
-	if (!iAppKey)
-		{
-		RWindowGroup& groupWin=iCoeEnv->RootWin();
-		iAppKey = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication0, 0, 0); // Capture app key
-		}
-	// Any orientation change is a waste of battery and triggers unnecesary window events and paining.
-	// Not only that: in landscape the BigRedButton is too small.
-	// Therefore we always stay in portrait. The icon looks much nicer.
-	SetOrientationL( EAppUiOrientationPortrait );
-	LockSideKeyL();
-	}
+  {
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::LockKeysL()"));
+  #endif
+  // capture appkey & volume key
+  if (!iAppKey)
+    {
+    RWindowGroup& groupWin=iCoeEnv->RootWin();
+    iAppKey = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication0, 0, 0); // Capture app key
+    }
+  TInt gripStatus = EPSHWRMGripClosed;
+  RProperty::Get( KPSUidHWRM, KHWRMGripStatus, gripStatus );
+  #if defined(_DEBUG)
+  RDebug::Printf( "%s %s (%u) gripStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, gripStatus );
+  #endif
+  if(gripStatus==EPSHWRMGripOpen)
+    ForceOrientation(0);
+  else
+    ForceOrientation(1);
+  LockSideKeyL();
+  }
 // ----------------------------------------------------
 // CAutolockAppUi::UnLockKeys()
 // unlocks keys 
 //----------------------------------------------------
 //
 void CAutolockAppUi::UnLockKeys()
-	{
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::UnLockKeysL()"));
-	#endif
-	// uncapture appkey
-	if (iAppKey)
-		{
-		RWindowGroup& groupWin=iCoeEnv->RootWin();
-		groupWin.CancelCaptureKeyUpAndDowns(iAppKey);
-		iAppKey = 0;
-		}
-	UnLockSideKey();
-	}
+  {
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::UnLockKeysL()"));
+  #endif
+  // uncapture appkey
+  if (iAppKey)
+    {
+    RWindowGroup& groupWin=iCoeEnv->RootWin();
+    groupWin.CancelCaptureKeyUpAndDowns(iAppKey);
+    iAppKey = 0;
+    }
+  UnLockSideKey();
+  }
 // ----------------------------------------------------
 // CAutolockAppUi::LockSideKeyL()
 // unlocks side-key 
 //----------------------------------------------------
 //
 void CAutolockAppUi::LockSideKeyL()
-	{
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::LockSideKeyL()"));
-	#endif
-	if (!iSideKey1)
-		{
-		RWindowGroup& groupWin=iCoeEnv->RootWin();
-		iSideKey1 = groupWin.CaptureKey(EKeyDeviceF,0,0);	// EKeySide -> EKeyDeviceF
-		#if defined(_DEBUG)
-		RDebug::Printf( "%s %s (%u) capturing EStdKeyDeviceF=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EStdKeyDeviceF );
-		#endif
-		iSideKey2 = groupWin.CaptureKeyUpAndDowns(EStdKeyDeviceF, 0, 0);	// EStdKeyDevice6 -> EStdKeyDeviceF
-		}
-	}
+  {
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::LockSideKeyL()"));
+  #endif
+  if (!iSideKey1)
+    {
+    RWindowGroup& groupWin=iCoeEnv->RootWin();
+    iSideKey1 = groupWin.CaptureKey(EKeyDeviceF,0,0); // EKeySide -> EKeyDeviceF
+    #if defined(_DEBUG)
+    RDebug::Printf( "%s %s (%u) capturing EStdKeyDeviceF=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EStdKeyDeviceF );
+    #endif
+    iSideKey2 = groupWin.CaptureKeyUpAndDowns(EStdKeyDeviceF, 0, 0);  // EStdKeyDevice6 -> EStdKeyDeviceF
+    }
+  }
 
 // -------------------------------------------------------------------------------------------------------------
 // part of emergency call handling when telephony+devicelock is active
@@ -1170,27 +1293,27 @@
     }
         
 // -------------------------------------------------------------------------------------------------------------
-	
+  
 // ----------------------------------------------------
 // CAutolockAppUi::UnLockSideKey()
 // unlocks side-key 
 //----------------------------------------------------
 //
 void CAutolockAppUi::UnLockSideKey()
-	{
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::UnLockSideKeyL()"));
-	#endif
-	if (iSideKey1)
-		{
-		RWindowGroup& groupWin=iCoeEnv->RootWin();
-		groupWin.CancelCaptureKeyUpAndDowns(iSideKey2);
-		groupWin.CancelCaptureKey(iSideKey1);
-		iSideKey1 = 0;
-		iSideKey2 = 0;
-		}
-	}
-	
+  {
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::UnLockSideKeyL()"));
+  #endif
+  if (iSideKey1)
+    {
+    RWindowGroup& groupWin=iCoeEnv->RootWin();
+    groupWin.CancelCaptureKeyUpAndDowns(iSideKey2);
+    groupWin.CancelCaptureKey(iSideKey1);
+    iSideKey1 = 0;
+    iSideKey2 = 0;
+    }
+  }
+  
 
 //
 // ---------------------------------------------------------
@@ -1218,28 +1341,28 @@
 //
 TBool CAutolockAppUi::IsPinBlocked()
 {
-	RMmCustomAPI::TSecurityCodeType secCodeType;
-	TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
-	TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
+  RMmCustomAPI::TSecurityCodeType secCodeType;
+  TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
+  TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
 
-	if(wcdmaSupported || upinSupported)
-	  {
-    	RMobilePhone::TMobilePhoneSecurityCode activePin;
-    	iCustomPhone.GetActivePin(activePin);
-    	if(activePin == RMobilePhone::ESecurityUniversalPin)
-    		secCodeType = RMmCustomAPI::ESecurityUniversalPin;
-    	else
-    		secCodeType = RMmCustomAPI::ESecurityCodePin1;
-	  }
-	else 
-	    secCodeType = RMmCustomAPI::ESecurityCodePin1;
-	
-	TBool isBlocked = EFalse;
+  if(wcdmaSupported || upinSupported)
+    {
+      RMobilePhone::TMobilePhoneSecurityCode activePin;
+      iCustomPhone.GetActivePin(activePin);
+      if(activePin == RMobilePhone::ESecurityUniversalPin)
+        secCodeType = RMmCustomAPI::ESecurityUniversalPin;
+      else
+        secCodeType = RMmCustomAPI::ESecurityCodePin1;
+    }
+  else 
+      secCodeType = RMmCustomAPI::ESecurityCodePin1;
+  
+  TBool isBlocked = EFalse;
     iCustomPhone.IsBlocked(secCodeType,isBlocked);
     #if defined(_DEBUG)
     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::IsPinBlocked result: %d"), isBlocked);
     #endif
-	return isBlocked;
+  return isBlocked;
 }
 
 //
@@ -1250,132 +1373,218 @@
 //
 void CAutolockAppUi::HandleWsEventL( const TWsEvent& aEvent,CCoeControl* aDestination )
     {
-    	const TInt type = aEvent.Type();
-		#if defined(_DEBUG)
-	    RDebug::Printf( "%s %s (%u) type=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, type );
-	    #endif
+      const TInt type = aEvent.Type();
+    #if defined(_DEBUG)
+      RDebug::Printf( "%s %s (%u) type=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, type );
+      #endif
 
-    	switch ( type )
-    	{
-    		case KAknFullOrPartialForegroundLost: // partial or full fg lost
-    			if( iIncallBubble )
+      switch ( type )
+      {
+        case KAknFullOrPartialForegroundLost: // partial or full fg lost
+          if( iIncallBubble )
                     {
                     #if defined(_DEBUG)
-    				RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleWsEventL: DISABLE call bubble"));
-    				#endif                    
+            RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleWsEventL: DISABLE call bubble"));
+            #endif                    
                     iIncallBubble->SetIncallBubbleAllowedInIdleL( EFalse );
                     }
-				break;
-		    case KAknFullOrPartialForegroundGained: // partial or full fg gained
-		    	if( iIncallBubble )
-		           	{
-		             	#if defined(_DEBUG)
-		    			RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleWsEventL: ENABLE call bubble"));
-		    			#endif
-   						CAknView* view = View(KAutoLockViewId);
-							if(view)
-								{	
-								TRect aInitialRect;
-								STATIC_CAST(CAutolockView*, view)->HandleCall(0x1A, aInitialRect);
-								}
+        break;
+        case KAknFullOrPartialForegroundGained: // partial or full fg gained
+          if( iIncallBubble )
+                {
+                  #if defined(_DEBUG)
+              RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleWsEventL: ENABLE call bubble"));
+              #endif
+              CAknView* view = View(KAutoLockViewId);
+              if(view)
+                { 
+                TRect aInitialRect;
+                STATIC_CAST(CAutolockView*, view)->HandleCall(0x1A, aInitialRect);
+                }
 
-		                iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );
-		            }
-		    	break;	
-    	    case EEventWindowGroupListChanged:
-    	        HandleWindowGroupListChange();
-    	        break;
-    	    case EEventPointer:
-    	    case EEventDragDrop:
-    	    		{
-    	    		TInt callState = 0;
-    	    		RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
-	    	        TPointerEvent *pointer = aEvent.Pointer();
-	    	          CAknView* view = View(KAutoLockViewId);
-								  if(view)
-								    {	
-								        STATIC_CAST(CAutolockView*, view)->ScreenDeviceChanged();
-								    	TRect aInitialRect;
-								        STATIC_CAST(CAutolockView*, view)->HandleCall(0x1, aInitialRect);
-   								    	if(aCallButtonRect.iBr.iX==0)	// initialize if not done already
-   								    		aCallButtonRect = TRect (aInitialRect);
-								    }
-			        if ( callState != EPSCTsyCallStateNone && callState != EPSCTsyCallStateUninitialized )
-			        	{
-	    	        if(pointer->iType==TPointerEvent::EButton1Down)
-	    	        	{
-		    	        TPoint iPosition = pointer->iPosition;
-									if(aCallButtonRect.iBr.iX<iPosition.iX && iPosition.iX<aCallButtonRect.iBr.iX+aCallButtonRect.iTl.iX && iPosition.iY>400 )
-	    		        	{
-	    		        	iGotEventDownDuringCall=1;
-	    		        	}
-	    		        }
-	    	        if(pointer->iType==TPointerEvent::EButton1Up)
-	    	        	{
-		    	        TPoint iPosition = pointer->iPosition;
-		    	        // touching at any point inside and below the BigRedButton. This is to handle the case where another dialog overlaps
-						if(iGotEventDownDuringCall==1 && aCallButtonRect.iBr.iX<iPosition.iX && iPosition.iX<aCallButtonRect.iBr.iX+aCallButtonRect.iTl.iX && iPosition.iY>400 )
-	    		        	{
-	    		        		TApaTaskList tasklist( iCoeEnv->WsSession() );
-                      TApaTask phonetask = tasklist.FindApp( KPhoneAppUid );
-	    		        		if ( phonetask.Exists() )
-                        {	// send End key to Telephony to end the call
-										    TRawEvent event;
-										    event.Set(TRawEvent::EKeyDown, EStdKeyNo);
-										    iEikonEnv->WsSession().SimulateRawEvent(event);
-                        					User::After(1000);
-										    event.Set(TRawEvent::EKeyUp, EStdKeyNo);
-										    iEikonEnv->WsSession().SimulateRawEvent(event);
-                        }
-	    		        	}
-	    		        iGotEventDownDuringCall=0;	// even if outside
-	    		        }
-	    		      }
-    		      }
-    	        break;
-    	    case EEventKeyUp:	// on touch devices, this happens only for the switch-key, which should turn on the lights.
-    	    case EEventKey:
-    	    case EEventKeyDown:
-		    		if(iLocked)
-		    				{	// need to capture the switch-key for the case activeCall because Autolock stays on top, even over Akn
-		    	    	TKeyEvent *key = aEvent.Key();
-		    	    	#if defined(_DEBUG)
-		    	    	RDebug::Printf( "%s %s (%u) key->iCode=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, key->iCode );
-		    	    	RDebug::Printf( "%s %s (%u) key->iScanCode=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, key->iScanCode );
-		    	    	#endif
-		    	   		if ( (key->iScanCode == EStdKeyDeviceF) || (key->iCode == EKeyDeviceF) )
-		    	   			{
-		    	   			#if defined(_DEBUG)
-		    	   			RDebug::Printf( "%s %s (%u) good key=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
-		    	   			#endif
-			    				RWsSession& ws = iEikonEnv->WsSession();
-				        	TApaTaskList tasklist( ws );
-				        	TApaTask capserver = tasklist.FindApp( KAknCapServerUid );
-				        	if( capserver.Exists() )
-				        	    {
-		    	   					#if defined(_DEBUG)
-				        	    RDebug::Printf( "%s %s (%u) found KAknCapServerUid=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KAknCapServerUid );
-			        	    	#endif
-				        	    capserver.SendKey( *key );
-				        	    }
-		   	        	SendMessageToSysAp( EEikSecurityQueryLights );
-									}
+                    iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );
+                }
+          break;  
+          case EEventWindowGroupListChanged:
+              HandleWindowGroupListChange();
+              break;
+          case EEventPointer:
+          case EEventDragDrop:
+              {
+              TInt gripStatus = EPSHWRMGripClosed;
+              RProperty::Get( KPSUidHWRM, KHWRMGripStatus, gripStatus );
+							#if defined(_DEBUG)
+							RDebug::Printf( "%s %s (%u) 1 gripStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, gripStatus );
+							RDebug::Printf( "%s %s (%u) EPSHWRMGripClosed=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EPSHWRMGripClosed );
+							#endif
+							if(gripStatus==EPSHWRMGripStatusUninitialized)
+								{
+								gripStatus=EPSHWRMGripClosed;
+								#if defined(_DEBUG)
+								RDebug::Printf( "%s %s (%u) new gripStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, gripStatus );
+								#endif
 								}
-    	    	break;
-		    default:
-		    	iGotEventDownDuringCall=0;	// any other event invalidates the Press inside the BigRedButton
-		    	break;
-    	}
-    	
-    	// All events are sent to base class.
-    	CAknViewAppUi::HandleWsEventL( aEvent, aDestination );
+              TInt callState = 0;
+              RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
+    	    	#if defined(_DEBUG)
+   	    		RDebug::Printf( "%s %s (%u) callState=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, callState );
+			    #endif
+                TPointerEvent *pointer = aEvent.Pointer();
+                  CAknView* view = View(KAutoLockViewId);
+                  if(view)
+                    { 
+                        STATIC_CAST(CAutolockView*, view)->ScreenDeviceChanged();
+                      TRect aInitialRect;
+                        STATIC_CAST(CAutolockView*, view)->HandleCall(0x1, aInitialRect);
+                        if(aCallButtonRect.iBr.iX==0) // initialize if not done already
+                          aCallButtonRect = TRect (aInitialRect);
+                    }
+              if ( callState != EPSCTsyCallStateNone && callState != EPSCTsyCallStateUninitialized )
+                {
+                if(pointer->iType==TPointerEvent::EButton1Down)
+                  {
+                  TPoint iPosition = pointer->iPosition;
+		    	       #if defined(_DEBUG)
+    	    			RDebug::Printf( "%s %s (%u) iPosition.iX=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iPosition.iX );
+    	    			RDebug::Printf( "%s %s (%u) aCallButtonRect.iBr.iX=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aCallButtonRect.iBr.iX );
+    	    			RDebug::Printf( "%s %s (%u) iPosition.iY=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iPosition.iY );
+    	    			RDebug::Printf( "%s %s (%u) aCallButtonRect.iBr.iY=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aCallButtonRect.iBr.iY );
+    	    			#endif
+                  if(aCallButtonRect.iBr.iX<iPosition.iX && iPosition.iX<aCallButtonRect.iBr.iX+aCallButtonRect.iTl.iX &&
+                    ( (gripStatus==EPSHWRMGripClosed && iPosition.iY>400) || (gripStatus!=EPSHWRMGripClosed && aCallButtonRect.iBr.iY<iPosition.iY && iPosition.iY<aCallButtonRect.iBr.iY+aCallButtonRect.iTl.iY ) )
+                     )
+                    {
+	    		        	#if defined(_DEBUG)
+    	    					RDebug::Printf( "%s %s (%u) iGotEventDownDuringCall=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iGotEventDownDuringCall );
+    	    					#endif
+                    iGotEventDownDuringCall=1;
+                    }
+                  }
+                if(pointer->iType==TPointerEvent::EButton1Up)
+                  {
+                  TPoint iPosition = pointer->iPosition;
+                  // touching at any point inside and below the BigRedButton. This is to handle the case where another dialog overlaps
+		    	        #if defined(_DEBUG)
+   	    					RDebug::Printf( "%s %s (%u) iGotEventDownDuringCall=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iGotEventDownDuringCall );
+	    	    			RDebug::Printf( "%s %s (%u) iPosition.iX=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iPosition.iX );
+	    	    			RDebug::Printf( "%s %s (%u) aCallButtonRect.iBr.iX=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aCallButtonRect.iBr.iX );
+	    	    			RDebug::Printf( "%s %s (%u) iPosition.iY=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iPosition.iY );
+	    	    			RDebug::Printf( "%s %s (%u) aCallButtonRect.iBr.iY=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aCallButtonRect.iBr.iY );
+   	    					#endif
+            if(iGotEventDownDuringCall==1 && aCallButtonRect.iBr.iX<iPosition.iX && iPosition.iX<aCallButtonRect.iBr.iX+aCallButtonRect.iTl.iX && 
+                  ( (gripStatus==EPSHWRMGripClosed && iPosition.iY>400) || (gripStatus!=EPSHWRMGripClosed && aCallButtonRect.iBr.iY<iPosition.iY && iPosition.iY<aCallButtonRect.iBr.iY+aCallButtonRect.iTl.iY ) )
+                     )
+                    {
+										// on some devices, simulating End-Key might not end the call. First, try the API
+										RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
+										#if defined(_DEBUG)
+										RDebug::Printf( "%s %s (%u) callState=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, callState );
+										#endif
+										if ( callState != EPSCTsyCallStateNone && callState != EPSCTsyCallStateUninitialized )
+											{
+				                    RTelServer telServer;
+				                    RMobilePhone mPhone;  
+				                    User::LeaveIfError(telServer.Connect());
+				                    TInt err;
+				                    err = telServer.LoadPhoneModule(KMmTsyModuleName);
+				                    if (err != KErrNone && err != KErrAlreadyExists)
+				                        User::Leave(err);
+				                    User::LeaveIfError(mPhone.Open(telServer, KMmTsyPhoneName));
+				                    CleanupClosePushL(mPhone);
+				                    RMobileLine mLine;
+				                    TPtrC lineName;
+				                    lineName.Set(KMmTsyVoice1LineName);
+				                    User::LeaveIfError(mLine.Open(mPhone, lineName));
+				                    CleanupClosePushL(mLine);
+            
+				                    TInt count(0);
+				                    User::LeaveIfError(mLine.EnumerateCall(count));
+								    #if defined(_DEBUG)
+								    RDebug::Printf( "%s %s (%u) count=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, count );
+								    #endif   
+				                    for (TInt jj = 0; jj < count; jj++)
+				                        {
+				                        RLine::TCallInfo cinfo;
+				                        User::LeaveIfError(mLine.GetCallInfo(jj, cinfo));
+				                        RMobileCall mCall;
+				                        User::LeaveIfError(mCall.OpenExistingCall(mLine, cinfo.iCallName));
+									    #if defined(_DEBUG)
+									    RDebug::Printf( "%s %s (%u) calling mCall.HangUp 0=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
+									    #endif   
+				                        mCall.HangUp(); // this gives an error, but succeeds
+				                        }
+				                    CleanupStack::PopAndDestroy(&mLine);
+				                    CleanupStack::PopAndDestroy(&mPhone);
+		    		        			}
+											User::After(100000);	// give time for the call to end
+											#if defined(_DEBUG)
+											RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
+											RDebug::Printf( "%s %s (%u) callState=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, callState );
+											#endif
+											if ( callState != EPSCTsyCallStateNone && callState != EPSCTsyCallStateUninitialized )
+												{
+												// send End key to Telephony to end the call. This works for GSM and VOIP
+											    #if defined(_DEBUG)
+											    RDebug::Printf( "%s %s (%u) sending EStdKeyNo=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EStdKeyNo );
+											    #endif
+												TRawEvent event;
+												event.Set(TRawEvent::EKeyDown, EStdKeyNo);
+												iEikonEnv->WsSession().SimulateRawEvent(event);
+												User::After(1000);
+												event.Set(TRawEvent::EKeyUp, EStdKeyNo);
+												iEikonEnv->WsSession().SimulateRawEvent(event);
+												User::After(100000);	// give time for the call to end
+												}
+                    }
+                  iGotEventDownDuringCall=0;  // even if outside the touch area
+                  aCallButtonRect.iBr.iX = 0;
+                  }
+                }
+              }
+              break;
+          case EEventKeyUp: // on touch devices, this happens only for the switch-key, which should turn on the lights.
+          case EEventKey:
+          case EEventKeyDown:
+            if(iLocked)
+                { // need to capture the switch-key for the case activeCall because Autolock stays on top, even over Akn
+                TKeyEvent *key = aEvent.Key();
+                #if defined(_DEBUG)
+                RDebug::Printf( "%s %s (%u) key->iCode=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, key->iCode );
+                RDebug::Printf( "%s %s (%u) key->iScanCode=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, key->iScanCode );
+                #endif
+                if ( (key->iScanCode == EStdKeyDeviceF) || (key->iCode == EKeyDeviceF) )
+                  {
+                  #if defined(_DEBUG)
+                  RDebug::Printf( "%s %s (%u) good key=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
+                  #endif
+                  RWsSession& ws = iEikonEnv->WsSession();
+                  TApaTaskList tasklist( ws );
+                  TApaTask capserver = tasklist.FindApp( KAknCapServerUid );
+                  if( capserver.Exists() )
+                      {
+                      #if defined(_DEBUG)
+                      RDebug::Printf( "%s %s (%u) found KAknCapServerUid=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KAknCapServerUid );
+                      #endif
+                      capserver.SendKey( *key );
+                      }
+                  SendMessageToSysAp( EEikSecurityQueryLights );
+                  }
+                }
+            break;
+        default:
+          iGotEventDownDuringCall=0;  // any other event invalidates the Press inside the BigRedButton
+          break;
+      }
+      
+      // All events are sent to base class.
+      CAknViewAppUi::HandleWsEventL( aEvent, aDestination );
         
         // part of emergency call handling when telephony+devicelock is active
         // this solution is meant only for 3.1 and 3.2
         // Emergency detector only handles key down events
         if ( iEmergencySupportReady )
-        	iEcsDetector->HandleWsEventL( aEvent, aDestination);    	
-	#if defined(_DEBUG)
+          iEcsDetector->HandleWsEventL( aEvent, aDestination);      
+  #if defined(_DEBUG)
     RDebug::Printf( "%s %s (%u) 0=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
     #endif
     }
@@ -1390,9 +1599,30 @@
     return iLocked;
     }
 
+void CAutolockAppUi::ForceOrientation(TInt value)
+    {
+    #if defined(_DEBUG)
+    RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, value );
+    #endif
+		if(value==1)
+			{
+			SetOrientationL( EAppUiOrientationLandscape );
+			SetOrientationL( EAppUiOrientationPortrait );
+			}
+		if(value==0)
+			{
+			SetOrientationL( EAppUiOrientationPortrait );
+			SetOrientationL( EAppUiOrientationLandscape );
+			}
+    aCallButtonRect.iBr.iX = 0;
+    #if defined(_DEBUG)
+    RDebug::Printf( "%s %s (%u) done value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, value );
+    #endif
+    }
+
 void CAutolockAppUi::CancelDeviceLockQuery()
     {
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Printf( "%s %s (%u) 0=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
     #endif
     TRawEvent rawEvent;
@@ -1404,15 +1634,15 @@
 
 TBool CAutolockAppUi::DeviceFpsLock(TInt iStatus)
     {
-		if(iStatus)
-			HandleCommandL(ESecUiCmdUnlock);
-		else
-			iModel->SetLockedL(ETimerLocked);
+    if(iStatus)
+      HandleCommandL(ESecUiCmdUnlock);
+    else
+      iModel->SetLockedL(ETimerLocked);
     return ETrue;
     }
 void CAutolockAppUi::HandleWindowGroupListChange()
     {
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Printf( "%s %s (%u) iLocked=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLocked );
     #endif
     if ( !iLocked )
@@ -1427,14 +1657,14 @@
         }
     else
         {
-		            CAknView* view = View(KAutoLockViewId);
-								  if(view)
-								    {	
-								    	TRect aInitialRect;
-								        STATIC_CAST(CAutolockView*, view)->HandleCall(0x10, aInitialRect);
-												if(aCallButtonRect.iBr.iX==0)	// initialize if not done already
-   								    		aCallButtonRect = TRect (aInitialRect);
-								    }
+                CAknView* view = View(KAutoLockViewId);
+                  if(view)
+                    { 
+                      TRect aInitialRect;
+                        STATIC_CAST(CAutolockView*, view)->HandleCall(0x10, aInitialRect);
+                        if(aCallButtonRect.iBr.iX==0) // initialize if not done already
+                          aCallButtonRect = TRect (aInitialRect);
+                    }
         // So now system is locked. When call is not ongoing, autolock should
         // be on the foreground.
         TInt callState = 0;
@@ -1461,7 +1691,7 @@
 {
     // Get the TARM admin flag value
     TInt tarmFlag;
-	TInt tRet = RProperty::Get( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
+  TInt tRet = RProperty::Get( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
     
     if ( tRet != KErrNone )
         {
@@ -1498,7 +1728,7 @@
         }  
 
 }
-	#if defined(_DEBUG)
+  #if defined(_DEBUG)
     RDebug::Printf( "%s %s (%u) ret=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, ret );
     #endif
 return ret;
@@ -1510,41 +1740,41 @@
 TBool CAutolockAppUi::HiddenReset()
     {
     #if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HiddenReset() begin"));
-	#endif	    				    			
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HiddenReset() begin"));
+  #endif                        
 
     TBool ret_val ( EFalse );
-	TInt startupReason(ENormalStartup);
-	TInt errorCode(KErrNone);
-	
-	RProperty::Get(KPSUidStartup, KPSStartupReason, startupReason);
-	
-	if ( errorCode != KErrNone )
-		{
-		    #if defined(_DEBUG)
-	        RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HiddenReset() error getting startup reason"));
-	        #endif
-	    }
+  TInt startupReason(ENormalStartup);
+  TInt errorCode(KErrNone);
+  
+  RProperty::Get(KPSUidStartup, KPSStartupReason, startupReason);
+  
+  if ( errorCode != KErrNone )
+    {
+        #if defined(_DEBUG)
+          RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HiddenReset() error getting startup reason"));
+          #endif
+      }
     ret_val = (startupReason != ENormalStartup);
     #if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HiddenReset() END: %d"), ret_val);
-	#endif
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HiddenReset() END: %d"), ret_val);
+  #endif
     return ret_val;
     }
 void CAutolockAppUi::EnableWGListChangeEventListening()
 {
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::EnableWGListChangeEventListening()"));
-	#endif
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::EnableWGListChangeEventListening()"));
+  #endif
     RWindowGroup& rootWin = iCoeEnv->RootWin();
     rootWin.EnableGroupListChangeEvents();
     rootWin.EnableScreenChangeEvents();
 }
 void CAutolockAppUi::DisableWGListChangeEventListening()
 {
-	#if defined(_DEBUG)
-	RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::DisableWGListChangeEventListening()"));
-	#endif
+  #if defined(_DEBUG)
+  RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::DisableWGListChangeEventListening()"));
+  #endif
     RWindowGroup& rootWin = iCoeEnv->RootWin();
     rootWin.DisableGroupListChangeEvents();
     rootWin.DisableScreenChangeEvents();
--- a/securitydialogs/Autolock/src/AutolockContainer.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/src/AutolockContainer.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -276,6 +276,13 @@
     TInt y = Rect().Height()/2 - iBitmap->SizeInPixels().iHeight/2;
 		TInt width =iBitmap->SizeInPixels().iWidth;
 		TInt height =iBitmap->SizeInPixels().iHeight;
+		
+		TInt gripStatus = EPSHWRMGripClosed;
+		RProperty::Get( KPSUidHWRM, KHWRMGripStatus, gripStatus );
+		#if defined(_DEBUG)
+		RDebug::Printf( "%s %s (%u) gripStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, gripStatus );
+		#endif
+		
       TInt callState = 0;
   	  RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
     if ( callState == EPSCTsyCallStateNone || callState == EPSCTsyCallStateUninitialized )
@@ -283,7 +290,8 @@
     	}
     else
     	{
-    	y-=100;
+			if (gripStatus != EPSHWRMGripOpen)
+    		y-=100;
     	}
     
     if (iBitmap && iMask)
@@ -295,8 +303,16 @@
     	  }
     	  else
     	  	{
-   	    	aCallRect_x=Rect().Width()/2 - iBitmapCall->SizeInPixels().iWidth/2;
-		    	aCallRect_y=Rect().Height() * 0.75;
+		    	if (gripStatus != EPSHWRMGripOpen)
+		    		{
+	   	    	aCallRect_x=Rect().Width()/2 - iBitmapCall->SizeInPixels().iWidth/2;
+		    		aCallRect_y=Rect().Height() * 0.75;
+		    		}
+		    	else
+		    		{
+		    		aCallRect_x=Rect().Width()* 0.75 - iBitmapCall->SizeInPixels().iWidth/2;
+		    		aCallRect_y = Rect().Height()/2-3*10;
+		    		}
 		    	aCallRect_width=iBitmapCall->SizeInPixels().iWidth;
 		    	aCallRect_height=iBitmapCall->SizeInPixels().iHeight;
     	  	TSize cornerSize(20,20); 
@@ -308,7 +324,8 @@
 					gc.SetPenStyle(CGraphicsContext::EDottedPen);
 					gc.DrawRoundRect(box,cornerSize);
         	gc.BitBltMasked(TPoint(aCallRect_x,aCallRect_y),iBitmapCall,TRect(TPoint(0,0),TPoint(aCallRect_width,aCallRect_height)), iMaskCall, ETrue);
-    	  	aCallRect_y+=100;	// coordinates are relative to TRect, not to Screen
+    	  	if (gripStatus != EPSHWRMGripOpen)
+    	  		aCallRect_y+=100;	// coordinates are relative to TRect, not to Screen
     	  	
     	  	// if active call, dismiss all pending notes. This avoids them on top of the BigRedButton
     	  	CAknSoftNotifier *softNotifier = NULL;
--- a/securitydialogs/Autolock/src/AutolockGripStatusObserver.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Autolock/src/AutolockGripStatusObserver.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -99,6 +99,7 @@
         #if defined(_DEBUG)
     	RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => Grip opened"));
     	#endif 
+   		iObserver->ForceOrientation(0);
     	if( !iObserver->DeviceLockQueryStatus() && iObserver->DeviceLockStatus() )
     		{
             #if defined(_DEBUG)
@@ -139,6 +140,8 @@
         #if defined(_DEBUG)
     	RDebug::Print(_L("(AUTOLOCK)CAutolockGripStatusObserver::::GripStatusChangedL => Grip closed"));
     	#endif 
+   		iObserver->ForceOrientation(1);
+
         //Grip closed
         if( iObserver->DeviceLockQueryStatus() )
         	{
--- a/securitydialogs/SecUi/Src/SecUiSecurityHandler.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/SecUi/Src/SecUiSecurityHandler.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -777,6 +777,24 @@
 		    if (StartUp)
 		    isConditionSatisfied = ETrue;  
 		}
+
+	// call TARM so that it verifies that configuration is in sync. This might internally accept the (default) lock code, but doesn't dismiss the query.
+	#if defined(_DEBUG)
+	RDebug::Printf( "%s %s (%u) pre isConditionSatisfied=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, isConditionSatisfied );
+  #endif
+	RSCPClient scpClientConfiguration;
+	User::LeaveIfError( scpClientConfiguration.Connect() );
+  CleanupClosePushL( scpClientConfiguration );
+	#if defined(_DEBUG)
+	RDebug::Printf( "%s %s (%u) calling CheckConfiguration KSCPComplete=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, KSCPComplete );
+  #endif
+	TInt finalConfStatus = scpClientConfiguration.CheckConfiguration( KSCPComplete );
+	#if defined(_DEBUG)
+	RDebug::Printf( "%s %s (%u) finalConfStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, finalConfStatus );
+	RDebug::Printf( "%s %s (%u) isConditionSatisfied=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, isConditionSatisfied );
+  #endif
+	CleanupStack::PopAndDestroy();	// scpClientConfiguration
+
 		if (isConditionSatisfied)
         {
         #if defined(_DEBUG)
--- a/securitydialogs/Securitynotifier/Src/SecurityNotifier.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/Securitynotifier/Src/SecurityNotifier.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -225,13 +225,33 @@
 //
 void CSecurityNotifier::GetParamsL(const TDesC8& aBuffer, TInt aReturnVal, const RMessagePtr2& aMessage)
     {
+	/*****************************************************
+	*	Series 60 Customer / ETel
+	*	Series 60  ETel API
+	*****************************************************/
+    iMessage = aMessage;
+    iReturnVal = aReturnVal;
+    TBool skipQuery = EFalse; // In some cases the query is handled by some other entity and SecurityNotifier should skip it.
+
+	#if defined(_DEBUG)
+    RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::GetParamsL() Start BEGIN"));
+    #endif
+    
+
+    TSecurityNotificationPckg pckg;
+    pckg.Copy( aBuffer );
+    iStartup = pckg().iStartup;
+    iEvent = static_cast<RMobilePhone::TMobilePhoneSecurityEvent>(pckg().iEvent);
+    
 	#if defined(_DEBUG)
 	RDebug::Printf( "%s %s (%u) searching for autolock.exe =%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0x0 );
+	RDebug::Printf( "%s %s (%u) iEvent=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iEvent );
+	RDebug::Printf( "%s %s (%u) 2 RMobilePhone::EPin1Required=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, RMobilePhone::EPin1Required );
 	#endif
 	TApaTaskList taskList( CCoeEnv::Static()->WsSession() );
 	const TUid KAutolockUid = { 0x100059B5 };
 	TApaTask task( taskList.FindApp( KAutolockUid ) );
-	if ( !task.Exists() )
+	if ( !task.Exists() && iEvent != RMobilePhone::EPin1Required )	// PIN-request should not start autolock, to prevent that lock-code is secretly accepted by TARM. Rely on Startup.
 		{
 		#if defined(_DEBUG)
 		RDebug::Printf( "%s %s (%u) autolock.exe not running. Starting now=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0x1 );
@@ -252,24 +272,6 @@
 		
 		CleanupStack::PopAndDestroy(2); // commandLine, ls
 		}
-	/*****************************************************
-	*	Series 60 Customer / ETel
-	*	Series 60  ETel API
-	*****************************************************/
-    iMessage = aMessage;
-    iReturnVal = aReturnVal;
-    TBool skipQuery = EFalse; // In some cases the query is handled by some other entity and SecurityNotifier should skip it.
-
-	#if defined(_DEBUG)
-    RDebug::Print(_L("(SECURITYNOTIFIER)CSecurityNotifier::GetParamsL() Start BEGIN"));
-    #endif
-    
-
-    TSecurityNotificationPckg pckg;
-    pckg.Copy( aBuffer );
-    iStartup = pckg().iStartup;
-    iEvent = static_cast<RMobilePhone::TMobilePhoneSecurityEvent>(pckg().iEvent);
-    
 
 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))
 		{
--- a/securitydialogs/simlockui/inc/SimLockUIBackgroundControl.h	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/simlockui/inc/SimLockUIBackgroundControl.h	Thu Aug 19 10:45:23 2010 +0300
@@ -50,19 +50,17 @@
      * NewL
      * Create a CSimLockUIBackgroundControl object, which will draw itself to aRect
      *
-     * @param aRect the rectangle this view will be drawn to
      * @return a pointer to the created instance of CSimLockUIBackgroundControl
      */
-    static CSimLockUIBackgroundControl* NewL( const TRect& aRect );
+    static CSimLockUIBackgroundControl* NewL();
 
     /**
      * NewLC
      * Create a CSimLockUIBackgroundControl object, which will draw itself to aRect
      *
-     * @param aRect the rectangle this view will be drawn to
      * @return a pointer to the created instance of CSimLockUIBackgroundControl
      */
-    static CSimLockUIBackgroundControl* NewLC( const TRect& aRect );
+    static CSimLockUIBackgroundControl* NewLC();
 
 
     /**
@@ -86,10 +84,8 @@
     /**
      * ConstructL
      * Perform the second phase construction of a CSimLockUIBackgroundControl object
-     *
-     * @param aRect the rectangle this view will be drawn to
      */
-    void ConstructL( const TRect& aRect );
+    void ConstructL();
 
 private: // From CCoeControl
 
@@ -100,6 +96,11 @@
     virtual void SizeChanged();
 
     /**
+     * HandleResourceChange
+     */
+    void HandleResourceChange( TInt aType );
+
+    /**
      * Draw
      * Draw this CSimLockUIBackgroundControl to the screen
      *
--- a/securitydialogs/simlockui/src/SimLockUIAppui.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/simlockui/src/SimLockUIAppui.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -30,6 +30,8 @@
 #include <aknmessagequerydialog.h> // CAknMessageQueryDialog
 #include <e32base.h>
 #include <e32property.h> //Rproperty
+#include <rmmcustomapi.h>       // TSimLockPassword
+
 // Local Includes
 #include "simlockisaserverdefinitions.h"
 #include "simlockui.pan"
@@ -128,7 +130,8 @@
     {
     TBool keepLooping = ETrue;
 
-    TBuf<SEC_ATT_PASSWORD_MAX_BUFFER> password;
+    RMmCustomAPI::TSimLockPassword password;
+
 
     // Loop until flag is set
     do
@@ -165,15 +168,7 @@
 // ---------------------------------------------------------------------------
 void CSimLockUIAppUi::CreateBackgroundControlL()
     {
-    CEikStatusPane* statusPane = StatusPane();
-
-    // Remove status pane
-    // Crop background pane to reveal idle status pane
-    TRect background = ClientRect();
-    statusPane->ReduceRect(background);
-    statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
-
-    iBackgroundControl = CSimLockUIBackgroundControl::NewL(background);
+    iBackgroundControl = CSimLockUIBackgroundControl::NewL();
     AddToStackL(iBackgroundControl);
     }
 
@@ -201,7 +196,7 @@
 // ---------------------------------------------------------------------------
 TBool CSimLockUIAppUi::PromptForPasswordL(TDes& aPassword)
     {
-    TBuf<SEC_ATT_PASSWORD_MAX_BUFFER> newPassword;
+    RMmCustomAPI::TSimLockPassword newPassword;
 
     // Prompt for password twice.  Loop until passwords match.
     do
@@ -210,8 +205,6 @@
 
         // Ask for password
         CAknTextQueryDialog* dialog = CAknTextQueryDialog::NewL(aPassword);
-       // dialog->SetMaxLength(SEC_ATT_PASSWORD_MAX_LENGTH);
-
         if (!dialog->ExecuteLD(R_SIM_INFO_ENTER_PASSWORD))
             {
             return EFalse;
@@ -329,7 +322,8 @@
 // ---------------------------------------------------------------------------
 TBool CSimLockUIAppUi::HandleUnlockFailedL()
     {
-    TBuf<SEC_ATT_PASSWORD_MAX_BUFFER> password;
+    RMmCustomAPI::TSimLockPassword password;
+
     // Otherwise, prompt user to try again
     SetBackgroundTextL(EBackgroundTextEmpty);
 
--- a/securitydialogs/simlockui/src/SimLockUIBackgroundControl.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/securitydialogs/simlockui/src/SimLockUIBackgroundControl.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -41,9 +41,9 @@
 // ---------------------------------------------------------------------------
 // CSimLockUIBackgroundControl::NewL
 // ---------------------------------------------------------------------------
-CSimLockUIBackgroundControl* CSimLockUIBackgroundControl::NewL( const TRect& aRect )
+CSimLockUIBackgroundControl* CSimLockUIBackgroundControl::NewL()
     {
-    CSimLockUIBackgroundControl* self = CSimLockUIBackgroundControl::NewLC( aRect );
+    CSimLockUIBackgroundControl* self = CSimLockUIBackgroundControl::NewLC();
     CleanupStack::Pop( self );
     return self;
     }
@@ -51,11 +51,11 @@
 // ---------------------------------------------------------------------------
 // CSimLockUIBackgroundControl::NewLC
 // ---------------------------------------------------------------------------
-CSimLockUIBackgroundControl* CSimLockUIBackgroundControl::NewLC( const TRect& aRect )
+CSimLockUIBackgroundControl* CSimLockUIBackgroundControl::NewLC()
     {
     CSimLockUIBackgroundControl* self = new ( ELeave ) CSimLockUIBackgroundControl;
     CleanupStack::PushL( self );
-    self->ConstructL( aRect );
+    self->ConstructL();
     return self;
     }
 
@@ -83,16 +83,14 @@
 // ---------------------------------------------------------------------------
 // CSimLockUIBackgroundControl::ConstructL
 // ---------------------------------------------------------------------------
-void CSimLockUIBackgroundControl::ConstructL( const TRect& aRect )
+void CSimLockUIBackgroundControl::ConstructL()
     {
     // Create a window for this application view
     CreateWindowL();
+    SetExtentToWholeScreen();
 
     iBackgroundSkinContext = CAknsBasicBackgroundControlContext::NewL(
-            KAknsIIDQsnBgAreaMain, aRect, EFalse );
-
-    // Set the windows size
-    SetRect( aRect );
+            KAknsIIDQsnBgAreaMain, Rect(), EFalse );
 
     // Activate the window, which makes it ready to be drawn
     ActivateL();
@@ -104,7 +102,22 @@
 void CSimLockUIBackgroundControl::SizeChanged()
     {
     // Background skin.
-    iBackgroundSkinContext->SetRect( Rect() );
+    if ( iBackgroundSkinContext )
+        iBackgroundSkinContext->SetRect( Rect() );
+    }
+
+// ---------------------------------------------------------------------------
+// CSimLockUIBackgroundControl::HandleResourceChange()
+// ---------------------------------------------------------------------------
+//
+void CSimLockUIBackgroundControl::HandleResourceChange( TInt aType )
+    {
+    CCoeControl::HandleResourceChange( aType );
+
+    if ( aType == KEikDynamicLayoutVariantSwitch )
+        {
+        SetExtentToWholeScreen();
+        }
     }
 
 
--- a/wim/Scard/inc/ScardConnector.h	Thu Jul 15 19:36:50 2010 +0300
+++ b/wim/Scard/inc/ScardConnector.h	Thu Aug 19 10:45:23 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -97,13 +97,11 @@
         /**
         * Two-phased constructor.
         * @param aConnRegistry Pointer to connection registry
-        * @param aClient Client thread
         * @param aMessage Client message
-        */ 
+        */
         static CScardConnector* NewL( CScardConnectionRegistry* aConnRegistry,
-                                      RThread& aClient, 
-                                      const RMessage2& aMessage );
-        
+            const RMessage2& aMessage );
+
         /**
         * Destructor.
         */
@@ -165,10 +163,8 @@
         /**
         * C++ default constructor.
         * @param aConnRegistry Pointer to connection registry
-        * @param aClient Client thread
         */
-        CScardConnector( CScardConnectionRegistry* aConnRegistry, 
-                         RThread& aClient );
+        CScardConnector( CScardConnectionRegistry* aConnRegistry );
 
         /**
         * By default Symbian 2nd phase constructor is private.
--- a/wim/Scard/src/ScardConnectionRegistry.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/wim/Scard/src/ScardConnectionRegistry.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -105,16 +105,8 @@
     TConnectionHandle handle;
     handle.iClient = aClient;
     CScardConnector* conn = NULL;
-    RThread thread;
-    
-    TInt err1 = thread.Open( KScardServerName );
-    
-    if ( err1 != KErrNone )
-        {
-        _WIMTRACE(_L("WIM|Scard|CScardConnectionRegistry::ConnectToReaderL|Thread open failed"));
-        }
 
-    TRAPD( err, conn = CScardConnector::NewL( this, thread, aMessage ) );
+    TRAPD( err, conn = CScardConnector::NewL( this, aMessage ) );
     if ( err )
         {
 #ifdef _DEBUG
--- a/wim/Scard/src/ScardConnector.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/wim/Scard/src/ScardConnector.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -89,17 +89,12 @@
 // might leave.
 // -----------------------------------------------------------------------------
 //
-CScardConnector::CScardConnector(
-    CScardConnectionRegistry* aConnRegistry, 
-    RThread& /*aClient*/ )
-    : CScardSession(),
-      iConnectionRegistry( aConnRegistry ),
-      iState( EActive )
+CScardConnector::CScardConnector( CScardConnectionRegistry* aConnRegistry ) :
+        CScardSession(), iConnectionRegistry( aConnRegistry ), iState( EActive )
     {
     _WIMTRACE(_L("WIM|Scard|CScardConnector::CScardConnector|Begin"));
     }
 
-
 // -----------------------------------------------------------------------------
 // CScardConnector::ConstructL
 // Symbian 2nd phase constructor can leave.
@@ -120,14 +115,12 @@
 // -----------------------------------------------------------------------------
 //
 CScardConnector* CScardConnector::NewL(
-    CScardConnectionRegistry* aConnRegistry, 
-    RThread& aClient, 
+    CScardConnectionRegistry* aConnRegistry,
     const RMessage2& aMessage )
     {
     _WIMTRACE(_L("WIM|Scard|CScardConnector::NewL|Begin"));
-    CScardConnector* self = new( ELeave ) CScardConnector( aConnRegistry, 
-        aClient );
-    
+    CScardConnector* self = new( ELeave ) CScardConnector( aConnRegistry );
+
     CleanupStack::PushL( self );
     self->ConstructL( aMessage );
     CleanupStack::Pop( self );
--- a/wim/WimPlugin/src/WimCertStore.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/wim/WimPlugin/src/WimCertStore.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -1575,6 +1575,8 @@
             // and assigned into mapping
             SetTrustSettingsOnMappingL( iTrusted,
                                         iCertificateApps );
+            _WIMTRACE3 ( _L( "CWimCertStore::DoInitializeLoadTrustSettingsWaitL(), index=%d, count=%d" ),
+                    iCertIndex, iCerts->Count() );
             if ( iCertIndex < iCerts->Count() - 1 )
                 {
                 iCertIndex++;
--- a/wim/WimServer/src/WimServer.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/wim/WimServer/src/WimServer.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -486,7 +486,6 @@
 
         case ESetApplicability:         //lint -fallthrough
         case ESetTrust:                 //lint -fallthrough
-        case ESetDefaultTrustSettings:  //lint -fallthrough
         case ERemoveTrustSettings:
             {
             if ( ResolveTrustModficationReqL( aMsg, usage ))
@@ -496,6 +495,16 @@
             break;
             }
 
+        case ESetDefaultTrustSettings:
+            {
+            _WIMTRACE( _L("CWimServer::CustomSecurityCheckL, ESetDefaultTrustSettings exception") );
+            if ( ResolveTrustModficationReqL( aMsg, usage ))
+                {
+                test = CheckReadCapsForUsage( aMsg, usage );
+                }
+            }
+            break;
+            
         case EExportPublicKey:
             {
             ResolveExportPublicReqL( aMsg, usage );
--- a/wim/WimServer/src/WimTrustSettingsStore.cpp	Thu Jul 15 19:36:50 2010 +0300
+++ b/wim/WimServer/src/WimTrustSettingsStore.cpp	Thu Aug 19 10:45:23 2010 +0300
@@ -384,6 +384,7 @@
             CleanupStack::PopAndDestroy( &applications );
             }
     );
+    _WIMTRACE2 ( _L( "CWimTrustSettingsStore::DoSetDefaultTrustSettingsL(), err=%d" ), err );
 
     if ( err != KErrNone ) // Some error occured
         {
@@ -418,7 +419,8 @@
         RemoveApplicationsL( certID );  // Remove applications
         RemoveCertificateL( certID );   // Remove certificate
     );
-
+    _WIMTRACE2 ( _L( "CWimTrustSettingsStore::DoRemoveTrustSettingsL(), err=%d" ), err );
+    
     if ( err ) // Some error occurred
         {
         iDatabase.Rollback(); // Rollback changes