iaupdate/IAD/firmwareupdate/src/iaupdatefwsynchandler.cpp
changeset 0 ba25891c3a9e
child 29 26b6f0522fd8
child 65 7333d7932ef7
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include <aknnotewrappers.h>
       
    23 #include <AknWaitDialog.h>
       
    24 #include <StringLoader.h>
       
    25 #include <e32property.h>
       
    26 #include <data_caging_path_literals.hrh>  // for resource and bitmap directories
       
    27 #include <SyncMLErr.h>      // sync error codes
       
    28 #include <iaupdate.rsg>
       
    29 #include <AknsUtils.h>
       
    30 #include <DevManInternalCRKeys.h>
       
    31 #include <centralrepository.h>
       
    32 #include <rconnmon.h>
       
    33 #include <es_enum.h>
       
    34 
       
    35 #include <cmconnectionmethodext.h>
       
    36 #include <cmconnectionmethoddef.h>
       
    37 #include <cmpluginpacketdatadef.h>
       
    38 #include <cmconnectionmethoddef.h>
       
    39 #include <cmconnectionmethodext.h>
       
    40 #include <cmdestinationext.h>
       
    41 #include <cmmanagerdef.h>
       
    42 
       
    43 #include "iaupdateconnectionmethod.h"
       
    44 #include "iaupdateprivatecrkeys.h"
       
    45 #include "iaupdatefwfotamodel.h"
       
    46 #include "iaupdatefwsyncappengine.h"
       
    47 #include "iaupdatefwsynchandler.h"
       
    48 #include "iaupdatefwsyncstate.h"
       
    49 #include "iaupdatefwdebug.h"
       
    50 #include "iaupdateuids.h"
       
    51 
       
    52 #include "iaupdatefwconst.h"
       
    53 #include "iaupdatefwnsmlcrkeys.h"
       
    54 #include "iaupdatefwnsmlpskeys.h"
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CIAUpdateFWSyncHandler::NewL
       
    58 //
       
    59 // Two-phased constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CIAUpdateFWSyncHandler* CIAUpdateFWSyncHandler::NewL( RSyncMLSession* aSyncSession,
       
    63                                               CIAUpdateFWSyncAppEngine* aAppEngine,
       
    64                                               CIAUpdateFWFotaModel* aFotaModel )
       
    65     {
       
    66 
       
    67     CIAUpdateFWSyncHandler* self =
       
    68         new (ELeave) CIAUpdateFWSyncHandler( aSyncSession,
       
    69                                          aAppEngine,
       
    70                                          aFotaModel );
       
    71 	CleanupStack::PushL(self);
       
    72 	self->ConstructL();
       
    73 	CleanupStack::Pop(self);
       
    74 	
       
    75 
       
    76     return self;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // Destructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CIAUpdateFWSyncHandler::~CIAUpdateFWSyncHandler()
       
    84     {
       
    85     if ( iWaitDialog )
       
    86         {
       
    87         TRAP_IGNORE( iWaitDialog->ProcessFinishedL() );
       
    88         iWaitDialog = NULL;
       
    89         }
       
    90     
       
    91 	delete iState;
       
    92 	delete iActiveCaller;
       
    93 
       
    94 	if ( iSyncRunning )
       
    95 	    {
       
    96 	    TRAP_IGNORE( iSyncJob.StopL() );
       
    97             iSyncJob.Close();
       
    98 	    }
       
    99 	    
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CIAUpdateFWSyncHandler::ConstructL
       
   104 // Symbian 2nd phase constructor can leave.
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CIAUpdateFWSyncHandler::ConstructL( void )
       
   108     {
       
   109       
       
   110 	iState = CIAUpdateFWSyncState::NewL();
       
   111 	iActiveCaller = CIAUpdateFWActiveCaller::NewL(this);
       
   112 	
       
   113 	iSyncRunning = EFalse;
       
   114 	iSyncError = KErrNone;
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CIAUpdateFWSyncHandler::CIAUpdateFWSyncHandler
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 CIAUpdateFWSyncHandler::CIAUpdateFWSyncHandler( RSyncMLSession* aSyncSession,
       
   122                                         CIAUpdateFWSyncAppEngine* aAppEngine,
       
   123                                         CIAUpdateFWFotaModel* aFotaModel  ) 
       
   124     : iSyncSession( aSyncSession ),
       
   125     iSyncAppEngine( aAppEngine ),
       
   126     iFotaModel( aFotaModel )
       
   127 	{
       
   128 	}
       
   129 
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CIAUpdateFWSyncHandler::SynchronizeL
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CIAUpdateFWSyncHandler::SynchronizeL( TDesC& aServerName,
       
   136                                        const TInt aProfileId,
       
   137                                        const TInt aJobId,
       
   138                                        const TInt aConnectionBearer,
       
   139                                        const TBool aUseFotaProgressNote )
       
   140 	{
       
   141 
       
   142 	iServerName = aServerName;
       
   143 	iConnectionBearer = aConnectionBearer;
       
   144     iProfileId = aProfileId;
       
   145     iJobId = aJobId;
       
   146     iUseFotaProgressNote = aUseFotaProgressNote;
       
   147     
       
   148     iSyncJob.OpenL( Session(), iJobId );
       
   149     iSyncJobId = iSyncJob.Identifier();
       
   150     SynchronizeL();
       
   151 	}
       
   152 	
       
   153 // -----------------------------------------------------------------------------
       
   154 // CIAUpdateFWSyncHandler::SynchronizeL
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CIAUpdateFWSyncHandler::SynchronizeL( TDesC& aServerName,
       
   158                                        const TInt aProfileId,
       
   159                                        const TInt aConnectionBearer,
       
   160                                        const TBool aUseFotaProgressNote )
       
   161     {
       
   162  
       
   163     FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL begin");
       
   164     
       
   165     iServerName = aServerName;
       
   166     iConnectionBearer = aConnectionBearer;
       
   167     iProfileId = aProfileId;
       
   168     iUseFotaProgressNote = aUseFotaProgressNote;
       
   169     
       
   170     //select the IAP which will be used for sync
       
   171     SelectIAPL();
       
   172     
       
   173     iSyncJob.CreateL( Session(), iProfileId );
       
   174     iSyncJobId = iSyncJob.Identifier();
       
   175     FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 1");
       
   176     SynchronizeL();
       
   177     FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 2");
       
   178     TInt dummyValue;
       
   179     TInt err = RProperty::Get( KPSUidNSmlDMSyncApp,
       
   180                                KNSmlDMSyncUiInitiatedJobKey,
       
   181                                dummyValue );
       
   182     if ( err == KErrNotFound )
       
   183         {
       
   184         _LIT_SECURITY_POLICY_S0( KWritePolicy, KIAUpdateUiUid );
       
   185         _LIT_SECURITY_POLICY_C1( KReadPolicy, ECapabilityReadDeviceData );
       
   186         RProperty::Define( KPSUidNSmlDMSyncApp,
       
   187                            KNSmlDMSyncUiInitiatedJobKey,
       
   188                            RProperty::EInt,
       
   189                            KReadPolicy,
       
   190                            KWritePolicy );
       
   191         }
       
   192     RProperty::Set( KPSUidNSmlDMSyncApp,
       
   193                     KNSmlDMSyncUiInitiatedJobKey,
       
   194                     iSyncJobId );
       
   195 	}
       
   196 	
       
   197 // -----------------------------------------------------------------------------
       
   198 // CIAUpdateFWSyncHandler::SynchronizeL
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CIAUpdateFWSyncHandler::SynchronizeL()
       
   202 	{
       
   203 	TInt err = KErrNone;
       
   204 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 12");
       
   205 	// for MSyncMLEventObserver events
       
   206 	TRAP( err, Session().RequestEventL(*this) );
       
   207 	if ( err != KErrNone )
       
   208 		{
       
   209 		FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 13");
       
   210 		iSyncJob.StopL();
       
   211 		iSyncJob.Close();
       
   212 		User::Leave(err);
       
   213 		}
       
   214     
       
   215 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 14");
       
   216     // for MSyncMLProgressObserver events
       
   217     TRAP( err, Session().RequestProgressL(*this) );
       
   218 	if ( err != KErrNone )
       
   219 		{
       
   220 		FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 15");
       
   221 		Session().CancelEvent();
       
   222 		iSyncJob.StopL();
       
   223 		iSyncJob.Close();
       
   224 		User::Leave( err );
       
   225 		}
       
   226 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 16");
       
   227 	State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseConnecting );
       
   228 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 17");
       
   229 	
       
   230 	TRAP( err, ShowProgressDialogL() );
       
   231 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeL 18");
       
   232 	if ( err != KErrNone )
       
   233 		{
       
   234 		Session().CancelEvent();
       
   235 		Session().CancelProgress();
       
   236 		iSyncJob.StopL();
       
   237 		iSyncJob.Close();
       
   238 		User::Leave( err );
       
   239 		}
       
   240 
       
   241 	iFotaModel->MarkFwUpdChangesStartL();
       
   242 	
       
   243 	iSyncRunning = ETrue;
       
   244 	iSyncError = KErrNone;
       
   245 	}
       
   246 
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CIAUpdateFWSyncHandler::SelectIAPL()
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CIAUpdateFWSyncHandler::SelectIAPL()
       
   253     {
       
   254     CIAUpdateFWSyncProfile* profile = iSyncAppEngine->OpenProfileL( iProfileId, ESmlOpenReadWrite );
       
   255     FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL 15");
       
   256     
       
   257     //get the current access point in DM profile
       
   258     TInt dmIap = profile->AccessPointL();
       
   259 
       
   260          
       
   261     // if in the default DM profile, the IAP is set to Always ask. 
       
   262     // we should choose an IAP here. 
       
   263     // if the IAP is not Always ask, we don't choose but use it.
       
   264     
       
   265     if (dmIap < 0)
       
   266         {
       
   267         FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL Always ask is the IAP for default DM profile");
       
   268         //the current IAP is "Always ask"
       
   269         CRepository* centrep = CRepository::NewL(  KCRUidIAUpdateSettings );
       
   270         
       
   271         //Fetch a working IAP use our own logic
       
   272         TUint32 iapid = SelectConnectionMethodL();
       
   273         
       
   274         if ( iapid )
       
   275             {
       
   276             FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL we found working IAP");
       
   277             //found working IAP found
       
   278             //save it to the DM profile and mark the cenrep overwritten indicator
       
   279             if (centrep)
       
   280                 { 
       
   281                 FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL save original IAP (should be alway ask as always) to cen rep");
       
   282                 //save the original IAP in cenrep also, so we can set DM profile back when FOTA is done
       
   283                 centrep->Set(  KIAUpdateFWDefaultIAPId, dmIap );                    
       
   284                 FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL Mark it as overwritten");
       
   285                  //Marked that default DM IAP was overwritten
       
   286                  centrep->Set(  KIAUpdateFWDefaultIAPIsOverwritten, 1 );                    
       
   287                  } 
       
   288             FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL save the chosen IAP into DM profile");
       
   289              //set the chosen one to DM profile
       
   290              profile->SetAccessPointL(iapid); 
       
   291              
       
   292              FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL 21");
       
   293              profile->SaveL();
       
   294              }
       
   295         else
       
   296             {
       
   297             //no working IAP found, access point dialog will pop to user later to select access point
       
   298             FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL DM profile has always ask setting for IAP and we didn't found any working one either");
       
   299             }
       
   300 
       
   301         delete centrep; 
       
   302         centrep = NULL;
       
   303         }       
       
   304 
       
   305 
       
   306 
       
   307     iSyncAppEngine->CloseProfile();
       
   308     FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SelectIAPL end");
       
   309 
       
   310           
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------------
       
   314 // CIAUpdateFWSyncHandler::SynchronizeCompletedL
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 void CIAUpdateFWSyncHandler::SynchronizeCompletedL( TInt aError )
       
   318 	{
       
   319 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeCompletedL");
       
   320 	
       
   321 	if ( !SyncRunning() )
       
   322 		{
       
   323 		FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeCompletedL 1");
       
   324 		return;  // sync has already completed
       
   325 		}
       
   326 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeCompletedL 2");	
       
   327     iSyncJob.Close();
       
   328     
       
   329     // Error code can be ignored.
       
   330     RProperty::Set( KPSUidNSmlDMSyncApp,
       
   331                     KNSmlDMSyncUiInitiatedJobKey,
       
   332                     KNSmlDMNoUserInitiatedJob );
       
   333 	
       
   334 	iSyncRunning = EFalse;
       
   335 	iSyncError = aError;
       
   336 
       
   337     if ( iWaitDialog )
       
   338         {
       
   339         
       
   340         iWaitDialog->ProcessFinishedL();
       
   341         iWaitDialog = NULL;
       
   342         }
       
   343 
       
   344 	iUseFotaProgressNote = EFalse;
       
   345     iSyncJob.Close();
       
   346     FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeCompletedL 13");
       
   347 	// handle error in HandleActiveCallL (when active caller completes)
       
   348 	iActiveCaller->Start( aError );
       
   349 
       
   350 	FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeCompletedL 14");
       
   351 
       
   352 	
       
   353 	//the sync with DM server is done if no error we should get DM profile prepared since the real firmware download and
       
   354 	//update are about to start.
       
   355     CIAUpdateFWSyncProfile* profile = 
       
   356                      iSyncAppEngine->OpenProfileL( iProfileId, ESmlOpenReadWrite );
       
   357 	
       
   358 	if ( aError == KErrNone )
       
   359 	    {
       
   360 	     FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::SynchronizeCompletedL 15");    
       
   361 
       
   362 	     TBool bIsActive  = ETrue;
       
   363 
       
   364 	     CRepository* centrep = NULL;
       
   365 	     TRAPD( err, centrep = CRepository::NewL(  KCRUidDeviceManagementInternalKeys ) );
       
   366 	     if (err == KErrNone)
       
   367 	         {
       
   368 	         centrep->Get(  KNSmlFotaProfileDefaultIsActive, bIsActive );                
       
   369 	         delete centrep; 
       
   370 	         centrep = NULL;         
       
   371 	         }
       
   372 
       
   373 	     if (!bIsActive)
       
   374 	         {
       
   375 	         profile->SetSASyncStateL(ESASyncStateDisable);      
       
   376 	         }
       
   377 	    }
       
   378 	else
       
   379 	    {
       
   380 	    //sync with DM server failed for some reason
       
   381 	    FLOG_NUM("[IAUPDATE] CIAUpdateFWSyncHandler Sync with DM failed with error = %d", aError );
       
   382 	    }
       
   383 	    
       
   384 
       
   385     //set the IAP back to the original one. After sync, the IAP is saved in FOTA side, 
       
   386     //no need to keep it anymore.	 
       
   387     CRepository* centrep = CRepository::NewLC(  KCRUidIAUpdateSettings );
       
   388 	  //set the IAP back to the original one
       
   389     TInt wasDMDefaultIAPOverwritten = EFalse;
       
   390     centrep->Get(  KIAUpdateFWDefaultIAPIsOverwritten, wasDMDefaultIAPOverwritten );                    
       
   391         
       
   392     if (wasDMDefaultIAPOverwritten)
       
   393         {
       
   394         TInt initialDMIAPId = -1;
       
   395         centrep->Get(  KIAUpdateFWDefaultIAPId, initialDMIAPId );                     
       
   396         TInt currentIAP = profile->AccessPointL();              
       
   397             
       
   398         if (currentIAP != initialDMIAPId)
       
   399             {
       
   400             profile->SetAccessPointL(initialDMIAPId);                         
       
   401                 
       
   402             }  
       
   403          centrep->Set(  KIAUpdateFWDefaultIAPIsOverwritten, EFalse );       
       
   404          }
       
   405    
       
   406   CleanupStack::PopAndDestroy( centrep );
       
   407 	    
       
   408 	//save the changes    
       
   409 	profile->SaveL();   
       
   410 	 
       
   411 	iSyncAppEngine->CloseProfile();
       
   412 	}
       
   413 
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CIAUpdateFWSyncHandler::SelectConnectionMethodL
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 TUint32 CIAUpdateFWSyncHandler::SelectConnectionMethodL()
       
   420     {
       
   421     // from back ground checker, choose the IAP to make the internet access silent
       
   422     TUint32 connectionMethodId( 0 );
       
   423     TInt connMethodId( 0 );
       
   424 
       
   425     // Let's first check whether cenrep contains SNAP id other than zero
       
   426     CRepository* cenrep( CRepository::NewLC( KCRUidIAUpdateSettings ) );
       
   427     User::LeaveIfError(  
       
   428         cenrep->Get( KIAUpdateAccessPoint, connMethodId ) );
       
   429     CleanupStack::PopAndDestroy( cenrep ); 
       
   430     cenrep = NULL;
       
   431 
       
   432     RCmManagerExt cmManagerExt;
       
   433     cmManagerExt.OpenL();
       
   434     CleanupClosePushL( cmManagerExt );
       
   435     
       
   436     if ( connMethodId == -1 )
       
   437         {
       
   438         //check what is the default connection by users     
       
   439         
       
   440         TCmDefConnValue DCSetting;
       
   441         cmManagerExt.ReadDefConnL( DCSetting );
       
   442        
       
   443         
       
   444         switch ( DCSetting.iType )
       
   445             {
       
   446             case ECmDefConnAlwaysAsk:
       
   447             case ECmDefConnAskOnce:
       
   448                 {
       
   449                 //go with the best IAP under internet snap
       
   450                 connectionMethodId = GetBestIAPInInternetSNAPL( cmManagerExt );
       
   451                 break;
       
   452                 }
       
   453             case ECmDefConnDestination:
       
   454                 {
       
   455                 //go with the best IAP under this snap
       
   456                 connectionMethodId = GetBestIAPInThisSNAPL( cmManagerExt, DCSetting.iId );
       
   457                 break;
       
   458                 }
       
   459             case ECmDefConnConnectionMethod:
       
   460                 {
       
   461                 //go with the best IAP under this snap
       
   462                 connectionMethodId = DCSetting.iId;
       
   463                 break;
       
   464                 }
       
   465             }
       
   466         }
       
   467     else if ( connMethodId == 0 )
       
   468         {
       
   469         //no choice from user, we go with the best IAP under Internent SNAP
       
   470         connectionMethodId = GetBestIAPInInternetSNAPL( cmManagerExt );
       
   471         }
       
   472     else
       
   473         {
       
   474 
       
   475         // It was some SNAP value
       
   476         connectionMethodId = GetBestIAPInThisSNAPL( cmManagerExt, connMethodId );
       
   477         }
       
   478 
       
   479     CleanupStack::PopAndDestroy( &cmManagerExt ); 
       
   480     
       
   481     return connectionMethodId;
       
   482               
       
   483     }
       
   484 
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CIAUpdateFWSyncHandler::GetBestIAPInInternetSNAPL
       
   488 // -----------------------------------------------------------------------------
       
   489 //
       
   490 TUint32 CIAUpdateFWSyncHandler::GetBestIAPInInternetSNAPL( RCmManagerExt& aCmManagerExt  )
       
   491     {
       
   492     //select IAP from Internet SNAP
       
   493     RArray<TUint32> destIdArray;
       
   494     aCmManagerExt.AllDestinationsL( destIdArray );
       
   495     TUint32 InternetSNAPID = 0;
       
   496     for ( TInt i = 0; i< destIdArray.Count(); i++ )
       
   497         {
       
   498         RCmDestinationExt dest = aCmManagerExt.DestinationL( destIdArray[i] );
       
   499         CleanupClosePushL( dest );
       
   500                                      
       
   501         if ( dest.MetadataL( CMManager::ESnapMetadataInternet ) )
       
   502             {
       
   503             InternetSNAPID = destIdArray[i];
       
   504             CleanupStack::PopAndDestroy( &dest ); 
       
   505             break;
       
   506             }                     
       
   507          CleanupStack::PopAndDestroy( &dest ); 
       
   508          }
       
   509     destIdArray.Reset();
       
   510     
       
   511     return GetBestIAPInThisSNAPL( aCmManagerExt, InternetSNAPID );
       
   512     }
       
   513 
       
   514 
       
   515 
       
   516 // -----------------------------------------------------------------------------
       
   517 // CIAUpdateFWSyncHandler::GetBestIAPInThisSNAPL
       
   518 // -----------------------------------------------------------------------------
       
   519 //
       
   520 TUint32 CIAUpdateFWSyncHandler::GetBestIAPInThisSNAPL( RCmManagerExt& aCmManagerExt, TUint32 aSNAPID  )
       
   521     {
       
   522     //get all usable IAPs
       
   523     TConnMonIapInfoBuf iapInfo;
       
   524     TRequestStatus status;
       
   525                        
       
   526     RConnectionMonitor connMon;
       
   527     connMon.ConnectL();
       
   528     CleanupClosePushL( connMon );
       
   529     
       
   530     connMon.GetPckgAttribute( EBearerIdAll, 0, KIapAvailability,iapInfo, status );
       
   531     User::WaitForRequest( status );
       
   532     User::LeaveIfError( status.Int() );
       
   533     
       
   534     CleanupStack::PopAndDestroy( &connMon ); 
       
   535     
       
   536     RCmDestinationExt dest = aCmManagerExt.DestinationL( aSNAPID );
       
   537     CleanupClosePushL( dest );
       
   538     
       
   539     // Check whether the SNAP contains any IAP.
       
   540     for  (TInt i = 0; i < dest.ConnectionMethodCount(); i++ )
       
   541         {
       
   542         RCmConnectionMethodExt cm =  dest.ConnectionMethodL( i );
       
   543         CleanupClosePushL( cm );
       
   544         
       
   545         TUint32 iapid= cm.GetIntAttributeL( CMManager::ECmIapId );
       
   546         
       
   547         for ( TInt i = 0; i < iapInfo().iCount; i++ )
       
   548             {
       
   549             if ( iapInfo().iIap[i].iIapId == iapid )
       
   550                 {
       
   551                 CleanupStack::PopAndDestroy( 2 ); //cm & dest;
       
   552                 return iapid;
       
   553                 }
       
   554             }    
       
   555                                                                                  
       
   556         CleanupStack::PopAndDestroy( &cm );
       
   557         }
       
   558     
       
   559     CleanupStack::PopAndDestroy( &dest ); 
       
   560     return 0;
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CIAUpdateFWSyncHandler::OnSyncMLSessionEvent
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CIAUpdateFWSyncHandler::OnSyncMLSessionEvent( TEvent aEvent,
       
   568                                                TInt aIdentifier,
       
   569                                                TInt aError,
       
   570                                                TInt /*aAdditionalData*/ )
       
   571 	{
       
   572 	 FLOG_NUM(" aEvent %d", aEvent );
       
   573 	 FLOG_NUM(" aError %d", aError );
       
   574 	 FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::OnSyncMLSessionEvent ");
       
   575 	if ( aEvent == EJobStop
       
   576 	    || aEvent == EJobStartFailed
       
   577 	    || aEvent == EJobRejected )
       
   578 		{
       
   579 
       
   580 		if ( iSyncJobId == aIdentifier )
       
   581 			{
       
   582 
       
   583             TRAP_IGNORE( SynchronizeCompletedL( aError ) );
       
   584 			}
       
   585 		}
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CIAUpdateFWSyncHandler::OnSyncMLSyncError
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 void CIAUpdateFWSyncHandler::OnSyncMLSyncError( TErrorLevel aErrorLevel,
       
   593                                             TInt aError,
       
   594                                             TInt /*aTaskId*/,
       
   595                                             TInt /*aInfo1*/,
       
   596                                             TInt /*aInfo2*/)
       
   597 	{
       
   598 	FLOG_NUM(" aError %d", aError );
       
   599 	 FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::OnSyncMLSyncError ");
       
   600 	if ( aErrorLevel == ESmlFatalError )
       
   601 		{
       
   602 		 FLOG("[IAUPDATE] CIAUpdateFWSyncHandler::OnSyncMLSyncError fatal error ");
       
   603         TRAP_IGNORE( SynchronizeCompletedL( aError ) );
       
   604 		}
       
   605 
       
   606 	}
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CIAUpdateFWSyncHandler::OnSyncMLSyncProgress
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 void CIAUpdateFWSyncHandler::OnSyncMLSyncProgress( TStatus aStatus,
       
   613                                                TInt /*aInfo1*/,
       
   614                                                TInt /*aInfo2*/ )
       
   615 	{
       
   616 	switch (aStatus)
       
   617 		{
       
   618 		case ESmlConnecting:
       
   619 		    FLOG("OnSyncMLSyncProgress::ESmlConnecting");
       
   620 		    State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseConnecting );
       
   621 		    break;
       
   622 		case ESmlConnected:
       
   623 		    FLOG("OnSyncMLSyncProgress::ESmlConnected");
       
   624 		    break;
       
   625 		case ESmlLoggingOn:
       
   626 		    FLOG("OnSyncMLSyncProgress::ESmlLoggingOn");
       
   627 		    break;
       
   628 		case ESmlLoggedOn:
       
   629 		    FLOG("OnSyncMLSyncProgress::ESmlLoggedOn");
       
   630 		    State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseSynchronizing );
       
   631 		    break;
       
   632 		case ESmlDisconnected:
       
   633 		    FLOG("OnSyncMLSyncProgress::ESmlDisconnected");
       
   634 		    State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseDisconnecting );
       
   635 		    break;
       
   636 		case ESmlCompleted:
       
   637 		    FLOG("OnSyncMLSyncProgress::ESmlCompleted");
       
   638 		    State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseDisconnecting );
       
   639 		    break;
       
   640 		case ESmlProcessingServerCommands:
       
   641 		    FLOG("OnSyncMLSyncProgress::ESmlProcessingServerCommands");
       
   642 		    State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseSending );
       
   643 		    break;
       
   644 		case ESmlReceivingServerCommands:
       
   645 		    FLOG("OnSyncMLSyncProgress::ESmlReceivingServerCommands");
       
   646 		    State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseReceiving );
       
   647 		    break;
       
   648 		default:
       
   649 		    break;
       
   650 		}
       
   651 	}
       
   652 
       
   653 // -----------------------------------------------------------------------------
       
   654 // CIAUpdateFWSyncHandler::OnSyncMLDataSyncModifications
       
   655 // -----------------------------------------------------------------------------
       
   656 //
       
   657 void CIAUpdateFWSyncHandler::OnSyncMLDataSyncModifications( TInt /*aTaskId*/,
       
   658                    const TSyncMLDataSyncModifications& /*aClientModifications*/,
       
   659                    const TSyncMLDataSyncModifications& /*aServerModifications*/ )
       
   660     {
       
   661     }
       
   662 
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CIAUpdateFWSyncHandler::HandleActiveCallL
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 void CIAUpdateFWSyncHandler::HandleActiveCallL()
       
   669 	{
       
   670 
       
   671     FLOG("CIAUpdateFWSyncHandler::HandleActiveCallL 1")
       
   672     // HandleSyncErrorL will set this to true if
       
   673     // sync will be retried.
       
   674     iRetrySync = EFalse;
       
   675 
       
   676 	if ( (iSyncError != KErrNone) && (iSyncError != KErrCancel) )
       
   677 		{
       
   678 		 FLOG("CIAUpdateFWSyncHandler::HandleActiveCallL 2")
       
   679 		TRAP_IGNORE( HandleSyncErrorL() );
       
   680 		}
       
   681 	if ( iRetrySync == EFalse )
       
   682 		{
       
   683 		 FLOG("CIAUpdateFWSyncHandler::HandleActiveCallL 3")
       
   684 	    // Inform parent that sync is done.
       
   685 	    iSyncAppEngine->SyncCompleted( ENSmlSyncComplete );		
       
   686 		 FLOG("CIAUpdateFWSyncHandler::HandleActiveCallL 4")
       
   687 		}
       
   688 	}
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CIAUpdateFWSyncHandler::HandleSyncErrorL
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 void CIAUpdateFWSyncHandler::HandleSyncErrorL()
       
   695 	{
       
   696 
       
   697 	FLOG("CIAUpdateFWSyncHandler::HandleSyncErrorL 1")
       
   698 	if ( iSyncError != KDMErr )
       
   699 		{
       
   700 		FLOG("CIAUpdateFWSyncHandler::HandleSyncErrorL 2")
       
   701 		}
       
   702 
       
   703 	   FLOG("CIAUpdateFWSyncHandler::HandleSyncErrorL 4")
       
   704 	if ( ( iSyncError == SyncMLError::KErrAuthenticationFailure ) ||
       
   705 	    ( iSyncError == SyncMLError::KErrTransportAuthenticationFailure ) )
       
   706         {
       
   707         //we don't handle this at the moment
       
   708         FLOG("CIAUpdateFWSyncHandler::HandleSyncErrorL 5")
       
   709         }
       
   710 	FLOG("CIAUpdateFWSyncHandler::HandleSyncErrorL 8")
       
   711     }
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // CIAUpdateFWSyncHandler::ShowProgressDialogL
       
   715 // -----------------------------------------------------------------------------
       
   716 //
       
   717 void CIAUpdateFWSyncHandler::ShowProgressDialogL( )
       
   718 	{
       
   719         iWaitDialog = new ( ELeave ) CAknWaitDialog(
       
   720             ( REINTERPRET_CAST( CEikDialog**, &iWaitDialog ) ) );
       
   721         iWaitDialog->ExecuteLD( R_FOTA_CHECK_WAIT_NOTE );
       
   722         iWaitDialog->SetCallback( this );
       
   723 	}
       
   724 
       
   725 // -----------------------------------------------------------------------------
       
   726 // CIAUpdateFWSyncHandler::HideProgressDialogL
       
   727 // -----------------------------------------------------------------------------
       
   728 //
       
   729 void CIAUpdateFWSyncHandler::HideProgressDialogL()
       
   730     {
       
   731     if ( iWaitDialog )
       
   732         {
       
   733         iWaitDialog->ProcessFinishedL();
       
   734         iWaitDialog = NULL;
       
   735         }
       
   736     }
       
   737 
       
   738 // -----------------------------------------------------------------------------
       
   739 // CIAUpdateFWSyncHandler::Session
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 RSyncMLSession& CIAUpdateFWSyncHandler::Session()
       
   743 	{
       
   744 	__ASSERT_DEBUG(iSyncSession, TUtil::Panic(KErrGeneral));
       
   745 	
       
   746 	return *iSyncSession;
       
   747 	}
       
   748 
       
   749 
       
   750 // -----------------------------------------------------------------------------
       
   751 // CIAUpdateFWSyncHandler::SyncRunning
       
   752 // -----------------------------------------------------------------------------
       
   753 //
       
   754 TBool CIAUpdateFWSyncHandler::SyncRunning()
       
   755 	{   
       
   756 	return iSyncRunning;
       
   757 	}
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // CIAUpdateFWSyncHandler::State
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 CIAUpdateFWSyncState* CIAUpdateFWSyncHandler::State()
       
   764 	{
       
   765 	__ASSERT_DEBUG(iState, TUtil::Panic(KErrGeneral));
       
   766 
       
   767 	return iState;
       
   768 	}
       
   769 	
       
   770 // -----------------------------------------------------------------------------
       
   771 // CIAUpdateFWSyncHandler::CancelSynchronizeL
       
   772 // -----------------------------------------------------------------------------
       
   773 //		
       
   774 void CIAUpdateFWSyncHandler::CancelSynchronizeL()
       
   775     { 
       
   776     if ( iSyncRunning )
       
   777         {
       
   778         iSyncJob.StopL();
       
   779         SynchronizeCompletedL( KErrCancel );
       
   780         }
       
   781     }
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 // CIAUpdateFWSyncHandler::DialogDismissedL
       
   785 // -----------------------------------------------------------------------------
       
   786 //		
       
   787 void CIAUpdateFWSyncHandler::DialogDismissedL( TInt aButtonId )
       
   788     {
       
   789 	if ( aButtonId == EEikBidCancel )
       
   790 		{
       
   791 
       
   792 		if ( SyncRunning() )
       
   793 			{
       
   794 
       
   795 			TRAP_IGNORE( iSyncJob.StopL() );
       
   796 		    
       
   797 		    State()->SetSyncPhase( CIAUpdateFWSyncState::EPhaseCanceling );
       
   798 			}
       
   799 		}
       
   800     }
       
   801 
       
   802 
       
   803 // End of File