policymanagement/policyengine/policyengineui/src/PolicyEngineUi.cpp
changeset 0 b497e44ab2fc
child 44 39aa16f3fdc2
child 58 4af31167ea77
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  This file contains the implementation of PolicyEngineUI
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "PolicyEngineUi.h"
       
    21 #include "debug.h"
       
    22 #include "policyengineui.hrh"
       
    23 #include <policyengineuidlgs.rsg>
       
    24 
       
    25 #include <bautils.h>
       
    26 #include <eikenv.h>
       
    27 #include <StringLoader.h>
       
    28 #include <AknQueryDialog.h>
       
    29 #include <eikprogi.h>
       
    30 #include <aknnotewrappers.h>
       
    31 #include <aknmessagequerydialog.h>
       
    32 #include <data_caging_path_literals.hrh>
       
    33 #include "SyncService.h"
       
    34 
       
    35 #include <implementationproxy.h>
       
    36 
       
    37 
       
    38 _LIT( KCUIResourceFileName, "PolicyEngineUIDlgs.rsc" );
       
    39 const TUid KUidPolicyEngineUi = { 0x10207817 };
       
    40 const TUid KScreenOutputChannel = { 0x0000781F };
       
    41 
       
    42 LOCAL_C void CreateNotifiersL( CArrayPtrFlat<MEikSrvNotifierBase2>* aNotifiers );
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 
       
    50 LOCAL_C void CreateNotifiersL( CArrayPtrFlat<MEikSrvNotifierBase2>* aNotifiers )
       
    51 {
       
    52     MEikSrvNotifierBase2 *policyEngineNotifier = CPolicyEngineNotifier::NewL();
       
    53     
       
    54     CleanupStack::PushL( policyEngineNotifier );
       
    55     aNotifiers->AppendL( policyEngineNotifier );
       
    56     CleanupStack::Pop( policyEngineNotifier ); // serNotify
       
    57 	RDEBUG("PolicyEngineUI notifier created!");
       
    58 }
       
    59 
       
    60 
       
    61 
       
    62 CArrayPtr<MEikSrvNotifierBase2>* NotifierArray()
       
    63     { 
       
    64     CArrayPtrFlat<MEikSrvNotifierBase2>* array =
       
    65     new CArrayPtrFlat<MEikSrvNotifierBase2>( 1 );
       
    66 
       
    67     if (array)
       
    68         {
       
    69         TRAPD( err, CreateNotifiersL( array ) );
       
    70         if (err != KErrNone)
       
    71             {
       
    72             delete array;
       
    73             array = NULL;
       
    74             }
       
    75         }
       
    76     return array;
       
    77     }
       
    78 
       
    79 const TImplementationProxy ImplementationTable[] = { {{0x10207817},(TProxyNewLPtr)NotifierArray} };
       
    80 
       
    81 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    82 	{
       
    83 	RDEBUG("PolicyEngineUI notifier detected!");
       
    84 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy) ;
       
    85 	return ImplementationTable;
       
    86 	}
       
    87 
       
    88 
       
    89 
       
    90 CPolicyEngineNotifier::CPolicyEngineNotifier()
       
    91 	{
       
    92 	}
       
    93 
       
    94 
       
    95 CPolicyEngineNotifier::~CPolicyEngineNotifier()
       
    96 	{
       
    97 	//delete and close policy engine ui
       
    98 	delete iPolicyEngineUi;	
       
    99 	}
       
   100 
       
   101 
       
   102 CPolicyEngineNotifier* CPolicyEngineNotifier::NewL()
       
   103 	{
       
   104 	CPolicyEngineNotifier* self = new (ELeave) CPolicyEngineNotifier();
       
   105 	
       
   106 	CleanupStack::PushL( self);
       
   107 	self->ConstructL();	
       
   108 	CleanupStack::Pop();
       
   109 	
       
   110 	return self;
       
   111 	}
       
   112 
       
   113 void CPolicyEngineNotifier::ConstructL()
       
   114 	{
       
   115 	}
       
   116 		
       
   117 
       
   118 void CPolicyEngineNotifier::Release()
       
   119 	{
       
   120 	delete this;	
       
   121 	}
       
   122 
       
   123 
       
   124 CPolicyEngineNotifier::TNotifierInfo CPolicyEngineNotifier::RegisterL()
       
   125 	{
       
   126 	//Registration info
       
   127     iInfo.iUid = KUidPolicyEngineUi;
       
   128     iInfo.iPriority = ENotifierPriorityHigh;
       
   129 	iInfo.iChannel = KScreenOutputChannel;	
       
   130 	
       
   131 	return iInfo;
       
   132 	}
       
   133 
       
   134 
       
   135 CPolicyEngineNotifier::TNotifierInfo CPolicyEngineNotifier::Info() const
       
   136 	{
       
   137 	//Registration info
       
   138 	return iInfo;
       
   139 	}
       
   140 
       
   141 
       
   142 TPtrC8 CPolicyEngineNotifier::StartL(const TDesC8& /*aBuffer*/)
       
   143 	{
       
   144 	return KNullDesC8().Ptr();
       
   145 	}
       
   146 
       
   147 
       
   148 void CPolicyEngineNotifier::Complete( TUserResponse aResponse)
       
   149 	{
       
   150 	RDEBUG("CPolicyEngineNotifier::Complete");
       
   151 
       
   152 	//Write return value to message and compeltes it
       
   153 	if ( aResponse == EUserAccept )
       
   154 		{
       
   155 		iMessage.Write( iReplySlot, KUserAcceptMark, 0);	
       
   156 		}
       
   157 	else
       
   158 		{
       
   159 		iMessage.Write( iReplySlot, KUserDenyMark, 0);	
       
   160 		}
       
   161 	
       
   162     iManager->CancelNotifier( iInfo.iUid );   // Notify framework we've done
       
   163 	iMessage.Complete( KErrNone);
       
   164 	}
       
   165 
       
   166 
       
   167 void CPolicyEngineNotifier::StartL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
   168 	{
       
   169 	RDEBUG("CPolicyEngineNotifier::StartL!");
       
   170 
       
   171 	TInt index = aBuffer.Locate( KDelimeterChar);
       
   172 	
       
   173 	if ( index != KErrNotFound && !iPolicyEngineUi)
       
   174 		{	
       
   175 		//decode name and fingerprint from message
       
   176 		TPtrC8 name = aBuffer.Left( index);
       
   177 		TPtrC8 fingerPrint = aBuffer.Mid( index + 1);
       
   178 
       
   179 		iReplySlot = aReplySlot;
       
   180 		iMessage = aMessage;
       
   181 
       
   182 		//Show policy engine ui dialogs
       
   183 		iPolicyEngineUi = CPolicyEngineUi::NewL();
       
   184 		iPolicyEngineUi->ActivateL( name, fingerPrint, this);
       
   185 		}
       
   186 	else
       
   187 		{
       
   188 		Complete( EUserDeny);
       
   189 		}
       
   190 	}
       
   191 
       
   192 
       
   193 void CPolicyEngineNotifier::Cancel()
       
   194 	{
       
   195 	RDEBUG("CPolicyEngineNotifier::Cancel!");
       
   196 
       
   197 	//Delete policy engine ui
       
   198 	delete iPolicyEngineUi;
       
   199 	iPolicyEngineUi = 0;
       
   200 	}
       
   201 
       
   202 
       
   203 TPtrC8 CPolicyEngineNotifier::UpdateL(const TDesC8& /*aBuffer*/)
       
   204 	{
       
   205 	return KNullDesC8().Ptr();
       
   206 	}
       
   207 
       
   208 CPolicyEngineUi::CPolicyEngineUi()
       
   209 	: CActive( EPriorityStandard)
       
   210     {  
       
   211     }
       
   212 
       
   213 void CPolicyEngineUi::ConstructL()
       
   214     {
       
   215 	RDEBUG("CPolicyEngineUi::ConstructL!");
       
   216 
       
   217     //get pointer to CEikonEnv
       
   218 	iCoeEnv = CEikonEnv::Static();    
       
   219     
       
   220     if ( !iCoeEnv )
       
   221     	{
       
   222 		RDEBUG("Policy engine ui: CoeEnv not found!");
       
   223         User::Leave( KErrGeneral );        
       
   224     	}
       
   225 
       
   226 	//Open resource file
       
   227     TFileName fileName;
       
   228     fileName.Zero();
       
   229 
       
   230     TFileName drivePath;
       
   231     Dll::FileName( drivePath );
       
   232 
       
   233     fileName.Append( TParsePtrC( drivePath ).Drive() );
       
   234     fileName.Append( KDC_RESOURCE_FILES_DIR );
       
   235     fileName.Append( KCUIResourceFileName );   
       
   236     
       
   237     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   238 
       
   239 	//handle to resource file
       
   240     iResourceFileOffset = iCoeEnv->AddResourceFileL( fileName );
       
   241 
       
   242 	RDEBUG("Policy engine ui resources loaded!");
       
   243  	}
       
   244 
       
   245 CPolicyEngineUi* CPolicyEngineUi::NewL()
       
   246 	{
       
   247     CPolicyEngineUi* self = new ( ELeave ) CPolicyEngineUi();
       
   248     CleanupStack::PushL( self );
       
   249     self->ConstructL();
       
   250     CleanupStack::Pop( self );
       
   251     return self; 
       
   252 	}
       
   253 
       
   254 
       
   255 CPolicyEngineUi::~CPolicyEngineUi()
       
   256 	{
       
   257 	RDEBUG("CPolicyEngineUi::~CPolicyEngineUi()");
       
   258 
       
   259     // Close non-modal dialogs
       
   260     if( iResourceFileOffset )
       
   261     	{
       
   262         iCoeEnv->DeleteResourceFile( iResourceFileOffset );
       
   263     	}
       
   264 	
       
   265 	delete iCorporate;
       
   266 	delete iRandomPart;
       
   267 	}
       
   268 
       
   269 
       
   270 void CPolicyEngineUi::ActivateL( const TDesC8& aCorporate, const TDesC8& aRandomPart, CPolicyEngineNotifier* aNotifier)
       
   271 	{
       
   272 	RDEBUG("CPolicyEngineUi::ActivateL");
       
   273 
       
   274 	//reference to notifier (for message completion)
       
   275 	iNotifier = aNotifier;
       
   276 	
       
   277 	//allocate new space for parameters and save them
       
   278 	delete iCorporate;
       
   279 	iCorporate = NULL;
       
   280 	delete iRandomPart;
       
   281 	iRandomPart = NULL;
       
   282 	iCorporate = HBufC::NewL( aCorporate.Length());
       
   283 	iRandomPart = HBufC::NewL( aRandomPart.Length());
       
   284 
       
   285 	iCorporate->Des().Copy( aCorporate);
       
   286 	iRandomPart->Des().Copy( aRandomPart);	
       
   287 	
       
   288 	//add active object to active scheduler and set object active
       
   289 	CActiveScheduler::Add( this);
       
   290 	SetActive();
       
   291 	
       
   292 	//complete request....
       
   293 	TRequestStatus * status = &iStatus;
       
   294 	User::RequestComplete( status, KErrNone);	
       
   295 	}
       
   296 
       
   297 
       
   298 
       
   299 void CPolicyEngineUi::RunL()
       
   300 	{
       
   301 	RDEBUG("CPolicyEngineUi::RunL()");
       
   302 	
       
   303 	//in state ERemove user has already accepted query
       
   304 	if ( ERemove == iState )
       
   305 		{
       
   306 		//show info, remove from scheduler
       
   307 		ShowDialogL( ERemove);
       
   308 		Deque();
       
   309 		iNotifier->Complete( EUserAccept);
       
   310 		return;		
       
   311 		}
       
   312 
       
   313 	if ( EDenied == iState )
       
   314 		{
       
   315 		//show info, remove from scheduler
       
   316 		ShowDialogL( EDenied);
       
   317 		Deque();
       
   318 		iNotifier->Complete( EUserDeny);
       
   319 		return;		
       
   320 		}
       
   321 
       
   322 	//Control dialog
       
   323 	if ( EUserAccept == ShowDialogL( (TDialog) iState))
       
   324 		{
       
   325 		//if user cancel dialog, show deny-dialog and return
       
   326 		iState = iState + 1;
       
   327 		}
       
   328 	else
       
   329 		{
       
   330 		//user press cancel -> state = EDenied
       
   331 		iState = EDenied;
       
   332 		}
       
   333 	
       
   334 	//set active and complete message
       
   335 	SetActive();
       
   336 	TRequestStatus * status = &iStatus;
       
   337 	User::RequestComplete( status, KErrNone);
       
   338 	}
       
   339 
       
   340 
       
   341 
       
   342 void CPolicyEngineUi::DoCancel()
       
   343 	{
       
   344 	}
       
   345 
       
   346 
       
   347 
       
   348 CPolicyEngineUi::TDlgResp CPolicyEngineUi::ShowConfirmationQueryL( 
       
   349 	const TDesC& aText, const TBool& aWithCancel)
       
   350 	{
       
   351 	//create dialog
       
   352     CAknQueryDialog* note = 
       
   353         CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
       
   354 				
       
   355 	//select correct text resource 					 
       
   356 	TInt resource = R_POLICYENGINEUI_CONFIRMATION_QUERY;
       
   357 	
       
   358 	if ( !aWithCancel )
       
   359 		{
       
   360 		resource = R_POLICYENGINEUI_CONFIRMATION;
       
   361 		}			   
       
   362 						
       
   363 	//execute dialog, dialog contains self destruction			 
       
   364     TInt response = note->ExecuteLD( resource, aText );
       
   365     
       
   366 	if ( response )
       
   367 		{
       
   368 		return EOkResp;
       
   369 		}
       
   370 	
       
   371 	return ECancelResp;
       
   372 	}
       
   373 
       
   374 
       
   375 CPolicyEngineUi::TDlgResp CPolicyEngineUi::DataQueryL( const TDesC& aText, TDes& aInput )
       
   376 	{
       
   377 
       
   378 	//Create dialog with reference to input descriptor
       
   379 	CAknTextQueryDialog* dlg = 
       
   380 		CAknTextQueryDialog::NewL( aInput, CAknQueryDialog::ENoTone);
       
   381 
       
   382 	//set prompt
       
   383 	CleanupStack::PushL( dlg);
       
   384 	dlg->SetPromptL( aText);
       
   385 	CleanupStack::Pop();
       
   386 	
       
   387 	//execute dialog, dialog contains self destruction			 
       
   388 	TInt response = dlg->ExecuteLD( R_POLICYENGINEUI_DATA_QUERY);
       
   389 	
       
   390 	if ( response )
       
   391 		{
       
   392 		return EOkResp;
       
   393 		}
       
   394 	
       
   395 	return ECancelResp;
       
   396 	}
       
   397 
       
   398 
       
   399 TInt CPolicyEngineUi::ShowDialogL( const TDialog& aDialog)
       
   400 	{
       
   401 	TInt response = EUserDeny;
       
   402 
       
   403 	//select correct dialog
       
   404 	switch ( aDialog)
       
   405 		{
       
   406 		case EControl : 
       
   407 			{
       
   408 			response = ShowPossessionMessageQueryL();
       
   409 			break;
       
   410 			}
       
   411 		case ERemove:
       
   412 			{
       
   413 			//load resource
       
   414 		    HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_TRUST_ESTABLISHED );
       
   415 			
       
   416 			TInt length1 = displayString->Length();
       
   417 			HBufC16* trustString = HBufC16::NewLC ( length1  );
       
   418 			TPtr bufPtr = trustString -> Des();
       
   419 			bufPtr.Append (*displayString);
       
   420 			// Hide background connecting note
       
   421 			CSyncService *syncService =
       
   422                             CSyncService::NewL(NULL, KDevManServiceStart);
       
   423                     if (syncService)
       
   424                         {
       
   425                         syncService->EnableProgressNoteL(EFalse);
       
   426                         }
       
   427 
       
   428                     delete syncService;
       
   429 			
       
   430 			response = ShowConfirmationQueryL( *trustString, EFalse);
       
   431 			CleanupStack::PopAndDestroy();
       
   432 			CleanupStack::PopAndDestroy();
       
   433 			
       
   434 			break;
       
   435 			}
       
   436 		case EDenied:
       
   437 			{
       
   438 			//load resource
       
   439 			TBuf<100> array(*iCorporate);
       
   440 		  HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_DENIED_NOTE, array);
       
   441 			
       
   442 			//show dialog and get response
       
   443 			response = ShowConfirmationQueryL( *displayString, EFalse);
       
   444 			//delete resource
       
   445 			CleanupStack::PopAndDestroy();
       
   446 			
       
   447 			break;
       
   448 			}		
       
   449 		case EUnMatch:
       
   450 			{
       
   451 			//load resource
       
   452 		    HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_UNMATCH_NOTE);
       
   453 			
       
   454 			//show dialog and get response
       
   455 			response = ShowConfirmationQueryL( *displayString, ETrue);
       
   456 			//delete resource
       
   457 			CleanupStack::PopAndDestroy();
       
   458 			
       
   459 			break;
       
   460 			}
       
   461 		case EQuestion:
       
   462 			{
       
   463 			//question note prompt
       
   464 			TBuf<100> array(*iCorporate);
       
   465     		HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_QUESTION_NOTE,array);
       
   466 			TBuf<RANDOM_PART_MAX_SIZE> input;
       
   467 			TBool ready = EFalse;
       
   468 
       
   469 			//until cancel pressed or valid user gives valid certificate part
       
   470 			while ( !ready)
       
   471 				{
       
   472 				//data query
       
   473 				CPolicyEngineUi::TDlgResp resp = DataQueryL( *displayString, input);
       
   474 				if ( resp == EUserAccept )
       
   475 					{
       
   476 					if ( input.CompareF( *iRandomPart) != 0)
       
   477 						{
       
   478 						//if user input doesn't match
       
   479 						if ( EUserDeny == ShowDialogL( EUnMatch))
       
   480 							{
       
   481 							//if user cancel dialog, show deny-dialog and return
       
   482 							response = EUserDeny;
       
   483 							break;
       
   484 							}			
       
   485 						}
       
   486 					else
       
   487 						{
       
   488 						response = EUserAccept;
       
   489 						ready = ETrue;				
       
   490 						}
       
   491 					}
       
   492 				else
       
   493 					{
       
   494 					//if user cancel dialog, show deny-dialog and return
       
   495 					response = EUserDeny;
       
   496 					break;
       
   497 					}
       
   498 				}	
       
   499 	
       
   500 			//delete resource
       
   501 			CleanupStack::PopAndDestroy();
       
   502 			break;
       
   503 			}
       
   504 		default:
       
   505 		break;
       
   506 		}
       
   507 	
       
   508 	return response;
       
   509 	}
       
   510 
       
   511 
       
   512 CPolicyEngineUi::TDlgResp CPolicyEngineUi::ShowPossessionMessageQueryL()
       
   513 	{
       
   514 	HBufC* securityInfoString = StringLoader::LoadLC( R_POLICYENGINEUI_SECURITY_INFO_NOTE );
       
   515 	TBuf<60> buffer;
       
   516 	buffer.Copy( *securityInfoString );
       
   517 	CleanupStack::PopAndDestroy( securityInfoString );
       
   518 		
       
   519 	//load resource
       
   520 	TBuf<100> array(*iCorporate);
       
   521   HBufC* displayString = StringLoader::LoadLC( R_POLICYENGINEUI_CONTROL_NOTE, array);
       
   522 			
       
   523 			
       
   524 	//show dialog and get response
       
   525 	CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *displayString );
       
   526     dlg->PrepareLC( R_POLICY_ENGINE_POSSESSION_INFO );
       
   527     dlg->QueryHeading()->SetTextL( buffer );
       
   528     TInt response = dlg->RunLD();
       
   529     
       
   530     CleanupStack::PopAndDestroy();
       
   531     
       
   532 	if ( response )
       
   533 		{
       
   534 		return EOkResp;
       
   535 		}
       
   536 	
       
   537 	return ECancelResp; 
       
   538 	}
       
   539 
       
   540 
       
   541 
       
   542 
       
   543