securitydialogs/SecUi/Src/SecUiSecuritySettings.cpp
changeset 0 164170e6151a
child 5 3b17fc5c9564
child 15 318c4eab2439
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Provides api for changing security settings.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <etelmm.h>
       
    21 #include <exterror.h>
       
    22 #include <textresolver.h>
       
    23 #include <SecUi.rsg>
       
    24 #include <aknnotedialog.h>
       
    25 #include <mmtsy_names.h>
       
    26 #include <centralrepository.h> 
       
    27 #include <gsmerror.h>
       
    28 #include <SCPClient.h>
       
    29 #include <StringLoader.h>
       
    30 #include <e32property.h>
       
    31 #include <PSVariables.h>   // Property values
       
    32 #include <securityuisprivatepskeys.h>
       
    33 #include <startupdomainpskeys.h>
       
    34 #include "secuisecuritysettings.h"
       
    35 #include "SecUiAutoLockSettingPage.h"
       
    36 #include "secui.hrh"
       
    37 #include "secuisecurityhandler.h"
       
    38 #include "secuicodequerydialog.h"
       
    39 #include "SecUiWait.h"
       
    40 
       
    41 #ifdef RD_REMOTELOCK
       
    42 #include <aknnotewrappers.h>
       
    43 #include <StringLoader.h>
       
    44 #include <RemoteLockSettings.h>
       
    45 #include "SecUiRemoteLockSettingPage.h"
       
    46 #endif // RD_REMOTELOCK
       
    47 #include <featmgr.h>
       
    48     /*****************************************************
       
    49     *    Series 60 Customer / TSY
       
    50     *    Needs customer TSY implementation
       
    51     *****************************************************/
       
    52 //  LOCAL CONSTANTS AND MACROS  
       
    53 
       
    54 const TInt KTriesToConnectServer( 2 );
       
    55 const TInt KTimeBeforeRetryingServerConnection( 50000 );
       
    56 const TInt PhoneIndex( 0 );
       
    57 
       
    58 const TInt KMaxNumberOfPINAttempts(3);
       
    59 const TInt KLastRemainingInputAttempt(1);
       
    60 
       
    61 // ================= MEMBER FUNCTIONS =======================
       
    62 //
       
    63 // ----------------------------------------------------------
       
    64 // CSecuritySettings::NewL()
       
    65 // ----------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CSecuritySettings* CSecuritySettings::NewL()
       
    68     {
       
    69     CSecuritySettings* self = new (ELeave) CSecuritySettings();
       
    70     CleanupStack::PushL(self);
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop(); //self
       
    73     return self;
       
    74     }
       
    75 //
       
    76 // ----------------------------------------------------------
       
    77 // CSecuritySettings::CSecuritySettings()
       
    78 // constructor
       
    79 // ----------------------------------------------------------
       
    80 //
       
    81 EXPORT_C CSecuritySettings::CSecuritySettings()
       
    82     {
       
    83     }
       
    84 //
       
    85 // ----------------------------------------------------------
       
    86 // CSecuritySettings::ConstructL()
       
    87 // Symbian OS constructor.
       
    88 // ----------------------------------------------------------
       
    89 //
       
    90 EXPORT_C void CSecuritySettings::ConstructL()
       
    91     {
       
    92     /*****************************************************
       
    93     *    Series 60 Customer / ETel
       
    94     *    Series 60  ETel API
       
    95     *****************************************************/
       
    96     /*****************************************************
       
    97     *    Series 60 Customer / TSY
       
    98     *    Needs customer TSY implementation
       
    99     *****************************************************/
       
   100 
       
   101     TInt err( KErrGeneral );
       
   102     TInt thisTry( 0 );
       
   103     iWait = CWait::NewL();
       
   104     RTelServer::TPhoneInfo PhoneInfo;
       
   105     /* All server connections are tried to be made KTriesToConnectServer times because occasional
       
   106     fails on connections are possible, at least on some servers */
       
   107     #if defined(_DEBUG)
       
   108     RDebug::Print(_L("(SECUI)CSecuritySettings::ConstructL()"));
       
   109     #endif
       
   110     
       
   111     FeatureManager::InitializeLibL();
       
   112     // connect to ETel server
       
   113     while ( ( err = iServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
       
   114         {
       
   115         User::After( KTimeBeforeRetryingServerConnection );
       
   116         }
       
   117     User::LeaveIfError( err );
       
   118 
       
   119     // load TSY
       
   120     err = iServer.LoadPhoneModule( KMmTsyModuleName );
       
   121     if ( err != KErrAlreadyExists )
       
   122         {
       
   123         // May return also KErrAlreadyExists if something else
       
   124         // has already loaded the TSY module. And that is
       
   125         // not an error.
       
   126         User::LeaveIfError( err );
       
   127         }
       
   128 
       
   129     // open phones
       
   130     User::LeaveIfError(iServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended));
       
   131     User::LeaveIfError(iServer.GetPhoneInfo(PhoneIndex, PhoneInfo));
       
   132     User::LeaveIfError(iPhone.Open(iServer,PhoneInfo.iName));
       
   133     User::LeaveIfError(iCustomPhone.Open(iPhone));
       
   134 
       
   135     iSecurityHandler = new( ELeave ) CSecurityHandler( iPhone );
       
   136     }
       
   137 //
       
   138 // ----------------------------------------------------------
       
   139 // CSecuritySettings::~CSecuritySettings()
       
   140 // Destructor
       
   141 // ----------------------------------------------------------
       
   142 //
       
   143 EXPORT_C CSecuritySettings::~CSecuritySettings()
       
   144     {
       
   145     /*****************************************************
       
   146     *    Series 60 Customer / ETel
       
   147     *    Series 60  ETel API
       
   148     *****************************************************/
       
   149     /*****************************************************
       
   150     *    Series 60 Customer / TSY
       
   151     *    Needs customer TSY implementation
       
   152     *****************************************************/
       
   153     delete iSecurityHandler;
       
   154 
       
   155     // Cancel active requests
       
   156     if(iWait->IsActive())
       
   157     {
       
   158         #if defined(_DEBUG)
       
   159 	    RDebug::Print(_L("(SECUI)CManualSecuritySettings::~CSecuritySettings() CANCEL REQ"));
       
   160 	    #endif
       
   161         iPhone.CancelAsyncRequest(iWait->GetRequestType());
       
   162         
       
   163         switch(iWait->GetRequestType())
       
   164             {   //inform query that it has beeen canceled
       
   165                 case EMobilePhoneSetLockSetting:
       
   166                 case EMobilePhoneSetFdnSetting:
       
   167                     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestCanceled);
       
   168                     break;
       
   169                 default:
       
   170                     break;
       
   171             }                            
       
   172         
       
   173     }
       
   174     // close phone
       
   175     if (iPhone.SubSessionHandle())
       
   176         iPhone.Close();
       
   177     // close custom phone
       
   178     if (iCustomPhone.SubSessionHandle())
       
   179         iCustomPhone.Close();
       
   180     //close ETel connection
       
   181     if (iServer.Handle())
       
   182         {
       
   183         iServer.UnloadPhoneModule(KMmTsyModuleName);
       
   184         iServer.Close();
       
   185         }
       
   186     delete iWait;
       
   187     FeatureManager::UnInitializeLib();
       
   188     }
       
   189 //
       
   190 // ----------------------------------------------------------
       
   191 // CSecuritySettings::ChangePinL()
       
   192 // Changes PIN1
       
   193 // ----------------------------------------------------------
       
   194 //
       
   195 EXPORT_C void CSecuritySettings::ChangePinL()
       
   196     {
       
   197     /*****************************************************
       
   198     *    Series 60 Customer / ETel
       
   199     *    Series 60  ETel API
       
   200     *****************************************************/
       
   201     
       
   202     TInt simState;
       
   203     TInt err( KErrGeneral );
       
   204     err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);
       
   205     User::LeaveIfError( err );
       
   206     TBool simRemoved(simState == ESimNotPresent);
       
   207 
       
   208     if ( simRemoved )
       
   209         {
       
   210         ShowResultNoteL(R_INSERT_SIM, CAknNoteDialog::EErrorTone);
       
   211         return;
       
   212         }
       
   213 
       
   214     #if defined(_DEBUG)
       
   215     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinL()"));
       
   216     #endif    
       
   217     RMobilePhone::TMobilePhoneSecurityCode secCodeType;
       
   218     secCodeType = RMobilePhone::ESecurityCodePin1;
       
   219 
       
   220     RMobilePhone::TMobilePassword oldPassword;
       
   221     RMobilePhone::TMobilePassword newPassword;
       
   222     RMobilePhone::TMobilePassword verifcationPassword;
       
   223     RMobilePhone::TMobilePhonePasswordChangeV1 passwords;
       
   224     RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
       
   225     RMobilePhone::TMobilePhoneSecurityCodeInfoV5Pckg codeInfoPkg(codeInfo);
       
   226 
       
   227     CCodeQueryDialog* verdlg = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   228     CleanupStack::PushL(verdlg);
       
   229 
       
   230     CCodeQueryDialog* newdlg = new (ELeave) CCodeQueryDialog(newPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   231     CleanupStack::PushL(newdlg);
       
   232 
       
   233     CCodeQueryDialog* dlg = new (ELeave) CCodeQueryDialog (oldPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);       
       
   234     CleanupStack::PushL(dlg);
       
   235 
       
   236     RMobilePhone::TMobilePhoneLock lockType;
       
   237     RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
   238     
       
   239     lockType = RMobilePhone::ELockICC;
       
   240 
       
   241     RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
   242     iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
   243     iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
   244     TInt res = iWait->WaitForRequestL();
       
   245     User::LeaveIfError(res);
       
   246 
       
   247     if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
       
   248         {    
       
   249         CleanupStack::PopAndDestroy(3,verdlg);
       
   250         ShowResultNoteL(R_PIN_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
   251         return;
       
   252         }
       
   253     
       
   254     CleanupStack::Pop(); // dlg
       
   255     iWait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
       
   256     iPhone.GetSecurityCodeInfo(iWait->iStatus, secCodeType, codeInfoPkg);
       
   257     res = iWait->WaitForRequestL();
       
   258     User::LeaveIfError(res);
       
   259     // ask pin
       
   260     if(codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
       
   261             res = dlg->ExecuteLD(R_PIN_QUERY);
       
   262     else if(codeInfo.iRemainingEntryAttempts > KLastRemainingInputAttempt)
       
   263        {
       
   264          HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_REMAINING_PIN_ATTEMPTS, codeInfo.iRemainingEntryAttempts);
       
   265          res = dlg->ExecuteLD(R_PIN_QUERY, *queryPrompt);
       
   266          CleanupStack::PopAndDestroy(queryPrompt);
       
   267        }
       
   268     else
       
   269        {
       
   270          HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_FINAL_PIN_ATTEMPT);
       
   271          res = dlg->ExecuteLD(R_PIN_QUERY, *queryPrompt);
       
   272          CleanupStack::PopAndDestroy(queryPrompt);   
       
   273        }  
       
   274     
       
   275       if( !res )
       
   276         {
       
   277         CleanupStack::PopAndDestroy(2,verdlg);
       
   278         return;
       
   279         }      
       
   280     CleanupStack::Pop(); // newdlg
       
   281     // new pin code query
       
   282      if (!(newdlg->ExecuteLD(R_NEW_PIN_CODE_QUERY)))
       
   283         {
       
   284         CleanupStack::PopAndDestroy(verdlg);
       
   285         return;
       
   286         }
       
   287 
       
   288     CleanupStack::Pop(); // verdlg
       
   289     // verification code query
       
   290     if (!(verdlg->ExecuteLD(R_VERIFY_NEW_PIN_CODE_QUERY)))
       
   291             return;
       
   292         
       
   293     while (newPassword.CompareF(verifcationPassword) != 0) 
       
   294         {
       
   295         // codes do not match -> note -> ask new pin and verification codes again  
       
   296         ShowResultNoteL(R_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone);
       
   297     
       
   298         newPassword = _L("");
       
   299         verifcationPassword = _L("");
       
   300 
       
   301         // new pin code query
       
   302         CCodeQueryDialog* newdlg = new (ELeave) CCodeQueryDialog (newPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   303         if (!(newdlg->ExecuteLD(R_NEW_PIN_CODE_QUERY)))
       
   304               return;
       
   305         
       
   306         // verification code query
       
   307         CCodeQueryDialog* verdlg = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   308         if (!(verdlg->ExecuteLD(R_VERIFY_NEW_PIN_CODE_QUERY)))
       
   309             return;
       
   310         }            
       
   311         
       
   312     // send code
       
   313     passwords.iOldPassword = oldPassword;
       
   314     passwords.iNewPassword = newPassword;
       
   315     iWait->SetRequestType(EMobilePhoneChangeSecurityCode);
       
   316     iPhone.ChangeSecurityCode(iWait->iStatus, secCodeType, passwords);
       
   317     res = iWait->WaitForRequestL();
       
   318     #if defined(_DEBUG)
       
   319     RDebug::Print( _L("(SECUI)CSecuritySettings::ChangePinL(): RETURN CODE: %d"), res);
       
   320     #endif
       
   321     switch(res)
       
   322         {
       
   323         case KErrNone:
       
   324             {
       
   325             // code changed 
       
   326             ShowResultNoteL(R_PIN_CODE_CHANGED_NOTE, CAknNoteDialog::EConfirmationTone);
       
   327             break;
       
   328             }        
       
   329         case KErrGsm0707IncorrectPassword:
       
   330         case KErrAccessDenied:
       
   331             {    
       
   332             // code was entered erroneously
       
   333             ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone);
       
   334             ChangePinL();
       
   335             break;
       
   336             }    
       
   337         case KErrGsmSSPasswordAttemptsViolation:
       
   338         case KErrLocked:
       
   339             {
       
   340             // Pin1 blocked! 
       
   341             return;
       
   342             }
       
   343         case KErrGsm0707OperationNotAllowed:
       
   344             {
       
   345             // not allowed with this sim
       
   346             ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
   347             return;
       
   348             }
       
   349         case KErrAbort:
       
   350             {
       
   351             break;
       
   352             }
       
   353         default:
       
   354             {
       
   355             ShowErrorNoteL(res);
       
   356             ChangePinL();
       
   357             break;
       
   358             }
       
   359         }
       
   360 
       
   361     }
       
   362 
       
   363 //
       
   364 // ----------------------------------------------------------
       
   365 // CSecuritySettings::ChangeUPinL()
       
   366 // Changes Universal PIN
       
   367 // ----------------------------------------------------------
       
   368 //
       
   369 EXPORT_C void CSecuritySettings::ChangeUPinL()
       
   370     {
       
   371     TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
       
   372     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
       
   373     if(wcdmaSupported || upinSupported)
       
   374       {
       
   375         #if defined(_DEBUG)
       
   376         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeUPinL()"));
       
   377         #endif
       
   378         TInt simState;
       
   379         TInt err( KErrGeneral );
       
   380         err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);
       
   381         User::LeaveIfError( err );
       
   382         TBool simRemoved(simState == ESimNotPresent);
       
   383     
       
   384         if ( simRemoved )
       
   385             {
       
   386             ShowResultNoteL(R_INSERT_SIM, CAknNoteDialog::EErrorTone);
       
   387             return;
       
   388             }
       
   389     
       
   390         RMobilePhone::TMobilePhoneSecurityCode secCodeType;
       
   391         secCodeType = RMobilePhone::ESecurityUniversalPin;
       
   392     
       
   393         RMobilePhone::TMobilePassword oldPassword;
       
   394         RMobilePhone::TMobilePassword newPassword;
       
   395         RMobilePhone::TMobilePassword verifcationPassword;
       
   396         RMobilePhone::TMobilePhonePasswordChangeV1 passwords;
       
   397         RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
       
   398         RMobilePhone::TMobilePhoneSecurityCodeInfoV5Pckg codeInfoPkg(codeInfo);
       
   399     
       
   400         CCodeQueryDialog* verdlg = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   401         CleanupStack::PushL(verdlg);
       
   402     
       
   403         CCodeQueryDialog* newdlg = new (ELeave) CCodeQueryDialog(newPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   404         CleanupStack::PushL(newdlg);
       
   405     
       
   406         CCodeQueryDialog* dlg = new (ELeave) CCodeQueryDialog (oldPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);       
       
   407         CleanupStack::PushL(dlg);
       
   408     
       
   409         RMobilePhone::TMobilePhoneLock lockType;
       
   410         RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
   411         
       
   412         lockType = RMobilePhone::ELockUniversalPin;
       
   413         
       
   414         RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
   415         iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
   416         iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
   417         TInt res = iWait->WaitForRequestL();
       
   418         User::LeaveIfError(res);
       
   419     
       
   420         if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
       
   421             {    
       
   422             CleanupStack::PopAndDestroy(3,verdlg);
       
   423             ShowResultNoteL(R_UPIN_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
   424             return;
       
   425             }
       
   426         
       
   427         CleanupStack::Pop(); // dlg
       
   428         // ask pin
       
   429         iWait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
       
   430         iPhone.GetSecurityCodeInfo(iWait->iStatus, secCodeType, codeInfoPkg);
       
   431         res = iWait->WaitForRequestL();
       
   432         User::LeaveIfError(res);
       
   433             
       
   434         if(codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
       
   435             res = dlg->ExecuteLD(R_UPIN_QUERY);
       
   436         else if(codeInfo.iRemainingEntryAttempts > KLastRemainingInputAttempt)
       
   437             {
       
   438               HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_REMAINING_UPIN_ATTEMPTS, codeInfo.iRemainingEntryAttempts);
       
   439               res = dlg->ExecuteLD(R_UPIN_QUERY, *queryPrompt);
       
   440               CleanupStack::PopAndDestroy(queryPrompt);
       
   441             }
       
   442         else
       
   443             {
       
   444               HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_FINAL_UPIN_ATTEMPT);
       
   445               res = dlg->ExecuteLD(R_UPIN_QUERY, *queryPrompt);
       
   446               CleanupStack::PopAndDestroy(queryPrompt);   
       
   447             }        
       
   448         
       
   449         
       
   450         
       
   451          if( !res )
       
   452             {
       
   453             CleanupStack::PopAndDestroy(2,verdlg);
       
   454             return;
       
   455             }      
       
   456         CleanupStack::Pop(); // newdlg
       
   457         // new pin code query
       
   458          if (!(newdlg->ExecuteLD(R_NEW_UPIN_CODE_QUERY)))
       
   459             {
       
   460             CleanupStack::PopAndDestroy(verdlg);
       
   461             return;
       
   462             }
       
   463     
       
   464         CleanupStack::Pop(); // verdlg
       
   465         // verification code query
       
   466         if (!(verdlg->ExecuteLD(R_VERIFY_NEW_UPIN_CODE_QUERY)))
       
   467                 return;
       
   468             
       
   469         while (newPassword.CompareF(verifcationPassword) != 0) 
       
   470             {
       
   471             // codes do not match -> note -> ask new pin and verification codes again  
       
   472             ShowResultNoteL(R_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone);
       
   473         
       
   474             newPassword = _L("");
       
   475             verifcationPassword = _L("");
       
   476     
       
   477             // new pin code query
       
   478             CCodeQueryDialog* newdlg = new (ELeave) CCodeQueryDialog (newPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   479             if (!(newdlg->ExecuteLD(R_NEW_UPIN_CODE_QUERY)))
       
   480                   return;
       
   481             
       
   482             // verification code query
       
   483             CCodeQueryDialog* verdlg = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);
       
   484             if (!(verdlg->ExecuteLD(R_VERIFY_NEW_UPIN_CODE_QUERY)))
       
   485                 return;
       
   486             }            
       
   487             
       
   488         // send code
       
   489         passwords.iOldPassword = oldPassword;
       
   490         passwords.iNewPassword = newPassword;
       
   491         iWait->SetRequestType(EMobilePhoneChangeSecurityCode);
       
   492         iPhone.ChangeSecurityCode(iWait->iStatus, secCodeType, passwords);
       
   493         res = iWait->WaitForRequestL();
       
   494         #if defined(_DEBUG)
       
   495         RDebug::Print( _L("(SECUI)CSecuritySettings::ChangePinL(): RETURN CODE: %d"), res);
       
   496         #endif
       
   497         switch(res)
       
   498             {
       
   499             case KErrNone:
       
   500                 {
       
   501                 // code changed 
       
   502                 ShowResultNoteL(R_UPIN_CODE_CHANGED_NOTE, CAknNoteDialog::EConfirmationTone);
       
   503                 break;
       
   504                 }        
       
   505             case KErrGsm0707IncorrectPassword:
       
   506             case KErrAccessDenied:
       
   507                 {    
       
   508                 // code was entered erroneously
       
   509                 ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone);
       
   510                 ChangeUPinL();
       
   511                 break;
       
   512                 }    
       
   513             case KErrGsmSSPasswordAttemptsViolation:
       
   514             case KErrLocked:
       
   515                 {
       
   516                 return;
       
   517                 }
       
   518             case KErrGsm0707OperationNotAllowed:
       
   519                 {
       
   520                 // not allowed with this sim
       
   521                 ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
   522                 return;
       
   523                 }
       
   524             case KErrAbort:
       
   525                 {
       
   526                 break;
       
   527                 }
       
   528             default:
       
   529                 {
       
   530                 ShowErrorNoteL(res);
       
   531                 ChangeUPinL();
       
   532                 break;
       
   533                 }
       
   534             }
       
   535       }
       
   536 
       
   537     }
       
   538 
       
   539 //
       
   540 // ----------------------------------------------------------
       
   541 // CSecuritySettings::ChangePin2L()
       
   542 // Changes PIN2
       
   543 // ----------------------------------------------------------
       
   544 //
       
   545 EXPORT_C void CSecuritySettings::ChangePin2L()
       
   546     {
       
   547     /*****************************************************
       
   548     *    Series 60 Customer / ETel
       
   549     *    Series 60  ETel API
       
   550     *****************************************************/
       
   551     #if defined(_DEBUG)
       
   552     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePin2L()"));
       
   553     #endif
       
   554     TInt simState;
       
   555     TInt err( KErrGeneral );
       
   556     err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);
       
   557     User::LeaveIfError( err );
       
   558     TBool simRemoved(simState == ESimNotPresent);
       
   559 
       
   560     if ( simRemoved )
       
   561         {
       
   562         ShowResultNoteL(R_INSERT_SIM, CAknNoteDialog::EErrorTone);
       
   563         return;
       
   564         }
       
   565 
       
   566     RMmCustomAPI::TSecurityCodeType secCodeType;
       
   567     RMobilePhone::TMobilePhoneSecurityCode EtelsecCodeType;
       
   568     secCodeType = RMmCustomAPI::ESecurityCodePin2;
       
   569     RMobilePhone::TMobilePassword oldPassword;
       
   570     RMobilePhone::TMobilePassword newPassword;
       
   571     RMobilePhone::TMobilePassword verifcationPassword;
       
   572     RMobilePhone::TMobilePhonePasswordChangeV1 passwords;
       
   573     RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
       
   574     RMobilePhone::TMobilePhoneSecurityCodeInfoV5Pckg codeInfoPkg(codeInfo);
       
   575     
       
   576     // check if pin2 is blocked...
       
   577     TBool isBlocked = EFalse;
       
   578 
       
   579     TInt ret = iCustomPhone.IsBlocked(secCodeType,isBlocked);
       
   580     
       
   581     if(isBlocked)
       
   582         return;
       
   583     
       
   584     if (ret != KErrNone)
       
   585         {    
       
   586         switch (ret)
       
   587             {
       
   588             // PIN2 Blocked.
       
   589             case KErrGsm0707SIMPuk2Required:
       
   590                 break;
       
   591             case KErrGsmSSPasswordAttemptsViolation:
       
   592             case KErrLocked:
       
   593                 // Pin2 features blocked permanently!
       
   594                 ShowResultNoteL(R_PIN2_REJECTED, CAknNoteDialog::EConfirmationTone);
       
   595                 break;
       
   596             case KErrGsm0707SimNotInserted:
       
   597                 // not allowed with this sim
       
   598                 ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
   599                 break;
       
   600             default:
       
   601                 ShowErrorNoteL(ret);
       
   602                 break;
       
   603             }
       
   604         return;
       
   605         }
       
   606     
       
   607     CCodeQueryDialog* verdlg = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_PIN2_CODE_MIN_LENGTH,SEC_C_PIN2_CODE_MAX_LENGTH,ESecUiNone);
       
   608     CleanupStack::PushL(verdlg);
       
   609 
       
   610     CCodeQueryDialog* newdlg = new (ELeave) CCodeQueryDialog(newPassword,SEC_C_PIN2_CODE_MIN_LENGTH,SEC_C_PIN2_CODE_MAX_LENGTH,ESecUiNone);    
       
   611     CleanupStack::PushL(newdlg);
       
   612 
       
   613     CCodeQueryDialog* dlg = new (ELeave) CCodeQueryDialog (oldPassword,SEC_C_PIN2_CODE_MIN_LENGTH,SEC_C_PIN2_CODE_MAX_LENGTH,ESecUiNone);      
       
   614     CleanupStack::PushL(dlg);
       
   615 
       
   616 
       
   617     // Security code must be changed to Etel API format
       
   618     // Custom API Pin1 and Pin2 have the same enum values as the Etel ones
       
   619     EtelsecCodeType = (RMobilePhone::TMobilePhoneSecurityCode)secCodeType;
       
   620     #ifndef __WINS__    
       
   621         iWait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
       
   622         iPhone.GetSecurityCodeInfo(iWait->iStatus, EtelsecCodeType, codeInfoPkg);
       
   623         ret = iWait->WaitForRequestL();
       
   624         User::LeaveIfError(ret);
       
   625     #else
       
   626         codeInfo.iRemainingEntryAttempts = 1;
       
   627     #endif //__WINS__
       
   628 
       
   629     if(codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
       
   630             ret = dlg->ExecuteLD(R_PIN2_QUERY);
       
   631     else if(codeInfo.iRemainingEntryAttempts > KLastRemainingInputAttempt)
       
   632        {
       
   633          HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_REMAINING_PIN2_ATTEMPTS, codeInfo.iRemainingEntryAttempts );
       
   634          ret = dlg->ExecuteLD(R_PIN2_QUERY, *queryPrompt);
       
   635          CleanupStack::PopAndDestroy(queryPrompt);
       
   636        }
       
   637     else
       
   638        {
       
   639          HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_FINAL_PIN2_ATTEMPT);
       
   640          ret = dlg->ExecuteLD(R_PIN2_QUERY, *queryPrompt);
       
   641          CleanupStack::PopAndDestroy(queryPrompt);   
       
   642        }
       
   643 
       
   644     CleanupStack::Pop(); // dlg
       
   645     if(!ret)
       
   646         {
       
   647         CleanupStack::PopAndDestroy(2,verdlg);
       
   648         return;
       
   649         }
       
   650 
       
   651     // new pin code query
       
   652     CleanupStack::Pop(); // newdlg
       
   653     if(!(newdlg->ExecuteLD(R_NEW_PIN2_CODE_QUERY)))
       
   654         {
       
   655         CleanupStack::PopAndDestroy(verdlg);
       
   656         return;
       
   657         }
       
   658 
       
   659      // verification code query
       
   660     CleanupStack::Pop(); // verdlg
       
   661     if(!(verdlg->ExecuteLD(R_VERIFY_NEW_PIN2_CODE_QUERY)))
       
   662         {
       
   663         return;
       
   664         }
       
   665 
       
   666     while (newPassword.CompareF(verifcationPassword) != 0)     
       
   667         {
       
   668         // codes do not match -> note -> ask new pin and verification codes again  
       
   669         ShowResultNoteL(R_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone);
       
   670 
       
   671         newPassword = _L("");
       
   672         verifcationPassword = _L("");
       
   673         
       
   674         // new pin code query
       
   675         CCodeQueryDialog* dlg = new (ELeave) CCodeQueryDialog (newPassword,SEC_C_PIN2_CODE_MIN_LENGTH,SEC_C_PIN2_CODE_MAX_LENGTH,ESecUiNone);
       
   676         if(!(dlg->ExecuteLD(R_NEW_PIN2_CODE_QUERY)))
       
   677             return;
       
   678               
       
   679         // verification code query
       
   680         CCodeQueryDialog* dlg2 = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_PIN2_CODE_MIN_LENGTH,SEC_C_PIN2_CODE_MAX_LENGTH,ESecUiNone);
       
   681           if(!(dlg2->ExecuteLD(R_VERIFY_NEW_PIN2_CODE_QUERY)))
       
   682             return;
       
   683         }        
       
   684     
       
   685 
       
   686     passwords.iOldPassword = oldPassword;
       
   687     passwords.iNewPassword = newPassword;
       
   688     iWait->SetRequestType(EMobilePhoneChangeSecurityCode);
       
   689     iPhone.ChangeSecurityCode(iWait->iStatus,EtelsecCodeType,passwords);
       
   690     TInt res = iWait->WaitForRequestL();
       
   691         #if defined(_DEBUG)
       
   692     RDebug::Print( _L("(SECUI)CSecuritySettings::ChangePin2L(): RETURN CODE: %d"), res);
       
   693     #endif
       
   694     switch(res)
       
   695         {
       
   696         case KErrNone:
       
   697             {
       
   698             // code changed 
       
   699             ShowResultNoteL(R_PIN2_CODE_CHANGED_NOTE, CAknNoteDialog::EConfirmationTone);
       
   700             break;
       
   701             }        
       
   702         case KErrGsm0707IncorrectPassword:
       
   703         case KErrAccessDenied:
       
   704             {    
       
   705             ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone);
       
   706             ChangePin2L();
       
   707             break;
       
   708             }    
       
   709         case KErrGsmSSPasswordAttemptsViolation:
       
   710         case KErrLocked:
       
   711             {
       
   712             // Pin2 blocked!
       
   713             ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone);
       
   714             CSecurityHandler* handler = new(ELeave) CSecurityHandler(iPhone);
       
   715             CleanupStack::PushL(handler); 
       
   716             handler->HandleEventL(RMobilePhone::EPuk2Required);
       
   717             CleanupStack::PopAndDestroy(handler); // handler    
       
   718             return;
       
   719             }
       
   720         case KErrGsm0707OperationNotAllowed:
       
   721             {
       
   722             // not allowed with this sim
       
   723             ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
   724             return;
       
   725             }
       
   726         case KErrAbort:
       
   727             {
       
   728             break;
       
   729             }
       
   730         default:
       
   731             {
       
   732             ShowErrorNoteL(res);
       
   733             ChangePin2L();
       
   734             break;
       
   735             }
       
   736         }
       
   737      }
       
   738 //
       
   739 // ----------------------------------------------------------
       
   740 // CSecuritySettings::ChangeSecCodeL()
       
   741 // Changes security code 
       
   742 // ----------------------------------------------------------
       
   743 //
       
   744 EXPORT_C void CSecuritySettings::ChangeSecCodeL()
       
   745     {  
       
   746     /*****************************************************
       
   747     *    Series 60 Customer / ETel
       
   748     *    Series 60  ETel API
       
   749     *****************************************************/
       
   750     #if defined(_DEBUG)
       
   751     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeSecCodeL()"));
       
   752     #endif
       
   753     TInt res;
       
   754     RMobilePhone::TMobilePassword newPassword;
       
   755 if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ) &&
       
   756 		(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements  )))   
       
   757 { 
       
   758     
       
   759     // Connect to the SCP server, and request the code change
       
   760     RSCPClient scpClient;
       
   761     User::LeaveIfError( scpClient.Connect() );
       
   762     CleanupClosePushL( scpClient );
       
   763     res = scpClient.ChangeCodeRequest();
       
   764     CleanupStack::PopAndDestroy(); // scpClient
       
   765     
       
   766 }
       
   767 else
       
   768 {
       
   769          
       
   770     RMobilePhone::TMobilePhoneSecurityCode secCodeType;
       
   771     secCodeType = RMobilePhone::ESecurityCodePhonePassword;
       
   772     RMobilePhone::TMobilePassword oldPassword;
       
   773     RMobilePhone::TMobilePassword verifcationPassword;
       
   774     RMobilePhone::TMobilePassword required_fourth;
       
   775     RMobilePhone::TMobilePhonePasswordChangeV1 passwords;
       
   776 
       
   777     CCodeQueryDialog* verdlg = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_SECURITY_CODE_MIN_LENGTH,SEC_C_SECURITY_CODE_CHANGE_MAX_LENGTH,ESecUiNone);
       
   778     CleanupStack::PushL(verdlg);
       
   779 
       
   780     CCodeQueryDialog* newdlg = new (ELeave) CCodeQueryDialog(newPassword,SEC_C_SECURITY_CODE_MIN_LENGTH,SEC_C_SECURITY_CODE_CHANGE_MAX_LENGTH,ESecUiNone);
       
   781     CleanupStack::PushL(newdlg);
       
   782 
       
   783     CCodeQueryDialog* dlg = new (ELeave) CCodeQueryDialog (oldPassword,SEC_C_SECURITY_CODE_MIN_LENGTH,SEC_C_SECURITY_CODE_MAX_LENGTH,ESecUiNone);
       
   784     CleanupStack::PushL(dlg);
       
   785 
       
   786     // ask security code
       
   787     CleanupStack::Pop(); // dlg
       
   788     if (!(dlg->ExecuteLD(R_SECURITY_QUERY)))
       
   789         {
       
   790         CleanupStack::PopAndDestroy(2,verdlg);
       
   791         return;
       
   792         }
       
   793     // new security code query
       
   794     CleanupStack::Pop(); // newdlg
       
   795     if(!(newdlg->ExecuteLD(R_NEW_SECURITY_CODE_QUERY)))
       
   796         {    
       
   797         CleanupStack::PopAndDestroy(verdlg);
       
   798         return;
       
   799         }
       
   800      
       
   801     // verification code query
       
   802     CleanupStack::Pop(); // verdlg
       
   803       if(!(verdlg->ExecuteLD(R_VERIFY_NEW_SECURITY_CODE_QUERY)))
       
   804         {
       
   805         return;
       
   806         }
       
   807 
       
   808     while (newPassword.CompareF(verifcationPassword) != 0)         
       
   809         {            
       
   810         // codes do not match -> note -> ask new pin and verification codes again  
       
   811         ShowResultNoteL(R_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone);
       
   812         
       
   813         newPassword = _L("");
       
   814         verifcationPassword = _L("");
       
   815 
       
   816         // new pin code query
       
   817         CCodeQueryDialog* dlg = new (ELeave) CCodeQueryDialog (newPassword,SEC_C_SECURITY_CODE_MIN_LENGTH,SEC_C_SECURITY_CODE_CHANGE_MAX_LENGTH,ESecUiNone);
       
   818         if(!(dlg->ExecuteLD(R_NEW_SECURITY_CODE_QUERY)))
       
   819             return;
       
   820           
       
   821         // verification code query
       
   822         CCodeQueryDialog* dlg2 = new (ELeave) CCodeQueryDialog (verifcationPassword,SEC_C_SECURITY_CODE_MIN_LENGTH,SEC_C_SECURITY_CODE_CHANGE_MAX_LENGTH,ESecUiNone);
       
   823           if(!(dlg2->ExecuteLD(R_VERIFY_NEW_SECURITY_CODE_QUERY)))
       
   824             return;    
       
   825         }            
       
   826     iWait->SetRequestType(EMobilePhoneVerifySecurityCode);    
       
   827     // check code
       
   828     iPhone.VerifySecurityCode(iWait->iStatus,secCodeType, oldPassword, required_fourth);
       
   829     res = iWait->WaitForRequestL();
       
   830     #if defined(_DEBUG)
       
   831     RDebug::Print( _L("(SECUI)CSecuritySettings::ChangeSecCode(): CODE VERIFY RESP: %d"), res);
       
   832     #endif
       
   833     // change code 
       
   834     if (res == KErrNone)
       
   835         {
       
   836         passwords.iOldPassword = oldPassword;
       
   837         passwords.iNewPassword = newPassword;
       
   838         iWait->SetRequestType(EMobilePhoneChangeSecurityCode);
       
   839         iPhone.ChangeSecurityCode(iWait->iStatus,secCodeType,passwords);
       
   840         res = iWait->WaitForRequestL();
       
   841         }
       
   842         
       
   843 }
       
   844         
       
   845     #if defined(_DEBUG)
       
   846     RDebug::Print( _L("(SECUI)CSecuritySettings::ChangeSecCode(): RETURN CODE: %d"), res);
       
   847     #endif
       
   848     switch(res)
       
   849         {
       
   850         case KErrNone:
       
   851             {
       
   852             // code changed 
       
   853             ShowResultNoteL(R_SECURITY_CODE_CHANGED_NOTE, CAknNoteDialog::EConfirmationTone);
       
   854             if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ) &&
       
   855 								!(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements  )))
       
   856 						{
       
   857             // Send the changed code to the SCP server. Not used with device lock enhancements.
       
   858             
       
   859             RSCPClient scpClient;
       
   860             TSCPSecCode newCode;
       
   861             newCode.Copy( newPassword );
       
   862             if ( scpClient.Connect() == KErrNone )
       
   863                 {
       
   864                 scpClient.StoreCode( newCode );
       
   865                 scpClient.Close();
       
   866                 }                                               
       
   867           }
       
   868                         
       
   869             break;
       
   870             }
       
   871         case KErrGsmSSPasswordAttemptsViolation:
       
   872         case KErrLocked:
       
   873             {
       
   874             ShowResultNoteL(R_SEC_BLOCKED, CAknNoteDialog::EErrorTone);
       
   875             ChangeSecCodeL();
       
   876             break;
       
   877             }
       
   878         case KErrGsm0707IncorrectPassword:
       
   879         case KErrAccessDenied:
       
   880             {    
       
   881             // code was entered erroneously
       
   882             ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone);
       
   883             ChangeSecCodeL();
       
   884             break;
       
   885             }
       
   886         case KErrAbort:
       
   887             {
       
   888             break;
       
   889             }
       
   890         default:
       
   891             {
       
   892             ShowErrorNoteL(res);
       
   893             ChangeSecCodeL();
       
   894             break;
       
   895             }
       
   896         }
       
   897     }
       
   898 //
       
   899 // ----------------------------------------------------------
       
   900 // CSecuritySettings::ChangeAutoLockPeriodL()
       
   901 // Changes autolock period
       
   902 // ----------------------------------------------------------
       
   903 //
       
   904 EXPORT_C TInt CSecuritySettings::ChangeAutoLockPeriodL(TInt aPeriod)
       
   905     {            
       
   906     /*****************************************************
       
   907     *    Series 60 Customer / ETel
       
   908     *    Series 60  ETel API
       
   909     *****************************************************/
       
   910     #if defined(_DEBUG)
       
   911     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodLXXXX()"));
       
   912     #endif
       
   913     RMobilePhone::TMobilePhoneLockSetting lockChange(RMobilePhone::ELockSetDisabled);
       
   914     RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
       
   915     TInt currentItem = 0;
       
   916     TInt oldPeriod = aPeriod;
       
   917 
       
   918     #if defined(_DEBUG)
       
   919     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() ReadDesC16ArrayResourceL"));
       
   920     #endif
       
   921 
       
   922 
       
   923     CCoeEnv* coeEnv = CCoeEnv::Static();        
       
   924     CDesCArrayFlat* items =  coeEnv->ReadDesC16ArrayResourceL(R_AUTOLOCK_LBX);
       
   925     CleanupStack::PushL(items);
       
   926         
       
   927     if (aPeriod == 0)
       
   928         {
       
   929         currentItem = 0;  // autolock off
       
   930         }
       
   931     else
       
   932         {
       
   933         currentItem = 1;  // user defined
       
   934         }
       
   935     
       
   936 
       
   937     #if defined(_DEBUG)
       
   938     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() New autolocksettingpage"));
       
   939     #endif
       
   940     
       
   941     CAutoLockSettingPage* dlg = new (ELeave)CAutoLockSettingPage(R_AUTOLOCK_SETTING_PAGE, currentItem, items, aPeriod);
       
   942     CleanupStack::PushL(dlg);
       
   943     dlg->ConstructL();
       
   944     TInt maxPeriod;
       
   945     if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))
       
   946 		{
       
   947     // Retrieve the current autolock period max. value from the SCP server, 
       
   948     // and check that the value the user
       
   949     // selected is ok from the Corporate Policy point of view.
       
   950 	RSCPClient scpClient;
       
   951     TInt ret = scpClient.Connect();
       
   952     if ( ret == KErrNone )
       
   953         {       
       
   954         CleanupClosePushL( scpClient );
       
   955         TBuf<KSCPMaxIntLength> maxPeriodBuf;
       
   956         if ( scpClient.GetParamValue( ESCPMaxAutolockPeriod, maxPeriodBuf ) == KErrNone )
       
   957             {
       
   958             TLex lex( maxPeriodBuf );          
       
   959             if ( ( lex.Val( maxPeriod ) == KErrNone ) && ( maxPeriod > 0 ) )
       
   960                 {               
       
   961                  dlg->SetPeriodMaximumValue(maxPeriod);
       
   962                 }
       
   963             else
       
   964                 {
       
   965                    maxPeriod = 0;
       
   966                    dlg->SetPeriodMaximumValue(maxPeriod);     
       
   967                 }
       
   968                 
       
   969             }
       
   970         else
       
   971             {
       
   972             #if defined(_DEBUG)
       
   973             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL():\
       
   974                 ERROR: Failed to retrieve max period"));
       
   975             #endif            
       
   976             }            
       
   977         }
       
   978     else
       
   979         {
       
   980         #if defined(_DEBUG)
       
   981         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL():\
       
   982             ERROR: Failed to connect to SCP."));
       
   983         #endif            
       
   984         }
       
   985     CleanupStack::PopAndDestroy(); // scpClient 
       
   986 }
       
   987     CleanupStack::Pop(); //dlg
       
   988     if (!dlg->ExecuteLD(CAknSettingPage::EUpdateWhenChanged))
       
   989         {
       
   990         CleanupStack::PopAndDestroy(items);           
       
   991         return oldPeriod;
       
   992         }
       
   993     
       
   994     CleanupStack::PopAndDestroy();    // items
       
   995     
       
   996     if(FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))
       
   997 		{
       
   998     TBool allow = ETrue;               
       
   999                
       
  1000     if ((aPeriod == 0) && (maxPeriod > 0))
       
  1001        {
       
  1002         #if defined(_DEBUG)
       
  1003         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() \
       
  1004         The period: %d is not allowed by TARM; max: %d"),aPeriod, maxPeriod );
       
  1005         #endif                
       
  1006         allow = EFalse;                                                
       
  1007         HBufC* prompt;
       
  1008         prompt = StringLoader::LoadLC( R_SECUI_TEXT_AUTOLOCK_MUST_BE_ACTIVE );
       
  1009         CAknNoteDialog* noteDlg = new (ELeave) CAknNoteDialog( REINTERPRET_CAST(CEikDialog**,&noteDlg) );
       
  1010         noteDlg->PrepareLC( R_CODE_ERROR );
       
  1011         noteDlg->SetTextL( *prompt );
       
  1012         noteDlg->SetTimeout( CAknNoteDialog::ELongTimeout );
       
  1013         noteDlg->SetTone( CAknNoteDialog::EErrorTone );
       
  1014         noteDlg->RunLD();                    
       
  1015                     
       
  1016         CleanupStack::PopAndDestroy( prompt );                      
       
  1017         }          
       
  1018         
       
  1019     if ( !allow ) 
       
  1020         {
       
  1021          return ChangeAutoLockPeriodL( oldPeriod );
       
  1022         }                       
       
  1023   }
       
  1024 
       
  1025     if (aPeriod == 0)
       
  1026         {
       
  1027         
       
  1028         #ifdef RD_REMOTELOCK
       
  1029 
       
  1030         // If remote lock is enabled, don't disable the domestic OS device lock
       
  1031         // since that would render the RemoteLock useless.
       
  1032         // Instead just re-set the DOS lock to enabled which as a side effect
       
  1033         // requests the security code from the user.
       
  1034 
       
  1035         TBool remoteLockStatus( EFalse );
       
  1036         CRemoteLockSettings* remoteLockSettings = CRemoteLockSettings::NewL();
       
  1037 
       
  1038         if ( remoteLockSettings->GetEnabled( remoteLockStatus ) )
       
  1039             {
       
  1040             if ( remoteLockStatus )
       
  1041                 {
       
  1042                 // Remote lock is enabled
       
  1043                 #ifdef _DEBUG
       
  1044                 RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeAutoLockPeriodL() - RemoteLock is enabled: lockChange = RMobilePhone::ELockSetEnabled" ) );
       
  1045                 #endif // _DEBUG
       
  1046 
       
  1047                 lockChange = RMobilePhone::ELockSetEnabled;
       
  1048                 }
       
  1049             else
       
  1050                 {
       
  1051                 // Remote lock is disabled
       
  1052                 #ifdef _DEBUG
       
  1053                 RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeAutoLockPeriodL() - RemoteLock is disabled: lockChange = RMobilePhone::ELockSetDisabled" ) );
       
  1054                 #endif // _DEBUG
       
  1055 
       
  1056                 lockChange = RMobilePhone::ELockSetDisabled;
       
  1057                 }
       
  1058             }
       
  1059         else
       
  1060             {
       
  1061             // Failed to get remote lock status
       
  1062             #ifdef _DEBUG
       
  1063             RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeAutoLockPeriodL() - Failed to get RemoteLock status" ) );
       
  1064             #endif // _DEBUG
       
  1065             }
       
  1066 
       
  1067         delete remoteLockSettings;
       
  1068         remoteLockSettings = NULL;
       
  1069 
       
  1070         #else // not defined RD_REMOTELOCK
       
  1071 
       
  1072         lockChange = RMobilePhone::ELockSetDisabled;
       
  1073 
       
  1074         #endif // RD_REMOTELOCK
       
  1075         }
       
  1076     else
       
  1077         {
       
  1078         lockChange = RMobilePhone::ELockSetEnabled;
       
  1079         }
       
  1080     #if defined(_DEBUG)
       
  1081     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() SetLockSetting"));
       
  1082     #endif
       
  1083         iWait->SetRequestType(EMobilePhoneSetLockSetting);
       
  1084         RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
       
  1085         iPhone.SetLockSetting(iWait->iStatus,lockType,lockChange);
       
  1086         TInt status = iWait->WaitForRequestL();
       
  1087         #if defined(_DEBUG)
       
  1088         RDebug::Print( _L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL(): RETURN CODE: %d"), status);
       
  1089         #endif
       
  1090         switch(status)
       
  1091         {
       
  1092         case KErrNone:
       
  1093             #if defined(_DEBUG)
       
  1094             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() KErrNone"));
       
  1095             #endif
       
  1096             break;
       
  1097         case KErrGsmSSPasswordAttemptsViolation:
       
  1098         case KErrLocked:
       
  1099             #if defined(_DEBUG)
       
  1100             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() PasswordAttemptsViolation"));
       
  1101             #endif
       
  1102             return ChangeAutoLockPeriodL(oldPeriod);
       
  1103         case KErrGsm0707IncorrectPassword:
       
  1104         case KErrAccessDenied:
       
  1105             #if defined(_DEBUG)
       
  1106             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() IncorrectPassword"));
       
  1107             #endif
       
  1108             // code was entered erroneously
       
  1109             return ChangeAutoLockPeriodL(oldPeriod);
       
  1110         case KErrAbort:
       
  1111             // User pressed "cancel" in the code query dialog.
       
  1112             return oldPeriod;
       
  1113         default:
       
  1114             #if defined(_DEBUG)
       
  1115             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() default"));
       
  1116             #endif            
       
  1117             return ChangeAutoLockPeriodL(oldPeriod);
       
  1118         }
       
  1119     #if defined(_DEBUG)
       
  1120     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() END"));
       
  1121     #endif
       
  1122     return aPeriod; 
       
  1123     }
       
  1124 
       
  1125 
       
  1126 
       
  1127 //
       
  1128 // ----------------------------------------------------------
       
  1129 // CSecuritySettings::ChangeRemoteLockStatusL()
       
  1130 // Changes remote lock status (on/off)
       
  1131 // ----------------------------------------------------------
       
  1132 //
       
  1133 EXPORT_C TInt CSecuritySettings::ChangeRemoteLockStatusL( TBool& aRemoteLockStatus, TDes& aRemoteLockCode, TInt aAutoLockPeriod )
       
  1134     {
       
  1135    #ifdef RD_REMOTELOCK
       
  1136     TInt retValue( KErrNone );
       
  1137 
       
  1138     #ifdef _DEBUG
       
  1139     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Enter, aRemoteLockStatus == %d, aAutoLockPeriod == %d" ), aRemoteLockStatus, aAutoLockPeriod );
       
  1140     #endif // _DEBUG
       
  1141 
       
  1142     CCoeEnv* coeEnv       = CCoeEnv::Static();        
       
  1143     CDesCArrayFlat* items = coeEnv->ReadDesC16ArrayResourceL( R_REMOTELOCK_LBX );
       
  1144     CleanupStack::PushL( items );
       
  1145 
       
  1146     // Store the current remote lock setting 
       
  1147     TInt previousItem( 0 );
       
  1148     TInt currentItem(  0 );
       
  1149 
       
  1150     if ( aRemoteLockStatus )
       
  1151         {
       
  1152         previousItem = KRemoteLockSettingItemOn;
       
  1153         currentItem  = KRemoteLockSettingItemOn;
       
  1154         }
       
  1155     else
       
  1156         {
       
  1157         previousItem = KRemoteLockSettingItemOff;
       
  1158         currentItem  = KRemoteLockSettingItemOff;
       
  1159         }
       
  1160 
       
  1161     // Create Remote Lock setting page for user to enable or disable remote locking 
       
  1162     CRemoteLockSettingPage* remoteLockSettingPage = new( ELeave ) CRemoteLockSettingPage( R_REMOTELOCK_SETTING_PAGE, currentItem, items );
       
  1163 
       
  1164     #ifdef _DEBUG
       
  1165     RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Executing CRemoteLockSettingPage dialog" ) );
       
  1166     #endif // _DEBUG
       
  1167 
       
  1168     // Execute the remote lock enable/disable dialog
       
  1169     TBool ret = remoteLockSettingPage->ExecuteLD( CAknSettingPage::EUpdateWhenChanged );
       
  1170 
       
  1171     // Setting page list box items (texts) no longer needed
       
  1172     CleanupStack::PopAndDestroy( items );
       
  1173 
       
  1174     if ( ret )
       
  1175         {
       
  1176         if ( currentItem == KRemoteLockSettingItemOn )
       
  1177             {
       
  1178             #ifdef _DEBUG
       
  1179             RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Remote lock status set to ON" ) );
       
  1180             #endif // _DEBUG
       
  1181 
       
  1182             aRemoteLockStatus = ETrue;
       
  1183 
       
  1184             // If user wishes to enable remote lock
       
  1185             // a new remote lock code is required.
       
  1186             // RemoteLockCodeQueryL also 
       
  1187             retValue = RemoteLockCodeQueryL( aRemoteLockCode );
       
  1188             }
       
  1189         else if ( currentItem == KRemoteLockSettingItemOff )
       
  1190             {
       
  1191             #ifdef _DEBUG
       
  1192             RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Remote lock status set to OFF" ) );
       
  1193             #endif // _DEBUG
       
  1194 
       
  1195             aRemoteLockStatus = EFalse;
       
  1196             retValue          = KErrNone;
       
  1197 
       
  1198             // Check whether the status was already off
       
  1199             // If not don't make the user enter the security code
       
  1200             // (which occurs when setting the DOS lock setting) for no reason.
       
  1201             if ( currentItem != previousItem )
       
  1202                 {
       
  1203                 // Check whether AutoLock is enabled (timeout value greater 
       
  1204                 // than zero) or not. If AutoLock is enabled the domestic OS 
       
  1205                 // device lock should be left enabled.
       
  1206                 if ( aAutoLockPeriod == 0 )
       
  1207                     {
       
  1208                     // Disable lock setting from domestic OS
       
  1209                     retValue = RemoteLockSetLockSettingL( EFalse );
       
  1210                     }
       
  1211                 else
       
  1212                     {
       
  1213                     // If AutoLock is enabled, don't disable the DOS device lock
       
  1214                     // Re-set (enable) the domestic OS device lock because as a 
       
  1215                     // side effect it requires the security code from the user
       
  1216                     retValue = RemoteLockSetLockSettingL( ETrue );
       
  1217                     }
       
  1218                 }
       
  1219             }
       
  1220         else
       
  1221             {
       
  1222             // This should never happen. But if it does don't change anything
       
  1223             retValue = KErrUnknown;
       
  1224             }
       
  1225         }
       
  1226     else
       
  1227         {
       
  1228         // Something went wrong with the RemoteLockSettingPage dialog 
       
  1229         retValue = KErrGeneral;
       
  1230 
       
  1231         #ifdef _DEBUG
       
  1232         RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - CRemoteLockSettingPage::ExecuteLD() failed" ) );
       
  1233         #endif // _DEBUG
       
  1234         }
       
  1235 
       
  1236     #ifdef _DEBUG
       
  1237     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Exit" ) );
       
  1238     #endif
       
  1239 
       
  1240     return retValue;
       
  1241     #else //! RD_REMOTELOCK
       
  1242     return KErrNotSupported;
       
  1243     #endif //RD_REMOTELOCK
       
  1244     }
       
  1245 //
       
  1246 // ----------------------------------------------------------
       
  1247 // CSecuritySettings::RemoteLockCodeQueryL()
       
  1248 // Pops up remote lock code query. Requires user to enter a new remote lock 
       
  1249 // code twice and if they match enables the domestic OS device lock (which as 
       
  1250 // a side effect pops up security code query).
       
  1251 // ----------------------------------------------------------
       
  1252 //
       
  1253 TInt CSecuritySettings::RemoteLockCodeQueryL( TDes& aRemoteLockCode )
       
  1254     {
       
  1255     #ifdef RD_REMOTELOCK
       
  1256     TInt retValue( KErrNone );
       
  1257 
       
  1258     #ifdef _DEBUG
       
  1259     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Enter" ) );
       
  1260     #endif // _DEBUG
       
  1261 
       
  1262     // Clear the remote lock code buffer
       
  1263     aRemoteLockCode.Zero();
       
  1264 
       
  1265     // ----- Remote lock code query -------------------------------------------
       
  1266 
       
  1267     // Execute Remote Lock code query
       
  1268     #ifdef _DEBUG
       
  1269     RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Executing remote lock code query" ) );
       
  1270     #endif // _DEBUG
       
  1271 
       
  1272     // Load the query prompt from resources
       
  1273     CCodeQueryDialog* codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1274     TInt buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
       
  1275     if ( buttonId == EEikBidOk )
       
  1276         {
       
  1277             // Ok was pressed and the remote lock code seems fine
       
  1278             retValue = KErrNone;
       
  1279         }
       
  1280     else
       
  1281         {
       
  1282         // User pressed Cancel
       
  1283         // Set the code length to zero leaving no trash for possible retry
       
  1284         aRemoteLockCode.Zero();
       
  1285         retValue = KErrAbort;
       
  1286         }
       
  1287 
       
  1288     if ( retValue != KErrNone )
       
  1289         {
       
  1290         #ifdef _DEBUG
       
  1291         RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Exit, Remote lock code error" ) );
       
  1292         #endif // _DEBUG
       
  1293 
       
  1294         // Can't continue beyond this 
       
  1295         return retValue;
       
  1296         }
       
  1297 
       
  1298     // ----- Remote lock code confirm query -----------------------------------
       
  1299 
       
  1300     // Confirm the code by asking it again
       
  1301     #ifdef _DEBUG
       
  1302     RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Executing remote lock code verify query" ) );
       
  1303     #endif // _DEBUG
       
  1304 
       
  1305     // Buffer for the confirmation code
       
  1306     TBuf<KRLockMaxLockCodeLength> confirmCode;
       
  1307 
       
  1308     // Load the confirmation query prompt from resources
       
  1309     CCodeQueryDialog* codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1310     buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
  1311 
       
  1312 
       
  1313    if ( buttonId == EEikBidOk )
       
  1314         {
       
  1315         // Compare codes. Compare returns zero if descriptors have
       
  1316         // the same length and the same content
       
  1317         while ( (aRemoteLockCode.CompareF( confirmCode ) != 0) && (buttonId == EEikBidOk))
       
  1318             {
       
  1319                 //Codes didn't match; zero the bufffers and show the dialog again
       
  1320                 aRemoteLockCode.Zero();
       
  1321                 confirmCode.Zero();
       
  1322                 // Codes don't match. Notify user
       
  1323                 ShowResultNoteL( R_REMOTELOCK_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone );
       
  1324                 codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1325                 buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
       
  1326                 //Unless user pressed Cancel show the verification query
       
  1327                 if(buttonId == EEikBidOk)
       
  1328                     {
       
  1329                         codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1330                         buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
  1331                     }
       
  1332                 
       
  1333             } 
       
  1334         //User pressed cancel        
       
  1335         if(buttonId != EEikBidOk)
       
  1336             {
       
  1337               // Set the code length to zero leaving no trash for possible retry
       
  1338               // Report error and let the user try again 
       
  1339               aRemoteLockCode.Zero();
       
  1340               confirmCode.Zero();
       
  1341               retValue = KErrAbort; 
       
  1342             }
       
  1343         else
       
  1344             {
       
  1345             // Codes match
       
  1346             confirmCode.Zero();
       
  1347 
       
  1348             // ----- Check against security code ------------------------------
       
  1349             
       
  1350             // Check that the new remote lock code doesn't match the security 
       
  1351             // code of the device.
       
  1352 
       
  1353             RMobilePhone::TMobilePhoneSecurityCode secCodeType;
       
  1354             secCodeType = RMobilePhone::ESecurityCodePhonePassword;
       
  1355             RMobilePhone::TMobilePassword securityCode;
       
  1356             RMobilePhone::TMobilePassword unblockCode;  // Required here only as a dummy parameter 
       
  1357 
       
  1358             if ( aRemoteLockCode.Length() <= RMobilePhone::KMaxMobilePasswordSize )
       
  1359                 {
       
  1360                 securityCode = aRemoteLockCode;
       
  1361                 iWait->SetRequestType( EMobilePhoneVerifySecurityCode );
       
  1362                 iPhone.VerifySecurityCode( iWait->iStatus, secCodeType, securityCode, unblockCode );
       
  1363                 TInt res = iWait->WaitForRequestL();
       
  1364                 // The remote lock code matches the security code 
       
  1365                 // and that is not allowed
       
  1366                 while ( (res == KErrNone) && (buttonId == EEikBidOk))
       
  1367                     {
       
  1368                     #ifdef _DEBUG
       
  1369                     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Unacceptable remote lock code" ) );
       
  1370                     #endif // _DEBUG
       
  1371                     aRemoteLockCode.Zero();
       
  1372                     confirmCode.Zero();
       
  1373                     
       
  1374 					ShowResultNoteL( R_REMOTELOCK_INVALID_CODE, CAknNoteDialog::EErrorTone );
       
  1375 					
       
  1376 					codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1377                     buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
       
  1378                     //Unless user pressed Cancel show the verification query
       
  1379                     if(buttonId == EEikBidOk)
       
  1380                         {
       
  1381                             codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1382                             buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
  1383                             
       
  1384                             // Compare codes. Compare returns zero if descriptors have
       
  1385                             // the same length and the same content
       
  1386                             while ( (aRemoteLockCode.CompareF( confirmCode ) != 0) && (buttonId == EEikBidOk))
       
  1387                                 {
       
  1388                                     //Codes didn't match; zero the bufffers and show the dialog again
       
  1389                                     aRemoteLockCode.Zero();
       
  1390                                     confirmCode.Zero();
       
  1391                                     // Codes don't match. Notify user
       
  1392                                     ShowResultNoteL( R_REMOTELOCK_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone );
       
  1393                                     codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1394                                     buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
       
  1395                                     //Unless user pressed Cancel show the verification query
       
  1396                                     if(buttonId == EEikBidOk)
       
  1397                                         {
       
  1398                                             codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
  1399                                             buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
  1400                                         }
       
  1401                 
       
  1402                                 } 
       
  1403                             //User pressed cancel        
       
  1404                             if(buttonId != EEikBidOk)
       
  1405                                 {
       
  1406                                   // Set the code length to zero leaving no trash for possible retry
       
  1407                                   // Report error and let the user try again 
       
  1408                                   aRemoteLockCode.Zero();
       
  1409                                   confirmCode.Zero();
       
  1410                                   retValue = KErrAbort; 
       
  1411                                 }
       
  1412                             else //Check against security code
       
  1413                                 {
       
  1414                                     securityCode = aRemoteLockCode;
       
  1415                                     iWait->SetRequestType( EMobilePhoneVerifySecurityCode );
       
  1416                                     iPhone.VerifySecurityCode( iWait->iStatus, secCodeType, securityCode, unblockCode );
       
  1417                                     res = iWait->WaitForRequestL();
       
  1418                                 }
       
  1419                         }
       
  1420 					
       
  1421                     }
       
  1422                //User pressed cancel        
       
  1423                if(buttonId != EEikBidOk)
       
  1424                     {
       
  1425                       // Set the code length to zero leaving no trash for possible retry
       
  1426                       // Report error and let the user try again 
       
  1427                       aRemoteLockCode.Zero();
       
  1428                       confirmCode.Zero();
       
  1429                       retValue = KErrAbort; 
       
  1430                     }
       
  1431                 }
       
  1432 
       
  1433             // ----- Enable DOS device lock (Security code query) -------------
       
  1434 
       
  1435             if ( retValue == KErrNone )
       
  1436                 {
       
  1437                 // Enable lock setting in domestic OS. It is safe to enable the 
       
  1438                 // lock setting since RemoteLock API requires remote locking to
       
  1439                 // be enabled when changing or setting the remote lock message.
       
  1440                 retValue = RemoteLockSetLockSettingL( ETrue );
       
  1441                 }
       
  1442             }
       
  1443         }
       
  1444     else //User pressed Cancel
       
  1445         {
       
  1446         // Set the code length to zero leaving no trash for possible retry
       
  1447         aRemoteLockCode.Zero();
       
  1448         confirmCode.Zero();
       
  1449         retValue = KErrAbort;
       
  1450         }
       
  1451 
       
  1452     #ifdef _DEBUG
       
  1453     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Exit" ) );
       
  1454     #endif // _DEBUG
       
  1455 
       
  1456     return retValue;
       
  1457     #else //! RD_REMOTELOCK
       
  1458     return KErrNotSupported;
       
  1459     #endif //RD_REMOTELOCK
       
  1460     }
       
  1461 //
       
  1462 // ----------------------------------------------------------
       
  1463 // CSecuritySettings::RemoteLockSetLockSettingL()
       
  1464 // Changes lock setting in domestic OS. Changing the domestic OS lock setting
       
  1465 // requires user to enter the security code.
       
  1466 // ----------------------------------------------------------
       
  1467 //
       
  1468 TInt CSecuritySettings::RemoteLockSetLockSettingL( TBool aLockSetting )
       
  1469     {
       
  1470     #ifdef RD_REMOTELOCK
       
  1471     TInt retValue( KErrNone );
       
  1472 
       
  1473     #ifdef _DEBUG
       
  1474     RDebug::Print(_L("(SecUi)CSecuritySettings::RemoteLockSetLockSettingL( %d ) - Enter" ), aLockSetting );
       
  1475     #endif // _DEBUG
       
  1476 
       
  1477     RMobilePhone::TMobilePhoneLockSetting lockSetting = RMobilePhone::ELockSetEnabled;
       
  1478     RMobilePhone::TMobilePhoneLock        lockType    = RMobilePhone::ELockPhoneDevice;
       
  1479 
       
  1480     if ( aLockSetting )
       
  1481         {
       
  1482         lockSetting = RMobilePhone::ELockSetEnabled;
       
  1483         }
       
  1484     else
       
  1485         {
       
  1486         lockSetting = RMobilePhone::ELockSetDisabled;
       
  1487         }
       
  1488 
       
  1489     iWait->SetRequestType( EMobilePhoneSetLockSetting );
       
  1490     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
       
  1491     iPhone.SetLockSetting( iWait->iStatus, lockType, lockSetting );
       
  1492 
       
  1493     // Wait for code verify to complete
       
  1494     retValue = iWait->WaitForRequestL();
       
  1495 
       
  1496     switch( retValue )
       
  1497         {
       
  1498         case KErrNone:
       
  1499             #ifdef _DEBUG
       
  1500             RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrNone" ) );
       
  1501             #endif // _DEBUG
       
  1502             break;
       
  1503 
       
  1504         case KErrGsmSSPasswordAttemptsViolation:
       
  1505         case KErrLocked:
       
  1506             #ifdef _DEBUG
       
  1507             RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrLocked" ) );
       
  1508             #endif // _DEBUG
       
  1509             //Error note is shown in CSecurityHandler::PassPhraseRequired()
       
  1510             break;
       
  1511 
       
  1512         case KErrGsm0707IncorrectPassword:
       
  1513         case KErrAccessDenied:
       
  1514             #ifdef _DEBUG
       
  1515             RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrAccessDenied" ) );
       
  1516             #endif // _DEBUG
       
  1517             // Security code was entered erroneously
       
  1518             //Error note is shown in CSecurityHandler::PassPhraseRequired()
       
  1519             break;
       
  1520 
       
  1521         case KErrAbort:
       
  1522             #ifdef _DEBUG
       
  1523             RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrAbort" ) );
       
  1524             #endif // _DEBUG
       
  1525             break;
       
  1526 
       
  1527         default:
       
  1528             #ifdef _DEBUG
       
  1529             RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned: %d"), retValue );
       
  1530             #endif // _DEBUG
       
  1531             break;
       
  1532         }
       
  1533 
       
  1534     #ifdef _DEBUG
       
  1535     RDebug::Print(_L("(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - Exit" ) );
       
  1536     #endif // _DEBUG
       
  1537 
       
  1538     return retValue;
       
  1539     #else //! RD_REMOTELOCK
       
  1540     return KErrNotSupported;
       
  1541     #endif //RD_REMOTELOCK
       
  1542     }
       
  1543 
       
  1544 
       
  1545 
       
  1546 //
       
  1547 // ----------------------------------------------------------
       
  1548 // CSecuritySettings::ChangeSimSecurityL()
       
  1549 // Changes SIM security
       
  1550 // ----------------------------------------------------------
       
  1551 //
       
  1552 EXPORT_C TBool CSecuritySettings::ChangeSimSecurityL()
       
  1553     {    
       
  1554     /*****************************************************
       
  1555     *    Series 60 Customer / ETel
       
  1556     *    Series 60  ETel API
       
  1557     *****************************************************/
       
  1558     #if defined(_DEBUG)
       
  1559     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeSimSecurityL()"));
       
  1560     #endif
       
  1561 
       
  1562     RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
  1563     RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
  1564     RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneToICC;
       
  1565     RMobilePhone::TMobilePhoneLockSetting lockChangeSetting;
       
  1566     CCoeEnv* coeEnv = CCoeEnv::Static();
       
  1567     CDesCArrayFlat* items = coeEnv->ReadDesC16ArrayResourceL(R_SECURITY_LBX);
       
  1568     CleanupStack::PushL(items);
       
  1569                         
       
  1570     //get lock info
       
  1571     iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
  1572     iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
  1573     TInt status = iWait->WaitForRequestL();
       
  1574     User::LeaveIfError(status);
       
  1575     TInt currentItem = 0;
       
  1576 
       
  1577     if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
       
  1578         {
       
  1579         #if defined(_DEBUG)
       
  1580         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeSimSecurityL()lockInfo: ELockSetDisabled"));
       
  1581         #endif
       
  1582         currentItem = 1;  // off
       
  1583         }
       
  1584                         
       
  1585     TInt oldItem = currentItem;
       
  1586 
       
  1587     CAknRadioButtonSettingPage* dlg = new (ELeave)CAknRadioButtonSettingPage(R_SECURITY_SETTING_PAGE, currentItem, items);
       
  1588     CleanupStack::PushL(dlg);
       
  1589     
       
  1590 
       
  1591     CleanupStack::Pop(); // dlg
       
  1592     if ( !(dlg->ExecuteLD(CAknSettingPage::EUpdateWhenChanged)) || oldItem==currentItem )
       
  1593         {
       
  1594         CleanupStack::PopAndDestroy();    // items
       
  1595         return EFalse;
       
  1596         }    
       
  1597 
       
  1598 
       
  1599 
       
  1600     if (currentItem == 1)
       
  1601         {
       
  1602         lockChangeSetting = RMobilePhone::ELockSetDisabled;
       
  1603         }
       
  1604     else
       
  1605         {
       
  1606         lockChangeSetting = RMobilePhone::ELockSetEnabled;
       
  1607         }
       
  1608 
       
  1609     CleanupStack::PopAndDestroy();    // items 
       
  1610     
       
  1611     iWait->SetRequestType(EMobilePhoneSetLockSetting);
       
  1612     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
       
  1613     iPhone.SetLockSetting(iWait->iStatus,lockType,lockChangeSetting);
       
  1614     status = iWait->WaitForRequestL();
       
  1615 
       
  1616     #if defined(_DEBUG)
       
  1617     RDebug::Print( _L("(SECUI)CSecuritySettings::ChangeSimSecurityL(): RETURN CODE: %d"), status);
       
  1618     #endif        
       
  1619     switch(status)
       
  1620         {
       
  1621         case KErrNone:
       
  1622             {
       
  1623             break;
       
  1624             }        
       
  1625         case KErrGsm0707IncorrectPassword:
       
  1626         case KErrAccessDenied:
       
  1627             {    
       
  1628             // code was entered erroneously
       
  1629             return ChangeSimSecurityL();
       
  1630             }    
       
  1631         case KErrGsmSSPasswordAttemptsViolation:
       
  1632         case KErrLocked:
       
  1633             {
       
  1634             return ChangeSimSecurityL();
       
  1635             }
       
  1636         case KErrAbort:
       
  1637             {
       
  1638             return EFalse;
       
  1639             }
       
  1640         default:
       
  1641             {
       
  1642             ShowErrorNoteL(status);
       
  1643             return ChangeSimSecurityL();
       
  1644             }
       
  1645         }
       
  1646     
       
  1647     return ETrue;
       
  1648     }
       
  1649 //
       
  1650 // ----------------------------------------------------------
       
  1651 // CSecuritySettings::ChangePinRequestL()
       
  1652 // Changes PIN1 request
       
  1653 // ----------------------------------------------------------
       
  1654 //
       
  1655 EXPORT_C TBool CSecuritySettings::ChangePinRequestL()
       
  1656     {    
       
  1657     /*****************************************************
       
  1658     *    Series 60 Customer / ETel
       
  1659     *    Series 60  ETel API
       
  1660     *****************************************************/
       
  1661     #if defined(_DEBUG)
       
  1662     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL()"));
       
  1663     #endif      
       
  1664     TInt simState;
       
  1665     TInt err( KErrGeneral );
       
  1666     err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);
       
  1667     User::LeaveIfError( err );
       
  1668     TBool simRemoved(simState == ESimNotPresent);
       
  1669 
       
  1670     if ( simRemoved )
       
  1671         {
       
  1672         ShowResultNoteL(R_INSERT_SIM, CAknNoteDialog::EErrorTone);
       
  1673         return EFalse;;
       
  1674         }
       
  1675 
       
  1676     RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
  1677     RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
  1678     RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockICC;
       
  1679 
       
  1680     RMobilePhone::TMobilePhoneLockSetting lockChangeSetting;
       
  1681     
       
  1682     CCoeEnv* coeEnv = CCoeEnv::Static();
       
  1683     CDesCArrayFlat* items = coeEnv->ReadDesC16ArrayResourceL(R_PIN_LBX);
       
  1684     CleanupStack::PushL(items);
       
  1685                         
       
  1686     //get lock info
       
  1687     iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
  1688     iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
  1689     TInt status = iWait->WaitForRequestL();
       
  1690     User::LeaveIfError(status);                    
       
  1691     TInt currentItem = 0;
       
  1692 
       
  1693     #if defined(_DEBUG)
       
  1694     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL() GetLockInfo"));
       
  1695     #endif
       
  1696 
       
  1697     if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
       
  1698         {
       
  1699         #if defined(_DEBUG)
       
  1700         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL() lockInfo: ELockSetDisabled"));
       
  1701         #endif
       
  1702         currentItem = 1;  // off
       
  1703         }
       
  1704                         
       
  1705     TInt oldItem = currentItem;
       
  1706 
       
  1707     CAknRadioButtonSettingPage* dlg = new (ELeave)CAknRadioButtonSettingPage(R_PIN_SETTING_PAGE, currentItem, items);
       
  1708     CleanupStack::PushL(dlg);
       
  1709     
       
  1710 
       
  1711     CleanupStack::Pop(); // dlg
       
  1712     if ( !(dlg->ExecuteLD(CAknSettingPage::EUpdateWhenChanged)) || oldItem==currentItem )
       
  1713         {
       
  1714         CleanupStack::PopAndDestroy();    // items
       
  1715         return EFalse;
       
  1716         }    
       
  1717 
       
  1718 
       
  1719     if (currentItem == 1)
       
  1720         {
       
  1721         #if defined(_DEBUG)
       
  1722         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL() currentItem: ELockSetDisabled"));
       
  1723         #endif
       
  1724         lockChangeSetting = RMobilePhone::ELockSetDisabled;
       
  1725         }
       
  1726     else
       
  1727         {
       
  1728         #if defined(_DEBUG)
       
  1729         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL() currentItem: ELockSetEnabled"));
       
  1730         #endif
       
  1731         lockChangeSetting = RMobilePhone::ELockSetEnabled;
       
  1732         }
       
  1733 
       
  1734     CleanupStack::PopAndDestroy();    // items 
       
  1735 
       
  1736     // Raise a flag to indicate that the PIN
       
  1737     // request coming from ETEL has originated from SecUi and not from Engine.
       
  1738     TInt tRet = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginated);
       
  1739     if ( tRet != KErrNone )
       
  1740         {
       
  1741         #if defined(_DEBUG)
       
  1742         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL():\
       
  1743             FAILED to set the SECUI query Flag: %d"), tRet);
       
  1744         #endif
       
  1745         }
       
  1746     // Change the lock setting
       
  1747     iWait->SetRequestType(EMobilePhoneSetLockSetting);
       
  1748     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
       
  1749     iPhone.SetLockSetting(iWait->iStatus,lockType,lockChangeSetting);
       
  1750     status = iWait->WaitForRequestL();
       
  1751     #if defined(_DEBUG)
       
  1752     RDebug::Print( _L("(SECUI)CSecuritySettings::ChangePinRequestL(): RETURN CODE: %d"), status);
       
  1753     #endif
       
  1754 
       
  1755     // Lower the flag                             
       
  1756     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsETelAPIOriginated);
       
  1757 
       
  1758     switch(status)
       
  1759         {
       
  1760         case KErrNone:
       
  1761             {
       
  1762             break;
       
  1763             }
       
  1764         case KErrGsm0707OperationNotAllowed:
       
  1765             {
       
  1766             // not allowed with this sim
       
  1767             ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  1768             return EFalse;
       
  1769             }
       
  1770         case KErrGsm0707IncorrectPassword:
       
  1771         case KErrAccessDenied:
       
  1772             {    
       
  1773             // code was entered erroneously
       
  1774             return ChangePinRequestL();
       
  1775             }    
       
  1776         case KErrGsmSSPasswordAttemptsViolation:
       
  1777         case KErrLocked:
       
  1778             {
       
  1779             return ETrue;
       
  1780             }
       
  1781         case KErrAbort:
       
  1782             {
       
  1783             return EFalse;
       
  1784             }
       
  1785         default:
       
  1786             {
       
  1787             return ChangePinRequestL();
       
  1788             }
       
  1789         }
       
  1790     
       
  1791     return ETrue;
       
  1792     }
       
  1793 
       
  1794 //
       
  1795 // ----------------------------------------------------------
       
  1796 // CSecuritySettings::ChangeUPinRequestL()
       
  1797 // Changes UPIN request on/off
       
  1798 // ----------------------------------------------------------
       
  1799 //
       
  1800 EXPORT_C TBool CSecuritySettings::ChangeUPinRequestL()
       
  1801     {
       
  1802     TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
       
  1803     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
       
  1804     if(wcdmaSupported || upinSupported)
       
  1805       {
       
  1806         #if defined(_DEBUG)
       
  1807         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeUPinRequestL()"));
       
  1808         #endif
       
  1809         
       
  1810         TInt simState;
       
  1811         TInt err( KErrGeneral );
       
  1812         err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);
       
  1813         User::LeaveIfError( err );
       
  1814         TBool simRemoved(simState == ESimNotPresent);
       
  1815     
       
  1816         if ( simRemoved )
       
  1817             {
       
  1818             ShowResultNoteL(R_INSERT_SIM, CAknNoteDialog::EErrorTone);
       
  1819             return EFalse;
       
  1820             }
       
  1821     
       
  1822         RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
  1823         RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
  1824         RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockUniversalPin;
       
  1825     
       
  1826         RMobilePhone::TMobilePhoneLockSetting lockChangeSetting = RMobilePhone::ELockSetDisabled;
       
  1827         
       
  1828         CCoeEnv* coeEnv = CCoeEnv::Static();
       
  1829         CDesCArrayFlat* items = coeEnv->ReadDesC16ArrayResourceL(R_UPIN_LBX);
       
  1830         CleanupStack::PushL(items);
       
  1831                             
       
  1832         //get lock info
       
  1833         iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
  1834         iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
  1835         TInt status = iWait->WaitForRequestL();
       
  1836         User::LeaveIfError(status);                    
       
  1837         TInt currentItem = 0;
       
  1838     
       
  1839         #if defined(_DEBUG)
       
  1840         RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeUPinRequestL() GetLockInfo"));
       
  1841         #endif
       
  1842     
       
  1843         if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
       
  1844             {
       
  1845             #if defined(_DEBUG)
       
  1846             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeUPinRequestL() lockInfo: ELockSetDisabled"));
       
  1847             #endif
       
  1848             currentItem = 1;  // off
       
  1849             }
       
  1850                             
       
  1851         TInt oldItem = currentItem;
       
  1852     
       
  1853         CAknRadioButtonSettingPage* dlg = new (ELeave)CAknRadioButtonSettingPage(R_UPIN_SETTING_PAGE, currentItem, items);
       
  1854         CleanupStack::PushL(dlg);
       
  1855         
       
  1856     
       
  1857         CleanupStack::Pop(); // dlg
       
  1858         if ( !(dlg->ExecuteLD(CAknSettingPage::EUpdateWhenChanged)) || oldItem==currentItem )
       
  1859             {
       
  1860             CleanupStack::PopAndDestroy();    // items
       
  1861             return EFalse;
       
  1862             }    
       
  1863     
       
  1864     
       
  1865        if (currentItem == 1)
       
  1866             {
       
  1867             #if defined(_DEBUG)
       
  1868             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL() currentItem: ELockSetDisabled"));
       
  1869             #endif
       
  1870             lockChangeSetting = RMobilePhone::ELockSetDisabled;
       
  1871             }
       
  1872         else
       
  1873             {
       
  1874             #if defined(_DEBUG)
       
  1875             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestL() currentItem: ELockSetEnabled"));
       
  1876             #endif
       
  1877             lockChangeSetting = RMobilePhone::ELockSetEnabled;
       
  1878             }
       
  1879     
       
  1880         CleanupStack::PopAndDestroy();    // items 
       
  1881     
       
  1882         // Raise a flag to indicate that the UPIN
       
  1883         // request coming from ETEL has originated from SecUi and not from Engine.
       
  1884         RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginated);                              
       
  1885         // Change the lock setting
       
  1886         iWait->SetRequestType(EMobilePhoneSetLockSetting);
       
  1887         RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
       
  1888         iPhone.SetLockSetting(iWait->iStatus,lockType,lockChangeSetting);
       
  1889         status = iWait->WaitForRequestL();
       
  1890         #if defined(_DEBUG)
       
  1891         RDebug::Print( _L("(SECUI)CSecuritySettings::ChangeUPinRequestL(): RETURN CODE: %d"), status);
       
  1892         #endif
       
  1893     
       
  1894         // Lower the flag                           
       
  1895         RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsETelAPIOriginated);
       
  1896         
       
  1897         switch(status)
       
  1898             {
       
  1899             case KErrNone:
       
  1900                 {
       
  1901                 break;
       
  1902                 }
       
  1903             case KErrGsm0707OperationNotAllowed:
       
  1904                 {
       
  1905                 // not allowed with this sim
       
  1906                 ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  1907                 return EFalse;
       
  1908                 }
       
  1909             case KErrGsm0707IncorrectPassword:
       
  1910             case KErrAccessDenied:
       
  1911                 {    
       
  1912                 // code was entered erroneously
       
  1913                 return ChangeUPinRequestL();
       
  1914                 }    
       
  1915             case KErrGsmSSPasswordAttemptsViolation:
       
  1916             case KErrLocked:
       
  1917                 {
       
  1918                 return EFalse;
       
  1919                 }
       
  1920             case KErrAbort:
       
  1921                 {
       
  1922                 return EFalse;
       
  1923                 }
       
  1924             default:
       
  1925                 {
       
  1926                 ShowErrorNoteL(status);
       
  1927                 return ChangeUPinRequestL();
       
  1928                 }
       
  1929             }
       
  1930         
       
  1931         return ETrue;
       
  1932       }
       
  1933     else
       
  1934         return EFalse;
       
  1935 
       
  1936     }
       
  1937 
       
  1938 //
       
  1939 // ----------------------------------------------------------
       
  1940 // CSecuritySettings::SwitchPinCodesL()
       
  1941 // Changes the pin code currently in use (PIN/UPIN)
       
  1942 // ----------------------------------------------------------
       
  1943 //
       
  1944 EXPORT_C TBool CSecuritySettings::SwitchPinCodesL()
       
  1945     { 
       
  1946     TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
       
  1947     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
       
  1948     if(wcdmaSupported || upinSupported)
       
  1949       {
       
  1950         #if defined(_DEBUG)
       
  1951         RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL()"));
       
  1952         #endif 
       
  1953     
       
  1954         // If we are in simless offline mode the PIN codes can't obviously be switched
       
  1955         TInt simState;
       
  1956         TInt err( KErrGeneral );
       
  1957         err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);    
       
  1958         User::LeaveIfError( err );
       
  1959         TBool simRemoved(simState == ESimNotPresent);
       
  1960     
       
  1961         if ( simRemoved )
       
  1962             {
       
  1963             ShowResultNoteL(R_INSERT_SIM, CAknNoteDialog::EErrorTone);
       
  1964             return EFalse;
       
  1965             }
       
  1966     
       
  1967        
       
  1968         RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockUniversalPin;
       
  1969         RMobilePhone::TMobilePhoneLockSetting lockChangeSetting = RMobilePhone::ELockReplaced;                       
       
  1970         RMobilePhone::TMobilePhoneSecurityCode activeCode;
       
  1971      
       
  1972         iCustomPhone.GetActivePin(activeCode);
       
  1973     
       
  1974         RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;    
       
  1975         RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
  1976         #if defined(_DEBUG)
       
  1977         RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() GetLockInfo"));
       
  1978         #endif    
       
  1979         iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
  1980     
       
  1981         if (activeCode == RMobilePhone::ESecurityUniversalPin)
       
  1982             {
       
  1983              lockType = RMobilePhone::ELockUniversalPin;
       
  1984              iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
  1985              TInt res = iWait->WaitForRequestL();
       
  1986              User::LeaveIfError(res);
       
  1987             #if defined(_DEBUG)
       
  1988             RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() Lock Info got: UPIN"));
       
  1989             #endif 
       
  1990             }
       
  1991         else
       
  1992             {
       
  1993              lockType = RMobilePhone::ELockICC;
       
  1994              iPhone.GetLockInfo(iWait->iStatus, lockType, lockInfoPkg);
       
  1995              TInt res = iWait->WaitForRequestL();
       
  1996              User::LeaveIfError(res);
       
  1997             #if defined(_DEBUG)
       
  1998             RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() Lock Info got: PIN"));
       
  1999             #endif 
       
  2000             }
       
  2001     
       
  2002         // code request must be ON to change active code.
       
  2003         if (lockInfo.iSetting == RMobilePhone::ELockSetDisabled)
       
  2004            {
       
  2005             #if defined(_DEBUG)
       
  2006             RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() CODE REQ NOT ON."));
       
  2007             #endif
       
  2008             if (activeCode == RMobilePhone::ESecurityUniversalPin)
       
  2009                 {
       
  2010                 ShowResultNoteL(R_UPIN_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  2011                 }
       
  2012             else
       
  2013                 {
       
  2014                 ShowResultNoteL(R_PIN_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  2015                 }
       
  2016             #if defined(_DEBUG)
       
  2017             RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() CODE REQ NOT ON NOTE END."));
       
  2018             #endif 
       
  2019             return EFalse;
       
  2020             }
       
  2021     
       
  2022         
       
  2023         
       
  2024         CCoeEnv* coeEnv = CCoeEnv::Static();
       
  2025         CDesCArrayFlat* items = coeEnv->ReadDesC16ArrayResourceL(R_CODE_LBX);
       
  2026         CleanupStack::PushL(items);
       
  2027     
       
  2028         iCustomPhone.GetActivePin(activeCode);
       
  2029         TInt currentItem = 0;
       
  2030     
       
  2031         #if defined(_DEBUG)
       
  2032         RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() GetLockInfo"));
       
  2033         #endif
       
  2034     
       
  2035         if (activeCode == RMobilePhone::ESecurityUniversalPin)
       
  2036             {
       
  2037             #if defined(_DEBUG)
       
  2038             RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() active code: UPIN"));
       
  2039             #endif
       
  2040             currentItem = 1;  // UPIN
       
  2041             }
       
  2042                             
       
  2043         TInt oldItem = currentItem;
       
  2044     
       
  2045         CAknRadioButtonSettingPage* dlg = new (ELeave)CAknRadioButtonSettingPage(R_CODE_IN_USE_SETTING_PAGE, currentItem, items);
       
  2046         CleanupStack::PushL(dlg);
       
  2047         
       
  2048     
       
  2049         CleanupStack::Pop(); // dlg
       
  2050         if ( !(dlg->ExecuteLD(CAknSettingPage::EUpdateWhenChanged)) || oldItem==currentItem )
       
  2051             {
       
  2052             CleanupStack::PopAndDestroy();    // items
       
  2053             return EFalse;
       
  2054             }    
       
  2055     
       
  2056     
       
  2057        if (currentItem == 1)
       
  2058             {
       
  2059             #if defined(_DEBUG)
       
  2060             RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() currentItem: UPIN"));
       
  2061             #endif
       
  2062             lockType = RMobilePhone::ELockUniversalPin;
       
  2063             }
       
  2064         else
       
  2065             {
       
  2066             #if defined(_DEBUG)
       
  2067             RDebug::Print(_L("(SECUI)CSecuritySettings::SwitchPinCodesL() currentItem: PIN1"));
       
  2068             #endif
       
  2069             lockType = RMobilePhone::ELockICC;
       
  2070             }
       
  2071     
       
  2072         CleanupStack::PopAndDestroy();    // items 
       
  2073     
       
  2074         // Raise a flag to indicate that the code
       
  2075         // request coming from ETEL has originated from SecUi and not from Engine.
       
  2076         RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsSecUIOriginated);                           
       
  2077         // Change the lock setting
       
  2078         iWait->SetRequestType(EMobilePhoneSetLockSetting);
       
  2079         RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
       
  2080         iPhone.SetLockSetting(iWait->iStatus,lockType,lockChangeSetting);
       
  2081         TInt status = iWait->WaitForRequestL();
       
  2082         #if defined(_DEBUG)
       
  2083         RDebug::Print( _L("(SECUI)CSecuritySettings::SwitchPinCodesL(): RETURN CODE: %d"), status);
       
  2084         #endif
       
  2085         // Lower the flag                            
       
  2086         RProperty::Set(KPSUidSecurityUIs, KSecurityUIsSecUIOriginatedQuery, ESecurityUIsETelAPIOriginated);
       
  2087         
       
  2088         switch(status)
       
  2089             {
       
  2090             case KErrNone:
       
  2091                 {
       
  2092                 break;
       
  2093                 }
       
  2094             case KErrGsm0707OperationNotAllowed:
       
  2095                 {
       
  2096                 // not allowed with this sim
       
  2097                 ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  2098                 return EFalse;
       
  2099                 }
       
  2100             case KErrGsm0707IncorrectPassword:
       
  2101             case KErrAccessDenied:
       
  2102                 {    
       
  2103                 // code was entered erroneously
       
  2104                 return SwitchPinCodesL();
       
  2105                 }    
       
  2106             case KErrGsmSSPasswordAttemptsViolation:
       
  2107             case KErrLocked:
       
  2108                 {
       
  2109                 return EFalse;
       
  2110                 }
       
  2111             case KErrAbort:
       
  2112                 {
       
  2113                 return EFalse;
       
  2114                 }
       
  2115             default:
       
  2116                 {
       
  2117                 ShowErrorNoteL(status);
       
  2118                 return SwitchPinCodesL();
       
  2119                 }
       
  2120             }
       
  2121         
       
  2122         return ETrue;
       
  2123       }
       
  2124     else
       
  2125         return EFalse;
       
  2126     }
       
  2127 
       
  2128 //
       
  2129 // ----------------------------------------------------------
       
  2130 // CSecuritySettings::IsLockEnabledL()
       
  2131 // Return is lock enabled/disabled
       
  2132 // ----------------------------------------------------------
       
  2133 //
       
  2134 EXPORT_C TBool CSecuritySettings::IsLockEnabledL(RMobilePhone::TMobilePhoneLock aLockType)
       
  2135     {
       
  2136     /*****************************************************
       
  2137     *    Series 60 Customer / ETel
       
  2138     *    Series 60  ETel API
       
  2139     *****************************************************/
       
  2140     #if defined(_DEBUG)
       
  2141     RDebug::Print(_L("(SECUI)CSecuritySettings::IsLockEnabledL()"));
       
  2142     #endif
       
  2143     #ifdef __WINS__
       
  2144 
       
  2145     return EFalse;
       
  2146 
       
  2147     #else  //WINS
       
  2148 
       
  2149     RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
  2150     
       
  2151     //get lock info
       
  2152     RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
  2153     iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
  2154     iPhone.GetLockInfo(iWait->iStatus, aLockType, lockInfoPkg);
       
  2155     TInt res = iWait->WaitForRequestL();
       
  2156 
       
  2157     if (res != KErrNone)
       
  2158         return ETrue;
       
  2159 
       
  2160      //lock is enabled return true
       
  2161     if (lockInfo.iSetting == RMobilePhone::ELockSetEnabled)
       
  2162         {
       
  2163         return ETrue;                        
       
  2164         }
       
  2165 
       
  2166     // lock is disabled return false
       
  2167     return EFalse;
       
  2168         
       
  2169     #endif 
       
  2170 
       
  2171     }
       
  2172 //
       
  2173 // ----------------------------------------------------------
       
  2174 // CSecuritySettings::AskSecCodeL()
       
  2175 // For asking security code e.g in settings
       
  2176 // ----------------------------------------------------------
       
  2177 //
       
  2178 EXPORT_C TBool CSecuritySettings::AskSecCodeL()
       
  2179     {
       
  2180     return iSecurityHandler->AskSecCodeL();
       
  2181     }
       
  2182 //
       
  2183 // ----------------------------------------------------------
       
  2184 // CSecuritySettings::AskPin2L()
       
  2185 // Asks PIN2
       
  2186 // ----------------------------------------------------------
       
  2187 //    
       
  2188 EXPORT_C TBool CSecuritySettings::AskPin2L()
       
  2189     {    
       
  2190     /*****************************************************
       
  2191     *    Series 60 Customer / ETel
       
  2192     *    Series 60  ETel API
       
  2193     *****************************************************/
       
  2194     #if defined(_DEBUG)
       
  2195     RDebug::Print(_L("(SECUI)CSecuritySettings::AskPin2L()"));
       
  2196     #endif
       
  2197     TInt ret = 0;
       
  2198     // check if pin2 is blocked...
       
  2199     RMmCustomAPI::TSecurityCodeType secCodeType = RMmCustomAPI::ESecurityCodePin2;
       
  2200     RMobilePhone::TMobilePhoneSecurityCode etelsecCodeType(RMobilePhone::ESecurityCodePin2);
       
  2201     RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
       
  2202     RMobilePhone::TMobilePhoneSecurityCodeInfoV5Pckg codeInfoPkg(codeInfo);
       
  2203     TBool isBlocked = EFalse;
       
  2204     //Check whether PIN2 is blocked
       
  2205     ret = iCustomPhone.IsBlocked(secCodeType,isBlocked);
       
  2206     
       
  2207 	#if defined(_DEBUG)
       
  2208     RDebug::Print(_L("(SECUI)CSecuritySettings::AskPin2L() IsBlocked return value: %d"), ret);
       
  2209     #endif
       
  2210     if(isBlocked)
       
  2211         return EFalse;
       
  2212     
       
  2213     if (ret != KErrNone)
       
  2214         {    
       
  2215         switch (ret)
       
  2216             {
       
  2217 			// PIN2 Blocked.
       
  2218             case KErrGsm0707SIMPuk2Required:
       
  2219                 break;
       
  2220             case KErrGsmSSPasswordAttemptsViolation:
       
  2221             case KErrLocked:
       
  2222                 // Pin2 features blocked permanently!
       
  2223                 ShowResultNoteL(R_PIN2_REJECTED, CAknNoteDialog::EConfirmationTone);
       
  2224                 break;
       
  2225             case KErrGsm0707SimNotInserted:
       
  2226                 // not allowed with this sim
       
  2227                 ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  2228                 break;
       
  2229             default:
       
  2230                 ShowErrorNoteL(ret);
       
  2231                 break;
       
  2232             }
       
  2233         return EFalse;
       
  2234         }
       
  2235     iWait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
       
  2236     iPhone.GetSecurityCodeInfo(iWait->iStatus, etelsecCodeType, codeInfoPkg);
       
  2237     ret = iWait->WaitForRequestL();
       
  2238         
       
  2239     #if defined(_DEBUG)
       
  2240     RDebug::Print(_L("(SECUI)CSecurityHandler::Pin2RequiredL(): get PIN2 info result: %d"), ret);
       
  2241     TInt attempts(codeInfo.iRemainingEntryAttempts);
       
  2242     RDebug::Print(_L("(SECUI)CSecurityHandler::Pin2RequiredL(): attempts remaining: %d"), attempts);
       
  2243     #endif
       
  2244     User::LeaveIfError(ret);
       
  2245     
       
  2246     // ask pin2 code  
       
  2247     RMobilePhone::TMobilePassword password;
       
  2248     CCodeQueryDialog* dlg = new (ELeave) CCodeQueryDialog (password,SEC_C_PIN_CODE_MIN_LENGTH,SEC_C_PIN_CODE_MAX_LENGTH,ESecUiNone);  
       
  2249     if(codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
       
  2250             ret = dlg->ExecuteLD(R_PIN2_QUERY);
       
  2251     else if(codeInfo.iRemainingEntryAttempts > KLastRemainingInputAttempt)
       
  2252             {
       
  2253                 HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_REMAINING_PIN2_ATTEMPTS, codeInfo.iRemainingEntryAttempts );
       
  2254                 ret = dlg->ExecuteLD(R_PIN2_QUERY, *queryPrompt);
       
  2255                 CleanupStack::PopAndDestroy(queryPrompt);
       
  2256             }
       
  2257     else
       
  2258             {
       
  2259                 HBufC* queryPrompt = StringLoader::LoadLC(R_SECUI_FINAL_PIN2_ATTEMPT);
       
  2260                 ret = dlg->ExecuteLD(R_PIN2_QUERY, *queryPrompt);
       
  2261                 CleanupStack::PopAndDestroy(queryPrompt);   
       
  2262             } 
       
  2263        
       
  2264     if (!ret)
       
  2265         {
       
  2266 		#if defined(_DEBUG)
       
  2267 		RDebug::Print(_L("(SECUI)CSecuritySettings::AskPin2L(): Cancel pressed"));
       
  2268 		#endif
       
  2269         return EFalse;
       
  2270         }
       
  2271     
       
  2272     // verify code
       
  2273     RMobilePhone::TMobilePassword required_fourth;
       
  2274     iWait->SetRequestType(EMobilePhoneVerifySecurityCode);
       
  2275     iPhone.VerifySecurityCode(iWait->iStatus,etelsecCodeType, password, required_fourth);
       
  2276     TInt res = iWait->WaitForRequestL();
       
  2277 
       
  2278 	#if defined(_DEBUG)
       
  2279     RDebug::Print(_L("(SECUI)CSecuritySettings::AskPin2L() VerifySecurityCode return value: %d"), res);
       
  2280     #endif
       
  2281 
       
  2282     switch(res)
       
  2283         {        
       
  2284         case KErrNone:
       
  2285             break;
       
  2286         case KErrGsm0707IncorrectPassword:
       
  2287         case KErrAccessDenied:
       
  2288             // code was entered erroneously
       
  2289             ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone);
       
  2290             return    AskPin2L();    
       
  2291         case KErrGsm0707OperationNotAllowed:
       
  2292             // not allowed with this sim
       
  2293             ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  2294             return EFalse;
       
  2295         case KErrGsmSSPasswordAttemptsViolation:
       
  2296         case KErrLocked:
       
  2297             // code was blocked
       
  2298             ShowResultNoteL(R_CODE_ERROR, CAknNoteDialog::EErrorTone);
       
  2299             return EFalse;        
       
  2300         default:
       
  2301             ShowErrorNoteL(res);
       
  2302             return    AskPin2L();
       
  2303         }
       
  2304 
       
  2305     return ETrue;
       
  2306     }
       
  2307 //
       
  2308 // ----------------------------------------------------------
       
  2309 // CSecuritySettings::SetFdnModeL()
       
  2310 // Activates or deactivates Fixed Dialling Numbers (FDN) mode.  
       
  2311 // ----------------------------------------------------------
       
  2312 //
       
  2313 EXPORT_C void CSecuritySettings::SetFdnModeL()
       
  2314     {    
       
  2315     /*****************************************************
       
  2316     *    Series 60 Customer / ETel
       
  2317     *    Series 60  ETel API
       
  2318     *****************************************************/
       
  2319     #if defined(_DEBUG)
       
  2320     RDebug::Print(_L("(SECUI)CSecuritySettings::SetFdnModeL()"));
       
  2321     #endif
       
  2322     RMmCustomAPI::TSecurityCodeType secCodeType = RMmCustomAPI::ESecurityCodePin2;
       
  2323     
       
  2324     TBool isBlocked = EFalse;
       
  2325     TInt ret = iCustomPhone.IsBlocked(secCodeType,isBlocked);
       
  2326     
       
  2327     if(isBlocked)
       
  2328         return;
       
  2329     
       
  2330     if (ret != KErrNone)
       
  2331         {    
       
  2332         switch (ret)
       
  2333             {
       
  2334              // PIN2 Blocked.
       
  2335             case KErrGsm0707SIMPuk2Required:
       
  2336                 break;
       
  2337             case KErrGsmSSPasswordAttemptsViolation:
       
  2338             case KErrLocked:
       
  2339                 // Pin2 features blocked permanently!
       
  2340                 ShowResultNoteL(R_PIN2_REJECTED, CAknNoteDialog::EConfirmationTone);
       
  2341                 break;
       
  2342             case KErrGsm0707SimNotInserted:
       
  2343                 // not allowed with this sim
       
  2344                 ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);    
       
  2345                 break;
       
  2346             default:
       
  2347                 ShowErrorNoteL(ret);
       
  2348                 break;
       
  2349             }
       
  2350         return;
       
  2351         }
       
  2352 
       
  2353     
       
  2354     TInt status = KErrNone;
       
  2355 
       
  2356     RMobilePhone::TMobilePhoneFdnStatus fdnMode;
       
  2357     RMobilePhone::TMobilePhoneFdnSetting fdnSet;
       
  2358                     
       
  2359     iPhone.GetFdnStatus(fdnMode);
       
  2360     
       
  2361     if (fdnMode == RMobilePhone::EFdnActive)
       
  2362         {
       
  2363         fdnSet = RMobilePhone::EFdnSetOff;
       
  2364         }
       
  2365     else
       
  2366         {
       
  2367         fdnSet = RMobilePhone::EFdnSetOn;   
       
  2368         }
       
  2369         
       
  2370       // Change the FDN setting
       
  2371     iWait->SetRequestType(EMobilePhoneSetFdnSetting);
       
  2372     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
       
  2373     iPhone.SetFdnSetting(iWait->iStatus, fdnSet);
       
  2374     status = iWait->WaitForRequestL();
       
  2375 
       
  2376     #if defined(_DEBUG)
       
  2377     RDebug::Print( _L("(SECUI)CSecuritySettings::SetFdnModeL(): RETURN CODE: %d"), status);
       
  2378     #endif
       
  2379     switch(status)
       
  2380         {        
       
  2381         case KErrNone:
       
  2382             break;
       
  2383         case KErrGsm0707IncorrectPassword:
       
  2384         case KErrAccessDenied:
       
  2385             // code was entered erroneously
       
  2386             SetFdnModeL();
       
  2387             break;
       
  2388         case KErrGsmSSPasswordAttemptsViolation:
       
  2389         case KErrLocked:
       
  2390             break;
       
  2391         case KErrAbort:
       
  2392             break;
       
  2393         case KErrGsm0707OperationNotAllowed:
       
  2394             // not allowed with this sim
       
  2395             ShowResultNoteL(R_OPERATION_NOT_ALLOWED, CAknNoteDialog::EErrorTone);
       
  2396             break;
       
  2397         default:
       
  2398             ShowErrorNoteL(status);
       
  2399             break;
       
  2400         }    
       
  2401   }
       
  2402 //
       
  2403 // ----------------------------------------------------------
       
  2404 // CSecuritySettings::GetFndMode()
       
  2405 // Retrieves the current Fixed Dialling Numbers mode
       
  2406 // ----------------------------------------------------------
       
  2407 //
       
  2408 EXPORT_C TInt CSecuritySettings::GetFdnMode (RMobilePhone::TMobilePhoneFdnStatus& aFdnMode)
       
  2409     {
       
  2410     /*****************************************************
       
  2411     *    Series 60 Customer / ETel
       
  2412     *    Series 60  ETel API
       
  2413     *****************************************************/
       
  2414     #if defined(_DEBUG)
       
  2415     RDebug::Print(_L("(SECUI)CSecuritySettings::GetFdnMode()"));
       
  2416     #endif
       
  2417     return iPhone.GetFdnStatus(aFdnMode);
       
  2418     }
       
  2419 
       
  2420 //
       
  2421 // ----------------------------------------------------------
       
  2422 // CSecuritySettings::ShowErrorNoteL()
       
  2423 // Shows error note
       
  2424 // ----------------------------------------------------------
       
  2425 //
       
  2426 void CSecuritySettings::ShowErrorNoteL(TInt aError)
       
  2427     {
       
  2428     #if defined(_DEBUG)
       
  2429     RDebug::Print(_L("(SECUI)CSecuritySettings::ShowErrorNoteL()"));
       
  2430     #endif
       
  2431     // Let's create TextResolver instance for error resolving...
       
  2432     CTextResolver* textresolver = CTextResolver::NewLC(); 
       
  2433     // Resolve the error
       
  2434     TPtrC errorstring;
       
  2435     errorstring.Set( textresolver->ResolveErrorString( aError ) );
       
  2436     CAknNoteDialog* noteDlg = new (ELeave) CAknNoteDialog(REINTERPRET_CAST(CEikDialog**,&noteDlg));
       
  2437     noteDlg->PrepareLC(R_CODE_ERROR);
       
  2438     noteDlg->SetTextL((TDesC&)errorstring);
       
  2439     noteDlg->SetTimeout(CAknNoteDialog::ELongTimeout);
       
  2440     noteDlg->SetTone(CAknNoteDialog::EErrorTone);
       
  2441     noteDlg->RunLD();
       
  2442     CleanupStack::PopAndDestroy(); // resolver    
       
  2443     }
       
  2444 
       
  2445 //
       
  2446 // ----------------------------------------------------------
       
  2447 // CSecuritySettings::ShowResultNoteL()
       
  2448 // Shows result note
       
  2449 // ----------------------------------------------------------
       
  2450 //
       
  2451 void CSecuritySettings::ShowResultNoteL(TInt aResourceID, CAknNoteDialog::TTone aTone)
       
  2452     {  
       
  2453     #if defined(_DEBUG)
       
  2454     RDebug::Print(_L("(SECUI)CSecuritySettings::ShowResultNoteL()"));
       
  2455     RDebug::Print(_L("(SECUI)CSecuritySettings::ShowResultNoteL() Resource ID: %d"), aResourceID);
       
  2456     #endif
       
  2457     CAknNoteDialog* noteDlg = new (ELeave) CAknNoteDialog(REINTERPRET_CAST(CEikDialog**,&noteDlg));
       
  2458     noteDlg->SetTimeout(CAknNoteDialog::ELongTimeout);
       
  2459     noteDlg->SetTone(aTone);
       
  2460     noteDlg->ExecuteLD(aResourceID);
       
  2461     }
       
  2462 
       
  2463 //
       
  2464 // ----------------------------------------------------------
       
  2465 // CSecuritySettings::IsUpinSupportedL()
       
  2466 // Return is UPIN supported
       
  2467 // ----------------------------------------------------------
       
  2468 //
       
  2469 EXPORT_C TBool CSecuritySettings::IsUpinSupportedL()
       
  2470 {
       
  2471     TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
       
  2472     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
       
  2473     if(wcdmaSupported || upinSupported)
       
  2474       {
       
  2475     	#if defined(_DEBUG)
       
  2476         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinSupported() BEGIN"));
       
  2477         #endif
       
  2478         #ifdef __WINS__
       
  2479     
       
  2480         return EFalse;
       
  2481     
       
  2482         #else  //WINS
       
  2483     
       
  2484         RMobilePhone::TMobilePhoneLockInfoV1 lockInfo;
       
  2485         
       
  2486         //get lock info
       
  2487         RMobilePhone::TMobilePhoneLockInfoV1Pckg lockInfoPkg(lockInfo);
       
  2488         iWait->SetRequestType(EMobilePhoneGetLockInfo);
       
  2489         #if defined(_DEBUG)
       
  2490         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinSupported() GetLockInfo"));
       
  2491         #endif
       
  2492         iPhone.GetLockInfo(iWait->iStatus, RMobilePhone::ELockUniversalPin, lockInfoPkg);
       
  2493         TInt res = iWait->WaitForRequestL();
       
  2494         #if defined(_DEBUG)
       
  2495         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinSupported() GetLockInfo DONE"));
       
  2496         #endif
       
  2497         if ((res == KErrNotSupported) || (res == KErrGsmInvalidParameter))
       
  2498         {
       
  2499             #if defined(_DEBUG)
       
  2500             RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinSupported(): NOT SUPPORTED"));
       
  2501             #endif
       
  2502             return EFalse;
       
  2503         }
       
  2504         #if defined(_DEBUG)
       
  2505         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinSupported(): SUPPORTED: %d"), res);
       
  2506         #endif
       
  2507         #if defined(_DEBUG)
       
  2508         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinSupported() END"));
       
  2509         #endif
       
  2510         return ETrue;
       
  2511             
       
  2512         #endif //WINS
       
  2513       }
       
  2514     else
       
  2515         return EFalse;
       
  2516 }
       
  2517 //
       
  2518 // ----------------------------------------------------------
       
  2519 // CSecuritySettings::IsCodeBlocked()
       
  2520 // Return is a code blocked
       
  2521 // ----------------------------------------------------------
       
  2522 //
       
  2523 EXPORT_C TBool CSecuritySettings::IsUpinBlocked()
       
  2524 {
       
  2525 TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
       
  2526     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
       
  2527     if(wcdmaSupported || upinSupported)
       
  2528       {
       
  2529     #ifdef __WINS__
       
  2530         return EFalse;
       
  2531     #else//__WINS__
       
  2532         #if defined(_DEBUG)
       
  2533         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinBlocked() BEGIN"));
       
  2534         #endif
       
  2535     	RMmCustomAPI::TSecurityCodeType secCodeType;
       
  2536         secCodeType = RMmCustomAPI::ESecurityUniversalPin;
       
  2537         TBool isBlocked = EFalse;
       
  2538         #if defined(_DEBUG)
       
  2539         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinBlocked() IsBlocked"));
       
  2540         #endif
       
  2541         TInt ret = iCustomPhone.IsBlocked(secCodeType,isBlocked);
       
  2542         #if defined(_DEBUG)
       
  2543         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinBlocked() DONE.RETURN: %d"), ret);
       
  2544         #endif
       
  2545         #if defined(_DEBUG)
       
  2546         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinBlocked():isblocked: %d"), isBlocked);
       
  2547         #endif
       
  2548         #if defined(_DEBUG)
       
  2549         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinBlocked() END"));
       
  2550         #endif
       
  2551         return isBlocked;
       
  2552     #endif //__WINS__
       
  2553       }
       
  2554     else
       
  2555         return EFalse;
       
  2556 }
       
  2557 //
       
  2558 // ----------------------------------------------------------
       
  2559 // CSecuritySettings::GetActivePinCode()
       
  2560 // Return the code active in current application (PIN/UPIN)
       
  2561 // ----------------------------------------------------------
       
  2562 //
       
  2563 EXPORT_C TBool CSecuritySettings::IsUpinActive()
       
  2564 {
       
  2565     TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
       
  2566     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
       
  2567     if(wcdmaSupported || upinSupported)
       
  2568       {
       
  2569         #ifdef __WINS__
       
  2570         return EFalse;
       
  2571         #else//__WINS__
       
  2572         #if defined(_DEBUG)
       
  2573         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinActive() BEGIN"));
       
  2574         #endif
       
  2575     	RMobilePhone::TMobilePhoneSecurityCode activePin;
       
  2576         #if defined(_DEBUG)
       
  2577         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinActive() GetActivePin"));
       
  2578         #endif
       
  2579         iCustomPhone.GetActivePin(activePin);
       
  2580         #if defined(_DEBUG)
       
  2581         RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinActive() GetActivePin DONE"));
       
  2582         #endif
       
  2583     	if(activePin == RMobilePhone::ESecurityUniversalPin)
       
  2584         {
       
  2585             #if defined(_DEBUG)
       
  2586             RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinActive(): UPIN ACTIVE"));
       
  2587             #endif
       
  2588     		return ETrue;
       
  2589         }
       
  2590          #if defined(_DEBUG)
       
  2591          RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinActive(): UPIN NOT ACTIVE"));
       
  2592          #endif
       
  2593          #if defined(_DEBUG)
       
  2594          RDebug::Print(_L("(SECUI)CSecuritySettings::IsUpinActive(): END"));
       
  2595          #endif
       
  2596     	return EFalse;
       
  2597         #endif //__WINS__
       
  2598       }
       
  2599     else
       
  2600         return EFalse;
       
  2601 }
       
  2602 
       
  2603 // End of file