securitydialogs/secuidialognotifiersrv/src/secuidialogoperbasicpinquery.cpp
changeset 63 989397f9511c
parent 59 881d92421467
--- a/securitydialogs/secuidialognotifiersrv/src/secuidialogoperbasicpinquery.cpp	Thu Oct 07 14:07:34 2010 +0300
+++ b/securitydialogs/secuidialognotifiersrv/src/secuidialogoperbasicpinquery.cpp	Thu Oct 14 13:56:11 2010 +0300
@@ -1,28 +1,26 @@
 /*
-* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
-* All rights reserved.
-* This component and the accompanying materials are made available
-* under the terms of "Eclipse Public License v1.0"
-* which accompanies this distribution, and is available
-* at the URL "http://www.eclipse.org/legal/epl-v10.html".
-*
-* Initial Contributors:
-* Nokia Corporation - initial contribution.
-*
-* Contributors:
-*
-* Description:  Basic PIN query operation in secui dialog
-*
-*/
+ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Nokia Corporation - initial contribution.
+ *
+ * Contributors:
+ *
+ * Description:  Basic PIN query operation in secui dialog
+ *
+ */
 
 #include "secuidialogoperbasicpinquery.h" // CBasicPinQueryOperation
 #include "secuidialogoperationobserver.h" // MSecuiDialogOperationObserver
 #include <hb/hbcore/hbtextresolversymbian.h> // HbTextResolverSymbian
 #include "secuidialogstrace.h"       // TRACE macro
-
 // TODO: fix this
 #include "../../../securitydialogs/SecUi/Inc/SecQueryUi.h"  // CSecQueryUi
-
 #include <secui.h>
 #include <secuisecurityhandler.h>
 #include <gsmerror.h>
@@ -31,21 +29,11 @@
 #include <startupdomainpskeys.h>
 #include <featmgr.h>
 
-const TInt KPhoneIndex( 0 );
-const TInt KTriesToConnectServer( 2 );
-const TInt KTimeBeforeRetryingServerConnection( 50000 );
-
-_LIT( KMmTsyModuleName, "PhoneTsy"); 
+const TInt KPhoneIndex(0);
+const TInt KTriesToConnectServer(2);
+const TInt KTimeBeforeRetryingServerConnection(50000);
 
-// Descriptors for different password queries
-_LIT( KBasicPinQueryKeyStorePassphrase, "Key store passphrase" );
-_LIT( KBasicPinQueryNewKeyStorePassphrase, "New key store passphrase" );
-_LIT( KBasicPinQueryImportedKeyFilePassphrase, "Passphrase of the imported key file" );
-_LIT( KBasicPinQueryExportedKeyFilePassphrase, "Passphrase of the exported key file" );
-_LIT( KBasicPinQueryPKCS12, "PKCS12");
-
-
-
+_LIT( KMmTsyModuleName, "PhoneTsy");
 
 // ======== MEMBER FUNCTIONS ========
 
@@ -53,13 +41,11 @@
 // CBasicPinQueryOperation::NewL()
 // ---------------------------------------------------------------------------
 //
-CBasicPinQueryOperation* CBasicPinQueryOperation::NewL(
-        MSecuiDialogOperationObserver& aObserver, const RMessage2& aMessage,
-        TInt aReplySlot )
+CBasicPinQueryOperation* CBasicPinQueryOperation::NewL(MSecuiDialogOperationObserver& aObserver, const RMessage2& aMessage, TInt aReplySlot)
     {
-    TRACE( "CBasicPinQueryOperation::NewL, aMessage 0x%08x", aMessage.Handle() );
-    TRACE( "CBasicPinQueryOperation::NewL, aMessage.Function = 0x%08x", aMessage.Function() );
-    return new( ELeave ) CBasicPinQueryOperation( aObserver, aMessage, aReplySlot );
+    RDEBUG("aMessage.Handle()", aMessage.Handle());
+    RDEBUG("aMessage.Function()", aMessage.Function());
+    return new (ELeave) CBasicPinQueryOperation(aObserver, aMessage, aReplySlot);
     }
 
 // ---------------------------------------------------------------------------
@@ -68,24 +54,24 @@
 //
 CBasicPinQueryOperation::~CBasicPinQueryOperation()
     {
-    TRACE( "CBasicPinQueryOperation::~CBasicPinQueryOperation" );
+    RDEBUG("0", 0);
     Cancel();
-    iPinInput = NULL;   // not owned
+    iPinInput = NULL; // not owned
     }
 
 // ---------------------------------------------------------------------------
 // CBasicPinQueryOperation::StartL()
 // ---------------------------------------------------------------------------
 //
