terminalsecurity/SCP/SCPClient/src/SCPClient.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 25 b183ec05bd8c
child 27 5cc2995847ea
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
    17 
    17 
    18 
    18 
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <e32svr.h>
    21 #include <e32svr.h>
       
    22 #include <bautils.h>
    22 #include <e32math.h>
    23 #include <e32math.h>
    23 #include <e32uid.h>
    24 #include <e32uid.h>
       
    25 #include <barsc.h>
    24 #include <AknGlobalNote.h>
    26 #include <AknGlobalNote.h>
    25 #include <aknnotewrappers.h> 
    27 #include <aknnotewrappers.h> 
    26 #include <AknQueryDialog.h>
    28 #include <AknQueryDialog.h>
    27 #include <AknGlobalConfirmationQuery.h>
    29 #include <AknGlobalConfirmationQuery.h>
    28 
    30 
    29 #include "SCPClient.h"
    31 #include "SCPClient.h"
       
    32 #include "SCPQueryDialog.h"
    30 #include "SCPParamObject.h"
    33 #include "SCPParamObject.h"
    31 
    34 
    32 #include <scpnotifier.rsg>
    35 #include <SCPNotifier.rsg>
    33 #include "SCP_IDs.h"
    36 #include "SCP_IDs.h"
    34 
    37 
    35 #include <centralrepository.h>
    38 #include <centralrepository.h>
    36 #include "SCPLockCode.h"
    39 #include "SCPLockCode.h"
    37 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
    40 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
    38 #include <TerminalControl3rdPartyAPI.h>
    41 #include <TerminalControl3rdPartyAPI.h>
    39 #include <SCPServerInterface.h>
    42 #include <SCPServerInterface.h>
       
    43 #include <SecUi.rsg>
       
    44 #include <scptimestamppluginlang.rsg>
    40 #include <secui.hrh>
    45 #include <secui.hrh>
    41 #include <StringLoader.h>
    46 #include <StringLoader.h>
    42 #include <bautils.h>
    47 #include <bautils.h>
    43 //#endif // DEVICE_LOCK_ENHANCEMENTS
    48 //#endif // DEVICE_LOCK_ENHANCEMENTS
       
    49 #include <DevManInternalCRKeys.h>
    44 
    50 
    45 #include <featmgr.h>
    51 #include <featmgr.h>
    46 #include "SCPDebug.h"
    52 #include "SCPDebug.h"
    47 #include <e32property.h>
    53 #include <e32property.h>
       
    54 #include <SCPPServerPluginDefs.hrh>
       
    55 #include <apgtask.h>
       
    56 #include    <e32property.h>
       
    57 #include    <PSVariables.h>
       
    58 #include    <coreapplicationuisdomainpskeys.h>
       
    59 
    48 /*#ifdef _DEBUG
    60 /*#ifdef _DEBUG
    49 #define __SCP_DEBUG
    61 #define __SCP_DEBUG
    50 #endif // _DEBUG
    62 #endif // _DEBUG
    51 
    63 
    52 // Define this so the precompiler in CW 3.1 won't complain about token pasting,
    64 // Define this so the precompiler in CW 3.1 won't complain about token pasting,
    59 #define Dprint(a)
    71 #define Dprint(a)
    60 #endif // _DEBUG*/
    72 #endif // _DEBUG*/
    61 
    73 
    62 static const TUint KDefaultMessageSlots = 3;
    74 static const TUint KDefaultMessageSlots = 3;
    63 static const TInt KSCPConnectRetries( 2 );
    75 static const TInt KSCPConnectRetries( 2 );
    64 
    76 const TInt KLockedbyLawmo (30);
    65 
    77 
    66 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
    78 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
    67 _LIT( KDriveZ, "Z:" );
    79 _LIT( KDriveZ, "Z:" );
    68 _LIT( KSCPResourceFilename, "\\Resource\\SCPNotifier.RSC" );
    80 _LIT( KSCPResourceFilename, "\\Resource\\SCPNotifier.RSC" );
    69 _LIT( KSCPSecUIResourceFilename, "\\Resource\\SecUi.RSC" );
    81 _LIT( KSCPSecUIResourceFilename, "\\Resource\\SecUi.RSC" );
       
    82 _LIT( KSCPTimestampPluginResFilename, "\\Resource\\SCPTimestampPluginLang.rsc");
    70 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
    83 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
    71 
    84 
    72 // Uid for the application; this should match the mmp file
    85 // Uid for the application; this should match the mmp file
    73 const TUid KServerUid3 = {0x10207836};
    86 const TUid KServerUid3 = {0x10207836};
    74 
    87 
   167     return result;
   180     return result;
   168     }
   181     }
   169 
   182 
   170 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
   183 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
   171 
   184 
       
   185 // ---------------------------------------------------------
       
   186 // RunDialog() Dialog execution wrapper
       
   187 // Initialize and run the query dialog
       
   188 // Returns: TInt: The return code from the dialog.
       
   189 //          Can leave with a generic error code.
       
   190 //
       
   191 // Status : Approved
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 TInt RunDialogL( TDes& aReplyBuf,
       
   195                 RSCPClient::TSCPButtonConfig aButtonsShown,
       
   196                 TInt aMinLen,
       
   197                 TInt aMaxLen,
       
   198                 TUint aResId = 0,
       
   199                 TDesC* aPrompt = NULL,
       
   200                 TBool aECSSupport = EFalse,
       
   201                 CSCPQueryDialog :: TKeypadContext aContext = CSCPQueryDialog :: ENumeric
       
   202               )
       
   203     {
       
   204     Dprint(_L("[RSCPClient]-> RunDialogL() >>> "));
       
   205     Dprint(_L("[RSCPClient]-> RunDialogL() aContext = %d "), aContext);
       
   206     
       
   207     FeatureManager::InitializeLibL();
       
   208     if(!FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
       
   209 	{
       
   210 			FeatureManager::UnInitializeLib();
       
   211 		return KErrNotSupported;
       
   212 	}
       
   213 		FeatureManager::UnInitializeLib();
       
   214     if ( ( aPrompt == NULL ) && ( aResId == 0 ) )
       
   215         {
       
   216         return KErrArgument;
       
   217         }
       
   218     Dprint((_L("--> SCPClient::RunDialogL() start the dialog")));    
       
   219     CSCPQueryDialog* dialog = new (ELeave) CSCPQueryDialog( 
       
   220         aReplyBuf,
       
   221         aButtonsShown,
       
   222         aMinLen,
       
   223         aMaxLen,
       
   224         aECSSupport,
       
   225         aContext
       
   226         ); 
       
   227         
       
   228     CleanupStack::PushL( dialog );            
       
   229     
       
   230     if ( aResId != 0 )
       
   231         {
       
   232         // Load and set the prompt from a resource ID
       
   233         HBufC* prompt;
       
   234         
       
   235         prompt = StringLoader::LoadLC( aResId );   
       
   236         dialog->SetPromptL( *prompt ); 
       
   237         
       
   238         CleanupStack::PopAndDestroy( prompt );       
       
   239         }
       
   240     else
       
   241         {
       
   242         // Set the given prompt
       
   243         dialog->SetPromptL( *aPrompt );
       
   244         }        
       
   245     Dprint((_L("-- SCPClient::RunDialogL() dialog->ExecuteLD")));
       
   246     TInt ret = dialog->ExecuteLD( R_SCP_CODE_QUERY );
       
   247     
       
   248     CleanupStack::Pop( dialog );
       
   249     Dprint( (_L("-- SCPClient::RunDialogL(): ret val %d"), ret));
       
   250     return ret;
       
   251     }
       
   252     
   172 
   253 
   173 // ---------------------------------------------------------
   254 // ---------------------------------------------------------
   174 // LoadResources() Resource loader
   255 // LoadResources() Resource loader
   175 // Load the resources for the library
   256 // Load the resources for the library
   176 // Returns: TInt: A generic error code.
   257 // Returns: TInt: A generic error code.
   393 // ---------------------------------------------------------
   474 // ---------------------------------------------------------
   394 //
   475 //
   395 EXPORT_C TInt RSCPClient::SetPhoneLock( TBool aLocked )
   476 EXPORT_C TInt RSCPClient::SetPhoneLock( TBool aLocked )
   396     {
   477     {
   397     Dprint( (_L("--> RSCPClient::SetPhoneLock( %d)"), aLocked ));
   478     Dprint( (_L("--> RSCPClient::SetPhoneLock( %d)"), aLocked ));
   398             
   479     TInt autolockState = -1;
       
   480     RProperty aProperty;
       
   481     aProperty.Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, autolockState);
       
   482     Dprint( (_L("RSCPClient::SetPhoneLock()Autolock state before %d"), autolockState ));
       
   483 
       
   484     if((aLocked==0)&&(autolockState != EAutolockStatusUninitialized))
       
   485     InformAutolockTask();            
       
   486     Dprint( (_L("RSCPClient sendreceive") ));
   399     TInt ret = SendReceive(ESCPServSetPhoneLock, TIpcArgs( aLocked ) );
   487     TInt ret = SendReceive(ESCPServSetPhoneLock, TIpcArgs( aLocked ) );
   400   
   488     Dprint( (_L("RSCPClient sendreceive done") ));
       
   489     aProperty.Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, autolockState);
       
   490     Dprint( (_L("RSCPClient::SetPhoneLock()Autolock state after %d"), autolockState ));
       
   491     // Put it here because, we cant change autolock status before sendreceive 
       
   492     // Uninitialised state is Only at Bootup.
       
   493     if((autolockState == EAutolockStatusUninitialized)&&(aLocked==0)&&(ret==KErrNone))
       
   494         {
       
   495         Dprint( (_L("RSCPClient::SetPhoneLock()setting autolock status") ));
       
   496         aProperty.Set(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus, EAutolockOff);
       
   497         // This is startup and we are done with ISA unlock
       
   498         // So set the Startup cenrep key so tht it is used in SeccodeQuery
       
   499         CRepository* lRepository = NULL; 
       
   500         TInt returnv;
       
   501         TRAP(returnv, lRepository = CRepository :: NewL(KCRUidSCPLockCode));
       
   502         returnv = lRepository->Set(KSCPStartupQuery, 1);
       
   503         if(returnv==KErrNone)
       
   504         Dprint( (_L("RSCPClient::SetPhoneLock()setting KSCPStartupQuery") ));
       
   505         delete lRepository;
       
   506         }
   401     Dprint( (_L("<-- RSCPClient::SetPhoneLock(): %d"), ret ));
   507     Dprint( (_L("<-- RSCPClient::SetPhoneLock(): %d"), ret ));
   402     return ret;
   508     return ret;
       
   509     }   
       
   510 
       
   511 void RSCPClient::InformAutolockTask()
       
   512     {
       
   513     Dprint( (_L("RSCPClient::InformAutolockTask") ));
       
   514     // Deactivation call, send the deactivation message to Autolock
       
   515         RWsSession wsSession;
       
   516         if ( wsSession.Connect() != KErrNone )
       
   517            {
       
   518            Dprint( (_L("RSCPClient::InformAutolockTask():\
       
   519                WsSession connection failed") ));        
       
   520            User::Leave( KErrGeneral );
       
   521            }
       
   522         CleanupClosePushL( wsSession );
       
   523 
       
   524         TApaTaskList taskList( wsSession );
       
   525         TApaTask task = taskList.FindApp( TUid::Uid( 0x100059B5 ) ); // Autolock
       
   526 
       
   527         if ( task.Exists() )
       
   528             {
       
   529             Dprint( (_L("RSCPClient::InformAutolockTask():\
       
   530                Autolock task found, sending msg") ));        
       
   531             // No parameters, just a dummy buffer
       
   532             TBuf8<8> buf;
       
   533             buf.Zero();            
       
   534             const TPtrC8& message = buf;                      
       
   535             User::LeaveIfError( 
       
   536                task.SendMessage( TUid::Uid( SCP_CMDUID_UNLOCK+1 ), message ) 
       
   537                );           
       
   538             }
       
   539         else
       
   540             {
       
   541             Dprint( (_L("RSCPClient::InformAutolockTask():\
       
   542                Autolock task not found") ));
       
   543             User::Leave( KErrNotFound );
       
   544             }
       
   545                   
       
   546         CleanupStack::PopAndDestroy(); // wsSession
   403     }   
   547     }   
   404 
   548 
   405 // ---------------------------------------------------------
   549 // ---------------------------------------------------------
   406 // TBool RSCPClient::QueryAdminCmd( TSCPAdminCommand aCommand )
   550 // TBool RSCPClient::QueryAdminCmd( TSCPAdminCommand aCommand )
   407 // Packs the command parameter into a buffer, and propagates
   551 // Packs the command parameter into a buffer, and propagates
   482     }    
   626     }    
   483     
   627     
   484 
   628 
   485 // *********** Device lock new features ************* -->>
   629 // *********** Device lock new features ************* -->>
   486 
   630 
       
   631 // ---------------------------------------------------------
       
   632 // RSCPClient::SecCodeQuery()
       
   633 // Request the security code from the user and authenticate
       
   634 // through the server.
       
   635 // 
       
   636 // Status : Approved
       
   637 // ---------------------------------------------------------
       
   638 //
       
   639 EXPORT_C TInt RSCPClient::SecCodeQuery( RMobilePhone::TMobilePassword& aPassword, 
       
   640                                         TSCPButtonConfig aButtonsShown, 
       
   641                                         TBool aECSSupport,
       
   642                                         TInt aFlags )
       
   643     {
       
   644     TInt lErr = KErrNone;
       
   645     TInt lStatus = KErrNone;
       
   646     TInt lResFileSCP = NULL;
       
   647     TInt lResFileSecUi = NULL;
       
   648     Dprint( (_L("--> RSCPClient::SecCodeQuery(%d, %d"), aButtonsShown, aECSSupport ));  
       
   649     TRAP(lErr, lStatus = SetSecurityCodeL(aPassword, aButtonsShown, aECSSupport, aFlags, lResFileSCP, lResFileSecUi));    
       
   650    
       
   651     
       
   652     if(lResFileSCP) {
       
   653         CCoeEnv :: Static()->DeleteResourceFile(lResFileSCP);
       
   654 	}
       
   655     
       
   656     if(lResFileSecUi) {
       
   657     
       
   658     
       
   659         CCoeEnv :: Static()->DeleteResourceFile(lResFileSecUi);
       
   660     }
       
   661     
       
   662     Dprint((_L("<-- RSCPClient::SecCodeQuery(): lStatus= %d, lErr= %d"), lStatus, lErr));
       
   663     CRepository* lRepository = NULL;  
       
   664     TInt startup = 0;
       
   665     TInt returnv;
       
   666     TRAP(returnv, lRepository = CRepository :: NewL(KCRUidSCPLockCode));
       
   667     returnv = lRepository->Get(KSCPStartupQuery, startup);
       
   668     if(returnv == KErrNone)
       
   669     Dprint( (_L("RSCPClient::SecCodeQuery()KSCPStartupQuery get done")));
       
   670     lRepository->Set(KSCPStartupQuery, 0);
       
   671     delete lRepository;
       
   672     Dprint((_L("RSCPClient::SecCodeQuery(): startup ? %d"), startup ));
       
   673     //Check if this is Startup Query and tht device is remote unlocked now ?
       
   674     if(startup)
       
   675         {
       
   676         Dprint((_L("[RSCPClient] SecCodeQuery() startup remote Unlocked")));
       
   677         return KErrNone;
       
   678         }
       
   679     else
       
   680     return (lErr != KErrNone) ? lErr : lStatus;
       
   681 }
       
   682 
       
   683 // ---------------------------------------------------------
       
   684 // RSCPClient::ChangeCodeRequest()
       
   685 // Show the current code query dialog and continue in GetNew
       
   686 // CodeAndChange.
       
   687 // 
       
   688 // Status : Approved
       
   689 // ---------------------------------------------------------
       
   690 //
       
   691 EXPORT_C TInt RSCPClient::ChangeCodeRequest()
       
   692     {
       
   693     Dprint((_L("[RSCPClient] ChangeCodeRequest() >>>")));
       
   694     
       
   695     if(EFalse == isFlagEnabled) {
       
   696         Dprint((_L("[RSCPClient]-> ChangeCodeRequest(): ERROR: Function not supported in this variant")));
       
   697         User :: Invariant();
       
   698         return KErrNotSupported;
       
   699 	}
       
   700 
       
   701     TInt lRet(KErrNone);
       
   702     TInt lErr(KErrNone);
       
   703 
       
   704     TInt resourceFileSCP(NULL);
       
   705     TInt resourceFileSecUi(NULL);
       
   706 
       
   707     // Check if the code change is allowed
       
   708     {
       
   709         HBufC8* addParamsHBuf = NULL;
       
   710         TRAP(lErr, addParamsHBuf = HBufC8 :: NewL(KSCPMaxTARMNotifParamLen));
       
   711         
       
   712         if(lErr != KErrNone) {
       
   713             return lErr;
       
   714         }
       
   715 
       
   716         TPtr8 addParams = addParamsHBuf->Des();
       
   717         addParams.Zero();
       
   718 
       
   719         TInt status(KErrNone);
       
   720         TPckg<TInt> retPackage(status);
       
   721         
       
   722         TInt ret = SendReceive(ESCPServCodeChangeQuery, TIpcArgs(&retPackage, &addParams));
       
   723 
       
   724         if((ret == KErrNone) && (addParams.Length() > 0)) {
       
   725             // The server has sent additional parameters, ignore errors in processing
       
   726             TRAP_IGNORE(ProcessServerCommandsL(addParams));
       
   727         }
       
   728 
       
   729         delete addParamsHBuf;
       
   730 
       
   731         if((ret != KErrNone) || (status != KErrNone)) {
       
   732             // Password cannot be changed now
       
   733             return KErrAbort;
       
   734         }
       
   735     }
       
   736 
       
   737     // Load the required resource files into this process
       
   738     lRet = LoadResources(resourceFileSCP, resourceFileSecUi);
       
   739     
       
   740     if(lRet != KErrNone) {
       
   741         return lRet;
       
   742     }
       
   743 
       
   744     HBufC* codeHBuf = NULL;
       
   745     
       
   746     TRAP(lErr, codeHBuf = HBufC :: NewL(KSCPPasscodeMaxLength + 1));
       
   747     
       
   748     if(lErr != KErrNone) {
       
   749         // Remove the resource files
       
   750         CCoeEnv :: Static()->DeleteResourceFile(resourceFileSCP);
       
   751         CCoeEnv :: Static()->DeleteResourceFile(resourceFileSecUi);
       
   752         return lErr;
       
   753     }
       
   754 
       
   755     TPtr codeBuffer = codeHBuf->Des();
       
   756     codeBuffer.Zero();
       
   757 
       
   758     TInt def_code = -1;
       
   759     CRepository* lRepository = NULL;
       
   760     
       
   761     TRAP(lErr, lRepository = CRepository :: NewL(KCRUidSCPLockCode));
       
   762     
       
   763     if(KErrNone == lErr) {
       
   764         lErr = lRepository->Get(KSCPLockCodeDefaultLockCode, def_code);
       
   765        
       
   766         if(def_code == 0) {
       
   767             TRAP(lErr, lRet = RunDialogL(codeBuffer, SCP_OK_CANCEL, KSCPPasscodeMinLength,
       
   768                                      KSCPPasscodeMaxLength, R_SECUI_TEXT_ENTER_SEC_CODE));
       
   769     
       
   770             if((lRet) && (lErr == KErrNone) && (lRet != ESecUiEmergencyCall)) {
       
   771                 lErr = GetNewCodeAndChange(codeBuffer, KSCPNormalChange);
       
   772             }
       
   773     
       
   774             if(lErr != KErrNone) {
       
   775                 Dprint((_L("RSCPClient::ChangeCodeRequest(): Code change FAILED: %d"), lErr));
       
   776             }
       
   777     
       
   778             if(((!lRet) && (lErr == KErrNone)) || (lRet == ESecUiEmergencyCall)) {
       
   779                 // Cancelled by user
       
   780                 lErr = KErrAbort;
       
   781             }
       
   782         }
       
   783         else if(def_code != -1) {
       
   784             _LIT(KText, "12345");
       
   785             TBufC<10> NBuf (KText);
       
   786             TPtr codeBuf = NBuf.Des();
       
   787             
       
   788             lErr = GetNewCodeAndChange(codeBuf, KSCPNormalChange);
       
   789             
       
   790             if(lErr == KErrNone) {
       
   791                 lRepository->Set(KSCPLockCodeDefaultLockCode, 0);
       
   792             }
       
   793             else {
       
   794                 Dprint((_L("RSCPClient::ChangeCodeRequest(): Code change FAILED automatic: %d"), lErr));
       
   795             }
       
   796         }
       
   797         
       
   798         delete lRepository;
       
   799     }
       
   800     
       
   801     Dprint((_L("<-- RSCPClient::ChangeCodeRequest(): %d"), lErr ));
       
   802     
       
   803     // Remove the resource files
       
   804     CCoeEnv :: Static()->DeleteResourceFile(resourceFileSCP);
       
   805     CCoeEnv :: Static()->DeleteResourceFile(resourceFileSecUi);    
       
   806     delete codeHBuf;
       
   807     return lErr;
       
   808 }
   487 
   809 
   488 // ---------------------------------------------------------
   810 // ---------------------------------------------------------
   489 // RSCPClient::CheckConfiguration()
   811 // RSCPClient::CheckConfiguration()
   490 // Ask the server if the configuration is OK
   812 // Ask the server if the configuration is OK
   491 // 
   813 // 
   528     Dprint( (_L("<-- RSCPClient::CheckConfiguration(): %d"), status ));
   850     Dprint( (_L("<-- RSCPClient::CheckConfiguration(): %d"), status ));
   529     
   851     
   530     return ret;
   852     return ret;
   531     }
   853     }
   532 EXPORT_C TInt RSCPClient :: PerformCleanupL(RArray<TUid>& aAppIDs) {
   854 EXPORT_C TInt RSCPClient :: PerformCleanupL(RArray<TUid>& aAppIDs) {
       
   855     Dprint((_L("RSCPClient::PerformCleanupL() >>>")));
   533     TInt lCount = aAppIDs.Count();
   856     TInt lCount = aAppIDs.Count();
   534     
   857     
   535     if(lCount < 1) {
   858     if(lCount < 1) {
   536         return KErrNone; 
   859         return KErrNone; 
   537     }
   860     }
   546         lWriteStream.WriteInt32L(aAppIDs[i].iUid);
   869         lWriteStream.WriteInt32L(aAppIDs[i].iUid);
   547     }
   870     }
   548     lWriteStream.CommitL();
   871     lWriteStream.CommitL();
   549     TInt lStatus = SendReceive(ESCPApplicationUninstalled, TIpcArgs(ESCPApplicationUninstalled, &lBuff->Des()));
   872     TInt lStatus = SendReceive(ESCPApplicationUninstalled, TIpcArgs(ESCPApplicationUninstalled, &lBuff->Des()));
   550     CleanupStack :: PopAndDestroy(2); // lBuff, lWriteStream
   873     CleanupStack :: PopAndDestroy(2); // lBuff, lWriteStream
       
   874     Dprint((_L("RSCPClient::PerformCleanupL() <<<")));
   551     return lStatus;
   875     return lStatus;
   552 }
   876 }
   553 // ---------------------------------------------------------
   877 // ---------------------------------------------------------
   554 // The server contains all the logic for the parameters, just
   878 // The server contains all the logic for the parameters, just
   555 // propagate the call.
   879 // propagate the call.
   560     Dprint((_L("RSCPClient::SetParamValue() >>>")));
   884     Dprint((_L("RSCPClient::SetParamValue() >>>")));
   561     TPckgBuf<TUint32> lCallerID(aCallerSID);
   885     TPckgBuf<TUint32> lCallerID(aCallerSID);
   562     TInt ret = SendReceive(ESCPServSetParam, TIpcArgs(aParamID, &aValue, &lCallerID));
   886     TInt ret = SendReceive(ESCPServSetParam, TIpcArgs(aParamID, &aValue, &lCallerID));
   563     Dprint((_L("RSCPClient::SetParamValue(): %d <<<"), ret));
   887     Dprint((_L("RSCPClient::SetParamValue(): %d <<<"), ret));
   564     return ret;
   888     return ret;
   565 }
       
   566 
       
   567 EXPORT_C TInt RSCPClient::GetPolicies(RArray<TInt>& aDeviceLockPolicies) {
       
   568     Dprint(_L("[RSCPClient]-> GetPolicies >>>"));
       
   569     HBufC8* lBuff = NULL;
       
   570     TInt lStatus = KErrNone;
       
   571 
       
   572     TRAP(lStatus, lBuff = HBufC8 :: NewL((EDevicelockTotalPolicies - 1)  * sizeof(TInt)));
       
   573 
       
   574     if (lStatus == KErrNone) {
       
   575 
       
   576         lStatus = SendReceive(ESCPServGetParam, TIpcArgs(-1, &lBuff->Des()));
       
   577 
       
   578         if (lStatus == KErrNone) {
       
   579             // Copy data from lBuff to aDeviceLockPolicies
       
   580             TPtr8 bufPtr = lBuff->Des();
       
   581 
       
   582             if (bufPtr.Length() > 0) {
       
   583                 RDesReadStream lBufReadStream(bufPtr);
       
   584                 Dprint(_L("[RSCPClient]-> Get from server complete, returning service request..."));
       
   585 
       
   586                 for (TInt i = 0; i < 17; i++) {
       
   587                     TInt32 lParamValue = 0;
       
   588                     TRAP(lStatus, lParamValue = lBufReadStream.ReadInt32L());
       
   589 
       
   590                     if (lStatus != KErrNone) {
       
   591                         break;
       
   592                     }
       
   593 
       
   594                     aDeviceLockPolicies.Append(lParamValue);
       
   595                 }
       
   596 
       
   597                 lBufReadStream.Close();
       
   598             }
       
   599             else {
       
   600                 lStatus = KErrGeneral;
       
   601             }
       
   602         }
       
   603     }
       
   604     delete lBuff;
       
   605     Dprint(_L("[RSCPClient]-> GetPolicies <<<"));
       
   606     return lStatus;
       
   607 }
   889 }
   608 
   890 
   609 /* ---------------------------------------------------------
   891 /* ---------------------------------------------------------
   610  * Alternative function that can be used to set the Auto Lock period
   892  * Alternative function that can be used to set the Auto Lock period
   611  * Caller should have AllFiles access level
   893  * Caller should have AllFiles access level
   617     TPckgBuf<TInt> lAutoLockPeriod(aValue);
   899     TPckgBuf<TInt> lAutoLockPeriod(aValue);
   618     TInt ret = SendReceive(ESCPServUISetAutoLock, TIpcArgs(&lAutoLockPeriod));
   900     TInt ret = SendReceive(ESCPServUISetAutoLock, TIpcArgs(&lAutoLockPeriod));
   619     Dprint((_L("[RSCPClient]-> SetAutoLockPeriod(): %d <<<"), ret));
   901     Dprint((_L("[RSCPClient]-> SetAutoLockPeriod(): %d <<<"), ret));
   620     return ret;
   902     return ret;
   621 }
   903 }
   622 
   904 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
   623 EXPORT_C TBool RSCPClient :: IsLockcodeChangeAllowedNow(RArray<TDevicelockPolicies>& aFailedPolicies) {
   905 
   624     Dprint((_L("[RSCPClient]-> IsLockcodeChangeAllowedNow() >>>")));
   906 // ---------------------------------------------------------
   625     TInt lStatus = KErrNone;
   907 // RSCPClient::GetNewCodeAndChange()
   626 	TInt lErr = KErrNone;
   908 // Show the new code request and verification dialogs and
   627     
   909 // send the change request to the server.
   628     // extra one for failed policies count
   910 // 
   629     //koys: if leave happens what errorcode we should return??
   911 // Status : Approved
   630     HBufC8* failedPoliciesBuff = NULL;
   912 // ---------------------------------------------------------
   631     TRAP(lStatus, failedPoliciesBuff = HBufC8 :: NewL((EDevicelockTotalPolicies + 1)* sizeof(TInt32)));
   913 //  
   632     
   914 TInt RSCPClient::GetNewCodeAndChange( TDes& aOldCode, 
   633 	if (lStatus == KErrNone) {
   915                                       TInt aMode,
   634 		lStatus = SendReceive(ESCPServCodeChangeQuery, TIpcArgs(&failedPoliciesBuff->Des()));
   916                                       TSCPSecCode* aNewDOSCode /*=NULL*/, 
   635 		//koya: if leave happens what errorcode we should return??
   917                                       HBufC** aNewCodePptr/* = NULL*/)
   636 		TPtr8 failedPoliciesBufPtr = failedPoliciesBuff->Des();
   918     {
   637 		TRAP(lErr, ReadFailedPoliciesL(failedPoliciesBufPtr, aFailedPolicies));
   919     
   638 		delete failedPoliciesBuff;
   920     Dprint(_L("[RSCPClient]-> GetNewCodeAndChange() >>>"));
       
   921     
       
   922     if(!isFlagEnabled)
       
   923 	{
       
   924 		return KErrNotSupported;
   639 	}
   925 	}
   640 	
   926     TInt err = KErrNone;
   641 	Dprint((_L("[RSCPClient]-> IsLockcodeChangeAllowedNow() <<<")));
   927     TInt ret = KErrNone;            
   642     return (lStatus != KErrNone) ? lStatus : ((lErr != KErrNone) ? lErr : KErrNone);
   928     
   643 }
   929             
   644 
   930     TInt maxLen = KSCPPasscodeMaxLength;
   645 EXPORT_C  TInt RSCPClient :: VerifyNewLockcodeAgainstPolicies(TDesC& aLockcode, RArray<TDevicelockPolicies>& aFailedPolicies) {
   931     TInt minLen = 1;
   646     Dprint((_L("[RSCPClient]-> VerifyNewLockcodeAgainstPolicies() >>>")));
   932         
   647     TInt lRet = KErrNone;
   933     // Fetch the minimum and maximum lengths for the code, if available.
   648     TInt lErr = KErrNone;
   934     // This feature is commented out for correction to BU error ID: BNIN-6LC3AP.
   649     // extra one for failed policies count
   935     // Left in the code for possible inclusion in the future.
   650     HBufC8* failedPoliciesBuff = NULL;
   936     //FetchLimits( minLen, maxLen );        
   651 
   937         
   652     TRAP(lRet, failedPoliciesBuff = HBufC8 :: NewL((EDevicelockTotalPolicies + 1) * sizeof(TInt32)));
   938     // Request the new code and verify it. Repeat this until the codes match.
   653 
   939     
   654     if(lRet == KErrNone) {
   940     // Create the buffers on the heap
   655         lRet = SendReceive(ESCPServValidateLockcode, TIpcArgs(&aLockcode, &failedPoliciesBuff->Des()));
   941     HBufC* newCodeHBuf = NULL;
   656 
   942     HBufC* verifyCodeHBuf = NULL;
   657         TPtr8 failedPoliciesBufPtr = failedPoliciesBuff->Des();
   943     
   658         TRAP(lErr, ReadFailedPoliciesL(failedPoliciesBufPtr, aFailedPolicies));
   944     TRAP( err, newCodeHBuf = HBufC::NewL( KSCPPasscodeMaxLength + 1 ) );
   659 
   945     if ( err == KErrNone )
   660         delete failedPoliciesBuff;
   946         {
   661     }
   947         TRAP( err, verifyCodeHBuf = HBufC::NewL( KSCPPasscodeMaxLength + 1 ) );
   662 
   948         }
   663     Dprint((_L("[RSCPClient]-> VerifyNewLockcodeAgainstPolicies() <<<")));
   949     
   664     return (lRet != KErrNone) ? lRet : ((lErr != KErrNone) ? lErr : KErrNone);
   950     if ( err != KErrNone )
   665 }
   951         {
   666 
   952         if ( newCodeHBuf != NULL )
   667 EXPORT_C  TInt RSCPClient :: StoreLockcode (TDesC& aNewLockcode, TDesC& aOldLockcode, RArray<TDevicelockPolicies>& aFailedPolicies) {
   953             {
   668     Dprint((_L("[RSCPClient]-> StoreLockcode() >>>")));
   954             delete newCodeHBuf;
   669     TInt lErr = KErrNone;
   955             }
   670     TInt lRet = KErrNone;
   956         return err; 
   671 
   957         }    
   672     if (!IsLockcodeChangeAllowedNow(aFailedPolicies)) {
   958         
   673         return KErrAccessDenied;
   959     TPtr newCodeBuffer = newCodeHBuf->Des();
   674     }
   960     TPtr verifyCodeBuffer = verifyCodeHBuf->Des();  
   675 
   961     
   676     HBufC8* failedPoliciesBuff = NULL;
   962     // Configure the buttons according to the mode
   677 
   963     TSCPButtonConfig bConfig;
   678     TRAP(lRet, failedPoliciesBuff = HBufC8 :: NewL((EDevicelockTotalPolicies + 1)* sizeof(TInt32)));
   964     TBool ecSupport;
   679 
   965     if ( aMode == KSCPForcedChange )
   680     if(lRet == KErrNone) {
   966         {
   681         lRet = SendReceive(ESCPServChangeEnhCode, TIpcArgs(&aOldLockcode, &aNewLockcode, &failedPoliciesBuff->Des()));
   967         bConfig = SCP_OK_ETEL;
   682 
   968         ecSupport = ETrue;
   683         TPtr8 failedPoliciesBufPtr = failedPoliciesBuff->Des();
   969         }
   684         TRAP(lErr, ReadFailedPoliciesL(failedPoliciesBufPtr, aFailedPolicies));
   970     else
   685 
   971         {
   686         delete failedPoliciesBuff;
   972         bConfig = SCP_OK_CANCEL;
   687     }
   973         ecSupport = EFalse;
   688 
   974         }
   689     Dprint((_L("[RSCPClient]-> StoreLockcode() <<<")));
   975     
   690     return (lRet != KErrNone) ? lRet : ((lErr != KErrNone) ? lErr : KErrNone);
   976     TBool isMismatch = EFalse;
   691 }
   977     do // Repeat loop BEGIN
   692 
   978         {
   693 EXPORT_C  TInt RSCPClient :: VerifyCurrentLockcode (TDesC& aLockcode,RMobilePhone::TMobilePassword& aISACode,RArray< TDevicelockPolicies > &aFailedPolicies, TInt aFlags) {
   979         isMismatch = EFalse;
   694     Dprint((_L("[RSCPClient]-> VerifyCurrentLockcode() >>>")));
   980                 
   695     TInt lErr = KErrNone;
   981         if ( err == KErrSCPInvalidCode )
   696     TInt lRet = KErrNone;
   982             {
   697 
   983             err = KErrNone; // "reset"
   698     // extra one for failed policies count
   984             }
   699     HBufC8* failedPoliciesBuff = NULL;
   985                           
   700 
   986         newCodeBuffer.Zero(); 
   701     TRAP(lRet, failedPoliciesBuff = HBufC8 :: NewL((EDevicelockTotalPolicies + 1)* sizeof(TInt32)));
   987         
   702 
   988         TRAP( err, ret = RunDialogL( newCodeBuffer, 
   703     if(lRet == KErrNone) {
   989                                  bConfig, 
   704         lRet = SendReceive(ESCPServAuthenticateS60, TIpcArgs(&aLockcode, &aISACode, &failedPoliciesBuff->Des(), aFlags));
   990                                  minLen,
   705 
   991                                  maxLen,
   706         TPtr8 failedPoliciesBufPtr = failedPoliciesBuff->Des();
   992                                  R_SECUI_TEXT_ENTER_NEW_SEC_CODE,
   707         TRAP(lRet, ReadFailedPoliciesL(failedPoliciesBufPtr, aFailedPolicies));
   993                                  NULL,
   708 
   994                                  ecSupport) );
   709         delete failedPoliciesBuff;
   995     
   710     }
   996         if ( ( ret ) && ( ret != ESecUiEmergencyCall ) && ( err == KErrNone ) )
   711 
   997             {
   712     return (lRet != KErrNone) ? lRet : ((lErr != KErrNone) ? lErr : KErrNone);
   998             verifyCodeBuffer.Zero();
   713 }
   999             /*TChar ch = static_cast<TChar>(newCodeBuffer[0]);
   714 
  1000 
   715 //#ifdef __SAP_DEVICE_LOCK_ENHANCEMENTS
  1001             CSCPQueryDialog :: TKeypadContext lKPContext =
   716 
  1002                     (ch.IsDigit() ? CSCPQueryDialog :: ENumeric : CSCPQueryDialog :: EAlphaNumeric);*/
       
  1003                     
       
  1004             TRAP( err, ret = RunDialogL( verifyCodeBuffer, 
       
  1005                                  bConfig, 
       
  1006                                  minLen,
       
  1007                                  maxLen,
       
  1008                                  R_SECUI_TEXT_VERIFY_NEW_SEC_CODE,
       
  1009                                  NULL,
       
  1010                                  ecSupport));
       
  1011             }
       
  1012 
       
  1013         if ( ( !ret ) || ( err != KErrNone ) || ( ret == ESecUiEmergencyCall ) )
       
  1014             {
       
  1015             break;
       
  1016             }            
       
  1017             
       
  1018         if  ( verifyCodeBuffer.Compare( newCodeBuffer ) != 0 )
       
  1019             {                        
       
  1020             // Ignore the errors from showing the note, it's better to continue if it fails
       
  1021             
       
  1022             TRAP_IGNORE(
       
  1023                 // Show an error note, the entered codes don't match             
       
  1024                 CAknNoteDialog* noteDlg = 
       
  1025                     new (ELeave) CAknNoteDialog(reinterpret_cast<CEikDialog**>( &noteDlg ) );
       
  1026                 noteDlg->SetTimeout( CAknNoteDialog::ELongTimeout );
       
  1027                 noteDlg->SetTone( CAknNoteDialog::EErrorTone );
       
  1028                 noteDlg->ExecuteLD( R_CODES_DONT_MATCH );
       
  1029             );
       
  1030             
       
  1031             isMismatch = ETrue; // Repeat code query
       
  1032             }        
       
  1033         
       
  1034         if ( !isMismatch )
       
  1035             {
       
  1036             HBufC8* addParamsHBuf = NULL;
       
  1037     
       
  1038             TRAP( err, addParamsHBuf = HBufC8::NewL( KSCPMaxTARMNotifParamLen ) );
       
  1039             if ( err != KErrNone )
       
  1040                 {
       
  1041                 delete verifyCodeHBuf;
       
  1042                 delete newCodeHBuf;             
       
  1043                 return err;
       
  1044                 }      
       
  1045         
       
  1046             TPtr8 addParams = addParamsHBuf->Des();
       
  1047             addParams.Zero();                                    
       
  1048             
       
  1049             if ( !isMismatch )
       
  1050                 {
       
  1051                 // Try to change the code
       
  1052                 TSCPSecCode newDOSCode;
       
  1053                 newDOSCode.Zero();
       
  1054                 
       
  1055                 err = SendReceive(  ESCPServChangeEnhCode, 
       
  1056                             TIpcArgs( &aOldCode, &verifyCodeBuffer, &addParams, &newDOSCode ) 
       
  1057                          );
       
  1058                 
       
  1059                 if ( addParams.Length() > 0 )
       
  1060                     {
       
  1061                     // The server has sent additional parameters
       
  1062                     TRAPD( err, ProcessServerCommandsL( addParams ) );
       
  1063                     if ( err != KErrNone )
       
  1064                         {
       
  1065                         Dprint( (_L("RSCPClient::GetNewCodeAndChange():\
       
  1066                             Process cmds FAILED: %d"), err ));
       
  1067                         }                    
       
  1068                     }
       
  1069                     
       
  1070                 if ( aNewDOSCode != NULL )
       
  1071                     {
       
  1072                     (*aNewDOSCode).Copy( newDOSCode );
       
  1073                     }
       
  1074                 }
       
  1075             
       
  1076             delete addParamsHBuf;
       
  1077             }
       
  1078                             
       
  1079         } while ( ( isMismatch ) || ( err == KErrSCPInvalidCode ) ); // Loop END
       
  1080         
       
  1081     if ( ( ( !ret ) && ( err == KErrNone ) ) || ( ret == ESecUiEmergencyCall ) )
       
  1082         {
       
  1083         // Cancelled by user
       
  1084         err = KErrAbort;
       
  1085         }
       
  1086 
       
  1087     if((KErrNone == err) && (aNewCodePptr != 0)) {
       
  1088         Dprint(_L("[RSCPClient]-> INFO: Updating new lock code to aNewCodePptr"));
       
  1089         TRAP(err, *aNewCodePptr = HBufC :: NewL(verifyCodeHBuf->Des().Length()));
       
  1090 
       
  1091         if(*aNewCodePptr != NULL) {
       
  1092             (*aNewCodePptr)->Des().Copy(verifyCodeHBuf->Des());
       
  1093             Dprint(_L("[RSCPClient]-> INFO: Updated new lock code to aNewCodePptr"));
       
  1094         }
       
  1095     }
       
  1096     
       
  1097     delete verifyCodeHBuf;
       
  1098     delete newCodeHBuf;
       
  1099         
       
  1100     Dprint(_L("[RSCPClient]-> GetNewCodeAndChange() <<<"));
       
  1101     return err;        
       
  1102     }
       
  1103        
       
  1104             
       
  1105         
       
  1106 // ---------------------------------------------------------
       
  1107 // RSCPClient::ProcessServerCommandsL()
       
  1108 // Handle the commands in the server's param-buffer
       
  1109 // 
       
  1110 // Status : Approved
       
  1111 // ---------------------------------------------------------
       
  1112 //
       
  1113 void RSCPClient::ProcessServerCommandsL( TDes8& aInParams, 
       
  1114                                          CSCPParamObject** aOutParams,
       
  1115                                          TBool isNotifierEvent )
       
  1116     {    
       
  1117 
       
  1118     if(!isFlagEnabled)
       
  1119 	{
       
  1120 		User::Leave(KErrNotSupported);
       
  1121 	}
       
  1122     Dprint( (_L("--> RSCPClient::ProcessServerCommandsL()") ));
       
  1123     (void)aOutParams;
       
  1124     
       
  1125     CSCPParamObject* theParams = CSCPParamObject::NewL();
       
  1126     CleanupStack::PushL( theParams );
       
  1127     
       
  1128     theParams->Parse( aInParams );
       
  1129     TInt actionID;
       
  1130     TInt ret = theParams->Get( KSCPParamAction, actionID );
       
  1131     
       
  1132     Dprint( (_L("RSCPClient::ProcessServerCommandsL():Params parsed") ));
       
  1133     
       
  1134     if ( ret != KErrNone )
       
  1135         {
       
  1136         Dprint( (_L("RSCPClient::ProcessServerCommands(): Can't get action ID: %d"), ret )); 
       
  1137         }
       
  1138     else
       
  1139         {
       
  1140         switch ( actionID )
       
  1141             {
       
  1142             case ( KSCPActionShowUI ):
       
  1143                 {
       
  1144                 TRAP( ret, ShowUIL( *theParams ) );
       
  1145                 break;
       
  1146                 }
       
  1147                 
       
  1148             case ( KSCPActionForceChange ):
       
  1149                 {
       
  1150                 if ( isNotifierEvent )
       
  1151                     {
       
  1152                     break; // Calling this through the notifier would jam the system
       
  1153                     // since the server is busy.
       
  1154                     }                                    
       
  1155                 
       
  1156                 HBufC* codeHBuf = NULL;
       
  1157                 codeHBuf = HBufC::NewL( KSCPPasscodeMaxLength + 1 );    
       
  1158                 CleanupStack::PushL( codeHBuf );
       
  1159                    
       
  1160                 TPtr codeBuf = codeHBuf->Des();
       
  1161                 codeBuf.Zero(); 
       
  1162                 
       
  1163                 ret = theParams->Get( KSCPParamPassword, codeBuf );
       
  1164 				
       
  1165                 if ( ret == KErrNone )
       
  1166                     {
       
  1167                     TInt lResFile = 0;
       
  1168                     TFileName resFile;
       
  1169                     resFile.Copy( KDriveZ );
       
  1170                     resFile.Append( KSCPTimestampPluginResFilename );
       
  1171                     BaflUtils :: NearestLanguageFile( CCoeEnv :: Static()->FsSession(), resFile );
       
  1172                     lResFile = CCoeEnv :: Static()->AddResourceFileL(resFile);
       
  1173 					
       
  1174                     CAknNoteDialog* lNoteDlg = new (ELeave) CAknNoteDialog(CAknNoteDialog :: ENoTone, CAknNoteDialog :: ELongTimeout);
       
  1175                     CleanupStack :: PushL(lNoteDlg);
       
  1176 					
       
  1177                     HBufC* lExpNoteMsg = CEikonEnv :: Static()->AllocReadResourceLC(R_SET_SEC_CODE_AGING);
       
  1178                     lNoteDlg->SetTextL(lExpNoteMsg->Des());
       
  1179 					
       
  1180                     lNoteDlg->ExecuteLD(R_DIALOG_WARNING);
       
  1181                     CleanupStack :: PopAndDestroy(1); //lExpNoteMsg
       
  1182                     CleanupStack :: Pop(1); //lNoteDlg
       
  1183 					
       
  1184                     CCoeEnv :: Static()->DeleteResourceFile( lResFile );
       
  1185 					
       
  1186                     TSCPSecCode newDOSCode;
       
  1187                     ret = GetNewCodeAndChange( codeBuf, KSCPForcedChange, &newDOSCode );
       
  1188                     
       
  1189                     // If aOutParams is defined, return the new code
       
  1190                     if ( aOutParams != NULL )
       
  1191                         {
       
  1192                         (*aOutParams) = CSCPParamObject::NewL();
       
  1193                         (*aOutParams)->Set( KSCPParamPassword, newDOSCode );
       
  1194                         }
       
  1195                     }
       
  1196                     
       
  1197                 CleanupStack::PopAndDestroy( codeHBuf );
       
  1198                                     
       
  1199                 break;
       
  1200                 }                            
       
  1201             }                
       
  1202         }
       
  1203                        
       
  1204     CleanupStack::PopAndDestroy( theParams );
       
  1205     
       
  1206     Dprint( (_L("<-- RSCPClient::ProcessServerCommandsL()") ));
       
  1207     User::LeaveIfError( ret );
       
  1208     }
       
  1209     
       
  1210 // ---------------------------------------------------------
       
  1211 // RSCPClient::ShowUI()
       
  1212 // Show the requested UI through AVKON
       
  1213 // 
       
  1214 // Status : Approved
       
  1215 // ---------------------------------------------------------
       
  1216 //
       
  1217 void RSCPClient::ShowUIL( CSCPParamObject& aContext )
       
  1218     {
       
  1219     
       
  1220     if(!isFlagEnabled)
       
  1221 	{
       
  1222 		User::Leave(KErrNotSupported);
       
  1223 	}
       
  1224     Dprint( (_L("--> RSCPClient::ShowUIL()") ));
       
  1225     TInt mode;
       
  1226     User::LeaveIfError( aContext.Get( KSCPParamUIMode, mode ) );
       
  1227     
       
  1228     switch ( mode )
       
  1229         {
       
  1230         case ( KSCPUINote ):
       
  1231             {
       
  1232             // Get prompt
       
  1233             TBuf<KSCPMaxPromptTextLen> promptText;
       
  1234             aContext.Get( KSCPParamPromptText, promptText );
       
  1235                         
       
  1236             // Try to get note icon, default is to use "error"
       
  1237             TInt noteType = KSCPUINoteError;
       
  1238             Dprint( (_L("RSCPClient::ShowUIL(): Creating note object") ));
       
  1239             
       
  1240             CAknResourceNoteDialog* note = NULL;
       
  1241             
       
  1242             if ( aContext.Get( KSCPParamNoteIcon, noteType ) != KErrNone )
       
  1243                 {
       
  1244                 noteType = KSCPUINoteError;
       
  1245                 }
       
  1246                 
       
  1247             switch ( noteType )
       
  1248                 {
       
  1249                 case ( KSCPUINoteWarning ):
       
  1250                     {
       
  1251                     note = new (ELeave) CAknWarningNote( ETrue );    
       
  1252                     break;
       
  1253                     }
       
  1254                     
       
  1255                 case ( KSCPUINoteError ):
       
  1256                 default: // default to error
       
  1257                     {
       
  1258                     note = new (ELeave) CAknErrorNote( ETrue ); 
       
  1259                     break;
       
  1260                     }                         
       
  1261                 }                                          
       
  1262 
       
  1263             if ( note != NULL )
       
  1264                 {
       
  1265                 Dprint( (_L("RSCPClient::ShowUIL(): Showing note") ));
       
  1266                 note->ExecuteLD( promptText );
       
  1267                 }            
       
  1268             }
       
  1269         }
       
  1270 
       
  1271     Dprint( (_L("<-- RSCPClient::ShowUIL()") ));
       
  1272     } 
       
  1273        
   717 
  1274 
   718 // ---------------------------------------------------------
  1275 // ---------------------------------------------------------
   719 // RSCPClient::FetchLimits()
  1276 // RSCPClient::FetchLimits()
   720 // Retrieve the limit-parameter values if available
  1277 // Retrieve the limit-parameter values if available
   721 // 
  1278 // 
   757         if ( ( lex.Val( aMax ) != KErrNone ) || ( aMax <= 0 ) )
  1314         if ( ( lex.Val( aMax ) != KErrNone ) || ( aMax <= 0 ) )
   758             {
  1315             {
   759             aMax = KSCPPasscodeMaxLength;
  1316             aMax = KSCPPasscodeMaxLength;
   760             }
  1317             }
   761         }
  1318         }
   762     }
  1319     }              
   763 
  1320 TInt RSCPClient :: SetSecurityCodeL(RMobilePhone :: TMobilePassword& aPassword, 
   764 void RSCPClient :: ReadFailedPoliciesL(TDes8& aFailedPolicyBuf, RArray< TDevicelockPolicies>& aFailedPolicies) {
  1321             TSCPButtonConfig aButtonsShown, TBool aECSSupport, TInt aFlags, TInt& aResFileSCP, TInt& aResFileSecUi) {
   765     Dprint((_L("[RSCPClient]-> ReadFailedPoliciesL() >>>")));
  1322     Dprint((_L("[RSCPClient]-> SetSecurityCodeL() >>>")));
   766     
  1323     Dprint((_L("[RSCPClient]-> input params - aButtonsShown=%d, aECSSupport=%d"), aButtonsShown, aECSSupport));
   767     if(aFailedPolicyBuf.Length() < 1) {
  1324 
   768         return;
  1325     if(EFalse == isFlagEnabled) {
   769     }
  1326         (void)aPassword;
   770     
  1327         Dprint((_L("[RSCPClient]-> ERROR: Function not supported in this variant")));
   771     RDesReadStream readStream(aFailedPolicyBuf);
  1328         User :: Invariant();
   772     CleanupClosePushL(readStream);
  1329         return KErrNotSupported;
   773     
  1330     }
   774     TInt failedPoliciesCount = readStream.ReadInt32L();    
  1331 
   775     aFailedPolicies.Reset();
  1332     TInt lRet = LoadResources(aResFileSCP, aResFileSecUi);
   776     Dprint((_L("[RSCPClient]-> ReadFailedPoliciesL failedPoliciesCount =%d"), failedPoliciesCount));
  1333 
   777     for(int i=0; i < failedPoliciesCount; i++) {
  1334     if(lRet != KErrNone) {
   778         TInt32 temp =  readStream.ReadInt32L();
  1335         return lRet;
   779         //aFailedPolicies.Append((TDevicelockPolicies) readStream.ReadInt32L());
  1336     }
   780         aFailedPolicies.AppendL((TDevicelockPolicies)temp);
  1337 
   781         Dprint((_L("[RSCPClient]-> ReadFailedPoliciesL failed policy =%d"), temp));
  1338     TInt lDefCode = 0;
   782     }
  1339     CRepository* lRepository = CRepository :: NewLC(KCRUidSCPLockCode);
   783 
  1340     lRet = lRepository->Get(KSCPLockCodeDefaultLockCode, lDefCode);
   784     CleanupStack :: PopAndDestroy(&readStream);
  1341 
   785     Dprint((_L("[RSCPClient]-> ReadFailedPoliciesL() <<<")));
  1342     if(lRet != KErrNone) {
       
  1343         Dprint(_L("[RSCPClient]-> ERROR: Unable to perform get on CenRep, lErr=%d"), lRet);
       
  1344         CleanupStack :: PopAndDestroy(lRepository);
       
  1345         return lRet;
       
  1346     }
       
  1347     TInt currentLawmoState(0); 
       
  1348     Dprint( (_L("CSCPClient::lawmo cenrep") ));
       
  1349     CRepository* crep = CRepository::NewLC( KCRUidDeviceManagementInternalKeys );
       
  1350     TInt reterr = crep->Get( KLAWMOPhoneLock, currentLawmoState ); 
       
  1351     Dprint( (_L("CSCPClient::lawmo cenrep done") ));
       
  1352     if(reterr != KErrNone) 
       
  1353         {
       
  1354         Dprint(_L("[RSCPClient]-> ERROR: Unable to perform get on CenRep lawmo, lErr=%d"), lRet);
       
  1355         CleanupStack :: PopAndDestroy(crep);
       
  1356         return reterr;
       
  1357         }
       
  1358     HBufC* codeHBuf = HBufC :: NewLC(KSCPPasscodeMaxLength + 1);
       
  1359     HBufC8* addParamsHBuf = HBufC8 :: NewLC(KSCPMaxTARMNotifParamLen);
       
  1360     TPtr codeBuffer = codeHBuf->Des();
       
  1361     TPtr8 addParams = addParamsHBuf->Des();
       
  1362     if(currentLawmoState!=KLockedbyLawmo)
       
  1363         {
       
  1364         // rundialog with a new resource file
       
  1365         Dprint((_L("[RSCPClient]-> lawmo current state !=30")));
       
  1366         TBuf<255> serverId;
       
  1367         serverId.Zero();
       
  1368         reterr = crep->Get( KLAWMOfactoryDmServerName, serverId );
       
  1369         Dprint( (_L("RSCPClient::SetSecurityCode serverid: %s"), serverId.PtrZ() ));
       
  1370         HBufC* prompt = StringLoader::LoadLC(R_SCP_LAWMO_LOCKED, serverId);
       
  1371         Dprint( (_L("RSCPClient::SetSecurityCode stringval: %s"), (prompt->Des()).PtrZ() ));
       
  1372 
       
  1373         lRet = RunDialogL(codeBuffer, aButtonsShown, KSCPPasscodeMinLength, KSCPPasscodeMaxLength,
       
  1374                         0, prompt, aECSSupport);
       
  1375 		if((lRet) && (lRet != ESecUiEmergencyCall) && (lRet != EAknSoftkeyEmergencyCall)) 
       
  1376 			{
       
  1377 			Dprint(_L("[RSCPClient]-> INFO: LL User has updated the lock code..."));
       
  1378 			
       
  1379 			lRet = SendReceive( ESCPServAuthenticateS60, TIpcArgs( &codeBuffer, &aPassword, &addParams, aFlags));
       
  1380 			
       
  1381 			Dprint((_L("[RSCPClient]-> INFO: LL addParams.Length()=%d")), addParams.Length());
       
  1382 			Dprint((_L("[RSCPClient]-> INFO: LL lRet=%d")), lRet);
       
  1383 			}
       
  1384 		else
       
  1385 			{
       
  1386 	        switch(lRet) 
       
  1387 	            {
       
  1388 	            case 0:
       
  1389 	                lRet = KErrCancel;
       
  1390 	                break;
       
  1391 	            }
       
  1392             }
       
  1393         CleanupStack::PopAndDestroy(1);
       
  1394         }
       
  1395     else if(lDefCode == 0) {
       
  1396         Dprint(_L("[RSCPClient]-> INFO: Default lock code has been set already by the user..."));
       
  1397 
       
  1398         lRet = RunDialogL(codeBuffer, aButtonsShown, KSCPPasscodeMinLength, KSCPPasscodeMaxLength,
       
  1399                 R_SECUI_TEXT_ENTER_SEC_CODE, NULL, aECSSupport);
       
  1400 
       
  1401         if((lRet) && (lRet != ESecUiEmergencyCall) && (lRet != EAknSoftkeyEmergencyCall)) {
       
  1402             Dprint(_L("[RSCPClient]-> INFO: User has updated the lock code..."));
       
  1403 
       
  1404             lRet = SendReceive( ESCPServAuthenticateS60, TIpcArgs( &codeBuffer, &aPassword, &addParams, aFlags));
       
  1405 
       
  1406             Dprint((_L("[RSCPClient]-> INFO: addParams.Length()=%d")), addParams.Length());
       
  1407             Dprint((_L("[RSCPClient]-> INFO: lRet=%d")), lRet);
       
  1408         }
       
  1409         else {
       
  1410             switch(lRet) {
       
  1411             case 0:
       
  1412 				lRet = KErrCancel;
       
  1413 				break;
       
  1414             case EAknSoftkeyEmergencyCall:
       
  1415                 //lRet = KErrCancel;
       
  1416                 break;
       
  1417             case ESecUiEmergencyCall:
       
  1418                 lRet = ESecUiEmergencyCall;
       
  1419                 break;
       
  1420             /*default:
       
  1421                 break;*/
       
  1422             }
       
  1423         }
       
  1424     }
       
  1425     else {
       
  1426         TRequestStatus statusSave;
       
  1427         Dprint(_L("[RSCPClient]-> INFO: Default lock code not set by the user, requesting for the same"));
       
  1428 
       
  1429         HBufC* msgConfirmSave = NULL;
       
  1430         CAknGlobalConfirmationQuery* query = CAknGlobalConfirmationQuery :: NewLC();
       
  1431 
       
  1432         if(aButtonsShown == SCP_OK || aButtonsShown == SCP_OK_ETEL) {
       
  1433             //msgConfirmSave = CEikonEnv :: Static()->AllocReadResourceLC(R_SET_SEC_CODE);
       
  1434              msgConfirmSave = CEikonEnv :: Static()->AllocReadResourceLC(R_SET_SEC_CODE_SETTING_QUERY_SERVER);
       
  1435             query->ShowConfirmationQueryL(statusSave, *msgConfirmSave, R_AVKON_SOFTKEYS_OK_EMPTY__OK, R_QGN_NOTE_INFO_ANIM);
       
  1436         }
       
  1437         else {
       
  1438             msgConfirmSave = CEikonEnv :: Static()->AllocReadResourceLC(R_SET_SEC_CODE);
       
  1439         	query->ShowConfirmationQueryL(statusSave, *msgConfirmSave, R_AVKON_SOFTKEYS_YES_NO__YES, R_QGN_NOTE_QUERY_ANIM);
       
  1440         }
       
  1441 
       
  1442         User :: WaitForRequest(statusSave);
       
  1443         CleanupStack :: PopAndDestroy(2); // msgConfirmSave query
       
  1444 
       
  1445         if((statusSave == EAknSoftkeyYes) || (statusSave == EAknSoftkeyOk)) {
       
  1446             Dprint(_L("[RSCPClient]-> INFO: calling GetNewCodeAndChange() ..."));
       
  1447 
       
  1448             TBufC<10> NBuf(KSCPDefaultEnchSecCode);
       
  1449             TPtr codeBuf = NBuf.Des();
       
  1450 
       
  1451             TSCPSecCode lNewSecCode;
       
  1452             TInt lButtonCfg = (aButtonsShown == SCP_OK || aButtonsShown == SCP_OK_ETEL) ? KSCPForcedChange : KSCPNormalChange;
       
  1453             HBufC* lNewLkCodeBuf = NULL;
       
  1454             lRet = GetNewCodeAndChange(codeBuf, lButtonCfg, &lNewSecCode, &lNewLkCodeBuf);
       
  1455 
       
  1456             Dprint(_L("[RSCPClient]-> INFO: GetNewCodeAndChange() complete, err=%d"), lRet);
       
  1457 
       
  1458             if(KErrNone == lRet) {
       
  1459                 /* This is being called as a workaround for a freezing issue with SecUI. This is in place
       
  1460                  * as a temporary measure until the source is identified.
       
  1461                 */
       
  1462                 TInt lTmpRet = SendReceive(ESCPServAuthenticateS60, TIpcArgs(&lNewLkCodeBuf->Des(), &aPassword, &addParams, aFlags));
       
  1463 
       
  1464                 Dprint(_L("[RSCPClient]-> INFO: lTmpRet from SendReceive()=%d"), lTmpRet);
       
  1465                 if(KErrNone == lRet) {
       
  1466                     Dprint(_L("[RSCPClient]-> INFO: updating CenRep ..."));
       
  1467                     lRepository->Set(KSCPLockCodeDefaultLockCode, 0);
       
  1468                     Dprint(_L("[RSCPClient]-> INFO: User updated lock code for the first time...err= %d"), lRet);
       
  1469                 }
       
  1470             }
       
  1471 
       
  1472             if(lNewLkCodeBuf) {
       
  1473                 delete lNewLkCodeBuf;
       
  1474             }
       
  1475         }
       
  1476         else {
       
  1477             Dprint(_L("[RSCPClient]-> INFO: Returning KErrCancel"));
       
  1478             lRet = KErrCancel;
       
  1479         }
       
  1480 
       
  1481         if(KErrAbort == lRet) {
       
  1482             Dprint(_L("[RSCPClient]-> INFO: Returning KErrCancel"));
       
  1483             lRet = KErrCancel;
       
  1484         }
       
  1485 
       
  1486     }
       
  1487 
       
  1488     if(addParams.Length() > 0) {
       
  1489         CSCPParamObject* tmp = CSCPParamObject :: NewLC();
       
  1490         TInt lTempRet = tmp->Parse(addParams);
       
  1491 
       
  1492         if(lTempRet == KErrNone) {
       
  1493             lTempRet = tmp->Set(KSCPParamPassword, codeBuffer);
       
  1494         }
       
  1495 
       
  1496         if(lTempRet == KErrNone) {
       
  1497             addParams.Zero();
       
  1498             HBufC8* tmpBuf;
       
  1499             lTempRet = tmp->GetBuffer(tmpBuf);
       
  1500 
       
  1501             if(lTempRet == KErrNone) {
       
  1502                 addParams.Copy(tmpBuf->Des());
       
  1503                 delete tmpBuf;
       
  1504             }
       
  1505         }
       
  1506 
       
  1507         if(lTempRet == KErrNone) {
       
  1508             CSCPParamObject* outParams = NULL;
       
  1509             /*
       
  1510              * aECSSupport when passed to ProcessServerCommandsL decides if the expiry note and subsequently change device lock
       
  1511              * code has to be shown or not. Normally if the lock code has expired, the same has to be prompted from the user and 
       
  1512              * has to be done only during device unlock. aECSSupport value is being passed to ensure that new lock code is prompted
       
  1513              * only during device unlock.
       
  1514              */
       
  1515             ProcessServerCommandsL(addParams, &outParams, !aECSSupport);
       
  1516 
       
  1517             if(outParams != NULL) {
       
  1518                 TSCPSecCode newSecCode;
       
  1519                 if(outParams->Get(KSCPParamPassword, newSecCode) == KErrNone) {
       
  1520                     Dprint((_L("[RSCPClient]-> INFO: Updating encoded password received from the server into aPassword...")));
       
  1521                     aPassword.Copy(newSecCode);
       
  1522                 }
       
  1523 
       
  1524                 delete outParams;
       
  1525             }
       
  1526         }
       
  1527 
       
  1528         CleanupStack :: PopAndDestroy(tmp);
       
  1529     }
       
  1530 
       
  1531     CleanupStack :: PopAndDestroy(4); // repository * 2, addParamsHBuf, codeHBuf 
       
  1532     Dprint(_L("[RSCPClient]-> SetSecurityCodeL() <<< lRet=%d"), lRet);
       
  1533     return lRet;
   786 }
  1534 }
       
  1535 
   787 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
  1536 //#endif // __SAP_DEVICE_LOCK_ENHANCEMENTS
   788 // <<-- *********** Device lock new features *************
  1537 // <<-- *********** Device lock new features *************
   789 
  1538 
   790 
  1539 
   791 // ================= OTHER EXPORTED FUNCTIONS ==============
  1540 // ================= OTHER EXPORTED FUNCTIONS ==============