coreapplicationuis/SysAp/Src/sysapdefaultkeyhandler.cpp
changeset 48 2222076f5c60
parent 0 2e3d3ce01487
child 61 224b21efc2d4
equal deleted inserted replaced
40:951aeeb3da43 48:2222076f5c60
    17 
    17 
    18 
    18 
    19 #include <e32property.h>
    19 #include <e32property.h>
    20 #include <eikon.hrh>
    20 #include <eikon.hrh>
    21 #include <coemain.h>
    21 #include <coemain.h>
    22 #include <aknkeylock.h>
    22 //#include <aknkeylock.h>
    23 #include <AknTaskList.h>
    23 //#include <AknTaskList.h>
       
    24 #include "SysApTaskList.h"
    24 #include <apgtask.h>
    25 #include <apgtask.h>
    25 #include <apgcli.h>
    26 #include <apgcli.h>
    26 #include <apgwgnam.h>
    27 #include <apgwgnam.h>
    27 #include <apacmdln.h>
    28 #include <apacmdln.h>
    28 #include <AiwPoCParameters.h>
    29 #include <AiwPoCParameters.h>
    31 #include <coreapplicationuisdomainpskeys.h>
    32 #include <coreapplicationuisdomainpskeys.h>
    32 #include <PSVariables.h>
    33 #include <PSVariables.h>
    33 #include <startupdomainpskeys.h>
    34 #include <startupdomainpskeys.h>
    34 #include <hwrmdomainpskeys.h>
    35 #include <hwrmdomainpskeys.h>
    35 #include <u32hal.h>
    36 #include <u32hal.h>
    36 #include <SysAp.rsg>
    37 //#include <SysAp.rsg>
    37 #include "sysapdefaultkeyhandler.h"
    38 #include "sysapdefaultkeyhandler.h"
    38 #include "sysapcallback.h"
    39 #include "sysapcallback.h"
    39 #include "SysAp.hrh"
    40 #include "SysAp.hrh"
    40 #include "AknSgcc.h"
    41 #include <AknSgcc.h>
       
    42 //#include "sysapappui.h"
       
    43 #include <w32std.h>
    41 
    44 
    42 
    45 
    43 const TInt KModifierMask( 0 );
    46 const TInt KModifierMask( 0 );
    44 
    47 
    45 // ======== MEMBER FUNCTIONS ========
    48 // ======== MEMBER FUNCTIONS ========
    46 
    49 
    47 // ---------------------------------------------------------------------------
    50 // ---------------------------------------------------------------------------
    48 // CSysApDefaultKeyHandler::CSysApDefaultKeyHandler
    51 // CSysApDefaultKeyHandler::CSysApDefaultKeyHandler
    49 // ---------------------------------------------------------------------------
    52 // ---------------------------------------------------------------------------
    50 //
    53 //
    51 CSysApDefaultKeyHandler::CSysApDefaultKeyHandler( MSysapCallback& aCallback ) :
    54 CSysApDefaultKeyHandler::CSysApDefaultKeyHandler( MSysapCallback& aCallback ):                                                      
    52                                                      iCallback(aCallback),
    55                                                      iCallback(aCallback),
    53                                                      iCameraSupported(EFalse),
    56                                                      iCameraSupported(EFalse),
    54                                                      iCoverDisplaySupported(EFalse),
    57                                                      iCoverDisplaySupported(EFalse),
    55                                                      iKeylock(NULL),
    58 //                                                     iKeylock(NULL),
    56                                                      iCapturedEKeyCamera(0),
    59                                                      iCapturedEKeyCamera(0),
    57                                                      iCapturedEKeyTwistOpen(0),
    60                                                      iCapturedEKeyTwistOpen(0),
    58                                                      iCapturedEKeyTwistClose(0),
    61                                                      iCapturedEKeyTwistClose(0),
    59                                                      iCapturedEKeyGripOpen(0),
    62                                                      iCapturedEKeyGripOpen(0),
    60                                                      iCapturedEKeyGripClose(0),
    63                                                      iCapturedEKeyGripClose(0),
    61                                                      iCapturedEKeyPoC(0),
    64                                                      iCapturedEKeyPoC(0)
    62                                                      iAknUiServerConnected(EFalse)
    65 //                                                     iAknUiServerConnected(EFalse)
    63     {
    66     {
    64     }
    67     }
    65 
    68 
    66 // ---------------------------------------------------------------------------
    69 // ---------------------------------------------------------------------------
    67 // CSysApDefaultKeyHandler::ConstructL
    70 // CSysApDefaultKeyHandler::ConstructL
    71     {
    74     {
    72     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::ConstructL()") ) );
    75     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::ConstructL()") ) );
    73     
    76     
    74     RWindowGroup groupWin = CCoeEnv::Static()->RootWin();
    77     RWindowGroup groupWin = CCoeEnv::Static()->RootWin();
    75     User::LeaveIfError ( iCapturedEKeyCamera = groupWin.CaptureKey( EKeyCamera, KModifierMask, KModifierMask ) );
    78     User::LeaveIfError ( iCapturedEKeyCamera = groupWin.CaptureKey( EKeyCamera, KModifierMask, KModifierMask ) );
    76     User::LeaveIfError ( iCapturedEKeyTwistOpen = groupWin.CaptureKey( EKeyTwistOpen, KModifierMask, KModifierMask ) );
       
    77     User::LeaveIfError ( iCapturedEKeyTwistClose = groupWin.CaptureKey( EKeyTwistClose, KModifierMask, KModifierMask ) );   
       
    78     User::LeaveIfError ( iCapturedEKeyGripOpen = groupWin.CaptureKey( EKeyGripOpen, KModifierMask, KModifierMask ) ); 
       
    79     User::LeaveIfError ( iCapturedEKeyGripClose = groupWin.CaptureKey( EKeyGripClose, KModifierMask, KModifierMask ) ); 
       
    80     User::LeaveIfError ( iCapturedEKeyPoC = groupWin.CaptureKey( EKeyPoC, KModifierMask, KModifierMask ) ); 
       
    81     
       
    82     // flip key events don't need to be captured, because in current setup they are not real events but simulated by SysAp
       
    83     // according to notifications received from P&S key that stores flip information
       
    84     
    79     
    85     FeatureManager::InitializeLibL();
    80     FeatureManager::InitializeLibL();
    86     iCameraSupported = FeatureManager::FeatureSupported( KFeatureIdCamera );
    81     iCameraSupported = FeatureManager::FeatureSupported( KFeatureIdCamera );
    87     iCoverDisplaySupported = FeatureManager::FeatureSupported( KFeatureIdCoverDisplay );
    82     iCoverDisplaySupported = FeatureManager::FeatureSupported( KFeatureIdCoverDisplay );
    88     FeatureManager::UnInitializeLib();
    83     FeatureManager::UnInitializeLib();
    89     
    84  
    90     TKeyLockBuf lockBuf;
       
    91     iCallback.ExecQueryL( MSysapCallback::EGetKeylock, lockBuf );  
       
    92     iKeylock = lockBuf();
       
    93     
       
    94     __ASSERT_DEBUG( iKeylock, User::Panic( _L("CSysApDefaultKeyHandler::ConstructL: iKeylock not initialized"), KErrBadHandle ) );
       
    95     
       
    96     if ( iCoverDisplaySupported ) // if flip status is monitored, set the initial flip status now
       
    97         {
       
    98         TInt flipValue;
       
    99         TInt err = RProperty::Get( KPSUidHWRM, KHWRMFlipStatus, flipValue );
       
   100 
       
   101         TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::ConstructL: flipValue=%d, err=%d"), flipValue, err ) );
       
   102         
       
   103         if ( err == KErrNone )
       
   104             {
       
   105             switch ( flipValue )
       
   106                 {
       
   107                 case EPSHWRMFlipOpen:
       
   108                     SetDisplayState( ETrue );
       
   109                     break;
       
   110                     
       
   111                 case EPSHWRMFlipClosed:
       
   112                     SetDisplayState( EFalse );
       
   113                     break;
       
   114                     
       
   115                 case EPSHWRMFlipStatusUninitialized:
       
   116                 default:
       
   117                     // set display state only if the current flip position is known
       
   118                     break;
       
   119                 }
       
   120             }
       
   121         }
       
   122     }
    85     }
   123 
    86 
   124 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
   125 // CSysApDefaultKeyHandler::NewL
    88 // CSysApDefaultKeyHandler::NewL
   126 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
   127 //
    90 //
   128 CSysApDefaultKeyHandler* CSysApDefaultKeyHandler::NewL( MSysapCallback& aCallback )
    91 CSysApDefaultKeyHandler* CSysApDefaultKeyHandler::NewL(MSysapCallback& aCallback )
   129     {
    92     {
   130     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::NewL()") ) );
    93     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::NewL()") ) );
   131     
    94     
   132     CSysApDefaultKeyHandler* self = new( ELeave ) CSysApDefaultKeyHandler( aCallback) ;
    95     CSysApDefaultKeyHandler* self = new( ELeave ) CSysApDefaultKeyHandler(aCallback) ;
   133     CleanupStack::PushL( self );
    96     CleanupStack::PushL( self );
   134     self->ConstructL();
    97     self->ConstructL();
   135     CleanupStack::Pop( self );
    98     CleanupStack::Pop( self );
   136     return self;
    99     return self;
   137     }
   100     }
   142 // ---------------------------------------------------------------------------
   105 // ---------------------------------------------------------------------------
   143 //
   106 //
   144 CSysApDefaultKeyHandler::~CSysApDefaultKeyHandler()
   107 CSysApDefaultKeyHandler::~CSysApDefaultKeyHandler()
   145     {
   108     {
   146     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::~CSysApDefaultKeyHandler()") ) );
   109     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::~CSysApDefaultKeyHandler()") ) );
   147     
       
   148     iAknUiServer.Close();
       
   149     
       
   150     RWindowGroup groupWin = CCoeEnv::Static()->RootWin();
   110     RWindowGroup groupWin = CCoeEnv::Static()->RootWin();
   151     groupWin.CancelCaptureKey( iCapturedEKeyCamera );
   111     groupWin.CancelCaptureKey( iCapturedEKeyCamera );    
   152     groupWin.CancelCaptureKey( iCapturedEKeyTwistOpen );
       
   153     groupWin.CancelCaptureKey( iCapturedEKeyTwistClose );
       
   154     groupWin.CancelCaptureKey( iCapturedEKeyGripOpen );
       
   155     groupWin.CancelCaptureKey( iCapturedEKeyGripClose );
       
   156     groupWin.CancelCaptureKey( iCapturedEKeyPoC );
       
   157     
       
   158     }
   112     }
   159     
   113     
   160 
   114 
   161 // ----------------------------------------------------------------------------
   115 // ----------------------------------------------------------------------------
   162 // CSysApDefaultKeyHandler::HandleKeyEventL()
   116 // CSysApDefaultKeyHandler::HandleKeyEventL()
   174     if( aType == EEventKey )
   128     if( aType == EEventKey )
   175         {
   129         {
   176         response = EKeyWasConsumed; // set again in default case if not consumed
   130         response = EKeyWasConsumed; // set again in default case if not consumed
   177         
   131         
   178         switch ( aKeyEvent.iCode )
   132         switch ( aKeyEvent.iCode )
   179             {
   133             {                              
   180             case EKeyGripOpen:
       
   181                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyGripOpen") ) );
       
   182                 RProperty::Set( KPSUidHWRM, KHWRMGripStatus, EPSHWRMGripOpen );
       
   183                 if (!IsDeviceLocked())
       
   184                     {
       
   185                     iCallback.ExecCommandL( MSysapCallback::EResetKeyguardState );
       
   186                     iKeylock->DisableKeyLock();
       
   187                     iCallback.ExecCommandL( MSysapCallback::ECancelPowermenu );
       
   188                     }
       
   189                 // apply default light control
       
   190                 iCallback.ExecCommandL( MSysapCallback::EUpdateLights, TUpdateLightsBuf(EKeyGripOpen) );
       
   191                 break;
       
   192             
       
   193             case EKeyGripClose:
       
   194                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyGripClosed") ) );
       
   195                 RProperty::Set( KPSUidHWRM, KHWRMGripStatus, EPSHWRMGripClosed );
       
   196                 iCallback.ExecCommandL( MSysapCallback::ECancelPowermenu );
       
   197                 if ( !IsDeviceLocked() && UiReady() )
       
   198                     {
       
   199                     iKeylock->OfferKeyLock();
       
   200                     }
       
   201                 // apply default light control
       
   202                 iCallback.ExecCommandL( MSysapCallback::EUpdateLights, TUpdateLightsBuf(EKeyGripClose) );
       
   203                 break;
       
   204             
       
   205             case EKeyFlipOpen: // simulated key event
       
   206                 {
       
   207                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyFlipOpen") ) );
       
   208                 SetDisplayState( ETrue );
       
   209                 // apply default light control
       
   210                 iCallback.ExecCommandL( MSysapCallback::EUpdateLights, TUpdateLightsBuf(EKeyFlipOpen) );
       
   211                 }
       
   212                 break;
       
   213             
       
   214             case EKeyFlipClose: // simulated key event
       
   215                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyFlipClose") ) );
       
   216                 SetDisplayState( EFalse );
       
   217                 // apply default light control
       
   218                 iCallback.ExecCommandL( MSysapCallback::EUpdateLights, TUpdateLightsBuf(EKeyFlipClose) );
       
   219                 break;
       
   220                 
       
   221             case EKeyTwistOpen:
       
   222                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyTwistOpen") ) );
       
   223                 RProperty::Set( KPSUidHWRM, KHWRMTwistStatus, EPSHWRMTwistOpen );
       
   224                 break;
       
   225                 
       
   226             case EKeyTwistClose:
       
   227                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyTwistClose") ) );
       
   228                 RProperty::Set( KPSUidHWRM, KHWRMTwistStatus, EPSHWRMTwistClose );
       
   229                 break;                
       
   230 
       
   231             case EKeyCamera:
   134             case EKeyCamera:
   232                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyCamera") ) );
   135                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyCamera") ) );
   233                 if ( iCameraSupported && !IsDeviceLocked() && !DoShowKeysLockedNote() )
   136                 if ( iCameraSupported && !IsDeviceLocked() && !DoShowKeysLockedNote() )
   234                     {
   137                     {
   235                     ActivateApplicationL( KSysApCamcorderUid );
   138                     ActivateApplicationL( KSysApCamcorderUid );
   236                     }
   139                     }
   237                 break;
   140                 break;
   238                 
       
   239             case EKeyPoC:
       
   240                 TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::HandleKeyEventL: EKeyPoC") ) );
       
   241                 LaunchPocL();
       
   242                 break;                
       
   243              
       
   244             default:
   141             default:
   245                 response = EKeyWasNotConsumed;
   142                 response = EKeyWasNotConsumed;
   246                 TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::CSysApDefaultKeyHandler: key was not consumed.") ) ); 
   143                 TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::CSysApDefaultKeyHandler: key was not consumed.") ) ); 
   247                 break;
   144                 break;               
   248                     
       
   249             }
   145             }
   250         }
   146         }
   251     
   147     
   252     return response;
   148     return response;
   253 }  
   149 }  
   316 // CSysApDefaultKeyHandler::ActivateApplicationL()
   212 // CSysApDefaultKeyHandler::ActivateApplicationL()
   317 // ----------------------------------------------------------------------------
   213 // ----------------------------------------------------------------------------
   318 //
   214 //
   319 void CSysApDefaultKeyHandler::ActivateApplicationL( const TUid aUid ) const
   215 void CSysApDefaultKeyHandler::ActivateApplicationL( const TUid aUid ) const
   320     {
   216     {
       
   217     TUid check = aUid;
       
   218     
   321     TRACES( RDebug::Print( _L( "CSysApDefaultKeyHandler::ActivateApplicationL") ) );
   219     TRACES( RDebug::Print( _L( "CSysApDefaultKeyHandler::ActivateApplicationL") ) );
   322     
   220     
   323     // Applications must not be activated before reaching normal system operation state
   221     // Applications must not be activated before reaching normal system operation state
   324     if ( UiReady() )
   222     if ( UiReady() )
   325         {
   223         {
   326         CAknTaskList* apaTaskList = CAknTaskList::NewL( CCoeEnv::Static()->WsSession() );
   224         CSysApTaskList* apaTaskList = CSysApTaskList::NewLC( CCoeEnv::Static()->WsSession() );
   327         TApaTask apaTask = apaTaskList->FindRootApp( aUid ); // only root application should not be activated
   225         TApaTask apaTask = apaTaskList->FindRootApp( aUid ); // only root application should not be activated
   328         delete apaTaskList;
   226         CleanupStack::PopAndDestroy( apaTaskList );
   329         
   227                 
   330         if ( apaTask.Exists() )
   228         if ( apaTask.Exists() )
   331             {
   229             {
   332             TRACES( RDebug::Print( _L( "CSysApDefaultKeyHandler::ActivateApplicationL: application brought to foreground") ) );
   230             TRACES( RDebug::Print( _L( "CSysApDefaultKeyHandler::ActivateApplicationL: application brought to foreground") ) );
   333 #ifdef _DEBUG
   231 #ifdef _DEBUG
   334             // camery latency measurement environment instrumentation, don't remove
   232             // camery latency measurement environment instrumentation, don't remove
   335             if ( aUid == KSysApCamcorderUid )
   233             if ( aUid == KSysApCamcorderUid )
   336                 {
   234                 {
   337                 TRACES( RDebug::Print( _L("e_CAM_PRI_OFF_TO_ON 1") ) );
   235                 TRACES( RDebug::Print( _L("e_CAM_PRI_OFF_TO_ON 1") ) );
   338                 }
   236                 }
   339 #endif // _DEBUG            
   237 #endif // _DEBUG                        
   340             CAknSgcClient::MoveApp ( apaTask.WgId(), ESgcMoveAppToForeground );
   238             apaTask.BringToForeground();
   341             }
   239             }
   342         else
   240         else
   343             {
   241             {
   344             TInt err( KErrNone );
   242             TInt err( KErrNone );
   345             TApaAppInfo appInfo;
   243             TApaAppInfo appInfo;
   378 // ----------------------------------------------------------------------------
   276 // ----------------------------------------------------------------------------
   379 //
   277 //
   380 void CSysApDefaultKeyHandler::LaunchPocL()
   278 void CSysApDefaultKeyHandler::LaunchPocL()
   381     {
   279     {
   382     TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::LaunchPocL") ) );
   280     TRACES( RDebug::Print(_L("CSysApDefaultKeyHandler::LaunchPocL") ) );
   383     
   281     // not supported
   384     if ( UiReady() && !IsDeviceLocked() && !DoShowKeysLockedNote() )
   282   }
   385         {
       
   386         CAiwServiceHandler* serviceHandler = CAiwServiceHandler::NewLC();
       
   387         serviceHandler->AttachL( R_POC_AIW_INTEREST );
       
   388             
       
   389         CAiwGenericParamList* inParams = CAiwGenericParamList::NewLC();
       
   390         inParams->AppendL(TAiwGenericParam( EGenericParamPoCLaunchView, TAiwVariant(EAiwPoCMainView)));
       
   391         serviceHandler->ExecuteServiceCmdL( KAiwCmdPoC, *inParams, serviceHandler->OutParamListL());
       
   392         
       
   393         CleanupStack::PopAndDestroy( inParams );
       
   394         CleanupStack::PopAndDestroy( serviceHandler);
       
   395         }
       
   396     }
       
   397     
   283     
   398 // ----------------------------------------------------------------------------
   284 // ----------------------------------------------------------------------------
   399 // CSysApDefaultKeyHandler::IsDeviceLocked()
   285 // CSysApDefaultKeyHandler::IsDeviceLocked()
   400 // ----------------------------------------------------------------------------
   286 // ----------------------------------------------------------------------------
   401 TBool CSysApDefaultKeyHandler::IsDeviceLocked() const    
   287 TBool CSysApDefaultKeyHandler::IsDeviceLocked() const    
   449     
   335     
   450     TInt err(KErrNone);
   336     TInt err(KErrNone);
   451     
   337     
   452     if ( !iAknUiServerConnected )
   338     if ( !iAknUiServerConnected )
   453         {
   339         {
   454         err = iAknUiServer.Connect();
   340 /*        err = iAknUiServer.Connect();
   455         
   341         
   456         if ( err != KErrNone )
   342         if ( err != KErrNone )
   457             {
   343             {
   458             TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::DoShowKeysLockedNote: RAknUiServer::Connect failed, err=%d"), err ) );
   344  //           TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::DoShowKeysLockedNote: RAknUiServer::Connect failed, err=%d"), err ) );
   459             return ETrue; // assume that keypad/device is locked
   345             return ETrue; // assume that keypad/device is locked
   460             }
   346             }
   461         iAknUiServerConnected = ETrue;            
   347         iAknUiServerConnected = ETrue;            
   462         }
   348   */      }
   463     
   349     
   464     TBool keysLocked;
   350     TBool keysLocked = EFalse;
   465     err = iAknUiServer.ShowKeysLockedNote( keysLocked );
   351 /*    err = iAknUiServer.ShowKeysLockedNote( keysLocked );
   466     
   352     
   467     if ( err != KErrNone )
   353     if ( err != KErrNone )
   468         {
   354         {
   469         TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::DoShowKeysLockedNote: RAknUiServer::ShowKeysLockedNote failed, err=%d"), err ) );
   355         TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::DoShowKeysLockedNote: RAknUiServer::ShowKeysLockedNote failed, err=%d"), err ) );
   470         keysLocked = ETrue; // assume that keypad/device is locked
   356         keysLocked = ETrue; // assume that keypad/device is locked
   471         }
   357         }
   472         
   358  */       
   473     return keysLocked;        
   359     return keysLocked;        
   474     }
   360     }
   475 
   361 
   476 // ----------------------------------------------------------------------------
   362 // ----------------------------------------------------------------------------
   477 // CSysApDefaultKeyHandler::IsDeviceModeKey
   363 // CSysApDefaultKeyHandler::IsDeviceModeKey
   498 
   384 
   499     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::IsDeviceModeKey: aKeyEvent.iCode=%d, response=%d"), aKeyEvent.iCode, response ) );
   385     TRACES( RDebug::Print( _L("CSysApDefaultKeyHandler::IsDeviceModeKey: aKeyEvent.iCode=%d, response=%d"), aKeyEvent.iCode, response ) );
   500     
   386     
   501     return response;        
   387     return response;        
   502     }
   388     }
       
   389 
       
   390 
       
   391