fotaapplication/fotaserver/FotaServer/src/fotadownload.cpp
changeset 0 b497e44ab2fc
child 9 57a65a3a658c
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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:   downloads upd pkg
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    22 #include <es_enum_internal.h>
       
    23 #endif
       
    24 #include <centralrepository.h>
       
    25 #include <f32file.h>
       
    26 #include <AknWaitDialog.h>
       
    27 #include <fotaserver.rsg>
       
    28 #include <eikprogi.h>
       
    29 #include <eikenv.h>
       
    30 #include <apgtask.h>
       
    31 #include <apgwgnam.h>
       
    32 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    33 #include <es_sock.h>
       
    34 #else
       
    35 #include <es_sock.h>
       
    36 #include <es_sock_partner.h>
       
    37 #endif
       
    38 #include <es_enum.h>
       
    39 #include <NSmlDMSync.rsg>	//OMA DM UI for reading resource
       
    40 #include <bautils.h>
       
    41 #include <StringLoader.h>
       
    42 #include <DevManInternalCRKeys.h> //for reading san feature
       
    43 #include <e32property.h>
       
    44 #include "fotastorage.h"
       
    45 #include "FotaSrvApp.h"
       
    46 #include "fotadownload.h"
       
    47 #include "fotaserverPrivatePSKeys.h"
       
    48 #include "FotaNetworkRegStatus.h"
       
    49 #include <startupdomainpskeys.h>	//globalrfsstates
       
    50 #define __LEAVE_IF_ERROR(x) if(KErrNone!=x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); }
       
    51 #define __LEAVE(x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); }
       
    52 
       
    53 
       
    54 // --------------------------------------------------------------------------
       
    55 // CFotaDownload::NewL 
       
    56 // --------------------------------------------------------------------------
       
    57 CFotaDownload* CFotaDownload::NewL (CFotaServer* aServer)
       
    58 	{
       
    59 	__ASSERT_ALWAYS( aServer, User::Panic(KFotaPanic, KErrArgument) );
       
    60 	CFotaDownload* ao = new (ELeave) CFotaDownload();
       
    61 	ao->iFotaServer = aServer;
       
    62 	return ao;
       
    63 	}
       
    64 
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CFotaDownload::RunL
       
    68 // Do operations started in HandleDmgrEvent
       
    69 // --------------------------------------------------------------------------
       
    70 void CFotaDownload::RunL()
       
    71 	{
       
    72 	FLOG(_L( "[FotaServer] CFotaDownload::RunL() >>"));
       
    73 	CancelDownload( ETrue );
       
    74 	CreateDownloadL();
       
    75 	FLOG(_L( "[FotaServer] CFotaDownload::RunL() <<" ) );
       
    76 	}
       
    77 
       
    78 
       
    79 // --------------------------------------------------------------------------
       
    80 // CFotaDownload::DoCancel()
       
    81 // Cancel notifier request
       
    82 // --------------------------------------------------------------------------
       
    83 //
       
    84 void CFotaDownload::DoCancel()
       
    85 	{
       
    86 	FLOG(_L("CFotaDownload::DoCancel() >>"));
       
    87 	FLOG(_L("CFotaDownload::DoCancel() <<"));
       
    88 	}
       
    89 
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CFotaDownload::RunError(TInt aError)
       
    93 // Handle active object run error.
       
    94 // --------------------------------------------------------------------------
       
    95 //
       
    96 TInt CFotaDownload::RunError(TInt aError)
       
    97 	{
       
    98 	if(aError)
       
    99 		{
       
   100 		FLOG(_L(" CFotaDownload::RunError err %d"), aError );
       
   101 		}
       
   102 	return aError;
       
   103 	}
       
   104 
       
   105 
       
   106 // --------------------------------------------------------------------------
       
   107 // CFotaDownload::CFotaDownload()
       
   108 // --------------------------------------------------------------------------
       
   109 //
       
   110 CFotaDownload::CFotaDownload() : CActive(EPriorityNormal)
       
   111 		, iUpdateAfterDownload (EFalse), iUrl( NULL ),
       
   112 		iDownload (NULL),
       
   113 		iDownloadedContentSize(0),
       
   114 		iPreviousContentSize ( 0 ), iShowOMACDUI(EFalse), iShowDLPrgUI(EFalse),
       
   115 		iDownloadResumable (EFalse),				
       
   116 		iFMSEnabled (EFalse),
       
   117 		iDownloadActive (EFalse),
       
   118 		iFreshDL(ETrue),
       
   119 		iUserInitiatedResume(EFalse),		
       
   120 		iSanValue(KErrNotFound),
       
   121 		iDownloadFinalized(EFalse)		
       
   122 	{
       
   123 	CActiveScheduler::Add( this ); 
       
   124 	FLOG(_L("CFotaDownload::CFotaDownload()"));
       
   125 	}
       
   126 
       
   127 
       
   128 // --------------------------------------------------------------------------
       
   129 // CFotaDownload::~CFotaDownload()
       
   130 // --------------------------------------------------------------------------
       
   131 //
       
   132 CFotaDownload::~CFotaDownload()
       
   133 	{
       
   134 	FLOG(_L("CFotaDownload::~CFotaDownload() >>"));
       
   135 	Cancel();
       
   136 	
       
   137 	//Sets download state inactive if accidently closed. This is anyhow taken care in FinalizeDownload in Server.
       
   138 	SetDownloadActive(EFalse);
       
   139 	CancelDownload( ETrue );
       
   140 	if ( iUrl )
       
   141 		{
       
   142 		delete iUrl; iUrl=NULL;
       
   143 		}
       
   144 /*	if ( iNotifHandler ) Deleted at server
       
   145 		{
       
   146 		iNotifHandler->Cancel();
       
   147 		delete iNotifHandler;        
       
   148 		}*/
       
   149 	if ( iDLProgressDlg )
       
   150 		{
       
   151 		delete iDLProgressDlg; iDLProgressDlg=NULL;
       
   152 		}
       
   153 
       
   154 	if (iDownloadMgr.Handle())
       
   155 		iDownloadMgr.Close();
       
   156 	//don't delete iFotaServer as it doesn't belong here.
       
   157 	
       
   158 	FLOG(_L("CFotaDownload::~CFotaDownload() <<"));
       
   159 }
       
   160 
       
   161 
       
   162 // --------------------------------------------------------------------------
       
   163 // CFotaDownload::CancelDownload
       
   164 // Cancel download
       
   165 // --------------------------------------------------------------------------
       
   166 //
       
   167 void CFotaDownload::CancelDownload( const TBool aCancelProgressBar )
       
   168 	{
       
   169 	FLOG(_L("CFotaDownload::CancelDownload() >>"));
       
   170 	
       
   171 	if( iDownloadMgr.Handle() )
       
   172 		{
       
   173 		iDownloadMgr.Close();
       
   174 		}
       
   175 
       
   176 	if ( aCancelProgressBar  && iDLProgressDlg )
       
   177 		{
       
   178 		TRAPD(err, iDLProgressDlg->ProcessFinishedL() ) ;// deletes
       
   179 		if(err); // remove compiler warning
       
   180 		delete iDLProgressDlg;
       
   181 		iDLProgressDlg = NULL;
       
   182 		}
       
   183 	FLOG(_L("CFotaDownload::CancelDownload() <<"));
       
   184 	}
       
   185 
       
   186 // --------------------------------------------------------------------------
       
   187 // CFotaDownload::CreateDownloadL
       
   188 // Create  download
       
   189 // --------------------------------------------------------------------------
       
   190 //
       
   191 void CFotaDownload::CreateDownloadL()
       
   192 	{
       
   193 	FLOG(_L("CFotaDownload::CreateDownloadL() >>") );
       
   194 	__ASSERT_ALWAYS( iDownloadMgr.Handle()==0, User::Leave(KErrAlreadyExists) );
       
   195 	RHttpDownload*  d(NULL);
       
   196 	iDLNeedsReset = EFalse;
       
   197 	TBool       created;
       
   198 	iDownloadMgr.ConnectL( TUid::Uid(KFotaServerUid) , *this, EFalse); 
       
   199 	FLOG(_L("CFotaDownload::CreateDownloadL, Stage 1") );
       
   200 	iDownloadMgr.DeleteAll();
       
   201 
       
   202 	TRAPD(err, d = &iDownloadMgr.CreateDownloadL( *iUrl, created ) );
       
   203 	RFs fs;	
       
   204 	if(fs.Connect() == KErrNone)
       
   205 	    {
       
   206 	    RFile file;    
       
   207 	    CleanupClosePushL( fs );
       
   208 	    CleanupClosePushL( file );
       
   209 	    err=fs.MkDir(KDDDirPath);
       
   210 	    FLOG(_L("creating directory err as %d"),err);
       
   211 	    err=fs.SetSessionPath(KDDDirPath);
       
   212 	    FLOG(_L("setting session path err as %d"),err);
       
   213 	    err=fs.ShareProtected();
       
   214 	    FLOG(_L("ShareProtected err as %d"),err);
       
   215 	    err = file.Replace(fs,KDDFilename, EFileWrite|EFileShareAny);	
       
   216 	    FLOG(_L("creating rfile err as %d"),err);	
       
   217 	    err = d->SetFileHandleAttribute(file);
       
   218 	    FLOG(_L("setting dlmgr destfile attrib err as %d"),err);
       
   219 	    CleanupStack::PopAndDestroy( &file );
       
   220 	    CleanupStack::PopAndDestroy( &fs );
       
   221 	    }	
       
   222 	FLOG(_L("CFotaDownload::CreateDownloadL, Stage 2. err %d"),err);
       
   223 	if ( err  == KErrArgument ) User::Leave( KErrNotFound );
       
   224 	else if( err !=KErrNone)    User::Leave( err );
       
   225 
       
   226 	if ( iDLState.iIapId > KErrNotFound )
       
   227 		{
       
   228 		FLOG(_L("   Using internet access point iapid: %d"), iDLState.iIapId);
       
   229 		err = iDownloadMgr.SetIntAttribute( EDlMgrIap, iDLState.iIapId); // IAP id
       
   230 		User::LeaveIfError( err );        
       
   231 		//At this point the iIapId used in the SyncML Session is presumed working. Hence
       
   232 		//the same is stored in database for use during download.
       
   233 		FLOG(_L("Setting IAPID=%d is FotaState"),iDLState.iIapId);
       
   234 		iFotaServer->iDatabase->OpenDBL();
       
   235 		iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBIapId );
       
   236 		iFotaServer->iDatabase->CloseAndCommitDB();
       
   237 		}
       
   238 	FLOG(_L("CFotaDownload::CreateDownloadL, Stage 3") );
       
   239 	User::LeaveIfError( d->SetIntAttribute(EDlAttrFotaPckgId ,iDLState.iPkgId) );
       
   240 	FLOG(_L("CFotaDownload::CreateDownloadL, Stage 4") );
       
   241 	User::LeaveIfError( d->SetBoolAttribute(EDlAttrNoContentTypeCheck,ETrue) );
       
   242 
       
   243 	// If ui hidden or download restarting, do not show descriptor
       
   244 	if ( !iShowOMACDUI || iRestartCounter > 0 )
       
   245 		{
       
   246 		FLOG(_L("setting DD to hidden"));
       
   247 		User::LeaveIfError(iDownloadMgr.SetBoolAttribute( EDlMgrSilentMode,ETrue )) ;
       
   248 		}
       
   249 	//It's a fresh download
       
   250 	iFreshDL = ETrue;
       
   251 
       
   252 	// Start download 
       
   253 	User::LeaveIfError(iDownloadMgr.StartAll()); 
       
   254 	FLOG(_L("CFotaDownload::CreateDownloadL, Stage 5") );
       
   255 	iDLProgress = EStarted;
       
   256 
       
   257 	//This P&S Key is used to notify DM UI on any download event. key=0 for idle and key=1 for download
       
   258 	err = RProperty::Set( TUid::Uid(KOmaDMAppUid),
       
   259 			KFotaDMRefresh,
       
   260 			ETrue );
       
   261 	FLOG(_L("RProperty KFotaDMRefresh Set Etrue, err = %d"), err);
       
   262 
       
   263 	SetDownloadActive(ETrue);
       
   264 
       
   265 	User::LeaveIfError(err);
       
   266 	FLOG(_L("[FotaServer]  CFotaDownload::CreateDownloadL <<"));
       
   267 }
       
   268 
       
   269 	// --------------------------------------------------------------------------
       
   270 	// CFotaDownload::DownloadL
       
   271 	// Start download of swupd package.
       
   272 	// --------------------------------------------------------------------------
       
   273 	//
       
   274 void CFotaDownload::DownloadL(TDownloadIPCParams aParams,const TDesC8& aPkgURL
       
   275 		,TBool aUpdateAfterDownload,const TInt aIapid,const TInt aRestartDownload)
       
   276 	{
       
   277 	FLOG(_L("[FotaServer]  CFotaDownload::DownloadL >> restart %d"),aRestartDownload);
       
   278 
       
   279 	TInt err = RProperty::Define( TUid::Uid(KOmaDMAppUid),
       
   280 			KFotaDMRefresh,
       
   281 			RProperty::EInt,KReadPolicy,KWritePolicy);
       
   282 	FLOG(_L("RProperty KFotaDMRefresh Define, err = %d"), err);        
       
   283 	if (err != KErrAlreadyExists )
       
   284 		{
       
   285 		User::LeaveIfError(err);
       
   286 
       
   287 		err = RProperty::Set( TUid::Uid(KOmaDMAppUid),
       
   288 				KFotaDMRefresh,
       
   289 				KErrNotFound );
       
   290 
       
   291 		FLOG(_L("RProperty KFotaDMRefresh Set KErrNotFound, err = %d"), err);
       
   292 		User::LeaveIfError(err);
       
   293 		}
       
   294 
       
   295 	if ( iUrl ) {delete iUrl; iUrl=NULL;}
       
   296 	iUrl = aPkgURL.Alloc();
       
   297 	iUpdateAfterDownload = aUpdateAfterDownload;
       
   298 	iRestartCounter = aRestartDownload;
       
   299 
       
   300 	iDLState        = aParams;
       
   301 	FLOG(_L("CFotaDownload::DownloadL, Stage 1") );
       
   302 
       
   303 	// Set state -------------------------------------------------------------
       
   304 	iDLState.iState = RFotaEngineSession::EStartingDownload;
       
   305 
       
   306 	iDLState.iResult = KErrNotFound;
       
   307 	iDLState.iUpdateLtr = aUpdateAfterDownload;
       
   308 	iFotaServer->iDatabase->OpenDBL();
       
   309 	iFotaServer->iDatabase->SetStateL( iDLState, *iUrl,EFDBState|EFDBResult
       
   310 			| EFDBProfileId|EFDBPkgUrl|EFDBPkgName|EFDBVersion|EFDBUpdateLtr);
       
   311 	iFotaServer->iDatabase->CloseAndCommitDB();
       
   312 	FLOG(_L("CFotaDownload::DownloadL, Stage 2, pkgid:%d"),iDLState.iPkgId);
       
   313 
       
   314 	// 2. Get Iap Id to use for download. This would be set in iDLState.iIapId.
       
   315 	SetIapToUseL(aParams, aIapid);
       
   316 
       
   317 	// 3. Determine whether download should be visible or not
       
   318 	// Autoaccepted profile?
       
   319 
       
   320 	SetDownloadUiBehavior(ETrue);
       
   321 
       
   322 	CancelDownload( ETrue );
       
   323 
       
   324 	FLOG(_L("Setting SessionType=%d in FotaState"),iDLState.iSessionType);
       
   325 	iFotaServer->iDatabase->OpenDBL();
       
   326 	iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBSessionType );
       
   327 	iFotaServer->iDatabase->CloseAndCommitDB();
       
   328 	FLOG(_L("CFotaDownload::DownloadL, Stage 3") );
       
   329 	//Called to read the download variations in Fota (resume support & FMS)
       
   330 	CheckDownloadVariations();
       
   331 
       
   332 	//Create the download
       
   333 	CreateDownloadL( );
       
   334 	FLOG(_L("[FotaServer]  CFotaDownload::DownloadL <<"));
       
   335 	}
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CFotaDownload::HandleDLProgressDialogExitL
       
   339 // Handle canceling of download
       
   340 // ---------------------------------------------------------------------------
       
   341 TBool CFotaDownload::HandleDLProgressDialogExitL( TInt aButtonId ) 
       
   342 	{
       
   343 	FLOG(_L("CFotaDownload::HandleDLProgressDialogExitL %d, note = %d >>"),aButtonId, iDLProgressDlg->iNoteType);
       
   344 	// Cancel clicked during download
       
   345 	if ( aButtonId == KErrNotFound )
       
   346 		{
       
   347 		iRestartCounter = -1;
       
   348 		FLOG(_L("[FotaServer]  CFotaDownload::HandleDLProgressDialogExitL Hiding UI"));
       
   349 		iFotaServer->iParentApp->SetUIVisibleL ( EFalse, ETrue );
       
   350 		iUpdateAfterDownload = EFalse;
       
   351 
       
   352 		iDLState.iResult = RFotaEngineSession::EResUserCancelled;
       
   353 
       
   354 		if (iDLProgressDlg->iNoteType == EConnectingNote)
       
   355 			{
       
   356 			iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume;
       
   357 
       
   358 			TInt active (KErrNotFound);
       
   359 			RProperty::Get( TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, active );
       
   360 			FLOG(_L("active = %d"),active);
       
   361 			
       
   362 			if (active) //Resume operation has just begun and download request is submitted to dlmgr. Hence need to suspend.
       
   363 				{
       
   364 				RunDownloadSuspendL(RFotaEngineSession::EResUserCancelled, ETrue);
       
   365 				}
       
   366 			else //Resume operation has just begun, but download request is not submitted to dlmgr
       
   367 				{
       
   368 				LaunchNotifierL( ESyncMLFwUpdOmaDLPostponed, EFalse, EFalse );
       
   369 				iFotaServer->FinalizeDownloadL( iDLState );
       
   370 				}
       
   371 			}
       
   372 		else if (iDLProgressDlg->iNoteType == EDownloadingNote)
       
   373 			{
       
   374 			if (iDownloadResumable)
       
   375 				{
       
   376 				//Resume is supported. Query user whether to postpone or cancel download.
       
   377 				FLOG(_L("User pressed cancel. Resume is supported; hence pause download and query user if download has to be postponed or cancelled permanently."));
       
   378 				RunDownloadSuspendL(RFotaEngineSession::EResUserCancelled);
       
   379 				}
       
   380 			else
       
   381 				{
       
   382 				//Resume is not supported. Download is cancelled
       
   383 				FLOG(_L("User pressed cancel. Resume is not supported & hence download has to be cancelled"));
       
   384 				RunDownloadCancelL(RFotaEngineSession::EResUserCancelled);
       
   385 				}
       
   386 			}
       
   387 		}
       
   388 	FLOG(_L("CFotaDownload::HandleDLProgressDialogExitL <<"));
       
   389 	return ETrue;
       
   390 	}
       
   391 
       
   392 
       
   393 // --------------------------------------------------------------------------
       
   394 // CFotaDownload::DoHandleDMgrEventL
       
   395 // Handles download events. Updates package state accordingly
       
   396 // --------------------------------------------------------------------------
       
   397 void CFotaDownload::DoHandleDMgrEventL( RHttpDownload* aDownload
       
   398 		, THttpDownloadEvent aEvent )
       
   399 	{
       
   400 	__ASSERT_ALWAYS( aDownload, User::Panic(KFotaPanic, KErrArgument) );
       
   401 	TInt32                      sysErrorId( KErrNone );
       
   402 	TInt32                      contentsize;
       
   403 	TInt32                      downloadedsize;
       
   404 
       
   405 	TInt32                      tmp;
       
   406 	THttpDownloadMgrError       dlErrorId;
       
   407 	iDownload = aDownload;
       
   408 	// If DL is in final state (complete/fail), there's an error id available.
       
   409 	User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrGlobalErrorId
       
   410 			,sysErrorId ) );
       
   411 	User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrDownloadedSize
       
   412 			,downloadedsize ) );
       
   413 	User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrLength
       
   414 			,contentsize ) );
       
   415 	User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrErrorId
       
   416 			,tmp ) );
       
   417 	dlErrorId = (THttpDownloadMgrError)tmp;
       
   418 
       
   419 
       
   420 	// Update progress dlg progress
       
   421 	if ( !iDLProgressDlg && iRestartCounter>0)
       
   422 		{
       
   423 		FLOG(_L("reshowing progress..."));
       
   424 		iDLProgressDlg = new(ELeave) CFotaDLProgressDlg((CEikDialog** ) &iDLProgressDlg , EFalse, this, EDownloadingNote );
       
   425 		iDLProgressDlg->PrepareLC( R_FOTASERVER_DL_PROGRESS_DIALOG );
       
   426 		iDLProgressDlg->RunLD();
       
   427 		}
       
   428 	if (iDLProgressDlg)
       
   429 		{
       
   430 		CEikProgressInfo* progressInfo = iDLProgressDlg->GetProgressInfoL();
       
   431 		__ASSERT_ALWAYS( progressInfo, User::Panic(KFotaPanic, KErrBadHandle) );
       
   432 		if ( iPreviousContentSize!=contentsize )
       
   433 			{
       
   434 			iPreviousContentSize = contentsize;
       
   435 			if ( contentsize > 0 )
       
   436 				{
       
   437 				progressInfo->SetFinalValue( contentsize );
       
   438 				}
       
   439 			}
       
   440 		TInt incr = downloadedsize - iDownloadedContentSize;
       
   441 		if (incr<=0) incr=0; //Protection
       
   442 		progressInfo->IncrementAndDraw(incr);
       
   443 		iDownloadedContentSize = downloadedsize;
       
   444 		}
       
   445 	FLOG(_L("CFotaDownload::HandleDMgrEventL() >>   DLstate:%d  ProgressSt:%d\
       
   446 	globErr: %d DLError: %d (%d/%d)"),aEvent.iDownloadState
       
   447 	,aEvent.iProgressState,sysErrorId,dlErrorId,downloadedsize,contentsize );
       
   448 
       
   449 	if ( sysErrorId <= -25000)  { FLOG(_L("  error %d interpreted as http \
       
   450 	error %d") , sysErrorId, sysErrorId + 25000 ); }
       
   451 
       
   452 	switch ( aEvent.iDownloadState )
       
   453 	{
       
   454 	case EHttpDlCreated:		// 1
       
   455 		{
       
   456 		FLOG(_L("Download State: EHttpDlCreated"));
       
   457 		}
       
   458 		break;
       
   459 	case EHttpDlInprogress:     // 2
       
   460 		{
       
   461 		FLOG(_L("Download State: EHttpDlProgress"));
       
   462 
       
   463 
       
   464 		if (aEvent.iProgressState == EHttpProgCodDescriptorDownloaded)
       
   465 			{
       
   466 			if (iShowOMACDUI || iShowDLPrgUI)
       
   467 				{
       
   468 				iFotaServer->iParentApp->SetUIVisibleL ( ETrue, EFalse);
       
   469 				}
       
   470 			}
       
   471 
       
   472 		// Is ECodLoadEnd optimized out?
       
   473 		if ( aEvent.iProgressState == EHttpProgCodLoadEnd ) // 2503
       
   474 			{
       
   475 			TInt    err;
       
   476 			err = aDownload->Start();  // PPAR-6FRHFY fixed
       
   477 			if(err)
       
   478 				{
       
   479 				FLOG(_L(" ERROR when restarting DL %d"),err);
       
   480 				User::Leave(err);
       
   481 				}
       
   482 			FLOG( _L("          DL restarted") );
       
   483 			}
       
   484 
       
   485 		// Should tell user to free disk space. But how do we know that disk space is about be exceeded?
       
   486 
       
   487 		if ( iDLNeedsReset )
       
   488 			{
       
   489 			FLOG(_L("aDownload->Reset();"));
       
   490 			iDLNeedsReset = EFalse;
       
   491 			iStatus = KRequestPending;
       
   492 			SetActive();
       
   493 			TRequestStatus* status = &iStatus;
       
   494 			User::RequestComplete( status, KErrNone );
       
   495 			User::LeaveIfError( aDownload->Reset() );
       
   496 			}
       
   497 
       
   498 		// Body data of descriptor or payload pkg
       
   499 		if ( aEvent.iProgressState == EHttpProgResponseBodyReceived && iDLProgress==EDescriptorDownloaded/*2500*/)
       
   500 			{
       
   501 			// Now pkg size can be retrieved. must check size.
       
   502 			iDLState.iPkgSize = contentsize;
       
   503 			FLOG(_L("Setting PkgSize=%d in FotaState"),contentsize);
       
   504 			iFotaServer->iDatabase->OpenDBL();
       
   505 			iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBPkgSize );
       
   506 			iFotaServer->iDatabase->CloseAndCommitDB();
       
   507 			
       
   508 
       
   509 			TInt contentsize2 = contentsize;
       
   510 			
       
   511 			TInt dlsize (KErrNone);
       
   512 			TInt tlsize (KErrNone);
       
   513 
       
   514 			TRAPD(err, iFotaServer->GetDownloadUpdatePackageSizeL(iDLState.iPkgId, dlsize,tlsize));
       
   515 			if(err); // remove compiler warning
       
   516 			contentsize2 -= dlsize;
       
   517 			FLOG(_L("check pkg size = %d"),contentsize2 );
       
   518 
       
   519 			CFotaStorage::TFreeSpace avail = iFotaServer->StoragePluginL()->IsPackageStoreSizeAvailableL(contentsize2);
       
   520 
       
   521 			iDLProgress = ESizeChecked;
       
   522 
       
   523 			if ( avail==CFotaStorage::EDoesntFitToFileSystem )
       
   524 				{
       
   525 				FLOG(_L("CFotaStorage::EDoesntFitToFileSystem"));
       
   526 				if (iFreshDL)
       
   527 					{
       
   528 					if ( iShowDLPrgUI )
       
   529 						{
       
   530 						FLOG(_L("iDLNeedsReset = ETrue;"));
       
   531 						iDLNeedsReset = ETrue;
       
   532 						LaunchNotifierL( ESyncMLFwUpdOmaDLNotEnoughMemory, KErrDiskFull,contentsize2 );
       
   533 						}
       
   534 					else
       
   535 						{
       
   536 						iDLState.iResult = RFotaEngineSession::EResDLFailDueToDeviceOOM;
       
   537 						iDLState.iState  = RFotaEngineSession::EDownloadFailed;
       
   538 						iUpdateAfterDownload = EFalse;
       
   539 						LaunchNotifierL( ESyncMLFwUpdErrorNote, KErrGeneral, contentsize2,ETrue );
       
   540 						}
       
   541 					}
       
   542 				else //resuming download
       
   543 					{
       
   544 					FLOG(_L("Memory need in order to resume. Notify user..."));
       
   545 					LaunchNotifierL( ESyncMLFwUpdOmaDLNotEnoughMemory, KErrDiskFull,contentsize2 );
       
   546 					RunDownloadSuspendL(RFotaEngineSession::EResDLFailDueToDeviceOOM);
       
   547 					}
       
   548 					
       
   549 				}
       
   550 			}
       
   551 
       
   552 		// OMA DD download completed , must hide progress
       
   553 		if ( aEvent.iProgressState == EHttpProgContentTypeChanged ) // 2055
       
   554 			{
       
   555 			if ( iDLProgressDlg )
       
   556 				{
       
   557 				iDLProgressDlg->ProcessFinishedL(); // deletes itself
       
   558 				delete iDLProgressDlg;
       
   559 				iDLProgressDlg = NULL;
       
   560 				}
       
   561 			}
       
   562 		// OMA DD accepted,show progress
       
   563 		if ( aEvent.iProgressState == EHttpProgCodDescriptorAccepted ) // 2502
       
   564 
       
   565 			{
       
   566 			iDLProgress = EDescriptorDownloaded;
       
   567 			if ( iShowDLPrgUI )
       
   568 				{
       
   569 				FLOG(_L("SHOW PROGRESS"));
       
   570 				if ( iDLProgressDlg )
       
   571 					{
       
   572 					FLOG(_L("Removing Connecting progress note..."));
       
   573 					iDLProgressDlg->ProcessFinishedL();
       
   574 					delete iDLProgressDlg;
       
   575 					iDLProgressDlg = NULL;
       
   576 					}
       
   577 				if (!iDLProgressDlg)
       
   578 					{
       
   579 					
       
   580 					FLOG(_L("Creating iDLProgressDlg"));
       
   581 					iDLProgressDlg = new(ELeave) CFotaDLProgressDlg((CEikDialog** ) &iDLProgressDlg , EFalse, this, EDownloadingNote );
       
   582 					iDLProgressDlg->PrepareLC( R_FOTASERVER_DL_PROGRESS_DIALOG );
       
   583 					iDLProgressDlg->RunLD();
       
   584 					}
       
   585 				CEikProgressInfo* progressInfo = iDLProgressDlg->GetProgressInfoL();
       
   586 				progressInfo->SetFinalValue( 500 );
       
   587 				iPreviousContentSize = -1;
       
   588 				iDownloadedContentSize = 0;
       
   589 				iFotaServer->iParentApp->SetUIVisibleL ( ETrue , EFalse );
       
   590 				}
       
   591 			if (iDownloadResumable)
       
   592 				{
       
   593 				FLOG(_L("Setting download as resumable"));
       
   594 				iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume;
       
   595 		    	iFotaServer->SetStartupReason(EFotaDownloadInterrupted);
       
   596 				}
       
   597 			else
       
   598 				{
       
   599 				FLOG(_L("Setting download as non resumable"));
       
   600 				iDLState.iState = RFotaEngineSession::EDownloadProgressing;
       
   601 				iFotaServer->SetStartupReason(EFotaPendingGenAlert);
       
   602 				}
       
   603 			iFotaServer->iDatabase->OpenDBL();
       
   604 			iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBState );
       
   605 			iFotaServer->iDatabase->CloseAndCommitDB();
       
   606 
       
   607 
       
   608 			if (iDLState.iIapId <= 0) //Read the IAP ID when not known, and set it into db.
       
   609 				{
       
   610 				TInt32 usedapid (KErrNotFound);
       
   611 				TInt er = iDownloadMgr.GetIntAttribute( EDlMgrIap, usedapid);
       
   612 				iDLState.iIapId = usedapid;
       
   613 				FLOG(_L("Setting IAPID=%d is FotaState"),iDLState.iIapId);
       
   614 				iFotaServer->iDatabase->OpenDBL();
       
   615 				iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBIapId );
       
   616 				iFotaServer->iDatabase->CloseAndCommitDB();
       
   617 				}
       
   618 			}
       
   619 		}
       
   620 		break;
       
   621 	case EHttpDlCompleted:      // 4
       
   622 		{
       
   623 		FLOG(_L("Download State: EHttpDlCompleted"));
       
   624 
       
   625 		iRestartCounter = -1;
       
   626 		if ( iDLProgressDlg )
       
   627 			{
       
   628 			iDLProgressDlg->ProcessFinishedL(); // deletes itself
       
   629 			delete iDLProgressDlg;
       
   630 			iDLProgressDlg = NULL;
       
   631 			}
       
   632 		iDLState.iState     = RFotaEngineSession::EDownloadComplete;
       
   633 
       
   634 		if (iUpdateAfterDownload)
       
   635 			iDLState.iResult = KErrNotFound;
       
   636 		else
       
   637 			iDLState.iResult    = RFotaEngineSession::EResSuccessful;
       
   638 		iFotaServer->FinalizeDownloadL( iDLState );
       
   639 		}
       
   640 		break;
       
   641 	case EHttpDlPaused: //Event thrown for any resumable download
       
   642 	case EHttpDlFailed: //Event thrown for any non-resumable download or critical error on resumable download
       
   643 		{
       
   644 		
       
   645 		if (aEvent.iProgressState != EHttpProgNone) //Accepting only events from COD
       
   646 			return;
       
   647 
       
   648 		if (aEvent.iDownloadState == EHttpDlPaused)
       
   649 			{
       
   650 			FLOG(_L("Download State: EHttpDlPaused"));
       
   651 			if (iDownloadResumable)
       
   652 				{
       
   653 				iDLState.iState     = RFotaEngineSession::EDownloadProgressingWithResume;
       
   654 				}
       
   655 			else 
       
   656 				{
       
   657 				// iDownloadResumable remains 0 even for resumable download.
       
   658 				iDLState.iState     = RFotaEngineSession::EDownloadFailed;
       
   659 				}
       
   660 			}
       
   661 		else //aEvent.iDownloadState = EHttpDlFailed
       
   662 			{
       
   663 			FLOG(_L("Download State: EHttpDlFailed"));
       
   664 			iDLState.iState     = RFotaEngineSession::EDownloadFailed;
       
   665 			iDownloadResumable = EFalse;
       
   666 			}
       
   667 		//Remove the download progress bar
       
   668 		if ( iDLProgressDlg && (iDLState.iResult != RFotaEngineSession::EResUserCancelled ))
       
   669 			{
       
   670 			FLOG(_L("Shd not come in EResUserCancelled"));
       
   671 			iDLProgressDlg->ProcessFinishedL(); // deletes itself
       
   672 			delete iDLProgressDlg;
       
   673 			iDLProgressDlg = NULL;
       
   674 			}
       
   675 		// This is restarted download => decrement counter
       
   676 		if ( iRestartCounter > 0 )
       
   677 			{
       
   678 			--iRestartCounter;
       
   679 			if ( iRestartCounter <=0 ) iRestartCounter = -1;
       
   680 			FLOG(_L("   iRestartCounter to %d"),iRestartCounter );
       
   681 			}
       
   682 		/*****************************/
       
   683 		//Handling all errors now...//
       
   684 		/****************************/
       
   685 		TInt notifType (KErrNotFound);
       
   686 		TInt notifParam (KErrNotFound);
       
   687 		//Handling User Cancel of Download Descriptor
       
   688 		if ( dlErrorId == EGeneral && (sysErrorId == KErrAbort || sysErrorId == KErrCancel ))
       
   689 			{
       
   690 			FLOG(_L("Reason: User cancelled download descriptor"));
       
   691 			//LaunchNotifierL(ESyncMLFwUpdOmaDLCancelled, EFalse, EFalse);
       
   692 			iRestartCounter = -1;
       
   693 			iDLState.iResult = RFotaEngineSession::EResUserCancelled;
       
   694 			notifType = ESyncMLFwUpdOmaDLCancelled;
       
   695 			notifParam = KErrNone;
       
   696 			}
       
   697 		//Handling User Cancel
       
   698 		else if ( iDLState.iResult == RFotaEngineSession::EResUserCancelled ) //This variable is set in RunDownloadCancelL or RunDownloadSuspendL
       
   699 			{
       
   700 			iRestartCounter = -1;
       
   701 			//If initial pause is successful, query user if he wants to postpone or cancel permanently.
       
   702 			iFotaServer->iDatabase->OpenDBL();
       
   703 			iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBState);
       
   704 			iFotaServer->iDatabase->CloseAndCommitDB();
       
   705 
       
   706 			if (iDownloadResumable)
       
   707 				{
       
   708 				if (!iSilentOpn)
       
   709 					{
       
   710 					FLOG(_L("Download has been paused successful. Query user if he wants to postpone or cancel permanently"));
       
   711 					LaunchNotifierL(ESyncMLFwUpdOmaDLUserCancel, KErrNone, KErrNone);
       
   712 					break;
       
   713 					}
       
   714 				else
       
   715 					{
       
   716 					notifType = ESyncMLFwUpdOmaDLPostponed;
       
   717 					notifParam = KErrNone;
       
   718 					}
       
   719 				}
       
   720 			else 
       
   721 				{
       
   722 				FLOG(_L("Error while initial pausing...%d Hence download has to be cancelled permanently!"));
       
   723 				RunDownloadCancelL(RFotaEngineSession::EResUserCancelled);
       
   724         notifType = ESyncMLFwUpdOmaDLCancelled;
       
   725         notifParam = KErrNone;
       
   726 				}
       
   727 			}
       
   728 		else if ( iDLState.iResult == RFotaEngineSession::EResDLFailDueToDeviceOOM )
       
   729 			{
       
   730 			FLOG(_L("Reason: Not enough memory to perform resume"));
       
   731 			iRestartCounter = -1;
       
   732 
       
   733 			if (iDownloadResumable)
       
   734 				iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume;
       
   735 			else
       
   736 				iDLState.iState = RFotaEngineSession::EDownloadFailed;
       
   737 			}
       
   738 		//Handling user cancel IAP selection popup
       
   739 		else if ( dlErrorId == EConnectionFailed && sysErrorId == KErrCancel)
       
   740 			{
       
   741 			FLOG(_L("Reason: User canceled IAP selection popup"));
       
   742 			iDLState.iResult = RFotaEngineSession::EResUserCancelled;
       
   743 			iRestartCounter = -1;
       
   744 
       
   745 			notifType = ESyncMLFwUpdOmaDLPostponed;
       
   746 			notifParam = KErrNone;
       
   747 			}
       
   748 		//Handling temproary network timeout. This may either try resume or restart based on download.
       
   749 /*		else if ( dlErrorId == EGeneral && sysErrorId == KErrTimedOut )
       
   750 			{
       
   751 			FLOG(_L("Reason: Network timeout"));
       
   752 			// No restart issued yet, this is 1st download attempt
       
   753 			if ( iRestartCounter == 0 )
       
   754 				{
       
   755 				iRestartCounter = KFotaDownloadTimeoutRestartCount;
       
   756 				iDLState.iState     = RFotaEngineSession::EIdle;
       
   757 				FLOG(_L("Trying to restart download (iRestartCounter=%d)"),iRestartCounter );
       
   758 				}
       
   759 			
       
   760 			}*/
       
   761 		//Handling all Network interrupts
       
   762 		else if ( (dlErrorId == EConnectionFailed && sysErrorId == KErrCommsLineFail)|| 
       
   763 				  dlErrorId == ETransactionFailed || 
       
   764 				  (dlErrorId == KErrCodWapConnectionDropped && sysErrorId == KErrGeneral) ||
       
   765 				  (dlErrorId == EGeneral && sysErrorId == KErrTimedOut) ||
       
   766 				  (dlErrorId == EConnectionFailed && sysErrorId == KErrGprsServicesNotAllowed ) ||
       
   767 				  (dlErrorId == EConnectionFailed && sysErrorId == KErrGsmMMNetworkFailure ) ||
       
   768 				  (dlErrorId == EConnectionFailed && sysErrorId == KErrWlanNetworkNotFound )
       
   769 				  )
       
   770 			{
       
   771 			FLOG(_L("Reason: Network breakage"));
       
   772 			iRestartCounter = -1;
       
   773 			notifType = ESyncMLFwUpdErrorNote;
       
   774 			if (iDownloadResumable)
       
   775 				{
       
   776 				notifParam = KErrCommsLineFail2;
       
   777 				iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume;
       
   778 				iDLState.iResult = RFotaEngineSession::EResDLFailDueToNWIssues;
       
   779 				}
       
   780 			else
       
   781 				{
       
   782 				notifParam = KErrCommsLineFail;
       
   783 				iDLState.iState = RFotaEngineSession::EDownloadFailed;
       
   784 				iDLState.iResult = RFotaEngineSession::EResDLFailDueToNWIssues;
       
   785 				}
       
   786 			}
       
   787 		//Handling Out Of Memory interrupt
       
   788 		else if ((dlErrorId == EGeneral && sysErrorId == KErrDiskFull ) || sysErrorId == KErrCodInsufficientSpace)
       
   789 			{
       
   790 			FLOG(_L("Reason: Disk full"));
       
   791 			iRestartCounter = -1;
       
   792 			notifType = KErrNotFound;
       
   793 			notifParam = KErrNotFound; // don't show anything
       
   794 			iDLState.iResult = RFotaEngineSession::EResDLFailDueToDeviceOOM;
       
   795 			}
       
   796 		//Handle unclassified (general) interrupts
       
   797 		else
       
   798 			{
       
   799 			iRestartCounter = -1;
       
   800 
       
   801 			
       
   802 			RProperty prop;
       
   803 			TInt val = KErrNone;
       
   804 		
       
   805 			TInt err = prop.Get(KPSUidStartup, KPSGlobalSystemState, val);
       
   806 			if (err==KErrNone && val!=ESwStateShuttingDown)
       
   807 				{
       
   808 				notifType = ESyncMLFwUpdErrorNote;				
       
   809 				}
       
   810 			else
       
   811 				{
       
   812 				FLOG(_L("Phone is powering down..."));
       
   813 				}
       
   814 
       
   815 			if (iDownloadResumable)
       
   816 				{
       
   817 				notifParam = KErrGeneralResume;
       
   818 				iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume;
       
   819 				}
       
   820 			else
       
   821 				{
       
   822 				notifParam = KErrGeneralNoResume;
       
   823 				iDLState.iState = RFotaEngineSession::EDownloadFailed;
       
   824 				}
       
   825 
       
   826 
       
   827         SetDLResultdlErrorId(dlErrorId ,sysErrorId  );
       
   828 			
       
   829 
       
   830 			}
       
   831 		if ( iRestartCounter <= 0)
       
   832 			{
       
   833 			iUpdateAfterDownload = EFalse;
       
   834 			SetDownloadActive(EFalse);
       
   835 			if ( iDLState.iSessionType!= ESanSilent && notifType!=KErrNotFound )
       
   836 				{
       
   837 				if ( iShowDLPrgUI )
       
   838 					LaunchNotifierL( (TSyncMLFwUpdNoteTypes)notifType, notifParam,0 );
       
   839 				else
       
   840 					LaunchNotifierL( (TSyncMLFwUpdNoteTypes)notifType, notifParam,0, ETrue);
       
   841 				}
       
   842 			FLOG(_L("Should  come here for nonpausable "));	
       
   843 			iDownloadFinalized = ETrue;
       
   844 			iFotaServer->FinalizeDownloadL( iDLState );
       
   845 			}
       
   846 		else
       
   847 			{
       
   848 			if (iDownloadResumable)
       
   849 				{
       
   850 				FLOG(_L("Resuming download..."));
       
   851 				iDownload->Start();
       
   852 				}
       
   853 			else
       
   854 				{
       
   855 				FLOG(_L("Restarting download..."));
       
   856 				iFotaServer->FinalizeDownloadL( iDLState );
       
   857 				}
       
   858 			}
       
   859 		}
       
   860 		break;
       
   861 
       
   862 	case EHttpDlPausable:
       
   863 		{
       
   864 		FLOG(_L("Download State: EHttpDlPausable"));
       
   865 		if (iDownloadResumable) //This is initially set by IsDownloadSuspendResumeSupported()
       
   866 			{
       
   867 			FLOG(_L("Download Suspend/Resume is supported!"));       				
       
   868 			}
       
   869 		else
       
   870 			{
       
   871 			FLOG(_L("Download Server support Suspend/Resume, but Fota doesn't!"));
       
   872 			//retain the state iDownloadResumable = EOmaDLResumeNotSupported;
       
   873 			}
       
   874 		}
       
   875 		break;
       
   876 
       
   877 	case EHttpDlNonPausable:
       
   878 		{
       
   879 		FLOG(_L("Download State: EHttpDlNonPausable"));
       
   880 		if (iDownloadResumable) //This is initially set by CheckDownloadVariations()
       
   881 			{
       
   882 			FLOG(_L("Download Server doesn't support Suspend/Resume, but Fota does!"));
       
   883 			//Reset the state to not supported.
       
   884 			iDownloadResumable = EFalse;
       
   885 			}
       
   886 		else
       
   887 			{
       
   888 			FLOG(_L("Download Server doesn't support Suspend/Resume, neither does Fota!"));
       
   889 			}
       
   890 		}
       
   891 		break;
       
   892 	case EHttpDlDeleting:	//13
       
   893 		{
       
   894 		FLOG(_L("Download State: EHttpDlDeleting"));
       
   895 		}
       
   896 		break;
       
   897 	case EHttpDlDeleted:	//11
       
   898 		{
       
   899 		FLOG(_L("Download State: EHttpDlDeleted"));
       
   900 		}
       
   901 		break;
       
   902 	default:
       
   903 		{
       
   904 		FLOG(_L("Default. No action performed for this Download State"));
       
   905 		}
       
   906 		break;
       
   907 	}
       
   908 	FLOG(_L("CFotaDownload::HandleDMgrEventL()  <<"));
       
   909 	}
       
   910 
       
   911 
       
   912 
       
   913 // --------------------------------------------------------------------------
       
   914 // CFotaDownload::SetDLResultdlErrorId
       
   915 // Sets the appropriate error
       
   916 // --------------------------------------------------------------------------
       
   917 //
       
   918 
       
   919 void CFotaDownload::SetDLResultdlErrorId( THttpDownloadMgrError adlErrorId, TInt32 asysErrorId)
       
   920 {
       
   921       if ( adlErrorId == EInternal)
       
   922 				{
       
   923 				FLOG(_L("Reason:   error EInternal"));
       
   924 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   925 				}
       
   926 			else if ( adlErrorId == EContentFileIntegrity)
       
   927 				{
       
   928 				FLOG(_L("Reason:   error EContentFileIntegrity"));
       
   929 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   930 				}
       
   931 			else if ( adlErrorId == EMMCRemoved)
       
   932 				{
       
   933 				FLOG(_L("Reason:   error EMMCRemoved,"));
       
   934 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   935 				}
       
   936 			else if ( adlErrorId == EBadUrl) 
       
   937 				{
       
   938 				FLOG(_L("Reason:   error EBadUrl"));
       
   939 				iDLState.iResult = RFotaEngineSession::EResMalformedOrBadURL;
       
   940 				}
       
   941 			else if ( adlErrorId == EHttpUnhandled)
       
   942 				{
       
   943 				FLOG(_L("Reason:   error EHttpUnhandled, check global error id!"));
       
   944 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   945 				}
       
   946 			else if ( adlErrorId == EHttpAuthenticationFailed)
       
   947 				{
       
   948 				FLOG(_L("Reason:   error EHttpAuthenticationFailed"));
       
   949 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   950 				}
       
   951 			else if ( adlErrorId == EObjectNotFound)
       
   952 				{
       
   953 				FLOG(_L("Reason:   error EObjectNotFound"));
       
   954 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   955 				}
       
   956 			else if ( adlErrorId == EPartialContentModified)
       
   957 				{
       
   958 				FLOG(_L("Reason:   error EPartialContentModified"));
       
   959 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   960 				}
       
   961 			else if ( adlErrorId == EContentExpired)
       
   962 				{
       
   963 				FLOG(_L("Reason:   error EContentExpired"));
       
   964 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   965 				}
       
   966 			else if ( adlErrorId == EHttpRestartFailed)
       
   967 				{
       
   968 				FLOG(_L("Reason:   error EHttpRestartFailed"));
       
   969 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   970 				}
       
   971 			else if ( asysErrorId == KErrCodInvalidDescriptor )
       
   972 				{
       
   973 				FLOG(_L("Reason:   error KErrCodInvalidDescriptor"));
       
   974 				iDLState.iResult  = RFotaEngineSession::EResMalformedOrBadURL;
       
   975 				}
       
   976 			else
       
   977 				{
       
   978 				FLOG(_L("Reason: unknown, check dlError!"));
       
   979 				iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
   980 				}
       
   981 
       
   982 }
       
   983 
       
   984 // --------------------------------------------------------------------------
       
   985 // CFotaDownload::HandleDMgrEventL
       
   986 // --------------------------------------------------------------------------
       
   987 //
       
   988 void CFotaDownload::HandleDMgrEventL( RHttpDownload& aDownload
       
   989 		, THttpDownloadEvent aEvent )
       
   990 	{   
       
   991 	DoHandleDMgrEventL(&aDownload,aEvent);
       
   992 	}
       
   993 
       
   994 
       
   995 // --------------------------------------------------------------------------
       
   996 // CFotaDownload::LaunchNotifierL
       
   997 // Launches notifier. This method is also used to finalize erronous DL
       
   998 // --------------------------------------------------------------------------
       
   999 //
       
  1000 void CFotaDownload::LaunchNotifierL( const TSyncMLFwUpdNoteTypes aNotetype
       
  1001 		,const TInt aIntParam
       
  1002 		,const TInt aMemoryNeeded
       
  1003 		,TBool aFinishOnly )
       
  1004 	{
       
  1005 	if ( iNotifHandler ) iNotifHandler->Cancel();
       
  1006 	else				 iNotifHandler = CFotaDownloadNotifHandler::NewL(this);
       
  1007 	iNotifHandler->LaunchNotifierL( aNotetype,aIntParam,aMemoryNeeded
       
  1008 			,aFinishOnly );
       
  1009 	}
       
  1010 
       
  1011 // --------------------------------------------------------------------------
       
  1012 // CFotaDownload::CheckDownloadVariations
       
  1013 // Reads download variations - fota suspend & resume bahavior & FMS from cenrep keys
       
  1014 // --------------------------------------------------------------------------
       
  1015 //
       
  1016 void CFotaDownload::CheckDownloadVariations()
       
  1017 	{
       
  1018 	FLOG(_L("CFotaDownload::CheckDownloadVariations >>"));
       
  1019 
       
  1020 	CRepository* centrep( NULL);
       
  1021 	TRAPD(err, centrep = CRepository::NewL( KCRUidFotaServer ) );
       
  1022 	if (err) FLOG(_L("Error reading FotaServer cenrep... %d"),err);
       
  1023 	TInt supported(KErrNone);
       
  1024 	if (centrep ) 
       
  1025 		{
       
  1026 		err = centrep->Get( KSuspendResumeFeatureSupported, supported );
       
  1027 		if (err) FLOG(_L("Error reading cenrep key... %d"),err);
       
  1028 		iDownloadResumable = (supported==1)? ETrue:EFalse;
       
  1029 
       
  1030 		supported = KErrNone;
       
  1031 		centrep->Get( KFotaMonitoryServiceEnabled, supported );
       
  1032 		if (err) FLOG(_L("Error reading cenrep key... %d"),err);
       
  1033 		iFMSEnabled = (supported > 0)? ETrue:EFalse;
       
  1034 
       
  1035 		delete centrep;
       
  1036 		centrep = NULL;
       
  1037 		}
       
  1038 
       
  1039 	FLOG(_L("Susp&Resume feature supported = %d, FMS feature supported = %d"),iDownloadResumable,iFMSEnabled);
       
  1040 	FLOG(_L("CFotaDownload::CheckDownloadVariations <<"));
       
  1041 	}
       
  1042 
       
  1043 // --------------------------------------------------------------------------
       
  1044 // CFotaDownload::RunDownloadCancelL
       
  1045 // Starts to cancel the download operation
       
  1046 // --------------------------------------------------------------------------
       
  1047 //
       
  1048 void CFotaDownload::RunDownloadCancelL(const TInt aReason, TBool aSilent)
       
  1049 	{
       
  1050 	FLOG(_L("CFotaDownload::RunDownloadCancelL, reason = %d, silent = %d >>"), aReason, aSilent);
       
  1051 
       
  1052 	iDLState.iState     = RFotaEngineSession::EDownloadFailed;
       
  1053 	iDLState.iResult    = aReason;
       
  1054 	iSilentOpn = aSilent;
       
  1055 	
       
  1056 	iRestartCounter = -1;
       
  1057 	iUpdateAfterDownload = EFalse;
       
  1058 	
       
  1059 	if (!iDownload)
       
  1060 		{
       
  1061 		//iDownload is null when user cancels the download permanently when prompted to resume.
       
  1062 		//hence retrieve the download object first 
       
  1063 		iDownload = RetrieveDownloadL();
       
  1064 		}
       
  1065 	TInt err = iDownload->Delete(); //or Cancel or Reset?
       
  1066 	FLOG(_L("Error = %d"),err);
       
  1067 	
       
  1068 	if(iDownloadFinalized == EFalse)
       
  1069 	{
       
  1070 	iFotaServer->FinalizeDownloadL( iDLState );
       
  1071 	FLOG(_L("Should not come here fro nopausable "));
       
  1072 	if (aReason == RFotaEngineSession::EResUserCancelled)
       
  1073 		LaunchNotifierL(ESyncMLFwUpdOmaDLCancelled, EFalse, EFalse);
       
  1074 	else if (aReason == RFotaEngineSession::EResUndefinedError)
       
  1075 		LaunchNotifierL(ESyncMLFwUpdErrorNote, KErrGeneralNoResume, EFalse );
       
  1076   }
       
  1077 	FLOG(_L("CFotaDownload::RunDownloadCancelL <<"));
       
  1078 	}
       
  1079 
       
  1080 // --------------------------------------------------------------------------
       
  1081 // CFotaDownload::RunDownloadSuspendL
       
  1082 // Starts to suspend the download operation
       
  1083 // --------------------------------------------------------------------------
       
  1084 //
       
  1085 void CFotaDownload::RunDownloadSuspendL(const TInt aReason, TBool aSilent)
       
  1086 	{
       
  1087 	FLOG(_L("CFotaDownload::RunDownloadSuspendL, reason = %d, silent = %d >>"), aReason, aSilent);
       
  1088 
       
  1089 	iDLState.iState     = RFotaEngineSession::EDownloadProgressingWithResume;
       
  1090 	iDLState.iResult    = aReason;
       
  1091 	iSilentOpn = aSilent;
       
  1092 	//First pause download, and later ask for user action.
       
  1093 	TInt err = iDownload->Pause();
       
  1094 
       
  1095 	if (err)
       
  1096 	{
       
  1097 	//initial pausing becomes a problem.
       
  1098 	FLOG(_L("Error while initial pausing...%d Hence download has to be cancelled permanently!"),err);
       
  1099 	RunDownloadCancelL(aReason);
       
  1100 	}
       
  1101 
       
  1102 	FLOG(_L("CFotaDownload::RunDownloadSuspendL <<"));
       
  1103 	}
       
  1104 
       
  1105 // --------------------------------------------------------------------------
       
  1106 // CFotaDownload::TryResumeDownloadL
       
  1107 // Tries to resume the download operation
       
  1108 // --------------------------------------------------------------------------
       
  1109 //
       
  1110 void CFotaDownload::TryResumeDownloadL(TBool aUserInitiated)
       
  1111 	{
       
  1112 	FLOG(_L("CFotaDownload::TryResumeDownloadL >>"));
       
  1113 
       
  1114 	iUserInitiatedResume = aUserInitiated;
       
  1115 	TInt err = RProperty::Define( TUid::Uid(KOmaDMAppUid),
       
  1116 			KFotaDMRefresh,
       
  1117 			RProperty::EInt,KReadPolicy,KWritePolicy);
       
  1118 	FLOG(_L("RProperty KFotaDMRefresh Define, err = %d"), err);        
       
  1119 	if (err != KErrAlreadyExists )
       
  1120 		{
       
  1121 		User::LeaveIfError(err);
       
  1122 		}
       
  1123 	//This P&S Key is used to notify DM UI on any download event. key=0 for idle and key=1 for download
       
  1124 	err = RProperty::Set( TUid::Uid(KOmaDMAppUid),
       
  1125 			KFotaDMRefresh,
       
  1126 			ETrue );
       
  1127 	FLOG(_L("RProperty KFotaDMRefresh Set ETrue, err = %d"), err);    
       
  1128 
       
  1129 	//Called to read the download variations in Fota (resume support & FMS)
       
  1130 	CheckDownloadVariations();	
       
  1131 	if (IsFMSEnabled() && iUserInitiatedResume)
       
  1132 		iFotaServer->CancelFmsL();
       
  1133 
       
  1134 	//Query based on the type of DM session used earlier.
       
  1135 	if (iUserInitiatedResume || iDLState.iSessionType != ESanSilent)
       
  1136 		{
       
  1137 		//Query user for resume
       
  1138 		FLOG(_L("Quering user for resume..."));
       
  1139 		if (iFotaServer->iNotifHandler)
       
  1140 			{
       
  1141 			iFotaServer->iNotifHandler->Cancel();
       
  1142 			delete iFotaServer->iNotifHandler;
       
  1143 			iFotaServer->iNotifHandler = NULL;
       
  1144 			}
       
  1145 		iNotifHandler = CFotaDownloadNotifHandler::NewL(this);
       
  1146 
       
  1147 		iNotifHandler->LaunchNotifierL(ESyncMLFwUpdOmaDLResume, EFalse, EFalse);
       
  1148 		}
       
  1149 	else //Only FMS initiated Silent Session download
       
  1150 		{
       
  1151 		//Resume directly
       
  1152 		FLOG(_L("Resuming automatically..."));
       
  1153 		ResumeDownloadL();
       
  1154 		}
       
  1155 	FLOG(_L("CFotaDownload::TryResumeDownloadL <<"));
       
  1156 	}
       
  1157 
       
  1158 // --------------------------------------------------------------------------
       
  1159 // CFotaDownload::ResumeDownloadL
       
  1160 // Resume the download operation
       
  1161 // --------------------------------------------------------------------------
       
  1162 //
       
  1163 void CFotaDownload::ResumeDownloadL()
       
  1164 	{
       
  1165 	FLOG(_L("CFotaDownload::ResumeDownloadL >>"));
       
  1166 	TBool toresetdl (EFalse);
       
  1167 	TBool downloadiapvalid (ETrue);
       
  1168 	//Find the download ui behavior from fota cenrep
       
  1169 	TInt behavior(KErrNotFound);
       
  1170 	CRepository* centrep = NULL;
       
  1171 	TRAPD(err, centrep = CRepository::NewL( KCRUidFotaServer ) );
       
  1172 	if (( centrep ) && ( err == KErrNone))
       
  1173 	    {
       
  1174 	    centrep->Get( KSilentOmaDlUIBehavior, behavior );
       
  1175 	    delete centrep;
       
  1176 	    }
       
  1177 	centrep = NULL;
       
  1178 
       
  1179 	if (iUserInitiatedResume || 
       
  1180 	        (behavior == EOmacdOffdlprgOn || behavior == EOmacdOndlprgOn))
       
  1181 		{
       
  1182 		FLOG(_L("Showing Connecting progress note..."));
       
  1183 		iFotaServer->iParentApp->SetUIVisibleL ( ETrue , EFalse );
       
  1184 		
       
  1185 		if ( !iDLProgressDlg )
       
  1186 			{
       
  1187 			iDLProgressDlg = new(ELeave) CFotaDLProgressDlg((CEikDialog** ) &iDLProgressDlg , EFalse, this, EConnectingNote );
       
  1188 			iDLProgressDlg->PrepareLC( R_CONNECTION_NOTE );
       
  1189 			}
       
  1190 		// Load the resource files
       
  1191 	    TInt err = KErrNone;
       
  1192 	       
       
  1193 	    // Localize the file name, and load the SCP resources
       
  1194 	    TFileName resFile;
       
  1195 	    resFile.Copy( KDriveZ );
       
  1196 	    resFile.Append( KSCPResourceFilename );
       
  1197     	    
       
  1198 	    BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resFile );    
       
  1199 
       
  1200 	    TInt Res1(KErrNone);
       
  1201 	    TRAP( err, Res1 =CCoeEnv::Static()->AddResourceFileL( resFile ) );        
       
  1202 
       
  1203 	    HBufC* buf = StringLoader::LoadLC(R_SYNCSTATUS_SYNC_CONN);
       
  1204 	
       
  1205 	    if( Res1 )
       
  1206 	    	{
       
  1207 	        iFotaServer->GetEikEnv()->DeleteResourceFile( Res1 );
       
  1208 	    	}
       
  1209 	    FLOG(_L("Reading txt as: %S"), &buf->Des());
       
  1210 		iDLProgressDlg->SetTextL(buf->Des());
       
  1211 		CleanupStack::PopAndDestroy(buf);
       
  1212 	
       
  1213 		iDLProgressDlg->RunLD();
       
  1214 		}
       
  1215 	FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 1"));
       
  1216 	
       
  1217 	iDownload = RetrieveDownloadL();
       
  1218 	if (iDownload)
       
  1219 		{
       
  1220 		FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 2: Successfully retrieved download object >>"));
       
  1221 
       
  1222 		SetIapToUseL(iDLState, iDLState.iIapId);
       
  1223 
       
  1224 		FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 3: Using iapid %d for resume..."), iDLState.iIapId);
       
  1225 		downloadiapvalid = iFotaServer->CheckIapExistsL(iDLState.iIapId);
       
  1226 		if (iDLState.iIapId > 0 && downloadiapvalid)
       
  1227 			{
       
  1228 			if (!iMonitor)
       
  1229 				{
       
  1230 				iMonitor = CFotaNetworkRegStatus::NewL (iFotaServer);
       
  1231 				}
       
  1232 			TBool val = iMonitor->IsConnectionPossibleL(iDLState.iIapId);
       
  1233 			FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 4"));
       
  1234 			delete iMonitor; iMonitor = NULL;
       
  1235 			
       
  1236 #if defined(__WINS__)
       
  1237 			val =ETrue;
       
  1238 #endif
       
  1239 			if (!val)
       
  1240 				{
       
  1241 				FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 5.1: Disallowing resume operation as connection not possible"));
       
  1242 				
       
  1243 				if ( !iShowDLPrgUI && iDLProgressDlg )
       
  1244 					{
       
  1245 					FLOG(_L("Removing Connecting progress note..."));
       
  1246 
       
  1247 					iDLProgressDlg->ProcessFinishedL();
       
  1248 					delete iDLProgressDlg;
       
  1249 					iDLProgressDlg = NULL;
       
  1250 					}
       
  1251 				if (iUserInitiatedResume || iDLState.iSessionType!=ESanSilent)
       
  1252 					LaunchNotifierL(ESyncMLFwUpdErrorNote, KErrCommsLineFail2,0);
       
  1253 				iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume;
       
  1254 				iDLState.iResult = RFotaEngineSession::EResDLFailDueToNWIssues;
       
  1255 				iUpdateAfterDownload = EFalse;
       
  1256 				iFotaServer->FinalizeDownloadL(iDLState);
       
  1257 				return;
       
  1258 				}
       
  1259 			}
       
  1260 
       
  1261 		if (iDLState.iIapId == KErrNotFound || !downloadiapvalid )
       
  1262 		    {
       
  1263 		    iDLState.iIapId = KErrNotFound;
       
  1264 			User::LeaveIfError( iDownloadMgr.SetIntAttribute( EDlMgrIap, 0)); // Download mgr interprets 0 for Always Ask
       
  1265 		    }
       
  1266 		else
       
  1267 			User::LeaveIfError( iDownloadMgr.SetIntAttribute( EDlMgrIap, iDLState.iIapId)); // IAP id
       
  1268 
       
  1269 		FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 5.2"));
       
  1270 		SetDownloadUiBehavior(EFalse);		
       
  1271 
       
  1272 		if ( !iShowDLPrgUI && iDLProgressDlg )
       
  1273 			{
       
  1274 			FLOG(_L("Removing Connecting progress note..."));
       
  1275 
       
  1276 			iDLProgressDlg->ProcessFinishedL();
       
  1277 			delete iDLProgressDlg;
       
  1278 			iDLProgressDlg = NULL;
       
  1279 			}
       
  1280 		TInt dlsize, tlsize;
       
  1281 		FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 6"));
       
  1282 		iFotaServer->GetDownloadUpdatePackageSizeL(iDLState.iPkgId, dlsize,tlsize);
       
  1283 		iDownloadedContentSize = dlsize; //for progress bar update only
       
  1284 		iUpdateAfterDownload = iDLState.iUpdateLtr; //should update after reboot?
       
  1285 		iRestartCounter = 0;
       
  1286 		
       
  1287 		//Set right states in fota db
       
  1288 		iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume;
       
  1289 		iDLState.iResult = KErrNotFound;
       
  1290 		
       
  1291 		iFotaServer->iDatabase->OpenDBL();
       
  1292 		iFotaServer->iDatabase->SetStateL( iDLState, KNullDesC8, EFDBState|EFDBResult);
       
  1293 		iFotaServer->iDatabase->CloseAndCommitDB();
       
  1294 		iFreshDL = EFalse;
       
  1295 		FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 6: Starting to resume download now..."));
       
  1296 		TInt err = iDownload->Start();
       
  1297 		if (err == KErrNone)
       
  1298 			{
       
  1299 			//Set the P&S Key to active...
       
  1300 			FLOG(_L("Resume operation is success!"));
       
  1301 			SetDownloadActive(ETrue);
       
  1302 			}
       
  1303 		else
       
  1304 			{
       
  1305 			FLOG(_L("An error occured during resume, err = %d"),err);
       
  1306 			toresetdl = ETrue;
       
  1307 			}
       
  1308 		}
       
  1309 	else
       
  1310 		{
       
  1311 		FLOG(_L("Failed to get the paused download object"));
       
  1312 		if ( iDLProgressDlg )
       
  1313 			{
       
  1314 			FLOG(_L("Removing Connecting progress note..."));
       
  1315 			iDLProgressDlg->ProcessFinishedL(); // deletes itself
       
  1316 			delete iDLProgressDlg;
       
  1317 			iDLProgressDlg = NULL;
       
  1318 			}
       
  1319 		toresetdl = ETrue;
       
  1320 		}
       
  1321       ReSetDownloadL(	toresetdl);
       
  1322 	
       
  1323 	FLOG(_L("CFotaDownload::ResumeDownloadL <<"));
       
  1324 	}
       
  1325 // --------------------------------------------------------------------------
       
  1326 // CFotaDownload::ReSetDownloadL
       
  1327 // Sets the download state to failed
       
  1328 // --------------------------------------------------------------------------
       
  1329 //
       
  1330 void CFotaDownload::ReSetDownloadL(TBool atoresetdl)
       
  1331 {
       
  1332 if (atoresetdl)
       
  1333 		{
       
  1334 		FLOG(_L("Resetting fota download !!!"));
       
  1335 		if (iUserInitiatedResume || iDLState.iSessionType!=ESanSilent)
       
  1336 			LaunchNotifierL(ESyncMLFwUpdErrorNote, KErrGeneralNoResume,0);
       
  1337 		iDLState.iState = RFotaEngineSession::EDownloadFailed;
       
  1338 		iDLState.iResult = RFotaEngineSession::EResUndefinedError;
       
  1339 		iUpdateAfterDownload = EFalse;
       
  1340 		iFotaServer->FinalizeDownloadL(iDLState);
       
  1341 		}
       
  1342 }
       
  1343 
       
  1344 
       
  1345 
       
  1346 // --------------------------------------------------------------------------
       
  1347 // CFotaDownload::IsFMSEnabled
       
  1348 // Returns FMS enabled state
       
  1349 // --------------------------------------------------------------------------
       
  1350 //
       
  1351 TBool CFotaDownload::IsFMSEnabled()
       
  1352 	{
       
  1353 	FLOG(_L("CFotaDownload::IsFMSEnabled, iFMSEnabled = %d <<"), iFMSEnabled);
       
  1354 	return iFMSEnabled;
       
  1355 	}
       
  1356 
       
  1357 // --------------------------------------------------------------------------
       
  1358 // CFotaDownload::IsDownloadResumable
       
  1359 // Returns whether the download is resumable or not.
       
  1360 // --------------------------------------------------------------------------
       
  1361 //
       
  1362 TBool CFotaDownload::IsDownloadResumable()
       
  1363 	{
       
  1364 	FLOG(_L("CFotaDownload::IsDownloadResumable, iDownloadResumable = %d <<"), iDownloadResumable);
       
  1365 	return iDownloadResumable;
       
  1366 	}
       
  1367 
       
  1368 // --------------------------------------------------------------------------
       
  1369 // CFotaDownload::SetIapToUseL
       
  1370 // Sets the IAP ID to use. This menthod is used in fresh and resume download.
       
  1371 // --------------------------------------------------------------------------
       
  1372 //
       
  1373 void CFotaDownload::SetIapToUseL(TPackageState aParams, const TInt aIapid)
       
  1374 	{
       
  1375 	FLOG(_L("CFotaDownload::SetIapToUseL >>"));
       
  1376 
       
  1377 	RSyncMLSession sml;
       
  1378 	TInt profIapid( KErrNotFound );
       
  1379 	TInt sockIapid( KErrNotFound );
       
  1380 	TSmlServerAlertedAction saa(ESmlConfirmSync);
       
  1381 
       
  1382 	CleanupClosePushL( sml );
       
  1383 	sml.OpenL();
       
  1384 	iFotaServer->GetProfileDataL(&sml,aParams.iProfileId, profIapid, saa
       
  1385 			,iIsjobStartedFromUI, iSanValue );
       
  1386 	CleanupStack::PopAndDestroy( &sml );
       
  1387 
       
  1388 	// 2/3 GET IAP FROM ESOCK ----------------------------------------------
       
  1389 	// resolve which accespoint is used for current DM session
       
  1390 	if ( profIapid == KErrNotFound && aIapid==KErrNotFound)
       
  1391 		{
       
  1392 		RSocketServ serv;
       
  1393 		CleanupClosePushL( serv );
       
  1394 		User::LeaveIfError( serv.Connect() );
       
  1395 
       
  1396 		RConnection conn;
       
  1397 		CleanupClosePushL( conn );
       
  1398 		User::LeaveIfError( conn.Open( serv ) );
       
  1399 
       
  1400 		TUint count( 0 );
       
  1401 		User::LeaveIfError( conn.EnumerateConnections ( count ) );
       
  1402 		// enumerate connections
       
  1403 		for( TUint idx=1; idx<=count; ++idx )
       
  1404 			{
       
  1405 			TConnectionInfo connectionInfo;
       
  1406 			TConnectionInfoBuf connInfo( connectionInfo );
       
  1407 
       
  1408 			TInt err = conn.GetConnectionInfo( idx, connInfo ); // iapid
       
  1409 			if( err != KErrNone )
       
  1410 				{
       
  1411 				CleanupStack::PopAndDestroy( 2 ); // conn, serv
       
  1412 				User::Leave( err );
       
  1413 				}
       
  1414 			// enumerate connectionclients
       
  1415 			TConnectionEnumArg	conArg;
       
  1416 			conArg.iIndex = idx;
       
  1417 			TConnEnumArgBuf conArgBuf(conArg);
       
  1418 			err=conn.Control(KCOLConnection,KCoEnumerateConnectionClients
       
  1419 					,conArgBuf);
       
  1420 			if( err != KErrNone )
       
  1421 				{
       
  1422 				CleanupStack::PopAndDestroy( 2 ); // conn, serv
       
  1423 				User::Leave( err );
       
  1424 				}
       
  1425 			TInt cliCount = conArgBuf().iCount;
       
  1426 			for ( TUint j=1; j<=cliCount ;++j )
       
  1427 				{
       
  1428 				TConnectionGetClientInfoArg conCliInfo;
       
  1429 				conCliInfo.iIndex = j;
       
  1430 				TConnGetClientInfoArgBuf conCliInfoBuf(conCliInfo);
       
  1431 				err=conn.Control(KCOLConnection, KCoGetConnectionClientInfo
       
  1432 						, conCliInfoBuf);
       
  1433 
       
  1434 				if( err != KErrNone )
       
  1435 					{
       
  1436 					CleanupStack::PopAndDestroy( 2 ); // conn, serv
       
  1437 					User::Leave( err );
       
  1438 					}				
       
  1439 				TConnectionClientInfo conCliInf = conCliInfoBuf().iClientInfo;
       
  1440 				TUid uid = conCliInf.iUid;
       
  1441 				if ( uid == TUid::Uid(KSosServerUid) )
       
  1442 					{
       
  1443 					sockIapid = connInfo().iIapId;
       
  1444 					FLOG(_L("[FotaServer]  IAP found %x"),sockIapid);
       
  1445 					}
       
  1446 
       
  1447 				FLOG(_L("[FotaServer]  CFotaDownload::DownloadL uid %x")
       
  1448 						,uid.iUid);
       
  1449 				}
       
  1450 			}
       
  1451 		CleanupStack::PopAndDestroy( 2 ); // conn, serv		
       
  1452 		}
       
  1453 	TInt newIapid( KErrNotFound );
       
  1454 	if ( sockIapid!=KErrNotFound ) newIapid = sockIapid;
       
  1455 	if ( profIapid!=KErrNotFound ) newIapid = profIapid;
       
  1456 	if ( aIapid   !=KErrNotFound ) newIapid = aIapid;
       
  1457 
       
  1458 	//Do some intelligent work during resume
       
  1459 	/* Some rules..
       
  1460 	 * 1. If IAP is always ask in DM profile, use the earlier set during FMS trigger
       
  1461 	 * 2. If IAP is always ask in DM profile, query user for IAP during user trigger
       
  1462 	 * 3. If IAP has changed in DM profile after suspend, use the newer one during resume
       
  1463 	 * 4. 
       
  1464 	 */
       
  1465 	TInt active (KErrNotFound);
       
  1466 	RProperty::Get( TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, active );
       
  1467 	FLOG(_L("active = %d"),active);
       
  1468 	if (active==EFalse && iDLState.iState == RFotaEngineSession::EDownloadProgressingWithResume)
       
  1469 		{
       
  1470 		//Actual resume only
       
  1471 		if (!iUserInitiatedResume && profIapid == KErrNotFound  )
       
  1472 			{
       
  1473 			//FMS triggered resume, apply Rule 1
       
  1474 			newIapid = iDLState.iIapId;
       
  1475 			}
       
  1476 		else if (profIapid == KErrNotFound)
       
  1477 			{
       
  1478 			//User triggered resume, apply Rule 2
       
  1479 			newIapid = KErrNotFound;
       
  1480 			}
       
  1481 		else if (profIapid != iDLState.iIapId)
       
  1482 			{
       
  1483 			//IAP has changed in DM profile, apply Rule 3
       
  1484 			newIapid = profIapid;
       
  1485 			}
       
  1486 		}
       
  1487 	iDLState.iIapId = newIapid;
       
  1488 
       
  1489 
       
  1490 	FLOG(_L("CFotaDownload::SetIapToUseL, iap = %d <<"), iDLState.iIapId);
       
  1491 	}
       
  1492 
       
  1493 // --------------------------------------------------------------------------
       
  1494 // CFotaDownload::SetDownloadUiBehavior
       
  1495 // Sets Download UI behavior. ex: DD display and Progress note
       
  1496 // --------------------------------------------------------------------------
       
  1497 //
       
  1498 void CFotaDownload::SetDownloadUiBehavior(TBool aFreshDL)
       
  1499 	{
       
  1500 	FLOG(_L("CFotaDownload::SetDownloadUiBehavior, aFreshDL = %d >>"),aFreshDL);
       
  1501 
       
  1502 	if (aFreshDL) //Fresh download
       
  1503 		{
       
  1504 		iDLState.iSessionType = iSanValue;
       
  1505 		}
       
  1506 	else //resuming download
       
  1507 		{
       
  1508 		iSanValue = iDLState.iSessionType;
       
  1509 		}
       
  1510 
       
  1511 	if ( !iIsjobStartedFromUI &&  iRestartCounter==0 ) //iRestartCounter to ensure that the UI behavior is read only once.
       
  1512 		{
       
  1513 		TInt behavior(KErrNotFound);
       
  1514 		TInt sansupported(KErrNone);
       
  1515 
       
  1516 		//Find whether SAN is supported or not
       
  1517 	    CRepository* centrep = NULL;
       
  1518 
       
  1519 	    TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys) );    
       
  1520 	    if( centrep ) centrep->Get( KDevManSANUIBitVariation, sansupported );
       
  1521 	    delete centrep; centrep = NULL;
       
  1522 	    FLOG(_L("...1..."));
       
  1523 	    if (sansupported != 1) sansupported = 0;
       
  1524 	    
       
  1525 		//Find the download ui behavior from fota cenrep
       
  1526 		TRAP(err, centrep = CRepository::NewL( KCRUidFotaServer ) );
       
  1527 		if ( centrep ) 	centrep->Get( KSilentOmaDlUIBehavior, behavior );
       
  1528 		delete centrep; centrep = NULL;
       
  1529 
       
  1530 		FLOG(_L("Values are... SAN enabled: %d, session type: %d, downloadbehavior: %d"),sansupported, iDLState.iSessionType,behavior);
       
  1531 
       
  1532 		if (sansupported) //SAN is supported
       
  1533 			{
       
  1534 				
       
  1535 			DetermineUISANON(behavior)	;
       
  1536 			
       
  1537 			}
       
  1538 		else //SAN not supported
       
  1539 			{
       
  1540 				DetermineUISANOFF(behavior);
       
  1541 		
       
  1542 			}
       
  1543 		}
       
  1544 	else// if (iRestartCounter==0) //Started from DM UI, but not retry
       
  1545 		{
       
  1546 		iShowOMACDUI = ETrue;
       
  1547 		iShowDLPrgUI = ETrue;
       
  1548 		if (aFreshDL)
       
  1549 			iDLState.iSessionType = KErrNotFound;
       
  1550 		}
       
  1551 
       
  1552 TInt value (EFotaUpdateDM);
       
  1553 TInt err = RProperty::Get( KPSUidNSmlDMSyncApp, KNSmlCurrentFotaUpdateAppName, value );
       
  1554 if (!err && ((value == EFotaUpdateNSC) || (value == EFotaUpdateNSCBg)))
       
  1555 {
       
  1556 			iShowOMACDUI = EFalse;		
       
  1557 			iShowDLPrgUI = ETrue;
       
  1558 			FLOG(_L("CFotaDownload::DownloadL UI will not be shown!"));
       
  1559 }
       
  1560 	FLOG(_L("UI Behavior: OMA DD Display = %d, Download Progress = %d"),iShowOMACDUI,iShowDLPrgUI);
       
  1561 
       
  1562 	FLOG(_L("CFotaDownload::SetDownloadUiBehavior <<"));
       
  1563 	}
       
  1564 
       
  1565 
       
  1566 // --------------------------------------------------------------------------
       
  1567 // CFotaDownload::DetermineUISANON
       
  1568 // Determine UI when SAN is ON
       
  1569 // --------------------------------------------------------------------------
       
  1570 //
       
  1571 void CFotaDownload::DetermineUISANON(TInt aBehavior)
       
  1572 {
       
  1573 				switch (aBehavior)
       
  1574 					{
       
  1575 					case EOmacdOffdlprgOff: //0
       
  1576 						{
       
  1577 						iShowOMACDUI = EFalse;
       
  1578 						iShowDLPrgUI = EFalse;
       
  1579 						}
       
  1580 						break;
       
  1581 					case EOmacdOffdlprgOn: //1
       
  1582 						{
       
  1583 						iShowOMACDUI = EFalse;
       
  1584 						iShowDLPrgUI = ETrue;
       
  1585 						}
       
  1586 						break;
       
  1587 					case EOmacdOndlprgOff: //2
       
  1588 						{
       
  1589 						iShowOMACDUI = ETrue;
       
  1590 						iShowDLPrgUI = EFalse;
       
  1591 						}
       
  1592 						break;
       
  1593 					case EOmacdOndlprgOn: //3
       
  1594 						{
       
  1595 						iShowOMACDUI = ETrue;
       
  1596 						iShowDLPrgUI = ETrue;
       
  1597 						}
       
  1598 						break;
       
  1599 					default: //includes EChooseFromSan
       
  1600 						{
       
  1601 						if(iSanValue == ESanSilent)
       
  1602 							{
       
  1603 							iShowOMACDUI = EFalse;
       
  1604 							iShowDLPrgUI = EFalse;
       
  1605 							}
       
  1606 						else if (iSanValue == ESanInformative)
       
  1607 							{
       
  1608 							iShowOMACDUI = EFalse;
       
  1609 							iShowDLPrgUI = ETrue;
       
  1610 							}
       
  1611 						else //includes ESanInteractive, ESanNotSpecified
       
  1612 							{
       
  1613 							iShowOMACDUI = ETrue;
       
  1614 							iShowDLPrgUI = ETrue;
       
  1615 							}
       
  1616 						}
       
  1617 						break;
       
  1618 					}
       
  1619 	
       
  1620 	
       
  1621 }
       
  1622 
       
  1623 // --------------------------------------------------------------------------
       
  1624 // CFotaDownload::DetermineUISANOFF
       
  1625 // Determine UI when SAN is OFF
       
  1626 // --------------------------------------------------------------------------
       
  1627 //
       
  1628 
       
  1629 void CFotaDownload::DetermineUISANOFF(TInt aBehavior)
       
  1630 {
       
  1631 			if (iSanValue==EAcceptedYes) //Accepted is Yes in Profile
       
  1632 				{
       
  1633 				switch (aBehavior)
       
  1634 					{
       
  1635 					case EOmacdOffdlprgOff: //0
       
  1636 						{
       
  1637 						iShowOMACDUI = EFalse;
       
  1638 						iShowDLPrgUI = EFalse;
       
  1639 						}
       
  1640 						break;
       
  1641 					case EOmacdOffdlprgOn: //1
       
  1642 						{
       
  1643 						iShowOMACDUI = EFalse;
       
  1644 						iShowDLPrgUI = ETrue;
       
  1645 						}
       
  1646 						break;
       
  1647 					case EOmacdOndlprgOff: //2
       
  1648 						{
       
  1649 						iShowOMACDUI = ETrue;
       
  1650 						iShowDLPrgUI = EFalse;
       
  1651 						}
       
  1652 						break;
       
  1653 					default: //includes EOmacdOndlprgOn
       
  1654 						{
       
  1655 						iShowOMACDUI = ETrue;
       
  1656 						iShowDLPrgUI = ETrue;
       
  1657 						}
       
  1658 						break;
       
  1659 					}
       
  1660 				}
       
  1661 			else // includes iSanValue = EAcceptedNo (Accepted is No in profile)
       
  1662 				{
       
  1663 				iShowOMACDUI = ETrue;
       
  1664 				iShowDLPrgUI = ETrue;
       
  1665 				}
       
  1666 }
       
  1667 
       
  1668 
       
  1669 
       
  1670 
       
  1671 
       
  1672 
       
  1673 
       
  1674 // --------------------------------------------------------------------------
       
  1675 // CFotaDownload::RetrieveDownloadL
       
  1676 // Retrieves the RHttpDownload object from download manager during resume
       
  1677 // --------------------------------------------------------------------------
       
  1678 //
       
  1679 RHttpDownload* CFotaDownload::RetrieveDownloadL()
       
  1680 	{
       
  1681 	FLOG(_L("CFotaDownload::RetrieveDownloadL >>"));
       
  1682 	//Retrieve RHttpDownload object for the suspended download from Download Mgr.
       
  1683 	if (!iDownloadMgr.Handle())
       
  1684 		iDownloadMgr.ConnectL( TUid::Uid(KFotaServerUid) , *this, EFalse);
       
  1685 	const CDownloadArray& downloads = iDownloadMgr.CurrentDownloads();
       
  1686 	
       
  1687 	TBuf8<KMaxPath> url8;
       
  1688 	TInt32 val (KErrNone);
       
  1689 	
       
  1690 	RHttpDownload* aDownload (NULL);
       
  1691 	for (TInt i = 0; i < downloads.Count(); i++ )
       
  1692 		{
       
  1693 		User::LeaveIfError( downloads[i]->GetStringAttribute( EDlAttrCurrentUrl, url8 ));
       
  1694 		User::LeaveIfError( downloads[i]->GetIntAttribute( EDlAttrFotaPckgId, val));
       
  1695 	
       
  1696 		FLOG(_L("Current download(s) as per download mgr: %d, url = %S, pkgid = %d"), i+1, &url8, val);
       
  1697 	
       
  1698 		if (iDLState.iPkgId ==  val)
       
  1699 			{
       
  1700 			FLOG(_L("Successfully found the paused download object"));
       
  1701 			aDownload = downloads[i];
       
  1702 			if ( iUrl ) {delete iUrl; iUrl=NULL;}
       
  1703 			iUrl = url8.Alloc();
       
  1704 	
       
  1705 			}
       
  1706 		}
       
  1707 	FLOG(_L("CFotaDownload::RetrieveDownloadL <<"));
       
  1708 	return aDownload;
       
  1709 	}
       
  1710 
       
  1711 // --------------------------------------------------------------------------
       
  1712 // CFotaDownload::SetDownloadActive
       
  1713 // Sets the download activity state P&S key
       
  1714 // --------------------------------------------------------------------------
       
  1715 //
       
  1716 void CFotaDownload::SetDownloadActive(TBool aValue)
       
  1717 	{
       
  1718 	FLOG(_L("CFotaDownload::SetDownloadActive, aValue = %d"),aValue);
       
  1719 	iDownloadActive = aValue;
       
  1720 	TBool val (EFalse);
       
  1721 	TInt err = RProperty::Get(TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, val );
       
  1722 
       
  1723 	if (err == KErrNone && val != aValue)
       
  1724 		{
       
  1725 		err = RProperty::Set(TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, aValue );
       
  1726 		FLOG(_L("RProperty KFotaDownloadActive Set %d, err = %d"), aValue, err);
       
  1727 		}
       
  1728 	
       
  1729 	FLOG(_L("CFotaDownload::SetDownloadActive <<"));
       
  1730 	}
       
  1731 
       
  1732 // --------------------------------------------------------------------------
       
  1733 // IsDownloadActive
       
  1734 // Returns the activeness of the download
       
  1735 // --------------------------------------------------------------------------
       
  1736 //
       
  1737 
       
  1738 TBool CFotaDownload::IsDownloadActive()
       
  1739 	{
       
  1740 	FLOG(_L("CFotaDownload::IsDownloadActive, value = %d"),iDownloadActive);
       
  1741 	return iDownloadActive;
       
  1742 	}
       
  1743 
       
  1744 
       
  1745 // --------------------------------------------------------------------------
       
  1746 // CFotaDownloadNotifHandler::NewL 
       
  1747 // --------------------------------------------------------------------------
       
  1748 //
       
  1749 CFotaDownloadNotifHandler* CFotaDownloadNotifHandler::NewL (CFotaDownload* aDownload)
       
  1750 	{
       
  1751 	FLOG(_L("CFotaDownloadNotifHandler::NewL"));
       
  1752 	__ASSERT_ALWAYS( aDownload, User::Panic(KFotaPanic, KErrArgument) );	
       
  1753 	CFotaDownloadNotifHandler* h=new (ELeave)CFotaDownloadNotifHandler;
       
  1754 	h->iDownload = aDownload;
       
  1755 	h->iDownload->iFotaServer->iNotifHandler = h;
       
  1756 	return h;
       
  1757 	}
       
  1758 
       
  1759 // --------------------------------------------------------------------------
       
  1760 CFotaDownloadNotifHandler::CFotaDownloadNotifHandler() : CActive(EPriorityNormal)
       
  1761 	{
       
  1762 	FLOG(_L("CFotaDownloadNotifHandler::CFotaDownloadNotifHandler()"));
       
  1763 	CActiveScheduler::Add( this ); 
       
  1764 	}
       
  1765 
       
  1766 // --------------------------------------------------------------------------
       
  1767 CFotaDownloadNotifHandler::~CFotaDownloadNotifHandler()
       
  1768 	{
       
  1769 	FLOG(_L("CFotaDownloadNotifHandler::~CFotaDownloadNotifHandler >>"));
       
  1770 	iNotifier.Close();
       
  1771 	Cancel();
       
  1772 	FLOG(_L("CFotaDownloadNotifHandler::~CFotaDownloadNotifHandler <<"));
       
  1773 	}
       
  1774 
       
  1775 // --------------------------------------------------------------------------
       
  1776 void CFotaDownloadNotifHandler::RunL()
       
  1777 	{
       
  1778 	FLOG(_L("CFotaDownloadNotifHandler::RunL() note:%d, param:%d" ),iNotifParams.iNoteType, iNotifParams.iIntParam);
       
  1779 
       
  1780 	TBool reset (ETrue);
       
  1781 
       
  1782 	iNotifier.Close();
       
  1783 
       
  1784 	iDownload->SetDownloadActive(EFalse);
       
  1785 	if ( iNotifParams.iNoteType == ESyncMLFwUpdErrorNote  ) // 1 
       
  1786 		{
       
  1787 		//do nothing here
       
  1788 		}
       
  1789 	if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLNotEnoughMemory ) // 7
       
  1790 		{
       
  1791 		//To be active as Flexible mem is in action.
       
  1792 		if (iDownload->iFreshDL)
       
  1793 			iDownload->SetDownloadActive(ETrue);
       
  1794 		}
       
  1795 	if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLUserCancel )
       
  1796 		{
       
  1797 		//At this point Download Mgr has already paused the download successfully.
       
  1798 		if (iStatus.Int() == KErrCancel) //RSK Press
       
  1799 			{
       
  1800 			//User wants to cancel download permanently.
       
  1801 			FLOG(_L("User choose to cancel download permanently!"));
       
  1802 			iDownload->RunDownloadCancelL(RFotaEngineSession::EResUserCancelled);
       
  1803 			}
       
  1804 		else
       
  1805 			{
       
  1806 			//Other keys pressed, like LSK or Call termination key
       
  1807 			FLOG(_L("User choose to resume download later, key press = %d"),iStatus.Int());
       
  1808 			iDownload->iFotaServer->FinalizeDownloadL( iDownload->iDLState );
       
  1809 			if (iStatus.Int() == KErrNone) //RSK is pressed
       
  1810 				{
       
  1811 				LaunchNotifierL(ESyncMLFwUpdOmaDLPostponed, EFalse, EFalse);
       
  1812 				reset = EFalse;
       
  1813 				}
       
  1814 			else
       
  1815 				iDownload->iFotaServer->ShutApp();
       
  1816 			}
       
  1817 		}
       
  1818 
       
  1819 	if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLPostponed )
       
  1820 		{
       
  1821 		//Nothing to do
       
  1822 		}
       
  1823 
       
  1824 	if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLCancelled )
       
  1825 		{
       
  1826 		//Nothing to do
       
  1827 		}
       
  1828 
       
  1829 	if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLResume )
       
  1830 		{
       
  1831 		if (iStatus.Int() == KErrNone) // LSK Press
       
  1832 			{
       
  1833 			FLOG(_L("User choose to continue download now."));
       
  1834 			iNotifParams.iNoteType = ESyncMLFwUpdUnknown;
       
  1835 			iNotifParams.iIntParam = 0;
       
  1836 			iDownload->ResumeDownloadL();
       
  1837 			reset = EFalse;
       
  1838 			}
       
  1839 		else	//RSK or any other key
       
  1840 			{
       
  1841 			FLOG(_L("User cancelled to continue download now, key press = %d."),iStatus.Int());
       
  1842 			if (iStatus.Int() == KErrCancel) //RSK is pressed
       
  1843 				{
       
  1844 				iDownload->iDLState.iResult = RFotaEngineSession::EResUserCancelled;
       
  1845 				LaunchNotifierL(ESyncMLFwUpdOmaDLUserCancel, EFalse, EFalse);
       
  1846 				reset = EFalse;
       
  1847 				}
       
  1848 			else
       
  1849 				iDownload->iFotaServer->ShutApp();
       
  1850 			}
       
  1851 		}
       
  1852 
       
  1853 	if (reset)
       
  1854 		{
       
  1855 		iNotifParams.iNoteType = ESyncMLFwUpdUnknown;
       
  1856 		iNotifParams.iIntParam = 0;
       
  1857 		}
       
  1858 	}
       
  1859 
       
  1860 // --------------------------------------------------------------------------
       
  1861 TInt CFotaDownloadNotifHandler::RunError(TInt aError)
       
  1862 	{	
       
  1863 	FLOG(_L("CFotaDownloadNotifHandler::RunError %d"),aError);
       
  1864 	return aError;
       
  1865 	}
       
  1866 
       
  1867 // --------------------------------------------------------------------------
       
  1868 void CFotaDownloadNotifHandler::DoCancel()
       
  1869 	{
       
  1870 	FLOG(_L("CFotaDownloadNotifHandler::DoCancel >>"));
       
  1871 	if (iNotifier.Handle())
       
  1872 		{
       
  1873 		iNotifier.CancelNotifier( KSyncMLFwUpdNotifierUid );
       
  1874 		iNotifier.Close();
       
  1875 		}
       
  1876 		FLOG(_L("CFotaDownloadNotifHandler::DoCancel <<"));
       
  1877 	}
       
  1878 
       
  1879 // --------------------------------------------------------------------------
       
  1880 void CFotaDownloadNotifHandler::LaunchNotifierL( const TSyncMLFwUpdNoteTypes aNotetype
       
  1881 		,const TInt aIntParam
       
  1882 		, const TInt aMemoryNeeded
       
  1883 		,TBool aFinishOnly)
       
  1884 	{
       
  1885 	FLOG(_L("CFotaDownloadNotifHandler::LaunchNotifierL, aNoteType=%d, aParam=%d, aMemoryNeeded=%d aFinishOnly=%d >>  "), aNotetype, aIntParam, aMemoryNeeded, aFinishOnly?1:0);
       
  1886 	
       
  1887 	__ASSERT_ALWAYS( iNotifier.Handle()==0, User::Leave(KErrAlreadyExists) );
       
  1888 	__ASSERT_ALWAYS( aMemoryNeeded>=0, User::Leave(KErrArgument) );
       
  1889 
       
  1890 
       
  1891 	// Launch notifier
       
  1892 	TSyncMLFwUpdNotifParams         params;
       
  1893 	FLOG(_L("           1"));
       
  1894 	params.iNoteType        = aNotetype;
       
  1895 	params.iIntParam        = aIntParam;
       
  1896 
       
  1897 	TInt rem = 0;
       
  1898 	rem = aMemoryNeeded % 1024 ;
       
  1899 	if (rem)
       
  1900 		{
       
  1901 		params.iMemoryNeeded = (aMemoryNeeded /1024) + 1;   	
       
  1902 		}
       
  1903 	else
       
  1904 		{  
       
  1905 		params.iMemoryNeeded = (aMemoryNeeded /1024) ;
       
  1906 		}
       
  1907 
       
  1908 	//    #endif    
       
  1909 	TSyncMLFwUpdNotifParamsPckg     pckg(params);
       
  1910 	iNotifParams.iNoteType  = params.iNoteType;
       
  1911 	iNotifParams.iIntParam  = params.iIntParam;
       
  1912 
       
  1913 	iNotifParams.iMemoryNeeded = params.iMemoryNeeded;
       
  1914 
       
  1915 	iDummyResponsePckg = TSyncMLFwUpdNotifRetValPckg();
       
  1916 	FLOG(_L("           2"));
       
  1917 	if ( !aFinishOnly )
       
  1918 		{
       
  1919 		User::LeaveIfError( iNotifier.Connect() );
       
  1920 		iNotifier.StartNotifierAndGetResponse( iStatus, KSyncMLFwUpdNotifierUid
       
  1921 				, pckg, iDummyResponsePckg );
       
  1922 		SetActive();
       
  1923 		}
       
  1924 	else
       
  1925 		{
       
  1926 		iStatus = KRequestPending;
       
  1927 		SetActive();
       
  1928 		TRequestStatus* status = &iStatus;
       
  1929 		User::RequestComplete( status, KErrNone );
       
  1930 		}
       
  1931 	FLOG(_L("           3  %d"),iStatus.Int());
       
  1932 	FLOG(_L("CFotaDownloadNotifHandler::LaunchNotifierL() <<"));	
       
  1933 	}
       
  1934 
       
  1935 TBool CFotaDownloadNotifHandler::IsOpen()
       
  1936 	{
       
  1937 	FLOG(_L("Handle = %d"), iNotifier.Handle());
       
  1938 	return (iNotifier.Handle())? ETrue:EFalse;
       
  1939 	}