-void CBasicPinQueryOperation::StartL( const TDesC8& aBuffer )
+void CBasicPinQueryOperation::StartL(const TDesC8& aBuffer)
     {
-    TRACE( "CBasicPinQueryOperation::StartL" );
-    iPinInput = reinterpret_cast< const TPINInput* >( aBuffer.Ptr() );
-    ASSERT( iPinInput != NULL );
+    RDEBUG("0", 0);
+    iPinInput = reinterpret_cast<const TPINInput*> (aBuffer.Ptr());
+    ASSERT(iPinInput != NULL);
 
     iStatus = KRequestPending;
     TRequestStatus* status = &iStatus;
-    User::RequestComplete( status, KErrNone );
+    User::RequestComplete(status, KErrNone);
     SetActive();
     }
 
@@ -95,7 +81,7 @@
 //
 void CBasicPinQueryOperation::CancelOperation()
     {
-    TRACE( "CBasicPinQueryOperation::CancelOperation" );
+    RDEBUG("0", 0);
     // nothing to do
     }
 
@@ -105,193 +91,129 @@
 //
 void CBasicPinQueryOperation::RunL()
     {
-    TRACE( "CBasicPinQueryOperation::RunL, iStatus.Int()=%d", iStatus.Int() );
-    User::LeaveIfError( iStatus.Int() );
+    RDEBUG("iStatus.Int()", iStatus.Int());
+    User::LeaveIfError(iStatus.Int());
 
-    TBool isRetry = ( iPinInput->iOperation & EPINValueIncorrect );
-    if( isRetry )
+    TBool isRetry = (iPinInput->iOperation & EPINValueIncorrect);
+    if (isRetry)
         {
         // Show "Invalid PIN code" error note, as previous attempt was failed.
         // TODO: localized UI string needed
-        _LIT( KInvalidPinCode, "Invalid PIN code" );
-        ShowWarningNoteL( KInvalidPinCode );
-        }
-TRACE( "CBasicPinQueryOperation::RunL, iPinInput->iOperation=%d", iPinInput->iOperation );
-
-    HBufC* caption = NULL;
-    if( iPinInput->iPIN.iPINLabel == KBasicPinQueryKeyStorePassphrase )
-        {
-        	TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryKeyStorePassphrase =%d", 1 );
-
-        // TODO: localized UI string needed
-        _LIT( KText, "Keystore password:" );
-        caption = KText().AllocLC();
+        _LIT(KInvalidPinCode, "Invalid PIN code");
+        ShowWarningNoteL( KInvalidPinCode);
         }
-    else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryNewKeyStorePassphrase )
-        {
-        	TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryNewKeyStorePassphrase =%d", 1 );
-
-        // "Keystore password must be created for using private keys."
-        // SecUi creates two input fields when caption contains two labels
-        // separated with a vertical bar. SecUi verifies that user types the
-        // same passphrase in both fields.
-        // TODO: localized UI strings needed
-        _LIT( KText, "Create keystore password:|Verify:" );
-        caption = KText().AllocLC();
-        }
-    else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryImportedKeyFilePassphrase )
-        {
-        	TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryImportedKeyFilePassphrase =%d", 1 );
+    RDEBUG("iPinInput->iOperation", iPinInput->iOperation);
 
-        // "Enter code for imported key:"
-        // TODO: localized UI strings needed
-        _LIT( KText, "Enter code for imported key:|Verify:" );
-        caption = KText().AllocLC();
-        }
-    else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryExportedKeyFilePassphrase )
-        {
-        	TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryExportedKeyFilePassphrase =%d", 1 );
-
-        // "Enter new code for exported key:"
-        // TODO: localized UI strings needed
-        _LIT( KText, "Enter new code for exported key:|Verify:" );
-        caption = KText().AllocLC();
-        }
-    else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryPKCS12 )
-        {
-        	TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryPKCS12 =%d", 1 );
-
-        // "Password for %U:", PKCS#12 password query prompt
-        // TODO: localized UI string needed
-        _LIT( KText, "Password for PKCS#12 file:" );
-        caption = KText().AllocLC();
-        }
-    else
-        {
-        	TRACE( "CBasicPinQueryOperation::RunL, else =%d", 1 );
-
-        // "Enter code for %0U in %1U"
-        // Data query for PIN request in keystore where %0U is the PIN's name %1U is the keystore's name.
-        // TODO: EEnterPinNR
-        _LIT( KText, "86" );
-        caption = KText().AllocLC();
-        }
     iPinValue.Copy(_L("0"));
