terminalsecurity/SCP/SCPServer/src/SCPLockSettingEventHandler.cpp
changeset 0 b497e44ab2fc
child 12 9e9792ae22e3
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2000 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: Implementation of terminalsecurity components
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <e32debug.h>
       
    22 
       
    23 #include <etelmm.h>
       
    24 #include <rmmcustomapi.h>
       
    25 
       
    26 
       
    27 
       
    28 #include    <e32property.h>
       
    29 #include    <PSVariables.h>   // Property values
       
    30 #include 	<coreapplicationuisdomainpskeys.h>
       
    31 
       
    32 
       
    33  
       
    34 #include <mmtsy_names.h>
       
    35 #include <w32std.h>
       
    36 #include <apgtask.h>
       
    37 
       
    38 #include "SCPLockSettingEventHandler.h"
       
    39 #include "SCPSession.h"
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // void CSCPLockSettingEventHandler::CSCPLockSettingEventHandler()
       
    45 // C++ default constructor
       
    46 // 
       
    47 // Status : Approved
       
    48 // ---------------------------------------------------------
       
    49 
       
    50 CSCPLockSettingEventHandler::CSCPLockSettingEventHandler( 
       
    51             const RMessage2& aLockMessage, 
       
    52             CSCPSession* aSession,
       
    53             TBool aState,
       
    54             TBool aAutolock,
       
    55             CSCPServer* aServer
       
    56             )
       
    57     :CSCPLockEventHandler( aServer ),
       
    58     iLockMessage( aLockMessage ),
       
    59     iSession( aSession ),
       
    60     iState( aState ),
       
    61     iAutolock( aAutolock ),
       
    62     iWaitingForAck( EFalse ),
       
    63     iAckReceived( EFalse ),
       
    64     iUnlockSent( EFalse ),
       
    65     iMessageStatus( KErrNone )
       
    66 	{
       
    67 	Dprint( (_L("--> CSCPLockSettingEventHandler::CSCPLockSettingEventHandler()") ));
       
    68 	
       
    69 	Dprint( (_L("<-- CSCPLockSettingEventHandler::CSCPLockSettingEventHandler()") ));
       
    70 	}
       
    71 
       
    72 
       
    73 // ---------------------------------------------------------
       
    74 // void CSCPLockSettingEventHandler::ConstructL()
       
    75 // Symbian 2nd phase constructor
       
    76 // 
       
    77 // Status : Approved
       
    78 // ---------------------------------------------------------
       
    79 
       
    80 void CSCPLockSettingEventHandler::ConstructL()
       
    81     {
       
    82     Dprint( (_L("--> CSCPLockSettingEventHandler::ConstructL()") ));
       
    83    
       
    84     BaseConstructL();         		
       
    85             
       
    86     Dprint( (_L("<-- CSCPLockSettingEventHandler::ConstructL()") ));
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // void CSCPLockSettingEventHandler::StartL()
       
    92 // Initiates the lock/unlock operation.
       
    93 // 
       
    94 // Status : Approved
       
    95 // ---------------------------------------------------------
       
    96 
       
    97 void CSCPLockSettingEventHandler::StartL()
       
    98     {
       
    99 #ifndef __WINS__
       
   100 
       
   101     // If this is an unlock call, we must check whether SMS Lock or Autolock is active
       
   102     // before disabling the DOS side lock.
       
   103     if ( ( !iState ) && 
       
   104 	     ( ( CSCPSession::IsSMSLockActiveL() ) || 
       
   105 	     ( iSession->IsAutolockActive() ) ) 
       
   106 	     )
       
   107         {
       
   108         Dprint( (_L("CSCPLockSettingEventHandler::ConstructL(): AL or SMS lock active,\
       
   109 	         leaving DOS lock on.") ));
       
   110 	    
       
   111         // Just unlock Symbian side, if Autolock handling specified
       
   112         if ( iAutolock )
       
   113             {        
       
   114             TRAPD( err, SetAutolockStateL( EFalse ) );
       
   115 	    
       
   116             if ( err == KErrNone )
       
   117                 {
       
   118                  // Inform the session-class that an unlock-message has been sent
       
   119                  // (the server won't respond to Autolock until the handler finishes)
       
   120                  iSession->LockOperationPending( ESCPCommandUnlockPhone, &iStatus );
       
   121                  iUnlockSent = ETrue;	                	            
       
   122                  SetActive(); // Wait for the session-class to complete this call
       
   123                 }
       
   124             else 
       
   125                 {
       
   126                 // Failed to signal autolock, this call is complete
       
   127                 iLockMessage.Complete( err );    
       
   128                 iSession->LockOperationCompleted();                  
       
   129                 }	        
       
   130             }
       
   131         }
       
   132     else // Set both the DOS side and the Symbian side locks, starting with SetLockSetting
       
   133         {
       
   134         RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
       
   135     
       
   136         // Run the SetLockSetting-command, either to activate or to disable the lock
       
   137         Dprint( (_L("CSCPLockSettingEventHandler::ConstructL():\
       
   138           Running SetLockSetting") ));
       
   139 
       
   140         if ( iState )
       
   141             {
       
   142             iPhone->SetLockSetting( iStatus, lockType, RMobilePhone::ELockSetEnabled );	
       
   143             }
       
   144         else
       
   145             {
       
   146             iPhone->SetLockSetting( iStatus, lockType, RMobilePhone::ELockSetDisabled );	
       
   147             }	    
       
   148 
       
   149         Dprint( (_L("CSCPLockSettingEventHandler::ConstructL(): Running SetActive") ));	   
       
   150                         
       
   151         SetActive();	
       
   152         }
       
   153 
       
   154 #else // __WINS__. In emulator we only care about Autolock
       
   155 	
       
   156     if ( iAutolock )
       
   157         {
       
   158         // Autolock activation/deactivation was requested
       
   159         TRAPD( err, SetAutolockStateL( iState ) );
       
   160 
       
   161         if ( err != KErrNone )
       
   162             {
       
   163             // If the call failed, send the result as the message status
       
   164             iMessageStatus = err;
       
   165             }
       
   166         else if ( !iState )
       
   167             {
       
   168             // Inform the session-class that an unlock-message has been sent
       
   169             // (the server won't respond to Autolock until the handler finishes)                    
       
   170             iSession->LockOperationPending( ESCPCommandUnlockPhone, &iStatus );
       
   171             iUnlockSent = ETrue;	                	          
       
   172             SetActive(); // Wait for the session-class to complete this call
       
   173             }
       
   174         else
       
   175             {
       
   176             // This call is complete, Autolock activated
       
   177             iLockMessage.Complete( KErrNone );    
       
   178             iSession->LockOperationCompleted();
       
   179             }	
       
   180         }
       
   181 	      
       
   182 #endif // __WINS__    
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------
       
   187 // void CSCPLockSettingEventHandler::NewL()
       
   188 // Static constructor.
       
   189 // 
       
   190 // Status : Approved
       
   191 // ---------------------------------------------------------
       
   192 
       
   193 CSCPLockSettingEventHandler* CSCPLockSettingEventHandler::NewL(
       
   194         const RMessage2& aLockMessage, 
       
   195         CSCPSession* aSession,
       
   196         TBool aState,
       
   197         TBool aAutolock,
       
   198         CSCPServer* aServer )
       
   199     {
       
   200     Dprint( (_L("--> CSCPLockSettingEventHandler::NewL()") ));
       
   201 
       
   202     CSCPLockSettingEventHandler* self = CSCPLockSettingEventHandler::NewLC( aLockMessage,
       
   203 	      aSession, aState, aAutolock, aServer );
       
   204     CleanupStack::Pop( self ); 
       
   205 	
       
   206     Dprint( (_L("<-- CSCPLockSettingEventHandler::NewL()") ));
       
   207     return self;	
       
   208     }
       
   209 	
       
   210 
       
   211 // ---------------------------------------------------------
       
   212 // void CSCPLockSettingEventHandler::NewLC()
       
   213 // Static constructor, leaves object pointer to the cleanup stack.
       
   214 // 
       
   215 // Status : Approved
       
   216 // ---------------------------------------------------------
       
   217 
       
   218 CSCPLockSettingEventHandler* CSCPLockSettingEventHandler::NewLC(
       
   219         const RMessage2& aLockMessage, 
       
   220         CSCPSession* aSession,
       
   221         TBool aState,
       
   222         TBool aAutolock,
       
   223         CSCPServer* aServer )
       
   224     {
       
   225     Dprint( (_L("--> CSCPLockSettingEventHandler::NewLC()") ));
       
   226 
       
   227     CSCPLockSettingEventHandler* self = new (ELeave) CSCPLockSettingEventHandler( 
       
   228 	      aLockMessage, aSession, aState, aAutolock, aServer );
       
   229 
       
   230     CleanupStack::PushL( self );
       
   231     self->ConstructL();	
       
   232     
       
   233     Dprint( (_L("<-- CSCPLockSettingEventHandler::NewLC()") ));
       
   234     return self;	
       
   235     }
       
   236 
       
   237     
       
   238 // ---------------------------------------------------------
       
   239 // void CSCPLockSettingEventHandler::AckReceived()
       
   240 // Destructor
       
   241 // 
       
   242 // Status : Approved
       
   243 // ---------------------------------------------------------
       
   244 
       
   245 CSCPLockSettingEventHandler::~CSCPLockSettingEventHandler()
       
   246     {
       
   247     Dprint( (_L("--> CSCPLockSettingEventHandler::~CSCPLockSettingEventHandler()") ));
       
   248          
       
   249     if ( IsActive() )
       
   250         {
       
   251         Dprint( (_L("CSCPLockSettingEventHandler::\
       
   252                CSCPLockSettingEventHandler(): Cancelling call") ));
       
   253         Cancel();
       
   254         }
       
   255            
       
   256     Dprint( (_L("<-- CSCPLockSettingEventHandler::~CSCPLockSettingEventHandler()") ));
       
   257     }
       
   258 
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // void CSCPLockSettingEventHandler::AckReceived()
       
   262 // Sets the ackReceived member to indicate that the call has
       
   263 // already been acknowledged.
       
   264 // 
       
   265 // Status : Approved
       
   266 // ---------------------------------------------------------
       
   267 
       
   268 void CSCPLockSettingEventHandler::AckReceived()
       
   269     {
       
   270     iAckReceived = ETrue;    
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------
       
   274 // void CSCPLockSettingEventHandler::SetAutolockStateL( TBool aActive )
       
   275 // Activates Autolock by signalling the SA/PubSub event, or
       
   276 // deactivates it by sending it the deactivation message.
       
   277 // 
       
   278 // Status : Approved
       
   279 // ---------------------------------------------------------
       
   280 
       
   281 void CSCPLockSettingEventHandler::SetAutolockStateL( TBool aActive )
       
   282     {
       
   283     if ( aActive ) 
       
   284         {
       
   285         // Activation call, set the admin flag and signal the lock event        
       
   286 
       
   287         TInt tarmFlag = 0;        
       
   288         TInt tRet = RProperty::Get( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
       
   289         
       
   290         if ( tRet == KErrNone )
       
   291             {
       
   292             tarmFlag |= KSCPFlagAdminLock;
       
   293             tRet = RProperty::Set( KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID, tarmFlag );
       
   294             }
       
   295 
       
   296         if ( tRet != KErrNone )
       
   297             {
       
   298             #if defined(_DEBUG)
       
   299             RDebug::Print(_L("CSCPLockSettingEventHandler::SetAutolockStateL():\
       
   300                 FAILED to set TARM Admin Flag"));
       
   301             #endif
       
   302             }                    
       
   303 #ifdef RD_REMOTELOCK        
       
   304 			// ERemoteLocked is meant for Remote Locking using SMS. Mfe/USB charging needed the lock status to be Manual.
       
   305 	        tRet = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EManualLocked );
       
   306 	 
       
   307 #else //RD_REMOTELOCK
       
   308 		
       
   309 	        tRet = RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOn );
       
   310 	                                                 
       
   311 #endif//RD_REMOTELOCK	 	
       
   312       
       
   313    	    if ( tRet == KErrNone )
       
   314    	        {
       
   315        	    Dprint( (_L("CSCPLockSettingEventHandler::SetAutolockStateL():\
       
   316    	            Autolock signalled OK") ));   	        
       
   317    	        }
       
   318    	    else
       
   319    	        {
       
   320        	    Dprint( (_L("CSCPLockSettingEventHandler::SetAutolockStateL():\
       
   321    	            FAILED to signal Autolock: %d"), tRet ));
       
   322    	        }   	    
       
   323 	    }
       
   324     else
       
   325         {
       
   326         // Deactivation call, send the deactivation message to Autolock
       
   327         RWsSession wsSession;
       
   328         if ( wsSession.Connect() != KErrNone )
       
   329            {
       
   330            Dprint( (_L("CSCPLockSettingEventHandler::SetAutolockStateL():\
       
   331                WsSession connection failed") ));        
       
   332            User::Leave( KErrGeneral );
       
   333            }
       
   334         CleanupClosePushL( wsSession );
       
   335 
       
   336         TApaTaskList taskList( wsSession );
       
   337         TApaTask task = taskList.FindApp( TUid::Uid( KSCPServerSIDAutolock ) ); // Autolock
       
   338 
       
   339         if ( task.Exists() )
       
   340             {
       
   341             Dprint( (_L("CSCPLockSettingEventHandler::SetAutolockStateL():\
       
   342                Autolock task found, sending msg") ));        
       
   343             // No parameters, just a dummy buffer
       
   344             TBuf8<8> buf;
       
   345             buf.Zero();            
       
   346             const TPtrC8& message = buf;                      
       
   347             User::LeaveIfError( 
       
   348                task.SendMessage( TUid::Uid( SCP_CMDUID_UNLOCK ), message ) 
       
   349                );           
       
   350             }
       
   351         else
       
   352             {
       
   353             Dprint( (_L("CSCPLockSettingEventHandler::SetAutolockStateL():\
       
   354                Autolock task not found") ));
       
   355             User::Leave( KErrNotFound );
       
   356             }
       
   357                   
       
   358         CleanupStack::PopAndDestroy(); // wsSession	                
       
   359         }    
       
   360     }
       
   361 
       
   362 
       
   363 // ---------------------------------------------------------
       
   364 // void CSCPLockSettingEventHandler::RunL()
       
   365 // Checks the status, and activates/deactivates autolock on success.
       
   366 // 
       
   367 // Status : Approved
       
   368 // ---------------------------------------------------------
       
   369 //
       
   370 void CSCPLockSettingEventHandler::RunL()
       
   371     {
       
   372     TInt ret = iStatus.Int();
       
   373     TBool finalCall = ETrue;
       
   374     TBool startFinalPhase = EFalse;
       
   375     
       
   376     Dprint( (_L("--> CSCPLockSettingEventHandler::RunL()") ));
       
   377      
       
   378     if ( iUnlockSent ) // Received an acknowledgement for the unlock-message
       
   379         {
       
   380         if ( ret == KErrNone ) 
       
   381             {
       
   382             Dprint( (_L("CSCPLockSettingEventHandler::RunL(): Unlock ack received") ));
       
   383             }
       
   384         else if ( ret == KErrCancel ) 
       
   385             {
       
   386             Dprint( (_L("CSCPLockSettingEventHandler::RunL(): Unlock call TIMEOUT") ));
       
   387             iMessageStatus = ret;
       
   388             }
       
   389         }    
       
   390     else if ( iWaitingForAck ) // Received an acknowledgement for the set lock setting call
       
   391         {
       
   392         if ( ret == KErrNone ) 
       
   393             {
       
   394             Dprint( (_L("CSCPLockSettingEventHandler::RunL():\
       
   395                 Acknowledgement received") ));            
       
   396             startFinalPhase = ETrue;
       
   397             }
       
   398         else if ( ret == KErrCancel ) 
       
   399             {
       
   400             Dprint( (_L("CSCPLockSettingEventHandler::RunL():\
       
   401                 Lock setting call TIMEOUT") ));
       
   402             iMessageStatus = ret;
       
   403             }            
       
   404         }
       
   405     else // SetLockSetting completed
       
   406         {        
       
   407         // Save the status of the lock setting call
       
   408         iMessageStatus = ret;
       
   409 
       
   410         Dprint( (_L("CSCPLockSettingEventHandler::RunL():\
       
   411             SetLockSetting returned: %d"), ret ));
       
   412       
       
   413         if ( iAckReceived )
       
   414             {
       
   415             Dprint( (_L("CSCPLockSettingEventHandler::RunL(): Ack already received") ));  
       
   416             startFinalPhase = ETrue;
       
   417             }
       
   418         else
       
   419             {
       
   420             iSession->LockOperationPending( ESCPCommandLockPhone, &iStatus );
       
   421             iWaitingForAck = ETrue;	                
       
   422             finalCall = EFalse;
       
   423 	        SetActive(); // Wait for the session-class to complete this call
       
   424             }                	    
       
   425         }
       
   426 	   
       
   427     if ( ( startFinalPhase ) && ( iAutolock ) )
       
   428         {
       
   429         // Autolock activation/deactivation was requested
       
   430         TRAPD( err, SetAutolockStateL( iState ) );
       
   431     
       
   432         if ( err != KErrNone )
       
   433             {
       
   434             // If the call failed, send the result as the message status
       
   435             iMessageStatus = err;
       
   436             }
       
   437         else if ( !iState )
       
   438             {
       
   439             // Inform the session-class that an unlock-message has been sent
       
   440             // (the server won't respond to Autolock until the handler finishes)                    
       
   441             iSession->LockOperationPending( ESCPCommandUnlockPhone, &iStatus );
       
   442             iUnlockSent = ETrue;	                
       
   443             finalCall = EFalse;
       
   444             SetActive(); // Wait for the session-class to complete this call
       
   445             }
       
   446         }
       
   447 	   
       
   448     if ( finalCall ) 
       
   449         {
       
   450         Dprint( (_L("CSCPLockSettingEventHandler::RunL():\
       
   451             Completing set lock state call, status: %d"), ret ));         			
       
   452         
       
   453         iLockMessage.Complete( iMessageStatus ); 	    
       
   454         // Inform the SessionBase class that this operation is complete
       
   455         iSession->LockOperationCompleted();
       
   456         }          
       
   457    
       
   458     Dprint( (_L("<-- CSCPLockSettingEventHandler::RunL()") ));
       
   459     }
       
   460     
       
   461 // ---------------------------------------------------------
       
   462 // void CSCPLockSettingEventHandler::DoCancel()
       
   463 // Cancel function, aborts the TSY request
       
   464 // 
       
   465 // Status : Approved
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 void CSCPLockSettingEventHandler::DoCancel()
       
   469     {
       
   470     Dprint( (_L("--> CSCPLockSettingEventHandler::DoCancel()") ));
       
   471 
       
   472     if ( !iWaitingForAck )
       
   473         {
       
   474         iPhone->CancelAsyncRequest( EMobilePhoneSetLockSetting );
       
   475         }        
       
   476 
       
   477     iLockMessage.Complete( KErrCancel );    
       
   478     iSession->LockOperationCompleted();  
       
   479 
       
   480     Dprint( (_L("<-- CSCPLockSettingEventHandler::DoCancel()") ));
       
   481     }
       
   482    
       
   483    
       
   484 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   485 
       
   486 //  End of File  
       
   487