securitydialogs/lockapp/src/lockappappui.cpp
changeset 0 164170e6151a
child 1 d5423fbb4f29
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  LockApp Application UI class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "lockappappui.h"
       
    20 #include "lockappstatecontrol.h"
       
    21 #include "lockappserver.h"
       
    22 #include "lockapptrace.h"
       
    23 #include <lockappclientserver.h>
       
    24 #include <aknglobalpopupprioritycontroller.h>
       
    25 #include <APGCLI.h>
       
    26 
       
    27 #ifdef __SAP_TERMINAL_CONTROL_FW
       
    28 #include <SCPClient.h>
       
    29 #endif // __SAP_TERMINAL_CONTROL_FW
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // Second phase constructor
       
    33 // ---------------------------------------------------------------------------
       
    34 void CLockAppAppUi::ConstructL( )
       
    35     {
       
    36     	RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0x8 );
       
    37     	    
       
    38    // default appui constructor has to be called
       
    39     BaseConstructL( );    	    
       
    40     	    
       
    41     TInt use_old_autolock=1;
       
    42     if(use_old_autolock)
       
    43     	{
       
    44 			// start autolock instead of lockapp . This is a backup solution to use in case that not all SysAp and Avkon changes are implemented
       
    45 	 	  RDebug::Printf( "%s %s (%u) 1=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0x1 );
       
    46 	    TApaTaskList taskList( iCoeEnv->WsSession() );
       
    47 	    TApaTask task( taskList.FindApp( _L("autolock.exe" )) );
       
    48 	    if ( !task.Exists() )
       
    49 	        {
       
    50 	        RApaLsSession ls;                   
       
    51 	        User::LeaveIfError(ls.Connect());   
       
    52 	        CleanupClosePushL(ls);         
       
    53 	        
       
    54 	        CApaCommandLine* commandLine = CApaCommandLine::NewLC();
       
    55 	        commandLine->SetExecutableNameL( _L("autolock.exe" ) );     
       
    56 	        commandLine->SetCommandL( EApaCommandRun );
       
    57 	        
       
    58 		    // Try to launch the application.        
       
    59 	        User::LeaveIfError(ls.StartApp(*commandLine));
       
    60 	    	  RDebug::Printf( "%s %s (%u) autolock.exe created=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0x7 );
       
    61 	        
       
    62 	        CleanupStack::PopAndDestroy(2); // commandLine, ls
       
    63 			}
       
    64 	    Exit();
       
    65 	  }
       
    66 
       
    67     INFO( "CLockAppAppUi::ConstructL started" );
       
    68 
       
    69     // start the server with the specified name
       
    70 	iLockServer = CLockAppServer::NewL( KLockAppServerName );
       
    71 	
       
    72     // status pane is should not be visible
       
    73     StatusPane()->MakeVisible( EFalse );
       
    74 
       
    75     // we need high priority even if lockapp is not in the foreground
       
    76     iEikonEnv->WsSession().ComputeMode( RWsSession::EPriorityControlDisabled );
       
    77     RThread().SetProcessPriority( EPriorityHigh );
       
    78 
       
    79     /*
       
    80      * LockApp is set as system application (Symbian terminology).
       
    81      * This means it does not get closed when system is asked to close applications.
       
    82      */
       
    83     iEikonEnv->SetSystem( ETrue );
       
    84 
       
    85 #ifdef _GLOBAL_PRIORITY_SUPPORTED
       
    86     // Enable global popup notes
       
    87     AknGlobalPopupPriorityController::EnablePriorityControlL();
       
    88     AknGlobalPopupPriorityController::AllowGlobalPopups( ETrue );
       
    89 #endif
       
    90 
       
    91     // main control storing and controling phone keylock/devicelock status
       
    92     iStateControl = CLockAppStateControl::NewL( );
       
    93 
       
    94     // the main control is given high stack priority
       
    95     // ECoeStackPriorityEnvironmentFilter-1 used to allow hw keys for keyfiler even if keypad is locked.
       
    96     AddToStackL( iStateControl, ECoeStackPriorityEnvironmentFilter-1, ECoeStackFlagStandard );
       
    97     INFO( "CLockAppAppUi::ConstructL finished" );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Default Constructor
       
   102 // ---------------------------------------------------------------------------
       
   103 CLockAppAppUi::CLockAppAppUi( )
       
   104     {
       
   105     // no implementation required
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // Destructor
       
   110 // ---------------------------------------------------------------------------
       
   111 CLockAppAppUi::~CLockAppAppUi( )
       
   112     {
       
   113 	if ( iLockServer )
       
   114 		{
       
   115 		delete iLockServer;
       
   116 		iLockServer = NULL;
       
   117 		}
       
   118     if ( iStateControl )
       
   119         {
       
   120         // remove main control from stack
       
   121         RemoveFromStack( iStateControl );
       
   122         delete iStateControl;
       
   123         iStateControl = NULL;
       
   124         }
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Returns interface to LockAppServer sessions for changing lock states
       
   129 // ---------------------------------------------------------------------------
       
   130 MLockAppStateControl* CLockAppAppUi::StateControl( )
       
   131     {
       
   132     return iStateControl;
       
   133     }
       
   134 
       
   135 #ifdef __SAP_TERMINAL_CONTROL_FW
       
   136 // ---------------------------------------------------------------
       
   137 // Handles the TARM command to unlock the phone from WindowServer.
       
   138 // ---------------------------------------------------------------
       
   139 MCoeMessageObserver::TMessageResponse CLockAppAppUi::HandleMessageL(
       
   140         TUint32 aClientHandleOfTargetWindowGroup,
       
   141         TUid aMessageUid,
       
   142         const TDesC8& aMessageParameters )
       
   143     {
       
   144     MCoeMessageObserver::TMessageResponse messageResponse( EMessageHandled);
       
   145     if ( aMessageUid.iUid == SCP_CMDUID_UNLOCK)
       
   146         {
       
   147         // For security reasons we must check from the SCP server
       
   148         // did this command originate from it.
       
   149         RSCPClient scpClient;
       
   150         if ( scpClient.Connect() == KErrNone )
       
   151             {
       
   152             CleanupClosePushL( scpClient );
       
   153             if ( scpClient.QueryAdminCmd( ESCPCommandUnlockPhone ) )
       
   154                 {
       
   155                 INFO( "CLockAppAppUi::HandleMessageL(): Admin command received, unlocking" );
       
   156                 iStateControl->DisableDevicelockL();
       
   157                 }
       
   158             else
       
   159                 {
       
   160                 INFO( "CLockAppAppUi::HandleMessageL(): Unauthorized attempt to unlock" );
       
   161                 }
       
   162             CleanupStack::PopAndDestroy(); // calls Close() on scpClient
       
   163             }
       
   164         else
       
   165             {
       
   166             INFO( "CLockAppAppUi::HandleMessageL(): Failed to connect to SCP, ignoring unlock-message." );
       
   167             }
       
   168         }
       
   169     else // aMessageUid.iUid != SCP_CMDUID_UNLOCK
       
   170         {
       
   171         messageResponse = CAknAppUi::HandleMessageL(
       
   172                 aClientHandleOfTargetWindowGroup,
       
   173                 aMessageUid,
       
   174                 aMessageParameters);
       
   175         }
       
   176     return messageResponse;
       
   177     }
       
   178 #endif // __SAP_TERMINAL_CONTROL_FW
       
   179 
       
   180 // ----------------------------------------------------------
       
   181 // Handle window-server events
       
   182 // ----------------------------------------------------------
       
   183 void CLockAppAppUi::HandleWsEventL( const TWsEvent& aEvent, CCoeControl* aDestination )
       
   184     {
       
   185 		RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   186     if ( aEvent.Type() == TRawEvent::EKeyDown )
       
   187         {
       
   188         RDebug::Printf("CLockAppAppUi::HandleWsEventL() - aEvent.Key()->iCode: %d", aEvent.Key()->iCode );
       
   189         }
       
   190 
       
   191     // call super-class
       
   192     CAknAppUi::HandleWsEventL( aEvent, aDestination );
       
   193     // propagate call
       
   194     iStateControl->HandleWsEventL( aEvent, aDestination);
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // From @c CAknAppUiBase. Overriden the parent method, because otherwise
       
   199 // the main lock state control would not receive the call, because is is not
       
   200 // window-owning control (=without window->not visible). The call is needed
       
   201 // because the main state control owns window-owning child controls.
       
   202 // ---------------------------------------------------------------------------
       
   203 void CLockAppAppUi::HandleResourceChangeL( TInt aType )
       
   204     {
       
   205     // call super-class
       
   206     CAknAppUi::HandleResourceChangeL( aType );
       
   207     // propagate call - since does not own window
       
   208     iStateControl->HandleResourceChange( aType );
       
   209     }