-		TRACE( "CBasicPinQueryOperation::RunL, 1 =%d", 1 );
+    RDEBUG("0", 0);
 
     TInt resultVerif = KErrNone;
-		TRACE( "CBasicPinQueryOperation::RunL, 1 =%d", 1 );
+    RDEBUG("0", 0);
+
+        {
+        RMobilePhone iPhone;
+
+        TInt err(KErrGeneral);
+        RDEBUG("ESecurityQueryActive", ESecurityQueryActive);
+        err = RProperty::Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryActive);
+        RDEBUG("err", err);
 
+        TInt thisTry(0);
+        RTelServer iTelServer;
+        RMmCustomAPI iCustomPhone;
+        while ((err = iTelServer.Connect()) != KErrNone && (thisTry++) <= KTriesToConnectServer)
             {
-		   					RMobilePhone	iPhone;
+            User::After( KTimeBeforeRetryingServerConnection);
+            }
+        err = iTelServer.LoadPhoneModule(KMmTsyModuleName);
+        RTelServer::TPhoneInfo PhoneInfo;
+        err = iTelServer.SetExtendedErrorGranularity(RTelServer::EErrorExtended);
+        err = iTelServer.GetPhoneInfo(KPhoneIndex, PhoneInfo);
+        err = iPhone.Open(iTelServer, PhoneInfo.iName);
+        err = iCustomPhone.Open(iPhone);
+        RDEBUG("err", err);
+        CSecurityHandler* handler = new (ELeave) CSecurityHandler(iPhone);
+        CleanupStack::PushL(handler);
+        // TSecUi::InitializeLibL(); 
+        RDEBUG("0", 0);
+        RMobilePhone::TMobilePhoneSecurityEvent iEvent;
+        TInt lEvent = iPinInput->iOperation;
+        RDEBUG("lEvent", lEvent);
+        if (lEvent >= 0x1000) // flag for iStartUp
+            {
+            lEvent -= 0x1000;
+            }
+        iEvent = static_cast<RMobilePhone::TMobilePhoneSecurityEvent> (lEvent);
+        RDEBUG("iEvent", iEvent);
+        RDEBUG("iStartUp", iStartUp);
+        TRAPD(resultHandler, handler->HandleEventL(iEvent, iStartUp, resultVerif));
+        RDEBUG("resultHandler", resultHandler);
+        RDEBUG("resultVerif", resultVerif);
 
