securitydialogs/Autolock/src/AutolockAppUi.cpp
changeset 17 8957df7b0072
parent 14 b75757c81051
equal deleted inserted replaced
15:318c4eab2439 17:8957df7b0072
    69 // ?implementation_description
    69 // ?implementation_description
    70 // ----------------------------------------------------------
    70 // ----------------------------------------------------------
    71 //
    71 //
    72 void CAutolockAppUi::ConstructL()
    72 void CAutolockAppUi::ConstructL()
    73     {
    73     {
       
    74     	RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
    75     		
    74 	#if defined(_DEBUG)
    76 	#if defined(_DEBUG)
    75     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL"));
    77     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL"));
    76     #endif
    78     #endif
    77     
    79     
       
    80    	RDebug::Printf( "%s %s (%u) EAutolockOff=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EAutolockOff );
       
    81     RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
       
    82 
    78     BaseConstructL( EAknEnableSkin | EAknEnableMSK );
    83     BaseConstructL( EAknEnableSkin | EAknEnableMSK );
    79     
    84     
    80     //Disable priority control so that Autolock process priority isn't set to "background" by 
       
    81 	//window server when it is not active.
       
    82 	iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled ); 
       
    83 	RThread().SetProcessPriority( EPriorityHigh );
       
    84 
       
    85     FeatureManager::InitializeLibL();
       
    86 
       
    87 	RTelServer::TPhoneInfo PhoneInfo;
       
    88 	// prevent autolock shutdown
       
    89 	iEikonEnv->SetSystem( ETrue ); 
       
    90 
       
    91 	iSideKey1 = 0;
       
    92 	iSideKey2 = 0;
       
    93 	iAppKey = 0;
       
    94 
       
    95 	aCallButtonRect = TRect (0,0,0,0);
       
    96 	//connect to ETel
       
    97 
       
    98 	TInt err( KErrGeneral );
       
    99     TInt thisTry( 0 );
       
   100     
       
   101 	/*All server connections are tried to be made KTiesToConnectServer times because occasional
       
   102     fails on connections are possible at least on some servers*/
       
   103 	#if defined(_DEBUG)
       
   104     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() connect to etel server"));
       
   105     #endif
       
   106 	// connect etel server
       
   107 	while ( ( err = iServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
   108         {
       
   109         User::After( KTimeBeforeRetryingServerConnection );
       
   110         }
       
   111     User::LeaveIfError( err );
       
   112 
       
   113 	#if defined(_DEBUG)
       
   114     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() load tsy"));
       
   115     #endif
       
   116     // load tsy
       
   117     err = iServer.LoadPhoneModule( KMmTsyModuleName );
       
   118 	#if defined(_DEBUG)
       
   119     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() load tsy ERROR: %d"), err);
       
   120     #endif
       
   121     if ( err != KErrAlreadyExists )
       
   122         {
       
   123         // may return also KErrAlreadyExists if some other
       
   124         // is already loaded the tsy module. And that is
       
   125         // not an error.
       
   126         User::LeaveIfError( err );
       
   127         }
       
   128 	
       
   129 	thisTry = 0;
       
   130 	#if defined(_DEBUG)
       
   131     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() open phone"));
       
   132     #endif
       
   133 	//open phone
       
   134 	User::LeaveIfError(iServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended));
       
   135 	User::LeaveIfError(iServer.GetPhoneInfo(PhoneIndex, PhoneInfo));
       
   136 	User::LeaveIfError(iPhone.Open(iServer,PhoneInfo.iName));
       
   137     User::LeaveIfError(iCustomPhone.Open(iPhone));
       
   138  	#if defined(_DEBUG)
       
   139     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() phone opened"));
       
   140     #endif
       
   141 
       
   142     TBool systemLocked = EFalse;
       
   143 	TBool autolockValue = EAutolockStatusUninitialized;
       
   144 
       
   145     iWait = NULL;
       
   146     iWait = CWait::NewL();
       
   147 
       
   148 	#ifndef __WINS__
       
   149 
       
   150 
       
   151 	/*****************************************************
       
   152 	*	Series 60 Customer / ETEL
       
   153 	*	Series 60 ETEL API
       
   154 	*****************************************************/
       
   155 
       
   156 	// set autolock period to 0, if lock is disabled in DOS side
       
   157 	#if defined(_DEBUG)
       
   158     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() set autolock period to 0"));
       
   159     #endif
       
   160 	RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
       
   161 	RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
   162 	RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
   163     
       
   164 	iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
   165 	iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
   166 	TInt res = iWait->WaitForRequestL();
       
   167 	User::LeaveIfError(res);
       
   168     TInt lockValue = 0;
       
   169     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings);
       
   170     TInt cRresult = repository->Get(KSettingsAutolockStatus, lockValue);
       
   171     TBool hiddenReset = HiddenReset();
       
   172     #if defined(_DEBUG)
       
   173     if(hiddenReset)
       
   174         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() Hidden reset"));
       
   175     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() CR get result: %d"), cRresult);
       
   176     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() CR lock value: %d"), lockValue);
       
   177     #endif
       
   178 	if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
       
   179 		{
       
   180         repository->Set(KSettingsAutoLockTime, 0);
       
   181         if ( FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) )
       
   182             {
       
   183             repository->Set(KSettingsLockOnPowerUp, 0);
       
   184             }
       
   185         }
       
   186     // In CDMA, the system can stay locked on after the boot-up sequence.
       
   187     else if ( FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) || (hiddenReset && (lockValue == 1)))
       
   188         {
       
   189         #if defined(_DEBUG)
       
   190         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() Hidden reset when locked"));
       
   191         #endif
       
   192         systemLocked = ETrue;
       
   193         }
       
   194 
       
   195         
       
   196  		if ( lockInfo.iSetting == RMobilePhone::ELockSetEnabled && lockValue != EAutolockOff && !hiddenReset)
       
   197 		{
       
   198 		    #if defined(_DEBUG)
       
   199         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() EAutolockStatusUninitialized %d"),EAutolockStatusUninitialized);
       
   200         #endif
       
   201         autolockValue = EAutolockStatusUninitialized;					            
       
   202     }
       
   203     else if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled || (hiddenReset && (lockValue == 0)) )
       
   204 		{
       
   205 		    #if defined(_DEBUG)
       
   206         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() EAutolockOff %d"),EAutolockOff);
       
   207         #endif
       
   208         autolockValue = EAutolockOff;
       
   209     }
       
   210      
       
   211     delete repository;
       
   212 	#endif   //__WINS__
       
   213 
       
   214 	#if defined(_DEBUG)
       
   215     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() Enable emergency call support"));
       
   216     #endif
       
   217 	
       
   218 	#if defined(_DEBUG)
       
   219     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() Autolock view"));
       
   220     #endif
       
   221     
       
   222 
       
   223 
       
   224     // -------------------------------------------------------------------------------------------------------------
       
   225     // part of emergency call handling when telephony+devicelock is active
       
   226     // this solution is meant only for 3.1 and 3.2
       
   227 
       
   228     iEcsNote = new (ELeave) CEcsNote();
       
   229     iEcsNote->ConstructSleepingNoteL(R_AVKON_EMERGENCY_CALL_NOTE);
       
   230     iEcsNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(0,2);
       
   231     
       
   232     if (AknLayoutUtils::PenEnabled())	// on touch devices, if Autolock is activated from IdleScreen in landscape, the buttons need to be drawn.
       
   233 	{
       
   234 	iEcsNote->ButtonGroupContainer().SetCommandL( 0, _L("") );	// as keyboard is locked, these buttons do nothing. Better to hide their labels.
       
   235   	iEcsNote->ButtonGroupContainer().SetCommandL( EAknSoftkeyCancel, _L("") );
       
   236 	iEcsNote->ButtonGroupContainer().ButtonGroup()->AsControl()->MakeVisible(ETrue);
       
   237   	}
       
   238 
       
   239 	// Emergency call support
       
   240     iEcsDetector = CAknEcsDetector::NewL();
       
   241     iEcsDetector->SetObserver( this );
       
   242 	iEmergencySupportReady = ETrue;
       
   243     // -------------------------------------------------------------------------------------------------------------
       
   244         
       
   245 
       
   246 	// Autolock view	
       
   247 	CAutolockView* lockView = new(ELeave) CAutolockView;
       
   248     CleanupStack::PushL(lockView);
       
   249     lockView->ConstructL();
       
   250     CleanupStack::Pop();	// lockView
       
   251     AddViewL(lockView);    // transfer ownership to CAknViewAppUi
       
   252 	SetDefaultViewL(*lockView);
       
   253 
       
   254 	// start autolock timer
       
   255 	iModel = CAutoLockModel::NewL(this, autolockValue);	
       
   256 
       
   257 	// phone event observer
       
   258 	iPhoneObserver = CValueObserver::NewL(this);
       
   259 	//call bubble
       
   260 	iIncallBubble = CAknIncallBubble::NewL();
       
   261 
       
   262 	//Autokeyguard Period observer
       
   263 	#ifdef RD_AUTO_KEYGUARD
       
   264 	iKeyguardObserver = CAutoKeyguardObserver::NewL();
       
   265 	#else //!RD_AUTO_KEYGUARD
       
   266 	iKeyguardObserver = NULL;
       
   267 	#endif //RD_AUTO_KEYGUARD
       
   268     // Create the write policy. Also processes with write device data can write the value.
       
   269     TSecurityPolicy writePolicy( ECapabilityWriteDeviceData ); 
       
   270 	// Create the read policy. Also processes with read device data can read the value.	
       
   271 	TSecurityPolicy readPolicy( ECapabilityReadDeviceData ); 
       
   272 	
       
   273 	TInt tRet = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, RProperty::EInt, readPolicy, writePolicy );
       
   274         
       
   275     if ( tRet != KErrNone )
       
   276         {
       
   277         #if defined(_DEBUG)
       
   278         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
       
   279             FAILED to define the SECUI query Flag: %d"), tRet);
       
   280         #endif
       
   281         }	
       
   282     
       
   283     tRet = RProperty::Define( KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, RProperty::EInt, readPolicy, writePolicy );
       
   284     if ( tRet != KErrNone )
       
   285         {
       
   286         #if defined(_DEBUG)
       
   287         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
       
   288             FAILED to define the SECUI query request state Flag: %d"), tRet);
       
   289         #endif
       
   290         }
       
   291 
       
   292 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))  
       
   293 {
       
   294 
       
   295     // Define the TARM admin flag.
       
   296     
       
   297     tRet = RProperty::Define( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, RProperty::EInt,
       
   298         readPolicy, writePolicy );    
       
   299     if ( tRet != KErrNone )
       
   300         {
       
   301         #if defined(_DEBUG)
       
   302         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
       
   303             FAILED to define the TARM Admin Flag"));
       
   304         #endif
       
   305         }
       
   306         
       
   307     // The following sequence is used to validate the configuration on SCP server.
       
   308     // This is needed on the first boot (initial or RFS) or if the C-drive has been formatted
       
   309     // (3-button format) and Autolock is not active.
       
   310 
       
   311     RSCPClient scpClient;
       
   312     if ( scpClient.Connect() == KErrNone )
       
   313         {
       
   314         TInt confStatus = scpClient.CheckConfiguration( KSCPInitial );
       
   315         
       
   316         if ( confStatus == KErrAccessDenied )
       
   317             {
       
   318             #ifndef __WINS__            
       
   319             if ( ( lockInfo.iSetting == RMobilePhone::ELockSetDisabled ) )    
       
   320             #else // __WINS__                    
       
   321             if ( 1 ) // DOS lock is never active in WINS            
       
   322             #endif // __WINS__     
       
   323 		        {					
       
   324 		        // DOS lock is not active. Note that if DOS is locked, checking the code here will
       
   325 		        // mess up the query sequence. On initial startup DOS is not locked.		                
       
   326                 
       
   327                 TInt finalConfStatus = scpClient.CheckConfiguration( KSCPComplete );
       
   328                 
       
   329                 if ( finalConfStatus == KErrAccessDenied )
       
   330                     {                
       
   331                     #ifdef __WINS__   
       
   332                     #if defined(_DEBUG)
       
   333                     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
       
   334                         DOS validation FAILED in WINS, something wrong!"));
       
   335                     #endif                                  
       
   336                     #else // !__WINS__                                            
       
   337 
       
   338                     // The SCP server is out of sync and Autolock is not active. (c-drive formatted)
       
   339                     // We must ask the security code. ( Note that it is very rare that this is executed )
       
   340 	                #if defined(_DEBUG)
       
   341                     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
       
   342                         Lock setting disabled, calling setlocksetting"));
       
   343                     #endif
       
   344                 
       
   345                     // Wait here until the startup is complete
       
   346                 
       
   347                     TInt tarmErr = KErrNone;
       
   348                     while ( tarmErr == KErrNone )
       
   349                         {                              
       
   350                         TInt sysState=0;
       
   351                             tarmErr = RProperty::Get(KPSUidStartup, KPSGlobalSystemState, sysState);
       
   352 
       
   353                             if ((sysState == ESwStateNormalRfOn) || (sysState == ESwStateNormalRfOff) 
       
   354                                  || (sysState == ESwStateNormalBTSap))
       
   355                                 {
       
   356                                 break;
       
   357                                 }                                        
       
   358                         User::After(500000);
       
   359                         }
       
   360                 
       
   361                     // Just change the lock setting again to disabled to request the security code.
       
   362                     // Set the TARM flag so SecUi knows it should display the "login" query.
       
   363 	                TInt tarmFlag=0;
       
   364 	                tRet = RProperty::Get( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
       
   365 	                if ( tRet == KErrNone )
       
   366     	                {
       
   367 	                    tarmFlag |= KSCPFlagResyncQuery;
       
   368 	                    tRet = RProperty::Set( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
       
   369 	                    }
       
   370 	            
       
   371 	                if ( tRet != KErrNone )
       
   372                         {
       
   373                         #if defined(_DEBUG)
       
   374                         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL():\
       
   375                             FAILED to set TARM Admin Flag"));
       
   376                         #endif
       
   377                         }
       
   378 	            
       
   379     	            RMobilePhone::TMobilePhoneLockSetting lockChange;
       
   380 	                lockChange = RMobilePhone::ELockSetDisabled;
       
   381 	                iWait->SetRequestType(EMobilePhoneSetLockSetting);
       
   382                     iPhone.SetLockSetting(iWait->iStatus, lockType, lockChange);
       
   383                 
       
   384                     res = iWait->WaitForRequestL();
       
   385                     #endif // __WINS__                                 
       
   386                     }
       
   387                 }                        
       
   388                                    
       
   389             } // if ( confStatus == KErrAccessDenied )
       
   390             
       
   391         scpClient.Close();               
       
   392         }
       
   393       
       
   394 }
       
   395 
       
   396     // Eventhough we might lock the device on boot-up (systemLocked == ETrue), we
       
   397     // want to hide the app until the handshake is done. StartUp application will
       
   398     // active the app when it is finished.
       
   399     if( !systemLocked )
       
   400         {// app to background
       
   401         #if defined(_DEBUG)
       
   402         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() app to background"));
       
   403         #endif
       
   404         TApaTask self(iCoeEnv->WsSession());
       
   405         self.SetWgId(iCoeEnv->RootWin().Identifier());
       
   406         self.SendToBackground();
       
   407         // flush
       
   408         iCoeEnv->WsSession().Flush();      
       
   409         }
       
   410     else
       
   411         {
       
   412         #if defined(_DEBUG)
       
   413         RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL() LOCK SYSTEM"));
       
   414         #endif
       
   415         TInt lockState = 0;
       
   416         
       
   417         #ifdef RD_REMOTELOCK
       
   418 	    lockState = EManualLocked; 	    
       
   419 	    #else //!RD_REMOTELOCK	    
       
   420 	    lockState = EAutolockOn; 	    
       
   421 	    #endif//RD_REMOTELOCK
       
   422         iModel->LockSystemL(lockState);  
       
   423         }
       
   424         
       
   425     iGripStatusObserver = CAutolockGripStatusObserver::NewL( this, iEikonEnv->WsSession() ); 
       
   426     iFpsStatusObserver = CAutolockFpsStatusObserver::NewL( this, iEikonEnv->WsSession() ); 
       
   427     iDeviceLockQueryStatus = EFalse;
       
   428     #if defined(_DEBUG)
       
   429     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::ConstructL()  END"));
       
   430     #endif
       
   431 	}
    85 	}
   432 // ----------------------------------------------------
    86 // ----------------------------------------------------
   433 // CAutolockAppUi::~CAutolockAppUi()
    87 // CAutolockAppUi::~CAutolockAppUi()
   434 // Destructor
    88 // Destructor
   435 // Frees reserved resources
    89 // Frees reserved resources
   436 // ----------------------------------------------------
    90 // ----------------------------------------------------
   437 //
    91 //
   438 CAutolockAppUi::~CAutolockAppUi()
    92 CAutolockAppUi::~CAutolockAppUi()
   439     {
    93     {
       
    94     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
   440     #if defined(_DEBUG)
    95     #if defined(_DEBUG)
   441     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::~CAutolockAppUi() BEGIN"));
    96     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::~CAutolockAppUi() BEGIN"));
   442     #endif
    97     #endif
   443 
    98 
   444     if(iWait)
    99     if(iWait)
   462     if (iServer.Handle())
   117     if (iServer.Handle())
   463         {           
   118         {           
   464         iServer.UnloadPhoneModule(KMmTsyModuleName);
   119         iServer.UnloadPhoneModule(KMmTsyModuleName);
   465         iServer.Close();
   120         iServer.Close();
   466         }
   121         }
       
   122   RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
   467 	delete iModel;
   123 	delete iModel;
   468 	delete iPhoneObserver;
   124 	delete iPhoneObserver;
   469 	delete iIncallBubble;
   125 	delete iIncallBubble;
   470 #ifdef RD_AUTO_KEYGUARD
   126 RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   127 	#ifdef RD_AUTO_KEYGUARD
   471 	delete iKeyguardObserver;
   128 	delete iKeyguardObserver;
   472 #endif
   129 #endif
   473 
   130 
   474     delete iEcsDetector;
   131     delete iEcsDetector;
   475     delete iEcsNote; // Ecs change
   132     delete iEcsNote; // Ecs change
   476     delete iWait;
   133 	RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   134 	  delete iWait;
   477     FeatureManager::UnInitializeLib();
   135     FeatureManager::UnInitializeLib();
   478     delete iGripStatusObserver;
   136     delete iGripStatusObserver;
   479     delete iFpsStatusObserver;
   137     delete iFpsStatusObserver;
   480     #if defined(_DEBUG)
   138     #if defined(_DEBUG)
   481     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::~CAutolockAppUi() END"));
   139     RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::~CAutolockAppUi() END"));
   482     #endif
   140     #endif
   483 	}
   141 RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   142 		}
   484 // ----------------------------------------------------
   143 // ----------------------------------------------------
   485 // CAutolockAppUi::HandleForegroundEventL()
   144 // CAutolockAppUi::HandleForegroundEventL()
   486 // Handles foreground event.
   145 // Handles foreground event.
   487 // ----------------------------------------------------
   146 // ----------------------------------------------------
   488 //
   147 //
   719             Exit();
   378             Exit();
   720             break;
   379             break;
   721 			}
   380 			}
   722         case ESecUiCmdUnlock:
   381         case ESecUiCmdUnlock:
   723 			{
   382 			{
   724 			#if defined(_DEBUG)
   383 			RDebug::Printf( "%s %s (%u) ESecUiCmdUnlock is not longer handled by Autolock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, ESecUiCmdUnlock );
   725 			RDebug::Print(_L("(AUTOLOCK)CAutolockAppUi::HandleCommandL() ESecUiCmdUnlock"));
       
   726 			#endif
       
   727 			// stop observing emergency call event
       
   728 			iEmergencySupportReady = EFalse;
       
   729 			iEcsDetector->Reset(); // Ecs queue is cleared; keys up til here are forgotten
       
   730 			// ask secuity code
       
   731 			CSecurityHandler* handler = new (ELeave) CSecurityHandler(iPhone);
       
   732 			CleanupStack::PushL(handler);
       
   733 			TSecUi::InitializeLibL();	
       
   734 	        
       
   735 	        // Put the lights on when security query is shown
       
   736 	        SendMessageToSysAp( EEikSecurityQueryLights );
       
   737 	        HideSoftNotification();	// dismiss all the pending notes just before asking the unlocking code
       
   738 	        
       
   739             TRAPD(err,
       
   740 			{
       
   741 			iDeviceLockQueryStatus = ETrue;
       
   742 			if(handler->AskSecCodeInAutoLockL())
       
   743 				{		
       
   744 				iLocked = EFalse;
       
   745 				DisableWGListChangeEventListening();
       
   746 				iDeviceLockQueryStatus = EFalse;
       
   747 				UnLockKeys();
       
   748 				iModel->SetLockedL(EFalse);
       
   749 				SwitchToPreviousAppL();
       
   750 				}
       
   751             else
       
   752 				{  // make sure that we will be topmost still
       
   753 				    iDeviceLockQueryStatus = EFalse;
       
   754                     TInt callState;
       
   755                     RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
       
   756                 if ( callState == EPSCTsyCallStateNone &&
       
   757                      !FeatureManager::FeatureSupported( KFeatureIdProtocolCdma ) )
       
   758                     {
       
   759 				    TApaTask self(CCoeEnv::Static()->WsSession());
       
   760 				    self.SetWgId(CCoeEnv::Static()->RootWin().Identifier());
       
   761 				    self.BringToForeground();
       
   762                     TBool featureNoPowerkey = FeatureManager::FeatureSupported( KFeatureIdNoPowerkey );
       
   763                     if ( featureNoPowerkey )
       
   764                         {//set lights on in case user pressed "red button". If he pressed cancel the lights are on anyway so it doesn't matter.
       
   765                         SendMessageToSysAp(EEikKeyLockLightsOnRequest);              
       
   766                         }
       
   767 				    // we don't want enable lock if call in progress    
       
   768                     RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
       
   769                     TInt keyguardDisableState(ECoreAppUIsDisableKeyguardUninitialized);
       
   770                     //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 
       
   771                     //after the alarm has been disabled/snoozed. Otherwise the alarm CBA is left under keyguard CBA.
       
   772                     RProperty::Get( KPSUidCoreApplicationUIs, KCoreAppUIsDisableKeyguard, keyguardDisableState );
       
   773                     if ((callState == EPSCTsyCallStateNone) && (keyguardDisableState != ECoreAppUIsDisableKeyguard))
       
   774                         {   
       
   775 				    	RAknKeyLock keylock;
       
   776 					    if ( keylock.Connect() == KErrNone )
       
   777 						    {
       
   778 						    keylock.EnableAutoLockEmulation();
       
   779 						    keylock.Close();
       
   780 						    }
       
   781 					    }
       
   782                     }
       
   783                 }
       
   784 			};)
       
   785 
       
   786 			// start observing emergency call event
       
   787 			iEmergencySupportReady = ETrue;
       
   788 			CleanupStack::PopAndDestroy(handler); // handler
       
   789 			TSecUi::UnInitializeLib();  // secui 		
       
   790 			
       
   791 			User::LeaveIfError(err);
       
   792 
   384 
   793 			break;
   385 			break;
   794 			}
   386 			}
   795         default:
   387         default:
   796             break;      
   388             break;