uifw/AknGlobalUI/OldStyleNotif/Src/aknkeylocknotifier.cpp
changeset 0 2f259fa3e83a
child 5 aabf2c525e0f
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Avkon KeyLock Notifier
       
    15 *
       
    16 */
       
    17 
       
    18 #include "AknKeyLockNotifier.h"
       
    19 
       
    20 #include <aknnotpi.rsg>
       
    21 #include <eikenv.h>
       
    22 #include <eikappui.h>
       
    23 #include <apgwgnam.h>
       
    24 #include <aknsoundsystem.h>
       
    25 #include <avkon.rsg>
       
    26 #include <eikkeysound.h>
       
    27 #include <bautils.h>
       
    28 #include <featmgr.h>
       
    29 
       
    30 #include <AknTasHook.h>
       
    31 #include <AknUtils.h>
       
    32 #include <eikcba.h>
       
    33 #include <aknnotecontrol.h>
       
    34 #include <aknlayoutscalable_avkon.cdl.h>
       
    35 
       
    36 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h>
       
    37 #include <avkondomainpskeys.h> // KPSUidAvkonDomain, KAknKeyguardStatus, TAknKeyguardStatus
       
    38 #include <startupdomainpskeys.h> // KStartupSecurityCodeQueryStatus
       
    39 #include <coreapplicationuisdomainpskeys.h> // KCoreAppUIsAutolockStatus
       
    40 #include <AknNotifySignature.h>
       
    41 #include "AknCapServerEntry.h"
       
    42 #include <aknglobalpopupprioritycontroller.h>
       
    43 #include "GlobalWindowPriorities.h"
       
    44 #include <keylockpolicyapi.h>
       
    45 #include <ScreensaverInternalPSKeys.h>
       
    46 
       
    47 #include <PSVariables.h>   // Property values
       
    48 #include <coreapplicationuisdomainpskeys.h>
       
    49 #include <startupdomainpskeys.h>
       
    50 #include <ctsydomainpskeys.h>
       
    51 #include <bafindf.h>
       
    52 #include "AknNotifyPlugin.hrh"
       
    53 
       
    54 
       
    55 
       
    56 #ifdef _DEBUG
       
    57     #define TRACES(x)   x
       
    58 #else
       
    59     #define TRACES(x)
       
    60 #endif
       
    61 
       
    62 /** Autolock application UID. */
       
    63 const TUid KAutolockUid = { 0x100059B5 };
       
    64 
       
    65 /** SysAp application UID. */
       
    66 const TUid KSysApUid    = { 0x100058F3 };
       
    67 
       
    68 const TInt KAknObserverListGranularity = 4;
       
    69 
       
    70 /** Timeout for the "offer keylock" note. */
       
    71 const TInt KAknOfferKeyLockTimeout = 6000000; // 6sec
       
    72 
       
    73 /** Command ID for note focus lost. */
       
    74 const TInt KNoteCmdFocusLost = 3100;
       
    75 
       
    76 // Asterisk key code for the keylock.
       
    77 const TUint KAknAsterisk = '*';
       
    78 const TUint KAknChineseAsterisk = 0xFF0A;
       
    79 
       
    80 // Timeout defined in Keylock UI spesification.
       
    81 // Custom value since Avkon note TTimeout values
       
    82 // don't support 1 second timeout
       
    83 const TInt KKeyLockCustomShortTimeout = 1000000;
       
    84 
       
    85 // Timeout for display locked note
       
    86 const TInt KKeyLockDisplayLockedTimeout = 3000000;
       
    87 
       
    88 _LIT( KRESOURCEFILE, "\\resource\\aknnotpi.rsc" );
       
    89 _LIT_SECURITY_POLICY_C1( KWritePolicy, ECapabilityWriteDeviceData );
       
    90 
       
    91 
       
    92 /**
       
    93  *  CAknKeylockScreenSaverObserver captures primary keys
       
    94  *  from screensaver when screen saver is active.
       
    95  *
       
    96  *  @lib   aknoldstylenotif.lib
       
    97  *  @since 3.2
       
    98  */
       
    99 NONSHARABLE_CLASS( CAknKeylockScreenSaverObserver ): public CActive
       
   100     {
       
   101 public:
       
   102 
       
   103     /**
       
   104     * Creates instance of the CAknKeylockScreenSaverObserver class.
       
   105     *
       
   106     * @param aWindowGroup application window group used to capture primary keys
       
   107     * @return Returns the instance just created.
       
   108     */
       
   109     static CAknKeylockScreenSaverObserver* NewL( RWindowGroup& aWindowGroup );
       
   110 
       
   111     /**
       
   112     * Destructor.
       
   113     */
       
   114     ~CAknKeylockScreenSaverObserver();
       
   115 
       
   116 public:
       
   117 
       
   118     /**
       
   119     * Starts asynchronic listening KUidCurrentCall event
       
   120     *
       
   121     * @return KErrNone: if no errors
       
   122     * @return KErrInUse: if already listening
       
   123     */
       
   124     TInt Start();
       
   125 
       
   126     /**
       
   127     * Stops asynchronic listening KUidAutolockStatus event
       
   128     */
       
   129     void Stop();
       
   130 
       
   131 public:
       
   132 
       
   133     /**
       
   134      *  Method handles the lock state changes.
       
   135      *
       
   136      * @param aStatus The new lock state
       
   137      */
       
   138     void SetLockStatus( TBool aKeylockEnabled, TBool aAutolockEnabled );
       
   139 
       
   140 private: // constructors
       
   141 
       
   142     /**
       
   143     * C++ default constructor.
       
   144     *
       
   145     * @param aAppUi (pointer to autolock appui)
       
   146     */
       
   147     CAknKeylockScreenSaverObserver( RWindowGroup& aWindowGroup );
       
   148 
       
   149     /**
       
   150     * Symbian OS constructor.
       
   151     */
       
   152     void ConstructL();
       
   153 
       
   154 private: // from CActive
       
   155 
       
   156     /** @see CActive::RunL() */
       
   157     void RunL();
       
   158 
       
   159     /** @see CActive::DoCancel() */
       
   160     void DoCancel();
       
   161 
       
   162 private:
       
   163 
       
   164     /**
       
   165     * Used to capture primary keys defined in keylocking policies
       
   166     */
       
   167     void CapturePrimaryKeys( TBool aCapture );
       
   168 
       
   169 private: // data
       
   170 
       
   171     // screen saver on property
       
   172     RProperty  iScreenSaverActiveProperty;
       
   173 
       
   174     // if screensaver is active or not
       
   175     TBool iScreenSaverActive;
       
   176 
       
   177     // if primary keys have been captured
       
   178     TBool iCaptured;
       
   179 
       
   180     // locking states
       
   181     TBool iKeylockEnabled;
       
   182     TBool iAutolockEnabled;
       
   183 
       
   184     // left softkey capture
       
   185     TInt iLeftSoftKey;
       
   186 
       
   187     // a reference to application window group
       
   188     RWindowGroup& iWindowGroup;
       
   189 
       
   190     // keylockpolicy support (not owned)
       
   191     CKeyLockPolicyApi* iUnlockPolicyApi;
       
   192 
       
   193     // keylockpolicy support (not owned)
       
   194     CKeyLockPolicyApi* iDevicelockPolicyApi;
       
   195 
       
   196     // primary key captures
       
   197     RArray<TUint> iPrimaryKeyCaptures;
       
   198     };
       
   199 
       
   200 // ===========================================================================
       
   201 // class CAknKeylockScreenSaverObserver
       
   202 // ===========================================================================
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // Constructs a new entry with given values.
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 CAknKeylockScreenSaverObserver* CAknKeylockScreenSaverObserver::NewL(
       
   209     RWindowGroup& aWindowGroup )
       
   210     {
       
   211     CAknKeylockScreenSaverObserver* self =
       
   212         new (ELeave) CAknKeylockScreenSaverObserver( aWindowGroup );
       
   213     CleanupStack::PushL( self );
       
   214     self->ConstructL();
       
   215     CleanupStack::Pop( self );
       
   216     return self;
       
   217     }
       
   218 
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // Destructor
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 CAknKeylockScreenSaverObserver::~CAknKeylockScreenSaverObserver()
       
   225     {
       
   226     Cancel();
       
   227 
       
   228     // Close the property handle.
       
   229     iScreenSaverActiveProperty.Close();
       
   230 
       
   231     // Release key captures.
       
   232     CapturePrimaryKeys( EFalse );
       
   233 
       
   234     // Delete policies.
       
   235     delete iUnlockPolicyApi;
       
   236     delete iDevicelockPolicyApi;
       
   237     }
       
   238 
       
   239 
       
   240 // ---------------------------------------------------------------------------
       
   241 // Starts listening to the KScreenSaverOn event.
       
   242 // ---------------------------------------------------------------------------
       
   243 //
       
   244 TInt CAknKeylockScreenSaverObserver::Start()
       
   245     {
       
   246     if ( IsActive() )
       
   247         {
       
   248         return KErrInUse;
       
   249         }
       
   250     iStatus = KRequestPending;
       
   251     iScreenSaverActiveProperty.Subscribe( iStatus );
       
   252     SetActive();
       
   253 
       
   254     return KErrNone;
       
   255     }
       
   256 
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // Stops listening to the KScreenSaverOn event.
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CAknKeylockScreenSaverObserver::Stop()
       
   263     {
       
   264     if ( !IsActive() )
       
   265         {
       
   266         return;
       
   267         }
       
   268     Cancel();
       
   269     iScreenSaverActiveProperty.Cancel();
       
   270     }
       
   271 
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // C++ constructor
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 CAknKeylockScreenSaverObserver::CAknKeylockScreenSaverObserver(
       
   278     RWindowGroup& aWindowGroup )
       
   279     : CActive( 0 ),
       
   280       iScreenSaverActive( EFalse ),
       
   281       iCaptured( EFalse ),
       
   282       iKeylockEnabled( EFalse ),
       
   283       iAutolockEnabled( EFalse ),
       
   284       iLeftSoftKey( NULL ),
       
   285       iWindowGroup( aWindowGroup )
       
   286     {
       
   287     }
       
   288 
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // Second phase constructor.
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CAknKeylockScreenSaverObserver::ConstructL()
       
   295     {
       
   296     // Add this active object to the scheduler.
       
   297     CActiveScheduler::Add( this );
       
   298     User::LeaveIfError( iScreenSaverActiveProperty.Attach( KPSUidScreenSaver,
       
   299                                                            KScreenSaverOn ) );
       
   300 
       
   301     // We need policies to poll primary keys.
       
   302     iUnlockPolicyApi = CKeyLockPolicyApi::NewL( EPolicyDeactivateKeyguard );
       
   303     if ( !iUnlockPolicyApi->HasConfiguration() )
       
   304         {
       
   305         delete iUnlockPolicyApi;
       
   306         iUnlockPolicyApi = NULL;
       
   307         }
       
   308 
       
   309     // we need policies to poll primary keys
       
   310     iDevicelockPolicyApi = CKeyLockPolicyApi::NewL( EPolicyDevicelockQuery );
       
   311     if ( !iDevicelockPolicyApi->HasConfiguration() )
       
   312         {
       
   313         delete iDevicelockPolicyApi;
       
   314         iDevicelockPolicyApi = NULL;
       
   315         }
       
   316     }
       
   317 
       
   318 
       
   319 // ---------------------------------------------------------------------------
       
   320 // From base class CActive.
       
   321 // Handles change in the screen saver state.
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CAknKeylockScreenSaverObserver::RunL()
       
   325     {
       
   326     if ( iKeylockEnabled || iAutolockEnabled )
       
   327         {
       
   328         // Resubscribe before processing new value to prevent missing updates.
       
   329         Start();
       
   330         }
       
   331 
       
   332     TInt screenSaverState;
       
   333     iScreenSaverActiveProperty.Get( screenSaverState );
       
   334     // Primary keys are captured from screensaver when screensaver
       
   335     // is the top most application.
       
   336     if ( screenSaverState > NULL )
       
   337         {
       
   338          __ASSERT_DEBUG( !iCaptured,
       
   339                          Panic( EAknPanicKeyLockObserverAlreadyExists ) );
       
   340         iScreenSaverActive = ETrue;
       
   341         CapturePrimaryKeys( ETrue );
       
   342         }
       
   343     else
       
   344         {
       
   345         // If screensaver is disabled, stop capturing primary key events.
       
   346         if ( iScreenSaverActive )
       
   347             {
       
   348             CapturePrimaryKeys( EFalse );
       
   349             }
       
   350         iScreenSaverActive = EFalse;
       
   351         }
       
   352     }
       
   353 
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // Set the lock status.
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CAknKeylockScreenSaverObserver::SetLockStatus( TBool aKeylockEnabled,
       
   360                                                     TBool aAutolockEnabled )
       
   361     {
       
   362     iKeylockEnabled  = aKeylockEnabled;
       
   363     iAutolockEnabled = aAutolockEnabled;
       
   364 
       
   365     if ( iKeylockEnabled || iAutolockEnabled )
       
   366         {
       
   367         // Start observing screensaver activation.
       
   368         Start();
       
   369         }
       
   370     else
       
   371         {
       
   372         if ( iScreenSaverActive )
       
   373             {
       
   374             CapturePrimaryKeys( EFalse );
       
   375             }
       
   376         // Screensaver is only observed when keylock is enabled.
       
   377         Stop();
       
   378         }
       
   379     }
       
   380 
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // Capture or uncapture primary keys.
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 void CAknKeylockScreenSaverObserver::CapturePrimaryKeys( TBool aCapture )
       
   387     {
       
   388     if ( aCapture )
       
   389         {
       
   390         if ( iScreenSaverActive && !iCaptured )
       
   391             {
       
   392             if ( iKeylockEnabled && !iAutolockEnabled )
       
   393                 {
       
   394                 iCaptured = ETrue;
       
   395                 // If no unlocking policy has been defined,
       
   396                 // the default primary key is the left soft key.
       
   397                 if ( !iUnlockPolicyApi )
       
   398                     {
       
   399                     // Capture LSK (starts unlock prosess, capturing
       
   400                     // bypasses screensaver)
       
   401                     iLeftSoftKey = iWindowGroup.CaptureKey( EKeyDevice0, 0, 0 );
       
   402                     }
       
   403                 else
       
   404                     {
       
   405                     iPrimaryKeyCaptures.Reset();
       
   406                     TUint32 index( 0 );
       
   407                     TUint32 primaryKey( 0 );
       
   408                     TUint32 secondaryKey( 0 );
       
   409                     while ( iUnlockPolicyApi->GetKeyCombination( index,
       
   410                                                                  primaryKey,
       
   411                                                                  secondaryKey ) == KErrNone )
       
   412                         {
       
   413                         iPrimaryKeyCaptures.Append(
       
   414                             iWindowGroup.CaptureKeyUpAndDowns( primaryKey, 0, 0 ) );
       
   415                         index++;
       
   416                         }
       
   417                     }
       
   418                 }
       
   419             else
       
   420                 {
       
   421                 if ( iKeylockEnabled && iAutolockEnabled )
       
   422                     {
       
   423                     iCaptured = ETrue;
       
   424                     // If no devicelock query policy has been defined,
       
   425                     // the default primary key is the left soft key.
       
   426                     if ( !iDevicelockPolicyApi )
       
   427                         {
       
   428                         // Capture LSK (starts unlock prosess,
       
   429                         // capturing bypasses screensaver).
       
   430                         iLeftSoftKey = iWindowGroup.CaptureKey( EKeyDevice0, 0, 0 );
       
   431                         }
       
   432                     else
       
   433                         {
       
   434                         iPrimaryKeyCaptures.Reset();
       
   435                         TUint32 index( 0 );
       
   436                         TUint32 primaryKey( 0 );
       
   437                         TUint32 secondaryKey( 0 );
       
   438                         while ( iDevicelockPolicyApi->GetKeyCombination( index, primaryKey, secondaryKey ) == KErrNone )
       
   439                             {
       
   440                             iPrimaryKeyCaptures.Append(
       
   441                                 iWindowGroup.CaptureKeyUpAndDowns( primaryKey, 0, 0 ) );
       
   442                             index++;
       
   443                             }
       
   444                         }
       
   445                     }
       
   446                 }
       
   447             }
       
   448         }
       
   449     else
       
   450         {
       
   451         if (iCaptured)
       
   452             {
       
   453             if (iLeftSoftKey > 0)
       
   454                 {
       
   455                 iWindowGroup.CancelCaptureKey(iLeftSoftKey); 
       
   456                 }
       
   457             iLeftSoftKey = 0;
       
   458             
       
   459             if (iPrimaryKeyCaptures.Count() > 0)
       
   460                 {
       
   461                 for (TInt x = 0; x < iPrimaryKeyCaptures.Count(); x++)
       
   462                     {
       
   463                     iWindowGroup.CancelCaptureKeyUpAndDowns(iPrimaryKeyCaptures[x]);
       
   464                     }
       
   465                 iPrimaryKeyCaptures.Reset();
       
   466                 }
       
   467             
       
   468             iCaptured = EFalse;
       
   469             }
       
   470         }
       
   471     }
       
   472 
       
   473 
       
   474 // ---------------------------------------------------------------------------
       
   475 // From base class CActive.
       
   476 // Cancels event listening.
       
   477 // ---------------------------------------------------------------------------
       
   478 //
       
   479 void CAknKeylockScreenSaverObserver::DoCancel()
       
   480     {
       
   481     iScreenSaverActiveProperty.Cancel();
       
   482     }
       
   483 
       
   484 
       
   485 // ===========================================================================
       
   486 // class CAknLockedNote.
       
   487 // ===========================================================================
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // C++ constructor.
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 CAknLockedNote::CAknLockedNote( TInt& aLocked,
       
   494                                 MEikCommandObserver* aCommandObserver )
       
   495     : CAknSleepingNote( aCommandObserver ),
       
   496       iLocked( aLocked )
       
   497     {
       
   498     AKNTASHOOK_ADD( this, "CAknLockedNote" );
       
   499     }
       
   500 
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // From base class CAknSleepingNote.
       
   504 // Handles a dialog button press for the button with ID aCommand.
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 TBool CAknLockedNote::OkToExitL( TInt aCommand )
       
   508     {
       
   509     iLocked = EFalse;
       
   510     if ( iCommandObserver )
       
   511         {
       
   512         iCommandObserver->ProcessCommandL( aCommand );
       
   513         }
       
   514     return ETrue;
       
   515     }
       
   516 
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 // Destructor
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 CAknLockedNote::~CAknLockedNote()
       
   523     {
       
   524     AKNTASHOOK_REMOVE();
       
   525     iLocked = EFalse;
       
   526     }
       
   527 
       
   528 
       
   529 // ---------------------------------------------------------------------------
       
   530 // Cancels the note.
       
   531 // ---------------------------------------------------------------------------
       
   532 //
       
   533 void CAknLockedNote::CancelNote()
       
   534     {
       
   535     if ( iTimer )
       
   536         {
       
   537         iTimer->Cancel();
       
   538         }
       
   539     ExitSleepingDialog();
       
   540     iLocked = EFalse;
       
   541     }
       
   542 
       
   543 
       
   544 // ---------------------------------------------------------------------------
       
   545 // From base class CEikDialog.
       
   546 // Handles focus change event.
       
   547 // ---------------------------------------------------------------------------
       
   548 //
       
   549 void CAknLockedNote::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   550     {
       
   551     if ( !IsFocused() && iCommandObserver )
       
   552         {
       
   553         TRAP_IGNORE( iCommandObserver->ProcessCommandL( KNoteCmdFocusLost ) )
       
   554         }
       
   555     }
       
   556 
       
   557 
       
   558 // ---------------------------------------------------------------------------
       
   559 // From base class CEikDialog.
       
   560 // For future use.
       
   561 // ---------------------------------------------------------------------------
       
   562 //
       
   563 void CAknLockedNote::CEikDialog_Reserved_1()
       
   564     {
       
   565     }
       
   566 
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 // From base class CEikDialog.
       
   570 // For future use.
       
   571 // ---------------------------------------------------------------------------
       
   572 //
       
   573 void CAknLockedNote::CEikDialog_Reserved_2()
       
   574     {
       
   575     }
       
   576 
       
   577 
       
   578 // ---------------------------------------------------------------------------
       
   579 // From base class CAknNoteDialog.
       
   580 // For future use.
       
   581 // ---------------------------------------------------------------------------
       
   582 //
       
   583 void CAknLockedNote::CAknNoteDialog_Reserved()
       
   584     {
       
   585     }
       
   586 
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // From base class CAknSleepingNote.
       
   590 // For future use.
       
   591 // ---------------------------------------------------------------------------
       
   592 //
       
   593 void CAknLockedNote::CAknSleepingNote_Reserved()
       
   594     {
       
   595     }
       
   596 
       
   597 
       
   598 // ===========================================================================
       
   599 // class CAknSleepingNote
       
   600 // ===========================================================================
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // C++ constructor.
       
   604 // ---------------------------------------------------------------------------
       
   605 //
       
   606 CAknSleepingNote::CAknSleepingNote( MEikCommandObserver* aCommandObserver ) :
       
   607     iCommandObserver( aCommandObserver )
       
   608     {
       
   609     AKNTASHOOK_ADD( this, "CAknSleepingNote" );
       
   610     }
       
   611 
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // Second-phase constructor.
       
   615 // ---------------------------------------------------------------------------
       
   616 //
       
   617 void CAknSleepingNote::ConstructSleepingNoteL( TInt aResourceId )
       
   618     {
       
   619     iResourceId = aResourceId;
       
   620     CAknNoteDialog::ConstructSleepingDialogL( aResourceId );
       
   621 
       
   622     // Construct now rather than in PreLayoutDynInit.
       
   623     delete iTimer;
       
   624     iTimer = NULL;
       
   625     iTimer = CPeriodic::NewL( 0 );
       
   626     }
       
   627 
       
   628 
       
   629 // ---------------------------------------------------------------------------
       
   630 // Displays the note.
       
   631 // ---------------------------------------------------------------------------
       
   632 //
       
   633 TInt CAknSleepingNote::ShowNote( const TInt aTimeout, const TTone aTone )
       
   634     {
       
   635     TRAP_IGNORE(AknGlobalPopupPriorityController::SetPopupPriorityL( *this, KGlobalWindowPriority_KeyLock ));
       
   636     iTimeoutInMicroseconds = aTimeout;
       
   637     iTone = aTone;
       
   638     return RouseSleepingDialog();
       
   639     }
       
   640 
       
   641 
       
   642 // ---------------------------------------------------------------------------
       
   643 // From base class CEikDialog.
       
   644 // Handles a dialog button press for the button with ID aCommand.
       
   645 // ---------------------------------------------------------------------------
       
   646 //
       
   647 TBool CAknSleepingNote::OkToExitL( TInt aCommand )
       
   648     {
       
   649     if ( iCommandObserver )
       
   650         {
       
   651         iCommandObserver->ProcessCommandL( aCommand );
       
   652         }
       
   653     return ETrue;
       
   654     }
       
   655 
       
   656 
       
   657 // ---------------------------------------------------------------------------
       
   658 // From base class CAknNoteDialog.
       
   659 // Updates the note animation on skin change event.
       
   660 // ---------------------------------------------------------------------------
       
   661 //
       
   662 void CAknSleepingNote::HandleResourceChange( TInt aType )
       
   663     {
       
   664     if ( aType == KAknsMessageSkinChange )
       
   665         {
       
   666         TInt animationRes( 0 );
       
   667         switch ( iResourceId )
       
   668             {
       
   669             case R_KEYLOCK_NOTE_KEYLOCKED:
       
   670                 {
       
   671                 animationRes = R_QGN_NOTE_INFO_ANIM;
       
   672                 break;
       
   673                 }
       
   674             case R_KEYLOCK_NOTE_UNLOCK_CONFIRM:
       
   675                 {
       
   676                 animationRes = R_QGN_NOTE_QUERY_ANIM;
       
   677                 break;
       
   678                 }
       
   679             case R_KEYLOCK_NOTE_UNLOCK_ASTERISK:
       
   680                 {
       
   681                 animationRes = R_QGN_NOTE_INFO_ANIM;
       
   682                 break;
       
   683                 }
       
   684             case R_KEYLOCK_NOTE_LOCK_ON:
       
   685                 {
       
   686                 animationRes = R_QGN_NOTE_KEYGUARD_LOCKED_ANIM;
       
   687                 break;
       
   688                 }
       
   689             case R_KEYLOCK_NOTE_LOCK_OFF:
       
   690                 {
       
   691                 animationRes = R_QGN_NOTE_KEYGUARD_OPEN_ANIM;
       
   692                 break;
       
   693                 }
       
   694             case R_KEYLOCK_OFFER_LOCK_NOTE:
       
   695                 {
       
   696                 animationRes = R_QGN_NOTE_QUERY_ANIM;
       
   697                 break;
       
   698                 }
       
   699             default:
       
   700                 {
       
   701                 break;
       
   702                 }
       
   703             } // end of switch
       
   704 
       
   705         if ( animationRes )
       
   706             {
       
   707             CAknNoteControl* ctrl = NULL;
       
   708             ctrl = NoteControl();
       
   709             if ( ctrl )
       
   710                 {
       
   711                 TRAP_IGNORE( ctrl->SetAnimationL( animationRes ) );
       
   712                 }
       
   713             }
       
   714         }
       
   715 
       
   716     CAknNoteDialog::HandleResourceChange( aType );
       
   717     }
       
   718 
       
   719 
       
   720 // ---------------------------------------------------------------------------
       
   721 // From base class CEikDialog.
       
   722 // For future use.
       
   723 // ---------------------------------------------------------------------------
       
   724 //
       
   725 void CAknSleepingNote::CEikDialog_Reserved_1()
       
   726     {
       
   727     }
       
   728 
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // From base class CEikDialog.
       
   732 // For future use.
       
   733 // ---------------------------------------------------------------------------
       
   734 //
       
   735 void CAknSleepingNote::CEikDialog_Reserved_2()
       
   736     {
       
   737     }
       
   738 
       
   739 
       
   740 // ---------------------------------------------------------------------------
       
   741 // From base class CAknNoteDialog.
       
   742 // For future use.
       
   743 // ---------------------------------------------------------------------------
       
   744 //
       
   745 void CAknSleepingNote::CAknNoteDialog_Reserved()
       
   746     {
       
   747     }
       
   748 
       
   749 
       
   750 // ---------------------------------------------------------------------------
       
   751 // For future use.
       
   752 // ---------------------------------------------------------------------------
       
   753 //
       
   754 void CAknSleepingNote::CAknSleepingNote_Reserved()
       
   755     {
       
   756     }
       
   757 
       
   758 
       
   759 /**
       
   760  *  CAknEcsNote implements the emergency number display during keylock.
       
   761  *
       
   762  *  @lib   aknoldstylenotif.lib
       
   763  *  @since 3.2
       
   764  */
       
   765 NONSHARABLE_CLASS( CAknEcsNote ): public CAknSleepingNote
       
   766     {
       
   767 public:
       
   768 
       
   769     /**
       
   770     * Constructor.
       
   771     */
       
   772     CAknEcsNote( MEikCommandObserver* aCommandObserver );
       
   773 
       
   774     /**
       
   775     * API to set the emergency number to be displayed
       
   776     *
       
   777     * @param  aMatchedNumber  Text to display (e.g. "112" )
       
   778     */
       
   779     void SetEmergencyNumber( const TDesC& aMatchedNumber );
       
   780 
       
   781     /**
       
   782     * Dismisses the sleeping note.
       
   783     */
       
   784     void SleepNote();
       
   785 
       
   786 public:
       
   787 
       
   788     /** Is note currently displayed. */
       
   789     TBool iNoteOnScreen;
       
   790     };
       
   791 
       
   792 
       
   793 // ---------------------------------------------------------------------------
       
   794 // C++ constructor.
       
   795 // ---------------------------------------------------------------------------
       
   796 //
       
   797 CAknEcsNote::CAknEcsNote( MEikCommandObserver* aCommandObserver ) :
       
   798     CAknSleepingNote( aCommandObserver )
       
   799     {
       
   800     }
       
   801 
       
   802 
       
   803 // ---------------------------------------------------------------------------
       
   804 // Sets the emergency number to be displayed.
       
   805 // ---------------------------------------------------------------------------
       
   806 //
       
   807 void CAknEcsNote::SetEmergencyNumber( const TDesC& aMatchedNumber )
       
   808     {
       
   809     TRect mainPane;
       
   810     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EPopupParent,
       
   811                                        mainPane );
       
   812 
       
   813     TAknLayoutRect popupNoteWindow;
       
   814     AknLayoutUtils::TAknCbaLocation cbaLocation(
       
   815         AknLayoutUtils::CbaLocation() );
       
   816 
       
   817     TInt variety( 0 );
       
   818     if ( cbaLocation == AknLayoutUtils::EAknCbaLocationRight )
       
   819         {
       
   820         variety = 5;
       
   821         }
       
   822     else if ( cbaLocation == AknLayoutUtils::EAknCbaLocationLeft )
       
   823         {
       
   824         variety = 8;
       
   825         }
       
   826     else
       
   827         {
       
   828         variety = 2;
       
   829         }
       
   830 
       
   831     popupNoteWindow.LayoutRect(
       
   832         mainPane,
       
   833         AknLayoutScalable_Avkon::popup_note_window( variety ) );
       
   834     TAknLayoutText textRect;
       
   835     textRect.LayoutText( popupNoteWindow.Rect(),
       
   836                          AknLayoutScalable_Avkon::popup_note_window_t5( 2 ) );
       
   837 
       
   838     // Size of a temporary buffer that contains new lines, spaces and
       
   839     // emergency number for a note.
       
   840     TBuf16<KAknEcsMaxMatchingLength+80> number;
       
   841     number.Append( '\n' );
       
   842     number.Append( '\n' );
       
   843 
       
   844     TInt spaceCharWidthInPixels = textRect.Font()->CharWidthInPixels( ' ' );
       
   845     if ( spaceCharWidthInPixels < 1 )
       
   846         {
       
   847         // Avoid divide by zero situation in case the space character
       
   848         // would have zero width.
       
   849         spaceCharWidthInPixels = 1;
       
   850         }
       
   851 
       
   852     TInt length = ( textRect.TextRect().Width() -
       
   853                     textRect.Font()->TextWidthInPixels( aMatchedNumber ) ) /
       
   854                   spaceCharWidthInPixels;
       
   855 
       
   856     const TInt matchedNumberLength = aMatchedNumber.Length();
       
   857     const TInt numberLength = number.Length();
       
   858     const TInt numberMaxLength = number.MaxLength();
       
   859 
       
   860     if ( numberLength + length + matchedNumberLength > numberMaxLength )
       
   861         {
       
   862         // To make sure that buffer overflow does not happen.
       
   863         length = numberMaxLength - numberLength - matchedNumberLength;
       
   864         }
       
   865     for ( TInt i = 0; i < length; i++ )
       
   866         {
       
   867         number.Append( ' ' );
       
   868         }
       
   869 
       
   870     number.Append( aMatchedNumber );
       
   871     TRAP_IGNORE( SetTextL( number ) );
       
   872     }
       
   873 
       
   874 
       
   875 // ---------------------------------------------------------------------------
       
   876 // Makes the note go to sleep.
       
   877 // ---------------------------------------------------------------------------
       
   878 //
       
   879 void CAknEcsNote::SleepNote()
       
   880     {
       
   881     if ( iNoteOnScreen )
       
   882         {
       
   883         // Causes flicker to other notes if called when note is not on screen.
       
   884         ExitSleepingDialog();
       
   885         }
       
   886     iNoteOnScreen = EFalse;
       
   887     }
       
   888 
       
   889 
       
   890 // ===========================================================================
       
   891 // class CAknKeyLockControl
       
   892 // ===========================================================================
       
   893 
       
   894 
       
   895 // ---------------------------------------------------------------------------
       
   896 // Default constructor.
       
   897 // ---------------------------------------------------------------------------
       
   898 //
       
   899 CAknKeyLockControl::CAknKeyLockControl() :
       
   900     iConsumeNextEventKey( EFalse )
       
   901     {
       
   902     AKNTASHOOK_ADD( this, "CAknKeyLockControl" );
       
   903     }
       
   904 
       
   905 
       
   906 // ---------------------------------------------------------------------------
       
   907 // C++ constructor.
       
   908 // ---------------------------------------------------------------------------
       
   909 //
       
   910 CAknKeyLockControl::CAknKeyLockControl( CAknKeyLockNotifierSubject* aNotif ) :
       
   911     iNotif( aNotif )
       
   912     {
       
   913     AKNTASHOOK_ADD( this, "CAknKeyLockControl" );
       
   914     }
       
   915 
       
   916 
       
   917 // ---------------------------------------------------------------------------
       
   918 // Destructor
       
   919 // ---------------------------------------------------------------------------
       
   920 //
       
   921 CAknKeyLockControl::~CAknKeyLockControl()
       
   922     {
       
   923     AKNTASHOOK_REMOVE();
       
   924     // We implicitely trust that Eikon env exists
       
   925     // (though in practice it does not make the
       
   926     // difference as this destructor is really never called...)
       
   927     RWindowGroup& groupWin = iEikonEnv->RootWin();
       
   928 
       
   929     groupWin.CancelCaptureKey( iEditKeyL );
       
   930     groupWin.CancelCaptureKey( iEditKeyR );
       
   931 
       
   932     AknGlobalPopupPriorityController::RemovePopupPriority( *this );
       
   933     FeatureManager::UnInitializeLib();
       
   934     iEikonEnv->EikAppUi()->RemoveFromStack( this );
       
   935     iStatusProperty.Close();
       
   936 
       
   937     delete iConfirmationNote;
       
   938     delete iConfirmationNoteAsterisk;
       
   939     delete iLockedNote;
       
   940     delete iKeypadUnlockedNote;
       
   941     delete iKeypadLockedNote;
       
   942     delete iEcsDetector;
       
   943     delete iKeyLockCba;
       
   944     delete iOfferLockNote;
       
   945     delete iEcsNote; // Ecs change
       
   946     delete iKeylockApi;
       
   947     delete iKeylockScreenSaverObserver;
       
   948     }
       
   949 
       
   950 
       
   951 // ---------------------------------------------------------------------------
       
   952 // Second phase construction.
       
   953 // ---------------------------------------------------------------------------
       
   954 //
       
   955 void CAknKeyLockControl::ConstructL()
       
   956     {
       
   957     TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::ConstructL ")); )
       
   958 
       
   959     FeatureManager::InitializeLibL();
       
   960     iFeatureKeypadNoSlider =
       
   961         FeatureManager::FeatureSupported( KFeatureIdKeypadNoSlider );
       
   962     iFeatureNoPowerkey =
       
   963         FeatureManager::FeatureSupported( KFeatureIdNoPowerkey );
       
   964 
       
   965     // Keyguard switch support.
       
   966     CRepository* repository = CRepository::NewLC( KCRUidLockConf );
       
   967     TInt hardwareSupport( 0 );
       
   968     repository->Get( KKeyguardHardwareConf, hardwareSupport );
       
   969     CleanupStack::PopAndDestroy( repository );
       
   970     iHardwareSupport = TLockHardware( hardwareSupport );
       
   971 
       
   972     CreateWindowL();
       
   973     Window().SetSize( TSize( 0, 0 ) );
       
   974     ActivateL();
       
   975 
       
   976     AknGlobalPopupPriorityController::SetPopupPriorityL(
       
   977         *this, KGlobalWindowPriority_KeyLock );
       
   978 
       
   979     // To allow HW keys for key filter even if keypad is locked.
       
   980     iEikonEnv->EikAppUi()->AddToStackL( this,
       
   981                                         ECoeStackPriorityEnvironmentFilter - 1,
       
   982                                         ECoeStackFlagRefusesFocus );
       
   983 
       
   984     iEcsNote = new (ELeave) CAknEcsNote( this );
       
   985     iEcsNote->ConstructSleepingNoteL( R_AVKON_EMERGENCY_CALL_NOTE );
       
   986     iEcsNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
   987 
       
   988     iOfferLockNote = new (ELeave) CAknLockedNote( iOfferLockEnabled, this );
       
   989     iOfferLockNote->ConstructSleepingNoteL( R_KEYLOCK_OFFER_LOCK_NOTE );
       
   990     iOfferLockNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
   991 
       
   992     TBool touchEnabled( AknLayoutUtils::PenEnabled() );
       
   993 
       
   994 	TBool hasSlider(iHardwareSupport != EKeyguardDefaultHardware);
       
   995 
       
   996     iKeyLockCba = CEikButtonGroupContainer::NewL(
       
   997                     CEikButtonGroupContainer::ECba,
       
   998                     CEikButtonGroupContainer::EHorizontal,
       
   999                     this,
       
  1000                     (touchEnabled&&hasSlider) ? R_AVKON_SOFTKEYS_EMPTY :
       
  1001                                    R_KEYLOCK_SOFTKEYS_UNLOCK_EMPTY );
       
  1002 
       
  1003     iKeyLockCba->ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(
       
  1004                 ECoeWinPriorityNeverAtFront );
       
  1005 
       
  1006     TRect screenRect;
       
  1007     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
  1008     iKeyLockCba->SetBoundingRect( screenRect );
       
  1009     iKeyLockCba->MakeVisible( EFalse );
       
  1010 
       
  1011     // Construct the "keypad locked" note.
       
  1012     iKeypadLockedNote = new (ELeave) CAknSleepingNote();
       
  1013     iKeypadLockedNote->ConstructSleepingNoteL(
       
  1014         touchEnabled ? R_KEYLOCK_NOTE_DISPLAY_LOCK_ON_TOUCH :
       
  1015                        R_KEYLOCK_NOTE_LOCK_ON );
       
  1016     iKeypadLockedNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
  1017     iKeypadLockedNote->PublishDialogL( EAknKeysLockedNote );
       
  1018 
       
  1019     // Construct the "keypad unlocked" note.
       
  1020     iKeypadUnlockedNote = new (ELeave) CAknSleepingNote();
       
  1021     iKeypadUnlockedNote->ConstructSleepingNoteL(
       
  1022         touchEnabled ? R_KEYLOCK_NOTE_DISPLAY_LOCK_OFF_TOUCH :
       
  1023                        R_KEYLOCK_NOTE_LOCK_OFF );
       
  1024     iKeypadUnlockedNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
  1025     iKeypadUnlockedNote->PublishDialogL( EAknKeysReleasedNote );
       
  1026 
       
  1027     // Construct the locked note.
       
  1028     iLockedNote = new (ELeave) CAknLockedNote( iLockedNoteDisplayed );
       
  1029     if ( touchEnabled )
       
  1030         {
       
  1031         iLockedNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_DISPLAY_LOCKED_TOUCH );
       
  1032         }
       
  1033     else
       
  1034         {
       
  1035         switch ( iHardwareSupport )
       
  1036             {
       
  1037             case EKeyguardOnePositionSwitch:
       
  1038             case EKeyguardTwoPositionSwitch:
       
  1039                 {
       
  1040                 iLockedNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_KEYLOCKED_SWITCH );
       
  1041                 break;
       
  1042                 }
       
  1043             case EKeyguardDefaultHardware:
       
  1044             default:
       
  1045                 {
       
  1046                 iLockedNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_KEYLOCKED );
       
  1047                 break;
       
  1048                 }
       
  1049             }
       
  1050         }
       
  1051     iLockedNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
  1052 
       
  1053     if ( !(touchEnabled&&hasSlider) )
       
  1054         {
       
  1055         // These are created only if touch is not enabled, since
       
  1056         // currently in touch devices the keylock state is controlled
       
  1057         // with switch.
       
  1058 
       
  1059         // Construct the confirmation note for unlocking keypad.
       
  1060         iConfirmationNote = new (ELeave) CAknLockedNote( iUnlockConfirmation );
       
  1061         iConfirmationNote->ConstructSleepingNoteL( R_KEYLOCK_NOTE_UNLOCK_CONFIRM );
       
  1062         iConfirmationNote->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
  1063 
       
  1064         if ( iFeatureKeypadNoSlider )
       
  1065             {
       
  1066             // Show note "Now press *".
       
  1067             // Note is shown when user has pressed "Unlock" when
       
  1068             // keypad is in locked state
       
  1069             iConfirmationNoteAsterisk =
       
  1070                 new (ELeave) CAknLockedNote( iUnlockConfirmation );
       
  1071             
       
  1072             TInt fileExist = KErrNone;
       
  1073             
       
  1074             CFindFileByType* pFindFile = new (ELeave) CFindFileByType(iEikonEnv->FsSession());
       
  1075             fileExist = pFindFile->FindFirst(UNLOCKKEY_MIF_FILE_UNICODE, _L(""), KNullUid);
       
  1076             delete pFindFile;
       
  1077             
       
  1078             if (KErrNone != fileExist)
       
  1079                 {
       
  1080                 iConfirmationNoteAsterisk->ConstructSleepingNoteL(
       
  1081                         R_KEYLOCK_NOTE_UNLOCK_ASTERISK);
       
  1082                 }
       
  1083             else
       
  1084                 {
       
  1085                 iConfirmationNoteAsterisk->ConstructSleepingNoteL(
       
  1086                         R_KEYLOCK_NOTE_UNLOCK_ASTERISK_ANIM_UNTOUCH);
       
  1087                 }
       
  1088           
       
  1089             iConfirmationNoteAsterisk->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition( 0, 2 );
       
  1090             }
       
  1091         }
       
  1092 
       
  1093     // Emergency call support.
       
  1094     iEcsDetector = CAknEcsDetector::NewL();
       
  1095     iEcsDetector->SetObserver( this );
       
  1096 
       
  1097     // As edit keys (shifts) shouldn't be passed to application as
       
  1098     // EEventKey, capture those here.
       
  1099     RWindowGroup& groupWin = iEikonEnv->RootWin();
       
  1100     iEditKeyL = groupWin.CaptureKey( EKeyLeftShift, 0, 0 );
       
  1101     iEditKeyR = groupWin.CaptureKey( EKeyRightShift, 0, 0 );
       
  1102 
       
  1103     // Create keylock policy component if an unlocking policy has been defined.
       
  1104     iKeylockApi = CKeyLockPolicyApi::NewL( EPolicyDeactivateKeyguard );
       
  1105     if ( !iKeylockApi->HasConfiguration() )
       
  1106         {
       
  1107         // Keylock API not initialized.
       
  1108         delete iKeylockApi;
       
  1109         iKeylockApi = NULL;
       
  1110         }
       
  1111 
       
  1112     iKeylockScreenSaverObserver =
       
  1113         CAknKeylockScreenSaverObserver::NewL( groupWin );
       
  1114 
       
  1115     // Define P&S key that is used to publish the keyguard status.
       
  1116     RProperty::Define( KPSUidAvkonDomain,
       
  1117                        KAknKeyguardStatus,
       
  1118                        RProperty::EInt,
       
  1119                        TSecurityPolicy( TSecurityPolicy::EAlwaysPass ),
       
  1120                        KWritePolicy );
       
  1121 
       
  1122     iStatusProperty.Attach( KPSUidAvkonDomain, KAknKeyguardStatus );
       
  1123     iStatusProperty.Set( EKeyguardNotActive );
       
  1124     }
       
  1125 
       
  1126 
       
  1127 // ---------------------------------------------------------------------------
       
  1128 // Enable key lock.
       
  1129 // ---------------------------------------------------------------------------
       
  1130 //
       
  1131 void CAknKeyLockControl::EnableKeylock( TBool aShowNote )
       
  1132     {
       
  1133     TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::EnableKeylock %d"), aShowNote); )
       
  1134 
       
  1135     // Policy can be used to disable support for keyguard.
       
  1136     if ( !iAutolockEnabled && !CKeyLockPolicyApi::KeyguardAllowed() )
       
  1137         {
       
  1138         // Keylock Disabled
       
  1139         return;
       
  1140         }
       
  1141     // Keylock Enabled
       
  1142     iKeylockScreenSaverObserver->SetLockStatus( ETrue, iAutolockEnabled );
       
  1143     if ( iOfferLockEnabled )
       
  1144         {
       
  1145         iOfferLockNote->CancelNote();
       
  1146         }
       
  1147 
       
  1148     // Update keyguard status to P&S system.
       
  1149     iStatusProperty.Set( iAutolockEnabled ? EKeyguardAutolockEmulation :
       
  1150                                             EKeyguardLocked );
       
  1151     iKeyLockEnabled = ETrue;
       
  1152 
       
  1153     if ( !iAutolockEnabled )
       
  1154         {
       
  1155         SendMessageToSysAp( EEikKeyLockEnabled );
       
  1156         }
       
  1157 
       
  1158     if ( !AknLayoutUtils::PenEnabled() || iHardwareSupport == EKeyguardDefaultHardware)
       
  1159         {
       
  1160         iKeyLockCba->MakeVisible( ETrue );
       
  1161         }
       
  1162     else
       
  1163         {
       
  1164         iKeyLockCba->MakeVisible( EFalse );
       
  1165         }
       
  1166 
       
  1167     TBool areWeInIdleState = CEikStatusPaneBase::Current()->PaneCapabilities(
       
  1168         TUid::Uid( EEikStatusPaneUidClock ) ).IsInCurrentLayout();
       
  1169 
       
  1170     if ( areWeInIdleState )
       
  1171         { // idle state
       
  1172         static_cast<CEikCba*>(
       
  1173             iKeyLockCba->ButtonGroup() )->SetSkinBackgroundId(
       
  1174                 KAknsIIDQsnBgAreaControlIdle );
       
  1175         }
       
  1176     else
       
  1177         {
       
  1178         static_cast<CEikCba*>(
       
  1179             iKeyLockCba->ButtonGroup() )->SetSkinBackgroundId(
       
  1180                 KAknsIIDQsnBgAreaControl );
       
  1181         }
       
  1182 
       
  1183     AknGlobalPopupPriorityController::ShowPopup( *this, ETrue );
       
  1184 
       
  1185     if ( aShowNote )
       
  1186         {
       
  1187         DisplayLockedNote();
       
  1188         }
       
  1189 
       
  1190     if ( !AknLayoutUtils::PenEnabled() || iHardwareSupport == EKeyguardDefaultHardware)
       
  1191         {
       
  1192         ShowKeylockCba();
       
  1193         }
       
  1194     else
       
  1195         {
       
  1196         // Set the window screen sized and make it transparent.
       
  1197         TRect screenRect;
       
  1198         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
  1199         Window().SetSize( screenRect.Size() );
       
  1200         Window().SetRequiredDisplayMode( EColor16MA );
       
  1201         TInt err = Window().SetTransparencyAlphaChannel();
       
  1202         if ( err == KErrNone )
       
  1203             {
       
  1204              Window().SetBackgroundColor( ~0 );
       
  1205             }
       
  1206         }
       
  1207 
       
  1208 		// in case Telephone-app is topmost, then the user is confused because he sees but can't use it.
       
  1209 		// therefore it's required to hide it, by sending to background. ETMA-7M8A2Y 20090105
       
  1210 		if ( AknLayoutUtils::PenEnabled() )
       
  1211        	{ 		
       
  1212 	   			TApaTaskList apaTaskList(CCoeEnv::Static()->WsSession());
       
  1213 	   			#define KPhoneAppUid TUid::Uid(0x100058B3)
       
  1214 
       
  1215      			TApaTask apaTask = apaTaskList.FindApp(KPhoneAppUid);
       
  1216      			if (apaTask.Exists())
       
  1217          	{
       
  1218 				 		#if defined(_DEBUG)
       
  1219 				 			RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::EnableKeylock() Bring phone to background"));
       
  1220 				 		#endif
       
  1221          		// Bring phone to background
       
  1222          		apaTask.SendToBackground();
       
  1223          	}
       
  1224 				}
       
  1225 
       
  1226     // Start capturing system keys.
       
  1227     CaptureSystemKeys();
       
  1228 
       
  1229     // Capture all pointer events.
       
  1230     CapturePointerEvents();
       
  1231 
       
  1232     iEcsDetector->ConnectToEventSource();
       
  1233 
       
  1234     if ( iNotif )
       
  1235         {
       
  1236         iNotif->NotifyStatusChange( EKeyLockEnabled );
       
  1237         }
       
  1238 
       
  1239     if ( !iSoundsMuted )
       
  1240         {
       
  1241         CAknAppUiBase* appUi = iAvkonAppUiBase;
       
  1242         TRAPD( err, appUi->KeySounds()->PushContextL( R_AVKON_SILENT_SKEY_LIST ) );
       
  1243         if ( !err )
       
  1244             {
       
  1245             appUi->KeySounds()->BringToForeground();
       
  1246             appUi->KeySounds()->LockContext();
       
  1247             iSoundsMuted = ETrue;
       
  1248             }
       
  1249         }
       
  1250 
       
  1251     // Basically this cannot fail so we ignore return code.
       
  1252     static_cast<CAknNotifierAppServerAppUi*>(
       
  1253         iEikonEnv->EikAppUi() )->SuppressAppSwitching( ETrue );
       
  1254 
       
  1255     // Method HandleResourceChangeL with parameter KAknInternalFSWClose cannot
       
  1256     // leave, but we trap it in just in case.
       
  1257     TRAP_IGNORE( static_cast<CAknCapAppServerAppUi*>( iEikonEnv->EikAppUi() )->HandleResourceChangeL(
       
  1258             KAknInternalFSWClose ); );
       
  1259     }
       
  1260 
       
  1261 
       
  1262 // ---------------------------------------------------------------------------
       
  1263 // Disable key lock.
       
  1264 // ---------------------------------------------------------------------------
       
  1265 //
       
  1266 void CAknKeyLockControl::DisableKeylock()
       
  1267     {
       
  1268     TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::DisableKeylock")); )
       
  1269 
       
  1270     // Keep locking status in sync.
       
  1271     iKeylockScreenSaverObserver->SetLockStatus( EFalse, iAutolockEnabled );
       
  1272     if ( iSoundsMuted )
       
  1273         {
       
  1274         CAknAppUiBase* appUi= iAvkonAppUiBase;
       
  1275         appUi->KeySounds()->ReleaseContext();
       
  1276         appUi->KeySounds()->PopContext();
       
  1277         iSoundsMuted = EFalse;
       
  1278         }
       
  1279 
       
  1280     iEcsDetector->CloseEventSource();
       
  1281 
       
  1282     // Stop capturing system keys.
       
  1283     UnCaptureSystemKeys();
       
  1284 
       
  1285     // Stop capturing pointer events.
       
  1286     UnCapturePointerEvents();
       
  1287 
       
  1288     AknGlobalPopupPriorityController::ShowPopup( *this, EFalse );
       
  1289 
       
  1290     // Make the window "disappear".
       
  1291     Window().SetSize( TSize( 0, 0 ) );
       
  1292 
       
  1293     iKeyLockCba->ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(
       
  1294         ECoeWinPriorityNeverAtFront );
       
  1295     iKeyLockCba->MakeVisible( EFalse );
       
  1296 
       
  1297     // Update keyguard status to P&S system.
       
  1298     iStatusProperty.Set( EKeyguardNotActive );
       
  1299     iKeyLockEnabled = EFalse;
       
  1300 
       
  1301     if ( !iAutolockEnabled )	// only when Autolock was user-activated
       
  1302         {
       
  1303 		    // in case Telephone-app was topmost and sent to background, then the user is confused because he expects to see it again.
       
  1304 				// therefore it's required to show it, by sending to foreground. 
       
  1305 				if ( AknLayoutUtils::PenEnabled() )
       
  1306 		     	{ 		
       
  1307     	    TInt callState;
       
  1308     	    RProperty::Get( KPSUidCtsyCallInformation, KCTsyCallState, callState );
       
  1309     	    #if defined(_DEBUG)
       
  1310 						RDebug::Printf( "%s %s (%u) callState=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, callState );
       
  1311 						RDebug::Printf( "%s %s (%u) EPSCTsyCallStateNone=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, EPSCTsyCallStateNone );
       
  1312 					#endif
       
  1313           if (callState != EPSCTsyCallStateNone )
       
  1314               {
       
  1315                 	
       
  1316 				   			TApaTaskList apaTaskList(CCoeEnv::Static()->WsSession());
       
  1317 				   			#define KPhoneAppUid TUid::Uid(0x100058B3)
       
  1318 				
       
  1319 				   			TApaTask apaTask = apaTaskList.FindApp(KPhoneAppUid);
       
  1320 				   			if (apaTask.Exists())
       
  1321 				       	{
       
  1322 									RDebug::Printf( "%s %s (%u) foreground=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
       
  1323 							 		#if defined(_DEBUG)
       
  1324 							 			RDebug::Print(_L("(AUTOLOCK)CAknKeyLockControl::EnableKeylock() Send phone to foreground"));
       
  1325 							 		#endif
       
  1326 				       		// Bring phone to foreground
       
  1327 				       		apaTask.BringToForeground();
       
  1328 				       	}
       
  1329 		       		}
       
  1330 					}	// PenEnabled()
       
  1331 
       
  1332         SendMessageToSysAp( EEikKeyLockDisabled );
       
  1333         }
       
  1334     if ( iNotif )
       
  1335         {
       
  1336         iNotif->NotifyStatusChange( EKeyLockDisabled );
       
  1337         }
       
  1338 
       
  1339     // Basically this cannot fail so we ignore return code.
       
  1340     static_cast<CAknNotifierAppServerAppUi*>(
       
  1341         iEikonEnv->EikAppUi() )->SuppressAppSwitching( EFalse );
       
  1342 
       
  1343     iAutolockEnabled = EFalse;
       
  1344     }
       
  1345 
       
  1346 
       
  1347 // ---------------------------------------------------------------------------
       
  1348 // Sends a message to the SysAp window group.
       
  1349 // ---------------------------------------------------------------------------
       
  1350 //
       
  1351 void CAknKeyLockControl::SendMessageToSysAp( TInt aMessage )
       
  1352     {
       
  1353     RWsSession& ws = iEikonEnv->WsSession();
       
  1354     TInt wgId = 0;
       
  1355     CApaWindowGroupName::FindByAppUid( KSysApUid, ws, wgId );
       
  1356     if ( wgId )
       
  1357         {
       
  1358         TWsEvent event;
       
  1359         event.SetType( aMessage );
       
  1360         event.SetTimeNow();
       
  1361         ws.SendEventToWindowGroup( wgId, event );
       
  1362         }
       
  1363     }
       
  1364 
       
  1365 
       
  1366 // ---------------------------------------------------------------------------
       
  1367 // Displays the "offer keylock" note.
       
  1368 // ---------------------------------------------------------------------------
       
  1369 //
       
  1370 void CAknKeyLockControl::OfferKeylock()
       
  1371     {
       
  1372     iOfferLockNote->ShowNote( (CAknNoteDialog::TTimeout)KAknOfferKeyLockTimeout,
       
  1373                               CAknNoteDialog::ENoTone );
       
  1374     iOfferLockEnabled = ETrue;
       
  1375     }
       
  1376 
       
  1377 
       
  1378 // ---------------------------------------------------------------------------
       
  1379 // Displays the "locked" note.
       
  1380 // ---------------------------------------------------------------------------
       
  1381 //
       
  1382 void CAknKeyLockControl::DisplayLockedNote()
       
  1383     {
       
  1384     if ( !iAutolockEnabled )
       
  1385         {
       
  1386         iKeypadLockedNote->ShowNote( KKeyLockCustomShortTimeout,
       
  1387                                      CAknNoteDialog::ENoTone );
       
  1388         }
       
  1389     }
       
  1390 
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // Displays the "keys active" note.
       
  1394 // ---------------------------------------------------------------------------
       
  1395 //
       
  1396 void CAknKeyLockControl::DisplayKeyActiveNote()
       
  1397     {
       
  1398     if ( !iAutolockEnabled )
       
  1399         {
       
  1400         iKeypadUnlockedNote->ShowNote( KKeyLockCustomShortTimeout,
       
  1401                                        CAknNoteDialog::ENoTone );
       
  1402         }
       
  1403     }
       
  1404 
       
  1405 
       
  1406 // ---------------------------------------------------------------------------
       
  1407 // Unlocks the keypad and displays the "keys active" note.
       
  1408 // ---------------------------------------------------------------------------
       
  1409 //
       
  1410 void CAknKeyLockControl::DoUnlock()
       
  1411     {
       
  1412     DisableKeylock();
       
  1413     DisplayKeyActiveNote();
       
  1414     }
       
  1415 
       
  1416 
       
  1417 // ---------------------------------------------------------------------------
       
  1418 // From base class CCoeControl.
       
  1419 // Handles resource change events.
       
  1420 // ---------------------------------------------------------------------------
       
  1421 //
       
  1422 void CAknKeyLockControl::HandleResourceChange( TInt aType )
       
  1423     {
       
  1424     if ( aType == KEikDynamicLayoutVariantSwitch )
       
  1425         {
       
  1426         TRect screenRect;
       
  1427         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
  1428         if ( !AknLayoutUtils::PenEnabled() )
       
  1429             {
       
  1430              iKeyLockCba->SetBoundingRect( screenRect );
       
  1431             }
       
  1432         else if ( iKeyLockEnabled )
       
  1433             {
       
  1434             // Only resize the window if keylock is active, as
       
  1435             // the window size must be zero when keylock is not active.
       
  1436             // The window is resized to correct size when keylock is activated.
       
  1437             Window().SetSize( screenRect.Size() );
       
  1438             Window().SetRequiredDisplayMode( EColor16MA );
       
  1439             TInt err = Window().SetTransparencyAlphaChannel();
       
  1440             if ( err == KErrNone )
       
  1441                 {
       
  1442                  Window().SetBackgroundColor( ~0 );
       
  1443                 }
       
  1444             }
       
  1445         }
       
  1446     }
       
  1447 
       
  1448 
       
  1449 // ---------------------------------------------------------------------------
       
  1450 // From base class MEikCommandObserver.
       
  1451 // Process commands.
       
  1452 // ---------------------------------------------------------------------------
       
  1453 //
       
  1454 void CAknKeyLockControl::ProcessCommandL( TInt aCommandId )
       
  1455     {
       
  1456     TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::ProcessCommandL %d"), aCommandId); )
       
  1457 
       
  1458     switch ( aCommandId )
       
  1459         {
       
  1460         case EAknSoftkeyUnlock:
       
  1461             {
       
  1462             if ( iAutolockEnabled && !iKeylockApi )
       
  1463                 {
       
  1464                 TApaTaskList tasklist( iCoeEnv->WsSession() );
       
  1465                 TApaTask autolocktask = tasklist.FindApp( KAutolockUid );
       
  1466                 if ( autolocktask.Exists() )
       
  1467                     {
       
  1468                     // if Autolock application is ready
       
  1469                     DisableKeylock();
       
  1470                     iNotif->NotifyStatusChange( EHideSoftNotifications );
       
  1471                     TKeyEvent keyEvent;
       
  1472                     keyEvent.iCode = EKeyBell;
       
  1473                     autolocktask.SendKey( keyEvent );
       
  1474                     }
       
  1475                 }
       
  1476             else
       
  1477                 {
       
  1478                 LeftSoftKeyPressed();
       
  1479                 }
       
  1480             break;
       
  1481             }
       
  1482         case EAknSoftkeyLock:
       
  1483             {
       
  1484             // Lock keys
       
  1485             DoExitOfferKeylock();
       
  1486             EnableKeylock();
       
  1487             break;
       
  1488             }
       
  1489         case EAknSoftkeyExit:
       
  1490             {
       
  1491             // Cancel offer keylock CBA
       
  1492             DoExitOfferKeylock();
       
  1493             break;
       
  1494             }
       
  1495         case EAknSoftkeyEmpty:
       
  1496             {
       
  1497             if ( iKeyLockEnabled )
       
  1498                 {
       
  1499                 ShowLockedNote();
       
  1500                 }
       
  1501             break;
       
  1502             }
       
  1503         case KNoteCmdFocusLost:
       
  1504             {
       
  1505             // Locked note has become unfocused - get rid of it.
       
  1506             if ( iOfferLockEnabled )
       
  1507                 {
       
  1508                 DoExitOfferKeylock();
       
  1509                 }
       
  1510             break;
       
  1511             }
       
  1512         default:
       
  1513             {
       
  1514             break;
       
  1515             }
       
  1516         }
       
  1517     }
       
  1518 
       
  1519 
       
  1520 // ---------------------------------------------------------------------------
       
  1521 // From base class CCoeControl.
       
  1522 // Gets the amount of component controls.
       
  1523 // ---------------------------------------------------------------------------
       
  1524 //
       
  1525 TInt CAknKeyLockControl::CountComponentControls() const
       
  1526     {
       
  1527     if ( iKeyLockEnabled )
       
  1528         {
       
  1529         return 1;
       
  1530         }
       
  1531     else
       
  1532         {
       
  1533         return 0;
       
  1534         }
       
  1535     }
       
  1536 
       
  1537 
       
  1538 // ---------------------------------------------------------------------------
       
  1539 // From base class CCoeControl.
       
  1540 // Returns the pointer to a component control.
       
  1541 // ---------------------------------------------------------------------------
       
  1542 //
       
  1543 CCoeControl* CAknKeyLockControl::ComponentControl( TInt /*aIndex*/ ) const
       
  1544     {
       
  1545     if ( iKeyLockEnabled )
       
  1546         {
       
  1547         return iKeyLockCba;
       
  1548         }
       
  1549     else
       
  1550         {
       
  1551         return NULL;
       
  1552         }
       
  1553     }
       
  1554 
       
  1555 
       
  1556 // ---------------------------------------------------------------------------
       
  1557 // Handles LSK keypress.
       
  1558 // ---------------------------------------------------------------------------
       
  1559 //
       
  1560 void CAknKeyLockControl::LeftSoftKeyPressed()
       
  1561     {
       
  1562     TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::LeftSoftKeyPressed")); )
       
  1563 
       
  1564     // Check that the confirmation note exists, as it's not created on
       
  1565     // startup if touch layout is in use. In emulator this might cause
       
  1566     // a problem, as layout can be changed to a non-touch one, and
       
  1567     // the confirmation notes do not exist.
       
  1568     if ( iConfirmationNote )
       
  1569         {
       
  1570         if ( iFeatureKeypadNoSlider )
       
  1571             {
       
  1572             // Show note "Now press *".
       
  1573             // Note is shown when user has pressed "Unlock" when keypad
       
  1574             // is in locked state.
       
  1575             iConfirmationNoteAsterisk->ShowNote( CAknNoteDialog::EShortTimeout,
       
  1576                                                  CAknNoteDialog::EConfirmationTone );
       
  1577             }
       
  1578         else
       
  1579             {
       
  1580             iConfirmationNote->ShowNote( CAknNoteDialog::EShortTimeout,
       
  1581                                          CAknNoteDialog::EConfirmationTone );
       
  1582             }
       
  1583         SendMessageToSysAp( EEikKeyLockLightsOnRequest );
       
  1584         iUnlockConfirmation = ETrue;
       
  1585         }
       
  1586     }
       
  1587 
       
  1588 
       
  1589 // ---------------------------------------------------------------------------
       
  1590 // From base class CCoeControl.
       
  1591 // Handle key events.
       
  1592 // ---------------------------------------------------------------------------
       
  1593 //
       
  1594 TKeyResponse CAknKeyLockControl::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
  1595                                                  TEventCode aType )
       
  1596     {
       
  1597     if ( AknLayoutUtils::PenEnabled() )
       
  1598         {
       
  1599         TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::OfferKeyEventL: PenEnabled"));)
       
  1600         if ( iAutolockEnabled )
       
  1601             { // The case when touch device is locked and so must be unlocked by hold switch.
       
  1602             TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::OfferKeyEventL: Autolock Enabled"));)
       
  1603             if ( aType == EEventKey && aKeyEvent.iCode == EKeyDeviceF )
       
  1604                 {
       
  1605                 TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::OfferKeyEventL: SysAp message"));)
       
  1606                 SendMessageToSysAp( EEikKeyLockLightsOnRequest );
       
  1607                 if ( iAutolockEnabled && !iKeylockApi )
       
  1608                     {
       
  1609                     TApaTaskList tasklist( iCoeEnv->WsSession() );
       
  1610                     TApaTask autolocktask = tasklist.FindApp( KAutolockUid );
       
  1611                     if ( autolocktask.Exists() )
       
  1612                         {
       
  1613                         // If Autolock application is ready
       
  1614                         DisableKeylock();
       
  1615                         iNotif->NotifyStatusChange( EHideSoftNotifications );
       
  1616                         TKeyEvent keyEvent;
       
  1617                         keyEvent.iCode = EKeyBell;
       
  1618                         autolocktask.SendKey( keyEvent );
       
  1619                         }
       
  1620                     }
       
  1621                 TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::OfferKeyEventL: return EKeyWasConsumed"));)
       
  1622                 return EKeyWasConsumed;
       
  1623                 }
       
  1624             }
       
  1625         }
       
  1626 
       
  1627     if ( !iOfferLockEnabled && !iKeyLockEnabled )
       
  1628         {
       
  1629         if ( aType == EEventKey &&
       
  1630              ( aKeyEvent.iCode == EKeyLeftShift ||
       
  1631                aKeyEvent.iCode == EKeyRightShift ) )
       
  1632             {
       
  1633             // Eat these events as they just cause problems elsewhere.
       
  1634             return EKeyWasConsumed;
       
  1635             }
       
  1636         if ( iKeylockApi && iConsumeNextEventKey )
       
  1637             {
       
  1638             if ( aType == EEventKeyUp )
       
  1639                 {
       
  1640                 iConsumeNextEventKey = EFalse;
       
  1641                 }
       
  1642             return EKeyWasConsumed;
       
  1643             }
       
  1644         return EKeyWasNotConsumed;
       
  1645         }
       
  1646 
       
  1647     if ( ( aType == EEventKey && aKeyEvent.iRepeats == 0 ) ||
       
  1648          ( aType == EEventKeyDown && aKeyEvent.iScanCode == EStdKeyDevice2 ) ) // Power key
       
  1649         {
       
  1650         // If power key pressed, tell SysAp about it.
       
  1651         if ( ( aKeyEvent.iScanCode == EStdKeyDevice2 && aType == EEventKeyDown ) ||
       
  1652              ( iFeatureNoPowerkey && aKeyEvent.iCode == EKeyNo ) )
       
  1653             {
       
  1654             SendMessageToSysAp( EEikKeyLockPowerKeyPressed );
       
  1655             if ( iFeatureNoPowerkey )
       
  1656                 {
       
  1657                 SendMessageToSysAp( EEikKeyLockLightsOnRequest );
       
  1658                 }
       
  1659             }
       
  1660         }
       
  1661 
       
  1662     // Product uses a Keylock Policy API if there exists a defined
       
  1663     // unlock configuration.
       
  1664     if ( iKeylockApi && iKeyLockEnabled )
       
  1665         {
       
  1666         // For keyguard policy
       
  1667         if ( !iAutolockEnabled )
       
  1668             {
       
  1669             // Send key events to KeylockPolicy first
       
  1670             if ( iKeylockApi->HandleKeyEventL( aKeyEvent, aType ) )
       
  1671                 {
       
  1672                 // Key combinations has been pressed -> unlocking.
       
  1673                 DoUnlock();
       
  1674                 iConsumeNextEventKey = ETrue;
       
  1675                 }
       
  1676             else
       
  1677                 {
       
  1678                 // Key combination is not complete.
       
  1679                 if ( iKeylockApi->PrimaryKeyPressed() )
       
  1680                     {
       
  1681                     if ( iKeylockApi->GetLastPrimaryKey() == aKeyEvent.iScanCode &&
       
  1682                          aType == EEventKeyDown )
       
  1683                         {
       
  1684                         // Only primary key has been pressed - show
       
  1685                         // how to unlock "Now press *"
       
  1686                         LeftSoftKeyPressed();
       
  1687                         }
       
  1688                     }
       
  1689                 else
       
  1690                     {
       
  1691                     // Not the primary key has been pressed.
       
  1692                     if ( aType == EEventKeyDown &&
       
  1693                          !( iEcsNote->iNoteOnScreen && aKeyEvent.iCode == EKeyYes ) )
       
  1694                         {
       
  1695                         ShowLockedNote();
       
  1696                         }
       
  1697                     }
       
  1698                 }
       
  1699             }
       
  1700         // for autolock policy
       
  1701         else
       
  1702             {
       
  1703             if ( aType == EEventKeyDown )
       
  1704                 {
       
  1705                 TApaTaskList tasklist( iCoeEnv->WsSession() );
       
  1706                 TApaTask autolocktask = tasklist.FindApp( KAutolockUid );
       
  1707                 if ( autolocktask.Exists() )
       
  1708                     {
       
  1709                     autolocktask.SendKey( aKeyEvent );
       
  1710                     }
       
  1711                 }
       
  1712             }
       
  1713         return EKeyWasConsumed;
       
  1714         }
       
  1715 
       
  1716     if ( ( aType == EEventKey && aKeyEvent.iRepeats == 0 ) ||
       
  1717          ( aType == EEventKeyDown && aKeyEvent.iScanCode == EStdKeyDevice2 ) ) // Power key
       
  1718         {
       
  1719         if ( iOfferLockEnabled )
       
  1720             {
       
  1721             switch ( aKeyEvent.iCode )
       
  1722                 {
       
  1723                 case EKeyOK: // fallthrough to return EKeyWasConsumed
       
  1724                     {
       
  1725                     DoExitOfferKeylock();
       
  1726                     EnableKeylock();
       
  1727                     }
       
  1728                 case EKeyLeftArrow:
       
  1729                 case EKeyRightArrow:
       
  1730                 case EKeyUpArrow:
       
  1731                 case EKeyDownArrow:
       
  1732                 case EKeyApplication:
       
  1733                     {
       
  1734                     return EKeyWasConsumed;
       
  1735                     }
       
  1736                 default:
       
  1737                     {
       
  1738                     // Normal response - send it to the CBA via the
       
  1739                     // control stack.
       
  1740                     return EKeyWasNotConsumed;
       
  1741                     }
       
  1742                 }
       
  1743             }
       
  1744         else if ( iKeyLockEnabled )
       
  1745             {
       
  1746             if ( iLockedNoteDisplayed )
       
  1747                 {
       
  1748                 // See if 'Unlock' has been pressed.
       
  1749                 if ( aKeyEvent.iCode == EKeyCBA1 )
       
  1750                     {
       
  1751                     LeftSoftKeyPressed();
       
  1752                     iLockedNote->CancelNote();
       
  1753                     }
       
  1754                 // Locked note is on-screen - discard key.
       
  1755                 return EKeyWasConsumed;
       
  1756                 }
       
  1757             else if ( iUnlockConfirmation )
       
  1758                 {
       
  1759                 // Confirmation note is on-screen - check for OK.
       
  1760                 // EStdKeyDevice1 is also needed since some applications generate
       
  1761                 // EKeyCBA2 key events and accidentally unlock the phone
       
  1762                 if ( ( ( aKeyEvent.iCode == KAknAsterisk ||
       
  1763                          aKeyEvent.iCode == KAknChineseAsterisk ) &&
       
  1764                        iFeatureKeypadNoSlider ) ||
       
  1765                      ( aKeyEvent.iCode == EKeyCBA2 &&
       
  1766                        aKeyEvent.iScanCode == EStdKeyDevice1 &&
       
  1767                        !iFeatureKeypadNoSlider ) )
       
  1768                     {
       
  1769                     DoUnlock();
       
  1770                     if ( iFeatureKeypadNoSlider )
       
  1771                         {
       
  1772                         // Show note "Now press *".
       
  1773                         // Note is shown when user has pressed "Unlock"
       
  1774                         // when keypad is in locked state
       
  1775                         iConfirmationNoteAsterisk->CancelNote();
       
  1776                         }
       
  1777                     else
       
  1778                         {
       
  1779                         iConfirmationNote->CancelNote();
       
  1780                         }
       
  1781                     }
       
  1782                 else
       
  1783                     {
       
  1784                     if ( aKeyEvent.iCode != EKeyCBA1 &&
       
  1785                          aKeyEvent.iCode != EKeyLeftShift &&
       
  1786                          aKeyEvent.iCode != EKeyRightShift )
       
  1787                         {
       
  1788                         ShowLockedNote();
       
  1789                         }
       
  1790                     }
       
  1791                 }
       
  1792             else
       
  1793                 {
       
  1794                 TKeyResponse cbaResponse = EKeyWasNotConsumed;
       
  1795                 // EKeyOK will be incorrectly translated to left soft key by the CBA.
       
  1796                 if ( aKeyEvent.iCode != EKeyOK )
       
  1797                     {
       
  1798                     // Normal response - send it to the CBA.
       
  1799                     cbaResponse =
       
  1800                         iKeyLockCba->ButtonGroup()->AsControl()->OfferKeyEventL(
       
  1801                             aKeyEvent, aType );
       
  1802                     }
       
  1803 
       
  1804                 if ( cbaResponse == EKeyWasNotConsumed )
       
  1805                     {
       
  1806                     if ( !( iEcsNote->iNoteOnScreen &&
       
  1807                             aKeyEvent.iCode == EKeyYes ) )
       
  1808                         {
       
  1809                         ShowLockedNote();
       
  1810                         }
       
  1811                     }
       
  1812                 }
       
  1813             }
       
  1814         }
       
  1815     // Needed for the pencil key/shift keys to show "keys locked" note.
       
  1816     else if ( iKeyLockEnabled )
       
  1817         {
       
  1818         if ( aType == EEventKeyDown &&
       
  1819              aKeyEvent.iRepeats == 0 &&
       
  1820              ( aKeyEvent.iScanCode == EStdKeyLeftShift ||
       
  1821                aKeyEvent.iScanCode == EStdKeyRightShift ) )
       
  1822             {
       
  1823             ShowLockedNote();
       
  1824             }
       
  1825         }
       
  1826 
       
  1827     return EKeyWasConsumed;
       
  1828     }
       
  1829 
       
  1830 
       
  1831 // ---------------------------------------------------------------------------
       
  1832 // Shows the "locked" note.
       
  1833 // ---------------------------------------------------------------------------
       
  1834 //
       
  1835 void CAknKeyLockControl::ShowLockedNote()
       
  1836     {
       
  1837     if ( !iLockedNoteDisplayed )
       
  1838         {
       
  1839         DoShowLockedNote();
       
  1840         }
       
  1841     }
       
  1842 
       
  1843 
       
  1844 // ---------------------------------------------------------------------------
       
  1845 // Shows the "locked" note.
       
  1846 // ---------------------------------------------------------------------------
       
  1847 //
       
  1848 void CAknKeyLockControl::DoShowLockedNote()
       
  1849     {
       
  1850     if ( !iAutolockEnabled )
       
  1851         {
       
  1852         iLockedNote->ShowNote( KKeyLockDisplayLockedTimeout,
       
  1853                                CAknNoteDialog::ENoTone );
       
  1854         iLockedNoteDisplayed = ETrue;
       
  1855         }
       
  1856     }
       
  1857 
       
  1858 
       
  1859 // ---------------------------------------------------------------------------
       
  1860 // Brings the keylock notifier's CBA visible.
       
  1861 // ---------------------------------------------------------------------------
       
  1862 //
       
  1863 void CAknKeyLockControl::ShowKeylockCba()
       
  1864     {
       
  1865     RDrawableWindow* cbaWindow =
       
  1866         iKeyLockCba->ButtonGroup()->AsControl()->DrawableWindow();
       
  1867     cbaWindow->SetFaded( EFalse, RWindowTreeNode::EFadeWindowOnly );
       
  1868     cbaWindow->SetOrdinalPosition( 0, 1 );
       
  1869     cbaWindow->SetNonFading( ETrue );
       
  1870     }
       
  1871 
       
  1872 
       
  1873 // ---------------------------------------------------------------------------
       
  1874 // Sets the necessary HW keys captured.
       
  1875 // ---------------------------------------------------------------------------
       
  1876 //
       
  1877 void CAknKeyLockControl::CaptureSystemKeys()
       
  1878     {
       
  1879     if ( !iKeysCaptured )
       
  1880         {
       
  1881         RWindowGroup& groupWin = iCoeEnv->RootWin();
       
  1882 
       
  1883         // Capture app key (disable application switching).
       
  1884         iAppKey = groupWin.CaptureKeyUpAndDowns( EStdKeyApplication0, 0, 0 );
       
  1885         iAppKey2 = groupWin.CaptureKey( EKeyApplication0, 0, 0 );
       
  1886 
       
  1887         // Capture power key (for lights).
       
  1888         iPowerKey = groupWin.CaptureKeyUpAndDowns( EStdKeyDevice2, 0, 0 );
       
  1889         iPowerKey2 = groupWin.CaptureKey( EKeyDevice2, 0, 0 );
       
  1890 
       
  1891         // Capture voice key.
       
  1892         iVoiceKey = groupWin.CaptureKeyUpAndDowns( EStdKeyDevice6, 0, 0 );
       
  1893         iVoiceKey2 = groupWin.CaptureKey( EKeyDevice6, 0, 0 );
       
  1894 
       
  1895         // Capture end key (lights for combined power/end key).
       
  1896         iEndKey = groupWin.CaptureKey( EKeyNo, 0, 0 );
       
  1897 
       
  1898         // Capture PoC key.
       
  1899         iPoCKey = groupWin.CaptureKeyUpAndDowns( EStdKeyApplication1, 0, 0 );
       
  1900         iPoCKey2 = groupWin.CaptureKey( EKeyApplication1, 0, 0 );
       
  1901 
       
  1902         iHoldSwitch = 0;
       
  1903 
       
  1904         if ( AknLayoutUtils::PenEnabled() )
       
  1905             {
       
  1906             TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::CaptureSystemKeys PenEnabled"));)
       
  1907             if ( iAutolockEnabled )
       
  1908                 { //Capture Hold Switch
       
  1909                 TRACES( RDebug::Print(_L("(KeyGuard)CAknKeyLockControl::CaptureSystemKeys iAutolockEnabled"));)
       
  1910                 iHoldSwitch = groupWin.CaptureKey( EKeyDeviceF, 0, 0 );
       
  1911                 }
       
  1912             }
       
  1913         iKeysCaptured = ETrue;
       
  1914         }
       
  1915     }
       
  1916 
       
  1917 
       
  1918 // ---------------------------------------------------------------------------
       
  1919 // Releases captured HW keys.
       
  1920 // ---------------------------------------------------------------------------
       
  1921 //
       
  1922 void CAknKeyLockControl::UnCaptureSystemKeys()
       
  1923     {
       
  1924     if ( iKeysCaptured )
       
  1925         {
       
  1926         RWindowGroup& groupWin = iCoeEnv->RootWin();
       
  1927         groupWin.CancelCaptureKeyUpAndDowns( iAppKey );
       
  1928         groupWin.CancelCaptureKeyUpAndDowns( iPowerKey );
       
  1929         groupWin.CancelCaptureKeyUpAndDowns( iVoiceKey );
       
  1930         groupWin.CancelCaptureKey( iAppKey2 );
       
  1931         groupWin.CancelCaptureKey( iPowerKey2 );
       
  1932         groupWin.CancelCaptureKey( iVoiceKey2 );
       
  1933         groupWin.CancelCaptureKey( iEndKey );
       
  1934         groupWin.CancelCaptureKeyUpAndDowns( iPoCKey );
       
  1935         groupWin.CancelCaptureKey( iPoCKey2 );
       
  1936 
       
  1937         if ( iHoldSwitch > 0 )
       
  1938             {
       
  1939             groupWin.CancelCaptureKey( iHoldSwitch );
       
  1940             }
       
  1941 
       
  1942         iKeysCaptured = EFalse;
       
  1943         }
       
  1944     }
       
  1945 
       
  1946 
       
  1947 // ---------------------------------------------------------------------------
       
  1948 // From base class MAknEcsObserver.
       
  1949 // Handles the ECS events.
       
  1950 // ---------------------------------------------------------------------------
       
  1951 //
       
  1952 void CAknKeyLockControl::HandleEcsEvent( CAknEcsDetector* aEcsDetector,
       
  1953                                          CAknEcsDetector::TState aState )
       
  1954     {
       
  1955     switch ( aState )
       
  1956         {
       
  1957         case CAknEcsDetector::ECompleteMatchThenSendKey:
       
  1958             {
       
  1959             // Do nothing since note will be removed on ECallAttempted event.
       
  1960             break;
       
  1961             }
       
  1962         case CAknEcsDetector::ECompleteMatch:
       
  1963             {
       
  1964             iEcsNote->SetEmergencyNumber( aEcsDetector->CurrentMatch() );
       
  1965             iEcsNote->ShowNote( CAknNoteDialog::ENoTimeout,
       
  1966                                 CAknNoteDialog::ENoTone );
       
  1967 
       
  1968             // Tell SysAp to switch lights on.
       
  1969             SendMessageToSysAp( EEikEcsQueryLights );
       
  1970             iEcsNote->iNoteOnScreen = ETrue;
       
  1971             break;
       
  1972             }
       
  1973         case CAknEcsDetector::EPartialMatch:
       
  1974             {
       
  1975             iEcsNote->SleepNote();
       
  1976             break;
       
  1977             }
       
  1978         case CAknEcsDetector::ECallAttempted:
       
  1979             {
       
  1980             iEcsNote->SleepNote();
       
  1981             break;
       
  1982             }
       
  1983         case CAknEcsDetector::EEmpty:
       
  1984             {
       
  1985             iEcsNote->SleepNote();
       
  1986             break;
       
  1987             }
       
  1988         case CAknEcsDetector::ENoMatch:
       
  1989             {
       
  1990             iEcsNote->SleepNote();
       
  1991             break;
       
  1992             }
       
  1993         default:
       
  1994             {
       
  1995             break;
       
  1996             }
       
  1997         }
       
  1998     }
       
  1999 
       
  2000 
       
  2001 // ---------------------------------------------------------------------------
       
  2002 // Cancels the offer keylock note.
       
  2003 // ---------------------------------------------------------------------------
       
  2004 //
       
  2005 void CAknKeyLockControl::DoExitOfferKeylock()
       
  2006     {
       
  2007     iOfferLockNote->CancelNote();
       
  2008     }
       
  2009 
       
  2010 
       
  2011 // ---------------------------------------------------------------------------
       
  2012 // Cancels the offer keylock note.
       
  2013 // ---------------------------------------------------------------------------
       
  2014 //
       
  2015 void CAknKeyLockControl::OfferTimerExpired()
       
  2016     {
       
  2017     DoExitOfferKeylock();
       
  2018     }
       
  2019 
       
  2020 
       
  2021 // ---------------------------------------------------------------------------
       
  2022 // Sets the autolock state.
       
  2023 // ---------------------------------------------------------------------------
       
  2024 //
       
  2025 void CAknKeyLockControl::AutolockEnabled( TBool aAutoLockOn )
       
  2026     {
       
  2027     iAutolockEnabled = aAutoLockOn;
       
  2028     }
       
  2029 
       
  2030 
       
  2031 // ---------------------------------------------------------------------------
       
  2032 // For CDMA implementation.
       
  2033 // ---------------------------------------------------------------------------
       
  2034 //
       
  2035 void CAknKeyLockControl::CallNumberL( TDesC& /*aNumber*/ )
       
  2036     {
       
  2037     }
       
  2038 
       
  2039 
       
  2040 // ---------------------------------------------------------------------------
       
  2041 // For CDMA implementation.
       
  2042 // ---------------------------------------------------------------------------
       
  2043 //
       
  2044 void CAknKeyLockControl::ShowLockPhoneQueryL()
       
  2045     {
       
  2046     }
       
  2047 
       
  2048 
       
  2049 // ---------------------------------------------------------------------------
       
  2050 // For capturing pointer events when key lock is enabled.
       
  2051 // ---------------------------------------------------------------------------
       
  2052 //
       
  2053 void CAknKeyLockControl::CapturePointerEvents()
       
  2054     {
       
  2055     if ( AknLayoutUtils::PenEnabled() )
       
  2056         {
       
  2057         Window().SetPointerCapture( RWindowBase::TCaptureDragDrop );
       
  2058         Window().ClaimPointerGrab( ETrue );
       
  2059         }
       
  2060     }
       
  2061 
       
  2062 
       
  2063 // ---------------------------------------------------------------------------
       
  2064 // For releasing pointer events when key lock is disabled.
       
  2065 // ---------------------------------------------------------------------------
       
  2066 //
       
  2067 void CAknKeyLockControl::UnCapturePointerEvents()
       
  2068     {
       
  2069     if ( AknLayoutUtils::PenEnabled() )
       
  2070         {
       
  2071         Window().SetPointerCapture( RWindowBase::TCaptureDisabled );
       
  2072         Window().ClaimPointerGrab( EFalse );
       
  2073         }
       
  2074     }
       
  2075 
       
  2076 
       
  2077 // ===========================================================================
       
  2078 // class CAknKeyLockNotifierSubject
       
  2079 // ===========================================================================
       
  2080 
       
  2081 // ---------------------------------------------------------------------------
       
  2082 // Two-phased constructor.
       
  2083 // ---------------------------------------------------------------------------
       
  2084 //
       
  2085 CAknKeyLockNotifierSubject* CAknKeyLockNotifierSubject::NewL()
       
  2086     {
       
  2087     CAknKeyLockNotifierSubject* self = new (ELeave) CAknKeyLockNotifierSubject();
       
  2088     CleanupStack::PushL( self );
       
  2089     self->ConstructL();
       
  2090     CleanupStack::Pop( self );
       
  2091     return self;
       
  2092     }
       
  2093 
       
  2094 
       
  2095 // ---------------------------------------------------------------------------
       
  2096 // Second-phase constructor.
       
  2097 // ---------------------------------------------------------------------------
       
  2098 //
       
  2099 void CAknKeyLockNotifierSubject::ConstructL()
       
  2100     {
       
  2101     CCoeEnv* environment = CCoeEnv::Static();
       
  2102 
       
  2103     TFileName resourceFile;
       
  2104     resourceFile.Append( KRESOURCEFILE );
       
  2105     BaflUtils::NearestLanguageFile( environment->FsSession(), resourceFile );
       
  2106 
       
  2107     iResourceFileOffset = environment->AddResourceFileL( resourceFile );
       
  2108 
       
  2109     iObserverList = new (ELeave) CArrayPtrFlat<MAknKeyLockObserver>(
       
  2110         KAknObserverListGranularity );
       
  2111 
       
  2112     iKeyLockControl = new (ELeave) CAknKeyLockControl( this );
       
  2113     iKeyLockControl->ConstructL();
       
  2114     }
       
  2115 
       
  2116 
       
  2117 // ---------------------------------------------------------------------------
       
  2118 // Default C++ constructor.
       
  2119 // ---------------------------------------------------------------------------
       
  2120 //
       
  2121 CAknKeyLockNotifierSubject::CAknKeyLockNotifierSubject() :
       
  2122     iAllowNotifications( ETrue )
       
  2123     {
       
  2124     }
       
  2125 
       
  2126 
       
  2127 // ---------------------------------------------------------------------------
       
  2128 // Destructor
       
  2129 // ---------------------------------------------------------------------------
       
  2130 //
       
  2131 CAknKeyLockNotifierSubject::~CAknKeyLockNotifierSubject()
       
  2132     {
       
  2133     if ( iResourceFileOffset )
       
  2134         {
       
  2135         CCoeEnv::Static()->DeleteResourceFile( iResourceFileOffset );
       
  2136         }
       
  2137     delete iKeyLockControl;
       
  2138     delete iObserverList;
       
  2139     iKeyLockControl = NULL;
       
  2140     iObserverList = NULL;
       
  2141     }
       
  2142 
       
  2143 
       
  2144 // ---------------------------------------------------------------------------
       
  2145 // From base class MEikSrvNotifierBase2.
       
  2146 // Frees all the resources owned by the keylock notifier.
       
  2147 // ---------------------------------------------------------------------------
       
  2148 //
       
  2149 void CAknKeyLockNotifierSubject::Release()
       
  2150     {
       
  2151     delete this;
       
  2152     }
       
  2153 
       
  2154 
       
  2155 // ---------------------------------------------------------------------------
       
  2156 // From base class MEikSrvNotifierBase2.
       
  2157 // Initialises the keylock notifier.
       
  2158 // ---------------------------------------------------------------------------
       
  2159 //
       
  2160 CAknKeyLockNotifierSubject::TNotifierInfo CAknKeyLockNotifierSubject::RegisterL()
       
  2161     {
       
  2162     iInfo.iUid      = KAknKeyLockNotifierUid;
       
  2163     iInfo.iChannel  = KAknKeyLockNotifierUid;
       
  2164     iInfo.iPriority = ENotifierPriorityHigh;
       
  2165     return iInfo;
       
  2166     }
       
  2167 
       
  2168 
       
  2169 // ---------------------------------------------------------------------------
       
  2170 // From base class MEikSrvNotifierBase2.
       
  2171 // Gets the notifier parameters.
       
  2172 // ---------------------------------------------------------------------------
       
  2173 //
       
  2174 CAknKeyLockNotifierSubject::TNotifierInfo CAknKeyLockNotifierSubject::Info() const
       
  2175     {
       
  2176     return iInfo;
       
  2177     }
       
  2178 
       
  2179 
       
  2180 // ---------------------------------------------------------------------------
       
  2181 // From base class MEikSrvNotifierBase2.
       
  2182 // Starts the keylock notifier synchronously.
       
  2183 // ---------------------------------------------------------------------------
       
  2184 //
       
  2185 TPtrC8 CAknKeyLockNotifierSubject::StartL( const TDesC8& aBuffer )
       
  2186     {
       
  2187     SAknNotifierPackage<SAknKeyLockNotifierParams>* params =
       
  2188         ( SAknNotifierPackage<SAknKeyLockNotifierParams>*)aBuffer.Ptr();
       
  2189 
       
  2190     if ( aBuffer.Length() < 0 ||
       
  2191          (TUint)aBuffer.Length() < sizeof(SAknNotifierPackage<SAknKeyLockNotifierParams>) ||
       
  2192          params->iSignature != KAKNNOTIFIERSIGNATURE )
       
  2193         {
       
  2194         User::Leave( KErrArgument );
       
  2195         }
       
  2196 
       
  2197     switch ( params->iParamData.iReason )
       
  2198         {
       
  2199         case ELockEnabled:
       
  2200         case ELockDisabled:
       
  2201         case EAllowNotifications:
       
  2202         case EStopNotifications:
       
  2203         case EOfferKeylock:
       
  2204         case ECancelAllNotifications:
       
  2205         case EEnableAutoLockEmulation:
       
  2206         case EDisableWithoutNote:
       
  2207         case EEnableWithoutNote:
       
  2208             {
       
  2209             break;
       
  2210             }
       
  2211         case EInquire:
       
  2212             {
       
  2213             iRetPckg().iEnabled = IsKeyLockEnabled();
       
  2214             break;
       
  2215             }
       
  2216         default:
       
  2217             {
       
  2218             break;
       
  2219             }
       
  2220         }
       
  2221 
       
  2222     return iRetPckg;
       
  2223     }
       
  2224 
       
  2225 
       
  2226 // ---------------------------------------------------------------------------
       
  2227 // From base class MEikSrvNotifierBase2.
       
  2228 // Starts the keylock notifier asynchronously.
       
  2229 // ---------------------------------------------------------------------------
       
  2230 //
       
  2231 void CAknKeyLockNotifierSubject::StartL( const TDesC8& aBuffer,
       
  2232                                          TInt /*aReplySlot*/,
       
  2233                                          const RMessagePtr2& aMessage )
       
  2234     {
       
  2235     SAknNotifierPackage<SAknKeyLockNotifierParams>* params =
       
  2236         ( SAknNotifierPackage<SAknKeyLockNotifierParams>*)aBuffer.Ptr();
       
  2237 
       
  2238     if ( aBuffer.Length() < 0 ||
       
  2239          (TUint)aBuffer.Length() < sizeof(SAknNotifierPackage<SAknKeyLockNotifierParams>) ||
       
  2240          params->iSignature != KAKNNOTIFIERSIGNATURE )
       
  2241         {
       
  2242         User::Leave( KErrArgument );
       
  2243         }
       
  2244 
       
  2245     switch ( params->iParamData.iReason )
       
  2246         {
       
  2247         case ELockEnabled:
       
  2248             {
       
  2249             if ( !iKeyLockControl->iAutolockEnabled )
       
  2250                 {
       
  2251                 DoEnableKeyLock();
       
  2252                 }
       
  2253             break;
       
  2254             }
       
  2255         case ELockDisabled:
       
  2256             {
       
  2257             // Protect unlocking keys if autolock emulation enabled.
       
  2258             // Either the application has the right capabilities, or EikSrvs does the calling.
       
  2259             if ( !iKeyLockControl->iAutolockEnabled ||
       
  2260                  aMessage.HasCapability( ECapabilityWriteDeviceData ) || aMessage.HasCapability( ECapabilityTrustedUI ) )
       
  2261                 {
       
  2262                 DoDisableKeyLock();
       
  2263                 }
       
  2264             break;
       
  2265             }
       
  2266         case EOfferKeylock:
       
  2267             {
       
  2268             DoOfferKeyLock();
       
  2269             break;
       
  2270             }
       
  2271         case EEnableAutoLockEmulation:
       
  2272             {
       
  2273             TInt queryActive( ESecurityQueryNotActive );
       
  2274             TInt autolockActive( EAutolockOff );
       
  2275 
       
  2276             RProperty::Get( KPSUidStartup,
       
  2277                             KStartupSecurityCodeQueryStatus,
       
  2278                             queryActive );
       
  2279 
       
  2280             RProperty::Get( KPSUidCoreApplicationUIs,
       
  2281                             KCoreAppUIsAutolockStatus,
       
  2282                             autolockActive );
       
  2283 
       
  2284             // Don't activate autolock emulation if there is a sec code query up;
       
  2285             // our softkey CBA will come on top of its CBA if we do.
       
  2286             if ( queryActive == ESecurityQueryActive &&
       
  2287                  autolockActive > EAutolockOff )
       
  2288                 {
       
  2289                 // Do nothing ... The emulation will be activated by Autolock
       
  2290                 // itself in case the query is canceled.
       
  2291                 }
       
  2292             else
       
  2293                 {
       
  2294                 // Business as usual.
       
  2295                 NotifyStatusChange( EShowSoftNotifications );
       
  2296                 LockKeys( ETrue );
       
  2297                 }
       
  2298             break;
       
  2299             }
       
  2300         case EDisableWithoutNote:
       
  2301             {
       
  2302             // Protect unlocking keys if autolock emulation enabled.
       
  2303             // Either the application has the right capabilities, or EikSrvs does the calling.
       
  2304             if ( !iKeyLockControl->iAutolockEnabled	||
       
  2305                  aMessage.HasCapability( ECapabilityWriteDeviceData ) || aMessage.HasCapability( ECapabilityTrustedUI ) )
       
  2306                 {
       
  2307                 UnlockKeys();
       
  2308                 }
       
  2309             break;
       
  2310             }
       
  2311         case EEnableWithoutNote:
       
  2312             {
       
  2313             if ( !iKeyLockControl->iAutolockEnabled )
       
  2314                 {
       
  2315                 if ( !IsKeyLockEnabled() )
       
  2316                     {
       
  2317                     iKeyLockControl->EnableKeylock( EFalse );
       
  2318                     }
       
  2319                 }
       
  2320             break;
       
  2321             }
       
  2322         default:
       
  2323             {
       
  2324             break;
       
  2325             }
       
  2326         };
       
  2327 
       
  2328     aMessage.Complete( KErrNone );
       
  2329     }
       
  2330 
       
  2331 
       
  2332 // ---------------------------------------------------------------------------
       
  2333 // From base class MEikSrvNotifierBase2.
       
  2334 // Called when the keylock notifier is cancelled.
       
  2335 // ---------------------------------------------------------------------------
       
  2336 //
       
  2337 void CAknKeyLockNotifierSubject::Cancel()
       
  2338     {
       
  2339     }
       
  2340 
       
  2341 
       
  2342 // ---------------------------------------------------------------------------
       
  2343 // From base class MEikSrvNotifierBase2.
       
  2344 // Called when the active keylock notifier's data is updated.
       
  2345 // ---------------------------------------------------------------------------
       
  2346 //
       
  2347 TPtrC8 CAknKeyLockNotifierSubject::UpdateL( const TDesC8& aBuffer )
       
  2348     {
       
  2349     return TPtrC8( aBuffer );
       
  2350     }
       
  2351 
       
  2352 
       
  2353 // ---------------------------------------------------------------------------
       
  2354 // From base class MAknKeyLockController.
       
  2355 // Gets the current keylock status.
       
  2356 // ---------------------------------------------------------------------------
       
  2357 //
       
  2358 TBool CAknKeyLockNotifierSubject::IsKeyLockEnabled()
       
  2359     {
       
  2360     return iKeyLockControl->iKeyLockEnabled;
       
  2361     }
       
  2362 
       
  2363 
       
  2364 // ---------------------------------------------------------------------------
       
  2365 // From base class MAknKeyLockController.
       
  2366 // Notifications are always allowed here.
       
  2367 // ---------------------------------------------------------------------------
       
  2368 //
       
  2369 TBool CAknKeyLockNotifierSubject::AllowNotifications()
       
  2370     {
       
  2371     return iAllowNotifications;
       
  2372     }
       
  2373 
       
  2374 
       
  2375 // ---------------------------------------------------------------------------
       
  2376 // From base class MAknKeyLockController.
       
  2377 // Disables the keylock.
       
  2378 // ---------------------------------------------------------------------------
       
  2379 //
       
  2380 void CAknKeyLockNotifierSubject::UnlockKeys()
       
  2381     {
       
  2382     if ( IsKeyLockEnabled() )
       
  2383         {
       
  2384         iKeyLockControl->DisableKeylock();
       
  2385         }
       
  2386     }
       
  2387 
       
  2388 
       
  2389 // ---------------------------------------------------------------------------
       
  2390 // From base class MAknKeyLockController.
       
  2391 // Enables the keylock.
       
  2392 // ---------------------------------------------------------------------------
       
  2393 //
       
  2394 void CAknKeyLockNotifierSubject::LockKeys( TBool aAutoLockOn )
       
  2395     {
       
  2396     // We'll have to disable keylock if we are changing autolock status.
       
  2397     if ( IsKeyLockEnabled() && aAutoLockOn != iKeyLockControl->iAutolockEnabled )
       
  2398         {
       
  2399         iKeyLockControl->DisableKeylock();
       
  2400         }
       
  2401 
       
  2402     if ( !IsKeyLockEnabled() )
       
  2403         {
       
  2404         iKeyLockControl->AutolockEnabled( aAutoLockOn );
       
  2405         iKeyLockControl->EnableKeylock();
       
  2406         }
       
  2407     }
       
  2408 
       
  2409 
       
  2410 // ---------------------------------------------------------------------------
       
  2411 // From base class MAknKeyLockController.
       
  2412 // Adds a keylock status change observer.
       
  2413 // ---------------------------------------------------------------------------
       
  2414 //
       
  2415 void CAknKeyLockNotifierSubject::AddObserverL( MAknKeyLockObserver* aObserver )
       
  2416     {
       
  2417 #if defined(_DEBUG)
       
  2418     TInt count = iObserverList->Count();
       
  2419     for ( TInt index = 0; index < count; index++ )
       
  2420         {
       
  2421         if ( ((*iObserverList)[index]) == aObserver )
       
  2422             {
       
  2423             Panic( EAknPanicKeyLockObserverAlreadyExists );
       
  2424             }
       
  2425         }
       
  2426 #endif
       
  2427     iObserverList->AppendL( aObserver );
       
  2428 
       
  2429     // Make sure that the observer isn't obscuring the keylock CBA
       
  2430     ShowKeylockCba();
       
  2431     }
       
  2432 
       
  2433 
       
  2434 // ---------------------------------------------------------------------------
       
  2435 // From base class MAknKeyLockController.
       
  2436 // Removes a keylock status change observer.
       
  2437 // ---------------------------------------------------------------------------
       
  2438 //
       
  2439 void CAknKeyLockNotifierSubject::RemoveObserver( MAknKeyLockObserver* aObserver )
       
  2440     {
       
  2441     TInt count = iObserverList->Count();
       
  2442     for ( TInt index = 0; index < count; index++ )
       
  2443         {
       
  2444         if ( ((*iObserverList)[index]) == aObserver )
       
  2445             {
       
  2446             iObserverList->Delete( index );
       
  2447             return;
       
  2448             }
       
  2449         }
       
  2450 #if defined(_DEBUG)
       
  2451     Panic( EAknPanicKeyLockObserverNotFound );
       
  2452 #endif
       
  2453     }
       
  2454 
       
  2455 
       
  2456 // ---------------------------------------------------------------------------
       
  2457 // Notifies the observers of a keylock status change.
       
  2458 // ---------------------------------------------------------------------------
       
  2459 //
       
  2460 void CAknKeyLockNotifierSubject::NotifyStatusChange( TKeyLockStatus aStatus )
       
  2461     {
       
  2462     TInt count = iObserverList->Count();
       
  2463     for ( TInt index = count - 1; index >= 0; index-- )
       
  2464         {
       
  2465         ((*iObserverList)[index])->KeyLockStatusChange( aStatus );
       
  2466         }
       
  2467     }
       
  2468 
       
  2469 
       
  2470 // ---------------------------------------------------------------------------
       
  2471 // Brings the keylock notifier's CBA visible.
       
  2472 // ---------------------------------------------------------------------------
       
  2473 //
       
  2474 void CAknKeyLockNotifierSubject::ShowKeylockCba()
       
  2475     {
       
  2476     if ( IsKeyLockEnabled() )
       
  2477         {
       
  2478         iKeyLockControl->ShowKeylockCba();
       
  2479         }
       
  2480     }
       
  2481 
       
  2482 
       
  2483 // ---------------------------------------------------------------------------
       
  2484 // Enables the keylock.
       
  2485 // ---------------------------------------------------------------------------
       
  2486 //
       
  2487 void CAknKeyLockNotifierSubject::DoEnableKeyLock()
       
  2488     {
       
  2489     if ( !IsKeyLockEnabled() )
       
  2490         {
       
  2491         iKeyLockControl->EnableKeylock();
       
  2492         }
       
  2493     }
       
  2494 
       
  2495 
       
  2496 // ---------------------------------------------------------------------------
       
  2497 // Disables the keylock if active.
       
  2498 // ---------------------------------------------------------------------------
       
  2499 //
       
  2500 void CAknKeyLockNotifierSubject::DoDisableKeyLock()
       
  2501     {
       
  2502     if ( IsKeyLockEnabled() )
       
  2503         {
       
  2504         iKeyLockControl->DisableKeylock();
       
  2505         // Attempt to display KeyActive note.
       
  2506         iKeyLockControl->DisplayKeyActiveNote();
       
  2507         }
       
  2508     else if ( iKeyLockControl->iOfferLockEnabled )
       
  2509         {
       
  2510         // Remove the offer key lock CBA.
       
  2511         iKeyLockControl->OfferTimerExpired();
       
  2512         }
       
  2513     }
       
  2514 
       
  2515 
       
  2516 // ---------------------------------------------------------------------------
       
  2517 // Displays the offer keylock note.
       
  2518 // ---------------------------------------------------------------------------
       
  2519 //
       
  2520 void CAknKeyLockNotifierSubject::DoOfferKeyLock()
       
  2521     {
       
  2522     if ( !IsKeyLockEnabled() )
       
  2523         {
       
  2524         NotifyStatusChange( EKeyLockOffered );
       
  2525         iKeyLockControl->OfferKeylock();
       
  2526         }
       
  2527     }