deviceupdatesui/deviceupdates/src/nsmldmsynchandler.cpp
branchRCL_3
changeset 57 6757f1e2efd2
equal deleted inserted replaced
55:c4687ff85147 57:6757f1e2efd2
       
     1 /*
       
     2 * Copyright (c) 2005 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 DM UI component
       
    15 * 	This is part of omadmappui.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 
       
    22 #include <textresolver.h>   // for CTextResolver
       
    23 #include <e32property.h>
       
    24 #include <data_caging_path_literals.hrh>  // for resource and bitmap directories
       
    25 #include <SyncMLErr.h>      // sync error codes
       
    26 #include <DevManInternalCRKeys.h>
       
    27 #include <centralrepository.h>
       
    28 #include <featmgr.h>
       
    29 #include "nsmldmsynchandler.h"
       
    30 #include "nsmldmsyncdebug.h"
       
    31 #include "nsmldmsyncinternalpskeys.h"
       
    32 #include "nsmldmsyncprivatecrkeys.h"
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CNSmlDMSyncHandler::NewL
       
    36 //
       
    37 // Two-phased constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CNSmlDMSyncHandler* CNSmlDMSyncHandler::NewL( RSyncMLSession* aSyncSession,
       
    41                                               CNSmlDMSyncAppEngine* aAppEngine )
       
    42     {
       
    43 	FLOG( "CNSmlDMSyncHandler::NewL()" );
       
    44 
       
    45     CNSmlDMSyncHandler* self =
       
    46         new (ELeave) CNSmlDMSyncHandler( aSyncSession,
       
    47                                          aAppEngine);
       
    48 	CleanupStack::PushL(self);
       
    49 	self->ConstructL();
       
    50 	CleanupStack::Pop(self);
       
    51     return self;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // Destructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CNSmlDMSyncHandler::~CNSmlDMSyncHandler()
       
    59     {
       
    60     FLOG( "CNSmlDMSyncHandler::~CNSmlDMSyncHandler()" );     
       
    61 	delete iActiveCaller;
       
    62 
       
    63 	if ( iSyncRunning )
       
    64 	    {
       
    65 	    TRAP_IGNORE( iSyncJob.StopL() );
       
    66         iSyncJob.Close();
       
    67 	    }
       
    68 	if(iPrimaryAction)
       
    69 	    iPrimaryAction->deleteLater();
       
    70 	
       
    71 	if(iDialog)
       
    72 	    iDialog->deleteLater();
       
    73 	
       
    74 	  FeatureManager::UnInitializeLib();
       
    75 	FLOG( "CNSmlDMSyncHandler::~CNSmlDMSyncHandler() completed" );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CNSmlDMSyncHandler::ConstructL
       
    80 // Symbian 2nd phase constructor can leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CNSmlDMSyncHandler::ConstructL( void )
       
    84     {
       
    85     FLOG( "CNSmlDMSyncHandler::ConstructL" );
       
    86    FeatureManager::InitializeLibL();   	
       
    87 	iActiveCaller = CNSmlDMActiveCaller::NewL(this);
       
    88 	iServerAlertedSync = EFalse;
       
    89 	iSyncRunning = EFalse;
       
    90 	iSyncError = KErrNone;	
       
    91 	iCheckUpdate = EFalse;	
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CNSmlDMSyncHandler::CNSmlDMSyncHandler
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CNSmlDMSyncHandler::CNSmlDMSyncHandler( RSyncMLSession* aSyncSession,
       
    99                                         CNSmlDMSyncAppEngine* aAppEngine) 
       
   100     : iSyncSession( aSyncSession ),
       
   101     iSyncAppEngine( aAppEngine )   
       
   102 	{
       
   103 	}
       
   104 
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CNSmlDMSyncHandler::SynchronizeL
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CNSmlDMSyncHandler::SynchronizeL( TDesC& aServerName,
       
   112                                        const TInt aProfileId,
       
   113                                        const TInt aJobId,
       
   114                                        const TInt aConnectionBearer,
       
   115                                        const TBool aUseFotaProgressNote )
       
   116 	{
       
   117 	FLOG( "CNSmlDMSyncHandler::SynchronizeL Server alert" );
       
   118 	
       
   119 	iServerName = aServerName;
       
   120 	iConnectionBearer = aConnectionBearer;
       
   121     iProfileId = aProfileId;
       
   122     iJobId = aJobId;
       
   123     iUseFotaProgressNote = aUseFotaProgressNote;
       
   124     
       
   125     iSyncJob.OpenL( Session(), iJobId );
       
   126     iSyncJobId = iSyncJob.Identifier();
       
   127     FTRACE( FPrint( _L(
       
   128 	    "[OMADM]\tCNSmlDMSyncHandler::SynchronizeL--server alert, iSyncJobId = %d" ),
       
   129 	     iSyncJobId ) ); 
       
   130 	  //SAN Support
       
   131 	  iServerAlertedSync = ETrue;  
       
   132 	                      
       
   133 	  //SAN Support
       
   134     SynchronizeL();
       
   135 	}
       
   136 	
       
   137 // -----------------------------------------------------------------------------
       
   138 // CNSmlDMSyncHandler::SynchronizeL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CNSmlDMSyncHandler::SynchronizeL( TDesC& aServerName,
       
   142                                        const TInt aProfileId,
       
   143                                        const TInt aConnectionBearer,
       
   144                                        const TBool aUseFotaProgressNote )
       
   145     {
       
   146     FLOG( "CNSmlDMSyncHandler::SynchronizeL" );
       
   147 
       
   148     iServerName = aServerName;
       
   149     iConnectionBearer = aConnectionBearer;
       
   150     iProfileId = aProfileId;
       
   151     iUseFotaProgressNote = aUseFotaProgressNote;
       
   152 
       
   153     iSyncJob.CreateL( Session(), iProfileId );
       
   154     iSyncJobId = iSyncJob.Identifier();
       
   155     SynchronizeL();
       
   156     
       
   157     
       
   158     FTRACE( FPrint( _L(
       
   159 	    "[OMADM]\tCNSmlDMSyncHandler::SynchronizeL--UI initiated, iSyncJobId = %d" ),
       
   160 	     iSyncJobId ) );       
       
   161 	}
       
   162 	
       
   163 // -----------------------------------------------------------------------------
       
   164 // CNSmlDMSyncHandler::SynchronizeL
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CNSmlDMSyncHandler::SynchronizeL()
       
   168 	{
       
   169 	FLOG( "CNSmlDMSyncHandler::SynchronizeL" );
       
   170 	
       
   171 	TInt err = KErrNone;
       
   172 	
       
   173 	// for MSyncMLEventObserver events
       
   174 	TRAP( err, Session().RequestEventL(*this) );
       
   175 	if ( err != KErrNone )
       
   176 		{
       
   177 		iSyncJob.StopL();
       
   178 		iSyncJob.Close();
       
   179 		User::Leave(err);
       
   180 		}
       
   181     
       
   182     // for MSyncMLProgressObserver events
       
   183     TRAP( err, Session().RequestProgressL(*this) );
       
   184 	if ( err != KErrNone )
       
   185 		{
       
   186 		Session().CancelEvent();
       
   187 		iSyncJob.StopL();
       
   188 		iSyncJob.Close();
       
   189 		User::Leave( err );
       
   190 		}
       
   191 	
       
   192 	   
       
   193 	
       
   194 	TRAP( err, ShowProgressDialogL() );
       
   195 	if ( err != KErrNone )
       
   196 		{
       
   197 		Session().CancelEvent();
       
   198 		Session().CancelProgress();
       
   199 		iSyncJob.StopL();
       
   200 		iSyncJob.Close();
       
   201 		User::Leave( err );
       
   202 		}
       
   203 	FLOG( "CNSmlDMSyncHandler::SynchronizeL Sync is running" );
       
   204 
       
   205     //iSyncDocument->MarkFwUpdChangesStartL();
       
   206 	
       
   207 	iSyncRunning = ETrue;
       
   208 	iSyncError = KErrNone;
       
   209 	}
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CNSmlDMSyncHandler::SynchronizeCompletedL
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CNSmlDMSyncHandler::SynchronizeCompletedL( TInt aError )
       
   216 	{
       
   217     FTRACE( FPrint(
       
   218         _L("[OMADM]\t CNSmlDMSyncHandler::SynchronizeCompletedL(), aError = %d"),
       
   219         aError ) );
       
   220 	
       
   221 	if ( !SyncRunning() )
       
   222 		{
       
   223 		FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL already completed" );
       
   224 		return;  // sync has already completed
       
   225 		}
       
   226 		
       
   227     iSyncJob.Close();
       
   228     
       
   229      FTRACE( FPrint( _L(
       
   230 	    "[OMADM]\tCNSmlDMSyncHandler::SynchronizecompletedL, iSyncJobId = %d" ),
       
   231 	     KNSmlDMNoUserInitiatedJob ) );
       
   232    	
       
   233 	iSyncRunning = EFalse;
       
   234 	iSyncError = aError;    
       
   235     iCheckUpdate = EFalse;        	
       
   236 
       
   237 #ifndef NO_UPDATE 
       
   238         CRepository* centrep = NULL;
       
   239         TRAPD( err, centrep = CRepository::NewL( KCRUidNSmlDMSyncApp ) );
       
   240 	TInt profileId;
       
   241 	centrep->Get( KNSmlDMDefaultFotaProfileKey, profileId );
       
   242 	//FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL profileId = %d", profileId );
       
   243 	delete centrep;
       
   244 	if ( profileId ==  iProfileId )
       
   245         {
       
   246         
       
   247 	//FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL - connected witrh default profile ID" );
       
   248         TInt configFlags( 0 );
       
   249         //TInt SetGenValue(0);
       
   250         TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys ) );
       
   251         if ( centrep )
       
   252             {
       
   253 
       
   254 	  //  FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL Centrep is defined" );
       
   255 	       if( err == KErrNone )
       
   256         	{
       
   257 	        centrep->Get( KDevManSessionType, configFlags );
       
   258 	    //	FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL DevManSessiontype = %d", configFlags );
       
   259              	}
       
   260 	       centrep->Set( KDevManSessionType, 0 );
       
   261 	    	//FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL KDevManSessionType getting reset" );
       
   262 	        delete centrep;
       
   263             } 
       
   264         // configFlags=2 for FOTA Package not downloaded case ,1- successful download
       
   265         if ( (aError == KErrNone) 
       
   266         			&& configFlags == 2 )
       
   267             {
       
   268             //FLOG( "[OMADM]\t CNSmlDMSyncHandler::SynchronizeCompletedL(): No changes in FW Update states." );
       
   269         iDialog = new HbDialog();
       
   270         iDialog->setHeadingWidget(new HbLabel(hbTrId("txt_device_update_title_phone_uptodate")));
       
   271         iDialog->setContentWidget(new HbLabel(hbTrId("txt_device_update_dpopinfo_your_phone_is_already_u")));
       
   272         iPrimaryAction = new HbAction();
       
   273         iPrimaryAction->setText(hbTrId("OK"));
       
   274 	    iDialog->setPrimaryAction(iPrimaryAction);
       
   275 	    iDialog->setTimeout(HbPopup::NoTimeout);
       
   276 	    iDialog->setDismissPolicy(HbPopup::NoDismiss);
       
   277 	    iDialog->show();
       
   278             // show the dialog
       
   279             }
       
   280 
       
   281         }  
       
   282 #endif
       
   283 
       
   284 	iUseFotaProgressNote = EFalse;
       
   285     iSyncJob.Close();
       
   286     
       
   287 	// handle error in HandleActiveCallL (when active caller completes)
       
   288 	iActiveCaller->Start( aError );
       
   289 
       
   290 	FLOG( "CNSmlDMSyncHandler::SynchronizeCompletedL() completed" );
       
   291 	}
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CNSmlDMSyncHandler::OnSyncMLSessionEvent
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CNSmlDMSyncHandler::OnSyncMLSessionEvent( TEvent aEvent,
       
   298                                                TInt aIdentifier,
       
   299                                                TInt aError,
       
   300                                                TInt /*aAdditionalData*/ )
       
   301 	{
       
   302 	FTRACE( FPrint( _L(
       
   303 	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent(), aEvent = %d, aIdentifier = %d, aError = %d" ),
       
   304 	    aEvent, aIdentifier, aError ) );
       
   305 	FTRACE( RDebug::Print( _L(
       
   306 	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent(), aEvent = %d, aIdentifier = %d, aError = %d" ),
       
   307 	    aEvent, aIdentifier, aError ) );
       
   308 
       
   309 	if ( aEvent == EJobStop
       
   310 	    || aEvent == EJobStartFailed
       
   311 	    || aEvent == EJobRejected )
       
   312 		{
       
   313     	FTRACE( RDebug::Print( _L(
       
   314     	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent(), iSyncJobId = %d" ),
       
   315     	    iSyncJobId ) );
       
   316     	  FTRACE( FPrint( _L(
       
   317     	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent(), iSyncJobId = %d" ),
       
   318     	    iSyncJobId ) );  
       
   319 			
       
   320 		if ( iSyncJobId == aIdentifier )
       
   321 			{
       
   322 			FLOG( "CNSmlDMSyncHandler::OnSyncMLSessionEvent EJobStop close" );
       
   323 			
       
   324             TRAP_IGNORE( SynchronizeCompletedL( aError ) );
       
   325 			}
       
   326 		}
       
   327     FLOG( "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSessionEvent() completed" );
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // CNSmlDMSyncHandler::OnSyncMLSyncError
       
   332 // -----------------------------------------------------------------------------
       
   333 //
       
   334 void CNSmlDMSyncHandler::OnSyncMLSyncError( TErrorLevel aErrorLevel,
       
   335                                             TInt aError,
       
   336                                             TInt /*aTaskId*/,
       
   337                                             TInt /*aInfo1*/,
       
   338                                             TInt /*aInfo2*/)
       
   339 	{
       
   340 	FTRACE( FPrint( _L(
       
   341 	    "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSyncError(), aErrorLevel = %d, aError = %d"),
       
   342 	    aErrorLevel, aError ) );
       
   343 	    FTRACE( RDebug::Print(
       
   344 	          _L("CNSmlDMSyncHandler::OnSyncMLSyncProgress  aErrorLevel =(%d) aError =(%d)"), aErrorLevel, aError  ) );
       
   345 	
       
   346 	if ( aErrorLevel == ESmlFatalError )
       
   347 		{
       
   348         TRAP_IGNORE( SynchronizeCompletedL( aError ) );
       
   349 		}
       
   350     FLOG( "[OMADM]\tCNSmlDMSyncHandler::OnSyncMLSyncError() completed" );
       
   351 	}
       
   352 
       
   353 // -----------------------------------------------------------------------------
       
   354 // CNSmlDMSyncHandler::OnSyncMLSyncProgress
       
   355 // -----------------------------------------------------------------------------
       
   356 //
       
   357 void CNSmlDMSyncHandler::OnSyncMLSyncProgress( TStatus aStatus,
       
   358                                                TInt /*aInfo1*/,
       
   359                                                TInt /*aInfo2*/ )
       
   360 	{
       
   361 	FTRACE( RDebug::Print(
       
   362 	          _L("CNSmlDMSyncHandler::OnSyncMLSyncProgress (%d)"), aStatus ) );
       
   363 	
       
   364 	switch (aStatus)
       
   365 		{
       
   366 		case ESmlConnecting:
       
   367 		    //State()->SetSyncPhase( CNSmlDMSyncState::EPhaseConnecting );
       
   368 		    break;
       
   369 		case ESmlConnected:
       
   370 		    break;
       
   371 		case ESmlLoggingOn:
       
   372 		    break;
       
   373 		case ESmlLoggedOn:
       
   374 		    
       
   375 		    break;
       
   376 		case ESmlDisconnected:
       
   377 		    
       
   378 		    break;
       
   379 		case ESmlCompleted:
       
   380 		   
       
   381 		    break;
       
   382 		case ESmlProcessingServerCommands:
       
   383 		   
       
   384 		    break;
       
   385 		case ESmlReceivingServerCommands:
       
   386 		   
       
   387 		    break;
       
   388 		
       
   389 		case ESmlSendingModificationsToServer:
       
   390 		    {		   		    
       
   391 		    break;
       
   392 		    }
       
   393 		
       
   394 		default:
       
   395 		    break;
       
   396 		}    
       
   397 	}
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CNSmlDMSyncHandler::OnSyncMLDataSyncModifications
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 void CNSmlDMSyncHandler::OnSyncMLDataSyncModifications( TInt /*aTaskId*/,
       
   404                    const TSyncMLDataSyncModifications& /*aClientModifications*/,
       
   405                    const TSyncMLDataSyncModifications& /*aServerModifications*/ )
       
   406     {
       
   407     FLOG( "CNSmlDMSyncHandler::OnSyncMLDataSyncModifications" );
       
   408 
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CNSmlDMSyncHandler::HandleActiveCallL
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CNSmlDMSyncHandler::HandleActiveCallL()
       
   416 	{
       
   417     FLOG( "CNSmlDMSyncHandler::HandleActiveCallL" );
       
   418     
       
   419     // HandleSyncErrorL will set this to true if
       
   420     // sync will be retried.
       
   421     iRetrySync = EFalse;
       
   422 
       
   423 	if ( (iSyncError != KErrNone) && (iSyncError != KErrCancel) )
       
   424 		{
       
   425 		TRAP_IGNORE( HandleSyncErrorL() );
       
   426 		}
       
   427 	if ( iRetrySync == EFalse )
       
   428 		{
       
   429 	    // Inform parent that sync is done.
       
   430 	    iSyncAppEngine->SyncCompleted( ENSmlSyncComplete );		
       
   431 		}
       
   432 	}
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CNSmlDMSyncHandler::HandleSyncErrorL
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CNSmlDMSyncHandler::HandleSyncErrorL()
       
   439 	{
       
   440 	FLOG( "CNSmlDMSyncHandler::HandleSyncErrorL" );
       
   441 	
       
   442 	if ( iSyncError != KDMErr )
       
   443 		{
       
   444 		}
       
   445 	if ( ( iSyncError == SyncMLError::KErrAuthenticationFailure ) ||
       
   446 	    ( iSyncError == SyncMLError::KErrTransportAuthenticationFailure ) )
       
   447         {
       
   448 	    FLOG( "CNSmlDMSyncHandler::HandleSyncErrorL ask username" );
       
   449         }
       
   450     }
       
   451 	
       
   452 // -----------------------------------------------------------------------------
       
   453 // CNSmlDMSyncHandler::ShowProgressDialogL
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 void CNSmlDMSyncHandler::ShowProgressDialogL( )
       
   457 	{
       
   458 	FLOG( "CNSmlDMSyncHandler::ShowProgressDialogL" );
       
   459 	
       
   460 	FLOG( "CNSmlDMSyncHandler::ShowProgressDialogL() completed" );
       
   461 	}
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CNSmlDMSyncHandler::HideProgressDialogL
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 void CNSmlDMSyncHandler::HideProgressDialogL()
       
   468     {
       
   469     FLOG( "CNSmlDMSyncHandler::HideProgressDialogL" );
       
   470     }
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // CNSmlDMSyncHandler::Session
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 RSyncMLSession& CNSmlDMSyncHandler::Session()
       
   477 	{
       
   478 	__ASSERT_DEBUG(iSyncSession, TUtil::Panic(KErrGeneral));
       
   479 	
       
   480 	return *iSyncSession;
       
   481 	}
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // CNSmlDMSyncHandler::SyncRunning
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 TBool CNSmlDMSyncHandler::SyncRunning()
       
   488 	{
       
   489 	FTRACE( RDebug::Print(
       
   490 	          _L("CNSmlDMSyncHandler::SyncRunning status (%d)"), iSyncRunning ) );
       
   491 	          
       
   492 	return iSyncRunning;
       
   493 	}
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CNSmlDMSyncHandler::CancelSynchronizeL
       
   497 // -----------------------------------------------------------------------------
       
   498 //		
       
   499 void CNSmlDMSyncHandler::CancelSynchronizeL()
       
   500     {
       
   501     FLOG( "CNSmlDMSyncHandler::CancelSynchronizeL" );
       
   502     
       
   503     if ( iSyncRunning )
       
   504         {
       
   505         iSyncJob.StopL();
       
   506         SynchronizeCompletedL( KErrCancel );
       
   507         }
       
   508     }
       
   509 
       
   510 // End of File