securitydialogs/SecUi/Src/SecQueryUi.cpp
changeset 15 318c4eab2439
child 17 8957df7b0072
equal deleted inserted replaced
14:b75757c81051 15:318c4eab2439
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of RSecQueryUiCli class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "SecQueryUi.h"                              // CSecQueryUi
       
    19 // #include <SecQueryUidefs.h>                          // SIF UI device dialog parameters
       
    20 #include <hb/hbcore/hbsymbiandevicedialog.h>    // CHbDeviceDialog
       
    21 #include <hb/hbcore/hbsymbianvariant.h>         // CHbSymbianVariantMap
       
    22 #include <apgicnfl.h>                           // CApaMaskedBitmap
       
    23 
       
    24 
       
    25 // Variant map keys for notification device dialog
       
    26 _LIT( KNotifDeviceDialogLiteral, "com.nokia.hb.devicenotificationdialog/1.0" );
       
    27 _LIT( KNotifDeviceDialogKeyTimeOut, "timeout" );
       
    28 _LIT( KNotifDeviceDialogKeyIconName, "iconName" );
       
    29 _LIT( KNotifDeviceDialogKeyText, "text" );
       
    30 _LIT( KNotifDeviceDialogKeyTitle, "title" );
       
    31 _LIT( KNotifDeviceDialogKeyTouchActivation, "touchActivation" );
       
    32 _LIT( KNotifDeviceDialogKeyActivated, "result" );
       
    33 _LIT( KNotifDeviceDialogKeyActivatedValue, "activated" );
       
    34 _LIT( KNotifDeviceDialogKeyTitleTextWrapping, "titleTextWrapping" );
       
    35 
       
    36 const TInt KMaxNumberOfPINAttempts(3);
       
    37 const TInt KLastRemainingInputAttempt(1);
       
    38 
       
    39 const TUid KSWInstHelpUid = { 0x101F8512 };	// TODO
       
    40 
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CSecQueryUi::NewLC()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C CSecQueryUi* CSecQueryUi::NewLC()
       
    49     {
       
    50     CSecQueryUi* self = new( ELeave ) CSecQueryUi();
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     return self;
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CSecQueryUi::NewL()
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CSecQueryUi* CSecQueryUi::NewL()
       
    61     {
       
    62     CSecQueryUi* self = CSecQueryUi::NewLC();
       
    63     CleanupStack::Pop( self );
       
    64     return self;
       
    65     }
       
    66 
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CSecQueryUi::~CSecQueryUi()
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CSecQueryUi::~CSecQueryUi()
       
    73     {
       
    74     Cancel();
       
    75     delete iWait;
       
    76     delete iDeviceDialog;
       
    77     delete iVariantMap;
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // CSecQueryUi::InstallConfirmationQueryL()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C TBool CSecQueryUi::InstallConfirmationQueryL( TInt aType, RMobilePhone::TMobilePassword& password )
       
    85 /*
       
    86         const TDesC& aAppName,
       
    87         const TDesC& aIconFile, const TDesC& aAppVersion, TInt aAppSize,
       
    88         const TDesC& aAppDetails ) */
       
    89     {
       
    90     RDebug::Printf( "%s %s (%u) aType=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aType );
       
    91     RDebug::Printf( "%s %s (%u) password=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
    92     TInt	ESecQueryUiInstallConfirmationQueryType=0x101;
       
    93     ClearParamsAndSetNoteTypeL( ESecQueryUiInstallConfirmationQueryType );
       
    94 
       
    95     AddParamL( _L("KSecQueryUiApplicationName"), _L("SecUi") );
       
    96 
       
    97 		_LIT(KTitle, "title");
       
    98     _LIT(KTitleValue1, "Enter PIN");
       
    99     _LIT(KTitleValue2, "Enter PIN with care");
       
   100     _LIT(KTitleValue3, "Enter PIN last");
       
   101     if(aType==KMaxNumberOfPINAttempts)
       
   102     	AddParamL( KTitle, KTitleValue1 );
       
   103     else if(aType> KLastRemainingInputAttempt)
       
   104     	AddParamL( KTitle, KTitleValue2 );
       
   105     else
       
   106     	AddParamL( KTitle, KTitleValue3 );
       
   107     
       
   108 		_LIT( KCodeTop, "codeTop" );						_LIT( KCodeTopValue, "codeTop" );
       
   109     AddParamL( KCodeTop, KCodeTopValue );
       
   110 
       
   111 		RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   112 	  DisplayDeviceDialogL();
       
   113     User::LeaveIfError( WaitUntilDeviceDialogClosed() );
       
   114     password.Copy(iPassword);
       
   115     return( iReturnValue == KErrNone );
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CSecQueryUi::SecQueryDialog()
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 EXPORT_C TInt CSecQueryUi::SecQueryDialog(const TDesC& aCaption, TDes& aDataText, TInt aMinLength,TInt aMaxLength,TInt aMode)
       
   123     {
       
   124     RDebug::Printf( "%s %s (%u) aCaption=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
       
   125     RDebug::Print( aCaption );
       
   126     RDebug::Printf( "%s %s (%u) aMode=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aMode );
       
   127 
       
   128     ClearParamsAndSetNoteTypeL( aMode );
       
   129     AddParamL( _L("KSecQueryUiApplicationName"), aCaption );
       
   130 
       
   131 		_LIT(KTitle, "title");
       
   132     // _LIT(KTitleValue1, "Enter PIN");
       
   133    	AddParamL( KTitle, aCaption );
       
   134     
       
   135 		_LIT( KCodeTop, "codeTop" );						_LIT( KCodeTopValue, "codeTop" );
       
   136     AddParamL( KCodeTop, KCodeTopValue );
       
   137 
       
   138 		RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   139 	  DisplayDeviceDialogL();
       
   140     User::LeaveIfError( WaitUntilDeviceDialogClosed() );
       
   141     aDataText.Copy(iPassword);
       
   142     return( iReturnValue == KErrNone );
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // CSecQueryUi::DisplayInformationNoteL()
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C void CSecQueryUi::DisplayInformationNoteL( const TDesC& aText )
       
   150     {
       
   151     /*
       
   152     ClearParamsAndSetNoteTypeL( SecQueryUiInformationNote );
       
   153     AddParamL( KNotifDeviceDialogKeyText, aText );
       
   154     AddParamL( KNotifDeviceDialogKeyTimeOut, 0 );
       
   155     iDeviceDialog->Show( KNotifDeviceDialogLiteral, *iVariantMap, this );
       
   156     User::LeaveIfError( WaitUntilDeviceDialogClosed() );
       
   157     */
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CSecQueryUi::DisplayWarningNoteL()
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 EXPORT_C void CSecQueryUi::DisplayWarningNoteL( const TDesC& aText )
       
   165     {
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CSecQueryUi::DisplayErrorNoteL()
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 EXPORT_C void CSecQueryUi::DisplayErrorNoteL( const TDesC& aText )
       
   173     {
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CSecQueryUi::DisplayPermanentNoteL()
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void CSecQueryUi::DisplayPermanentNoteL( const TDesC& aText )
       
   181     {
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CSecQueryUi::ClosePermanentNote()
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 EXPORT_C void CSecQueryUi::ClosePermanentNote()
       
   189     {
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CSecQueryUi::DisplayProgressNoteL()
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 EXPORT_C void CSecQueryUi::DisplayProgressNoteL( const TDesC& aText, TInt aFinalValue )
       
   197     {
       
   198 /*
       
   199     ClearParamsAndSetNoteTypeL( ESecQueryUiProgressNoteType );
       
   200     AddParamL( KSecQueryUiProgressNoteText, aText );
       
   201     AddParamL( KSecQueryUiProgressNoteFinalValue, aFinalValue );
       
   202     DisplayDeviceDialogL();
       
   203 */    }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // CSecQueryUi::UpdateProgressNoteValueL()
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 EXPORT_C void CSecQueryUi::UpdateProgressNoteValueL( TInt aNewValue )
       
   210     {
       
   211 /*
       
   212     ClearParamsAndSetNoteTypeL( ESecQueryUiProgressNoteType );
       
   213     AddParamL( KSecQueryUiProgressNoteValue, aNewValue );
       
   214     DisplayDeviceDialogL();
       
   215 */    }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CSecQueryUi::CloseProgressNoteL()
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 EXPORT_C void CSecQueryUi::CloseProgressNoteL()
       
   222     {
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CSecQueryUi::DisplayWaitNoteL()
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C void CSecQueryUi::DisplayWaitNoteL( const TDesC& aText,
       
   230         TRequestStatus& aStatus )
       
   231     {
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // CSecQueryUi::CloseWaitNote()
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C void CSecQueryUi::CloseWaitNote()
       
   239     {
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // CSecQueryUi::LaunchHelpL()
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 EXPORT_C void CSecQueryUi::LaunchHelpL( const TDesC& aContext, const TUid& aUid )
       
   247     {
       
   248     }
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CSecQueryUi::LaunchHelpL()
       
   252 // ---------------------------------------------------------------------------
       
   253 //
       
   254 EXPORT_C void CSecQueryUi::LaunchHelpL( const TDesC& aContext )
       
   255     {
       
   256     LaunchHelpL( aContext, KSWInstHelpUid );
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CSecQueryUi::DoCancel()
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CSecQueryUi::DoCancel()
       
   264     {
       
   265     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   266     if( iWait && iWait->IsStarted() && iWait->CanStopNow() )
       
   267         {
       
   268         iCompletionCode = KErrCancel;
       
   269         iWait->AsyncStop();
       
   270         }
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // CSecQueryUi::RunL()
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CSecQueryUi::RunL()
       
   278     {
       
   279     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   280     if( iWait )
       
   281         {
       
   282         iWait->AsyncStop();
       
   283         }
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CSecQueryUi::DataReceived()
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CSecQueryUi::DataReceived( CHbSymbianVariantMap& aData )
       
   291     {
       
   292     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   293     const CHbSymbianVariant* acceptedVariant = aData.Get( _L("accepted") );	// KSecQueryUiQueryAccepted
       
   294     if( acceptedVariant )
       
   295         {
       
   296         TBool* acceptedValue = acceptedVariant->Value<TBool>();
       
   297         if( acceptedValue && *acceptedValue )
       
   298             {
       
   299             iReturnValue = KErrNone;
       
   300             }
       
   301         else
       
   302             {
       
   303             iReturnValue = KErrCancel;
       
   304             }
       
   305         }
       
   306     const CHbSymbianVariant* acceptedVariantTop = aData.Get( _L("codeTop") );	// KSecQueryUiQueryAccepted
       
   307     if( acceptedVariantTop )
       
   308         {
       
   309         TPtrC acceptedValueTop = *acceptedVariantTop->Value<TDesC>();
       
   310         RDebug::Printf( "%s %s (%u) acceptedValueTop=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   311    	    RDebug::Print( acceptedValueTop );
       
   312    	    iPassword.Copy(acceptedValueTop);
       
   313         }
       
   314     }
       
   315 
       
   316 // ---------------------------------------------------------------------------
       
   317 // CSecQueryUi::DeviceDialogClosed()
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 void CSecQueryUi::DeviceDialogClosed( TInt aCompletionCode )
       
   321     {
       
   322     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   323     iCompletionCode = aCompletionCode;
       
   324     iIsDisplayingDialog = EFalse;
       
   325 
       
   326     TRequestStatus* status( &iStatus );
       
   327     User::RequestComplete( status, KErrNone );
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // CSecQueryUi::CSecQueryUi()
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 CSecQueryUi::CSecQueryUi() : CActive( CActive::EPriorityStandard )
       
   335     {
       
   336     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   337     CActiveScheduler::Add( this );
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // CSecQueryUi::ConstructL()
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 void CSecQueryUi::ConstructL()
       
   345     {
       
   346     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   347     iWait = new( ELeave ) CActiveSchedulerWait;
       
   348     // iDeviceDialog is allocated later, first call of DisplayDeviceDialogL()
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CSecQueryUi::ClearParamsL()
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 void CSecQueryUi::ClearParamsL()
       
   356     {
       
   357     if( iVariantMap )
       
   358         {
       
   359         delete iVariantMap;
       
   360         iVariantMap = NULL;
       
   361         }
       
   362     iVariantMap = CHbSymbianVariantMap::NewL();
       
   363     }
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // CSecQueryUi::ClearParamsAndSetNoteTypeL()
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 void CSecQueryUi::ClearParamsAndSetNoteTypeL( TInt aType )
       
   370     {
       
   371     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   372     ClearParamsL();
       
   373     AddParamL( _L("type"), aType );
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CSecQueryUi::AddParamL()
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CSecQueryUi::AddParamL( const TDesC& aKey, TInt aValue )
       
   381     {
       
   382     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   383     CHbSymbianVariant* variant = NULL;
       
   384     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EInt );
       
   385     iVariantMap->Add( aKey, variant );
       
   386     }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // CSecQueryUi::AddParamL()
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 void CSecQueryUi::AddParamL( const TDesC& aKey, const TDesC& aValue )
       
   393     {
       
   394     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   395     CHbSymbianVariant* variant = NULL;
       
   396     variant = CHbSymbianVariant::NewL( &aValue, CHbSymbianVariant::EDes );
       
   397     iVariantMap->Add( aKey, variant );
       
   398     }
       
   399 
       
   400 TInt strlen( const char* aStr )
       
   401     {
       
   402     TInt len = 0;
       
   403     while( *aStr++ != 0 )
       
   404         ++len;
       
   405     return len;
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CSecQueryUi::DisplayDeviceDialogL()
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 void CSecQueryUi::DisplayDeviceDialogL()
       
   413     {
       
   414     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   415     if( iDeviceDialog && iIsDisplayingDialog )
       
   416         {
       
   417         iDeviceDialog->Update( *iVariantMap );
       
   418         }
       
   419     else
       
   420         {
       
   421         if( !iDeviceDialog )
       
   422             {
       
   423             iDeviceDialog = CHbDeviceDialog::NewL();
       
   424             }
       
   425         _LIT( KSecQueryUiDeviceDialog, "com.nokia.secuinotificationdialog/1.0" );
       
   426         RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   427         iDeviceDialog->Show( KSecQueryUiDeviceDialog, *iVariantMap, this );
       
   428         RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   429         iIsDisplayingDialog = ETrue;
       
   430         }
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // CSecQueryUi::WaitUntilDeviceDialogClosed()
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 TInt CSecQueryUi::WaitUntilDeviceDialogClosed()
       
   438     {
       
   439     RDebug::Printf( "%s %s (%u) value=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 0 );
       
   440     iCompletionCode = KErrInUse;
       
   441     iReturnValue = KErrUnknown;
       
   442     if( !IsActive() && iWait && !iWait->IsStarted() )
       
   443         {
       
   444         iStatus = KRequestPending;
       
   445         SetActive();
       
   446         iWait->Start();
       
   447         }
       
   448     return iCompletionCode;
       
   449     }
       
   450