securitydialogs/SecUi/Src/SecUiSecurityHandler.cpp
branchGCC_SURGE
changeset 40 604cd42065d1
parent 38 e0432375ea67
child 45 5d3e34b7618a
equal deleted inserted replaced
29:b63e8c2d8cff 40:604cd42065d1
    13 *
    13 *
    14 * Description:  Provides api for handling security events.
    14 * Description:  Provides api for handling security events.
    15 *
    15 *
    16 *
    16 *
    17 */
    17 */
    18 
    18 #include <e32notif.h>
    19 
       
    20 #include <aknnotedialog.h>
    19 #include <aknnotedialog.h>
    21 #include <etelmm.h>
    20 #include <etelmm.h>
    22 #include <SecUi.rsg>
    21 // #include <SecUi.rsg>
    23 #include <exterror.h>
    22 #include <exterror.h>
    24 #include <textresolver.h>
    23 #include <textresolver.h>
    25 
    24 
    26 #ifdef __COVER_DISPLAY
    25 #ifdef __COVER_DISPLAY
    27 #include <aknmediatorfacade.h>
    26 #include <aknmediatorfacade.h>
    28 // #include <secondarydisplay/SecondaryDisplayStartupAPI.h>
    27 // #include <secondarydisplay/SecondaryDisplayStartupAPI.h>
    29 #endif //__COVER_DISPLAY
    28 #endif //__COVER_DISPLAY
    30 #include <centralrepository.h> 
    29 #include <centralrepository.h> 
    31 #include <starterclient.h>     //used for RemoveSplashScreen
    30 #include <starterclient.h>     //used for RemoveSplashScreen
    32 #include <e32property.h>
    31 #include <e32property.h>
       
    32 
    33 #include <PSVariables.h>   // Property values
    33 #include <PSVariables.h>   // Property values
    34 #include <coreapplicationuisdomainpskeys.h>
    34 #include <coreapplicationuisdomainpskeys.h>
    35 #include <startupdomainpskeys.h>
    35 #include <startupdomainpskeys.h>
    36 #include <uikon/eiksrvui.h>
    36 #include <uikon/eiksrvui.h>
    37 #include <settingsinternalcrkeys.h>
    37 #include <settingsinternalcrkeys.h>
    39 #include <AknNotiferAppServerApplication.h>
    39 #include <AknNotiferAppServerApplication.h>
    40 
    40 
    41 #include <SCPClient.h>
    41 #include <SCPClient.h>
    42 #include <securitynotification.h>
    42 #include <securitynotification.h>
    43 #include "secui.hrh"
    43 #include "secui.hrh"
       
    44 #include "SecUi.h"
    44 #include "secuisecurityhandler.h"
    45 #include "secuisecurityhandler.h"
    45 #include "secuicodequerydialog.h"
    46 #include "secuicodequerydialog.h"
    46 #include "secuisecuritysettings.h"
    47 #include "secuisecuritysettings.h"
    47 #include "SecUiWait.h"
    48 #include "SecUiWait.h"
    48 #include "SecUiLockObserver.h"
    49 // #include "SecUiLockObserver.h"
    49 #ifdef RD_REMOTELOCK
       
    50 #include <RemoteLockSettings.h>
    50 #include <RemoteLockSettings.h>
    51 #endif // RD_REMOTELOCK
       
    52 #include <StringLoader.h>
    51 #include <StringLoader.h>
    53 #include <featmgr.h>
    52 #include <featmgr.h>
    54 
    53 
    55 #include "SecQueryUi.h"
    54 #include "SecQueryUi.h"
    56 
    55 
    57 //  LOCAL CONSTANTS AND MACROS
    56 //  LOCAL CONSTANTS AND MACROS
    58 const TInt KMaxNumberOfPUKAttempts(10);
    57 const TInt KMaxNumberOfPUKAttempts(10);
    59 const TInt KMaxNumberOfPINAttempts(3);
    58 const TInt KMaxNumberOfPINAttempts(3);
    60 const TInt KLastRemainingInputAttempt(1);
    59 // not used
       
    60 // const TInt KLastRemainingInputAttempt(1);
    61 
    61 
    62 const TInt KTriesToConnectServer(2);
    62 const TInt KTriesToConnectServer(2);
    63 const TInt KTimeBeforeRetryingRequest(50000);
    63 const TInt KTimeBeforeRetryingRequest(50000);
    64 
    64 
    65 // ================= MEMBER FUNCTIONS =======================
    65 // ================= MEMBER FUNCTIONS =======================
    91     if (iDestroyedPtr)
    91     if (iDestroyedPtr)
    92         {
    92         {
    93         *iDestroyedPtr = ETrue;
    93         *iDestroyedPtr = ETrue;
    94         iDestroyedPtr = NULL;
    94         iDestroyedPtr = NULL;
    95         }
    95         }
    96     CancelSecCodeQuery();
    96     RDEBUG("calling CancelOpenQuery", 0);
       
    97     TInt err = CancelOpenQuery(-1);
       
    98     RDEBUG("err", err);
    97     iCustomPhone.Close();
    99     iCustomPhone.Close();
    98     FeatureManager::UnInitializeLib();
   100     FeatureManager::UnInitializeLib();
       
   101    	RDEBUG("1", 1);
    99     }
   102     }
   100 //
   103 //
   101 // ----------------------------------------------------------
   104 // ----------------------------------------------------------
   102 // CSecurityHandler::HandleEventL()
   105 // CSecurityHandler::HandleEventL()
   103 // Handles different security events
   106 // Handles different security events
   149     RDEBUG("aEvent", aEvent);
   152     RDEBUG("aEvent", aEvent);
   150 
   153 
   151     switch (aEvent)
   154     switch (aEvent)
   152         {
   155         {
   153         case RMobilePhone::EPin1Required:
   156         case RMobilePhone::EPin1Required:
   154 #if defined(_DEBUG)
   157 						RDEBUG("RMobilePhone::EPin1Required", 0);
   155             RDebug::Print(_L("(SECUI)CSecurityHandler::HandleEventL() Pin1Required"));
       
   156 #endif
       
   157             aResult = Pin1RequiredL();
   158             aResult = Pin1RequiredL();
   158             break;
   159             break;
   159         case RMobilePhone::EPuk1Required:
   160         case RMobilePhone::EPuk1Required:
   160 #if defined(_DEBUG)
   161 						RDEBUG("RMobilePhone::EPuk1Required", 0);
   161             RDebug::Print(_L("(SECUI)CSecurityHandler::HandleEventL() PUK1Required"));
       
   162 #endif
       
   163             Puk1RequiredL();
   162             Puk1RequiredL();
   164             break;
   163             break;
   165         case RMobilePhone::EPin2Required:
   164         case RMobilePhone::EPin2Required:
   166             Pin2RequiredL();
   165             Pin2RequiredL();
   167             break;
   166             break;
   189             break;
   188             break;
   190         case RMobilePhone::EICCTerminated:
   189         case RMobilePhone::EICCTerminated:
   191             SimLockEventL();
   190             SimLockEventL();
   192             break;
   191             break;
   193         default:
   192         default:
       
   193         		RDEBUG("default", aEvent);
   194             break;
   194             break;
   195         }
   195         }
   196     RDEBUG("aResult", aResult);
   196     RDEBUG("aResult", aResult);
   197     }
   197     }
   198 //
   198 //
   205     {
   205     {
   206     /*****************************************************
   206     /*****************************************************
   207      *    Series 60 Customer / ETel
   207      *    Series 60 Customer / ETel
   208      *    Series 60  ETel API
   208      *    Series 60  ETel API
   209      *****************************************************/
   209      *****************************************************/
   210 #if defined(_DEBUG)
   210 		RDEBUG("0", 0);
   211     RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeL()"));
       
   212 #endif
       
   213 
   211 
   214     /* if code is still not initialized, then there's no need to ask it. This fixes the error when the RFS requests the code */
   212     /* if code is still not initialized, then there's no need to ask it. This fixes the error when the RFS requests the code */
   215     const TUid KCRUidSCPLockCode =
   213     const TUid KCRUidSCPLockCode =
   216         {
   214         {
   217         0x2002677B
   215         0x2002677B
   233         // code is the default one; no need to request it.
   231         // code is the default one; no need to request it.
   234         return ETrue;
   232         return ETrue;
   235         }
   233         }
   236     /* end check for default code */
   234     /* end check for default code */
   237 
   235 
   238     iQueryCanceled = EFalse;
       
   239     RMobilePhone::TMobilePassword required_fourth;
   236     RMobilePhone::TMobilePassword required_fourth;
   240 
   237 
   241     TInt ret = KErrNone;
   238     TInt ret = KErrNone;
   242     TInt status = KErrNone;
   239     TInt status = KErrNone;
   243 
   240 
   251 
   248 
   252         /* request PIN using QT */
   249         /* request PIN using QT */
   253         CSecQueryUi *iSecQueryUi;
   250         CSecQueryUi *iSecQueryUi;
   254         RDEBUG("CSecQueryUi", 0);
   251         RDEBUG("CSecQueryUi", 0);
   255         iSecQueryUi = CSecQueryUi::NewL();
   252         iSecQueryUi = CSecQueryUi::NewL();
       
   253 				iQueryCanceled = EFalse;
   256         lAlphaSupported = ESecUiAlphaSupported;
   254         lAlphaSupported = ESecUiAlphaSupported;
   257         lCancelSupported = ESecUiCancelSupported;
   255         lCancelSupported = ESecUiCancelSupported;
   258         TBuf<0x100> title;
   256         TBuf<0x100> title;
   259         title.Zero();
   257         title.Zero();
   260         title.Append(_L("AskSecCodeL"));
   258         title.Append(_L("AskSecCodeL"));
   263         queryAccepted
   261         queryAccepted
   264                 = iSecQueryUi->SecQueryDialog(title, iSecUi_password,
   262                 = iSecQueryUi->SecQueryDialog(title, iSecUi_password,
   265                         SEC_C_SECURITY_CODE_MIN_LENGTH,
   263                         SEC_C_SECURITY_CODE_MIN_LENGTH,
   266                         SEC_C_SECURITY_CODE_MAX_LENGTH, ESecUiSecretSupported
   264                         SEC_C_SECURITY_CODE_MAX_LENGTH, ESecUiSecretSupported
   267                                 | lAlphaSupported | lCancelSupported
   265                                 | lAlphaSupported | lCancelSupported
   268                                 | secCodeType /*aMode*/);
   266                                 | secCodeType );
   269         RDEBUG("iSecUi_password", 0);
   267         RDEBUG("iSecUi_password", 0);
   270         RDebug::Print(iSecUi_password);
   268         RDebug::Print(iSecUi_password);
   271         RDEBUG("delete", 0);
   269         RDEBUG("delete", 0);
       
   270         iQueryCanceled = ETrue;
   272         delete iSecQueryUi;
   271         delete iSecQueryUi;
   273         RDEBUG("queryAccepted", queryAccepted);
   272         RDEBUG("queryAccepted", queryAccepted);
   274         /* end request PIN using QT */
   273         /* end request PIN using QT */
   275         if (queryAccepted != KErrNone)
   274         if (queryAccepted != KErrNone)
   276             {
   275             {
   317 
   316 
   318                     CleanupStack::PopAndDestroy(); //scpClient
   317                     CleanupStack::PopAndDestroy(); //scpClient
   319                     queryAccepted = KErrNone;
   318                     queryAccepted = KErrNone;
   320                     }
   319                     }
   321 
   320 
   322                 iQueryCanceled = ETrue; // TODO
   321                 iQueryCanceled = ETrue;
   323                 return ETrue;
   322                 return ETrue;
   324                 }
   323                 }
   325             case KErrGsmSSPasswordAttemptsViolation:
   324             case KErrGsmSSPasswordAttemptsViolation:
   326             case KErrLocked:
   325             case KErrLocked:
   327                 {
   326                 {
   348     iQueryCanceled = ETrue;
   347     iQueryCanceled = ETrue;
   349     return ret;
   348     return ret;
   350     }
   349     }
   351 //
   350 //
   352 // ----------------------------------------------------------
   351 // ----------------------------------------------------------
       
   352 // Cancels all security code queries
       
   353 // aStatus = -1		from destructor
       
   354 // aStatus =  1		from API. Will kill all dialogs through signal P&S
       
   355 // ----------------------------------------------------------
       
   356 // qtdone
       
   357 TInt CSecurityHandler::CancelOpenQuery(TInt aStatus)
       
   358     {
       
   359 		RDEBUG("aStatus", aStatus);
       
   360 		RDEBUG("iQueryCanceled", iQueryCanceled);
       
   361 		TInt res = 0;
       
   362 		
       
   363 		if(aStatus==1)	// also signal all other dialogs
       
   364 				{
       
   365 				RDEBUG("set KSecurityUIsDismissDialog to ESecurityUIsDismissDialogOn", ESecurityUIsDismissDialogOn);
       
   366 		    TInt err = RProperty::Set(KPSUidSecurityUIs, KSecurityUIsDismissDialog, ESecurityUIsDismissDialogOn );
       
   367 		    RDEBUG("err", err);
       
   368 		    res += 1;
       
   369 			  }
       
   370 
       
   371     if (!iQueryCanceled)
       
   372         {
       
   373 				// notify all dialogs, in particular SecUiNotificationDialog::subscriberKSecurityUIsDismissDialogChanged
       
   374 				// this will cancel only the dialog which was opened by same client.
       
   375     		res += 0x10;
       
   376         iQueryCanceled = ETrue;
       
   377         if (iSecurityDlg != NULL)
       
   378             {
       
   379             RDEBUG("deleting iSecurityDlg", 0);
       
   380 		    		res += 0x100;
       
   381             delete iSecurityDlg;
       
   382             }
       
   383         if (iNoteDlg != NULL)
       
   384             {
       
   385             RDEBUG("deleting iNoteDlg", 0);
       
   386 		    		res += 0x1000;
       
   387             delete iNoteDlg;
       
   388             }
       
   389         iNoteDlg = NULL;
       
   390         iSecurityDlg = NULL;
       
   391         }
       
   392  		res += 0x10000;
       
   393 		RDEBUG("res", res);
       
   394  		return res;
       
   395 		}
       
   396 
       
   397 //
       
   398 // ----------------------------------------------------------
   353 // CSecurityHandler::CancelSecCodeQuery()    
   399 // CSecurityHandler::CancelSecCodeQuery()    
   354 // Cancels PIN2 and security code queries
   400 // Cancels PIN2 and security code queries
   355 // TODO is this used?
   401 // this is used by rfsHandler
   356 // ----------------------------------------------------------
   402 // ----------------------------------------------------------
   357 // qtdone
   403 // qtdone
   358 EXPORT_C void CSecurityHandler::CancelSecCodeQuery()
   404 EXPORT_C void CSecurityHandler::CancelSecCodeQuery()
   359     {
   405     {
   360 #if defined(_DEBUG)
   406 		RDEBUG("0", 0);
   361     RDebug::Print(_L("(SECUI)CSecurityHandler::CancelSecCodeQuery()"));
   407 
   362 #endif
   408 		TInt err = CancelOpenQuery(1);
   363     if (!iQueryCanceled)
   409 
   364         {
   410 		RDEBUG("err", err);
   365         iQueryCanceled = ETrue;
       
   366         if (iSecurityDlg != NULL)
       
   367             {
       
   368             delete iSecurityDlg;
       
   369             }
       
   370         if (iNoteDlg != NULL)
       
   371             {
       
   372             delete iNoteDlg;
       
   373             }
       
   374         iNoteDlg = NULL;
       
   375         iSecurityDlg = NULL;
       
   376         }
       
   377     }
   411     }
   378 //
   412 //
   379 // ----------------------------------------------------------
   413 // ----------------------------------------------------------
   380 // CSecurityHandler::AskSecCodeInAutoLock()
   414 // CSecurityHandler::AskSecCodeInAutoLock()
   381 // for asking security code in autolock
   415 // for asking security code in autolock
   387      *    Series 60 Customer / ETel
   421      *    Series 60 Customer / ETel
   388      *    Series 60  ETel API
   422      *    Series 60  ETel API
   389      *****************************************************/
   423      *****************************************************/
   390 
   424 
   391     RDEBUG("0", 0);
   425     RDEBUG("0", 0);
   392 
       
   393 #if defined(_DEBUG)
       
   394     RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL()"));
       
   395 #endif
       
   396     TInt res;
   426     TInt res;
   397     CWait* wait;
   427     CWait* wait;
   398 
   428 
   399     RMobilePhone::TMobilePhoneLockSetting lockChange(
   429     RMobilePhone::TMobilePhoneLockSetting lockChange(
   400             RMobilePhone::ELockSetDisabled);
   430             RMobilePhone::ELockSetDisabled);
   401     RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
   431     RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
   402 
       
   403 #if defined(_DEBUG)
       
   404     RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL() get autolock period"));
       
   405 #endif
       
   406 
   432 
   407     // get autolock period from Central Repository.
   433     // get autolock period from Central Repository.
   408     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings);
   434     CRepository* repository = CRepository::NewL(KCRUidSecuritySettings);
   409     TInt period = 0;
   435     TInt period = 0;
   410     res = repository->Get(KSettingsAutoLockTime, period);
   436     res = repository->Get(KSettingsAutoLockTime, period);
   411     delete repository;
   437     delete repository;
   412 
   438 
   413     RDEBUG("res", res);
   439     RDEBUG("res", res);
   414 
   440     RDEBUG("period", period);
   415 #if defined(_DEBUG)
   441 
   416     RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL() autolock period:%d"), res);
       
   417 #endif
       
   418     if (res == KErrNone)
   442     if (res == KErrNone)
   419         {
   443         {
   420         // disable autolock in Domestic OS side too if autolock period is 0.
   444         // disable autolock in Domestic OS side too if autolock period is 0.
   421         RDEBUG("period", period);
       
   422         if (period == 0)
   445         if (period == 0)
   423             {
   446             {
   424 #if defined(_DEBUG)
   447 						RDEBUG("period", period);
   425             RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL() Call SetLockSetting"));
   448 
   426 #endif
       
   427 
       
   428 #ifdef RD_REMOTELOCK
       
   429             // If remote lock is enabled, don't disable the domestic OS device lock
   449             // If remote lock is enabled, don't disable the domestic OS device lock
   430             // since that would render the RemoteLock useless.
   450             // since that would render the RemoteLock useless.
   431             // Instead just re-set the DOS lock to enabled which as a side effect
   451             // Instead just re-set the DOS lock to enabled which as a side effect
   432             // requests the security code from the user.
   452             // requests the security code from the user.
   433 
   453 
   438                 {
   458                 {
   439                 RDEBUG( "0", 0 );
   459                 RDEBUG( "0", 0 );
   440                 if ( remoteLockStatus )
   460                 if ( remoteLockStatus )
   441                     {
   461                     {
   442                     // Remote lock is enabled
   462                     // Remote lock is enabled
   443 #ifdef _DEBUG
       
   444                     RDebug::Print( _L( "(SecUi)CSecurityHandler::AskSecCodeInAutoLockL() - RemoteLock is enabled: lockChange = RMobilePhone::ELockSetEnabled" ) );
       
   445 #endif // _DEBUG
       
   446                     lockChange = RMobilePhone::ELockSetEnabled;
   463                     lockChange = RMobilePhone::ELockSetEnabled;
       
   464                     RDEBUG("lockChange", lockChange);
   447                     }
   465                     }
   448                 else
   466                 else
   449                     {
   467                     {
   450                     // Remote lock is disabled
   468                     // Remote lock is disabled
   451 #ifdef _DEBUG
       
   452                     RDebug::Print( _L( "(SecUi)CSecurityHandler::AskSecCodeInAutoLockL() - RemoteLock is disabled: lockChange = RMobilePhone::ELockSetDisabled" ) );
       
   453 #endif // _DEBUG
       
   454                     lockChange = RMobilePhone::ELockSetDisabled;
   469                     lockChange = RMobilePhone::ELockSetDisabled;
       
   470                     RDEBUG("lockChange", lockChange);
   455                     }
   471                     }
   456                 }
   472                 }
   457             else
   473             else
   458                 {
   474                 {
   459                 // Failed to get remote lock status
   475                 // Failed to get remote lock status
   460 #ifdef _DEBUG
   476 								RDEBUG("Failed", lockChange);
   461                 RDebug::Print( _L( "(SecUi)CSecurityHandler::AskSecCodeInAutoLockL() - Failed to get RemoteLock status" ) );
       
   462 #endif // _DEBUG
       
   463                 }
   477                 }
   464 
   478 
   465             delete remoteLockSettings;
   479             delete remoteLockSettings;
   466             remoteLockSettings = NULL;
   480             remoteLockSettings = NULL;
   467 
   481 
   468 #else // not defined RD_REMOTELOCK
       
   469             lockChange = RMobilePhone::ELockSetDisabled;
       
   470 
       
   471 #endif // RD_REMOTELOCK
       
   472             RDEBUG("lockChange", lockChange);
   482             RDEBUG("lockChange", lockChange);
   473             wait = CWait::NewL();
   483             wait = CWait::NewL();
   474             RDEBUG("0", 0);
   484             RDEBUG("0", 0);
   475             // this also calls PassPhraseRequiredL ???
   485             // this also calls PassPhraseRequiredL ???
   476             RDEBUG("SetLockSetting", 1);
   486             RDEBUG("SetLockSetting", 1);
   478             res = KErrNone;
   488             res = KErrNone;
   479             RDEBUG("WaitForRequestL", 0);
   489             RDEBUG("WaitForRequestL", 0);
   480             res = wait->WaitForRequestL();
   490             res = wait->WaitForRequestL();
   481             RDEBUG("res", res);
   491             RDEBUG("res", res);
   482             delete wait;
   492             delete wait;
   483 #if defined(_DEBUG)
       
   484             RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL() SetLockSetting RESULT:%d"), res);
       
   485 #endif
       
   486             } // from   period == 0
   493             } // from   period == 0
   487         else
   494         else
   488             { // ask security code
   495             { // ask security code
   489 #if defined(_DEBUG)
   496             RDEBUG("codeQueryNotifier 0", 0);
   490             RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL() Ask sec code via notifier"));
       
   491 #endif
       
   492             RDEBUG("0", 0);
       
   493             RNotifier codeQueryNotifier;
   497             RNotifier codeQueryNotifier;
   494             User::LeaveIfError(codeQueryNotifier.Connect());
   498             User::LeaveIfError(codeQueryNotifier.Connect());
   495             CWait* wait = CWait::NewL();
   499             CWait* wait = CWait::NewL();
   496             CleanupStack::PushL(wait);
   500             CleanupStack::PushL(wait);
   497             TInt queryResponse = 0;
   501             TInt queryResponse = 0;
   499             RDEBUG("0", 0);
   503             RDEBUG("0", 0);
   500             TSecurityNotificationPckg params;
   504             TSecurityNotificationPckg params;
   501             params().iEvent
   505             params().iEvent
   502                     = static_cast<TInt> (RMobilePhone::EPhonePasswordRequired);
   506                     = static_cast<TInt> (RMobilePhone::EPhonePasswordRequired);
   503             params().iStartup = EFalse;
   507             params().iStartup = EFalse;
   504 #if defined(_DEBUG)
   508 
   505             RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL() Start Notifier"));
       
   506 #endif
       
   507             RDEBUG("0", 0);
       
   508             RDEBUG("StartNotifierAndGetResponse", 0);
   509             RDEBUG("StartNotifierAndGetResponse", 0);
   509             codeQueryNotifier.StartNotifierAndGetResponse(wait->iStatus,
   510             codeQueryNotifier.StartNotifierAndGetResponse(wait->iStatus,
   510                     KSecurityNotifierUid, params, response);
   511                     KSecurityNotifierUid, params, response);
   511             // this will eventually call PassPhraseRequiredL
   512             // this will eventually call PassPhraseRequiredL
   512             RDEBUG("WaitForRequestL", 0);
   513             RDEBUG("WaitForRequestL", 0);
   521         }
   522         }
   522     else
   523     else
   523         { // can't read repository for KSettingsAutoLockTime
   524         { // can't read repository for KSettingsAutoLockTime
   524         RDEBUG("KERRSOMETHING:Call SetLockSetting", 0);
   525         RDEBUG("KERRSOMETHING:Call SetLockSetting", 0);
   525 
   526 
   526 #ifdef RD_REMOTELOCK
       
   527 
       
   528         // If remote lock is enabled, don't disable the domestic OS device lock
   527         // If remote lock is enabled, don't disable the domestic OS device lock
   529         // since that would render the RemoteLock useless.
   528         // since that would render the RemoteLock useless.
   530         // Instead just re-set the DOS lock to enabled which as a side effect
   529         // Instead just re-set the DOS lock to enabled which as a side effect
   531         // requests the security code from the user.
   530         // requests the security code from the user.
   532 
   531 
   536         if ( remoteLockSettings->GetEnabled( remoteLockStatus ) )
   535         if ( remoteLockSettings->GetEnabled( remoteLockStatus ) )
   537             {
   536             {
   538             if ( remoteLockStatus )
   537             if ( remoteLockStatus )
   539                 {
   538                 {
   540                 // Remote lock is enabled
   539                 // Remote lock is enabled
   541 #ifdef _DEBUG
       
   542                 RDebug::Print( _L( "(SecUi)CSecurityHandler::AskSecCodeInAutoLockL() - Failed to get AutoLock status and RemoteLock is enabled: lockChange = RMobilePhone::ELockSetEnabled" ) );
       
   543 #endif // _DEBUG
       
   544                 lockChange = RMobilePhone::ELockSetEnabled;
   540                 lockChange = RMobilePhone::ELockSetEnabled;
       
   541                 RDEBUG("lockChange", lockChange);
   545                 }
   542                 }
   546             else
   543             else
   547                 {
   544                 {
   548                 // Remote lock is disabled
   545                 // Remote lock is disabled
   549 #ifdef _DEBUG
       
   550                 RDebug::Print( _L( "(SecUi)CSecurityHandler::AskSecCodeInAutoLockL() - Failed to get AutoLock status and RemoteLock is disabled: lockChange = RMobilePhone::ELockSetDisabled" ) );
       
   551 #endif // _DEBUG
       
   552                 lockChange = RMobilePhone::ELockSetDisabled;
   546                 lockChange = RMobilePhone::ELockSetDisabled;
       
   547                 RDEBUG("lockChange", lockChange);
   553                 }
   548                 }
   554             }
   549             }
   555         else
   550         else
   556             {
   551             {
   557             // Failed to get remote lock status
   552             // Failed to get remote lock status
   558 #ifdef _DEBUG
   553             RDEBUG("Failed", lockChange);
   559             RDebug::Print( _L( "(SecUi)CSecurityHandler::AskSecCodeInAutoLockL() - Failed to get AutoLock status and failed to get RemoteLock status" ) );
       
   560 #endif // _DEBUG
       
   561             }
   554             }
   562 
   555 
   563         delete remoteLockSettings;
   556         delete remoteLockSettings;
   564         remoteLockSettings = NULL;
   557         remoteLockSettings = NULL;
   565 
   558 
   566 #else // not defined RD_REMOTELOCK
       
   567         // could not get the current autolock time... disable autolock in Domestic OS side.
       
   568         lockChange = RMobilePhone::ELockSetDisabled;
       
   569 
       
   570 #endif // RD_REMOTELOCK
       
   571         RDEBUG("0", 0);
   559         RDEBUG("0", 0);
   572 
       
   573         wait = CWait::NewL();
   560         wait = CWait::NewL();
   574         RDEBUG("SetLockSetting", 0);
   561         RDEBUG("SetLockSetting", 0);
   575         iPhone.SetLockSetting(wait->iStatus, lockType, lockChange);
   562         iPhone.SetLockSetting(wait->iStatus, lockType, lockChange);
   576         RDEBUG("WaitForRequestL", 0);
   563         RDEBUG("WaitForRequestL", 0);
   577         res = wait->WaitForRequestL();
   564         res = wait->WaitForRequestL();
   578         RDEBUG("WaitForRequestL", 1);
   565         RDEBUG("WaitForRequestL res", res);
   579         delete wait;
   566         delete wait;
   580 #if defined(_DEBUG)
       
   581         RDebug::Print(_L("(SECUI)CSecurityHandler::AskSecCodeInAutoLockL() KES: SetLockSetting RESULT:%d"), res);
       
   582 #endif
       
   583         }
   567         }
   584 
   568 
   585     RDEBUG("res", res);
   569     RDEBUG("res", res);
   586     switch (res)
   570     switch (res)
   587         {
   571         {
   595         case KErrAccessDenied:
   579         case KErrAccessDenied:
   596             {
   580             {
   597             RDEBUG("KErrAccessDenied", KErrAccessDenied);
   581             RDEBUG("KErrAccessDenied", KErrAccessDenied);
   598             return AskSecCodeInAutoLockL();
   582             return AskSecCodeInAutoLockL();
   599             }
   583             }
       
   584         case KErrInUse:
       
   585             {
       
   586         		RDEBUG("KErrInUse", KErrInUse);
       
   587         		return EFalse;
       
   588             }
       
   589         case KErrDied :
       
   590             {
       
   591         		RDEBUG("KErrDied ", KErrDied );
       
   592         		return EFalse;
       
   593             }
       
   594         case KErrServerTerminated :
       
   595             {
       
   596         		RDEBUG("KErrServerTerminated ", KErrServerTerminated );
       
   597         		return EFalse;
       
   598             }
       
   599         case KErrServerBusy :
       
   600             {
       
   601         		RDEBUG("KErrServerBusy ", KErrServerBusy );
       
   602         		return EFalse;
       
   603             }
   600         case KErrAbort:
   604         case KErrAbort:
       
   605             {
       
   606         		RDEBUG("KErrAbort", KErrAbort);
       
   607         		return EFalse;
       
   608             }
   601         case KErrCancel:
   609         case KErrCancel:
       
   610             {
       
   611         		RDEBUG("KErrCancel", KErrCancel);
   602             // user pressed "cancel"
   612             // user pressed "cancel"
   603             return EFalse;
   613             return EFalse;
       
   614             }
   604         default:
   615         default:
   605             {
   616             {
   606             RDEBUG("default", res);
   617             RDEBUG("default", res);
   607             return AskSecCodeInAutoLockL();
   618             return AskSecCodeInAutoLockL();
   608             }
   619             }
   635     err = RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus,
   646     err = RProperty::Get(KPSUidCoreApplicationUIs, KCoreAppUIsAutolockStatus,
   636             autolockState);
   647             autolockState);
   637     RDEBUG("StartUp", StartUp);
   648     RDEBUG("StartUp", StartUp);
   638     RDEBUG("err", err);
   649     RDEBUG("err", err);
   639     if (!StartUp)
   650     if (!StartUp)
       
   651     		{
       
   652     		RDebug::Printf( "%s %s (%u) might leave if StartUp=0 and err=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, err );
   640         User::LeaveIfError(err);
   653         User::LeaveIfError(err);
       
   654       	}
   641     TBool isConditionSatisfied = EFalse;
   655     TBool isConditionSatisfied = EFalse;
   642     TInt tarmFlag = 0;
   656     TInt tarmFlag = 0;
   643     if (FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))
   657     if (FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw ))
   644         {
   658         {
   645         TInt tRet = RProperty::Get(KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID,
   659         TInt tRet = RProperty::Get(KSCPSIDAutolock, SCP_TARM_ADMIN_FLAG_UID,
   646                 tarmFlag);
   660                 tarmFlag);
   647 
   661 
   648         if (tRet != KErrNone)
   662         if (tRet != KErrNone)
   649             {
   663             {
   650 #if defined(_DEBUG)
   664             RDEBUG("Warning: failed to get TARM Admin Flag state", tRet);
   651             RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL():\
       
   652             Warning: failed to get TARM Admin Flag state"));
       
   653 #endif
       
   654             }
   665             }
   655         else
   666         else
   656             {
   667             {
   657 #if defined(_DEBUG)
   668             RDEBUG("TARM flag", tarmFlag);
   658             RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL(): TARM flag: %d"), tarmFlag );
       
   659 #endif
       
   660             }
   669             }
   661 
   670 
   662         if ((StartUp) || (tarmFlag & KSCPFlagResyncQuery))
   671         if ((StartUp) || (tarmFlag & KSCPFlagResyncQuery))
   663             isConditionSatisfied = ETrue;
   672             isConditionSatisfied = ETrue;
   664         }
   673         }
   665     else
   674     else
   666         {
   675         {
   667         if (StartUp)
   676         if (StartUp)
   668             isConditionSatisfied = ETrue;
   677             isConditionSatisfied = ETrue;
   669         }
   678         }
   670 #if defined(_DEBUG)
   679 
   671     RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() Dialog 1"));
       
   672 #endif
       
   673     // Security code at bootup: No "cancel" softkey; Emergency calls enabled.
   680     // Security code at bootup: No "cancel" softkey; Emergency calls enabled.
   674     RMobilePhone::TMobilePhoneSecurityCode secCodeTypeToAsk =
   681     RMobilePhone::TMobilePhoneSecurityCode secCodeTypeToAsk = RMobilePhone::ESecurityCodePhonePassword;
   675             RMobilePhone::ESecurityCodePhonePassword; // for starters
       
   676     RDEBUG("isConditionSatisfied", isConditionSatisfied);
   682     RDEBUG("isConditionSatisfied", isConditionSatisfied);
   677     if (isConditionSatisfied)
   683     if (isConditionSatisfied)
   678         {
   684         {
   679         // starter or special TARM. NoCancel+Emergency
   685         // starter or special TARM. NoCancel+Emergency
   680         lCancelSupported = ESecUiCancelNotSupported;
   686         lCancelSupported = ESecUiCancelNotSupported;
   693         lEmergencySupported = ESecUiEmergencyNotSupported;
   699         lEmergencySupported = ESecUiEmergencyNotSupported;
   694         }
   700         }
   695 
   701 
   696     CSecQueryUi *iSecQueryUi;
   702     CSecQueryUi *iSecQueryUi;
   697     iSecQueryUi = CSecQueryUi::NewL();
   703     iSecQueryUi = CSecQueryUi::NewL();
       
   704 		iQueryCanceled = EFalse;
   698     TInt lType = ESecUiSecretSupported | ESecUiAlphaSupported
   705     TInt lType = ESecUiSecretSupported | ESecUiAlphaSupported
   699             | lCancelSupported | lEmergencySupported | secCodeTypeToAsk;
   706             | lCancelSupported | lEmergencySupported | secCodeTypeToAsk;
   700     RDEBUG("lType", lType);
   707     RDEBUG("lType", lType);
   701     iSecUi_password.Copy(_L("12345"));
       
   702     queryAccepted = iSecQueryUi->SecQueryDialog(_L("PassPhraseRequiredL"),
   708     queryAccepted = iSecQueryUi->SecQueryDialog(_L("PassPhraseRequiredL"),
   703             iSecUi_password, SEC_C_SECURITY_CODE_MIN_LENGTH,
   709             iSecUi_password, SEC_C_SECURITY_CODE_MIN_LENGTH,
   704             SEC_C_SECURITY_CODE_MAX_LENGTH, lType);
   710             SEC_C_SECURITY_CODE_MAX_LENGTH, lType);
   705     RDEBUG("iSecUi_password", 0);
   711     RDEBUG("iSecUi_password", 0);
   706     RDebug::Print(iSecUi_password);
   712     RDebug::Print(iSecUi_password);
   707     RDEBUG("queryAccepted", queryAccepted);
   713     RDEBUG("queryAccepted", queryAccepted);
       
   714     iQueryCanceled = ETrue;
   708     delete iSecQueryUi;
   715     delete iSecQueryUi;
   709 
   716 
   710     TBool wasCancelledOrEmergency = EFalse;
   717     TBool wasCancelledOrEmergency = EFalse;
   711     RDEBUG("KFeatureIdSapDeviceLockEnhancements",
   718     RDEBUG("KFeatureIdSapDeviceLockEnhancements",
   712             KFeatureIdSapDeviceLockEnhancements);
   719             KFeatureIdSapDeviceLockEnhancements);
   714             == KErrCancel))
   721             == KErrCancel))
   715         wasCancelledOrEmergency = ETrue;
   722         wasCancelledOrEmergency = ETrue;
   716     RDEBUG("wasCancelledOrEmergency", wasCancelledOrEmergency);
   723     RDEBUG("wasCancelledOrEmergency", wasCancelledOrEmergency);
   717     if (wasCancelledOrEmergency)
   724     if (wasCancelledOrEmergency)
   718         {
   725         {
   719 #if defined(_DEBUG)
   726 				RDEBUG("StartUp", StartUp);
   720         RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() DIALOG ERROR"));
       
   721 #endif
       
   722         if (!StartUp)
   727         if (!StartUp)
   723             {
   728             {
   724             RDEBUG("AbortSecurityCode", 0);
   729             RDEBUG("AbortSecurityCode", 0);
   725             iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePhonePassword);
   730             iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePhonePassword);
   726             RDEBUG("AbortSecurityCode", 1);
   731             RDEBUG("AbortSecurityCode", 1);
   730 
   735 
   731     RMobilePhone::TMobilePhoneSecurityCode secCodeType =
   736     RMobilePhone::TMobilePhoneSecurityCode secCodeType =
   732             RMobilePhone::ESecurityCodePhonePassword;
   737             RMobilePhone::ESecurityCodePhonePassword;
   733     CWait* wait = NULL;
   738     CWait* wait = NULL;
   734     TInt status = KErrNone;
   739     TInt status = KErrNone;
   735     ;
   740     
   736     wait = CWait::NewL();
   741     wait = CWait::NewL();
   737     RDEBUG("VerifySecurityCode", 0);
   742     RDEBUG("VerifySecurityCode", 0);
   738     iPhone.VerifySecurityCode(wait->iStatus, secCodeType, iSecUi_password,
   743     iPhone.VerifySecurityCode(wait->iStatus, secCodeType, iSecUi_password,
   739             required_fourth);
   744             required_fourth);
   740     RDEBUG("WaitForRequestL", 0);
   745     RDEBUG("WaitForRequestL", 0);
   750 #endif
   755 #endif
   751 
   756 
   752     TInt returnValue = status;
   757     TInt returnValue = status;
   753     RDEBUG("tarmFlag", tarmFlag);
   758     RDEBUG("tarmFlag", tarmFlag);
   754     RDEBUG("StartUp", StartUp);
   759     RDEBUG("StartUp", StartUp);
       
   760     RDEBUG("status", status);
   755     switch (status)
   761     switch (status)
   756         {
   762         {
   757         case KErrNone:
   763         case KErrNone:
   758 #if defined(_DEBUG)
   764             // code approved
   759             RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() KErrNone"));
   765             RDEBUG( "KErrNone", KErrNone );
   760 #endif
       
   761             // code approved 
       
   762             CSecuritySettings::ShowResultNoteL(R_CONFIRMATION_NOTE,
   766             CSecuritySettings::ShowResultNoteL(R_CONFIRMATION_NOTE,
   763                     CAknNoteDialog::EConfirmationTone);
   767                     CAknNoteDialog::EConfirmationTone);
   764             RDEBUG("R_CONFIRMATION_NOTE", R_CONFIRMATION_NOTE);
   768             RDEBUG("R_CONFIRMATION_NOTE", R_CONFIRMATION_NOTE);
   765             if (FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw))
   769             if (FeatureManager::FeatureSupported(KFeatureIdSapTerminalControlFw))
   766                 {
   770                 {
   779                                 SCP_TARM_ADMIN_FLAG_UID, tarmFlag);
   783                                 SCP_TARM_ADMIN_FLAG_UID, tarmFlag);
   780                         }
   784                         }
   781 
   785 
   782                     if (tRet != KErrNone)
   786                     if (tRet != KErrNone)
   783                         {
   787                         {
   784 #if defined(_DEBUG)
   788                         RDEBUG( "FAILED to unset TARM Admin Flag tRet=", tRet );
   785                         RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL():\
       
   786                             FAILED to unset TARM Admin Flag"));
       
   787 #endif
       
   788                         }
   789                         }
   789                     }
   790                     }
   790                 if (!FeatureManager::FeatureSupported(
   791                 if (!FeatureManager::FeatureSupported(
   791                         KFeatureIdSapDeviceLockEnhancements))
   792                         KFeatureIdSapDeviceLockEnhancements))
   792                     {
   793                     {
   793                     RDEBUG("KFeatureIdSapDeviceLockEnhancements",
   794                     RDEBUG("KFeatureIdSapDeviceLockEnhancements",
   794                             KFeatureIdSapDeviceLockEnhancements);
   795                             KFeatureIdSapDeviceLockEnhancements);
   795                     RSCPClient scpClient;
   796                     RSCPClient scpClient;
   796                     RDEBUG("scpClient.Connect", 0);
   797                     RDEBUG("scpClient.Connect", 0);
   797                     User::LeaveIfError(scpClient.Connect());
   798                     TInt tRet = scpClient.Connect();
       
   799                     RDEBUG("tRet", tRet);
       
   800                     User::LeaveIfError(tRet);
   798                     RDEBUG("scpClient.Connect", 1);
   801                     RDEBUG("scpClient.Connect", 1);
   799                     CleanupClosePushL(scpClient);
   802                     CleanupClosePushL(scpClient);
   800                     TSCPSecCode newCode;
   803                     TSCPSecCode newCode;
   801                     newCode.Copy(iSecUi_password);
   804                     newCode.Copy(iSecUi_password);
   802                     scpClient.StoreCode(newCode);
   805                     scpClient.StoreCode(newCode);
   806 
   809 
   807                 }
   810                 }
   808             RDEBUG("StartUp", StartUp);
   811             RDEBUG("StartUp", StartUp);
   809             if (StartUp)
   812             if (StartUp)
   810                 {
   813                 {
   811 #if defined(_DEBUG)
       
   812                 RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL()KErrNone: Startup; get autolock period."));
       
   813 #endif
       
   814 
       
   815                 // get autolock period from Central Repository.
   814                 // get autolock period from Central Repository.
   816                 CRepository* repository = CRepository::NewL(
   815                 CRepository* repository = CRepository::NewL(
   817                         KCRUidSecuritySettings);
   816                         KCRUidSecuritySettings);
   818                 TInt period = 0;
   817                 TInt period = 0;
   819                 TInt res = repository->Get(KSettingsAutoLockTime, period);
   818                 TInt res = repository->Get(KSettingsAutoLockTime, period);
   820                 delete repository;
   819                 delete repository;
       
   820                 RDEBUG("res", res);
       
   821                 RDEBUG("period", period);
   821 
   822 
   822                 _LIT_SECURITY_POLICY_PASS( KReadPolicy);
   823                 _LIT_SECURITY_POLICY_PASS( KReadPolicy);
   823                 _LIT_SECURITY_POLICY_C1(KWritePolicy,
   824                 _LIT_SECURITY_POLICY_C1(KWritePolicy,
   824                         ECapabilityWriteDeviceData);
   825                         ECapabilityWriteDeviceData);
   825                 RProperty::Define(KPSUidCoreApplicationUIs,
   826                 RProperty::Define(KPSUidCoreApplicationUIs,
   826                         KCoreAppUIsAutolockStatus, RProperty::EInt,
   827                         KCoreAppUIsAutolockStatus, RProperty::EInt,
   827                         KReadPolicy, KWritePolicy);
   828                         KReadPolicy, KWritePolicy);
   828                 RProperty::Set(KPSUidCoreApplicationUIs,
   829                 RProperty::Set(KPSUidCoreApplicationUIs,
   829                         KCoreAppUIsAutolockStatus, EAutolockOff);
   830                         KCoreAppUIsAutolockStatus, EAutolockOff);
   830 #if defined(_DEBUG)
   831                 RDEBUG("KCoreAppUIsAutolockStatus", KCoreAppUIsAutolockStatus);
   831                 RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() EAutolockOff"));
       
   832 #endif                                                              
       
   833 
   832 
   834                 if (res == KErrNone)
   833                 if (res == KErrNone)
   835                     {
   834                     {
   836                     // disable autolock in Domestic OS side too if autolock period is 0.
   835                     // disable autolock in Domestic OS side too if autolock period is 0.
   837                     if (period == 0)
   836                     if (period == 0)
   838                         {
   837                         {
   839 #ifdef RD_REMOTELOCK
   838                         // Don't disable the domestic OS device lock
   840                         // If remote lock is enabled, don't disable the domestic OS device lock
       
   841                         // since that would render the RemoteLock useless.
   839                         // since that would render the RemoteLock useless.
   842 
   840 
   843                         TBool remoteLockStatus( EFalse );
   841                         TBool remoteLockStatus( EFalse );
   844                         CRemoteLockSettings* remoteLockSettings = CRemoteLockSettings::NewL();
   842                         CRemoteLockSettings* remoteLockSettings = CRemoteLockSettings::NewL();
   845 
   843 
   846                         if ( remoteLockSettings->GetEnabled( remoteLockStatus ) )
   844                         if ( remoteLockSettings->GetEnabled( remoteLockStatus ) )
   847                             {
   845                             {
   848                             if ( !remoteLockStatus )
   846                             if ( !remoteLockStatus )
   849                                 {
   847                                 {
   850                                 // Remote lock is disabled
   848                                 // Remote lock is disabled
   851 #ifdef _DEBUG
   849                                 RDEBUG("Autolock and RemoteLock are disabled -> disable DOS device lock", 0);
   852                                 RDebug::Print( _L( "(SecUi)CSecurityHandler::PassPhraseRequiredL() - Autolock and RemoteLock are disabled -> disable DOS device lock" ) );
       
   853 #endif // _DEBUG
       
   854                                 // Disable DOS device lock setting
   850                                 // Disable DOS device lock setting
   855                                 RDEBUG( "iCustomPhone.DisablePhoneLock", 0 );
   851                                 RDEBUG( "iCustomPhone.DisablePhoneLock", 0 );
   856                                 wait = CWait::NewL();
   852                                 wait = CWait::NewL();
   857                                 iCustomPhone.DisablePhoneLock(wait->iStatus,iSecUi_password);
   853                                 iCustomPhone.DisablePhoneLock(wait->iStatus,iSecUi_password);
   858                                 wait->WaitForRequestL();
   854                                 RDEBUG( "WaitForRequestL", 0 );
   859                                 RDEBUG( "iCustomPhone.DisablePhoneLock", 1 );
   855                                 status = wait->WaitForRequestL();
       
   856                                 RDEBUG( "WaitForRequestL", status );
   860                                 delete wait;
   857                                 delete wait;
   861                                 }
   858                                 }
   862                             }
   859                             }
   863                         else
   860                         else
   864                             {
   861                             {
   865                             // Failed to get remote lock status
   862                             // Failed to get remote lock status
   866 #ifdef _DEBUG
   863                             RDEBUG( "Autolock is disabled, but failed to get RemoteLock status, so do nothing", 0 );
   867                             RDebug::Print( _L( "(SecUi)CSecurityHandler::PassPhraseRequiredL() - Autolock is disabled, but failed to get RemoteLock status, so do nothing." ) );
       
   868 #endif // _DEBUG
       
   869                             }
   864                             }
   870 
   865 
   871                         delete remoteLockSettings;
   866                         delete remoteLockSettings;
   872                         remoteLockSettings = NULL;
   867                         remoteLockSettings = NULL;
   873 
   868 
   874 #else // not defined RD_REMOTELOCK
       
   875                         RDEBUG("iCustomPhone.DisablePhoneLock", 0);
       
   876                         wait = CWait::NewL();
       
   877                         iCustomPhone.DisablePhoneLock(wait->iStatus,
       
   878                                 iSecUi_password);
       
   879                         wait->WaitForRequestL();
       
   880                         RDEBUG("iCustomPhone.DisablePhoneLock", 1);
       
   881                         delete wait;
       
   882 #endif // RD_REMOTELOCK
       
   883                         }
   869                         }
   884                     }
   870                     }
   885                 else // error getting repository
   871                 else // error getting repository
   886                     {
   872                     {
   887                     RDEBUG("error getting repository", 0);
   873                     RDEBUG("error getting repository", 0);
   888 #ifdef RD_REMOTELOCK
   874                     // Don't disable the domestic OS device lock
   889                     // If remote lock is enabled, don't disable the domestic OS device lock
       
   890                     // since that would render the RemoteLock useless.
   875                     // since that would render the RemoteLock useless.
   891 
   876 
   892                     TBool remoteLockStatus( EFalse );
   877                     TBool remoteLockStatus( EFalse );
   893                     CRemoteLockSettings* remoteLockSettings = CRemoteLockSettings::NewL();
   878                     CRemoteLockSettings* remoteLockSettings = CRemoteLockSettings::NewL();
   894 
   879 
   898                             {
   883                             {
   899                             // Remote lock is disabled
   884                             // Remote lock is disabled
   900                             RDEBUG( "iCustomPhone.DisablePhoneLock", 0 );
   885                             RDEBUG( "iCustomPhone.DisablePhoneLock", 0 );
   901                             wait = CWait::NewL();
   886                             wait = CWait::NewL();
   902                             iCustomPhone.DisablePhoneLock(wait->iStatus,iSecUi_password);
   887                             iCustomPhone.DisablePhoneLock(wait->iStatus,iSecUi_password);
   903                             wait->WaitForRequestL();
   888 		                        RDEBUG( "WaitForRequestL", 0 );
   904                             RDEBUG( "iCustomPhone.DisablePhoneLock", 1 );
   889 		                        status = wait->WaitForRequestL();
       
   890 		                        RDEBUG( "WaitForRequestL status", status );
   905                             delete wait;
   891                             delete wait;
   906                             }
   892                             }
   907                         }
   893                         }
   908                     else
   894                     else
   909                         {
   895                         {
   910                         // Failed to get remote lock status
   896                         // Failed to get remote lock status
   911 #ifdef _DEBUG
   897                         RDEBUG( "Failed to get Autolock period and RemoteLock status, so do nothing", 0 );
   912                         RDebug::Print( _L( "(SecUi)CSecurityHandler::PassPhraseRequiredL() - Failed to get Autolock period and RemoteLock status, so do nothing." ) );
       
   913 #endif // _DEBUG
       
   914                         }
   898                         }
   915 
   899 
   916                     delete remoteLockSettings;
   900                     delete remoteLockSettings;
   917                     remoteLockSettings = NULL;
   901                     remoteLockSettings = NULL;
   918 
   902 
   919 #else // not defined RD_REMOTELOCK
       
   920                     // could not get the current autolock time... disable autolock in Domestic OS side.
       
   921                     RDEBUG("iCustomPhone.DisablePhoneLock", 0);
       
   922                     wait = CWait::NewL();
       
   923                     iCustomPhone.DisablePhoneLock(wait->iStatus,
       
   924                             iSecUi_password);
       
   925                     wait->WaitForRequestL();
       
   926                     RDEBUG("iCustomPhone.DisablePhoneLock", 1);
       
   927                     delete wait;
       
   928 
       
   929 #endif // RD_REMOTELOCK
       
   930                     }
   903                     }
   931 
   904 
   932                 } // no Startup
   905                 } // no Startup
   933 
   906 
   934             break;
   907             break;
   935         case KErrGsmSSPasswordAttemptsViolation:
   908         case KErrGsmSSPasswordAttemptsViolation:
   936         case KErrLocked:
   909         case KErrLocked:
   937             // security code blocked!
   910             // security code blocked!
   938 #if defined(_DEBUG)
   911 						RDEBUG("KErrLocked", KErrLocked);
   939             RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() ErrGsmSSPasswordAttemptsViolation"));
       
   940 #endif
       
   941             CSecuritySettings::ShowResultNoteL(R_SEC_BLOCKED,
   912             CSecuritySettings::ShowResultNoteL(R_SEC_BLOCKED,
   942                     CAknNoteDialog::EErrorTone);
   913                     CAknNoteDialog::EErrorTone);
   943             break;
   914             break;
   944         case KErrGsm0707IncorrectPassword:
   915         case KErrGsm0707IncorrectPassword:
   945         case KErrAccessDenied:
   916         case KErrAccessDenied:
   946             RDEBUG("KErrAccessDenied", KErrAccessDenied);
   917             RDEBUG("KErrAccessDenied", KErrAccessDenied);
   947             // TODO should this try again? It seems that it's not asked again.
   918             // The Settings caller might retry
   948 #if defined(_DEBUG)
       
   949             RDebug::Print(_L("(SECUI)CSecurityHandler::PassPhraseRequiredL() KErrGsm0707IncorrectPassword"));
       
   950 #endif
       
   951             CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
   919             CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
   952                     CAknNoteDialog::EErrorTone);
   920                     CAknNoteDialog::EErrorTone);
   953             break;
   921             break;
   954         default:
   922         default:
   955             RDEBUG("default", status);
   923             RDEBUG("default", status);
   956             CSecuritySettings::ShowErrorNoteL(status);
   924             CSecuritySettings::ShowErrorNoteL(status);
   957             // TODO should this try again? It seems that it's not asked again.
   925             // The Settings caller might retry
   958             break;
   926             break;
   959         }
   927         }
   960     RDEBUG("returnValue", returnValue);
   928     RDEBUG("returnValue", returnValue);
   961     return returnValue;
   929     return returnValue;
   962     }
   930     }
   997     if (!StartUp)
   965     if (!StartUp)
   998         {
   966         {
   999         // read a flag to see whether the query is SecUi originated. For example, from CSecuritySettings::ChangePinRequestParamsL
   967         // read a flag to see whether the query is SecUi originated. For example, from CSecuritySettings::ChangePinRequestParamsL
  1000         err = RProperty::Get(KPSUidSecurityUIs,
   968         err = RProperty::Get(KPSUidSecurityUIs,
  1001                 KSecurityUIsSecUIOriginatedQuery, secUiOriginatedQuery);
   969                 KSecurityUIsSecUIOriginatedQuery, secUiOriginatedQuery);
  1002 
       
  1003         if (err != KErrNone)
   970         if (err != KErrNone)
  1004             {
   971             {
  1005 #if defined(_DEBUG)
   972 						RDEBUG("FAILED to get the SECUI query Flag err", err);
  1006             RDebug::Print(_L("(SECUI)CSecurityHandler::Pin1RequiredL():\
   973             }
  1007             FAILED to get the SECUI query Flag: %d"), err);
   974         }
  1008 #endif
   975     RDEBUG("err", err);
  1009             }
       
  1010         else
       
  1011             {
       
  1012 #if defined(_DEBUG)
       
  1013             RDebug::Print(_L("(SECUI)CSecurityHandler::Pin1RequiredL():\
       
  1014                     SECUI query Flag: %d"), secUiOriginatedQuery);
       
  1015 #endif 
       
  1016             }
       
  1017         }
       
  1018 #if defined(_DEBUG)
       
  1019     RDebug::Print(_L("CSecurityHandler::Pin1RequiredL() Execute dlg"));
       
  1020 #endif
       
  1021 
       
  1022     RDEBUG("StartUp", StartUp);
       
  1023     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
   976     RDEBUG("secUiOriginatedQuery", secUiOriginatedQuery);
  1024     RDEBUG("ESecurityUIsSecUIOriginated", ESecurityUIsSecUIOriginated);
   977     RDEBUG("ESecurityUIsSecUIOriginated", ESecurityUIsSecUIOriginated);
  1025     RDEBUG("err", err);
       
  1026     if (StartUp || (secUiOriginatedQuery != ESecurityUIsSecUIOriginated)
   978     if (StartUp || (secUiOriginatedQuery != ESecurityUIsSecUIOriginated)
  1027             || (err != KErrNone))
   979             || (err != KErrNone))
  1028         {
   980         {
  1029         RDEBUG("0", 0);
   981         RDEBUG("0", 0);
  1030         lCancelSupported = ESecUiCancelNotSupported;
   982         lCancelSupported = ESecUiCancelNotSupported;
  1043 #ifdef __WINS__
   995 #ifdef __WINS__
  1044     RDEBUG( "emulator can't read PIN attempts", res );
   996     RDEBUG( "emulator can't read PIN attempts", res );
  1045     res=KErrNone;
   997     res=KErrNone;
  1046     codeInfo.iRemainingEntryAttempts=3;
   998     codeInfo.iRemainingEntryAttempts=3;
  1047 #endif
   999 #endif
  1048 
       
  1049     User::LeaveIfError(res);
  1000     User::LeaveIfError(res);
  1050 
  1001 
  1051     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1002     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1052             codeInfo.iRemainingEntryAttempts);
  1003             codeInfo.iRemainingEntryAttempts);
  1053     if (codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
  1004     if (codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
  1055 
  1006 
  1056     /* request PIN using QT */
  1007     /* request PIN using QT */
  1057     CSecQueryUi *iSecQueryUi;
  1008     CSecQueryUi *iSecQueryUi;
  1058     RDEBUG("CSecQueryUi", 0);
  1009     RDEBUG("CSecQueryUi", 0);
  1059     iSecQueryUi = CSecQueryUi::NewL();
  1010     iSecQueryUi = CSecQueryUi::NewL();
       
  1011 		iQueryCanceled = EFalse;
  1060     RDEBUG("SecQueryDialog", 1);
  1012     RDEBUG("SecQueryDialog", 1);
  1061     // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1013     // ESecUiCodeEtelReqest/ESecUiNone might be useful
  1062     // TODO also support Emergency
       
  1063     lAlphaSupported = ESecUiAlphaNotSupported;
  1014     lAlphaSupported = ESecUiAlphaNotSupported;
  1064     TBuf<0x100> title;
  1015     TBuf<0x100> title;
  1065     title.Zero();
  1016     title.Zero();
  1066     title.Append(_L("Pin1RequiredL"));
  1017     title.Append(_L("Pin1RequiredL"));
  1067     title.Append(_L("#"));
  1018     title.Append(_L("#"));
  1071     RDEBUG("amode", amode);
  1022     RDEBUG("amode", amode);
  1072     queryAccepted = iSecQueryUi->SecQueryDialog(title, iSecUi_password,
  1023     queryAccepted = iSecQueryUi->SecQueryDialog(title, iSecUi_password,
  1073             SEC_C_PIN_CODE_MIN_LENGTH, SEC_C_PIN_CODE_MAX_LENGTH, amode);
  1024             SEC_C_PIN_CODE_MIN_LENGTH, SEC_C_PIN_CODE_MAX_LENGTH, amode);
  1074     RDEBUG("iSecUi_password", 0);
  1025     RDEBUG("iSecUi_password", 0);
  1075     RDebug::Print(iSecUi_password);
  1026     RDebug::Print(iSecUi_password);
       
  1027     iQueryCanceled = ETrue;
  1076     delete iSecQueryUi;
  1028     delete iSecQueryUi;
  1077     RDEBUG("queryAccepted", queryAccepted);
  1029     RDEBUG("queryAccepted", queryAccepted);
  1078     // TODO handle emergency
       
  1079     /* end request PIN using QT */
  1030     /* end request PIN using QT */
  1080 
  1031 
  1081     if (queryAccepted == KErrAbort) // emergency call
  1032     if (queryAccepted == KErrAbort) // emergency call
  1082         {
  1033         {
  1083 #if defined(_DEBUG)
  1034 				RDEBUG("queryAccepted", queryAccepted);
  1084         RDebug::Print(_L("CSecurityHandler::Pin1RequiredL() R_PIN_REQUEST_QUERY CANCEL!"));
       
  1085 #endif
       
  1086         CleanupStack::PopAndDestroy(wait); // this is needed
  1035         CleanupStack::PopAndDestroy(wait); // this is needed
  1087         return KErrCancel;
  1036         return KErrCancel;
  1088         }
  1037         }
  1089     if (lCancelSupported && (queryAccepted == KErrCancel))
  1038     if (lCancelSupported && (queryAccepted == KErrCancel))
  1090         {
  1039         {
  1108 
  1057 
  1109     TInt returnValue = res;
  1058     TInt returnValue = res;
  1110     switch (res)
  1059     switch (res)
  1111         {
  1060         {
  1112         case KErrNone:
  1061         case KErrNone:
  1113             // code approved 
  1062             // code approved
  1114 #if defined(_DEBUG)
  1063             RDEBUG("code approved", res);
  1115             RDebug::Print(_L("CSecurityHandler::Pin1RequiredL()code approved "));
  1064             if(lCancelSupported == ESecUiCancelNotSupported)
  1116 #endif
  1065             	{	// OK note is not displayed in boot-up, to make things faster
  1117             CSecuritySettings::ShowResultNoteL(R_CONFIRMATION_NOTE,
  1066 	            CSecuritySettings::ShowResultNoteL(R_CONFIRMATION_NOTE,
  1118                     CAknNoteDialog::EConfirmationTone);
  1067                     CAknNoteDialog::EConfirmationTone);
       
  1068               }
  1119             break;
  1069             break;
  1120         case KErrGsm0707IncorrectPassword:
  1070         case KErrGsm0707IncorrectPassword:
  1121         case KErrAccessDenied:
  1071         case KErrAccessDenied:
  1122             // code was entered erroneously
  1072             // code was entered erroneously
  1123             CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
  1073             CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
  1128                 }
  1078                 }
  1129             break;
  1079             break;
  1130         case KErrGsmSSPasswordAttemptsViolation:
  1080         case KErrGsmSSPasswordAttemptsViolation:
  1131         case KErrLocked:
  1081         case KErrLocked:
  1132             // code blocked; show error note and terminate.
  1082             // code blocked; show error note and terminate.
  1133             // TODO what if not during Startup? Probably it's Ok since the SIM would had also failed at StartUp
  1083             // what if not during Startup? Probably it's Ok since the SIM would had also failed at StartUp
  1134             if (StartUp)
  1084             if (StartUp)
  1135                 CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
  1085                 CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
  1136                         CAknNoteDialog::EErrorTone);
  1086                         CAknNoteDialog::EErrorTone);
  1137             break;
  1087             break;
  1138         case KErrGsm0707SimWrong:
  1088         case KErrGsm0707SimWrong:
  1139             // sim lock active
  1089             // sim lock active
  1140             // TODO no error? This is strange
  1090             // no error? This is strange
  1141             break;
  1091             break;
  1142         default:
  1092         default:
  1143             CSecuritySettings::ShowErrorNoteL(res);
  1093             CSecuritySettings::ShowErrorNoteL(res);
  1144             if (StartUp)
  1094             if (StartUp)
  1145                 {
  1095                 {
  1151     }
  1101     }
  1152 //
  1102 //
  1153 // ----------------------------------------------------------
  1103 // ----------------------------------------------------------
  1154 // CSecurityHandler::Puk1Required()
  1104 // CSecurityHandler::Puk1Required()
  1155 // Handles Puk1Required event
  1105 // Handles Puk1Required event
       
  1106 // First asks the PUK1, then verifies, then the newPIN + re-type , and then writes . This is odd, but the API needs the PUK and newPIN in same step.
       
  1107 // Afterwards, the PIN1 might be asked (because the initial program still needs it)
  1156 // ----------------------------------------------------------
  1108 // ----------------------------------------------------------
  1157 // qtdone
  1109 // qtdone
  1158 TInt CSecurityHandler::Puk1RequiredL()
  1110 TInt CSecurityHandler::Puk1RequiredL()
  1159     {
  1111     {
  1160     /*****************************************************
  1112     /*****************************************************
  1161      *    Series 60 Customer / ETel
  1113      *    Series 60 Customer / ETel
  1162      *    Series 60  ETel API
  1114      *    Series 60  ETel API
  1163      *****************************************************/
  1115      *****************************************************/
  1164 #if defined(_DEBUG)
  1116 		RDEBUG("0", 0);
  1165     RDebug::Print(_L("(SECUI)CSecurityHandler::Puk1RequiredL()"));
       
  1166 #endif            
       
  1167     TInt queryAccepted = KErrCancel;
  1117     TInt queryAccepted = KErrCancel;
  1168     RMobilePhone::TMobilePassword iSecUi_password;
  1118     RMobilePhone::TMobilePassword puk1_password;
  1169     RMobilePhone::TMobilePassword aNewPassword;
  1119     RMobilePhone::TMobilePassword aNewPinPassword;
  1170     RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
  1120     RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
  1171     RMobilePhone::TMobilePhoneSecurityCodeInfoV5Pckg codeInfoPkg(codeInfo);
  1121     RMobilePhone::TMobilePhoneSecurityCodeInfoV5Pckg codeInfoPkg(codeInfo);
  1172     RMobilePhone::TMobilePhoneSecurityCode blockCodeType;
  1122     RMobilePhone::TMobilePhoneSecurityCode blockCodeType;
  1173     blockCodeType = RMobilePhone::ESecurityCodePuk1;
  1123     blockCodeType = RMobilePhone::ESecurityCodePuk1;
  1174     CWait* wait = CWait::NewL();
  1124     CWait* wait = CWait::NewL();
  1175     CleanupStack::PushL(wait);
  1125     CleanupStack::PushL(wait);
  1176 
  1126 
  1177     TBool StartUp(ETrue);
  1127     TBool StartUp(ETrue);
  1178     StartUp = iStartup;
  1128     StartUp = iStartup;
  1179 
  1129 
  1180     TInt res(KErrNone);
  1130     TInt res(KErrCancel);	// for the first try
  1181     wait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
  1131     wait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
  1182 
  1132 
  1183     TInt thisTry = 0;
  1133     TInt thisTry = 0;
  1184 
  1134 
  1185     // If there was a problem (as there might be in case we're dropping off SIM Access Profile); try again a couple of times.
  1135     // If there was a problem (as there might be in case we're dropping off SIM Access Profile); try again a couple of times.
  1191         iPhone.GetSecurityCodeInfo(wait->iStatus, blockCodeType, codeInfoPkg);
  1141         iPhone.GetSecurityCodeInfo(wait->iStatus, blockCodeType, codeInfoPkg);
  1192         RDEBUG("WaitForRequestL", 0);
  1142         RDEBUG("WaitForRequestL", 0);
  1193         res = wait->WaitForRequestL();
  1143         res = wait->WaitForRequestL();
  1194         RDEBUG("WaitForRequestL res", res);
  1144         RDEBUG("WaitForRequestL res", res);
  1195         }
  1145         }
  1196 #if defined(_DEBUG)
  1146 		RDEBUG("res", res);
  1197     RDebug::Print(_L("(SECUI)CSecurityHandler::Puk1RequiredL(): Get Code info result: %d"), res);
  1147     // If there's still an error we're doomed. Bail out.
  1198 #endif
       
  1199     //If there's still an error we're doomed. Bail out.
       
  1200     User::LeaveIfError(res);
  1148     User::LeaveIfError(res);
  1201 
       
  1202 #if defined(_DEBUG)
       
  1203     RDebug::Print(_L("(SECUI)CSecurityHandler::Puk1RequiredL(): Show last note"));
       
  1204 #endif
       
  1205 
  1149 
  1206     RDEBUG("StartUp", StartUp);
  1150     RDEBUG("StartUp", StartUp);
  1207     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1151     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1208             codeInfo.iRemainingEntryAttempts);
  1152             codeInfo.iRemainingEntryAttempts);
  1209     //show the last "Code Error" note of PIN verify result here so it won't be left under the PUK1 dialog
  1153   	TInt attempts(codeInfo.iRemainingEntryAttempts);
  1210     if (!StartUp && (codeInfo.iRemainingEntryAttempts
  1154   	RDEBUG( "attempts", attempts );
       
  1155     // show the last "Code Error" note of PIN verify result here so it won't be left under the PUK1 dialog
       
  1156     if (!StartUp && (attempts
  1211             == KMaxNumberOfPUKAttempts))
  1157             == KMaxNumberOfPUKAttempts))
  1212         CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
  1158         CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
  1213                 CAknNoteDialog::EErrorTone);
  1159                 CAknNoteDialog::EErrorTone);
  1214 
  1160 
  1215     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1161     if (attempts == KMaxNumberOfPINAttempts)
  1216             codeInfo.iRemainingEntryAttempts);
  1162         attempts = -1;
  1217     if (codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
  1163 
  1218         codeInfo.iRemainingEntryAttempts = -1;
       
  1219 
       
  1220     // ask PUK code
       
  1221     /* request PIN using QT */
       
  1222     CSecQueryUi *iSecQueryUi;
  1164     CSecQueryUi *iSecQueryUi;
  1223     RDEBUG("CSecQueryUi", 0);
  1165     RDEBUG("CSecQueryUi", 0);
  1224     iSecQueryUi = CSecQueryUi::NewL();
  1166     iSecQueryUi = CSecQueryUi::NewL();
       
  1167 		iQueryCanceled = EFalse;
  1225     RDEBUG("SecQueryDialog", 1);
  1168     RDEBUG("SecQueryDialog", 1);
  1226     // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1169     // ESecUiCodeEtelReqest/ESecUiNone might be useful
  1227     // TODO also support Emergency
       
  1228     TBuf<0x100> title;
  1170     TBuf<0x100> title;
  1229     title.Zero();
  1171     title.Zero();
  1230     title.Append(_L("Puk1RequiredL"));
  1172     title.Append(_L("Puk1RequiredL"));
  1231     title.Append(_L("#"));
  1173     title.Append(_L("#"));
  1232     title.AppendNum(codeInfo.iRemainingEntryAttempts);
  1174     title.AppendNum(attempts);
  1233     queryAccepted = iSecQueryUi->SecQueryDialog(title, iSecUi_password,
  1175     TInt lSecUiCancelSupported = ESecUiCancelSupported | ESecUiEmergencyNotSupported;
       
  1176     if(StartUp)		// how to know whether PUK comes from failing at Starter, or failing at any other PIN (i.e. changing PIN, or changing PIN-request) ???
       
  1177     	lSecUiCancelSupported = ESecUiCancelNotSupported | ESecUiEmergencySupported;
       
  1178     queryAccepted = iSecQueryUi->SecQueryDialog(title, puk1_password,
  1234             SEC_C_PUK_CODE_MIN_LENGTH, SEC_C_PUK_CODE_MAX_LENGTH,
  1179             SEC_C_PUK_CODE_MIN_LENGTH, SEC_C_PUK_CODE_MAX_LENGTH,
  1235             ESecUiSecretNotSupported | ESecUiAlphaNotSupported
  1180             ESecUiSecretNotSupported | ESecUiAlphaNotSupported
  1236                     | ESecUiCancelSupported | ESecUiPukRequired);
  1181                     | lSecUiCancelSupported | ESecUiPukRequired);
  1237     RDEBUG("iSecUi_password", 0);
  1182     RDEBUG("puk1_password", 0);
  1238     RDebug::Print(iSecUi_password);
  1183     RDebug::Print(puk1_password);
       
  1184     iQueryCanceled = ETrue;
  1239     delete iSecQueryUi;
  1185     delete iSecQueryUi;
  1240     RDEBUG("queryAccepted", queryAccepted);
  1186     RDEBUG("queryAccepted", queryAccepted);
  1241 
  1187 
  1242     if ((queryAccepted == KErrAbort) || (queryAccepted == KErrCancel))
  1188     if ((queryAccepted == KErrAbort) || (queryAccepted == KErrCancel))
  1243         {
  1189         {
  1244         CleanupStack::PopAndDestroy(wait); // TODO this is needed ???
  1190         CleanupStack::PopAndDestroy(wait); // this is needed
  1245         return KErrCancel;
  1191         return KErrCancel;
  1246         }
  1192         }
  1247 
  1193 
  1248         {
       
  1249         // new pin code query
       
  1250         CSecQueryUi * iSecQueryUi;
       
  1251         RDEBUG("CSecQueryUi", 0);
       
  1252         iSecQueryUi = CSecQueryUi::NewL();
       
  1253         RDEBUG("SecQueryDialog", 1);
       
  1254         // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
       
  1255         // TODO also support Emergency
       
  1256 
       
  1257         queryAccepted = iSecQueryUi->SecQueryDialog(
       
  1258                 _L("Puk1-New|Puk1-Verif"), aNewPassword,
       
  1259                 SEC_C_PUK_CODE_MIN_LENGTH, SEC_C_PUK_CODE_MAX_LENGTH,
       
  1260                 ESecUiAlphaNotSupported | ESecUiCancelSupported
       
  1261                         | ESecUiPukRequired);
       
  1262         RDEBUG("aNewPassword", 0);
       
  1263         RDebug::Print(aNewPassword);
       
  1264         delete iSecQueryUi;
       
  1265         RDEBUG("queryAccepted", queryAccepted);
       
  1266         }
       
  1267 
       
  1268     if ((queryAccepted == KErrAbort) || (queryAccepted == KErrCancel))
       
  1269         {
       
  1270         CleanupStack::PopAndDestroy(wait);
       
  1271         return KErrCancel;
       
  1272         }
       
  1273 
       
  1274     // send code
  1194     // send code
       
  1195     // first we verify the puk. For this, we reset the PIN to the same as the PUK
       
  1196     // Hopefully this will never fail in the case "new PIN too long"
  1275     RDEBUG("VerifySecurityCode", 0);
  1197     RDEBUG("VerifySecurityCode", 0);
  1276     iPhone.VerifySecurityCode(wait->iStatus, blockCodeType, aNewPassword,
  1198     iPhone.VerifySecurityCode(wait->iStatus, blockCodeType, puk1_password, puk1_password);
  1277             iSecUi_password);
       
  1278     RDEBUG("WaitForRequestL", 0);
  1199     RDEBUG("WaitForRequestL", 0);
  1279     res = wait->WaitForRequestL();
  1200     res = wait->WaitForRequestL();
  1280     RDEBUG("WaitForRequestL res", res);
  1201     RDEBUG("WaitForRequestL res", res);
  1281     CleanupStack::PopAndDestroy(wait);
  1202 		CleanupStack::PopAndDestroy(wait);
  1282 
  1203 	
  1283     TInt returnValue = res;
  1204     TInt returnValue = res;
  1284     switch (res)
  1205     switch (res)
  1285         {
  1206         {
  1286         case KErrNone:
  1207         case KErrNone:
  1287             // code approved -> note
  1208             // code approved -> note . The process continue and new-pin is requested
  1288             CSecuritySettings::ShowResultNoteL(R_PIN_CODE_CHANGED_NOTE,
  1209             CSecuritySettings::ShowResultNoteL(res,
  1289                     CAknNoteDialog::EConfirmationTone);
  1210                     CAknNoteDialog::EConfirmationTone);
  1290             break;
  1211             break;
  1291         case KErrGsm0707IncorrectPassword:
  1212         case KErrGsm0707IncorrectPassword:
  1292         case KErrAccessDenied:
  1213         case KErrAccessDenied:
  1293             // wrong PUK code -> note -> ask PUK code again        
  1214             // wrong PUK code -> note -> ask PUK code again        
  1295                     CAknNoteDialog::EErrorTone);
  1216                     CAknNoteDialog::EErrorTone);
  1296             returnValue = Puk1RequiredL();
  1217             returnValue = Puk1RequiredL();
  1297             break;
  1218             break;
  1298         case KErrGsm0707SimWrong:
  1219         case KErrGsm0707SimWrong:
  1299             // sim lock active
  1220             // sim lock active
  1300             // TODO no message ?
  1221             // no message ?
  1301             break;
  1222             break;
  1302         case KErrGsmSSPasswordAttemptsViolation:
  1223         case KErrGsmSSPasswordAttemptsViolation:
  1303         case KErrLocked:
  1224         case KErrLocked:
  1304             // sim card rejected.
  1225             // sim card rejected.
  1305             break;
  1226             break;
  1307             CSecuritySettings::ShowErrorNoteL(res);
  1228             CSecuritySettings::ShowErrorNoteL(res);
  1308             returnValue = Puk1RequiredL();
  1229             returnValue = Puk1RequiredL();
  1309             break;
  1230             break;
  1310         }
  1231         }
  1311 
  1232 
       
  1233 		// Now the PUK1 is validated. It's time for asking the new PIN1
       
  1234 		RDEBUG("new wait", 0);
       
  1235 		wait = CWait::NewL();
       
  1236 		CleanupStack::PushL(wait);
       
  1237         {
       
  1238         // new-pin query
       
  1239         CSecQueryUi * iSecQueryUi;
       
  1240         RDEBUG("CSecQueryUi", 0);
       
  1241         iSecQueryUi = CSecQueryUi::NewL();
       
  1242 				iQueryCanceled = EFalse;
       
  1243         RDEBUG("SecQueryDialog", 1);
       
  1244 
       
  1245         queryAccepted = iSecQueryUi->SecQueryDialog(
       
  1246                 _L("PIN1-New|PIN1-Verif"), aNewPinPassword,
       
  1247                 SEC_C_PIN_CODE_MIN_LENGTH, SEC_C_PIN_CODE_MAX_LENGTH,
       
  1248                 ESecUiAlphaNotSupported | ESecUiCancelSupported
       
  1249                         | ESecUiPukRequired);
       
  1250         RDEBUG("aNewPinPassword", 0);
       
  1251         RDebug::Print(aNewPinPassword);
       
  1252         iQueryCanceled = ETrue;
       
  1253         delete iSecQueryUi;
       
  1254         RDEBUG("queryAccepted", queryAccepted);
       
  1255         }
       
  1256 
       
  1257     if ((queryAccepted == KErrAbort) || (queryAccepted == KErrCancel))
       
  1258         {
       
  1259         CleanupStack::PopAndDestroy(wait);
       
  1260         return KErrCancel;
       
  1261         }
       
  1262 
       
  1263     // send code again, now with the user pin
       
  1264     RDEBUG("VerifySecurityCode", 0);
       
  1265     iPhone.VerifySecurityCode(wait->iStatus, blockCodeType, aNewPinPassword,
       
  1266             puk1_password);
       
  1267     RDEBUG("WaitForRequestL", 0);
       
  1268     res = wait->WaitForRequestL();
       
  1269     RDEBUG("WaitForRequestL res", res);
       
  1270     CleanupStack::PopAndDestroy(wait);
       
  1271 
       
  1272     returnValue = res;
       
  1273     switch (res)
       
  1274         {
       
  1275         case KErrNone:
       
  1276             // code approved -> note
       
  1277             CSecuritySettings::ShowResultNoteL(R_PIN_CODE_CHANGED_NOTE,
       
  1278                     CAknNoteDialog::EConfirmationTone);
       
  1279             break;
       
  1280         case KErrGsm0707IncorrectPassword:
       
  1281         case KErrAccessDenied:
       
  1282             // wrong PUK code -> note -> ask PUK code again        
       
  1283             CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
       
  1284                     CAknNoteDialog::EErrorTone);
       
  1285             returnValue = Puk1RequiredL();
       
  1286             break;
       
  1287         case KErrGsm0707SimWrong:
       
  1288             // sim lock active
       
  1289             // no message ?
       
  1290             break;
       
  1291         case KErrGsmSSPasswordAttemptsViolation:
       
  1292         case KErrLocked:
       
  1293             // sim card rejected.
       
  1294             break;
       
  1295         default:
       
  1296             CSecuritySettings::ShowErrorNoteL(res);
       
  1297             returnValue = Puk1RequiredL();
       
  1298             break;
       
  1299         }
       
  1300 		RDEBUG("returnValue", returnValue);
  1312     return returnValue;
  1301     return returnValue;
  1313     }
  1302     }
  1314 //
  1303 //
  1315 // ----------------------------------------------------------
  1304 // ----------------------------------------------------------
  1316 // CSecurityHandler::Pin2Required()
  1305 // CSecurityHandler::Pin2Required()
  1322     /*****************************************************
  1311     /*****************************************************
  1323      *    Series 60 Customer / ETel
  1312      *    Series 60 Customer / ETel
  1324      *    Series 60  ETel API
  1313      *    Series 60  ETel API
  1325      *****************************************************/
  1314      *****************************************************/
  1326 
  1315 
  1327 #if defined(_DEBUG)
  1316 		RDEBUG("0", 0);
  1328     RDebug::Print(_L("(SECUI)CSecurityHandler::Pin2RequiredL() BEGIN"));
       
  1329 #endif
       
  1330     TInt queryAccepted = KErrCancel;
  1317     TInt queryAccepted = KErrCancel;
  1331     RMobilePhone::TMobilePassword iSecUi_password;
  1318     RMobilePhone::TMobilePassword iSecUi_password;
  1332     RMobilePhone::TMobilePassword required_fourth;
  1319     RMobilePhone::TMobilePassword required_fourth;
  1333     RMobilePhone::TMobilePhoneSecurityCode secCodeType(
  1320     RMobilePhone::TMobilePhoneSecurityCode secCodeType(
  1334             RMobilePhone::ESecurityCodePin2);
  1321             RMobilePhone::ESecurityCodePin2);
  1341     RDEBUG("GetSecurityCodeInfo", 0);
  1328     RDEBUG("GetSecurityCodeInfo", 0);
  1342     iPhone.GetSecurityCodeInfo(wait->iStatus, secCodeType, codeInfoPkg);
  1329     iPhone.GetSecurityCodeInfo(wait->iStatus, secCodeType, codeInfoPkg);
  1343     RDEBUG("WaitForRequestL", 0);
  1330     RDEBUG("WaitForRequestL", 0);
  1344     TInt ret = wait->WaitForRequestL();
  1331     TInt ret = wait->WaitForRequestL();
  1345     RDEBUG("WaitForRequestL ret", ret);
  1332     RDEBUG("WaitForRequestL ret", ret);
  1346 
       
  1347     User::LeaveIfError(ret);
  1333     User::LeaveIfError(ret);
  1348 
  1334 
  1349     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1335     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1350             codeInfo.iRemainingEntryAttempts);
  1336             codeInfo.iRemainingEntryAttempts);
  1351     if (codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts) // TODO this might be 10 ?
  1337     if (codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts)
  1352         codeInfo.iRemainingEntryAttempts = -1;
  1338         codeInfo.iRemainingEntryAttempts = -1;
  1353 
  1339 
  1354     /* request PIN using QT */
  1340     /* request PIN using QT */
  1355     CSecQueryUi *iSecQueryUi;
  1341     CSecQueryUi *iSecQueryUi;
  1356     RDEBUG("CSecQueryUi", 0);
  1342     RDEBUG("CSecQueryUi", 0);
  1357     iSecQueryUi = CSecQueryUi::NewL();
  1343     iSecQueryUi = CSecQueryUi::NewL();
       
  1344 		iQueryCanceled = EFalse;
  1358     RDEBUG("SecQueryDialog", 1);
  1345     RDEBUG("SecQueryDialog", 1);
  1359     // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful against KLastRemainingInputAttempt
  1346     // ESecUiCodeEtelReqest/ESecUiNone might be useful against KLastRemainingInputAttempt
  1360     // TODO also support Emergency
       
  1361 
  1347 
  1362     TBuf<0x100> title;
  1348     TBuf<0x100> title;
  1363     title.Zero();
  1349     title.Zero();
  1364     title.Append(_L("Pin2RequiredL"));
  1350     title.Append(_L("Pin2RequiredL"));
  1365     title.Append(_L("#"));
  1351     title.Append(_L("#"));
  1369             ESecUiSecretNotSupported | ESecUiAlphaNotSupported
  1355             ESecUiSecretNotSupported | ESecUiAlphaNotSupported
  1370                     | ESecUiCancelSupported | secCodeType);
  1356                     | ESecUiCancelSupported | secCodeType);
  1371     RDEBUG("iSecUi_password", 0);
  1357     RDEBUG("iSecUi_password", 0);
  1372     RDebug::Print(iSecUi_password);
  1358     RDebug::Print(iSecUi_password);
  1373     RDEBUG("queryAccepted", queryAccepted);
  1359     RDEBUG("queryAccepted", queryAccepted);
       
  1360     iQueryCanceled = ETrue;
  1374     delete iSecQueryUi;
  1361     delete iSecQueryUi;
  1375 
  1362 
  1376     // If failed or device became locked, any pending request should be cancelled.
  1363     // If failed or device became locked, any pending request should be cancelled.
  1377     if (queryAccepted != KErrNone)
  1364     if (queryAccepted != KErrNone)
  1378         {
  1365         {
  1409             break;
  1396             break;
  1410         default:
  1397         default:
  1411             CSecuritySettings::ShowErrorNoteL(status);
  1398             CSecuritySettings::ShowErrorNoteL(status);
  1412             break;
  1399             break;
  1413         }
  1400         }
  1414 #if defined(_DEBUG)
       
  1415     RDebug::Print(_L("(SECUI)CSecurityHandler::Pin2RequiredL(): END"));
       
  1416 #endif
       
  1417     }
  1401     }
  1418 //
  1402 //
  1419 // ----------------------------------------------------------
  1403 // ----------------------------------------------------------
  1420 // CSecurityHandler::Puk2Required()
  1404 // CSecurityHandler::Puk2Required()
  1421 // Handles Puk2Required event
  1405 // Handles Puk2Required event
  1425     {
  1409     {
  1426     /*****************************************************
  1410     /*****************************************************
  1427      *    Series 60 Customer / ETel
  1411      *    Series 60 Customer / ETel
  1428      *    Series 60  ETel API
  1412      *    Series 60  ETel API
  1429      *****************************************************/
  1413      *****************************************************/
       
  1414 		RDEBUG("0", 0);
  1430     TInt queryAccepted = KErrCancel;
  1415     TInt queryAccepted = KErrCancel;
  1431     RMobilePhone::TMobilePassword iSecUi_password;
  1416     RMobilePhone::TMobilePassword iSecUi_password;
  1432     RMobilePhone::TMobilePassword aNewPassword;
  1417     RMobilePhone::TMobilePassword aNewPassword;
  1433     RMobilePhone::TMobilePassword verifcationPassword;
  1418     RMobilePhone::TMobilePassword verifcationPassword;
  1434     RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
  1419     RMobilePhone::TMobilePhoneSecurityCodeInfoV5 codeInfo;
  1437     RMobilePhone::TMobilePhoneSecurityCode secCodeType =
  1422     RMobilePhone::TMobilePhoneSecurityCode secCodeType =
  1438             RMobilePhone::ESecurityCodePuk2;
  1423             RMobilePhone::ESecurityCodePuk2;
  1439     CWait* wait = CWait::NewL();
  1424     CWait* wait = CWait::NewL();
  1440     CleanupStack::PushL(wait);
  1425     CleanupStack::PushL(wait);
  1441 
  1426 
  1442 #if defined(_DEBUG)
       
  1443     RDebug::Print(_L("(SECUI)CSecurityHandler::Puk2RequiredL()"));
       
  1444 #endif
       
  1445     // ask PUK2
  1427     // ask PUK2
  1446 
  1428 
  1447     TInt ret(KErrNone);
  1429     TInt ret(KErrNone);
  1448     wait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
  1430     wait->SetRequestType(EMobilePhoneGetSecurityCodeInfo);
  1449     RDEBUG("GetSecurityCodeInfo", 0);
  1431     RDEBUG("GetSecurityCodeInfo", 0);
  1455 
  1437 
  1456     /* request PIN using QT */
  1438     /* request PIN using QT */
  1457     CSecQueryUi *iSecQueryUi;
  1439     CSecQueryUi *iSecQueryUi;
  1458     RDEBUG("CSecQueryUi", 0);
  1440     RDEBUG("CSecQueryUi", 0);
  1459     iSecQueryUi = CSecQueryUi::NewL();
  1441     iSecQueryUi = CSecQueryUi::NewL();
       
  1442 		iQueryCanceled = EFalse;
  1460     RDEBUG("SecQueryDialog", 1);
  1443     RDEBUG("SecQueryDialog", 1);
  1461     // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1444     // ESecUiCodeEtelReqest/ESecUiNone might be useful
  1462     // TODO also support Emergency
       
  1463 
  1445 
  1464     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1446     RDEBUG("codeInfo.iRemainingEntryAttempts",
  1465             codeInfo.iRemainingEntryAttempts);
  1447             codeInfo.iRemainingEntryAttempts);
  1466     if (codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts) // TODO this might be 10 ?
  1448     if (codeInfo.iRemainingEntryAttempts == KMaxNumberOfPINAttempts) // TODO this might be 10 ?
  1467         codeInfo.iRemainingEntryAttempts = -1;
  1449         codeInfo.iRemainingEntryAttempts = -1;
  1472     title.Append(_L("#"));
  1454     title.Append(_L("#"));
  1473     title.AppendNum(codeInfo.iRemainingEntryAttempts);
  1455     title.AppendNum(codeInfo.iRemainingEntryAttempts);
  1474     queryAccepted = iSecQueryUi->SecQueryDialog(title, iSecUi_password,
  1456     queryAccepted = iSecQueryUi->SecQueryDialog(title, iSecUi_password,
  1475             SEC_C_PUK2_CODE_MIN_LENGTH, SEC_C_PUK2_CODE_MAX_LENGTH,
  1457             SEC_C_PUK2_CODE_MIN_LENGTH, SEC_C_PUK2_CODE_MAX_LENGTH,
  1476             ESecUiSecretNotSupported | ESecUiAlphaNotSupported
  1458             ESecUiSecretNotSupported | ESecUiAlphaNotSupported
  1477                     | ESecUiCancelSupported | secCodeType /*aMode*/);
  1459                     | ESecUiCancelSupported | secCodeType );
  1478     RDEBUG("iSecUi_password", 0);
  1460     RDEBUG("iSecUi_password", 0);
  1479     RDebug::Print(iSecUi_password);
  1461     RDebug::Print(iSecUi_password);
       
  1462     iQueryCanceled = ETrue;
  1480     delete iSecQueryUi;
  1463     delete iSecQueryUi;
  1481     RDEBUG("queryAccepted", queryAccepted);
  1464     RDEBUG("queryAccepted", queryAccepted);
  1482 
  1465 
  1483     if (queryAccepted != KErrNone)
  1466     if (queryAccepted != KErrNone)
  1484         {
  1467         {
  1488         RDEBUG("AbortSecurityCode", 1);
  1471         RDEBUG("AbortSecurityCode", 1);
  1489         CleanupStack::PopAndDestroy(1); //wait
  1472         CleanupStack::PopAndDestroy(1); //wait
  1490         return;
  1473         return;
  1491         }
  1474         }
  1492 
  1475 
  1493         {
  1476     RDEBUG("VerifySecurityCode", 0);
  1494         // new pin code query
  1477     iPhone.VerifySecurityCode(wait->iStatus, secCodeType, iSecUi_password, iSecUi_password);
       
  1478     // this writes the newPIN2 with the value of PUK2. It's ok, since the user forgot it
       
  1479     RDEBUG("WaitForRequestL", 0);
       
  1480     TInt res = wait->WaitForRequestL();
       
  1481     RDEBUG("WaitForRequestL res", res);
       
  1482     CleanupStack::PopAndDestroy(wait);
       
  1483 
       
  1484     switch (res)
       
  1485         {
       
  1486         case KErrNone:
       
  1487             // code approved -> note
       
  1488             CSecuritySettings::ShowResultNoteL(res,
       
  1489                     CAknNoteDialog::EConfirmationTone);
       
  1490             break;
       
  1491         case KErrGsm0707IncorrectPassword:
       
  1492         case KErrAccessDenied:
       
  1493             // wrong PUK2 code -> note -> ask PUK2 code again        
       
  1494             CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
       
  1495                     CAknNoteDialog::EErrorTone);
       
  1496             Puk2RequiredL();
       
  1497             break;
       
  1498         case KErrGsmSSPasswordAttemptsViolation:
       
  1499         case KErrLocked:
       
  1500             // Pin2 features blocked permanently!
       
  1501             CSecuritySettings::ShowResultNoteL(R_PIN2_REJECTED,
       
  1502                     CAknNoteDialog::EConfirmationTone);
       
  1503             break;
       
  1504         default:
       
  1505             CSecuritySettings::ShowErrorNoteL(res);
       
  1506             Puk2RequiredL();
       
  1507             break;
       
  1508         }
       
  1509 
       
  1510 		// now the PUK2 is valid. Time to get the new PIN2
       
  1511 		wait = CWait::NewL();
       
  1512     CleanupStack::PushL(wait);
       
  1513     	  {
       
  1514         // new pin2 code query
  1495         CSecQueryUi * iSecQueryUi;
  1515         CSecQueryUi * iSecQueryUi;
  1496         RDEBUG("CSecQueryUi", 0);
  1516         RDEBUG("CSecQueryUi", 0);
  1497         iSecQueryUi = CSecQueryUi::NewL();
  1517         iSecQueryUi = CSecQueryUi::NewL();
  1498         // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1518 				iQueryCanceled = EFalse;
  1499         // TODO also support Emergency
  1519         // ESecUiCodeEtelReqest/ESecUiNone might be useful
  1500 
       
  1501         queryAccepted
  1520         queryAccepted
  1502                 = iSecQueryUi->SecQueryDialog(_L("Puk2-New|Puk2-Verif"),
  1521                 = iSecQueryUi->SecQueryDialog(_L("PIN2-New|PIN2-Verif"),
  1503                         aNewPassword, SEC_C_PUK2_CODE_MIN_LENGTH,
  1522                         aNewPassword, SEC_C_PIN2_CODE_MIN_LENGTH,
  1504                         SEC_C_PUK2_CODE_MAX_LENGTH, ESecUiAlphaNotSupported
  1523                         SEC_C_PIN2_CODE_MAX_LENGTH, ESecUiAlphaNotSupported
  1505                                 | ESecUiCancelSupported | secCodeType);
  1524                                 | ESecUiCancelSupported | secCodeType);
  1506         RDEBUG("aNewPassword", 0);
  1525         RDEBUG("aNewPassword", 0);
  1507         RDebug::Print(aNewPassword);
  1526         RDebug::Print(aNewPassword);
       
  1527         iQueryCanceled = ETrue;
  1508         delete iSecQueryUi;
  1528         delete iSecQueryUi;
  1509         RDEBUG("queryAccepted", queryAccepted);
  1529         RDEBUG("queryAccepted", queryAccepted);
  1510         if (queryAccepted != KErrNone)
  1530         if (queryAccepted != KErrNone)
  1511             {
  1531             {
  1512             // cancel "get security unblock code" request
  1532             // cancel "get security unblock code" request
  1515             RDEBUG("AbortSecurityCode", 1);
  1535             RDEBUG("AbortSecurityCode", 1);
  1516             CleanupStack::PopAndDestroy(1); //wait
  1536             CleanupStack::PopAndDestroy(1); //wait
  1517             return;
  1537             return;
  1518             }
  1538             }
  1519         }
  1539         }
  1520     // send code
  1540     // send code. The code was temporarilly changed before. Thus, this really done to set the new-new one
  1521     // TODO the current code should be verified before
       
  1522     RDEBUG("VerifySecurityCode", 0);
  1541     RDEBUG("VerifySecurityCode", 0);
  1523     iPhone.VerifySecurityCode(wait->iStatus, secCodeType, aNewPassword,
  1542     iPhone.VerifySecurityCode(wait->iStatus, secCodeType, aNewPassword,
  1524             iSecUi_password);
  1543             iSecUi_password);
  1525     RDEBUG("WaitForRequestL", 0);
  1544     RDEBUG("WaitForRequestL", 0);
  1526     TInt res = wait->WaitForRequestL();
  1545     res = wait->WaitForRequestL();
  1527     RDEBUG("WaitForRequestL res", res);
  1546     RDEBUG("WaitForRequestL res", res);
  1528     CleanupStack::PopAndDestroy(wait);
  1547     CleanupStack::PopAndDestroy(wait);
  1529 
  1548 
  1530     switch (res)
  1549     switch (res)
  1531         {
  1550         {
  1567      *    Series 60  ETel API
  1586      *    Series 60  ETel API
  1568      *****************************************************/
  1587      *****************************************************/
  1569     TBool wcdmaSupported(
  1588     TBool wcdmaSupported(
  1570             FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma));
  1589             FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma));
  1571     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin));
  1590     TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin));
       
  1591     	RDEBUG("wcdmaSupported", wcdmaSupported);
       
  1592     	RDEBUG("upinSupported", upinSupported);
  1572     if (wcdmaSupported || upinSupported)
  1593     if (wcdmaSupported || upinSupported)
  1573         {
  1594         {
  1574         TInt queryAccepted = KErrCancel;
  1595         TInt queryAccepted = KErrCancel;
  1575         TInt lCancelSupported = ESecUiCancelNotSupported;
  1596         TInt lCancelSupported = ESecUiCancelNotSupported;
  1576         RMobilePhone::TMobilePassword iSecUi_password;
  1597         RMobilePhone::TMobilePassword iSecUi_password;
  1607 
  1628 
  1608         /* request PIN using QT */
  1629         /* request PIN using QT */
  1609         CSecQueryUi *iSecQueryUi;
  1630         CSecQueryUi *iSecQueryUi;
  1610         RDEBUG("CSecQueryUi", 0);
  1631         RDEBUG("CSecQueryUi", 0);
  1611         iSecQueryUi = CSecQueryUi::NewL();
  1632         iSecQueryUi = CSecQueryUi::NewL();
  1612         // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1633 				iQueryCanceled = EFalse;
       
  1634         // ESecUiCodeEtelReqest/ESecUiNone might be useful
  1613         // TODO also support Emergency
  1635         // TODO also support Emergency
  1614         if (StartUp || (secUiOriginatedQuery != ESecurityUIsSecUIOriginated)
  1636         if (StartUp || (secUiOriginatedQuery != ESecurityUIsSecUIOriginated)
  1615                 || (err != KErrNone))
  1637                 || (err != KErrNone))
  1616             lCancelSupported = ESecUiCancelNotSupported;
  1638             lCancelSupported = ESecUiCancelNotSupported;
  1617         else
  1639         else
  1626                 SEC_C_PIN_CODE_MIN_LENGTH, SEC_C_PIN_CODE_MAX_LENGTH,
  1648                 SEC_C_PIN_CODE_MIN_LENGTH, SEC_C_PIN_CODE_MAX_LENGTH,
  1627                 ESecUiSecretSupported | ESecUiAlphaNotSupported
  1649                 ESecUiSecretSupported | ESecUiAlphaNotSupported
  1628                         | lCancelSupported | ESecUiCodeEtelReqest);
  1650                         | lCancelSupported | ESecUiCodeEtelReqest);
  1629         RDEBUG("iSecUi_password", 0);
  1651         RDEBUG("iSecUi_password", 0);
  1630         RDebug::Print(iSecUi_password);
  1652         RDebug::Print(iSecUi_password);
       
  1653         iQueryCanceled = ETrue;
  1631         delete iSecQueryUi;
  1654         delete iSecQueryUi;
  1632         RDEBUG("queryAccepted", queryAccepted);
  1655         RDEBUG("queryAccepted", queryAccepted);
  1633         if (queryAccepted != KErrNone)
  1656         if (queryAccepted != KErrNone)
  1634             {
  1657             {
  1635             CleanupStack::PopAndDestroy(wait);
  1658             CleanupStack::PopAndDestroy(wait);
  1650         TInt returnValue = res;
  1673         TInt returnValue = res;
  1651         switch (res)
  1674         switch (res)
  1652             {
  1675             {
  1653             case KErrNone:
  1676             case KErrNone:
  1654                 // code approved 
  1677                 // code approved 
  1655 #if defined(_DEBUG)
  1678                 RDEBUG("code approved ", 0);
  1656                 RDebug::Print(_L("CSecurityHandler::UPinRequiredL()code approved "));
       
  1657 #endif
       
  1658                 CSecuritySettings::ShowResultNoteL(R_CONFIRMATION_NOTE,
  1679                 CSecuritySettings::ShowResultNoteL(R_CONFIRMATION_NOTE,
  1659                         CAknNoteDialog::EConfirmationTone);
  1680                         CAknNoteDialog::EConfirmationTone);
  1660                 break;
  1681                 break;
  1661             case KErrGsm0707IncorrectPassword:
  1682             case KErrGsm0707IncorrectPassword:
  1662             case KErrAccessDenied:
  1683             case KErrAccessDenied:
  1670                 break;
  1691                 break;
  1671             case KErrGsmSSPasswordAttemptsViolation:
  1692             case KErrGsmSSPasswordAttemptsViolation:
  1672             case KErrLocked:
  1693             case KErrLocked:
  1673                 // code blocked; show error note and terminate.
  1694                 // code blocked; show error note and terminate.
  1674                 if (StartUp)
  1695                 if (StartUp)
  1675                     CSecuritySettings::ShowResultNoteL(R_CODE_ERROR,
  1696                     CSecuritySettings::ShowResultNoteL(res,
  1676                             CAknNoteDialog::EErrorTone);
  1697                             CAknNoteDialog::EErrorTone);
  1677                 break;
  1698                 break;
  1678             case KErrGsm0707SimWrong:
  1699             case KErrGsm0707SimWrong:
  1679                 // sim lock active
  1700                 // sim lock active
  1680                 break;
  1701                 break;
  1681             default:
  1702             default:	// for example, KErrArgument
  1682                 CSecuritySettings::ShowErrorNoteL(res);
  1703                 CSecuritySettings::ShowErrorNoteL(res);
  1683                 if (StartUp)
  1704                 if (StartUp)
  1684                     {
  1705                     {
  1685                     returnValue = UPinRequiredL();
  1706                     returnValue = UPinRequiredL();
  1686                     }
  1707                     }
  1739         /* request PIN using QT */
  1760         /* request PIN using QT */
  1740             {
  1761             {
  1741             CSecQueryUi *iSecQueryUi;
  1762             CSecQueryUi *iSecQueryUi;
  1742             RDEBUG("CSecQueryUi", 0);
  1763             RDEBUG("CSecQueryUi", 0);
  1743             iSecQueryUi = CSecQueryUi::NewL();
  1764             iSecQueryUi = CSecQueryUi::NewL();
       
  1765 						iQueryCanceled = EFalse;
  1744             // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1766             // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1745             // TODO also support Emergency
  1767             // TODO also support Emergency
  1746 
  1768 
  1747             TBuf<0x100> title;
  1769             TBuf<0x100> title;
  1748             title.Zero();
  1770             title.Zero();
  1753                     iSecUi_password, SEC_C_PUK_CODE_MIN_LENGTH,
  1775                     iSecUi_password, SEC_C_PUK_CODE_MIN_LENGTH,
  1754                     SEC_C_PUK_CODE_MAX_LENGTH, ESecUiAlphaNotSupported
  1776                     SEC_C_PUK_CODE_MAX_LENGTH, ESecUiAlphaNotSupported
  1755                             | ESecUiCancelSupported | ESecUiPukRequired);
  1777                             | ESecUiCancelSupported | ESecUiPukRequired);
  1756             RDEBUG("iSecUi_password", 0);
  1778             RDEBUG("iSecUi_password", 0);
  1757             RDebug::Print(iSecUi_password);
  1779             RDebug::Print(iSecUi_password);
       
  1780             iQueryCanceled = ETrue;
  1758             delete iSecQueryUi;
  1781             delete iSecQueryUi;
  1759             RDEBUG("queryAccepted", queryAccepted);
  1782             RDEBUG("queryAccepted", queryAccepted);
  1760 
  1783 
  1761             if (queryAccepted != KErrNone)
  1784             if (queryAccepted != KErrNone)
  1762                 {
  1785                 {
  1768             {
  1791             {
  1769             /* request PIN using QT */
  1792             /* request PIN using QT */
  1770             CSecQueryUi *iSecQueryUi;
  1793             CSecQueryUi *iSecQueryUi;
  1771             RDEBUG("CSecQueryUi", 0);
  1794             RDEBUG("CSecQueryUi", 0);
  1772             iSecQueryUi = CSecQueryUi::NewL();
  1795             iSecQueryUi = CSecQueryUi::NewL();
       
  1796 						iQueryCanceled = EFalse;
  1773             // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1797             // TODO ESecUiCodeEtelReqest/ESecUiNone might be useful
  1774             // TODO also support Emergency
  1798             // TODO also support Emergency
  1775 
  1799 
  1776             queryAccepted = iSecQueryUi->SecQueryDialog(_L(
  1800             queryAccepted = iSecQueryUi->SecQueryDialog(_L(
  1777                     "UPuk-New|UPuk-Verif"), aNewPassword,
  1801                     "UPuk-New|UPuk-Verif"), aNewPassword,
  1778                     SEC_C_PUK_CODE_MIN_LENGTH, SEC_C_PUK_CODE_MAX_LENGTH,
  1802                     SEC_C_PUK_CODE_MIN_LENGTH, SEC_C_PUK_CODE_MAX_LENGTH,
  1779                     ESecUiAlphaNotSupported | ESecUiCancelSupported
  1803                     ESecUiAlphaNotSupported | ESecUiCancelSupported
  1780                             | ESecUiPukRequired);
  1804                             | ESecUiPukRequired);
  1781             RDEBUG("aNewPassword", 0);
  1805             RDEBUG("aNewPassword", 0);
  1782             RDebug::Print(aNewPassword);
  1806             RDebug::Print(aNewPassword);
       
  1807             iQueryCanceled = ETrue;
  1783             delete iSecQueryUi;
  1808             delete iSecQueryUi;
  1784             RDEBUG("queryAccepted", queryAccepted);
  1809             RDEBUG("queryAccepted", queryAccepted);
  1785             if (queryAccepted != KErrNone)
  1810             if (queryAccepted != KErrNone)
  1786                 {
  1811                 {
  1787                 CleanupStack::PopAndDestroy(wait);
  1812                 CleanupStack::PopAndDestroy(wait);
  1863     {
  1888     {
  1864     // Let's create TextResolver instance for error resolving...
  1889     // Let's create TextResolver instance for error resolving...
  1865     RDEBUG("aStatus", aStatus);
  1890     RDEBUG("aStatus", aStatus);
  1866     RDEBUG("!!!!! this should never be called !!!!", 0);
  1891     RDEBUG("!!!!! this should never be called !!!!", 0);
  1867 
  1892 
  1868     CTextResolver* textresolver = CTextResolver::NewLC();
  1893     CSecuritySettings::ShowResultNoteL(aStatus, CAknNoteDialog::EErrorTone);
  1869     // Resolve the error
       
  1870     TPtrC errorstring;
       
  1871     errorstring.Set(textresolver->ResolveErrorString(aStatus));
       
  1872     iNoteDlg = new (ELeave) CAknNoteDialog(REINTERPRET_CAST(CEikDialog**,&iNoteDlg));
       
  1873     iNoteDlg->PrepareLC(R_CODE_ERROR);
       
  1874     iNoteDlg->SetTextL((TDesC&) errorstring);
       
  1875     iNoteDlg->RunDlgLD(CAknNoteDialog::ELongTimeout,
       
  1876             CAknNoteDialog::EErrorTone);
       
  1877     CleanupStack::PopAndDestroy(textresolver);
       
  1878     }
  1894     }
  1879 
  1895 
  1880 // End of file
  1896 // End of file