-								TInt err( KErrGeneral);
-								TRACE( "CBasicPinQueryOperation::RunL, ESecurityQueryActive =%d", ESecurityQueryActive );
-								err = RProperty::Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryActive);
-								TRACE( "CBasicPinQueryOperation::RunL, err =%d", err );
-								
-								TInt thisTry( 0);
-								RTelServer iTelServer;
-								RMmCustomAPI iCustomPhone;
-								while ( ( err = iTelServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer )
-								{
-								User::After( KTimeBeforeRetryingServerConnection );
-								}
-								err = iTelServer.LoadPhoneModule( KMmTsyModuleName );
-								RTelServer::TPhoneInfo PhoneInfo;
-								err = iTelServer.SetExtendedErrorGranularity( RTelServer::EErrorExtended ) ;
-								err = iTelServer.GetPhoneInfo( KPhoneIndex, PhoneInfo ) ;
-								err = iPhone.Open( iTelServer, PhoneInfo.iName ) ;
-								err = iCustomPhone.Open( iPhone ) ;
-								TRACE( "CBasicPinQueryOperation::RunL, err =%d", err );
-						    CSecurityHandler* handler = new(ELeave) CSecurityHandler(iPhone);
-						    CleanupStack::PushL(handler);
-						    // TSecUi::InitializeLibL(); 
-								TRACE( "CBasicPinQueryOperation::RunL, TMobilePhoneSecurityEvent 1 =%d", 1 );
-								RMobilePhone::TMobilePhoneSecurityEvent iEvent;
-						    TInt lEvent = iPinInput->iOperation;
-						    TRACE( "CBasicPinQueryOperation::RunL, lEvent =%d", lEvent );
-								if( lEvent >= 0x1000 )	// flag for iStartUp
-									{
-									lEvent-=0x1000;
-									}
-						    iEvent = static_cast<RMobilePhone::TMobilePhoneSecurityEvent>(lEvent);
-						    TRACE( "CBasicPinQueryOperation::RunL, iEvent =%d", iEvent );
-						    TRACE( "CBasicPinQueryOperation::RunL, TBool iStartUp =%d", iStartUp );
-						    TRAPD( resultHandler, handler->HandleEventL( iEvent, iStartUp, resultVerif ) );
-						    TRACE( "CBasicPinQueryOperation::RunL, resultHandler =%d", resultHandler );
-						    TRACE( "CBasicPinQueryOperation::RunL, resultVerif =%d", resultVerif );
-   
-						    // if something went wrong cancel the code request
-						    if (resultHandler)
-						        {
-						        if(resultVerif==KErrNone)	// if the process failed, then the result shoud also indicate the failure (unless it does it already)
-						        	resultVerif = resultHandler;
-						    TRACE( "CBasicPinQueryOperation::RunL, iEvent =%d", iEvent );
-								TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma ));
-								TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin ));
-						        switch (iEvent)
-						            {
-						            case RMobilePhone::EUniversalPinRequired:
-						                if(wcdmaSupported || upinSupported)
-						                  {
-						                   iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPin);
-						                  }
-						                break;
-						            case RMobilePhone::EUniversalPukRequired:
-						                if(wcdmaSupported || upinSupported)
-						                  {
-						                   iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPuk);
-						                  }
-						                break;
-									case RMobilePhone::EPin1Required:
-						                iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin1);
-						                break;
-									case RMobilePhone::EPuk1Required:
-						                iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk1);
-						                break;
-									case RMobilePhone::EPin2Required:
-						                iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin2);
-						                break;
-									case RMobilePhone::EPuk2Required:
-						                iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk2);
-						                break;
-									case RMobilePhone::EPhonePasswordRequired:
-						                iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePhonePassword);
-						                break;
-						            default:
-         								    TRACE( "CBasicPinQueryOperation::RunL, default iEvent =%d", iEvent );
-						                break;
-						            }
-						        }
-						
-						    // uninitialize security ui
-						    TRACE( "CBasicPinQueryOperation::RunL, PopAndDestroy(handler) =%d", 0 );
-						    CleanupStack::PopAndDestroy(handler); // handler
-								TRACE( "CBasicPinQueryOperation::RunL, UnInitializeLib =%d", 1 );
-						    TSecUi::UnInitializeLib();  
-								TRACE( "CBasicPinQueryOperation::RunL, ESecurityQueryNotActive =%d", ESecurityQueryNotActive );
-								err = RProperty::Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryNotActive);
-								TRACE( "CBasicPinQueryOperation::RunL, err =%d", err );
-						    //close ETel connection
-						    if (iTelServer.Handle())
-						        {
-						        TRACE( "CBasicPinQueryOperation::RunL, iPhone.Close =%d", 0 );
-						        iPhone.Close();
-						        iTelServer.UnloadPhoneModule(KMmTsyModuleName);
-						        iTelServer.Close();
-						        TRACE( "CBasicPinQueryOperation::RunL, iTelServer.Close =%d", 1 );
-						        }
+        // if something went wrong cancel the code request
+        if (resultHandler)
+            {
+            if (resultVerif == KErrNone) // if the process failed, then the result shoud also indicate the failure (unless it does it already)
+                resultVerif = resultHandler;
+            RDEBUG("iEvent", iEvent);
+            TBool wcdmaSupported(FeatureManager::FeatureSupported(KFeatureIdProtocolWcdma));
+            TBool upinSupported(FeatureManager::FeatureSupported(KFeatureIdUpin));
+            switch (iEvent)
+                {
+                case RMobilePhone::EUniversalPinRequired:
+                    if (wcdmaSupported || upinSupported)
+                        {
+                        iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPin);
+                        }
+                    break;
+                case RMobilePhone::EUniversalPukRequired:
+                    if (wcdmaSupported || upinSupported)
+                        {
+                        iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPuk);
+                        }
+                    break;
+                case RMobilePhone::EPin1Required:
+                    iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin1);
+                    break;
+                case RMobilePhone::EPuk1Required:
+                    iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk1);
+                    break;
+                case RMobilePhone::EPin2Required:
+                    iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin2);
+                    break;
+                case RMobilePhone::EPuk2Required:
+                    iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk2);
+                    break;
+                case RMobilePhone::EPhonePasswordRequired:
+                    iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePhonePassword);
+                    break;
+                default:
+                    RDEBUG("default iEvent", iEvent);
+                    break;
+                }
             }
 
