securitydialogs/lockapp/src/lockappstatecontrol.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:  Controls lock states (unlocked, keylock, devicelock)
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "lockappstatecontrol.h"
       
    20 
       
    21 // child controls
       
    22 #include "lockappidlecontrol.h"
       
    23 #include "lockappkeyguardcontrol.h"
       
    24 #include "lockappdevicelockcontrol.h"
       
    25 
       
    26 #include "lockapppubsubobserver.h"
       
    27 #include "lockappcenrepobserver.h"
       
    28 
       
    29 #include "lockappkeycapturecontroller.h"
       
    30 #include "lockappstatepublisher.h"
       
    31 #include "lockappecsdetector.h"
       
    32 #include "lockapputils.h"
       
    33 #include <featmgr.h>
       
    34 
       
    35 #include <settingsinternalcrkeys.h>
       
    36 // #include <ScreensaverInternalPSKeys.h>
       
    37 #include <ctsydomainpskeys.h>
       
    38 // #include <activeidle2domainpskeys.h>
       
    39 
       
    40 #include "GlobalWindowPriorities.h"
       
    41 
       
    42 #include <avkon.rsg> // general avkon resources
       
    43 #include <aknnotpi.rsg> // keyguard spesific resources
       
    44 #include <aknsoundsystem.h>
       
    45 #include <AknIncallBubbleNotify.h> // incall bubble
       
    46 #include <bautils.h> // BaflUtils
       
    47 #include <apgwgnam.h>
       
    48 
       
    49 #include <keylockpolicyapi.h>
       
    50 
       
    51 #include <hwrmdomainpskeys.h>
       
    52     TUid KUidFpsCategory = {0x1020507E};
       
    53 const		TInt KFpsAuthenticationKey = 1;
       
    54 
       
    55 // used avkon dialog resources
       
    56 _LIT(KRESOURCEFILE, "z:\\resource\\aknnotpi.rsc");
       
    57 
       
    58 // Visibility gate WG priority's relative offset from ECoeWinPriorityAlwaysAtFront
       
    59 // Now equals -1000 to be an absolute 0.
       
    60 const TInt KGlobalWindowPriority_LockVisibilityGate = -1000;
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // Standard Symbian OS construction sequence
       
    64 // ---------------------------------------------------------------------------
       
    65 CLockAppStateControl* CLockAppStateControl::NewL( )
       
    66     {
       
    67     CLockAppStateControl* self = new (ELeave) CLockAppStateControl();
       
    68     CleanupStack::PushL( self );
       
    69     self->ConstructL( );
       
    70     CleanupStack::Pop( self );
       
    71     return self;
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Destruction releases key captures.
       
    76 // ---------------------------------------------------------------------------
       
    77 CLockAppStateControl::~CLockAppStateControl( )
       
    78     {
       
    79     // localized resources are freed
       
    80     if ( iResourceFileOffset )
       
    81         {
       
    82         // We implicitely trust that eikon env exists (though in practice it does not make the
       
    83         // difference as this destructor is really never called...)
       
    84         iEikonEnv->DeleteResourceFile(iResourceFileOffset);
       
    85         }
       
    86 
       
    87     // PuSub observers
       
    88     if ( iPSScreenSaverObserver )
       
    89         {
       
    90         delete iPSScreenSaverObserver;
       
    91         iPSScreenSaverObserver = NULL;
       
    92         }
       
    93 
       
    94     if ( iPSTelephonyObserver )
       
    95         {
       
    96         delete iPSTelephonyObserver;
       
    97         iPSTelephonyObserver = NULL;
       
    98         }
       
    99 
       
   100     if ( iPSGripObserver )
       
   101         {
       
   102         delete iPSGripObserver;
       
   103         iPSGripObserver = NULL;
       
   104         }
       
   105 
       
   106     if ( iPSFPSObserver )
       
   107         {
       
   108         delete iPSFPSObserver;
       
   109         iPSFPSObserver = NULL;
       
   110         }
       
   111 
       
   112     CLockAppKeyCaptureController::Destroy( );
       
   113 
       
   114     if ( iIncallBubble )
       
   115         {
       
   116         delete iIncallBubble;
       
   117         iIncallBubble = NULL;
       
   118         }
       
   119 
       
   120     if ( iSoundsMuted )
       
   121         {
       
   122         MuteSounds( EFalse );
       
   123         }
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // The uninitialized status is ELockNoteActive.
       
   128 // ---------------------------------------------------------------------------
       
   129 CLockAppStateControl::CLockAppStateControl( ) :
       
   130     iLockStatus( ELockNotActive),
       
   131     iWGEventGate( iEikonEnv->RootWin()),
       
   132     iEnvState( 0 )
       
   133     {
       
   134     // no implementation required
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // All lock state observers are created here.
       
   139 // ---------------------------------------------------------------------------
       
   140 void CLockAppStateControl::ConstructL( )
       
   141     {
       
   142     INFO( "CLockAppStateControl::ConstructL started" );
       
   143 
       
   144     // creates observer list
       
   145     BaseConstructL( );
       
   146 
       
   147     // localized resources are loaded
       
   148     TFileName resourceFile;
       
   149     resourceFile.Append( KRESOURCEFILE );
       
   150     BaflUtils::NearestLanguageFile( iEikonEnv->FsSession(), resourceFile );
       
   151     iResourceFileOffset = iEikonEnv->AddResourceFileL(resourceFile);
       
   152 
       
   153     // fetch power key configuration from feature manager
       
   154     FeatureManager::InitializeLibL( );
       
   155     iFeatureNoPowerkey = FeatureManager::FeatureSupported( KFeatureIdNoPowerkey );
       
   156     FeatureManager::UnInitializeLib( );
       
   157 
       
   158     // allow autoforwarding for the application (stacked bringforwards)
       
   159     iEikonEnv->SetAutoForwarding( ETrue );
       
   160 
       
   161     CLockAppKeyCaptureController::InitL( iEikonEnv->RootWin() );
       
   162 
       
   163     // Create second windowgroup for visibility gate
       
   164     CreateVisibilityGateWgL( );
       
   165 
       
   166     INFO_1( "CLockAppStateControl - EventGate WgID = %d", iWGEventGate.WindowGroupId() );
       
   167     INFO_1( "CLockAppStateControl - VisibilityGate WgID = %d", iWGVisibilityGate.WindowGroupId() );
       
   168 
       
   169     //
       
   170     // Construct Controls
       
   171     //
       
   172     iIdle = CLockAppIdleControl::NewL( *this );
       
   173     AddObserverL( iIdle ); // ownership is transfered
       
   174 
       
   175     iCurrentControl = iIdle;
       
   176     iCurrentControl->HandleActivateEventL( iEnvState );
       
   177 
       
   178     iKeyguard = CLockAppKeyguardControl::NewL( *this );
       
   179     AddObserverL( iKeyguard ); // ownership is transfered
       
   180     
       
   181     RDebug::Printf( "%s %s (%u) iDevicelock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iDevicelock );
       
   182     iDevicelock = CLockAppDevicelockControl::NewL( *this, iWGVisibilityGate ); 
       
   183     RDebug::Printf( "%s %s (%u) iDevicelock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iDevicelock );
       
   184     iDevicelock->ConnectToPhoneL( iWGVisibilityGate );
       
   185     RDebug::Printf( "%s %s (%u) iDevicelock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iDevicelock );
       
   186     AddObserverL( iDevicelock ); // ownership is transfered
       
   187 
       
   188     // Emergency support
       
   189     iLockEcsDetector = CLockAppEcsDetector::NewL( );
       
   190     AddObserverL( iLockEcsDetector ); // ownership is transfered
       
   191 
       
   192     // Lock state publisher
       
   193     CLockAppStatePublisher* lockPublisher = CLockAppStatePublisher::NewL( );
       
   194     AddObserverL( lockPublisher ); // ownership is transfered
       
   195 
       
   196     // PubSub observers
       
   197 		/* This is not used any more because screensavers are removed now
       
   198     iPSScreenSaverObserver = CLockAppPubSubObserver::NewL( this, KPSUidScreenSaver, KScreenSaverOn );
       
   199     */
       
   200     iPSTelephonyObserver = CLockAppPubSubObserver::NewL( this, KPSUidCtsyCallInformation, KCTsyCallState );
       
   201     iPSGripObserver = CLockAppPubSubObserver::NewL( this, KPSUidHWRM, KHWRMGripStatus );
       
   202 
       
   203     iPSFPSObserver = CLockAppPubSubObserver::NewL( this, KUidFpsCategory, KFpsAuthenticationKey );
       
   204 
       
   205     // Call bubble
       
   206     iIncallBubble = CAknIncallBubble::NewL( );
       
   207 
       
   208     ActivateL( );
       
   209 
       
   210     INFO( "CLockAppStateControl::ConstructL completed" );
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // Create visibility gate window group
       
   215 // ---------------------------------------------------------------------------
       
   216 void CLockAppStateControl::CreateVisibilityGateWgL( )
       
   217     {
       
   218     INFO( "CLockAppStateControl - CreateVisibilityGateL" );
       
   219 
       
   220     iWGVisibilityGate = RWindowGroup( iCoeEnv->WsSession( ) );
       
   221     User::LeaveIfError( iWGVisibilityGate.Construct( (TUint32) &iWGVisibilityGate ) );
       
   222 
       
   223     /* hide this window group from the app switcher */
       
   224     iWGVisibilityGate.SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront );
       
   225     iWGVisibilityGate.EnableReceiptOfFocus( EFalse );
       
   226 
       
   227     /*CApaWindowGroupName* wn = CApaWindowGroupName::NewLC( ws );
       
   228     wn->SetHidden( ETrue );
       
   229     wn->SetWindowGroupName( iWGVisibilityGate );
       
   230     CleanupStack::PopAndDestroy( wn );*/
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // This method should be called to enable keyguard.
       
   235 // ---------------------------------------------------------------------------
       
   236 TInt CLockAppStateControl::EnableKeyguardL( TBool aWithNote )
       
   237     {
       
   238     INFO_1( "CLockAppStateControl::EnableKeyguardL aWithNote= %d", aWithNote );
       
   239     TInt err = CheckIfLegal( ELockAppEnableKeyguard );
       
   240     if ( err == KErrNone && !iKeyguard->ActivationAllowedL( ) )
       
   241         {
       
   242         err = KErrPermissionDenied;
       
   243         }
       
   244     if ( err == KErrNone )
       
   245         {
       
   246         PostStatusChangeL( EKeyguardActive );
       
   247         __ASSERT_DEBUG( iLockStatus == EKeyguardActive, DoPanic(ELockIllegalState));
       
   248         INFO( "CLockAppStateControl - Keyguard Enabled" );
       
   249         if ( aWithNote )
       
   250             {
       
   251             iKeyguard->DisplayKeysLockedNote( );
       
   252             }
       
   253         }
       
   254     return err;
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 // This method should be called to disable keyguard.
       
   259 // ---------------------------------------------------------------------------
       
   260 TInt CLockAppStateControl::DisableKeyguardL( TBool aWithNote )
       
   261     {
       
   262     INFO_1( "CLockAppStateControl::DisableKeyguardL aWithNote= %d", aWithNote );
       
   263     TInt err = CheckIfLegal( ELockAppDisableKeyguard );
       
   264     if ( err == KErrNone && !iKeyguard->DeActivationAllowedL( ) )
       
   265         {
       
   266         err = KErrPermissionDenied;
       
   267         }
       
   268     if ( err == KErrNone )
       
   269         {
       
   270         PostStatusChangeL( ELockNotActive );
       
   271         __ASSERT_DEBUG( iLockStatus == ELockNotActive, DoPanic(ELockIllegalState));
       
   272         INFO( "CLockAppStateControl - Keyguard Disabled" );
       
   273         if ( aWithNote )
       
   274             {
       
   275             iKeyguard->DisplayKeysActiveNote( );
       
   276             }
       
   277         }
       
   278     return err;
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // This method should be called to enable device lock.
       
   283 // ---------------------------------------------------------------------------
       
   284 TInt CLockAppStateControl::EnableDevicelockL( TDevicelockReason aReason )
       
   285     {
       
   286     INFO_1( "CLockAppStateControl::EnableDevicelockL aReason= %d", aReason );
       
   287     RDebug::Printf( "%s %s (%u) iDevicelock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iDevicelock );
       
   288     TInt err = CheckIfLegal( ELockAppEnableDevicelock );
       
   289     if ( err == KErrNone && !iDevicelock->ActivationAllowedL( aReason ) )
       
   290         {
       
   291         err = KErrPermissionDenied;
       
   292         }
       
   293     if ( err == KErrNone )
       
   294         {
       
   295         PostStatusChangeL( EDevicelockActive );
       
   296         __ASSERT_DEBUG( iLockStatus == EDevicelockActive, DoPanic(ELockIllegalState));
       
   297         iDevicelock->SetLockingReason( aReason );
       
   298         INFO( "CLockAppStateControl - Devicelock Enabled" );
       
   299         }
       
   300     return err;
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // This method should be called to disable device lock.
       
   305 // ---------------------------------------------------------------------------
       
   306 TInt CLockAppStateControl::DisableDevicelockL( )
       
   307     {
       
   308     INFO_1( "CLockAppStateControl::DisableDevicelockL 1= %d", 1 );
       
   309     TInt err = CheckIfLegal( ELockAppDisableDevicelock );
       
   310     if ( err == KErrNone && !iDevicelock->DeActivationAllowedL( ) )
       
   311         {
       
   312         err = KErrPermissionDenied;
       
   313         }
       
   314     if ( err == KErrNone )
       
   315         {
       
   316         PostStatusChangeL( ELockNotActive );
       
   317         __ASSERT_DEBUG( iLockStatus == ELockNotActive, DoPanic(ELockIllegalState));
       
   318         INFO( "CLockAppStateControl - Devicelock Disabled" );
       
   319         }
       
   320     return err;
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // Checks if offer keyguard is allowed and if it is, offers to lock keyguard.
       
   325 // ---------------------------------------------------------------------------
       
   326 TInt CLockAppStateControl::OfferKeyguard( )
       
   327     {
       
   328     INFO_1( "CLockAppStateControl::OfferKeyguard 1= %d", 1 );
       
   329     TInt err = CheckIfLegal( ELockAppOfferKeyguard );
       
   330     if ( err == KErrNone )
       
   331         {
       
   332         __ASSERT_DEBUG( iLockStatus == ELockNotActive, DoPanic(ELockIllegalState));
       
   333         INFO( "CLockAppStateControl - OfferKeyguard" );
       
   334         iIdle->OfferKeyLock( );
       
   335         }
       
   336     return err;
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // Shows keys locked note if keyguard is enabled.
       
   341 // ---------------------------------------------------------------------------
       
   342 TInt CLockAppStateControl::ShowKeysLockedNote( )
       
   343     {
       
   344     INFO_1( "CLockAppStateControl::ShowKeysLockedNote 1= %d", 1 );
       
   345     TInt err = CheckIfLegal( ELockAppShowKeysLockedNote );
       
   346     if ( err == KErrNone )
       
   347         {
       
   348         __ASSERT_DEBUG( iLockStatus == EKeyguardActive, DoPanic(ELockIllegalState));
       
   349         INFO( "CLockAppStateControl - ShowKeysLockedNote" );
       
   350         iKeyguard->DisplayLockedNote( );
       
   351         }
       
   352     return err;
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // A method for returning the lock status.
       
   357 // ---------------------------------------------------------------------------
       
   358 TLockStatus CLockAppStateControl::LockStatus( ) const
       
   359     {
       
   360     INFO_1( "CLockAppStateControl::LockStatus iLockStatus= %d", iLockStatus );
       
   361     return iLockStatus;
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 // A method for returning the environment status bitmask.
       
   366 // ---------------------------------------------------------------------------
       
   367 TUint CLockAppStateControl::EnvironmentStatus( ) const
       
   368     {
       
   369     return iEnvState;
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // A method for executing different internal tests.
       
   374 // ---------------------------------------------------------------------------
       
   375 TInt CLockAppStateControl::ExecuteInternalTest( )
       
   376     {
       
   377 #ifdef _DEBUG
       
   378     return iLockEcsDetector->TestEcsNote( );
       
   379 #else
       
   380     return KErrNone;
       
   381 #endif
       
   382     }
       
   383 
       
   384 // ---------------------------------------------------------------------------
       
   385 // Number of owned UI controls (idle, keyguard, devicelock)
       
   386 // ---------------------------------------------------------------------------
       
   387 TInt CLockAppStateControl::CountComponentControls( ) const
       
   388     {
       
   389     return 3;
       
   390     }
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // Owned UI controls (idle, keyguard, devicelock)
       
   394 // ---------------------------------------------------------------------------
       
   395 CCoeControl* CLockAppStateControl::ComponentControl( TInt aIndex ) const
       
   396     {
       
   397     RDebug::Printf( "%s %s (%u) aIndex=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aIndex );
       
   398     switch ( aIndex )
       
   399         {
       
   400         case 0:
       
   401             return iIdle;
       
   402         case 1:
       
   403             return iKeyguard;
       
   404         case 2:
       
   405      		    RDebug::Printf( "%s %s (%u) iDevicelock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iDevicelock );
       
   406             return iDevicelock;
       
   407         default:
       
   408             return NULL;
       
   409         }
       
   410     }
       
   411 
       
   412 // ----------------------------------------------------------
       
   413 // Handle window-server events
       
   414 // ----------------------------------------------------------
       
   415 void CLockAppStateControl::HandleWsEventL( const TWsEvent& aEvent, CCoeControl* /*aDestination*/)
       
   416     {
       
   417     TInt type = aEvent.Type( );
       
   418     	RDebug::Printf( "%s %s (%u) type=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, type );
       
   419     switch ( type )
       
   420         {
       
   421         case KAknFullOrPartialForegroundLost: // partial or full fg lost
       
   422         case KAknFullOrPartialForegroundGained: // partial or full fg gained
       
   423             {
       
   424     				RDebug::Printf( "%s %s (%u) type=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, type );
       
   425             RWsSession& ws = iCoeEnv->WsSession( );
       
   426             TFileName windowName;
       
   427             TInt fwgid = ws.GetFocusWindowGroup( );
       
   428             ws.GetWindowGroupNameFromIdentifier( fwgid, windowName );
       
   429             INFO_3( "CLockAppStateControl::HandleWsEventL type: %d - FocusWg: %d %S", type, fwgid, &windowName);
       
   430             }
       
   431             break;
       
   432         case EEventKeyUp:
       
   433         case EEventKey:
       
   434         case EEventKeyDown:
       
   435         		{
       
   436         		RDebug::Printf( "%s %s (%u) EEventKey*=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EEventKeyDown );
       
   437         		TKeyEvent* aKeyEvent = aEvent.Key();
       
   438         		TKeyResponse response = OfferKeyEventL( *aKeyEvent, (TEventCode)type );
       
   439         		}
       
   440             break;
       
   441         default:
       
   442             break;
       
   443         }
       
   444     }
       
   445 
       
   446 // ---------------------------------------------------------------------------
       
   447 // From @c CAknAppUiBase. Overriden the parent method, because otherwise
       
   448 // the main lock state control would not receive the call, because is is not
       
   449 // window-owning control (=without window->not visible). The call is needed
       
   450 // because the main state control owns window-owning child controls.
       
   451 // ---------------------------------------------------------------------------
       
   452 void CLockAppStateControl::HandleResourceChange( TInt aType )
       
   453     {
       
   454     // these would not normally get handleresource call since they do not own window
       
   455 		RDebug::Printf( "%s %s (%u) aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aType );
       
   456 	if(iIdle)
       
   457 		iIdle->HandleResourceChange( aType );
       
   458 	if(iKeyguard)
       
   459 		iKeyguard->HandleResourceChange( aType );
       
   460 	if(iDevicelock)
       
   461 		iDevicelock->HandleResourceChange( aType );
       
   462     // call parent
       
   463     CCoeControl::HandleResourceChange( aType );
       
   464     }
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // Update the environment state variable with the event.
       
   468 // ---------------------------------------------------------------------------
       
   469 TBool CLockAppStateControl::HandleEnvironmentChange( TUint aEventMask, TBool aEnable )
       
   470     {
       
   471     // check if there will be a change
       
   472 
       
   473     if ( IsBitFieldSet( iEnvState, aEventMask ) != aEnable )
       
   474         {
       
   475         // set the bit-field
       
   476         SetBitField( iEnvState, aEventMask, aEnable );
       
   477         // notify current control
       
   478         __ASSERT_DEBUG( iCurrentControl, DoPanic(ELockIllegalState));
       
   479         iCurrentControl->HandleEnvironmentChange( iEnvState, aEventMask );
       
   480         // return true because the environment changed
       
   481         return ETrue;
       
   482         }
       
   483     return EFalse;
       
   484     }
       
   485 
       
   486 // ---------------------------------------------------------------------------
       
   487 // Handle all Central Repository observer callbacks.
       
   488 // ---------------------------------------------------------------------------
       
   489 void CLockAppStateControl::HandleCenRepNotify(TUid aCenRepUid, TUint32 aKeyId, TInt aValue )
       
   490     {
       
   491     	RDebug::Printf( "%s %s (%u) ???? Nothing done for aKeyId=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyId );
       
   492 
       
   493     INFO_3( "CLockAppStateControl::HandleCenRepNotify %d %d = %d", aCenRepUid.iUid, aKeyId, aValue );
       
   494     }
       
   495 
       
   496 // ---------------------------------------------------------------------------
       
   497 // Handle all Publish & Subscribe observer callbacks.
       
   498 // ---------------------------------------------------------------------------
       
   499 void CLockAppStateControl::HandlePubSubNotify(TUid aPubSubUid, TUint aKeyId, TInt aValue )
       
   500     {
       
   501     INFO_3( "CLockAppStateControl::HandlePubSubNotify %x %x = %d", aPubSubUid.iUid, aKeyId, aValue );
       
   502 		/* This is not used any more because screensavers are removed now
       
   503     INFO_3( "CLockAppStateControl::HandlePubSubNotify KPSUidScreenSaver=%x KPSUidCtsyCallInformation=%x KPSUidAiInformation=%x", KPSUidScreenSaver, KPSUidCtsyCallInformation, KPSUidAiInformation );
       
   504     INFO_3( "CLockAppStateControl::HandlePubSubNotify KPSUidHWRM=%x KHWRMGripStatus=%x KPSUidAiInformation=%x", KPSUidHWRM, KHWRMGripStatus, KPSUidAiInformation );
       
   505     if ( aPubSubUid == KPSUidScreenSaver )
       
   506         {
       
   507         switch ( aKeyId )
       
   508             {
       
   509             case KScreenSaverOn:
       
   510                 {
       
   511                 INFO_1("CLockAppStateControl::ScreenSaver - %d", (aValue > 0));
       
   512                 HandleEnvironmentChange( KLockAppEnvScreenSaverOn, (aValue > 0) );
       
   513                 }
       
   514                 break;
       
   515             default:
       
   516                 break;
       
   517             }
       
   518         }
       
   519     else if ( aPubSubUid == KPSUidCtsyCallInformation )
       
   520         {
       
   521         switch ( aKeyId )
       
   522             {
       
   523             case KCTsyCallState:
       
   524                 {
       
   525                 PrintCallState( aValue );
       
   526                 HandleEnvironmentChange( KLockAppEnvPhonecallOngoing, (aValue > EPSCTsyCallStateNone) );
       
   527                 }
       
   528                 break;
       
   529             default:
       
   530                 break;
       
   531             }
       
   532         }
       
   533     else if ( aPubSubUid == KPSUidAiInformation )	// ActiveIdle
       
   534             {
       
   535             switch ( aKeyId )
       
   536                 {
       
   537                 case KActiveIdleState:
       
   538                     {
       
   539                     INFO_1("CLockAppStateControl::ActiveIdle - %d", (aValue == EPSAiForeground));
       
   540                     HandleEnvironmentChange( KLockAppEnvIdleOnForeground, (aValue == EPSAiForeground) );
       
   541                     }
       
   542                     break;
       
   543                 default:
       
   544                     break;
       
   545                 }
       
   546             }
       
   547     else if ( aPubSubUid == KPSUidHWRM )
       
   548         {
       
   549         switch ( aKeyId )
       
   550             {
       
   551             case KHWRMGripStatus:
       
   552                 {
       
   553                 INFO_1("CLockAppStateControl::Grip - %d", aValue );
       
   554                 HandleEnvironmentChange( KLockAppEnvGrip, (aValue == EPSHWRMGripOpen) );
       
   555                 }
       
   556                 break;
       
   557             default:
       
   558                 break;
       
   559             }
       
   560         }
       
   561     else if ( aPubSubUid == KUidFpsCategory )
       
   562         {
       
   563         switch ( aKeyId )
       
   564             {
       
   565             case KFpsAuthenticationKey:
       
   566                 {
       
   567                 INFO_1("CLockAppStateControl::Grip - %d", aValue );
       
   568                 #define EAuthenticationSuccess 1
       
   569                 HandleEnvironmentChange( KLockAppEnvFPS, (aValue == EAuthenticationSuccess) );
       
   570                 }
       
   571                 break;
       
   572             default:
       
   573                 break;
       
   574             }
       
   575         }
       
   576     */
       
   577     }
       
   578 
       
   579 // ---------------------------------------------------------------------------
       
   580 // All keyevents should go trough here.
       
   581 // ---------------------------------------------------------------------------
       
   582 TKeyResponse CLockAppStateControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   583     {
       
   584     	RDebug::Printf( "%s %s (%u) iDevicelock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iDevicelock );
       
   585     	RDebug::Printf( "%s %s (%u) aKeyEvent.iCode=%x aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyEvent.iCode, aType );
       
   586     TKeyResponse keyResponse = PreCheckKeyEvents( aKeyEvent, aType );
       
   587     if ( keyResponse == EKeyWasNotConsumed )
       
   588         {
       
   589         if ( aKeyEvent.iRepeats == 0 )
       
   590             {
       
   591             // handle only without the repeats
       
   592             INFO_3("KeyEvent %d, %d, %d", aType, aKeyEvent.iCode, aKeyEvent.iScanCode );
       
   593             __ASSERT_DEBUG( iCurrentControl, DoPanic(ELockIllegalState));
       
   594             keyResponse = iCurrentControl->OfferKeyEventL( aKeyEvent, aType );
       
   595             }
       
   596         else
       
   597             {
       
   598             // set consumed which are repeated
       
   599             keyResponse = EKeyWasConsumed;
       
   600             }
       
   601         }
       
   602 
       
   603     return keyResponse;
       
   604     }
       
   605 
       
   606 // ---------------------------------------------------------------------------
       
   607 // From @c CLockAppObserverList. The main state control is the first
       
   608 // to handle the lock state changes, locks/unlocks the phone depending
       
   609 // on the state change.
       
   610 // ---------------------------------------------------------------------------
       
   611 void CLockAppStateControl::HandleLockStatusChangedL( TLockStatus aLockStatus )
       
   612     {    
       
   613     __ASSERT_DEBUG( iCurrentControl, DoPanic(ELockIllegalState));
       
   614     INFO_1("CLockAppStateControl::HandleLockStatusChangedL - %d", aLockStatus);
       
   615     iCurrentControl->HandleDeActivateEventL( iEnvState );
       
   616 
       
   617     switch ( aLockStatus )
       
   618         {
       
   619         case ELockNotActive:
       
   620             {
       
   621             iCurrentControl = iIdle;
       
   622             MuteSounds( EFalse );
       
   623             BringForward( EFalse );
       
   624             }
       
   625             break;
       
   626         case EKeyguardActive:
       
   627             {
       
   628             iCurrentControl = iKeyguard;
       
   629             MuteSounds( ETrue );
       
   630             BringForward( ETrue );
       
   631             }
       
   632             break;
       
   633         case EDevicelockActive:
       
   634             {
       
   635        	    RDebug::Printf( "%s %s (%u) iDevicelock=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iDevicelock );
       
   636             iCurrentControl = iDevicelock;
       
   637             MuteSounds( ETrue );
       
   638             BringForward( ETrue );
       
   639             }
       
   640             break;
       
   641         default:
       
   642         		INFO_1("CLockAppStateControl::HandleLockStatusChangedL - ???? aLockStatus=%d", aLockStatus);
       
   643             DoPanic( ELockUnknownValue );
       
   644             break;
       
   645         }
       
   646 
       
   647     __ASSERT_DEBUG( iCurrentControl, DoPanic(ELockIllegalState));
       
   648     iCurrentControl->HandleActivateEventL( iEnvState );
       
   649 
       
   650     // finally we update the value (only place were changing the status is allowed)
       
   651     iLockStatus = aLockStatus;
       
   652     }
       
   653 
       
   654 // ---------------------------------------------------------------------------
       
   655 // Check if requested transition is valid.
       
   656 // ---------------------------------------------------------------------------
       
   657 TInt CLockAppStateControl::CheckIfLegal( TLockAppMessageReason aReason )
       
   658     {
       
   659     INFO_1("CLockAppStateControl::CheckIfLegal aReason=%d", aReason);
       
   660     INFO_1("CLockAppStateControl::CheckIfLegal iLockStatus=%d", iLockStatus);
       
   661     switch ( aReason )
       
   662         {
       
   663         case ELockAppEnableKeyguard:
       
   664             {
       
   665            	RDebug::Printf( "%s %s (%u) ELockAppEnableKeyguard iLockStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus );
       
   666             switch ( iLockStatus )
       
   667                 {
       
   668                 case ELockNotActive:
       
   669                     if ( !CKeyLockPolicyApi::KeyguardAllowed() )
       
   670                         return KErrPermissionDenied;
       
   671                     else
       
   672                         return KErrNone;
       
   673                 case EKeyguardActive:
       
   674                     return KErrAlreadyExists;
       
   675                 case EDevicelockActive:
       
   676                     return KErrPermissionDenied;
       
   677                 }
       
   678             }
       
   679             break;
       
   680         case ELockAppDisableKeyguard:
       
   681             {
       
   682            	RDebug::Printf( "%s %s (%u) ELockAppDisableKeyguard iLockStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus );
       
   683             switch ( iLockStatus )
       
   684                 {
       
   685                 case ELockNotActive:
       
   686                     return KErrAlreadyExists;
       
   687                 case EKeyguardActive:
       
   688                     return KErrNone;
       
   689                 case EDevicelockActive:
       
   690                     return KErrPermissionDenied;
       
   691                 }
       
   692             }
       
   693             break;
       
   694         case ELockAppEnableDevicelock:
       
   695             {
       
   696            	RDebug::Printf( "%s %s (%u) ELockAppEnableDevicelock iLockStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus );
       
   697             switch ( iLockStatus )
       
   698                 {
       
   699                 case ELockNotActive:
       
   700                     return KErrNone;
       
   701                 case EKeyguardActive:
       
   702                     return KErrNone;
       
   703                 case EDevicelockActive:
       
   704                     return KErrAlreadyExists;
       
   705                 }
       
   706             }
       
   707             break;
       
   708         case ELockAppDisableDevicelock:
       
   709             {
       
   710            	RDebug::Printf( "%s %s (%u) ELockAppDisableDevicelock iLockStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus );
       
   711             switch ( iLockStatus )
       
   712                 {
       
   713                 case ELockNotActive:
       
   714                     return KErrAlreadyExists;
       
   715                 case EKeyguardActive:
       
   716                     return KErrPermissionDenied;
       
   717                 case EDevicelockActive:
       
   718                     return KErrNone;
       
   719                 }
       
   720             }
       
   721             break;
       
   722         case ELockAppOfferKeyguard:
       
   723             {
       
   724            	RDebug::Printf( "%s %s (%u) ELockAppOfferKeyguard iLockStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus );
       
   725             switch ( iLockStatus )
       
   726                 {
       
   727                 case ELockNotActive:
       
   728                     return KErrNone;
       
   729                 case EKeyguardActive:
       
   730                     return KErrPermissionDenied;
       
   731                 case EDevicelockActive:
       
   732                     return KErrPermissionDenied;
       
   733                 }
       
   734             }
       
   735             break;
       
   736         case ELockAppShowKeysLockedNote:
       
   737             {
       
   738            	RDebug::Printf( "%s %s (%u) ELockAppShowKeysLockedNote iLockStatus=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus );
       
   739             switch ( iLockStatus )
       
   740                 {
       
   741                 case ELockNotActive:
       
   742                     return KErrPermissionDenied;
       
   743                 case EKeyguardActive:
       
   744                     return KErrNone;
       
   745                 case EDevicelockActive:
       
   746                     return KErrPermissionDenied;
       
   747                 }
       
   748             }
       
   749             break;
       
   750         }
       
   751     return KErrPermissionDenied;
       
   752     }
       
   753 
       
   754 // ---------------------------------------------------------------------------
       
   755 // Prescreen key events for special cases before giving them to child controls
       
   756 // ---------------------------------------------------------------------------
       
   757 TKeyResponse CLockAppStateControl::PreCheckKeyEvents(const TKeyEvent& aKeyEvent, TEventCode aType )
       
   758     {
       
   759     	RDebug::Printf( "%s %s (%u) aKeyEvent.iCode=%x aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyEvent.iCode, aType );
       
   760     TKeyResponse keyResponse = EKeyWasNotConsumed;
       
   761     // power key always turns the lights on
       
   762     CheckForPowerKeyLights( aKeyEvent, aType );
       
   763     if ( iLockEcsDetector->EcsNoteOnScreen( ) )
       
   764         {
       
   765         // the key events are fully handled by the emergency
       
   766         // detector when emergency note is shown
       
   767         keyResponse = EKeyWasConsumed;
       
   768         }
       
   769     else
       
   770         {
       
   771         if ( CheckForPhoneKeys( aKeyEvent, aType ) )
       
   772             {
       
   773             keyResponse = EKeyWasConsumed;
       
   774             }
       
   775         else if ( aKeyEvent.iCode == EKeyLeftShift || aKeyEvent.iCode == EKeyRightShift )
       
   776             {
       
   777             // eat these modifier events as they just cause problems elsewhere
       
   778             keyResponse = EKeyWasConsumed;
       
   779             }
       
   780         }
       
   781     return keyResponse;
       
   782     }
       
   783 
       
   784 // ---------------------------------------------------------------------------
       
   785 // Checks if power key has been pressed and inform the sysap accordingly.
       
   786 // ---------------------------------------------------------------------------
       
   787 void CLockAppStateControl::CheckForPowerKeyLights( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   788     {
       
   789     // only handle power key when keys are locked
       
   790     	RDebug::Printf( "%s %s (%u) aKeyEvent.iCode=%x aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyEvent.iCode, aType );
       
   791     	RDebug::Printf( "%s %s (%u) iLockStatus=%x ELockNotActive=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus, ELockNotActive );
       
   792     if ( iLockStatus != ELockNotActive )
       
   793         {
       
   794     		RDebug::Printf( "%s %s (%u) iFeatureNoPowerkey=%x EStdKeyDevice2=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iFeatureNoPowerkey, EStdKeyDevice2 );
       
   795         if ( (aType == EEventKey && aKeyEvent.iRepeats == 0) || (aType == EEventKeyDown && aKeyEvent.iScanCode == EStdKeyDevice2) ) // Power key
       
   796             {
       
   797             // If power key pressed, tell SysAp about if
       
   798             if ( (aKeyEvent.iScanCode == EStdKeyDevice2 && aType == EEventKeyDown) || (iFeatureNoPowerkey && aKeyEvent.iCode == EKeyNo) )
       
   799                 {
       
   800                 // normal power key event
       
   801                 RDebug::Printf( "%s %s (%u) EEikKeyLockPowerKeyPressed=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iFeatureNoPowerkey );
       
   802                 SendMessageToSysAp( EEikKeyLockPowerKeyPressed );
       
   803                 if ( iFeatureNoPowerkey )
       
   804                     {
       
   805                 		RDebug::Printf( "%s %s (%u) EEikKeyLockLightsOnRequest=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EEikKeyLockLightsOnRequest );
       
   806                     // end key as power key needs additional info (ugly solution)
       
   807                     SendMessageToSysAp( EEikKeyLockLightsOnRequest );
       
   808                     }
       
   809                 }
       
   810             }
       
   811         }
       
   812     }
       
   813 
       
   814 // ---------------------------------------------------------------------------
       
   815 // Checks if green or red key has been pressed and forward it to phone
       
   816 // in case there is a phone call ongoing.
       
   817 // ---------------------------------------------------------------------------
       
   818 TBool CLockAppStateControl::CheckForPhoneKeys( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   819     {
       
   820     	RDebug::Printf( "%s %s (%u) aKeyEvent.iCode=%x aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aKeyEvent.iCode, aType );
       
   821 #ifndef RD_GLOBALWG_PRIORITY_CHANGE
       
   822     // only handle phone keys when locked and phonecall ongoing
       
   823     	RDebug::Printf( "%s %s (%u) iLockStatus=%x ELockNotActive=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iLockStatus, ELockNotActive );
       
   824     if ( iLockStatus != ELockNotActive )
       
   825         {
       
   826         if ( aKeyEvent.iScanCode == EStdKeyYes || aKeyEvent.iScanCode == EStdKeyNo )
       
   827             {
       
   828             if ( IsBitFieldSet( iEnvState, KLockAppEnvPhonecallOngoing ) )	// TODO what about video-call
       
   829                 {
       
   830                 // send Green and Red keys to phoneapp's windowgroup
       
   831                 INFO( "CLockAppStateControl::CheckForPhoneKeys - SendKeyToPhoneApp");
       
   832                 SendKeyToPhoneApp( aKeyEvent, aType );
       
   833                 return ETrue;
       
   834                 }
       
   835             }
       
   836         }
       
   837 #endif // !RD_GLOBALWG_PRIORITY_CHANGE
       
   838     return EFalse;
       
   839     }
       
   840 
       
   841 // ---------------------------------------------------------------------------
       
   842 // Brings foreground/background the root window.
       
   843 // ---------------------------------------------------------------------------
       
   844 void CLockAppStateControl::BringForward(TBool aForeground )
       
   845     {
       
   846     	RDebug::Printf( "%s %s (%u) aForeground=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aForeground );
       
   847     if ( aForeground )
       
   848         {
       
   849         INFO_4( "CLockAppStateControl::BringForward(1) STA - EvWG(%d,%d) ViWG(%d,%d)",
       
   850                 iWGEventGate.OrdinalPosition(), iWGEventGate.OrdinalPriority(),
       
   851                 iWGVisibilityGate.OrdinalPosition(), iWGVisibilityGate.OrdinalPriority());
       
   852         // not sure if these cause flush in WindowServer
       
   853         iWGVisibilityGate.SetOrdinalPosition( 0, ECoeWinPriorityAlwaysAtFront + KGlobalWindowPriority_LockVisibilityGate );
       
   854         iWGEventGate.SetOrdinalPosition( 0, ECoeWinPriorityAlwaysAtFront + KGlobalWindowPriority_LockVisibilityGate );
       
   855         iEikonEnv->BringForwards( ETrue, ECoeWinPriorityAlwaysAtFront + KGlobalWindowPriority_KeyLock );
       
   856         /*if ( iIncallBubble )
       
   857             {
       
   858             iIncallBubble->SetIncallBubbleAllowedInIdleL( ETrue );
       
   859             }*/
       
   860         }
       
   861     else
       
   862         {
       
   863         INFO_4( "CLockAppStateControl::BringForward(0) STA - EvWG(%d,%d) ViWG(%d,%d)",
       
   864                 iWGEventGate.OrdinalPosition(), iWGEventGate.OrdinalPriority(),
       
   865                 iWGVisibilityGate.OrdinalPosition(), iWGVisibilityGate.OrdinalPriority());
       
   866 
       
   867         // not sure if these cause flush in WindowServer
       
   868         iWGVisibilityGate.SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront );
       
   869 		iWGEventGate.SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront );
       
   870         iEikonEnv->BringForwards( EFalse );
       
   871         /*if ( iIncallBubble )
       
   872             {
       
   873             iIncallBubble->SetIncallBubbleAllowedInIdleL( EFalse );
       
   874             }*/
       
   875         }
       
   876 
       
   877     INFO_4( "CLockAppStateControl::BringForward END - EvWG(%d,%d) ViWG(%d,%d)",
       
   878             iWGEventGate.OrdinalPosition(), iWGEventGate.OrdinalPriority(),
       
   879             iWGVisibilityGate.OrdinalPosition(), iWGVisibilityGate.OrdinalPriority());
       
   880     }
       
   881 
       
   882 // ---------------------------------------------------------------------------
       
   883 // Mute key sounds when phone is locked.
       
   884 // ---------------------------------------------------------------------------
       
   885 void CLockAppStateControl::MuteSounds(TBool aMuteSounds )
       
   886     {
       
   887     	RDebug::Printf( "%s %s (%u) aMuteSounds=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aMuteSounds );
       
   888     if ( iSoundsMuted != aMuteSounds )
       
   889         {
       
   890         if ( aMuteSounds )
       
   891             {
       
   892             TRAPD(err, iAvkonAppUiBase->KeySounds()->PushContextL(R_AVKON_SILENT_SKEY_LIST))
       
   893             if ( !err )
       
   894                 {
       
   895                 iAvkonAppUiBase->KeySounds()->BringToForeground();
       
   896                 iAvkonAppUiBase->KeySounds()->LockContext();
       
   897                 iSoundsMuted = ETrue;
       
   898                 }
       
   899             }
       
   900         else
       
   901             {
       
   902             iAvkonAppUiBase->KeySounds()->ReleaseContext();
       
   903             iAvkonAppUiBase->KeySounds()->PopContext();
       
   904             iSoundsMuted = EFalse;
       
   905             }
       
   906         }
       
   907     }
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 // Print out call state.
       
   911 // ---------------------------------------------------------------------------
       
   912 void CLockAppStateControl::PrintCallState( TInt aValue )
       
   913     {
       
   914     RDebug::Printf( "%s %s (%u) aValue=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aValue );
       
   915     switch ( aValue )
       
   916         {
       
   917         case EPSCTsyCallStateUninitialized:
       
   918             INFO("CLockAppStateControl::PrintCallState - Uninitialized")
       
   919             break;
       
   920         case EPSCTsyCallStateNone:
       
   921             INFO("CLockAppStateControl::PrintCallState - None")
       
   922             break;
       
   923         case EPSCTsyCallStateAlerting:
       
   924             INFO("CLockAppStateControl::PrintCallState - Alerting")
       
   925             break;
       
   926         case EPSCTsyCallStateRinging:
       
   927             INFO("CLockAppStateControl::PrintCallState - Ringing")
       
   928             break;
       
   929         case EPSCTsyCallStateDialling:
       
   930             INFO("CLockAppStateControl::PrintCallState - Dialling")
       
   931             break;
       
   932         case EPSCTsyCallStateAnswering:
       
   933             INFO("CLockAppStateControl::PrintCallState - Answering")
       
   934             break;
       
   935         case EPSCTsyCallStateDisconnecting:
       
   936             INFO("CLockAppStateControl::PrintCallState - Disconnecting")
       
   937             break;
       
   938         case EPSCTsyCallStateConnected:
       
   939             INFO("CLockAppStateControl::PrintCallState - Connected")
       
   940             break;
       
   941         case EPSCTsyCallStateHold:
       
   942             INFO("CLockAppStateControl::PrintCallState - Hold")
       
   943             break;
       
   944         default:
       
   945             break;
       
   946         }
       
   947     }
       
   948 
       
   949 // END OF FILE