securitydialogs/SecUi/Src/SecUiSecuritySettings.cpp
changeset 22 6b63ca65093a
parent 19 098e361762d2
child 26 aad866c37519
equal deleted inserted replaced
19:098e361762d2 22:6b63ca65093a
   314 // ----------------------------------------------------------
   314 // ----------------------------------------------------------
   315 // no qtdone
   315 // no qtdone
   316 EXPORT_C TInt CSecuritySettings::ChangeRemoteLockStatusL(
   316 EXPORT_C TInt CSecuritySettings::ChangeRemoteLockStatusL(
   317         TBool& aRemoteLockStatus, TDes& aRemoteLockCode, TInt aAutoLockPeriod)
   317         TBool& aRemoteLockStatus, TDes& aRemoteLockCode, TInt aAutoLockPeriod)
   318     {
   318     {
       
   319     TInt retValue( KErrNone );
       
   320 		RDEBUG("aRemoteLockStatus", aRemoteLockStatus);
       
   321 		RDEBUG("aAutoLockPeriod", aAutoLockPeriod);
       
   322 
       
   323     TInt currentItem( 0 );
       
   324 
       
   325     if ( aRemoteLockStatus )
       
   326         {
       
   327         currentItem = KRemoteLockSettingItemOn;
       
   328         }
       
   329     else
       
   330         {
       
   331         currentItem = KRemoteLockSettingItemOff;
       
   332         }
       
   333 		RDEBUG("currentItem", currentItem);
       
   334 
       
   335     if ( currentItem == KRemoteLockSettingItemOn )
       
   336         {
       
   337 				RDEBUG("KRemoteLockSettingItemOn", KRemoteLockSettingItemOn);
       
   338         aRemoteLockStatus = ETrue;
       
   339 
       
   340         // If user wishes to enable remote lock
       
   341         // a new remote lock code is required.
       
   342         // RemoteLockCodeQueryL also 
       
   343         retValue = RemoteLockCodeQueryL( aRemoteLockCode );
       
   344         }
       
   345     else if ( currentItem == KRemoteLockSettingItemOff )
       
   346         {
       
   347 				RDEBUG("KRemoteLockSettingItemOff", KRemoteLockSettingItemOff);
       
   348         aRemoteLockStatus = EFalse;
       
   349         retValue = KErrNone;
       
   350 				// TODO this should calculate aAutoLockPeriod itself, and not trust the input
       
   351 
       
   352         // Check whether AutoLock is enabled (timeout value greater 
       
   353         // than zero) or not. If AutoLock is enabled the domestic OS 
       
   354         // device lock should be left enabled.
       
   355         if ( aAutoLockPeriod == 0 )
       
   356             {
       
   357             // Disable lock setting from domestic OS
       
   358             retValue = RemoteLockSetLockSettingL( EFalse );
       
   359             }
       
   360         else
       
   361             {
       
   362             // If AutoLock is enabled, don't disable the DOS device lock
       
   363             // Re-set (enable) the domestic OS device lock because as a 
       
   364             // side effect it requires the security code from the user
       
   365             retValue = RemoteLockSetLockSettingL( ETrue );
       
   366             }
       
   367         }
       
   368 		RDEBUG( "retValue", retValue );
       
   369     return retValue;
       
   370     }
       
   371 //
       
   372 // ----------------------------------------------------------
       
   373 // CSecuritySettings::RemoteLockCodeQueryL()
       
   374 // Pops up remote lock code query. Requires user to enter a new remote lock 
       
   375 // code (RemoteMsg) twice and if they match enables the domestic OS device lock (which as 
       
   376 // a side effect pops up security code query).
       
   377 // ----------------------------------------------------------
       
   378 // no qtdone
       
   379 TInt CSecuritySettings::RemoteLockCodeQueryL(TDes& aRemoteLockCode)
       
   380     {
   319 #ifdef RD_REMOTELOCK
   381 #ifdef RD_REMOTELOCK
   320     TInt retValue( KErrNone );
   382     TInt retValue( KErrNone );
   321 
   383 
   322 #ifdef _DEBUG
   384 		RDEBUG( "retValue", retValue );
   323     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Enter, aRemoteLockStatus == %d, aAutoLockPeriod == %d" ), aRemoteLockStatus, aAutoLockPeriod );
       
   324 #endif // _DEBUG
       
   325     CCoeEnv* coeEnv = CCoeEnv::Static();
       
   326     CDesCArrayFlat* items = coeEnv->ReadDesC16ArrayResourceL( R_REMOTELOCK_LBX );
       
   327     CleanupStack::PushL( items );
       
   328 
       
   329     // Store the current remote lock setting 
       
   330     TInt previousItem( 0 );
       
   331     TInt currentItem( 0 );
       
   332 
       
   333     if ( aRemoteLockStatus )
       
   334         {
       
   335         previousItem = KRemoteLockSettingItemOn;
       
   336         currentItem = KRemoteLockSettingItemOn;
       
   337         }
       
   338     else
       
   339         {
       
   340         previousItem = KRemoteLockSettingItemOff;
       
   341         currentItem = KRemoteLockSettingItemOff;
       
   342         }
       
   343 
       
   344     // Create Remote Lock setting page for user to enable or disable remote locking 
       
   345     CRemoteLockSettingPage* remoteLockSettingPage = new( ELeave ) CRemoteLockSettingPage( R_REMOTELOCK_SETTING_PAGE, currentItem, items );
       
   346 
       
   347 #ifdef _DEBUG
       
   348     RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Executing CRemoteLockSettingPage dialog" ) );
       
   349 #endif // _DEBUG
       
   350     // Execute the remote lock enable/disable dialog
       
   351     TBool ret = remoteLockSettingPage->ExecuteLD( CAknSettingPage::EUpdateWhenChanged );
       
   352 
       
   353     // Setting page list box items (texts) no longer needed
       
   354     CleanupStack::PopAndDestroy( items );
       
   355 
       
   356     if ( ret )
       
   357         {
       
   358         if ( currentItem == KRemoteLockSettingItemOn )
       
   359             {
       
   360 #ifdef _DEBUG
       
   361             RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Remote lock status set to ON" ) );
       
   362 #endif // _DEBUG
       
   363             aRemoteLockStatus = ETrue;
       
   364 
       
   365             // If user wishes to enable remote lock
       
   366             // a new remote lock code is required.
       
   367             // RemoteLockCodeQueryL also 
       
   368             retValue = RemoteLockCodeQueryL( aRemoteLockCode );
       
   369             }
       
   370         else if ( currentItem == KRemoteLockSettingItemOff )
       
   371             {
       
   372 #ifdef _DEBUG
       
   373             RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Remote lock status set to OFF" ) );
       
   374 #endif // _DEBUG
       
   375             aRemoteLockStatus = EFalse;
       
   376             retValue = KErrNone;
       
   377 
       
   378             // Check whether the status was already off
       
   379             // If not don't make the user enter the security code
       
   380             // (which occurs when setting the DOS lock setting) for no reason.
       
   381             if ( currentItem != previousItem )
       
   382                 {
       
   383                 // Check whether AutoLock is enabled (timeout value greater 
       
   384                 // than zero) or not. If AutoLock is enabled the domestic OS 
       
   385                 // device lock should be left enabled.
       
   386                 if ( aAutoLockPeriod == 0 )
       
   387                     {
       
   388                     // Disable lock setting from domestic OS
       
   389                     retValue = RemoteLockSetLockSettingL( EFalse );
       
   390                     }
       
   391                 else
       
   392                     {
       
   393                     // If AutoLock is enabled, don't disable the DOS device lock
       
   394                     // Re-set (enable) the domestic OS device lock because as a 
       
   395                     // side effect it requires the security code from the user
       
   396                     retValue = RemoteLockSetLockSettingL( ETrue );
       
   397                     }
       
   398                 }
       
   399             }
       
   400         else
       
   401             {
       
   402             // This should never happen. But if it does don't change anything
       
   403             retValue = KErrUnknown;
       
   404             }
       
   405         }
       
   406     else
       
   407         {
       
   408         // Something went wrong with the RemoteLockSettingPage dialog 
       
   409         retValue = KErrGeneral;
       
   410 
       
   411 #ifdef _DEBUG
       
   412         RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - CRemoteLockSettingPage::ExecuteLD() failed" ) );
       
   413 #endif // _DEBUG
       
   414         }
       
   415 
       
   416 #ifdef _DEBUG
       
   417     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockStatusL() - Exit" ) );
       
   418 #endif
       
   419 
       
   420     return retValue;
       
   421 #else //! RD_REMOTELOCK
       
   422     return KErrNotSupported;
       
   423 #endif //RD_REMOTELOCK
       
   424     }
       
   425 //
       
   426 // ----------------------------------------------------------
       
   427 // CSecuritySettings::RemoteLockCodeQueryL()
       
   428 // Pops up remote lock code query. Requires user to enter a new remote lock 
       
   429 // code twice and if they match enables the domestic OS device lock (which as 
       
   430 // a side effect pops up security code query).
       
   431 // ----------------------------------------------------------
       
   432 // no qtdone
       
   433 TInt CSecuritySettings::RemoteLockCodeQueryL(TDes& aRemoteLockCode)
       
   434     {
       
   435 #ifdef RD_REMOTELOCK
       
   436     TInt retValue( KErrNone );
       
   437 
       
   438 #ifdef _DEBUG
       
   439     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Enter" ) );
       
   440 #endif // _DEBUG
       
   441     // Clear the remote lock code buffer
       
   442     aRemoteLockCode.Zero();
   385     aRemoteLockCode.Zero();
   443 
   386 
   444     // ----- Remote lock code query -------------------------------------------
   387     TInt queryAccepted = KErrCancel;
   445 
   388         queryAccepted = KErrCancel;
   446     // Execute Remote Lock code query
   389         CSecQueryUi * iSecQueryUi;
   447 #ifdef _DEBUG
   390         iSecQueryUi = CSecQueryUi::NewL();
   448     RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Executing remote lock code query" ) );
   391         // this queries both, and verifies itself
   449 #endif // _DEBUG
   392         queryAccepted = iSecQueryUi->SecQueryDialog(
   450     // Load the query prompt from resources
   393                 _L("RemoteMsg-New|RemoteMsg-Ver"), aRemoteLockCode,
   451     CCodeQueryDialog* codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
   394                 SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH,
   452     TInt buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
   395                 ESecUiAlphaSupported | ESecUiCancelSupported
   453     if ( buttonId == EEikBidOk )
   396                         | ESecUiEmergencyNotSupported | ESecUiNone);
   454         {
   397         RDEBUG("aRemoteLockCode", 0);
   455         // Ok was pressed and the remote lock code seems fine
   398         RDebug::Print(aRemoteLockCode);
   456         retValue = KErrNone;
   399         RDEBUG("queryAccepted", queryAccepted);
   457         }
   400         delete iSecQueryUi;
   458     else
   401         if (queryAccepted != KErrNone)
   459         {
   402             return KErrAbort;
   460         // User pressed Cancel
   403 
   461         // Set the code length to zero leaving no trash for possible retry
   404 		// TODO it should ask first for the code, and _later_ for the RemoteMsg
   462         aRemoteLockCode.Zero();
   405 		
   463         retValue = KErrAbort;
       
   464         }
       
   465 
       
   466     if ( retValue != KErrNone )
       
   467         {
       
   468 #ifdef _DEBUG
       
   469         RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Exit, Remote lock code error" ) );
       
   470 #endif // _DEBUG
       
   471         // Can't continue beyond this 
       
   472         return retValue;
       
   473         }
       
   474 
       
   475     // ----- Remote lock code confirm query -----------------------------------
       
   476 
       
   477     // Confirm the code by asking it again
       
   478 #ifdef _DEBUG
       
   479     RDebug::Print( _L( "(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Executing remote lock code verify query" ) );
       
   480 #endif // _DEBUG
       
   481     // Buffer for the confirmation code
       
   482     TBuf<KRLockMaxLockCodeLength> confirmCode;
       
   483 
       
   484     // Load the confirmation query prompt from resources
       
   485     CCodeQueryDialog* codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
   486     buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
   487 
       
   488     if ( buttonId == EEikBidOk )
       
   489         {
       
   490         // Compare codes. Compare returns zero if descriptors have
       
   491         // the same length and the same content
       
   492         while ( (aRemoteLockCode.CompareF( confirmCode ) != 0) && (buttonId == EEikBidOk))
       
   493             {
       
   494             //Codes didn't match; zero the bufffers and show the dialog again
       
   495             aRemoteLockCode.Zero();
       
   496             confirmCode.Zero();
       
   497             // Codes don't match. Notify user
       
   498             ShowResultNoteL( R_REMOTELOCK_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone );
       
   499             codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
   500             buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
       
   501             //Unless user pressed Cancel show the verification query
       
   502             if(buttonId == EEikBidOk)
       
   503                 {
       
   504                 codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
   505                 buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
   506                 }
       
   507 
       
   508             }
       
   509         //User pressed cancel        
       
   510         if(buttonId != EEikBidOk)
       
   511             {
       
   512             // Set the code length to zero leaving no trash for possible retry
       
   513             // Report error and let the user try again 
       
   514             aRemoteLockCode.Zero();
       
   515             confirmCode.Zero();
       
   516             retValue = KErrAbort;
       
   517             }
       
   518         else
       
   519             {
       
   520             // Codes match
       
   521             confirmCode.Zero();
       
   522 
       
   523             // ----- Check against security code ------------------------------
   406             // ----- Check against security code ------------------------------
   524 
   407 
   525             // Check that the new remote lock code doesn't match the security 
   408             // Check that the new remote lock code doesn't match the security 
   526             // code of the device.
   409             // code of the device.
   527 
   410 
   528             RMobilePhone::TMobilePhoneSecurityCode secCodeType;
   411             RMobilePhone::TMobilePhoneSecurityCode secCodeType;
   529             secCodeType = RMobilePhone::ESecurityCodePhonePassword;
   412             secCodeType = RMobilePhone::ESecurityCodePhonePassword;
   530             RMobilePhone::TMobilePassword securityCode;
   413             RMobilePhone::TMobilePassword securityCode;
   531             RMobilePhone::TMobilePassword unblockCode; // Required here only as a dummy parameter 
   414             RMobilePhone::TMobilePassword unblockCode; // Required here only as a dummy parameter 
   532 
   415 
   533             if ( aRemoteLockCode.Length() <= RMobilePhone::KMaxMobilePasswordSize )
   416 						RDEBUG( "RMobilePhone::KMaxMobilePasswordSize", RMobilePhone::KMaxMobilePasswordSize );
   534                 {
   417 
   535                 securityCode = aRemoteLockCode;
   418                 securityCode = aRemoteLockCode;
   536                 iWait->SetRequestType( EMobilePhoneVerifySecurityCode );
   419                 iWait->SetRequestType( EMobilePhoneVerifySecurityCode );
   537                 RDEBUG( "VerifySecurityCode", 0 );
   420                 RDEBUG( "VerifySecurityCode", 0 );
   538                 iPhone.VerifySecurityCode( iWait->iStatus, secCodeType, securityCode, unblockCode );
   421                 iPhone.VerifySecurityCode( iWait->iStatus, secCodeType, securityCode, unblockCode );
   539                 RDEBUG( "WaitForRequestL", 0 );
   422                 RDEBUG( "WaitForRequestL", 0 );
   541                 RDEBUG( "WaitForRequestL res", res );
   424                 RDEBUG( "WaitForRequestL res", res );
   542 #ifdef __WINS__
   425 #ifdef __WINS__
   543                 if (res == KErrNotSupported || res == KErrTimedOut)
   426                 if (res == KErrNotSupported || res == KErrTimedOut)
   544                 res = KErrNone;
   427                 res = KErrNone;
   545 #endif
   428 #endif
   546                 // The remote lock code matches the security code 
   429                 if(res != KErrNone)
   547                 // and that is not allowed
       
   548                 while ( (res == KErrNone) && (buttonId == EEikBidOk))
       
   549                     {
   430                     {
   550 #ifdef _DEBUG
   431 		                // The remote lock code matches the security code 
   551                     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Unacceptable remote lock code" ) );
   432 		                // and that is not allowed
   552 #endif // _DEBUG
   433 		                RDEBUG( "res", res );
   553                     aRemoteLockCode.Zero();
   434 		                return res;
   554                     confirmCode.Zero();
       
   555 
       
   556                     ShowResultNoteL( R_REMOTELOCK_INVALID_CODE, CAknNoteDialog::EErrorTone );
       
   557 
       
   558                     codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
   559                     buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
       
   560                     //Unless user pressed Cancel show the verification query
       
   561                     if(buttonId == EEikBidOk)
       
   562                         {
       
   563                         codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
   564                         buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
   565 
       
   566                         // Compare codes. Compare returns zero if descriptors have
       
   567                         // the same length and the same content
       
   568                         while ( (aRemoteLockCode.CompareF( confirmCode ) != 0) && (buttonId == EEikBidOk))
       
   569                             {
       
   570                             //Codes didn't match; zero the bufffers and show the dialog again
       
   571                             aRemoteLockCode.Zero();
       
   572                             confirmCode.Zero();
       
   573                             // Codes don't match. Notify user
       
   574                             ShowResultNoteL( R_REMOTELOCK_CODES_DONT_MATCH, CAknNoteDialog::EErrorTone );
       
   575                             codeQuery = new( ELeave ) CCodeQueryDialog( aRemoteLockCode, SEC_REMOTELOCK_CODE_MIN_LENGTH,SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
   576                             buttonId = codeQuery->ExecuteLD( R_REMOTELOCK_CODE_QUERY );
       
   577                             //Unless user pressed Cancel show the verification query
       
   578                             if(buttonId == EEikBidOk)
       
   579                                 {
       
   580                                 codeConfirmQuery = new( ELeave ) CCodeQueryDialog( confirmCode, SEC_REMOTELOCK_CODE_MIN_LENGTH, SEC_REMOTELOCK_CODE_MAX_LENGTH, ESecUiNone, ETrue );
       
   581                                 buttonId = codeConfirmQuery->ExecuteLD( R_VERIFY_REMOTELOCK_CODE_QUERY);
       
   582                                 }
       
   583 
       
   584                             }
       
   585                         //User pressed cancel        
       
   586                         if(buttonId != EEikBidOk)
       
   587                             {
       
   588                             // Set the code length to zero leaving no trash for possible retry
       
   589                             // Report error and let the user try again 
       
   590                             aRemoteLockCode.Zero();
       
   591                             confirmCode.Zero();
       
   592                             retValue = KErrAbort;
       
   593                             }
       
   594                         else //Check against security code
       
   595 
       
   596                             {
       
   597                             securityCode = aRemoteLockCode;
       
   598                             iWait->SetRequestType( EMobilePhoneVerifySecurityCode );
       
   599                             RDEBUG( "VerifySecurityCode", 0 );
       
   600                             iPhone.VerifySecurityCode( iWait->iStatus, secCodeType, securityCode, unblockCode );
       
   601                             RDEBUG( "WaitForRequestL", 0 );
       
   602                             res = iWait->WaitForRequestL();
       
   603 #ifdef __WINS__
       
   604                             if (res == KErrNotSupported || res == KErrTimedOut)
       
   605                             res = KErrNone;
       
   606 #endif
       
   607                             RDEBUG( "WaitForRequestL res", res );
       
   608                             }
       
   609                         }
       
   610 
       
   611                     }
   435                     }
   612                 //User pressed cancel        
       
   613                 if(buttonId != EEikBidOk)
       
   614                     {
       
   615                     // Set the code length to zero leaving no trash for possible retry
       
   616                     // Report error and let the user try again 
       
   617                     aRemoteLockCode.Zero();
       
   618                     confirmCode.Zero();
       
   619                     retValue = KErrAbort;
       
   620                     }
       
   621                 }
       
   622 
   436 
   623             // ----- Enable DOS device lock (Security code query) -------------
   437             // ----- Enable DOS device lock (Security code query) -------------
   624 
       
   625             if ( retValue == KErrNone )
   438             if ( retValue == KErrNone )
   626                 {
   439                 {
   627                 // Enable lock setting in domestic OS. It is safe to enable the 
   440                 // Enable lock setting in domestic OS. It is safe to enable the 
   628                 // lock setting since RemoteLock API requires remote locking to
   441                 // lock setting since RemoteLock API requires remote locking to
   629                 // be enabled when changing or setting the remote lock message.
   442                 // be enabled when changing or setting the remote lock message.
   630                 retValue = RemoteLockSetLockSettingL( ETrue );
   443                 retValue = RemoteLockSetLockSettingL( ETrue );
   631                 }
   444                 }
   632             }
   445 RDEBUG( "retValue", retValue );
   633         }
       
   634     else //User pressed Cancel
       
   635 
       
   636         {
       
   637         // Set the code length to zero leaving no trash for possible retry
       
   638         aRemoteLockCode.Zero();
       
   639         confirmCode.Zero();
       
   640         retValue = KErrAbort;
       
   641         }
       
   642 
       
   643 #ifdef _DEBUG
   446 #ifdef _DEBUG
   644     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Exit" ) );
   447     RDebug::Print(_L("(SecUi)CSecuritySettings::ChangeRemoteLockCodeL() - Exit" ) );
   645 #endif // _DEBUG
   448 #endif // _DEBUG
   646     return retValue;
   449     return retValue;
   647 #else //! RD_REMOTELOCK
   450 #else //! RD_REMOTELOCK
   655 // requires user to enter the security code.
   458 // requires user to enter the security code.
   656 // ----------------------------------------------------------
   459 // ----------------------------------------------------------
   657 // no qtdone
   460 // no qtdone
   658 TInt CSecuritySettings::RemoteLockSetLockSettingL(TBool aLockSetting)
   461 TInt CSecuritySettings::RemoteLockSetLockSettingL(TBool aLockSetting)
   659     {
   462     {
   660 #ifdef RD_REMOTELOCK
       
   661     TInt retValue( KErrNone );
   463     TInt retValue( KErrNone );
   662 
   464 		RDEBUG( "aLockSetting", aLockSetting );
   663 #ifdef _DEBUG
   465 
   664     RDebug::Print(_L("(SecUi)CSecuritySettings::RemoteLockSetLockSettingL( %d ) - Enter" ), aLockSetting );
       
   665 #endif // _DEBUG
       
   666     RMobilePhone::TMobilePhoneLockSetting lockSetting = RMobilePhone::ELockSetEnabled;
   466     RMobilePhone::TMobilePhoneLockSetting lockSetting = RMobilePhone::ELockSetEnabled;
   667     RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
   467     RMobilePhone::TMobilePhoneLock lockType = RMobilePhone::ELockPhoneDevice;
   668 
   468 
   669     if ( aLockSetting )
   469     if ( aLockSetting )
   670         {
   470         {
   672         }
   472         }
   673     else
   473     else
   674         {
   474         {
   675         lockSetting = RMobilePhone::ELockSetDisabled;
   475         lockSetting = RMobilePhone::ELockSetDisabled;
   676         }
   476         }
       
   477 		RDEBUG("lockSetting", lockSetting);
   677 
   478 
   678     iWait->SetRequestType( EMobilePhoneSetLockSetting );
   479     iWait->SetRequestType( EMobilePhoneSetLockSetting );
   679     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
   480     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel, ESecurityUIsQueryRequestOk);
   680     RDEBUG( "SetLockSetting", 0 );
   481     RDEBUG( "SetLockSetting", 0 );
   681     iPhone.SetLockSetting( iWait->iStatus, lockType, lockSetting );
   482     iPhone.SetLockSetting( iWait->iStatus, lockType, lockSetting );	// this will PassPhraseRequiredL
   682 
       
   683     // Wait for code verify to complete
       
   684     RDEBUG( "WaitForRequestL", 0 );
   483     RDEBUG( "WaitForRequestL", 0 );
   685     retValue = iWait->WaitForRequestL();
   484     retValue = iWait->WaitForRequestL();
   686     RDEBUG( "WaitForRequestL retValue", retValue );
   485     RDEBUG( "WaitForRequestL retValue", retValue );
   687 #ifdef __WINS__
   486 #ifdef __WINS__
   688     if (retValue == KErrNotSupported || retValue == KErrTimedOut)
   487     if (retValue == KErrNotSupported || retValue == KErrTimedOut)
   690 #endif
   489 #endif
   691 
   490 
   692     switch( retValue )
   491     switch( retValue )
   693         {
   492         {
   694         case KErrNone:
   493         case KErrNone:
   695 #ifdef _DEBUG
       
   696         RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrNone" ) );
       
   697 #endif // _DEBUG
       
   698         break;
   494         break;
   699 
   495 
   700         case KErrGsmSSPasswordAttemptsViolation:
   496         case KErrGsmSSPasswordAttemptsViolation:
   701         case KErrLocked:
   497         case KErrLocked:
   702 #ifdef _DEBUG
       
   703         RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrLocked" ) );
       
   704 #endif // _DEBUG
       
   705         //Error note is shown in CSecurityHandler::PassPhraseRequired()
       
   706         break;
       
   707 
       
   708         case KErrGsm0707IncorrectPassword:
   498         case KErrGsm0707IncorrectPassword:
   709         case KErrAccessDenied:
   499         case KErrAccessDenied:
   710 #ifdef _DEBUG
       
   711         RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrAccessDenied" ) );
       
   712 #endif // _DEBUG
       
   713         // Security code was entered erroneously
   500         // Security code was entered erroneously
   714         //Error note is shown in CSecurityHandler::PassPhraseRequired()
   501         //Error note is shown in CSecurityHandler::PassPhraseRequired()
   715         break;
   502         break;
   716 
   503 
   717         case KErrAbort:
   504         case KErrAbort:
   718 #ifdef _DEBUG
       
   719         RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned KErrAbort" ) );
       
   720 #endif // _DEBUG
       
   721         break;
   505         break;
   722 
   506 
   723         default:
   507         default:
   724 #ifdef _DEBUG
       
   725         RDebug::Print( _L( "(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - EMobilePhoneSetLockSetting request returned: %d"), retValue );
       
   726 #endif // _DEBUG
       
   727         break;
   508         break;
   728         }
   509         }
   729 
   510 
   730 #ifdef _DEBUG
   511 		RDEBUG( "retValue", retValue );
   731     RDebug::Print(_L("(SecUi)CSecuritySettings::RemoteLockSetLockSettingL() - Exit" ) );
       
   732 #endif // _DEBUG
       
   733     return retValue;
   512     return retValue;
   734 #else //! RD_REMOTELOCK
       
   735     return KErrNotSupported;
       
   736 #endif //RD_REMOTELOCK
       
   737     }
   513     }
   738 
   514 
   739 //
   515 //
   740 // ----------------------------------------------------------
   516 // ----------------------------------------------------------
   741 // CSecuritySettings::ChangeSimSecurityL()
   517 // CSecuritySettings::ChangeSimSecurityL()
   856 
   632 
   857     TBuf<0x80> iCaption;
   633     TBuf<0x80> iCaption;
   858     iCaption.Copy(_L("ChangePinRequestL"));
   634     iCaption.Copy(_L("ChangePinRequestL"));
   859     TInt iShowError = 1;
   635     TInt iShowError = 1;
   860     ChangePinRequestParamsL(
   636     ChangePinRequestParamsL(
   861             1/* TODO it's imposible to know if we want to set or clear*/,
   637             1/* it's imposible to know if we want to set or clear*/,
   862             iOldPassword, iFlags, iCaption, iShowError);
   638             iOldPassword, iFlags, iCaption, iShowError);
   863     RDEBUG("0", 0);
   639     RDEBUG("0", 0);
   864 
   640 
   865     return ETrue;
   641     return ETrue;
   866     }
   642     }
  1651             break;
  1427             break;
  1652         case KErrArgument:
  1428         case KErrArgument:
  1653             titleTr.Append(_L("KErrArgument"));
  1429             titleTr.Append(_L("KErrArgument"));
  1654             title.Append(_L("Error Argument"));
  1430             title.Append(_L("Error Argument"));
  1655             break;
  1431             break;
       
  1432         case R_SIM_OFF:
       
  1433             titleTr.Append(_L("R_SIM_OFF"));
       
  1434             title.Append(_L("SIM OFF"));
       
  1435             break;
       
  1436         case R_SIM_ALLREADY_OFF:
       
  1437             titleTr.Append(_L("R_SIM_ALLREADY_OFF"));
       
  1438             title.Append(_L("SIM ALLREADY OFF"));
       
  1439             break;
       
  1440         case R_SIM_NOT_ALLOWED:
       
  1441             titleTr.Append(_L("R_SIM_NOT_ALLOWED"));
       
  1442             title.Append(_L("SIM NOT ALLOWED"));
       
  1443             break;
  1656 
  1444 
  1657         default: // " "
  1445         default: // " "
  1658             titleTr.Append(_L("Specific Error"));
  1446             titleTr.Append(_L("Specific Error"));
  1659             title.Append(_L("Specific Error"));
  1447             title.Append(_L("Specific Error"));
  1660             break;
  1448             break;
  2534             {
  2322             {
  2535             RMobilePhone::TMobilePhoneLock lockType =
  2323             RMobilePhone::TMobilePhoneLock lockType =
  2536                     RMobilePhone::ELockPhoneDevice;
  2324                     RMobilePhone::ELockPhoneDevice;
  2537             RMobilePhone::TMobilePhoneLockSetting lockChangeSetting =
  2325             RMobilePhone::TMobilePhoneLockSetting lockChangeSetting =
  2538                     RMobilePhone::ELockSetEnabled;
  2326                     RMobilePhone::ELockSetEnabled;
  2539             if (oldPassword.Length() == 6)
       
  2540                 {
       
  2541                 lockChangeSetting = RMobilePhone::ELockSetDisabled;
       
  2542                 RDEBUG("RMobilePhone::ELockSetDisabled",
       
  2543                         RMobilePhone::ELockSetDisabled);
       
  2544                 }
       
  2545             iWait->SetRequestType(EMobilePhoneSetLockSetting);
  2327             iWait->SetRequestType(EMobilePhoneSetLockSetting);
  2546             RDEBUG("SetLockSetting", 0);
  2328             RDEBUG("SetLockSetting", 0);
  2547             iPhone.SetLockSetting(iWait->iStatus, lockType, lockChangeSetting);
  2329             iPhone.SetLockSetting(iWait->iStatus, lockType, lockChangeSetting);
  2548             RDEBUG("WaitForRequestL", 0);
  2330             RDEBUG("WaitForRequestL", 0);
  2549             res = iWait->WaitForRequestL();
  2331             res = iWait->WaitForRequestL();
  2624     return res;
  2406     return res;
  2625     }
  2407     }
  2626 
  2408 
  2627 /**************************************/
  2409 /**************************************/
  2628 // qtdone
  2410 // qtdone
       
  2411 // the params are changed in the settings,. This only asks for password.
  2629 EXPORT_C TInt CSecuritySettings::ChangeAutoLockPeriodParamsL(TInt aPeriod,
  2412 EXPORT_C TInt CSecuritySettings::ChangeAutoLockPeriodParamsL(TInt aPeriod,
  2630         RMobilePhone::TMobilePassword aOldPassword, TInt aFlags,
  2413         RMobilePhone::TMobilePassword aOldPassword, TInt aFlags,
  2631         TDes& aCaption, TInt aShowError)
  2414         TDes& aCaption, TInt aShowError)
  2632     {
  2415     {
  2633     RDEBUG("aPeriod", aPeriod);
  2416     RDEBUG("aPeriod", aPeriod);
  2659                 {
  2442                 {
  2660                 TLex lex(maxPeriodBuf);
  2443                 TLex lex(maxPeriodBuf);
  2661                 if ((lex.Val(maxPeriod) == KErrNone) && (maxPeriod > 0))
  2444                 if ((lex.Val(maxPeriod) == KErrNone) && (maxPeriod > 0))
  2662                     {
  2445                     {
  2663                     RDEBUG("from SCP maxPeriod", maxPeriod);
  2446                     RDEBUG("from SCP maxPeriod", maxPeriod);
  2664                     // nothing to do
       
  2665                     }
  2447                     }
  2666                 else
  2448                 else
  2667                     {
  2449                     {
  2668                     maxPeriod = 0;
  2450                     maxPeriod = 0;
  2669                     RDEBUG("not from SCP maxPeriod", maxPeriod);
  2451                     RDEBUG("not from SCP maxPeriod", maxPeriod);
  2685         {
  2467         {
  2686         TBool allow = ETrue;
  2468         TBool allow = ETrue;
  2687 
  2469 
  2688         if ((aPeriod == 0) && (maxPeriod > 0))
  2470         if ((aPeriod == 0) && (maxPeriod > 0))
  2689             {
  2471             {
  2690 #if defined(_DEBUG)
  2472             	RDEBUG("The period is not allowed by TARM", aPeriod);
  2691             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() \
  2473             	RDEBUG( "maxPeriod", maxPeriod );
  2692         The period: %d is not allowed by TARM; max: %d"),aPeriod, maxPeriod );
       
  2693 #endif                
       
  2694             allow = EFalse;
  2474             allow = EFalse;
  2695             ShowResultNoteL(R_SECUI_TEXT_AUTOLOCK_MUST_BE_ACTIVE,
  2475             ShowResultNoteL(R_SECUI_TEXT_AUTOLOCK_MUST_BE_ACTIVE,
  2696                     CAknNoteDialog::EErrorTone);
  2476                     CAknNoteDialog::EErrorTone);
  2697             }
  2477             }
  2698         if (!allow)
  2478         if (!allow)
  2702             }
  2482             }
  2703         }
  2483         }
  2704 
  2484 
  2705     if (aPeriod == 0)
  2485     if (aPeriod == 0)
  2706         {
  2486         {
  2707 #ifdef RD_REMOTELOCK
       
  2708 
       
  2709         // If remote lock is enabled, don't disable the domestic OS device lock
  2487         // If remote lock is enabled, don't disable the domestic OS device lock
  2710         // since that would render the RemoteLock useless.
  2488         // since that would render the RemoteLock useless.
  2711         // Instead just re-set the DOS lock to enabled which as a side effect
  2489         // Instead just re-set the DOS lock to enabled which as a side effect
  2712         // requests the security code from the user.
  2490         // requests the security code from the user.
  2713 
  2491 
  2736             }
  2514             }
  2737 
  2515 
  2738         delete remoteLockSettings;
  2516         delete remoteLockSettings;
  2739         remoteLockSettings = NULL;
  2517         remoteLockSettings = NULL;
  2740 
  2518 
  2741 #else // not defined RD_REMOTELOCK
       
  2742         lockChange = RMobilePhone::ELockSetDisabled;
       
  2743 
       
  2744 #endif // RD_REMOTELOCK
       
  2745         }
  2519         }
  2746     else
  2520     else
  2747         {
  2521         {
  2748         lockChange = RMobilePhone::ELockSetEnabled;
  2522         lockChange = RMobilePhone::ELockSetEnabled;
  2749         RDEBUG("aPeriod != 0 lockChange", lockChange);
  2523         RDEBUG("aPeriod != 0 lockChange", lockChange);
  2750         }
  2524         }
  2751 
  2525 
  2752     iWait->SetRequestType(EMobilePhoneSetLockSetting);
  2526     iWait->SetRequestType(EMobilePhoneSetLockSetting);
       
  2527     RDEBUG("lockChange", lockChange);
  2753     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel,
  2528     RProperty::Set(KPSUidSecurityUIs, KSecurityUIsQueryRequestCancel,
  2754             ESecurityUIsQueryRequestOk);
  2529             ESecurityUIsQueryRequestOk);
  2755     RDEBUG("SetLockSetting", 0);
  2530     RDEBUG("SetLockSetting", 0);
  2756     iPhone.SetLockSetting(iWait->iStatus, lockType, lockChange); // this eventually calls PassPhraseRequiredL
  2531     iPhone.SetLockSetting(iWait->iStatus, lockType, lockChange); // this eventually calls PassPhraseRequiredL
  2757     RDEBUG("WaitForRequestL", 0);
  2532     RDEBUG("WaitForRequestL", 0);
  2763     status = KErrNone;
  2538     status = KErrNone;
  2764 #endif
  2539 #endif
  2765     switch (status)
  2540     switch (status)
  2766         {
  2541         {
  2767         case KErrNone:
  2542         case KErrNone:
  2768 #if defined(_DEBUG)
       
  2769             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() KErrNone"));
       
  2770 #endif
       
  2771             break;
  2543             break;
  2772         case KErrGsmSSPasswordAttemptsViolation:
  2544         case KErrGsmSSPasswordAttemptsViolation:
  2773         case KErrLocked:
  2545         case KErrLocked:
  2774 #if defined(_DEBUG)
  2546         		RDEBUG("KErrLocked", KErrLocked);
  2775             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() PasswordAttemptsViolation"));
       
  2776 #endif
       
  2777             ShowResultNoteL(KErrLocked, CAknNoteDialog::EErrorTone); // the old code didn't show messages
  2547             ShowResultNoteL(KErrLocked, CAknNoteDialog::EErrorTone); // the old code didn't show messages
  2778             return ChangeAutoLockPeriodParamsL(oldPeriod, aOldPassword,
  2548             return ChangeAutoLockPeriodParamsL(oldPeriod, aOldPassword,
  2779                     aFlags, aCaption, aShowError); // ask again
  2549                     aFlags, aCaption, aShowError); // ask again
  2780         case KErrGsm0707IncorrectPassword:
  2550         case KErrGsm0707IncorrectPassword:
  2781         case KErrAccessDenied:
  2551         case KErrAccessDenied:
  2782 #if defined(_DEBUG)
  2552         		RDEBUG("KErrAccessDenied", KErrAccessDenied);
  2783             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() IncorrectPassword"));
       
  2784 #endif
       
  2785             // code was entered erroneously
  2553             // code was entered erroneously
  2786             ShowResultNoteL(KErrAccessDenied, CAknNoteDialog::EErrorTone); // the old code didn't show messages
  2554             ShowResultNoteL(KErrAccessDenied, CAknNoteDialog::EErrorTone); // the old code didn't show messages
  2787             return ChangeAutoLockPeriodParamsL(oldPeriod, aOldPassword,
  2555             return ChangeAutoLockPeriodParamsL(oldPeriod, aOldPassword,
  2788                     aFlags, aCaption, aShowError); // ask again
  2556                     aFlags, aCaption, aShowError); // ask again
  2789         case KErrAbort:
  2557         case KErrAbort:
  2790             // User pressed "cancel" in the code query dialog.
  2558             // User pressed "cancel" in the code query dialog.
  2791             return oldPeriod;
  2559             return oldPeriod;
  2792         default:
  2560         default:
  2793 #if defined(_DEBUG)
  2561         		RDEBUG("default", status);
  2794             RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() default"));
       
  2795 #endif
       
  2796             ShowResultNoteL(status, CAknNoteDialog::EErrorTone); // the old code didn't show messages
  2562             ShowResultNoteL(status, CAknNoteDialog::EErrorTone); // the old code didn't show messages
  2797             return ChangeAutoLockPeriodParamsL(oldPeriod, aOldPassword,
  2563             return ChangeAutoLockPeriodParamsL(oldPeriod, aOldPassword,
  2798                     aFlags, aCaption, aShowError); // ask again
  2564                     aFlags, aCaption, aShowError); // ask again
  2799         }
  2565         }
  2800 #if defined(_DEBUG)
  2566  		RDEBUG("aPeriod", aPeriod);
  2801     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangeAutoLockPeriodL() END"));
       
  2802 #endif
       
  2803     return aPeriod;
  2567     return aPeriod;
  2804     }
  2568     }
  2805 /*****************************/
  2569 /*****************************/
  2806 // qtdone
  2570 // qtdone
  2807 EXPORT_C TInt CSecuritySettings::ChangePinRequestParamsL(TInt aEnable,
  2571 EXPORT_C TInt CSecuritySettings::ChangePinRequestParamsL(TInt aEnable,
  2808         RMobilePhone::TMobilePassword aOldPassword, TInt aFlags,
  2572         RMobilePhone::TMobilePassword aOldPassword, TInt aFlags,
  2809         TDes& aCaption, TInt aShowError)
  2573         TDes& aCaption, TInt aShowError)
  2810     {
  2574     {
  2811     RDEBUG("aEnable", aEnable);
  2575     RDEBUG("aEnable", aEnable);
  2812     RDEBUG("aFlags", aFlags);
  2576     RDEBUG("aFlags", aFlags);
  2813     /*****************************************************
       
  2814      *    Series 60 Customer / ETel
       
  2815      *    Series 60  ETel API
       
  2816      *****************************************************/
       
  2817 #if defined(_DEBUG)
       
  2818     RDebug::Print(_L("(SECUI)CSecuritySettings::ChangePinRequestParamsL()"));
       
  2819 #endif      
       
  2820     TInt simState = 0;
  2577     TInt simState = 0;
  2821     TInt lEnable = aEnable;
  2578     TInt lEnable = aEnable;
  2822     TInt err(KErrGeneral);
  2579     TInt err(KErrGeneral);
  2823     err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);
  2580     err = RProperty::Get(KPSUidStartup, KPSSimStatus, simState);
  2824     User::LeaveIfError(err);
  2581     User::LeaveIfError(err);