-
-    ReturnResultL( resultVerif );
+        // uninitialize security ui
+        RDEBUG("PopAndDestroy 0", 0);
+        CleanupStack::PopAndDestroy(handler); // handler
+        RDEBUG("UnInitializeLib 0", 0);
+        TSecUi::UnInitializeLib();
+        RDEBUG("ESecurityQueryNotActive", ESecurityQueryNotActive);
+        err = RProperty::Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryNotActive);
+        RDEBUG("err", err);
+        //close ETel connection
+        if (iTelServer.Handle())
+            {
+            RDEBUG("iPhone.Close()", 0);
+            iPhone.Close();
+            iTelServer.UnloadPhoneModule(KMmTsyModuleName);
+            iTelServer.Close();
+            RDEBUG("0", 0);
+            }
+        }
 
-    if( caption )
-        {
-        CleanupStack::PopAndDestroy( caption );
-        caption = NULL;
-        }
+    ReturnResultL(resultVerif);
+
     }
 
 // ---------------------------------------------------------------------------
@@ -300,40 +222,39 @@
 //
 void CBasicPinQueryOperation::DoCancel()
     {
-    TRACE( "CBasicPinQueryOperation::DoCancel" );
+    RDEBUG("0", 0);
     }
 
 // ---------------------------------------------------------------------------
 // CBasicPinQueryOperation::CBasicPinQueryOperation()
 // ---------------------------------------------------------------------------
 //
-CBasicPinQueryOperation::CBasicPinQueryOperation(
-        MSecuiDialogOperationObserver& aObserver, const RMessage2& aMessage,
-        TInt aReplySlot ) : CSecuiDialogOperation( aObserver, aMessage, aReplySlot )
+CBasicPinQueryOperation::CBasicPinQueryOperation(MSecuiDialogOperationObserver& aObserver, const RMessage2& aMessage, TInt aReplySlot) :
+    CSecuiDialogOperation(aObserver, aMessage, aReplySlot)
     {
-    TRACE( "CBasicPinQueryOperation::CBasicPinQueryOperation, aMessage 0x%08x", aMessage.Handle() );
-    TRACE( "CBasicPinQueryOperation::CBasicPinQueryOperation, aMessage.Function = 0x%08x", aMessage.Function() );
-    iStartUp=EFalse;
-    if(aMessage.Function()>=0x1000)
-    	iStartUp=ETrue;
+    RDEBUG("aMessage.Handle()", aMessage.Handle());
+    RDEBUG("aMessage.Function()", aMessage.Function());
+    iStartUp = EFalse;
+    if (aMessage.Function() >= 0x1000)
+        iStartUp = ETrue;
     }
 
 // ---------------------------------------------------------------------------
 // CBasicPinQueryOperation::ReturnResultL()
 // ---------------------------------------------------------------------------
 //
-void CBasicPinQueryOperation::ReturnResultL( TInt aErrorCode )
+void CBasicPinQueryOperation::ReturnResultL(TInt aErrorCode)
     {
-    TRACE( "CBasicPinQueryOperation::ReturnResultL, begin, aErrorCode=%d", aErrorCode );
-    if( aErrorCode <= KErrNone )	// TODO should skip WriteL is error?
+    RDEBUG("aErrorCode", aErrorCode);
+    if (aErrorCode <= KErrNone) // TODO should skip WriteL is error?
         {
-        TPINValueBuf output( iPinValue );
-        iMessage.WriteL( iReplySlot, output );
+        TPINValueBuf output(iPinValue);
+        iMessage.WriteL(iReplySlot, output);
         }
-    TRACE( "CBasicPinQueryOperation::ReturnResultL, completing msg 0x%08x", iMessage.Handle() );
-    iMessage.Complete( aErrorCode );
-    TRACE( "CBasicPinQueryOperation::ReturnResultL, informing observer" );
+    RDEBUG("Complete iMessage.Handle()", iMessage.Handle());
+    iMessage.Complete(aErrorCode);
+    RDEBUG("informing observer 0", 0);
     iObserver.OperationComplete();
-    TRACE( "CBasicPinQueryOperation::ReturnResultL, end" );
+    RDEBUG("0x99", 0x99);
     }