securitydialogs/lockapp/src/lockappkeyguardcontrol.cpp
branchGCC_SURGE
changeset 40 604cd42065d1
parent 29 b63e8c2d8cff
parent 38 e0432375ea67
equal deleted inserted replaced
29:b63e8c2d8cff 40:604cd42065d1
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Keyguard UI
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "lockappkeyguardcontrol.h"
       
    20 #include "lockappstatecontrolinterface.h"
       
    21 #include "lockappcenrepobserver.h"
       
    22 #include "lockapppubsubobserver.h"
       
    23 #include "lockapputils.h"
       
    24 #include "lockapplockednote.h" // keyguard notes
       
    25 #include "lockappkeycapturecontroller.h"
       
    26 
       
    27 #include <avkon.rsg> // general avkon resources
       
    28 #include <aknnotpi.rsg> // keyguard spesific resources
       
    29 #include <AknUtils.h>
       
    30 #include <activitymanager.h>
       
    31 // this is not needed
       
    32 // #include <SecondaryDisplay/AknSecondaryDisplayDefs.h> // publishing keyguard notes to secondary display
       
    33 #include <featmgr.h> // feature manager
       
    34 #include <eikcba.h> // keyguard soft buttons
       
    35 #include <eikspane.h>
       
    36 
       
    37 #include "AutolockPrivateCRKeys.h"
       
    38 #include <settingsinternalcrkeys.h>
       
    39 // #include <ScreensaverInternalPSKeys.h>
       
    40 #include <hwrmdomainpskeys.h>
       
    41 // #include <activeidle2domainpskeys.h>
       
    42 //#include <CoreApplicationUIsPrivateCRKeys.h> TODO remove
       
    43 #include <coreapplicationuisdomainpskeys.h>
       
    44 #include <ctsydomainpskeys.h>
       
    45 #include <startupdomainpskeys.h>
       
    46 
       
    47 // Asterisk key's scan code for the keylock
       
    48 const TUint KStdKeyAsterisk = 42;
       
    49 //const TUint KAknChineseAsterisk = 0xFF0A;
       
    50 
       
    51 // timeout defined in keyguard ui specification custom value
       
    52 // since avkon note TTimeout values don't support 1 second timeout
       
    53 const TInt KKeyLockCustomShortTimeout = 1000000;
       
    54 
       
    55 // Auto Keyguard Off value
       
    56 const TInt KAutoKeyguardOff( 60000 );
       
    57 
       
    58 // Flip open value
       
    59 const TInt KFlipOpen = 1;
       
    60 
       
    61 // Screensaver started fron idle status value
       
    62 const TInt KSsStartedFromIdle = 1;
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Standard Symbian OS construction sequence
       
    66 // ---------------------------------------------------------------------------
       
    67 CLockAppKeyguardControl* CLockAppKeyguardControl::NewL(MLockAppStateControl& aStateControl )
       
    68     {
       
    69     CLockAppKeyguardControl* self = new (ELeave) CLockAppKeyguardControl( aStateControl );
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL( );
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Notes, cba and localized resources are freed in Keyguard UI destruction.
       
    78 // ---------------------------------------------------------------------------
       
    79 CLockAppKeyguardControl::~CLockAppKeyguardControl( )
       
    80     {
       
    81 #ifdef RD_AUTO_KEYGUARD
       
    82     if ( iActivityManager )
       
    83         {
       
    84         iActivityManager->Cancel( );
       
    85         delete iActivityManager;
       
    86         iActivityManager = NULL;
       
    87         }
       
    88     // CenRep observers
       
    89     if ( iCRAutoKeyguardTime )
       
    90         {
       
    91         delete iCRAutoKeyguardTime;
       
    92         iCRAutoKeyguardTime = NULL;
       
    93         }
       
    94 #endif //RD_AUTO_KEYGUARD
       
    95     if ( iCRPersistentKeyguardStatus )
       
    96         {
       
    97         delete iCRPersistentKeyguardStatus;
       
    98         iCRPersistentKeyguardStatus = NULL;
       
    99         }
       
   100     if ( iPSStartupObserver )
       
   101         {
       
   102         delete iPSStartupObserver;
       
   103         iPSStartupObserver = NULL;
       
   104         }
       
   105     // child notes
       
   106     delete iConfirmationNote;
       
   107     delete iLockedNote;
       
   108     delete iKeypadUnlockedNote;
       
   109     delete iKeypadLockedNote;
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Constructor passes the reference to the main state control.
       
   114 // ---------------------------------------------------------------------------
       
   115 CLockAppKeyguardControl::CLockAppKeyguardControl(MLockAppStateControl& aStateControl ) :
       
   116     CLockAppBaseControl(aStateControl)
       
   117     {
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // Keyguard UI constructor reserves localized resources, configures itself
       
   122 // using CenRep and FeatureManager and reserves child controls.
       
   123 // ---------------------------------------------------------------------------
       
   124 void CLockAppKeyguardControl::ConstructL( )
       
   125     {
       
   126     INFO( "CLockAppKeyguardControl::ConstructL started" );
       
   127     CLockAppBaseControl::ConstructL( );
       
   128 
       
   129     // feature manager is used for determining if the phone is a slider
       
   130     TBool aFeatureKeypadNoSlider(ETrue);
       
   131     FeatureManager::InitializeLibL( );
       
   132     aFeatureKeypadNoSlider = FeatureManager::FeatureSupported( KFeatureIdKeypadNoSlider );
       
   133     INFO_1("CLockAppKeyguardControl::ConstructL - aFeatureKeypadNoSlider: %d", aFeatureKeypadNoSlider);
       
   134     FeatureManager::UnInitializeLib( );
       
   135 
       
   136     // keyguard hardware switch support
       
   137     CRepository* repository = CRepository::NewLC( KCRUidLockConf );
       
   138     TInt hardwareSupport(0);
       
   139     repository->Get( KKeyguardHardwareConf, hardwareSupport );
       
   140     CleanupStack::PopAndDestroy( repository );
       
   141     iHardwareSupport = TLockHardware( hardwareSupport );
       
   142     iHardwareSupport = TLockHardware( 0 );
       
   143 
       
   144     TBool touchEnabled( AknLayoutUtils::PenEnabled() );
       
   145     
       
   146     // Cba control
       
   147     iCba = CEikButtonGroupContainer::NewL( CEikButtonGroupContainer::ECba,
       
   148                                            CEikButtonGroupContainer::EHorizontal,
       
   149                                            this,
       
   150                                            touchEnabled ? R_AVKON_SOFTKEYS_EMPTY :
       
   151                                            R_KEYLOCK_SOFTKEYS_UNLOCK_EMPTY );
       
   152     TRect screenRect;
       
   153     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
   154     iCba->SetBoundingRect( screenRect );
       
   155     iCba->MakeVisible( EFalse );
       
   156 
       
   157     // Construct Keyguard Notes
       
   158     iKeypadLockedNote = new (ELeave) CLockAppLockedNote();
       
   159     iKeypadLockedNote->ConstructSleepingNoteL( touchEnabled ? R_KEYLOCK_NOTE_DISPLAY_LOCK_ON_TOUCH :
       
   160                                                R_KEYLOCK_NOTE_LOCK_ON );
       
   161     iKeypadLockedNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
   162 		// this is not needed
       
   163     // iKeypadLockedNote->PublishDialogL( EAknKeysLockedNote );
       
   164 
       
   165     iKeypadUnlockedNote = new (ELeave) CLockAppLockedNote();
       
   166     iKeypadUnlockedNote->ConstructSleepingNoteL( touchEnabled ? R_KEYLOCK_NOTE_DISPLAY_LOCK_OFF_TOUCH :
       
   167                                                  R_KEYLOCK_NOTE_LOCK_OFF );
       
   168     iKeypadUnlockedNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
   169 		// this is not needed
       
   170     // iKeypadUnlockedNote->PublishDialogL( EAknKeysReleasedNote );
       
   171 
       
   172     iLockedNote = new (ELeave) CLockAppLockedNote();
       
   173     if ( touchEnabled )
       
   174         {
       
   175         iLockedNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_DISPLAY_LOCKED_TOUCH );
       
   176         }
       
   177     else
       
   178         {
       
   179         switch ( iHardwareSupport )
       
   180             {
       
   181             case EKeyguardOnePositionSwitch:
       
   182             case EKeyguardTwoPositionSwitch:
       
   183                 {
       
   184                 iLockedNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_KEYLOCKED_SWITCH );
       
   185                 break;
       
   186                 }
       
   187             case EKeyguardDefaultHardware:
       
   188             default:
       
   189                 {
       
   190                 iLockedNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_KEYLOCKED );
       
   191                 break;
       
   192                 }
       
   193             }
       
   194         }
       
   195     iLockedNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
   196 
       
   197     // These are created only if touch is not enabled, since
       
   198     // currently in touch devices the keylock state is controlled
       
   199     // with switch.
       
   200     if ( !touchEnabled )
       
   201         {
       
   202         //Note showing "Now Press *" - when user has pressed "Unlock" in locked state.
       
   203         if ( aFeatureKeypadNoSlider )
       
   204             {
       
   205             // for normal phones
       
   206             iConfirmationNote = new (ELeave) CLockAppLockedNote();
       
   207             iConfirmationNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_UNLOCK_ASTERISK );
       
   208             }
       
   209         else
       
   210             {
       
   211             // for special slider phones
       
   212             iConfirmationNote = new (ELeave) CLockAppLockedNote();
       
   213             iConfirmationNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_UNLOCK_CONFIRM );
       
   214             }
       
   215         iConfirmationNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
   216         
       
   217         }
       
   218     
       
   219     
       
   220     // CenRep observers
       
   221     // TODO create private CR key for storing persistent keyguard state (currently in Sysap)
       
   222     // iCRPersistentKeyguardStatus = CLockAppCenRepObserver::NewL ( this, KCRUidCoreApplicationUIsSysAp, KSysApKeyguardActive );
       
   223 
       
   224 #ifdef RD_AUTO_KEYGUARD
       
   225     iCRAutoKeyguardTime = CLockAppCenRepObserver::NewL ( this, KCRUidSecuritySettings, KSettingsAutomaticKeyguardTime );
       
   226     // Activity manager
       
   227     iActivityManager = CUserActivityManager::NewL( CActive::EPriorityStandard );
       
   228     StartActivityMonitoringL( );
       
   229 #endif //RD_AUTO_KEYGUARD
       
   230 
       
   231     // PubSub observers
       
   232     iPSStartupObserver = CLockAppPubSubObserver::NewL( this, KPSUidStartup, KPSGlobalSystemState );
       
   233 
       
   234     // Setup key pattern matcher
       
   235     if ( !SetupKeyPatternsWithPolicyL( EPolicyDeactivateKeyguard ) )
       
   236         {
       
   237         INFO( "CLockAppKeyguardControl::ConstructL - No CenRep policy defined" );
       
   238         if ( aFeatureKeypadNoSlider )
       
   239             {
       
   240             iKeyPattern->AddPattern( EStdKeyDevice0, KStdKeyAsterisk ); // LSK + *
       
   241             }
       
   242         else
       
   243             {
       
   244             iKeyPattern->AddPattern( EStdKeyDevice0, EStdKeyDevice1 ); // LSK + RSK
       
   245             }
       
   246         }
       
   247 #ifdef __WINS__
       
   248     // In Emulator add the LSK+* pattern also.
       
   249     iKeyPattern->AddPattern( EStdKeyDevice0, EStdKeyNkpAsterisk ); // LSK + *
       
   250 #endif
       
   251 
       
   252     INFO( "CLockAppKeyguardControl::ConstructL completed" );
       
   253     }
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // Check weather its allowed to automatically lock the keys
       
   257 // ---------------------------------------------------------------------------
       
   258 TBool CLockAppKeyguardControl::AutoActivationAllowedL( )
       
   259     {
       
   260 #ifdef RD_AUTO_KEYGUARD
       
   261     TInt value = 0;
       
   262     TBool flipOpen(EFalse);
       
   263     RProperty::Get( KPSUidHWRM, KHWRMFlipStatus, value );
       
   264     flipOpen = (value = KFlipOpen);
       
   265     INFO_1("CLockAppKeyguardControl::AutoActivationAllowedL - flipOpen: %d", flipOpen);
       
   266     if ( flipOpen )
       
   267         {
       
   268         CRepository* repository = CRepository::NewL( KCRUidAutolockConf );
       
   269         repository->Get( KAutoKeyLockConf, value );
       
   270         delete repository;
       
   271         if ( value & KAutoKeylockFeatureIdFlipOpenDisabled )
       
   272             {
       
   273             INFO( "CLockAppKeyguardControl::AutoActivationAllowedL : False because flipOpenDisabled" );
       
   274             return EFalse;
       
   275             }
       
   276         }
       
   277 
       
   278     TInt lightStatus=EForcedLightsUninitialized; 
       
   279     RProperty::Get(KPSUidCoreApplicationUIs,KLightsVTForcedLightsOn,lightStatus ); 
       
   280     INFO_1("CLockAppKeyguardControl::AutoActivationAllowedL - lightStatus: %d", lightStatus);
       
   281     if ( lightStatus == EForcedLightsOn )
       
   282 	{
       
   283 	INFO( "CLockAppKeyguardControl::AutoActivationAllowedL : False because EForcedLightsOn" );
       
   284 	return EFalse;
       
   285 	}
       
   286 
       
   287     TBool keysLocked(EFalse);
       
   288     TBool idle(EFalse);
       
   289     TBool ongoingCall(EFalse);
       
   290     TBool screenSaverOn(EFalse);
       
   291     TBool screenSaverStertedFromIdle(EFalse);
       
   292 
       
   293     keysLocked = (iStateControl.LockStatus() != ELockNotActive);
       
   294     INFO_1("CLockAppKeyguardControl::AutoActivationAllowedL - keysLocked: %d", keysLocked);
       
   295     value = 0;
       
   296     RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, value );
       
   297     ongoingCall = (value > EPSCTsyCallStateNone);
       
   298     INFO_2("CLockAppKeyguardControl::AutoActivationAllowedL - ongoingCall: %d %d", value, ongoingCall);
       
   299     value = 0;
       
   300     // RProperty::Get( KPSUidAiInformation, KActiveIdleState, value );
       
   301     // idle = (value == EPSAiForeground);
       
   302     idle = ETrue; // don't care about idle state. Phone should autolock on any UI, not only HomeSreeen.
       
   303     INFO_2("CLockAppKeyguardControl::AutoActivationAllowedL - idle: %d %d", value, idle);
       
   304     value = 0;
       
   305 		/* This is not used any more because screensavers are removed now
       
   306     RProperty::Get( KPSUidScreenSaver, KScreenSaverOn, value );
       
   307     screenSaverOn = (value > 0);
       
   308     */
       
   309     screenSaverOn = ETrue;
       
   310     
       
   311     INFO_2("CLockAppKeyguardControl::AutoActivationAllowedL - screenSaverOn: %d %d", value, screenSaverOn);
       
   312     value = 0;
       
   313 		/* This is not used any more because screensavers are removed now
       
   314     RProperty::Get( KPSUidScreenSaver, KScreenSaverActivatedFromIdle, value );
       
   315     screenSaverStertedFromIdle = (value == KSsStartedFromIdle);
       
   316     */
       
   317     screenSaverStertedFromIdle = ETrue;
       
   318     
       
   319     INFO_2("CLockAppKeyguardControl::AutoActivationAllowedL - screenSaverStertedFromIdle: %d %d", value, screenSaverStertedFromIdle);
       
   320 
       
   321     // If a call is ongoing or idle doesnt have foreground and
       
   322     // screensaver is not started from idle -> dont lock keys
       
   323     if ( keysLocked || ongoingCall || (!idle && !(screenSaverOn && screenSaverStertedFromIdle)) )
       
   324         {
       
   325         INFO("CLockAppKeyguardControl::AutoActivationAllowedL : False");
       
   326         return EFalse;
       
   327         }
       
   328 #endif //RD_AUTO_KEYGUARD
       
   329     INFO("CLockAppKeyguardControl::AutoActivationAllowedL : True");
       
   330     return ETrue;
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // Check weather its allowed to activate the control
       
   335 // ---------------------------------------------------------------------------
       
   336 TBool CLockAppKeyguardControl::ActivationAllowedL( )
       
   337     {
       
   338     return ETrue;
       
   339     }
       
   340 
       
   341 // ---------------------------------------------------------------------------
       
   342 // Check weather its allowed to deactivate the control
       
   343 // ---------------------------------------------------------------------------
       
   344 TBool CLockAppKeyguardControl::DeActivationAllowedL( )
       
   345     {
       
   346     return ETrue;
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // Activate control
       
   351 // ---------------------------------------------------------------------------
       
   352 void CLockAppKeyguardControl::HandleActivateEventL( TUint aEnvMask )
       
   353     {    
       
   354     INFO_1("CLockAppKeyguardControl::HandleActivateEventL - aEnvMask: %x", aEnvMask);
       
   355     
       
   356     CLockAppBaseControl::HandleActivateEventL( aEnvMask );
       
   357 
       
   358     if ( IsBitFieldSet( aEnvMask, KLockAppEnvScreenSaverOn ) )
       
   359         {
       
   360         // if screensaver is on - capture primary keys
       
   361         CapturePrimaryKeys( ETrue );
       
   362         }
       
   363 
       
   364     // capture keys
       
   365     CLockAppKeyCaptureController::CaptureKey( EStdKeyApplication0, EKeyApplication0, EKeyCaptureAllEvents ); // App key
       
   366     CLockAppKeyCaptureController::CaptureKey( EStdKeyDevice2, EKeyDevice2, EKeyCaptureAllEvents ); // Power key (for lights)
       
   367     CLockAppKeyCaptureController::CaptureKey( EStdKeyDevice6, EKeyDevice6, EKeyCaptureAllEvents ); // Voice key (for lights)
       
   368     CLockAppKeyCaptureController::CaptureKey( EStdKeyNo, EKeyNo, EKeyCaptureAllEvents ); // End key (for Rosetta lights)
       
   369 
       
   370     SetPointerEventCapture( ETrue );
       
   371     SetKeyguardIndicatorStateL( ETrue );
       
   372     ShowCba( ETrue );
       
   373     // close task-list in case it is displayed : fast-swap window
       
   374     iEikonEnv->DismissTaskList( );
       
   375     if ( iCba )
       
   376         {
       
   377         TBool areWeInIdleState = CEikStatusPaneBase::Current()->PaneCapabilities(TUid::Uid(EEikStatusPaneUidClock)).IsInCurrentLayout( );
       
   378         if ( areWeInIdleState )
       
   379             {
       
   380             (static_cast<CEikCba*>(iCba->ButtonGroup()))->SetSkinBackgroundId( KAknsIIDQsnBgAreaControlIdle );
       
   381             }
       
   382         else
       
   383             {
       
   384             (static_cast<CEikCba*>(iCba->ButtonGroup()))->SetSkinBackgroundId( KAknsIIDQsnBgAreaControl );
       
   385             }
       
   386         }
       
   387 
       
   388     if ( iCRPersistentKeyguardStatus )
       
   389         {
       
   390         iCRPersistentKeyguardStatus->SetValue( 1 );
       
   391         }
       
   392     }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // DeActivate control
       
   396 // ---------------------------------------------------------------------------
       
   397 void CLockAppKeyguardControl::HandleDeActivateEventL( TUint aEnvMask )
       
   398     {
       
   399     INFO_1("CLockAppKeyguardControl::HandleDeActivateEventL - aEnvMask: 0x%x", aEnvMask);
       
   400     
       
   401     CLockAppBaseControl::HandleDeActivateEventL( aEnvMask );
       
   402 
       
   403     if ( IsBitFieldSet( aEnvMask, KLockAppEnvScreenSaverOn ) )
       
   404         {
       
   405         // if screensaver is on - uncapture primary keys
       
   406         CapturePrimaryKeys( EFalse );
       
   407         }
       
   408 
       
   409     // phonecall or not - uncapture keys anyway
       
   410     CLockAppKeyCaptureController::ReleaseKey( EStdKeyApplication0 );
       
   411     CLockAppKeyCaptureController::ReleaseKey( EStdKeyDevice2 );
       
   412     CLockAppKeyCaptureController::ReleaseKey( EStdKeyDevice6 );
       
   413     CLockAppKeyCaptureController::ReleaseKey( EStdKeyNo );
       
   414 
       
   415     SetPointerEventCapture( EFalse );
       
   416     SetKeyguardIndicatorStateL( EFalse );
       
   417     ShowCba( EFalse );
       
   418 
       
   419     if ( iCRPersistentKeyguardStatus )
       
   420         {
       
   421         iCRPersistentKeyguardStatus->SetValue( 0 );
       
   422         }
       
   423     }
       
   424 
       
   425 // ---------------------------------------------------------------------------
       
   426 // Handle environment changes (Screensaver, Telephony, etc.)
       
   427 // ---------------------------------------------------------------------------
       
   428 void CLockAppKeyguardControl::HandleEnvironmentChange( TUint aEnvMask, TUint aEventMask )
       
   429     {
       
   430     if ( IsBitFieldSet( aEventMask, KLockAppEnvScreenSaverOn ) )
       
   431         {
       
   432         // screen saver state changed
       
   433         CapturePrimaryKeys( IsBitFieldSet( aEnvMask, KLockAppEnvScreenSaverOn ) );
       
   434         }
       
   435     if ( IsBitFieldSet( aEventMask, KLockAppEnvFPS ) )
       
   436         {
       
   437     		// iStateControl.DisableKeyguardL( ETrue );
       
   438     		// iStateControl.LockStatus() != ELockNotActive		// no need to check, because keyguard will catch fingerprint only if not locked
       
   439     		iStateControl.EnableDevicelockL( EDevicelockManual );
       
   440         }
       
   441     }
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // Inform the user that keys are locked (i.e. "Please press LSK+'*' to unlock).
       
   445 // ---------------------------------------------------------------------------
       
   446 void CLockAppKeyguardControl::DisplayLockedNote( )
       
   447     {
       
   448     ShowNote( iLockedNote, CAknNoteDialog::ELongTimeout, CAknNoteDialog::ENoTone );
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // Handle all Central Repository observer callbacks.
       
   453 // ---------------------------------------------------------------------------
       
   454 void CLockAppKeyguardControl::HandleCenRepNotify(TUid aCenRepUid, TUint32 aKeyId, TInt aValue )
       
   455     {
       
   456     if ( aCenRepUid == KCRUidSecuritySettings )
       
   457         {
       
   458         switch ( aKeyId )
       
   459             {
       
   460             case KSettingsAutomaticKeyguardTime:
       
   461                 {
       
   462                 INFO_1( "CLockAppKeyguardControl::HandleCenRepNotify - KSettingsAutomaticKeyguardTime = %d", aValue );
       
   463                 ResetInactivityTimeout( );
       
   464                 }
       
   465                 break;
       
   466             default:
       
   467                 break;
       
   468             }
       
   469         }
       
   470     }
       
   471 
       
   472 // ---------------------------------------------------------------------------
       
   473 // Handle all Publish & Subscribe observer callbacks.
       
   474 // ---------------------------------------------------------------------------
       
   475 void CLockAppKeyguardControl::HandlePubSubNotify(TUid aPubSubUid, TUint aKeyId, TInt aValue )
       
   476     {
       
   477     if ( aPubSubUid == KPSUidStartup )
       
   478         {
       
   479         switch ( aKeyId )
       
   480             {
       
   481             case KPSGlobalSystemState:
       
   482                 {
       
   483                 // In case of unexpected reset (e.g. hidden boot) the keylock must be enabled silently.
       
   484                 if ( !iAlreadyNormalState && (aValue == ESwStateNormalRfOn || aValue == ESwStateNormalRfOff) )
       
   485                     {
       
   486                     iAlreadyNormalState = ETrue;
       
   487                     TInt keylockWasEnabled = 0;
       
   488                     if ( iCRPersistentKeyguardStatus )
       
   489                         {
       
   490                         iCRPersistentKeyguardStatus->GetValue( keylockWasEnabled );
       
   491                         if ( keylockWasEnabled )
       
   492                             {
       
   493                             TRAPD(err, iStateControl.EnableKeyguardL( EFalse ));
       
   494                             ERROR(err, "CLockAppKeyguardControl::HandlePubSubNotify - EnableKeyguardL");
       
   495                             }
       
   496                         }
       
   497                     }
       
   498                 }
       
   499                 break;
       
   500             default:
       
   501                 break;
       
   502             }
       
   503         }
       
   504     INFO_3( "CLockAppKeyguardControl::HandlePubSubNotify %x %x = %x", aPubSubUid.iUid, aKeyId, aValue );
       
   505     }
       
   506 
       
   507 // ---------------------------------------------------------------------------
       
   508 // Show that keys are locked.
       
   509 // ---------------------------------------------------------------------------
       
   510 void CLockAppKeyguardControl::DisplayKeysLockedNote( )
       
   511     {
       
   512     ShowNote( iKeypadLockedNote, KKeyLockCustomShortTimeout, CAknNoteDialog::ENoTone );
       
   513     }
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 // Show that keys are unlocked.
       
   517 // ---------------------------------------------------------------------------
       
   518 void CLockAppKeyguardControl::DisplayKeysActiveNote( )
       
   519     {
       
   520     ShowNote( iKeypadUnlockedNote, KKeyLockCustomShortTimeout, CAknNoteDialog::ENoTone );
       
   521     }
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 // Show confirmation note when user has pressed "Unlock".
       
   525 // ---------------------------------------------------------------------------
       
   526 void CLockAppKeyguardControl::DisplayConfirmationNote( )
       
   527     {
       
   528     ShowNote( iConfirmationNote, CAknNoteDialog::EShortTimeout, CAknNoteDialog::EConfirmationTone );
       
   529     // inform sysap to put lights on left soft key press
       
   530     SendMessageToSysAp( EEikKeyLockLightsOnRequest );
       
   531     }
       
   532 
       
   533 // ---------------------------------------------------------------------------
       
   534 // Keyguard UI key events are handled trough here.
       
   535 // ---------------------------------------------------------------------------
       
   536 TKeyResponse CLockAppKeyguardControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
       
   537     {
       
   538     RDebug::Printf( "%s %s (%u) aKeyEvent.iCode=%x aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyEvent.iCode, aType );
       
   539     RDebug::Printf( "%s %s (%u) iActive=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iActive );
       
   540     if ( iActive )
       
   541         {
       
   542         		if(AknLayoutUtils::PenEnabled())
       
   543         			{
       
   544         			if(aKeyEvent.iCode == EKeyDeviceF)	// any Type
       
   545         				{
       
   546         				iStateControl.DisableKeyguardL( ETrue );
       
   547         				}
       
   548         			}
       
   549         if ( aType == EEventKeyDown )
       
   550             {
       
   551             switch ( iKeyPattern->HandleKeyEvent( aKeyEvent.iScanCode ) )
       
   552                 {
       
   553                 case EPatternNoMatch:
       
   554                     DisplayLockedNote( );
       
   555                     break;
       
   556                 case EPatternPrimaryMatch:
       
   557                     DisplayConfirmationNote( );
       
   558                     break;
       
   559                 case EPatternSecondaryMatch:
       
   560                     iStateControl.DisableKeyguardL( ETrue );
       
   561                     break;
       
   562                 default:
       
   563         						RDebug::Printf( "%s %s (%u) default=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
       
   564                     break;
       
   565                 }
       
   566             }
       
   567         }
       
   568     return EKeyWasConsumed;
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // Get autokeyguard timeout (in seconds)
       
   573 // @return 0 means Off
       
   574 // ---------------------------------------------------------------------------
       
   575 TInt CLockAppKeyguardControl::GetAutoKeyguardTimeout( )
       
   576     {
       
   577     TInt timeoutInSeconds( 0 );
       
   578 #ifdef RD_AUTO_KEYGUARD
       
   579     iCRAutoKeyguardTime->GetValue( timeoutInSeconds );
       
   580 #endif //RD_AUTO_KEYGUARD
       
   581     return timeoutInSeconds;
       
   582     }
       
   583 
       
   584 // ----------------------------------------------------------
       
   585 // Starts monitoring user activity
       
   586 // ----------------------------------------------------------
       
   587 void CLockAppKeyguardControl::StartActivityMonitoringL( )
       
   588     {
       
   589 #ifdef RD_AUTO_KEYGUARD
       
   590     __ASSERT_DEBUG( iActivityManager, DoPanic(ELockIllegalState));
       
   591     if ( iActivityManager && !iActivityManager->IsActive() )
       
   592         {
       
   593         TInt value = GetAutoKeyguardTimeout( );
       
   594         INFO_1( "CLockAppKeyguardControl::StartActivityMonitoringL - %d sec", value);
       
   595         if ( value )
       
   596             {
       
   597             iActivityManager->Start( value,
       
   598                     TCallBack( HandleInactiveEventL, this ),
       
   599                     TCallBack( HandleActiveEventL, this ) );
       
   600             }
       
   601         else
       
   602             {
       
   603             iActivityManager->Start( KAutoKeyguardOff,
       
   604                     TCallBack( HandleInactiveEventL, this ),
       
   605                     TCallBack( HandleActiveEventL, this ) );
       
   606             }
       
   607         }
       
   608 #endif //RD_AUTO_KEYGUARD
       
   609     }
       
   610 
       
   611 // ----------------------------------------------------------
       
   612 // Gets keyguard period and starts monitoring user activity
       
   613 // ----------------------------------------------------------
       
   614 void CLockAppKeyguardControl::ResetInactivityTimeout( )
       
   615     {
       
   616 #ifdef RD_AUTO_KEYGUARD
       
   617     __ASSERT_DEBUG( iActivityManager, DoPanic(ELockIllegalState));
       
   618     if ( iActivityManager )
       
   619         {
       
   620         TInt value = GetAutoKeyguardTimeout( );
       
   621         INFO_1( "CLockAppKeyguardControl::ResetInactivityTimeout - %d sec", value);
       
   622         if ( value )
       
   623             {
       
   624             iActivityManager->SetInactivityTimeout( value );
       
   625             }
       
   626         else
       
   627             {
       
   628             iActivityManager->SetInactivityTimeout( KAutoKeyguardOff );
       
   629             }
       
   630         }
       
   631 #endif //RD_AUTO_KEYGUARD
       
   632     }
       
   633 
       
   634 // ----------------------------------------------------------
       
   635 // Stop monitoring user activity.
       
   636 // ----------------------------------------------------------
       
   637 void CLockAppKeyguardControl::StopActivityMonitoring( )
       
   638     {
       
   639 #ifdef RD_AUTO_KEYGUARD
       
   640     if ( iActivityManager )
       
   641         {
       
   642         iActivityManager->Cancel( );
       
   643         }
       
   644 #endif //RD_AUTO_KEYGUARD
       
   645     }
       
   646 
       
   647 // ----------------------------------------------------------
       
   648 // Handle Active event. Called by ActivityManager
       
   649 // ----------------------------------------------------------
       
   650 TInt CLockAppKeyguardControl::HandleActiveEventL(TAny* /*aPtr*/)
       
   651     {
       
   652     return KErrNone;
       
   653     }
       
   654 
       
   655 // ----------------------------------------------------------
       
   656 // Handles InActive event. Called by ActivityManager
       
   657 // ----------------------------------------------------------
       
   658 TInt CLockAppKeyguardControl::HandleInactiveEventL(TAny* aPtr )
       
   659     {
       
   660 #ifdef RD_AUTO_KEYGUARD
       
   661     CLockAppKeyguardControl* keyguard = STATIC_CAST(CLockAppKeyguardControl*, aPtr);
       
   662     if ( keyguard->GetAutoKeyguardTimeout( ) && keyguard->AutoActivationAllowedL( ) )
       
   663         {
       
   664         keyguard->iStateControl.EnableKeyguardL( EFalse );
       
   665         }
       
   666 #endif //RD_AUTO_KEYGUARD
       
   667     return KErrNone;
       
   668     }
       
   669 
       
   670 // ---------------------------------------------------------------------------
       
   671 // Handle UI commands received from the child controls
       
   672 // ---------------------------------------------------------------------------
       
   673 void CLockAppKeyguardControl::ProcessCommandL( TInt aCommandId )
       
   674     {
       
   675     INFO_1("CLockAppKeyguardControl::ProcessCommandL : %d ", aCommandId );
       
   676     }
       
   677 
       
   678 TInt CLockAppKeyguardControl::CountComponentControls( ) const
       
   679     {
       
   680     return 1;
       
   681     }
       
   682 
       
   683 CCoeControl* CLockAppKeyguardControl::ComponentControl(TInt /*aIndex*/) const
       
   684     {
       
   685     return iCba;
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // Notification if layout changes.
       
   690 // ---------------------------------------------------------------------------
       
   691 void CLockAppKeyguardControl::HandleResourceChange(TInt aType )
       
   692     {
       
   693     if ( aType == KEikDynamicLayoutVariantSwitch && iCba )
       
   694         {
       
   695         TRect screenRect;
       
   696         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
   697         iCba->SetBoundingRect( screenRect );
       
   698         }
       
   699     CCoeControl::HandleResourceChange( aType );
       
   700     }
       
   701 
       
   702 // END OF FILE