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