fotaapplication/fotaserver/FotaServer/src/FotaServer.cpp
changeset 0 b497e44ab2fc
child 9 57a65a3a658c
child 22 19fb38abab1d
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:   Fota server update and download functionality 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <aknenv.h>
       
    22 #include <apgtask.h>
       
    23 #include <apgwgnam.h>
       
    24 #include <schtime.h>
       
    25 #include <csch_cli.h>
       
    26 #include <e32property.h>
       
    27 #include <ApUtils.h> 
       
    28 #include <commdb.h>
       
    29 #include <DevManInternalCRKeys.h>
       
    30 #include <nsmlconstants.h>
       
    31 #include <centralrepository.h>
       
    32 #include <sysversioninfo.h>
       
    33 #include "FotaSrvApp.h"
       
    34 #include "FotaServer.h"
       
    35 #include "FotaSrvDebug.h"
       
    36 #include "FotasrvSession.h"
       
    37 #include "fotaConst.h"
       
    38 #include "nsmldmtreedbclient.h"
       
    39 #include "fotaserverPrivatePSKeys.h"
       
    40 #include "FotaNetworkRegStatus.h"
       
    41 _LIT(KSizePass, "contentsize");
       
    42 #include "DevEncController.h"
       
    43 #define __LEAVE_IF_ERROR(x) if(KErrNone!=x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); }
       
    44 // ============================= LOCAL FUNCTIONS =============================
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // ToDesC16LC
       
    48 // Converts to 16bit desc
       
    49 // ---------------------------------------------------------------------------
       
    50 HBufC* ToDesC16LC( const TDesC8& a )
       
    51     {
       
    52     HBufC* bf = HBufC::NewLC( a.Length() );
       
    53     bf->Des().Copy(a);
       
    54     return bf;
       
    55     }
       
    56 // ---------------------------------------------------------------------------
       
    57 // GetPredefinedNodeL
       
    58 // function to get preconfigured node for FUMO
       
    59 // ---------------------------------------------------------------------------
       
    60 void GetPredefinedNodeL(TDes8& aNode)
       
    61 	{
       
    62 	FLOG(_L("GetPredefinedNodeL() Begin"));
       
    63     CRepository* centrep( NULL);
       
    64 	aNode.Zero();
       
    65    	centrep = CRepository::NewLC( TUid::Uid(0x101F9A0A) );
       
    66 
       
    67     if ( centrep )
       
    68 	    {
       
    69 	    FLOG(_L("centralrepository found End"));
       
    70     	TFullName temp;
       
    71 		
       
    72     	if (centrep->Get( KDevManFUMOPredefinedNodes, temp )==KErrNone && temp.Length() )
       
    73 			{
       
    74 			temp.Trim();
       
    75 			aNode.Copy(temp);
       
    76 			}
       
    77 		CleanupStack::PopAndDestroy(centrep);
       
    78 	    }
       
    79 	FLOG(_L("GetPredefinedNodeL() End"));	    
       
    80 	}
       
    81 // ---------------------------------------------------------------------------
       
    82 // DeleteFUMOTreeL
       
    83 // function to get preconfigured node for FUMO
       
    84 // ---------------------------------------------------------------------------
       
    85 void DeleteFUMOTreeL ()
       
    86     {
       
    87     FLOG(_L("DeleteFUMOTreeL() Begin"));
       
    88     const TUint32 KNSmlFotaAdapterUid = 0x101F9A09;
       
    89     _LIT8( KNSmlFumoPath, "FUMO" );
       
    90     _LIT8( KNSmlFumoSeparator, "/" );
       
    91     const TInt KGranularity = 10;
       
    92     TBuf8<KMaxFullName> temp;
       
    93 	GetPredefinedNodeL(temp);
       
    94     RNSmlDMCallbackSession session;
       
    95     User::LeaveIfError(session.Connect());
       
    96     CleanupClosePushL(session);
       
    97     
       
    98     CBufBase *emptyList = CBufFlat::NewL(0);
       
    99     CleanupStack::PushL(emptyList);
       
   100     CArrayFixFlat <TSmlDmMappingInfo>* UriSegList;
       
   101     UriSegList = new (ELeave) CArrayFixFlat <TSmlDmMappingInfo> (KGranularity);
       
   102     
       
   103     CleanupStack::PushL(UriSegList);
       
   104 			
       
   105     session.GetUriSegListL(KNSmlFotaAdapterUid,KNSmlFumoPath,*UriSegList);
       
   106     
       
   107     for ( TUint16 i=0;i<UriSegList->Count();i++)
       
   108         {
       
   109         	if (temp.Length() && UriSegList->At(i).iURISeg.Find( temp ) != KErrNotFound)
       
   110             {
       
   111               FLOG(_L("DeleteFUMOTreeL predefined match =%S"), &temp);
       
   112               continue;
       
   113             }
       
   114        
       
   115        	TBuf8<KMaxFullName> tempFumo;
       
   116        	tempFumo.Append(KNSmlFumoPath);
       
   117        	tempFumo.Append(KNSmlFumoSeparator);
       
   118        	tempFumo.Append(UriSegList->At(i).iURISeg);
       
   119        	FLOG(_L("DeleteFUMOTreeL() call update mapping info for node %S"),&tempFumo);
       
   120         session.UpdateMappingInfoL(KNSmlFotaAdapterUid,tempFumo,*emptyList);
       
   121         
       
   122         }
       
   123     // session.UpdateMappingInfoL(KNSmlFotaAdapterUid,KNSmlFumoPath,*emptyList);
       
   124 	CleanupStack::PopAndDestroy(UriSegList); 
       
   125     CleanupStack::PopAndDestroy(emptyList); 
       
   126     CleanupStack::PopAndDestroy(&session); //session
       
   127     FLOG(_L("DeleteFUMOTreeL() End"));
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CFotaServer::GetProfileDataL
       
   132 // ---------------------------------------------------------------------------
       
   133 void CFotaServer::GetProfileDataL( RSyncMLSession* aSyncml
       
   134     ,const TSmlProfileId aProf, TInt& aIapId, TSmlServerAlertedAction& aSrvAA
       
   135     ,TBool& aUIJob, TInt& aSanVal)
       
   136 	{
       
   137     FLOG(_L("CFotaServer::GetProfileDataL prof %d"),aProf);
       
   138     __ASSERT_ALWAYS( aSyncml, User::Panic(KFotaPanic, KErrArgument) );
       
   139     __ASSERT_ALWAYS( aSyncml->Handle(), User::Panic(KFotaPanic, KErrBadHandle) );
       
   140     // GET IAP FROM PROFILE ----------------------------------------------
       
   141     TSmlJobId               jobid( KErrNotFound );
       
   142     TInt                    jobidFromUI( KErrNotFound );
       
   143     RSyncMLDevManProfile    smlprof;
       
   144     RArray<TSmlTransportId> connections;
       
   145     TSmlTransportId         transport;
       
   146     RSyncMLConnection       connection;
       
   147                    
       
   148     CleanupClosePushL(smlprof);
       
   149     CleanupClosePushL(connections);
       
   150     CleanupClosePushL(connection);
       
   151     FLOG(_L("[FotaServer]   1"));
       
   152     
       
   153     FLOG(_L("[FotaServer]   1.1 opening syncml \
       
   154                         profileid %d "), aProf);
       
   155     smlprof.OpenL(*aSyncml, aProf, ESmlOpenRead);
       
   156     FLOG(_L("[FotaServer]  1.1"));
       
   157     smlprof.ListConnectionsL(connections);
       
   158     FLOG(_L("[FotaServer]  1.3"));
       
   159     transport = connections[0];
       
   160     connection.OpenL(smlprof,transport);
       
   161     TBuf8<20> iapid2 = connection.GetPropertyL ( KNSmlIAPId );
       
   162     TLex8 iapid3(iapid2);
       
   163     iapid3.Val(aIapId);
       
   164 
       
   165     // 1. Profile's "accepted" field.
       
   166     aSrvAA = smlprof.SanUserInteraction ();
       
   167     FLOG(_L("[FotaServer]  1.4 \
       
   168                     SanUserInteraction:%d"),aSrvAA );
       
   169 
       
   170     // 2. Has job been started from omadmappui. That is, did user start the job
       
   171     TSmlUsageType dmusagetype(ESmlDevMan);
       
   172     aSyncml->CurrentJobL( jobid,dmusagetype );
       
   173     RProperty::Get( TUid::Uid(KOmaDMAppUid), KNsmlCurrentJobId, jobidFromUI);
       
   174     aUIJob = ( jobidFromUI == jobid && jobid!=KErrNotFound );
       
   175     
       
   176     aSanVal = KErrNotFound; 
       
   177     if ( aUIJob )
       
   178     	{
       
   179     	//First for not server alert or SAN not supported value is -1
       
   180     	RProperty::Get( TUid::Uid(KOmaDMAppUid), KNsmlSanUIMode, aSanVal);
       
   181     	if ( aSanVal != -1 ) //SAN Supported
       
   182     	    {
       
   183    	    	aUIJob = 0;
       
   184     	    }
       
   185     	}
       
   186     FLOG(_L("  jobidFromUI: %d jobid: %d, aUIJob: %d, aSanVal: %d"),jobidFromUI,jobid,aUIJob,aSanVal);
       
   187     CleanupStack::PopAndDestroy (&connection); 
       
   188     CleanupStack::PopAndDestroy (&connections);
       
   189     CleanupStack::PopAndDestroy (&smlprof); 
       
   190 	}
       
   191 
       
   192 // --------------------------------------------------------------------------
       
   193 // CreateDeviceManagementSessionL       
       
   194 // Creates DM session 
       
   195 // --------------------------------------------------------------------------
       
   196 void CFotaServer::CreateDeviceManagementSessionL( TPackageState& aState )
       
   197     {
       
   198     FLOG(_L("[cfotasever]   CreateDeviceManagementSessionL dms >> profid %d\
       
   199     %d counts left ,sml handle %d, iNetworkAvailable=%d"), aState.iProfileId, aState.iSmlTryCount 
       
   200     , iSyncMLSession.Handle(),iNetworkAvailable);
       
   201 	
       
   202     SetStartupReason(EFotaPendingGenAlert);
       
   203 
       
   204 	if (!iNetworkAvailable)
       
   205 		{
       
   206 		iRetryingGASend = ETrue;
       
   207 		iStoredState = aState;
       
   208 		StartNetworkMonitorL();
       
   209 		}
       
   210 	else 
       
   211 		{
       
   212 
       
   213 	    TBool dbAlreadyOpen = iDatabase->IsOpen();
       
   214 	    TBool triesLeft( EFalse );
       
   215  		
       
   216  		iNetworkAvailable = EFalse; // to check network again when GA is sent next time
       
   217  		
       
   218 	    if ( iSyncMLSession.Handle() )
       
   219 	        {
       
   220 	        User::Leave( KErrAlreadyExists );
       
   221 	        }
       
   222 
       
   223 	    if ( !dbAlreadyOpen ) iDatabase->OpenDBL();
       
   224 	    // There is still tries left
       
   225 	    if ( aState.iSmlTryCount > 0 )
       
   226 	        {
       
   227 	        triesLeft = ETrue;
       
   228 	        FLOG(_L(" decrementing the retry count"));
       
   229 	        aState.iSmlTryCount = aState.iSmlTryCount - 1;
       
   230 	        iDatabase->SetStateL( aState, KNullDesC8, EFDBSmlTryCount );
       
   231 	        }
       
   232 	    // out of tries, set state to idle
       
   233 	    else
       
   234 	        {
       
   235 	        triesLeft = EFalse;
       
   236 	        FLOG(_L("   out of tries, resetting pkg state"));
       
   237 	        
       
   238 	        SetStartupReason(EFotaDefault);
       
   239 	        aState.iState = RFotaEngineSession::EIdle;
       
   240 	        aState.iResult = KErrNotFound;
       
   241 	        iDatabase->SetStateL( aState, KNullDesC8, EFDBState|EFDBResult );
       
   242 	        }
       
   243 	    if ( !dbAlreadyOpen ) iDatabase->CloseAndCommitDB();
       
   244 
       
   245 	    if ( triesLeft )
       
   246 	        {
       
   247 	        TInt iapid;
       
   248 	        TSmlServerAlertedAction tmp;
       
   249 	        TBool                   tmp2;
       
   250 	        TInt					tmp3;
       
   251 	        iSyncMLSession.OpenL(); 
       
   252 	        GetProfileDataL( &iSyncMLSession,aState.iProfileId,iapid,tmp,tmp2,tmp3);
       
   253 	        FLOG(_L("Using IAP: %d to send GA"),iapid);
       
   254 	        FLOG(_L("From Db Using IAP: %d to send GA"),aState.iIapId);
       
   255 	        RSyncMLDevManJob    dmJob;
       
   256 	        TBuf<10> genalertap,temp;
       
   257 	        genalertap.Zero();
       
   258 	        temp.Zero();	  
       
   259 	        genalertap.Append(KNSmlDMJobIapPrefix);
       
   260 	        temp.Num(aState.iIapId);//Decimal Iap
       
   261 	        if( temp.Length() <= KNSmlHalfTransportIdLength && 
       
   262 	            aState.iIapId > KErrNotFound && CheckIapExistsL(aState.iIapId) )
       
   263 	        	{
       
   264 	        	genalertap.AppendFill('0',KNSmlHalfTransportIdLength-temp.Length());
       
   265 	        	genalertap.Append(temp);
       
   266 	        	TLex gavalue(genalertap);
       
   267 	        	gavalue.Val(iIapId);
       
   268 	        	dmJob.CreateL( iSyncMLSession, aState.iProfileId,iIapId);	
       
   269 	        	iSyncMLAttempts = KSyncmlAttemptCount;
       
   270 	        	}
       
   271 	        else 
       
   272 	        	{
       
   273 	        	iSyncMLAttempts = 0;
       
   274 	        	dmJob.CreateL( iSyncMLSession, aState.iProfileId);
       
   275 	        	}
       
   276 
       
   277 			// If there's no iapid defined, sml will pop up connection dialog.
       
   278 			// In that case, only one connection attempt is allowed.
       
   279 	        iSyncJobId   = dmJob.Identifier();
       
   280 	        iSyncProfile = aState.iProfileId;
       
   281 	        dmJob.Close();
       
   282 	        iSyncMLSession.RequestEventL( *this ); 
       
   283 	        }
       
   284 	}
       
   285 
       
   286     FLOG(_L("[cfotasever]   CreateDeviceManagementSessionL dms << profid %d")
       
   287                             ,aState.iProfileId);
       
   288     }
       
   289 
       
   290 
       
   291 // ============================= MEMBER FUNCTIONS ============================
       
   292 
       
   293 // --------------------------------------------------------------------------
       
   294 // CFotaServer::CFotaServer()   
       
   295 // --------------------------------------------------------------------------
       
   296 //
       
   297 CFotaServer::CFotaServer() : iInitialized(EFalse), iNeedToClose(0), iParentApp(0)
       
   298 , iDatabase(0),iDownloader(0), iUpdater(0)
       
   299  , iDownloadFinalizer(0), iUpdateFinalizer(0), iTimedExecuteResultFile(0)
       
   300  , iTimedSMLSessionClose(0), iStorage(0), iAppShutter(0), iMonitor (NULL), iSyncJobId(-1), iRetryingGASend (EFalse), iNetworkAvailable (EFalse)
       
   301  , iIapId(KErrNotFound),iSessMode(0),iUserResume(KErrNotFound), iInstallupdClient(EFalse), iDEController(NULL)
       
   302 	{
       
   303     RProcess pr; TFullName fn = pr.FullName();  TUint prid = pr.Id();
       
   304 	FLOG(_L( "CFotaServer::CFotaServer process(id %d)%S. this 0x%x"),prid,&fn
       
   305         ,this);
       
   306 
       
   307 	}
       
   308 
       
   309 
       
   310 // --------------------------------------------------------------------------
       
   311 // CFotaServer::DoExecuteResultFileL
       
   312 // Interprets result of update (file update.resp)
       
   313 // --------------------------------------------------------------------------
       
   314 //
       
   315 void CFotaServer::DoExecuteResultFileL()
       
   316     {
       
   317     FLOG(_L("CFotaServer::DoExecuteResultFileL() >>"));
       
   318 
       
   319     if ( iTimedExecuteResultFile ) 
       
   320         {
       
   321         iTimedExecuteResultFile->Cancel();
       
   322         delete iTimedExecuteResultFile;
       
   323         iTimedExecuteResultFile = NULL;
       
   324         }
       
   325     iUpdater = CFotaUpdate::NewL(this);
       
   326     iUpdater->ExecuteUpdateResultFileL( iFs );
       
   327     FLOG(_L("CFotaServer::DoExecuteResultFileL() <<"));
       
   328     }
       
   329 
       
   330 // --------------------------------------------------------------------------
       
   331 // StaticDoExecuteResultFile
       
   332 // --------------------------------------------------------------------------
       
   333 //
       
   334 static TInt StaticDoExecuteResultFile(TAny *aPtr)
       
   335     {
       
   336     FLOG(_L("[cfotaserver] StaticDoExecuteResultFile() >>"));
       
   337     __ASSERT_ALWAYS( aPtr, User::Panic(KFotaPanic, KErrBadHandle) );
       
   338     CFotaServer* srv = (CFotaServer*) aPtr;
       
   339     TRAPD( err,  srv->DoExecuteResultFileL() );
       
   340     if(err) 
       
   341         {
       
   342         FLOG(_L("[cfotaserver] StaticDoExecuteResultFile ERROR %d"),err);
       
   343         TRAP_IGNORE(srv->DoDeleteUpdateResultFileL());
       
   344         }
       
   345 
       
   346     FLOG(_L("[cfotaserver] StaticDoExecuteResultFile() <<"));
       
   347     return err;
       
   348     }
       
   349 
       
   350 
       
   351 // --------------------------------------------------------------------------
       
   352 // CFotaServer::CFotaServer()   
       
   353 // Constructor. Can't do all constructing since fotaserver might call itself
       
   354 // recursively (via downloadmgr). 
       
   355 // --------------------------------------------------------------------------
       
   356 //
       
   357 void CFotaServer::ConstructL(const TDesC &aFixedServerName)
       
   358     {
       
   359     FLOG(_L("CFotaServer::ConstructL() >> name=%S"), &aFixedServerName);
       
   360     TBool   updated (EFalse);
       
   361     TInt    err;
       
   362     CAknAppServer::ConstructL( aFixedServerName );
       
   363 
       
   364     User::LeaveIfError( iFs.Connect() );
       
   365     
       
   366     err = iFs.CreatePrivatePath(EDriveC);
       
   367     if ( err != KErrNone && err != KErrAlreadyExists ) { User::Leave (err); }
       
   368     User::LeaveIfError( iFs.SetSessionToPrivate( EDriveC ) );
       
   369 
       
   370     if ( !iDatabase )
       
   371         {
       
   372         TRAPD( err,iDatabase = CFotaDB::NewL() );
       
   373         if ( err ) 
       
   374             {
       
   375             FLOG(_L("CFotaServer::  DB creationg error %d"), err);
       
   376             User::Leave( err );
       
   377             }
       
   378         }
       
   379 
       
   380     updated = CFotaUpdate::CheckUpdateResults( iFs );
       
   381 
       
   382     // Update has happened, and result file is in place
       
   383     if ( updated )
       
   384         {
       
   385         FLOG(_L("scheduling update result file execution"));
       
   386         if ( iTimedExecuteResultFile ) 
       
   387             {
       
   388             iTimedExecuteResultFile->Cancel();
       
   389             delete iTimedExecuteResultFile;
       
   390             iTimedExecuteResultFile = NULL;
       
   391             }
       
   392         iTimedExecuteResultFile = CPeriodic::NewL (EPriorityNormal) ;
       
   393         iTimedExecuteResultFile->Start (
       
   394             TTimeIntervalMicroSeconds32(KDownloadFinalizerWaitTime)
       
   395             , TTimeIntervalMicroSeconds32(KDownloadFinalizerWaitTime)
       
   396             , TCallBack(StaticDoExecuteResultFile,this) ) ;
       
   397         }
       
   398 
       
   399 	iEikEnv = CEikonEnv::Static();
       
   400     FLOG(_L("CFotaServer::ConstructL() <<"));
       
   401     }
       
   402 
       
   403 
       
   404 // --------------------------------------------------------------------------
       
   405 // CFotaServer::ClientAwareConstructL
       
   406 // Does rest of constructing, if not done. If parent of this fotaserver 
       
   407 // instance is another fotaserver, skip maintenance operations (since parent 
       
   408 // takes care of them). DmHOstserver triggers cleanup for states: 20,70,80
       
   409 // ,90,100 , must handle state 60 here
       
   410 // --------------------------------------------------------------------------
       
   411 void CFotaServer::ClientAwareConstructL( const RMessage2 &aMessage )
       
   412     {
       
   413     FLOG(_L("CFotaServer::ClientAwareConstructL >>"));
       
   414     if ( iInitialized ) return;
       
   415     CFotaSrvSession::TClient client 
       
   416                     = CFotaSrvSession::CheckClientSecureIdL ( aMessage );
       
   417 	// temporary fix to keep FS from polluting FSW in case it was opened from omadmappui
       
   418     if ( client == CFotaSrvSession::EOMADMAppUi || client == CFotaSrvSession::EFotaServer ||
       
   419        client == CFotaSrvSession::ESoftwareChecker || client == CFotaSrvSession::ESoftwareCheckerBackground  ) 
       
   420         {
       
   421         //Loading the storage plugin (during DM UI launch) to adjust the reserved memory accordingly.
       
   422         StoragePluginL();
       
   423         iParentApp->SetUIVisibleL ( EFalse, ETrue ); // 
       
   424         }
       
   425 
       
   426     // Do constructing if client is other that fotaserver
       
   427     if ( client != CFotaSrvSession::EFotaServer )
       
   428         {
       
   429         RArray<TInt>    states;
       
   430         TPackageState   state;
       
   431         CleanupClosePushL (states);
       
   432         iDatabase->OpenDBL();
       
   433         iDatabase->GetAllL ( states );
       
   434     	TBool value (EFalse);
       
   435     	if (iDownloader)
       
   436     		{
       
   437     		value = iDownloader->IsDownloadActive();
       
   438     		}
       
   439     	else
       
   440     		{
       
   441     		TInt err = RProperty::Get(TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, value );
       
   442     		FLOG(_L("value of KFotaDownloadActive & err as %d,%d "), (TInt)value,err);
       
   443     		}
       
   444     	FLOG(_L("Download active value is:%d "), (TInt)value);
       
   445         // Loop states. 
       
   446         for(TInt i = 0; i < states.Count(); ++i ) 
       
   447             {
       
   448             TPackageState   tmp;
       
   449             TBool           toIdle(EFalse);
       
   450             tmp = iDatabase->GetStateL(  states[i]  );
       
   451             FLOG(_L("   1 got state id:%d state:%d result:%d"), tmp.iPkgId
       
   452                 , tmp.iState, tmp.iResult);
       
   453             
       
   454              if ( tmp.iState == RFotaEngineSession::EStartingUpdate )
       
   455              
       
   456              {
       
   457              	TBool ispkgvalid= ETrue;
       
   458              	TRAPD(err1,ispkgvalid= CheckSWVersionL()   )
       
   459               if (!ispkgvalid && err1 == KErrNone)
       
   460               {
       
   461               StoragePluginL()->DeleteUpdatePackageL (  tmp.iPkgId );	
       
   462              	tmp.iState    = RFotaEngineSession::EUpdateFailed;
       
   463               tmp.iResult   = RFotaEngineSession::EResPackageMismatch;
       
   464               iDatabase->SetStateL( tmp,KNullDesC8, EFDBState | EFDBResult );
       
   465    
       
   466              }	
       
   467              }
       
   468             // Update has been started (60)
       
   469             // If there is no result file, means that update agent failed
       
   470             // to run. Must get back to 50 to allow user to try again. 
       
   471             if ( tmp.iState == RFotaEngineSession::EUpdateProgressing 
       
   472                 && iTimedExecuteResultFile==NULL )
       
   473                 {
       
   474                 FLOG(_L("     State 60 found, UA didnt run! id %d "), tmp.iPkgId);
       
   475                 tmp.iState    = RFotaEngineSession::EStartingUpdate;
       
   476                 iDatabase->SetStateL( tmp,KNullDesC8, EFDBState);
       
   477                 }
       
   478 
       
   479             // These states need must trigger generic alert! (70+ )
       
   480             if ( tmp.iState >= RFotaEngineSession::EUpdateFailed  )
       
   481                 {
       
   482                 if ( iSyncMLSession.Handle() == NULL )
       
   483                     {
       
   484                     iDatabase->CloseAndCommitDB();
       
   485                     CreateDeviceManagementSessionL( tmp );
       
   486                     iDatabase->OpenDBL();
       
   487                     }
       
   488                 }
       
   489 
       
   490             if (tmp.iState == RFotaEngineSession::EDownloadComplete && tmp.iResult == RFotaEngineSession::EResSuccessful )
       
   491             	{
       
   492                 CreateDeviceManagementSessionL( tmp );
       
   493             	}
       
   494 
       
   495             if (value != 1) //if download is not active, EStartingDownload should be reset to EDownloadFailed
       
   496             	{
       
   497             	if (tmp.iState == RFotaEngineSession::EStartingDownload ||
       
   498             			tmp.iState == RFotaEngineSession::EDownloadProgressing )
       
   499             		{
       
   500             		FLOG(_L("Resetting state %d to 20..."), tmp.iState);
       
   501             		tmp.iState = RFotaEngineSession::EDownloadFailed;
       
   502                     iDatabase->SetStateL( tmp,KNullDesC8, EFDBState ) ;
       
   503                     iDatabase->CloseAndCommitDB();
       
   504                     iDatabase->OpenDBL();
       
   505             		}
       
   506             	}
       
   507 
       
   508             if ( tmp.iState == RFotaEngineSession::EDownloadFailed )
       
   509                 {
       
   510                 StoragePluginL()->DeleteUpdatePackageL( tmp.iPkgId ); 
       
   511                 tmp.iResult   = RFotaEngineSession::EResDLFailDueToNWIssues;
       
   512                 iDatabase->SetStateL( tmp,KNullDesC8, EFDBResult ) ;
       
   513                 iDatabase->CloseAndCommitDB();
       
   514                 CreateDeviceManagementSessionL( tmp );
       
   515                 iDatabase->OpenDBL();
       
   516                 }
       
   517 
       
   518             // Reset package state to idle
       
   519             if ( toIdle )
       
   520                 {
       
   521                 FLOG(_L("   2 resetting state %d to idle"), tmp.iPkgId);
       
   522                 tmp.iState    = RFotaEngineSession::EIdle;
       
   523                 iDatabase->SetStateL( tmp,KNullDesC8, EFDBState ) ;
       
   524                 DeleteFUMOTreeL();
       
   525                 }
       
   526             }
       
   527             iDatabase->CloseAndCommitDB();
       
   528             CleanupStack::PopAndDestroy( &states );
       
   529         }
       
   530     else // client is child fotaserver
       
   531         {
       
   532         }
       
   533     iInitialized = ETrue;
       
   534     FLOG(_L("CFotaServer::ClientAwareConstructL <<"));
       
   535     }
       
   536 
       
   537 
       
   538 // ---------------------------------------------------------------------------
       
   539 // CFotaServer::StoragePluginL
       
   540 // Getter function for iStorage. If it doesn't exist, load it.
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 CFotaStorage* CFotaServer::StoragePluginL()
       
   544     {
       
   545     if ( iStorage == NULL )
       
   546         {
       
   547         LoadStoragePluginL();
       
   548         }
       
   549     return iStorage;
       
   550     }
       
   551 
       
   552 
       
   553 // --------------------------------------------------------------------------
       
   554 // CFotaServer::LoadStoragePluginL 
       
   555 // Load update storage plugin via ecom framework.
       
   556 // --------------------------------------------------------------------------
       
   557 //
       
   558 void CFotaServer::LoadStoragePluginL ()
       
   559     {
       
   560     FLOG(_L("CFotaServer::LoadStoragePluginL"));
       
   561     if(iStorage)
       
   562         {
       
   563         UnLoadStoragePluginL ();
       
   564         }
       
   565     TUid                if_uid;
       
   566     if_uid.iUid = ( KStorageIFUid );
       
   567     RImplInfoPtrArray   pluginArray;
       
   568     REComSession::ListImplementationsL( if_uid, pluginArray );
       
   569     CleanupClosePushL( pluginArray );
       
   570 
       
   571     if( pluginArray.Count() )
       
   572         {
       
   573         for( TInt i = 0; i < pluginArray.Count(); i++ )
       
   574             {
       
   575             CImplementationInformation* info = pluginArray[ i ];
       
   576             TUid id = info->ImplementationUid();
       
   577             delete info;
       
   578             info = NULL;
       
   579             iStorage =(CFotaStorage*) REComSession::CreateImplementationL( id
       
   580                                         ,iStorageDtorKey); 
       
   581             }
       
   582         }
       
   583     else
       
   584         {
       
   585         FLOG(_L("  storage plugin not found, ERROR"));
       
   586         User::Leave ( KErrNotFound );
       
   587         }
       
   588     CleanupStack::PopAndDestroy( &pluginArray );
       
   589     }
       
   590 
       
   591 // --------------------------------------------------------------------------
       
   592 // CFotaServer::UnLoadStoragePluginL
       
   593 // Unloads storage plugin
       
   594 // --------------------------------------------------------------------------
       
   595 //
       
   596 void CFotaServer::UnLoadStoragePluginL ()
       
   597     {
       
   598     FLOG(_L("CFotaServer::UnLoadStoragePluginL"));
       
   599     if ( iStorage ) 
       
   600         {
       
   601         delete iStorage;
       
   602         iStorage=NULL;
       
   603         }
       
   604     FLOG(_L("    destroying"));
       
   605     REComSession::DestroyedImplementation(iStorageDtorKey); // zeroes referenc
       
   606                                                             // count of plugin
       
   607     FLOG(_L("    finalclosing"));
       
   608     REComSession::FinalClose();
       
   609     }
       
   610 
       
   611 
       
   612 // --------------------------------------------------------------------------
       
   613 // StaticDoFinalizeUpdate
       
   614 // Intermediate function
       
   615 // --------------------------------------------------------------------------
       
   616 static TInt StaticDoFinalizeUpdate(TAny *aPtr)
       
   617     {
       
   618     FLOG(_L("[cfotaserver] StaticDoFinalizeUpdate() >>"));
       
   619     CFotaServer* srv = (CFotaServer*) aPtr;
       
   620     TRAPD( err,  srv->DoFinalizeUpdateL() );
       
   621     if(err)
       
   622         {
       
   623         FLOG(_L("[cfotaserver] StaticDoFinalizeUpdate ERROR %d"),err);
       
   624         }
       
   625 
       
   626     FLOG(_L("[cfotaserver] StaticDoFinalizeUpdate() <<"));
       
   627     return err;
       
   628     }
       
   629 
       
   630 
       
   631 // --------------------------------------------------------------------------
       
   632 // CFotaServer::FinalizeUpdate()
       
   633 // Initialize finalization of updater
       
   634 // --------------------------------------------------------------------------
       
   635 //
       
   636 void CFotaServer::FinalizeUpdateL()
       
   637     {
       
   638     FLOG(_L("CFotaServer::FinalizeUpdate() >>"));
       
   639     if ( iUpdateFinalizer )
       
   640         {
       
   641         iUpdateFinalizer->Cancel();
       
   642         delete iUpdateFinalizer;
       
   643         iUpdateFinalizer=NULL;
       
   644         }
       
   645     iUpdateFinalizer = CPeriodic::NewL (EPriorityNormal) ;
       
   646     iUpdateFinalizer->Start (
       
   647                 TTimeIntervalMicroSeconds32(KDownloadFinalizerWaitTime)
       
   648                 ,TTimeIntervalMicroSeconds32(KDownloadFinalizerWaitTime)
       
   649                 ,TCallBack(StaticDoFinalizeUpdate,this) ) ;
       
   650     FLOG(_L("CFotaServer::FinalizeUpdate() <<"));
       
   651     }
       
   652 
       
   653 
       
   654 // --------------------------------------------------------------------------
       
   655 // CFotaServer::DoFinalizeUpdateL
       
   656 // Finalize update. Free resources
       
   657 // --------------------------------------------------------------------------
       
   658 //
       
   659 void CFotaServer::DoFinalizeUpdateL()
       
   660     {
       
   661     FLOG(_L("CFotaServer::DoFinalizeUpdateL() >>"));
       
   662 
       
   663     // Free resources
       
   664     FLOG(_L("iupdater = %d"), iUpdater);
       
   665     if ( iUpdater ) 
       
   666         {
       
   667         FLOG(_L("Deleting iupdater..."));
       
   668         iUpdater->Cancel();
       
   669         delete iUpdater; 
       
   670         iUpdater=NULL;
       
   671         }
       
   672     
       
   673     if ( iUpdateFinalizer ) 
       
   674         {
       
   675         iUpdateFinalizer->Cancel();
       
   676         }
       
   677     // Hide UI
       
   678     iParentApp->SetUIVisibleL ( EFalse, ETrue );
       
   679     FLOG(_L("CFotaServer::DoFinalizeUpdateL() <<"));
       
   680     }
       
   681 
       
   682 
       
   683 // --------------------------------------------------------------------------
       
   684 // StaticDoFinalizeDownload
       
   685 // Intermediate function
       
   686 // --------------------------------------------------------------------------
       
   687 static TInt StaticDoFinalizeDownload(TAny *aPtr)
       
   688     {
       
   689     FLOG(_L("[cfotaserver] StaticDoFinalizeDownload() >>"));
       
   690     CFotaServer* srv = (CFotaServer*) aPtr;
       
   691     TRAPD( err,  srv->DoFinalizeDownloadL() );
       
   692     if(err)
       
   693         {
       
   694         FLOG(_L("[cfotaserver] StaticDoFinalizeDownload ERROR %d"),err);
       
   695         }
       
   696 
       
   697     FLOG(_L("[cfotaserver] StaticDoFinalizeDownload() <<"));
       
   698     return err;
       
   699     }
       
   700 
       
   701 
       
   702 // --------------------------------------------------------------------------
       
   703 // CFotaServer::FinalizeDownload
       
   704 // Initialize finalization of download
       
   705 // --------------------------------------------------------------------------
       
   706 //
       
   707 void CFotaServer::FinalizeDownloadL( const TPackageState& aDLState )
       
   708     {
       
   709     FLOG(_L("CFotaServer::FinalizeDownload() >> state:%d result:%d")
       
   710                 ,aDLState.iState, aDLState.iResult);
       
   711     __ASSERT_ALWAYS( iDownloader, User::Panic(KFotaPanic, KErrBadHandle ));
       
   712     
       
   713     SetStartupReason(EFotaDefault);
       
   714           
       
   715     if ( iDownloadFinalizer )
       
   716         {
       
   717         iDownloadFinalizer->Cancel();
       
   718         delete iDownloadFinalizer;
       
   719         iDownloadFinalizer=NULL;
       
   720         }
       
   721     iDownloadFinalizer = CPeriodic::NewL (EPriorityMuchMore) ;
       
   722     iDLFinalizeState = aDLState;
       
   723     
       
   724     // Not restarting,quick finalize
       
   725     if ( iDownloader->iRestartCounter<=0 )
       
   726         {
       
   727         iDownloadFinalizer->Start(
       
   728                         TTimeIntervalMicroSeconds32(KDownloadFinalizerWaitTime)
       
   729                         ,TTimeIntervalMicroSeconds32(KDownloadFinalizerWaitTime)
       
   730                         ,TCallBack(StaticDoFinalizeDownload,this) ) ;
       
   731         }
       
   732     // Restarting, wait some time
       
   733     else
       
   734         {
       
   735         iDownloadFinalizer->Start(
       
   736                         TTimeIntervalMicroSeconds32(2000000)
       
   737                         ,TTimeIntervalMicroSeconds32(2000000)
       
   738                         ,TCallBack(StaticDoFinalizeDownload,this) ) ;
       
   739         }
       
   740     FLOG(_L("CFotaServer::FinalizeDownload() <<"));
       
   741     }
       
   742 
       
   743 
       
   744 // --------------------------------------------------------------------------
       
   745 // CFotaServer::DoFinalizeDownloadL
       
   746 // Finalize download. Free resources
       
   747 // --------------------------------------------------------------------------
       
   748 //
       
   749 void CFotaServer::DoFinalizeDownloadL()
       
   750     {
       
   751     FLOG(_L("CFotaServer::DoFinalizeDownloadL() >> state:%d result:%d")
       
   752             ,iDLFinalizeState.iState, iDLFinalizeState.iResult );
       
   753     __ASSERT_ALWAYS( iDownloader, User::Panic(KFotaPanic, KErrBadHandle ));
       
   754     
       
   755     if ( iDownloadFinalizer ) 
       
   756         {
       
   757         iDownloadFinalizer->Cancel();
       
   758         }
       
   759 
       
   760     if (iDownloader->iDLState.iState == RFotaEngineSession::EDownloadFailed)
       
   761         StoragePluginL()->DeleteUpdatePackageL ( iDownloader->iDLState.iPkgId );
       
   762         
       
   763     // Download not to be restarted, delete
       
   764     if ( iDownloader->iRestartCounter<=0 )
       
   765         {
       
   766         // Set downloader's ending state to DB
       
   767         iDatabase->OpenDBL();
       
   768         iDatabase->SetStateL(iDLFinalizeState
       
   769                             ,KNullDesC8,EFDBState|EFDBResult);
       
   770         iDatabase->CloseAndCommitDB();
       
   771 
       
   772         iDownloader->SetDownloadActive(EFalse);
       
   773         iParentApp->SetUIVisibleL( EFalse,ETrue);
       
   774 
       
   775         // Initiate update 
       
   776         if ( iDownloader && iDownloader->iUpdateAfterDownload )
       
   777             {
       
   778             UpdateL( iDownloader->iDLState );  
       
   779             }
       
   780         // Report status to DM server
       
   781         else
       
   782             {
       
   783             if (iDownloader->iDLState.iState == RFotaEngineSession::EDownloadProgressingWithResume )
       
   784             	{
       
   785             	if (iDownloader->IsFMSEnabled())
       
   786                 	{
       
   787                 	FLOG(_L("Invoking FMS..."));
       
   788                 	InvokeFmsL();
       
   789                 	SetStartupReason(EFotaDownloadInterrupted);
       
   790                 	}
       
   791             	}
       
   792             else
       
   793             	{
       
   794             	CreateDeviceManagementSessionL( iDownloader->iDLState );
       
   795             	}
       
   796             }
       
   797 
       
   798         // Free resources
       
   799         if ( iDownloader ) 
       
   800             {
       
   801             iDownloader->Cancel();
       
   802 			iDownloader->CancelDownload (ETrue);
       
   803             delete iDownloader; 
       
   804             iDownloader=NULL;
       
   805             }
       
   806         TInt val (EFalse);
       
   807         TInt err = RProperty::Get(TUid::Uid(KOmaDMAppUid), KFotaDMRefresh, val );
       
   808         if (val!=EFalse)
       
   809         	err = RProperty::Set(TUid::Uid(KOmaDMAppUid), KFotaDMRefresh, EFalse );
       
   810         FLOG(_L("RProperty KFotaDMRefresh EFalse, err = %d"), err);
       
   811         }
       
   812     // Download to be restarted
       
   813     else
       
   814         {
       
   815         __ASSERT_ALWAYS( iDownloader->iUrl
       
   816                 ,User::Panic(KFotaPanic, KErrBadHandle ));
       
   817         FLOG(_L(" Restarting download(iRestartCounter %d)"),iDownloader->iRestartCounter);
       
   818 
       
   819         // Reuse url and iapid
       
   820         HBufC8* url = iDownloader->iUrl->AllocLC();
       
   821         TInt    iapid = iDownloader->iDLState.iIapId;
       
   822 
       
   823         TBool   update= iDownloader->iUpdateAfterDownload;
       
   824         TInt    restart=iDownloader->iRestartCounter;
       
   825         
       
   826         iDownloader->CancelDownload( EFalse ); //Doesn't actually deletes downloads when S&R feature is supported.
       
   827       
       
   828         iDownloader->DownloadL( iDLFinalizeState , *url,update,iapid, restart);
       
   829         CleanupStack::PopAndDestroy( url );
       
   830         }
       
   831 
       
   832 
       
   833     FLOG(_L("CFotaServer::DoFinalizeDownloadL() <<"));
       
   834     }
       
   835 
       
   836 
       
   837 // --------------------------------------------------------------------------
       
   838 // StaticDoCloseSMLSession 
       
   839 // Intermediate function
       
   840 // --------------------------------------------------------------------------
       
   841 static TInt StaticDoCloseSMLSession ( TAny *aPtr )
       
   842     {
       
   843     FLOG(_L("[cfotaserver] StaticDoCloseSMLSession() >>"));
       
   844     CFotaServer* srv = (CFotaServer*) aPtr;
       
   845     TRAPD( err,  srv->DoCloseSMLSessionL() );
       
   846     if(err)
       
   847         {
       
   848         FLOG(_L("[cfotaserver] StaticDoCloseSMLSession ERROR %d"),err);
       
   849         }
       
   850 
       
   851     FLOG(_L("[cfotaserver] StaticDoCloseSMLSession() <<"));
       
   852     return err;
       
   853     }
       
   854 
       
   855 // --------------------------------------------------------------------------
       
   856 // CFotaServer::DoCloseSMLSessionL
       
   857 // Close syncml session, or resync
       
   858 // --------------------------------------------------------------------------
       
   859 //
       
   860 void CFotaServer::DoCloseSMLSessionL()
       
   861     {
       
   862     FLOG(_L("CFotaServer::DoCloseSMLSessionL() >>"));
       
   863 
       
   864     // Must still try to sync
       
   865     if ( iSyncMLAttempts > 0 )
       
   866         {
       
   867         FLOG(_L("   trycount %d => creating new job"),iSyncMLAttempts);
       
   868 	    RSyncMLDevManJob    dmJob;
       
   869     	if(iIapId > KErrNotFound)
       
   870     		{
       
   871     		FLOG(_L("DoCloseSMLSessionL new job uses iap from fotadb %d"),
       
   872     				iIapId);
       
   873     		dmJob.CreateL( iSyncMLSession, iSyncProfile,iIapId );
       
   874     		}
       
   875     	else
       
   876     		{
       
   877     		FLOG(_L("DoCloseSMLSessionL new job uses iap from profile"));
       
   878     		dmJob.CreateL( iSyncMLSession, iSyncProfile );
       
   879     		}
       
   880 			iSyncMLAttempts--;
       
   881 			iSyncJobId = dmJob.Identifier();
       
   882 	    dmJob.Close();
       
   883         }
       
   884     else 
       
   885     // We ran out of attempts, close sml
       
   886         {
       
   887         if ( iSyncMLSession.Handle() ) 
       
   888             {
       
   889             FLOG(_L("   Closing syncml session"));
       
   890             iSyncMLSession.CancelEvent();
       
   891             iSyncMLSession.Close();
       
   892             }
       
   893         } 
       
   894 
       
   895     if ( iTimedSMLSessionClose ) 
       
   896         {
       
   897         FLOG(_L("   closing smlsession timer"));
       
   898         iTimedSMLSessionClose->Cancel();
       
   899         delete iTimedSMLSessionClose;
       
   900         iTimedSMLSessionClose = NULL;
       
   901         }
       
   902 
       
   903     FLOG(_L("CFotaServer::DoCloseSMLSessionL() <<"));
       
   904     }
       
   905 
       
   906 
       
   907 // --------------------------------------------------------------------------
       
   908 // CFotaServer::ReadChunkL
       
   909 // Read data from chunk created by client.
       
   910 // --------------------------------------------------------------------------
       
   911 //
       
   912 void CFotaServer::ReadChunkL( const TInt aSize,TInt aError )
       
   913 	{
       
   914     __ASSERT_ALWAYS( aSize>=0 , User::Panic(KFotaPanic, KErrArgument) );
       
   915     TUint8* b = iChunk.Base();
       
   916     TPtr8   data(b, aSize, aSize );
       
   917 
       
   918     iStorage->iBytesWritten += aSize;
       
   919     FLOG(_L("     CFotaServer::ReadChunkL  >>  reading %d bytes"),aSize);
       
   920     if (iStorageStream && aError !=KErrServerTerminated &&
       
   921     		aError !=KErrDiskFull )
       
   922        {FLOG(_L("     CFotaServer::ReadChunkL  >>  inside if(iStorageStream)"));
       
   923        TRAPD ( err, iStorageStream->WriteL(data) );
       
   924 
       
   925        if ( !err ) 
       
   926            {
       
   927            iStorageStream->CommitL();
       
   928            }
       
   929        else
       
   930     	  {
       
   931           FLOG(_L("Error when writing pkg %d"), err);
       
   932           iStorageStream->Close();
       
   933           iStorageStream = NULL;
       
   934           User::Leave ( err );
       
   935           }
       
   936        }  
       
   937     FLOG(_L("     CFotaServer::ReadChunkL  << "));
       
   938     }
       
   939 
       
   940 
       
   941 // --------------------------------------------------------------------------
       
   942 // CFotaServer::OpenUpdatePackageStoreL 
       
   943 // Opens package store. Calling chain in case of oma DL:  
       
   944 // fotaserver->downloadmgr->codhandler->fotaserver  (subject to change, 
       
   945 // depending on downloadmgr&codhandler changes)
       
   946 // Fotaadapter calls this function in direct way: fotaadapter->fotaserver
       
   947 //
       
   948 // --------------------------------------------------------------------------
       
   949 //
       
   950 void CFotaServer::OpenUpdatePackageStoreL ( const RMessage2& aMessage )
       
   951     {
       
   952     FLOG(_L("CFotaServer::OpenUpdatePackageStoreL  >>"));
       
   953 
       
   954     // If chunk is already open, bail out
       
   955     THandleInfo     info;
       
   956     TInt            pkgid;
       
   957     iChunk.HandleInfo(&info);
       
   958     
       
   959      
       
   960     if(info.iNumOpenInProcess>0)
       
   961         {
       
   962         FLOG(_L("CFotaServer::SetChunkHandleL  chunk is open %d times by \
       
   963             current process (%d times in thread)"),info.iNumOpenInProcess
       
   964             ,info.iNumOpenInThread);
       
   965         User::Leave(KErrInUse);
       
   966         }
       
   967 
       
   968     // Set package state 
       
   969     pkgid = aMessage.Int0();
       
   970     iStorageDownloadPackageId = pkgid;
       
   971 
       
   972     TPackageState   state = GetStateL(pkgid);
       
   973 
       
   974     // AS  16.02.05: must be in failed state until complete
       
   975 
       
   976     FLOG(_L("CFotaServer::OpenUpdatePackageStoreL  opening update pkg storage\
       
   977                 ffor pkgid: %d "),pkgid);
       
   978 
       
   979     TInt size2 = state.iPkgSize;
       
   980     // Use storage api to save update pkg 
       
   981     StoragePluginL()->OpenUpdatePackageStoreL(pkgid,size2, iStorageStream);
       
   982 
       
   983     User::LeaveIfError( iChunk.Open(aMessage,1,EFalse) );
       
   984 	TInt err = RProperty::Define( TUid::Uid(KFotaServerUid),
       
   985 					KFotaLrgObjDl,RProperty::EInt,
       
   986 					KReadPolicy,  KWritePolicy );
       
   987 	TInt    err1 = RProperty::Set( TUid::Uid(KFotaServerUid),
       
   988 			KFotaLrgObjDl, KErrNotFound );
       
   989 	FLOG(_L("CFotaServer::OpenUpdatePackageStoreL err for KFotaLrgObjDl define is %d err is %d"),
       
   990 			err,err1 );  
       
   991 	err = RProperty::Define( TUid::Uid(KFotaServerUid),
       
   992 				KFotaLrgObjProfileId,RProperty::EInt,
       
   993 				KReadPolicy,KWritePolicy );
       
   994 	err1 = RProperty::Set( TUid::Uid(KFotaServerUid),
       
   995 						KFotaLrgObjProfileId, KErrNotFound );
       
   996 	FLOG(_L("CFotaServer::OpenUpdatePackageStoreL err for KFotaLrgObjProfileId define is %d err is %d"),
       
   997 			err,err1 );  
       
   998     FLOG(_L("CFotaServer::OpenUpdatePackageStoreL  <<"));
       
   999     }
       
  1000 
       
  1001 // --------------------------------------------------------------------------
       
  1002 // CFotaServer::GetDownloadUpdatePackageSizeL 
       
  1003 // Gets the downloaded update package size in bytes
       
  1004 // --------------------------------------------------------------------------
       
  1005 //
       
  1006 void CFotaServer::GetDownloadUpdatePackageSizeL (const TInt aPkgId, TInt& aDownloadedSize, TInt& aTotalSize)
       
  1007 	{
       
  1008 	FLOG(_L("CFotaServer::GetDownloadUpdatePackageSize, aPkgId = %d  >>"),aPkgId);
       
  1009 	TPackageState temp;
       
  1010 
       
  1011 	//Getting the total package size from database.
       
  1012 	iDatabase->OpenDBL();
       
  1013 	temp = iDatabase->GetStateL(aPkgId);
       
  1014 	iDatabase->CloseAndCommitDB();
       
  1015 	
       
  1016 	FLOG(_L("fota state for given pkg id is = %d"),temp.iState);
       
  1017 	if (temp.iState == RFotaEngineSession::EDownloadProgressing
       
  1018 			|| temp.iState == RFotaEngineSession::EDownloadProgressingWithResume
       
  1019 			|| temp.iState == RFotaEngineSession::EDownloadComplete
       
  1020 			|| temp.iState == RFotaEngineSession::EStartingUpdate)
       
  1021 		{
       
  1022 		aTotalSize = temp.iPkgSize;
       
  1023 		//Getting the downloaded update package size from storage pluggin.
       
  1024 		StoragePluginL()->GetDownloadedUpdatePackageSizeL(aPkgId, aDownloadedSize);
       
  1025 		}
       
  1026 	else
       
  1027 		{
       
  1028 		FLOG(_L("No progressing/suspended/completed download corresponding to the given pkgid (%d)"),aPkgId);
       
  1029 		User::Leave (KErrNotFound);
       
  1030 		}
       
  1031 
       
  1032 	
       
  1033 	FLOG(_L("CFotaServer::GetDownloadUpdatePackageSize, aDownloadedSize = %d, aTotalSize = %d  <<"),aDownloadedSize, aTotalSize);
       
  1034 	}
       
  1035 
       
  1036 // --------------------------------------------------------------------------
       
  1037 // CFotaServer::TryResumeDownloadL 
       
  1038 // Tries to resume the download operation
       
  1039 // --------------------------------------------------------------------------
       
  1040 //
       
  1041 void CFotaServer::TryResumeDownloadL(TBool aUserInitiated)
       
  1042 	{
       
  1043 	FLOG(_L("CFotaServer::TryResumeDownloadL, aUserInitiated = %d  >>"),aUserInitiated);
       
  1044 	//Check whether there is a paused resume actually.
       
  1045 	if(aUserInitiated)
       
  1046 	    iUserResume = ETrue;
       
  1047 	else
       
  1048 	    iUserResume = EFalse;
       
  1049 	TPackageState temp = GetStateL(-1); //Gets the state of the current/last fota download
       
  1050 	iSessMode = temp.iSessionType;
       
  1051 	FLOG(_L("iSessMode = %d ,temp.iSessionType=%d  "),iSessMode,
       
  1052 	            temp.iSessionType);	
       
  1053 	if ( temp.iState != RFotaEngineSession::EDownloadProgressingWithResume )
       
  1054 		{
       
  1055 		FLOG(_L("There are no paused downloads currently; hence leaving with KErrNotFound..."));
       
  1056 		User::Leave (KErrNotFound);
       
  1057 		}
       
  1058 
       
  1059 	//Resume download now
       
  1060     if(!iDownloader)
       
  1061         {
       
  1062         FLOG(_L("Creating new idownloader"));
       
  1063         iDownloader = CFotaDownload::NewL( this );
       
  1064         }
       
  1065     if (iDownloader->IsDownloadActive())
       
  1066     	{
       
  1067     	FLOG(_L("Another download is already active, hence returning..."));
       
  1068     	User::Leave (KErrAlreadyExists);
       
  1069     	}
       
  1070     iDownloader->iDLState = temp;
       
  1071 	SetStartupReason(EFotaDownloadInterrupted);
       
  1072     iDownloader->TryResumeDownloadL(aUserInitiated);
       
  1073 	
       
  1074 	FLOG(_L("CFotaServer::TryResumeDownloadL  <<"));
       
  1075 	}
       
  1076 
       
  1077 // --------------------------------------------------------------------------
       
  1078 // CFotaServer::InvokeFmsL 
       
  1079 // Starts Fota Monitory Service with relevant parameters for monitoring.
       
  1080 // --------------------------------------------------------------------------
       
  1081 //
       
  1082 void CFotaServer::InvokeFmsL()
       
  1083 	{
       
  1084 	FLOG(_L("CFotaServer::InvokeFmsL  >>"));
       
  1085 	//Collect all information needed to invoke FMS.
       
  1086 	TPackageState temp = GetStateL(iDownloader->iDLState.iPkgId);
       
  1087 	FLOG(_L("State as recorded in fota db:"));
       
  1088 	FLOG(_L("iPkgId = %d"),temp.iPkgId);
       
  1089 	FLOG(_L("iProfileId = %d"),temp.iProfileId);
       
  1090 	FLOG(_L("iPkgName = %S"),&temp.iPkgName);
       
  1091 	FLOG(_L("iPkgVersion = %S"),&temp.iPkgVersion);
       
  1092 	FLOG(_L("iSendAlert = %d"),temp.iSendAlert);
       
  1093 	FLOG(_L("iIapId = %d"),temp.iIapId);
       
  1094 	FLOG(_L("iPkgSize = %d"),temp.iPkgSize);
       
  1095 	FLOG(_L("iSessionType = %d"),temp.iSessionType);
       
  1096 	FLOG(_L("iState = %d"),temp.iState);
       
  1097 	FLOG(_L("iResult = %d"),temp.iResult);
       
  1098 	
       
  1099 	
       
  1100 	//Finding the reason for download interrupt
       
  1101 	TOmaDLInterruptReason reason (EGeneralInterrupt); // 3
       
  1102 	
       
  1103 	switch (iDownloader->iDLState.iResult)
       
  1104 	{
       
  1105 	case RFotaEngineSession::EResUserCancelled:
       
  1106 		{
       
  1107 		reason = EUserInterrupt; //0
       
  1108 		break;
       
  1109 		}
       
  1110 	case RFotaEngineSession::EResDLFailDueToNWIssues:
       
  1111 		{
       
  1112 		reason = ENetworkInterrupt; //1
       
  1113 		break;
       
  1114 		}
       
  1115 	case RFotaEngineSession::EResDLFailDueToDeviceOOM:
       
  1116 		{
       
  1117 		reason = EMemoryInterrupt;   //2
       
  1118 		break;
       
  1119 		}
       
  1120 	default:
       
  1121 		{
       
  1122 		//reason is already EGeneralInterrupt
       
  1123 		break;
       
  1124 		}
       
  1125 	}
       
  1126 	//FotaState has the last successfully worked IAP. Hence use this for FMS monitoring.
       
  1127 //	TInt apid = iDownloader->iDLState.iIapId;
       
  1128 	TInt apid = temp.iIapId;
       
  1129 	
       
  1130 	//Finding the drive number
       
  1131 	TBuf8<KMaxPath> path8;
       
  1132 	path8.Zero();
       
  1133 	StoragePluginL()->GetUpdatePackageLocationL(iDownloader->iDLState.iPkgId, path8);
       
  1134 	TPath path16;
       
  1135 	path16.Copy(path8);
       
  1136 
       
  1137 
       
  1138     TInt drive (EDriveC ); //Default drive is Phone Memory
       
  1139 	TParse p;
       
  1140     if (!p.Set(path16,NULL,NULL))
       
  1141     	{
       
  1142     	TDriveName drivename(p.Drive());
       
  1143     	TDriveUnit driveunit(drivename);
       
  1144     	if (iFs.IsValidDrive((TInt) driveunit))
       
  1145     		drive = driveunit;
       
  1146     	}
       
  1147     else
       
  1148     	{
       
  1149     	FLOG(_L("Error while parsing for drive number! defaulting to Phone Memory (C)"));
       
  1150     	}
       
  1151 
       
  1152     TInt dlsize, tsize;
       
  1153     GetDownloadUpdatePackageSizeL(iDownloader->iDLState.iPkgId, dlsize, tsize);
       
  1154 	TInt neededsize = tsize - dlsize;
       
  1155 	FLOG(_L("Launching FMS with params... reason = %d, iapid = %d, drive = %d, neededsize = %d"),reason, apid, drive, neededsize);
       
  1156 	iFMSClient.OpenL();
       
  1157 	iFMSClient.NotifyForResumeL( reason, apid, (TDriveNumber)drive, neededsize );
       
  1158 	iFMSClient.Close();
       
  1159 	
       
  1160 	FLOG(_L("CFotaServer::InvokeFmsL  <<"));
       
  1161 	}
       
  1162 
       
  1163 // --------------------------------------------------------------------------
       
  1164 // CFotaServer::CancelFmsL 
       
  1165 // Cancels any outstanding monitoring requests in Fota Monitory Service
       
  1166 // --------------------------------------------------------------------------
       
  1167 //
       
  1168 void CFotaServer::CancelFmsL()
       
  1169 	{
       
  1170 	FLOG(_L("CFotaServer::CancelFmsL  >>"));
       
  1171 	
       
  1172 	iFMSClient.OpenL();
       
  1173 	iFMSClient.CancelNotifyForResume();
       
  1174 	iFMSClient.Close();
       
  1175 	
       
  1176 	FLOG(_L("CFotaServer::CancelFmsL  <<"));
       
  1177 	}
       
  1178 
       
  1179 // --------------------------------------------------------------------------
       
  1180 // CFotaServer::SetStartupReason 
       
  1181 // Sets the startup reason for Fota. This is used in Fota Startup pluggin.
       
  1182 // --------------------------------------------------------------------------
       
  1183 //
       
  1184 void CFotaServer::SetStartupReason(TInt aReason)
       
  1185 	{
       
  1186 	FLOG(_L("CFotaServer::SetStartupReason, aReason = %d  >>"), aReason);
       
  1187 	
       
  1188 	CRepository* centrep = NULL;
       
  1189     TRAPD( err, centrep = CRepository::NewL( KCRUidFotaServer ) )
       
  1190     if (err==KErrNone ) 
       
  1191     	{
       
  1192          centrep->Set(  KFotaUpdateState, aReason );
       
  1193         }
       
  1194     delete centrep;
       
  1195     centrep = NULL;
       
  1196 
       
  1197 	FLOG(_L("CFotaServer::SetStartupReason  <<"));
       
  1198 	}
       
  1199 
       
  1200 // --------------------------------------------------------------------------
       
  1201 // CFotaServer::~CFotaServer()
       
  1202 // Frees database, download, chunk, filewriter, etc resources
       
  1203 // --------------------------------------------------------------------------
       
  1204 //
       
  1205 CFotaServer::~CFotaServer()
       
  1206 	{
       
  1207     FLOG(_L("CFotaServer::~CFotaServer  >>"));
       
  1208 
       
  1209     if(iDatabase)
       
  1210         {
       
  1211         iDatabase->CloseAndCommitDB();
       
  1212         delete iDatabase;
       
  1213         iDatabase = NULL;
       
  1214         }
       
  1215 
       
  1216     if(iDownloader)
       
  1217         {
       
  1218         iDownloader->Cancel();
       
  1219         delete iDownloader;
       
  1220         iDownloader = NULL;
       
  1221         }
       
  1222 
       
  1223     if(iUpdater)
       
  1224         {
       
  1225         iUpdater->Cancel();
       
  1226         delete iUpdater;
       
  1227         iUpdater = NULL;
       
  1228         }
       
  1229 
       
  1230     if(iDownloadFinalizer) 
       
  1231         {
       
  1232         iDownloadFinalizer->Cancel();
       
  1233         delete iDownloadFinalizer;
       
  1234         iDownloadFinalizer = NULL;
       
  1235         }
       
  1236 
       
  1237     if(iUpdateFinalizer)
       
  1238         {
       
  1239         iUpdateFinalizer->Cancel();
       
  1240         delete iUpdateFinalizer;
       
  1241         iUpdateFinalizer = NULL;
       
  1242         }
       
  1243 
       
  1244     if ( iTimedExecuteResultFile ) 
       
  1245         {
       
  1246         iTimedExecuteResultFile->Cancel();
       
  1247         delete iTimedExecuteResultFile;
       
  1248         iTimedExecuteResultFile = NULL;
       
  1249         }
       
  1250 
       
  1251     if ( iAppShutter )
       
  1252         {
       
  1253         iAppShutter->Cancel();
       
  1254         delete iAppShutter;
       
  1255         iAppShutter=NULL;
       
  1256         }
       
  1257         
       
  1258     if ( iMonitor )    
       
  1259     	{
       
  1260     	delete iMonitor;
       
  1261     	iMonitor = NULL;
       
  1262     	}
       
  1263     //don't delete iEikEnv, fw will take care.
       
  1264     if (iChunk.Handle())
       
  1265     	iChunk.Close();
       
  1266     
       
  1267     if (iStorageStream) {
       
  1268     	TRAP_IGNORE(iStorageStream->CommitL());
       
  1269     	iStorageStream->Close();
       
  1270     	iStorageStream = NULL;
       
  1271     }
       
  1272     iSyncMLSession.Close();
       
  1273     TRAP_IGNORE( UnLoadStoragePluginL () );
       
  1274     iFs.Close();
       
  1275     
       
  1276     
       
  1277     if (iFMSClient.Handle())
       
  1278     	iFMSClient.Close();
       
  1279 
       
  1280 	if ( iNotifHandler ) 
       
  1281 		{
       
  1282 		iNotifHandler->Cancel();
       
  1283 		delete iNotifHandler;        
       
  1284 		}
       
  1285 	TInt err = RProperty::Delete(TUid::Uid(KFotaServerUid),
       
  1286     		KFotaLrgObjDl);
       
  1287     FLOG( _L( "CFotaServer::~CFotaServer err for KFotaLrgObjDl is %d " ),err );  
       
  1288     err = RProperty::Delete(TUid::Uid(KFotaServerUid),
       
  1289     		KFotaLrgObjDl);
       
  1290     FLOG( _L( "CFotaServer::~CFotaServer err for KFotaLrgObjProfileId is %d " ),err );  
       
  1291     err = RProperty::Delete(TUid::Uid(KFotaServerUid),
       
  1292     		KFotaLrgObjProfileId);    
       
  1293     
       
  1294     if (iDEController)
       
  1295         {
       
  1296         delete iDEController;
       
  1297         iDEController = NULL;
       
  1298         }
       
  1299  
       
  1300 	FLOG(_L("CFotaServer::~CFotaServer  <<"));  
       
  1301 	}
       
  1302 
       
  1303 
       
  1304 // ---------------------------------------------------------------------------
       
  1305 // CFotaServer::UpdatePackageDownloadCompleteL
       
  1306 // Sets state and package streaming related objects. If this is child
       
  1307 // fotaserver (not largeobject), don't set state since parent fotaserver does
       
  1308 // it.
       
  1309 // ---------------------------------------------------------------------------
       
  1310 void CFotaServer::UpdatePackageDownloadCompleteL(TBool aLargObj
       
  1311                                                         , const TInt aPkgId)
       
  1312     {
       
  1313     FLOG(_L("CFotaServer::UpdatePackageDownloadCompleteL %d >>"),aPkgId);
       
  1314     TInt        pkgid(aPkgId);
       
  1315 
       
  1316     // Set state in case of lrg obj download 
       
  1317     // If not lrg ob download, calling app sets state
       
  1318     if (aLargObj)
       
  1319         {
       
  1320         TPackageState s;
       
  1321         s.iPkgId = aPkgId;
       
  1322         s.iState = RFotaEngineSession::EStartingUpdate;
       
  1323         iDatabase->OpenDBL();
       
  1324         iDatabase->SetStateL( s,KNullDesC8,EFDBState );
       
  1325         iDatabase->CloseAndCommitDB();
       
  1326         //To refresh in DM UI for OMA DM large object
       
  1327         TInt err = RProperty::Define( TUid::Uid(KOmaDMAppUid),
       
  1328 				KFotaDMRefresh,
       
  1329 				RProperty::EInt,KReadPolicy,KWritePolicy);
       
  1330 		FLOG(_L("CFotaServer::UpdatePackageDownloadCompleteL KFotaDMRefresh Define, err = %d")
       
  1331 														, err);        
       
  1332 		if (err != KErrAlreadyExists && err != KErrNone)
       
  1333 			{
       
  1334 			User::LeaveIfError(err);
       
  1335 			}
       
  1336 		//notify DM UI, EFalse indicates no Download going on 
       
  1337 		err = RProperty::Set( TUid::Uid(KOmaDMAppUid),
       
  1338 				KFotaDMRefresh,
       
  1339 				EFalse );
       
  1340 		FLOG(_L("RProperty KFotaDMRefresh Set ETrue, err = %d"), err);           
       
  1341         }
       
  1342     // Free resources
       
  1343     iChunk.Close();
       
  1344     iStorage->UpdatePackageDownloadCompleteL(pkgid);
       
  1345     FLOG(_L("CFotaServer::UpdatePackageDownloadCompleteL %d <<"),aPkgId);
       
  1346     }
       
  1347 
       
  1348 
       
  1349 // ---------------------------------------------------------------------------
       
  1350 // CFotaServer::DeletePackageL 
       
  1351 // Deletes update package from db
       
  1352 // ---------------------------------------------------------------------------
       
  1353 void CFotaServer::DeletePackageL ( const TInt aPkgId)
       
  1354     {
       
  1355     FLOG(_L("CFotaServer::DeletePackageL  >> id %d"),aPkgId );
       
  1356    // TInt err;
       
  1357 
       
  1358     StoragePluginL()->DeleteUpdatePackageL ( aPkgId );
       
  1359 //    User::LeaveIfError( err );
       
  1360     FLOG(_L("CFotaServer::DeletePackageL  <<") );
       
  1361     }
       
  1362 
       
  1363 
       
  1364 // ---------------------------------------------------------------------------
       
  1365 //  CFotaServer::DownloadL
       
  1366 //  Create package downloader and download update package.
       
  1367 // ---------------------------------------------------------------------------
       
  1368 void CFotaServer::DownloadL(TDownloadIPCParams aParams, const TDesC8& aPkgURL)
       
  1369     {
       
  1370     FLOG(_L("[FotaServer]  Download >>"));
       
  1371 
       
  1372     // If download already in progress, delete it
       
  1373     if ( iDownloader )
       
  1374         {
       
  1375         FLOG(_L("CFotaServer::DownloadL already downloading!"));
       
  1376         User::Leave (KErrAlreadyExists);
       
  1377         }
       
  1378     
       
  1379     if(!iDownloader)
       
  1380         {
       
  1381         iDownloader = CFotaDownload::NewL( this );
       
  1382         }
       
  1383         
       
  1384         TBuf<KSysVersionInfoTextLength> temp;
       
  1385     if (GetSoftwareVersion(temp) == KErrNone)
       
  1386         {
       
  1387         
       
  1388           RFileWriteStream    wstr;
       
  1389         	CleanupClosePushL ( wstr );
       
  1390         	TInt err1=wstr.Replace( iFs,KSWversionFile, EFileWrite  );
       
  1391         	if(err1==KErrNone)
       
  1392         	{
       
  1393            HBufC16*             swv;
       
  1394            swv = HBufC16::NewLC ( temp.Length() );
       
  1395            swv->Des().Copy( temp );
       
  1396            wstr.WriteInt16L( swv->Des().Length()); // length  
       
  1397            wstr.WriteL( swv->Des() );
       
  1398            wstr.WriteInt16L( 0 );
       
  1399            CleanupStack::PopAndDestroy( swv );
       
  1400                
       
  1401           }                           
       
  1402                                         
       
  1403         	CleanupStack::PopAndDestroy( &wstr ); // wstr      
       
  1404         }
       
  1405     
       
  1406     iDownloader->DownloadL(aParams,aPkgURL,EFalse);
       
  1407     FLOG(_L("[FotaServer]  Download <<"));
       
  1408     }
       
  1409 
       
  1410 
       
  1411 // --------------------------------------------------------------------------
       
  1412 // CFotaServer::DownloadAndUpdateL
       
  1413 // Downloads update package and updates fw
       
  1414 // --------------------------------------------------------------------------
       
  1415 //
       
  1416 void CFotaServer::DownloadAndUpdateL(TDownloadIPCParams aParams 
       
  1417                                             ,const TDesC8& aPkgURL)
       
  1418     {
       
  1419     FLOG(_L("CFotaServer::DownloadAndUpdateL >>"));
       
  1420 
       
  1421     // If download already in progress, delete it
       
  1422     if ( iDownloader )
       
  1423         {
       
  1424         FLOG(_L("CFotaServer::DownloadAndUpdateL already downloading!"));
       
  1425         User::Leave (KErrAlreadyExists);
       
  1426         }
       
  1427     if (!iDownloader)
       
  1428         {
       
  1429         iDownloader = CFotaDownload::NewL(this);
       
  1430         }
       
  1431         TBuf<KSysVersionInfoTextLength> temp;
       
  1432     if (GetSoftwareVersion(temp) == KErrNone)
       
  1433         {
       
  1434         	RFileWriteStream    wstr;
       
  1435         	CleanupClosePushL ( wstr );
       
  1436           TInt err = wstr.Replace( iFs ,KSWversionFile, EFileWrite );
       
  1437          if(err ==KErrNone) 
       
  1438           {
       
  1439           HBufC16*             swv;
       
  1440           swv = HBufC16::NewLC ( temp.Length( ) );
       
  1441           swv->Des().Copy( temp );
       
  1442           wstr.WriteInt16L( swv->Des().Length()); // length  
       
  1443           wstr.WriteL( swv->Des() );
       
  1444           wstr.WriteInt16L( 0 );
       
  1445           CleanupStack::PopAndDestroy( swv );
       
  1446                 
       
  1447           }       
       
  1448                                  
       
  1449          CleanupStack::PopAndDestroy( &wstr ); // wstr                                   
       
  1450         	
       
  1451         }
       
  1452     iDownloader->DownloadL( aParams,aPkgURL,ETrue );
       
  1453     FLOG(_L("CFotaServer::DownloadAndUpdateL <<"));
       
  1454     }
       
  1455 
       
  1456 // --------------------------------------------------------------------------
       
  1457 // CFotaServer::UpdateL
       
  1458 // Start update 
       
  1459 // --------------------------------------------------------------------------
       
  1460 //
       
  1461 void CFotaServer::UpdateL( const TDownloadIPCParams &aParams )
       
  1462     {
       
  1463     FLOG(_L("CFotaServer::UpdateL  >>"));
       
  1464     
       
  1465      TBool isPkgvalid(ETrue);
       
  1466      isPkgvalid = CheckSWVersionL();
       
  1467       
       
  1468     if (isPkgvalid)
       
  1469         {
       
  1470         	
       
  1471         FLOG(_L("CFotaServer::UpdateL  package is valid >>"));	
       
  1472         if(!iUpdater)
       
  1473             {
       
  1474             iUpdater = CFotaUpdate::NewL(this);
       
  1475             }
       
  1476         iUpdater->StartUpdateL( aParams );
       
  1477         }
       
  1478     else
       
  1479         {
       
  1480         FLOG(_L("IMPORTANT:: Firmware version mismatch! Resetting fota state"));
       
  1481         ResetFotaStateL(aParams);
       
  1482         }
       
  1483        
       
  1484         FLOG(_L("CFotaServer::UpdateL  <<"));  
       
  1485     }
       
  1486 
       
  1487 
       
  1488 
       
  1489 // --------------------------------------------------------------------------
       
  1490 // CFotaServer::CheckSWVersionL
       
  1491 // Check the s/w version
       
  1492 // --------------------------------------------------------------------------
       
  1493 //
       
  1494 
       
  1495 TBool CFotaServer::CheckSWVersionL()
       
  1496 
       
  1497 {
       
  1498 	
       
  1499 	
       
  1500 	  FLOG(_L("CFotaServer::CheckSWVersionL  >>"));  
       
  1501 	 TBuf<KSysVersionInfoTextLength> temp;
       
  1502     HBufC16*            message16=NULL;
       
  1503     TBool isPkgvalid(ETrue);
       
  1504     if (GetSoftwareVersion(temp) == KErrNone)
       
  1505         {
       
  1506           
       
  1507          //TBuf<KSysVersionInfoTextLength>swvfromfile;
       
  1508         //Fetch the software version ...
       
  1509         RFileReadStream     rstr;
       
  1510         TInt err1=rstr.Open(iFs,KSWversionFile ,EFileRead);
       
  1511         if(err1== KErrNone)
       
  1512         {
       
  1513          CleanupClosePushL( rstr );
       
  1514          TInt msglen = rstr.ReadInt16L(); 
       
  1515          if(msglen > 0)
       
  1516          { 
       
  1517           	message16         = HBufC16::NewLC(msglen + 1);
       
  1518         	 TPtr16 tempswv = message16->Des();
       
  1519         	 TRAPD(err, rstr.ReadL(tempswv,msglen ));
       
  1520         	        
       
  1521            if ( err != KErrNone && err != KErrEof)
       
  1522             {
       
  1523              FLOG(_L("  file read err %d"),err); //User::Leave( err ); 
       
  1524               msglen =0;
       
  1525             }
       
  1526            else
       
  1527            { 
       
  1528             FLOG(_L("  msglen  %d"),msglen); 
       
  1529             TPtr swvfromfile = message16->Des();
       
  1530                      
       
  1531             FLOG(_L("  swvfromfile=%S"),message16); 
       
  1532             
       
  1533              //Compare the software versions to decide whether the download is still valid or not.
       
  1534               if (msglen != temp.Length() || temp.Compare(tempswv)!=KErrNone)
       
  1535               {
       
  1536         	     isPkgvalid = EFalse;
       
  1537         	      FLOG(_L("CFotaServer::software not matching  >>"));
       
  1538         	
       
  1539               }
       
  1540             } 
       
  1541           
       
  1542              CleanupStack::PopAndDestroy( message16 );
       
  1543          }    
       
  1544             CleanupStack::PopAndDestroy( &rstr ); 
       
  1545             
       
  1546             
       
  1547         }
       
  1548         
       
  1549        } 
       
  1550        
       
  1551         FLOG(_L("CFotaServer::CheckSWVersionL  <<"));  
       
  1552        return isPkgvalid;
       
  1553 	
       
  1554 	
       
  1555 }	
       
  1556 
       
  1557 
       
  1558 // --------------------------------------------------------------------------
       
  1559 // CFotaServer::ScheduledUpdateL
       
  1560 // Update, triggered by scheduler
       
  1561 // --------------------------------------------------------------------------
       
  1562 void CFotaServer::ScheduledUpdateL( TFotaScheduledUpdate aUpdate )
       
  1563     {
       
  1564     FLOG(_L("CFotaServer::ScheduledUpdateL"));
       
  1565     TPackageState s = GetStateL( aUpdate.iPkgId );
       
  1566 
       
  1567     // If update is in progress, do not start new one (multiple popups)
       
  1568     if ( iUpdater )
       
  1569     	{
       
  1570     	FLOG(_L("\t\tupdate in progress"));
       
  1571 		return;
       
  1572     	}
       
  1573 	else
       
  1574 		{
       
  1575 		
       
  1576 		//Check to find whether the user has already installed the package before the
       
  1577 		//reminder could expire
       
  1578 		
       
  1579 		RFs aRfs;
       
  1580 		RDir aDir;
       
  1581 		TEntryArray anArray;
       
  1582 		User::LeaveIfError(aRfs.Connect());
       
  1583 		
       
  1584 		
       
  1585 		TBuf16<KMaxFileName> temp;
       
  1586 		temp.Zero();
       
  1587 		temp.Copy(KSwupdPath8);
       
  1588 		
       
  1589 		if(aDir.Open(aRfs,temp,KEntryAttNormal)==KErrNone)
       
  1590 		{
       
  1591 			TInt error = aDir.Read(anArray);	
       
  1592 		}
       
  1593 		aDir.Close();
       
  1594 		aRfs.Close();
       
  1595 	
       
  1596 		temp.Zero();
       
  1597 		temp.Copy(KSwupdFileExt8);
       
  1598 		
       
  1599 		TBool aStartUpdate(EFalse);
       
  1600 		
       
  1601 		for (TInt i=0; i<anArray.Count();i++)
       
  1602 			{
       
  1603 			if (anArray[i].iName.Find(temp)!=KErrNotFound)
       
  1604 				{
       
  1605 				aStartUpdate = ETrue;
       
  1606 				break;
       
  1607 				}
       
  1608 			}
       
  1609 		
       
  1610 		if (aStartUpdate)
       
  1611 			{
       
  1612 			FLOG(_L("\t\tReminder expired and update packages found on dir"));
       
  1613 			iUpdater = CFotaUpdate::NewL(this);
       
  1614 	    	iUpdater->StartUpdateL( s );
       
  1615 			}
       
  1616 		else
       
  1617 			{
       
  1618 			FLOG(_L("\t\tReminder expired, but no update package is found on dir; skipping"));
       
  1619 			}
       
  1620 		}
       
  1621     }
       
  1622 
       
  1623 // --------------------------------------------------------------------------
       
  1624 // CFotaServer::DoConnect
       
  1625 // From CServer2. Initializes class members. 
       
  1626 // --------------------------------------------------------------------------
       
  1627 void CFotaServer::DoConnect(const RMessage2 &aMessage)
       
  1628     {
       
  1629     FLOG(_L("CFotaServer::DoConnect(const RMessage2 &aMessage) >>") );
       
  1630 
       
  1631     // In case shutdown is in progress, cancel it.
       
  1632     if ( iAppShutter )
       
  1633         {
       
  1634         iAppShutter->Cancel();
       
  1635         delete iAppShutter;
       
  1636         iAppShutter=NULL;
       
  1637         }
       
  1638 
       
  1639     if ( iInitialized == EFalse )
       
  1640         {
       
  1641         TRAPD( err, ClientAwareConstructL( aMessage ) );
       
  1642         if ( err ) FLOG(_L("   ClientAwareConstructL err %d"),err);
       
  1643         }
       
  1644 
       
  1645     CAknAppServer::DoConnect( aMessage );
       
  1646     FLOG(_L("CFotaServer::DoConnect(const RMessage2 &aMessage) <<"));
       
  1647     }   
       
  1648 
       
  1649 
       
  1650 // --------------------------------------------------------------------------
       
  1651 // CFotaServer::GetStateL
       
  1652 // Get state of a download package
       
  1653 // --------------------------------------------------------------------------
       
  1654 TPackageState CFotaServer::GetStateL( const TInt aPkgId)
       
  1655     {
       
  1656     TPackageState s=RFotaEngineSession::EIdle;
       
  1657 
       
  1658     if (aPkgId >= 0) // Used by all clients
       
  1659     	{
       
  1660     	iDatabase->OpenDBL();
       
  1661     	s = iDatabase->GetStateL( aPkgId );
       
  1662    	    iDatabase->CloseAndCommitDB();
       
  1663     	}
       
  1664     else if (aPkgId == -2) //Used by DM UI to check if fota ui has to be in foreground
       
  1665     	{
       
  1666     	TBool value (EFalse);
       
  1667     	/** This P&S Key is used to notify DM UI on any download event. key=0 for idle and key=1 for download */     	
       
  1668     	TInt err = RProperty::Get(TUid::Uid(KOmaDMAppUid),
       
  1669                            KFotaDMRefresh,
       
  1670                            value);
       
  1671         FLOG(_L("RProperty KFotaDMRefresh Get, err = %d, val = %d"), err,value);
       
  1672 		if (err==KErrNone && value)
       
  1673 			{
       
  1674 			FLOG(_L("Ongoing download operation detected!"));
       
  1675 			s=RFotaEngineSession::EDownloadProgressing;
       
  1676 			}
       
  1677     	}
       
  1678     else if ( aPkgId == -1) //Used by DM UI to get the state of last fota operation
       
  1679     	{
       
  1680 		//Read status from fotastate last entry
       
  1681 
       
  1682     	iDatabase->OpenDBL();
       
  1683 
       
  1684 		RArray<TInt>    states;
       
  1685         CleanupClosePushL (states);
       
  1686         iDatabase->GetAllL ( states );
       
  1687         // Loop states. 
       
  1688         for(TInt i = 0; i < states.Count(); ++i ) 
       
  1689             {
       
  1690             TPackageState   tmp;
       
  1691             tmp = iDatabase->GetStateL(  states[i]  );
       
  1692             FLOG(_L("***Package: %d, State = %d"),states[i],(TInt) tmp.iState);
       
  1693             if (tmp.iState!=RFotaEngineSession::EIdle)
       
  1694 	            {
       
  1695             	s=tmp;
       
  1696     	        }
       
  1697             }
       
  1698 			FLOG(_L("Status of current operation is %d"),(TInt)s.iState);
       
  1699 		
       
  1700 		CleanupStack::PopAndDestroy( &states );
       
  1701    	    iDatabase->CloseAndCommitDB();
       
  1702     	}
       
  1703     return s;
       
  1704     }
       
  1705 
       
  1706 
       
  1707 // --------------------------------------------------------------------------
       
  1708 // CFotaServer::IsPackageStoreSizeAvailable 
       
  1709 // Checks if update package fits into storage
       
  1710 // --------------------------------------------------------------------------
       
  1711 //
       
  1712 TBool CFotaServer::IsPackageStoreSizeAvailableL ( const TInt aSize)
       
  1713     {
       
  1714     FLOG(_L("CFotaServer::IsPackageStoreSizeAvailableL >>"));
       
  1715     TInt size=aSize;
       
  1716 
       
  1717 		// Write content size for later use (flexible memory usage)
       
  1718 		RFileWriteStream str;	
       
  1719 		TUint32 				size2 = aSize;
       
  1720 		User::LeaveIfError(str.Replace(iFs, KSizePass, EFileWrite)); 
       
  1721 		CleanupClosePushL(str);
       
  1722 		str.WriteUint32L(size2);
       
  1723 		CleanupStack::PopAndDestroy(1);
       
  1724 
       
  1725     
       
  1726     CFotaStorage::TFreeSpace avail = StoragePluginL()->IsPackageStoreSizeAvailableL(size);
       
  1727     FLOG(_L("CFotaServer::IsPackageStoreSizeAvailableL <<"));
       
  1728     return avail==CFotaStorage::EDoesntFitToFileSystem ? EFalse : ETrue;
       
  1729     }
       
  1730 
       
  1731 // --------------------------------------------------------------------------
       
  1732 // CFotaServer::OnSyncMLSessionEvent
       
  1733 // --------------------------------------------------------------------------
       
  1734 //
       
  1735 void CFotaServer::OnSyncMLSessionEvent(TEvent aEvent, TInt aIdentifier
       
  1736                                        , TInt aError, TInt /*aAdditionalData*/)
       
  1737     {
       
  1738     if ( iSyncJobId != aIdentifier ) return;
       
  1739     FLOG(_L("CFotaServer::OnSyncMLSessionEvent %d err:%d (id %d==%d?)")
       
  1740             , aEvent,aError,aIdentifier,iSyncJobId);
       
  1741 
       
  1742     if ( iSyncJobId == aIdentifier )
       
  1743 	    {
       
  1744         TTimeIntervalMicroSeconds32 close(0);
       
  1745         TBool end ( EFalse );
       
  1746 	    switch( aEvent )
       
  1747 		    {
       
  1748             //EJobStart = 0
       
  1749             case EJobStartFailed: // 1 E
       
  1750                 {
       
  1751                 end = ETrue;
       
  1752                 }
       
  1753 			    break;
       
  1754             case EJobStop: // 2 E
       
  1755                 {
       
  1756                 end = ETrue;
       
  1757                 // Sync ok => do not try anymore
       
  1758                 if ( aError == KErrNone ) 
       
  1759                     {
       
  1760                     iSyncMLAttempts=0;
       
  1761                     }
       
  1762                 }
       
  1763 			    break;
       
  1764             case EJobRejected: // 3 E
       
  1765                 {
       
  1766                 end = ETrue;
       
  1767                 }
       
  1768 			    break;
       
  1769             // ETransportTimeout , // 7
       
  1770     	    default:
       
  1771                 {
       
  1772                 }
       
  1773 			    break;
       
  1774             }
       
  1775 
       
  1776 
       
  1777         // sml session OK,close it 
       
  1778         if ( end && iSyncMLAttempts == 0 ) 
       
  1779             {
       
  1780             FLOG(_L("   Sml OK, scheduling close"));
       
  1781         	if( aError == KErrNone ) //always ask session successful
       
  1782     		  {
       
  1783     		  TInt val = KErrNotFound;
       
  1784     		  TInt    err1 = RProperty::Get( TUid::Uid(KFotaServerUid),
       
  1785     				  KFotaLrgObjDl, val );
       
  1786     		  FLOG( _L( "CFotaSrvDocument::OnSyncMLSessionEvent KFotaLrgObjDl val & err is %d, %d" )
       
  1787     		  														,val,err1 );  
       
  1788     				  if( val == EOmaDmLrgObjDlFail ) //if large object
       
  1789     					{
       
  1790     					err1 = RProperty::Set( TUid::Uid(KFotaServerUid),
       
  1791     							KFotaLrgObjDl, KErrNotFound );
       
  1792     					FLOG( _L( "CFotaSrvDocument::OnSyncMLSessionEvent err for KFotaLrgObjDl is %d" )
       
  1793     							,err1 );  
       
  1794     					err1 = RProperty::Set( TUid::Uid(KFotaServerUid),
       
  1795     							KFotaLrgObjProfileId, KErrNotFound );
       
  1796     					FLOG( _L( "CFotaSrvDocument::OnSyncMLSessionEvent err for KFotaLrgObjProfileId is %d")
       
  1797     																							 ,err1 );  
       
  1798     							FLOG( _L( "[FotaServer] CFotaSrvDocument::OnSyncMLSessionEvent pkgid is %d" )
       
  1799     									,iStorageDownloadPackageId );  
       
  1800     							TRAP_IGNORE(GenericAlertSentL( iStorageDownloadPackageId ));
       
  1801     					}
       
  1802     		  }
       
  1803             close = TTimeIntervalMicroSeconds32( 100000 );
       
  1804             }
       
  1805         // sml session NOK, retry
       
  1806         if ( end && iSyncMLAttempts>0)
       
  1807             {
       
  1808             FLOG(_L("   Sml OK, scheduling retry"));
       
  1809             close = TTimeIntervalMicroSeconds32( KSyncmlSessionRetryInterval);
       
  1810             }
       
  1811 
       
  1812         if ( close > TTimeIntervalMicroSeconds32(0) )
       
  1813             {
       
  1814             if ( iTimedSMLSessionClose ) 
       
  1815                 {
       
  1816                 FLOG(_L("   closing smlsession timer"));
       
  1817                 iTimedSMLSessionClose->Cancel();
       
  1818                 delete iTimedSMLSessionClose;
       
  1819                 iTimedSMLSessionClose = NULL;
       
  1820                 }
       
  1821             FLOG(_L("   starting smlsession timer"));
       
  1822             TRAPD( err2, iTimedSMLSessionClose = CPeriodic::NewL (EPriorityNormal) );
       
  1823             if ( !err2 )
       
  1824             	{
       
  1825 							iTimedSMLSessionClose->Start (
       
  1826                 close
       
  1827                 , TTimeIntervalMicroSeconds32( KSyncmlSessionRetryInterval )
       
  1828                 , TCallBack( StaticDoCloseSMLSession,this ) ) ;
       
  1829 							}
       
  1830 							else FLOG(_L(" iTimedSMLSessionClose err %d"),err2);
       
  1831             }
       
  1832         }
       
  1833     }
       
  1834 
       
  1835 
       
  1836 // --------------------------------------------------------------------------
       
  1837 // CFotaServer::TryToShutDownFotaServer()
       
  1838 // Try to shut down. After last client left, this is tried periodically.
       
  1839 // --------------------------------------------------------------------------
       
  1840 //
       
  1841 TInt CFotaServer::TryToShutDownFotaServer()
       
  1842     {
       
  1843     RProcess pr; TFullName fn = pr.FullName();  TUint prid = pr.Id();
       
  1844 	FLOG(_L( "CFotaServer::TryToShutDownFotaServer process(id %d)%S. this 0x%x")
       
  1845 	                ,prid,&fn,this);
       
  1846     FLOG(_L("CFotaServer::TryToShutDownFotaServer()"));
       
  1847     FLOG(_L("iSessMode:%d,iUserResume:%d,iNeedToClose:%d"),iSessMode,
       
  1848                         iUserResume,iNeedToClose);
       
  1849     TBool val (EFalse);
       
  1850     if (iNotifHandler)
       
  1851     	val = iNotifHandler->IsOpen();
       
  1852     if( !iDownloader  && !iUpdater && !iTimedExecuteResultFile 
       
  1853         && !iSyncMLSession.Handle() && !iRetryingGASend  && !val
       
  1854         && !( iDownloader 
       
  1855              && iDownloader->IsDownloadActive() && iUserResume == EFalse /*FMS*/ 
       
  1856              && !iNeedToClose ))
       
  1857         {
       
  1858         
       
  1859         FLOG(_L("   shutting down fotaserver"));
       
  1860         if (iDownloader && iDownloader->IsDownloadActive() )
       
  1861             {
       
  1862             FLOG(_L("Shutting down active in TryToShutDownFotaServer..."));
       
  1863             StopDownload(RFotaEngineSession::EResUndefinedError);
       
  1864             }      
       
  1865        	CAknAppServer::HandleAllClientsClosed();
       
  1866        	return 1;
       
  1867         }
       
  1868     else
       
  1869         {
       
  1870         FLOG(_L("   shutdownwait:%d.%d.%d.%d.%d"), iDownloader,iUpdater
       
  1871             , iTimedExecuteResultFile,iSyncMLSession.Handle(),val);
       
  1872         }
       
  1873     return 0;
       
  1874     }
       
  1875 
       
  1876 
       
  1877 // ---------------------------------------------------------------------------
       
  1878 // StaticApplicationShutter
       
  1879 // Intermediate function
       
  1880 // ---------------------------------------------------------------------------
       
  1881 static TInt StaticApplicationShutter(TAny *aPtr)
       
  1882     {
       
  1883     __ASSERT_ALWAYS( aPtr, User::Panic(KFotaPanic, KErrArgument) );
       
  1884     CFotaServer* srv = (CFotaServer*) aPtr;
       
  1885     srv->TryToShutDownFotaServer();
       
  1886     return KErrNone;
       
  1887     }
       
  1888 
       
  1889 
       
  1890 // ---------------------------------------------------------------------------
       
  1891 // CFotaServer::HandleAllClientsClosed()
       
  1892 // Tries to shut down fotaserver. If unsuccesfull, periodically try it again
       
  1893 // and again and again ...
       
  1894 // ---------------------------------------------------------------------------
       
  1895 void CFotaServer::HandleAllClientsClosed()
       
  1896     {   
       
  1897     FLOG(_L("CFotaServer::HandleAllClientsClosed() >>"));
       
  1898 
       
  1899     if ( TryToShutDownFotaServer() == 0) 
       
  1900         {
       
  1901         FLOG(_L("   starting application shutdown" ));
       
  1902         if ( iAppShutter )
       
  1903             {
       
  1904             iAppShutter->Cancel();
       
  1905             delete iAppShutter;
       
  1906             iAppShutter=NULL;
       
  1907             }
       
  1908         TRAPD ( err , iAppShutter = CPeriodic::NewL (EPriorityNormal) );
       
  1909         __ASSERT_ALWAYS( err == KErrNone , User::Panic(KFotaPanic, err) );
       
  1910         FLOG(_L("iSessMode = %d iUserResume:%d,iNeedToClose:%d"),
       
  1911                 iSessMode,iUserResume,iNeedToClose);
       
  1912         if (iDownloader && iDownloader->IsDownloadActive() &&
       
  1913                 !(iUserResume == EFalse /*FMS*/ 
       
  1914                   && !iNeedToClose ) )
       
  1915         	{
       
  1916             FLOG(_L("Shutting down active..."));
       
  1917         	StopDownload(RFotaEngineSession::EResUndefinedError);
       
  1918         	}
       
  1919 
       
  1920         iAppShutter->Start( KFotaTimeShutDown , KFotaTimeShutDown
       
  1921                 , TCallBack(StaticApplicationShutter,this) ) ;
       
  1922         }
       
  1923 
       
  1924     FLOG(_L("CFotaServer::HandleAllClientsClosed() <<"));
       
  1925     }
       
  1926 
       
  1927 // --------------------------------------------------------------------------
       
  1928 // CFotaServer::GetUpdateTimeStampL 
       
  1929 // Gets time of last update. It is stored in a file.
       
  1930 // --------------------------------------------------------------------------
       
  1931 void CFotaServer::GetUpdateTimeStampL (TDes16& aTime)
       
  1932     {
       
  1933     FLOG(_L("CFotaServer::GetUpdateTimeStampL  >>"));
       
  1934     TInt                err;
       
  1935 
       
  1936     RFileReadStream     rstr;
       
  1937     err = rstr.Open( iFs, _L("updatetimestamp"), EFileRead );
       
  1938 
       
  1939     if ( err == KErrNone) 
       
  1940         {
       
  1941         FLOG(_L(" update time stamp file found,reading"));
       
  1942         CleanupClosePushL (rstr);
       
  1943         TInt year   =  rstr.ReadInt32L();
       
  1944         TInt month  =  rstr.ReadInt32L();    
       
  1945         TInt day    =  rstr.ReadInt32L();
       
  1946         TInt hour   =  rstr.ReadInt32L();  
       
  1947         TInt minute =  rstr.ReadInt32L();
       
  1948         TInt year16   = year;
       
  1949         TInt month16  = month; 
       
  1950         TInt day16    = day;   
       
  1951         TInt hour16   = hour;  
       
  1952         TInt minute16 = minute;
       
  1953         CleanupStack::PopAndDestroy( &rstr );
       
  1954         aTime.Append (year16);
       
  1955         aTime.Append (month16);
       
  1956         aTime.Append (day16);
       
  1957         aTime.Append (hour16);
       
  1958         aTime.Append (minute16);
       
  1959         }
       
  1960     else if ( err != KErrNotFound )
       
  1961         {
       
  1962         User::Leave ( err );
       
  1963         }
       
  1964 
       
  1965     if ( err == KErrNotFound ) 
       
  1966         {
       
  1967         FLOG(_L(" update time stamp not found "));
       
  1968         }
       
  1969 
       
  1970     FLOG(_L("CFotaServer::GetUpdateTimeStampL  <<"));
       
  1971     }
       
  1972 
       
  1973 // --------------------------------------------------------------------------
       
  1974 // CFotaServer::GetUpdatePackageIdsL
       
  1975 // --------------------------------------------------------------------------
       
  1976 //
       
  1977 void CFotaServer::GetUpdatePackageIdsL(TDes16& aPackageIdList)
       
  1978     {
       
  1979     FLOG(_L("CFotaServer::GetUpdatePackageIdsL()"));
       
  1980     StoragePluginL()->GetUpdatePackageIdsL( aPackageIdList );
       
  1981     }
       
  1982 
       
  1983 
       
  1984 
       
  1985 // --------------------------------------------------------------------------
       
  1986 // CFotaServer::GenericAlertSentL
       
  1987 // Generic alert sent, do cleanup. FUMO spec specifies cleanup need to have 
       
  1988 // for states 20,70,80,90,100. Called by syncml framework when it has sent
       
  1989 // generic alert
       
  1990 // --------------------------------------------------------------------------
       
  1991 //
       
  1992 void CFotaServer::GenericAlertSentL( const TInt aPackageID )
       
  1993     {
       
  1994     FLOG(_L("CFotaServer::GenericAlertSentL %d"), aPackageID);
       
  1995     TPackageState   state;
       
  1996     TBool           toidle(EFalse);
       
  1997     TBool           deletepkg(EFalse);
       
  1998 
       
  1999     iDatabase->OpenDBL();
       
  2000     state = iDatabase->GetStateL( aPackageID );
       
  2001 
       
  2002 	switch( state.iState  )
       
  2003 		{
       
  2004         case RFotaEngineSession::EDownloadFailed:
       
  2005             {
       
  2006             toidle = ETrue;
       
  2007             deletepkg = ETrue;
       
  2008             }
       
  2009 			break;
       
  2010         case RFotaEngineSession::EUpdateFailed:
       
  2011             {
       
  2012             toidle = ETrue;
       
  2013             deletepkg = ETrue;
       
  2014             }
       
  2015 			break;
       
  2016         case RFotaEngineSession::EUpdateFailedNoData:
       
  2017             {
       
  2018             toidle = ETrue;
       
  2019             }
       
  2020 			break;
       
  2021         case RFotaEngineSession::EUpdateSuccessful:
       
  2022             {
       
  2023             toidle = ETrue;
       
  2024             deletepkg = ETrue;
       
  2025             }
       
  2026 			break;
       
  2027         case RFotaEngineSession::EUpdateSuccessfulNoData:
       
  2028             {
       
  2029             toidle = ETrue;
       
  2030             }
       
  2031 			break;
       
  2032         case RFotaEngineSession::EDownloadComplete:
       
  2033         	{
       
  2034         	state.iState = RFotaEngineSession::EStartingUpdate;
       
  2035         	state.iResult = KErrNotFound;
       
  2036             iDatabase->SetStateL( state,KNullDesC8, EFDBState );
       
  2037         	toidle = EFalse;
       
  2038         	}
       
  2039         	break;
       
  2040     	default:
       
  2041             {
       
  2042             FLOG(_L(" pkg %d (state:%d) doesnt need cleanup"), aPackageID
       
  2043                         ,state.iState );
       
  2044             }
       
  2045 			break;
       
  2046         }
       
  2047     
       
  2048     if ( toidle )
       
  2049         {
       
  2050         state.iState = RFotaEngineSession::EIdle;
       
  2051         state.iResult = KErrNotFound;
       
  2052         iDatabase->SetStateL( state,KNullDesC8, EFDBState|EFDBResult );
       
  2053         DeleteFUMOTreeL();
       
  2054         }
       
  2055 
       
  2056 
       
  2057    	SetStartupReason(EFotaDefault);
       
  2058 
       
  2059     iDatabase->CloseAndCommitDB();
       
  2060 
       
  2061     if ( deletepkg )
       
  2062         {
       
  2063         StoragePluginL()->DeleteUpdatePackageL( aPackageID );
       
  2064         }
       
  2065 
       
  2066     // this should already be done when user was notified 
       
  2067     // about update result
       
  2068     DoDeleteUpdateResultFileL();
       
  2069     }
       
  2070 
       
  2071 // --------------------------------------------------------------------------
       
  2072 // CFotaServer::DoDeleteUpdateResultFileL
       
  2073 // Deletes the update resule file
       
  2074 // --------------------------------------------------------------------------
       
  2075 void CFotaServer::DoDeleteUpdateResultFileL()
       
  2076 	{
       
  2077     CFotaUpdate::DeleteUpdateResultFileL( iFs );
       
  2078 	}
       
  2079 
       
  2080 // --------------------------------------------------------------------------
       
  2081 // CFotaServer::CreateServiceL
       
  2082 // Creates session object
       
  2083 // --------------------------------------------------------------------------
       
  2084 CApaAppServiceBase* CFotaServer::CreateServiceL( TUid aServiceType ) const
       
  2085 	{
       
  2086     FLOG(_L( "CFotaServer::CreateServiceL 0x%x " ), aServiceType.iUid );
       
  2087     if ( aServiceType.iUid == KFotaServiceUid )
       
  2088         {
       
  2089 	    return ((CApaAppServiceBase*) (new (ELeave) CFotaSrvSession));
       
  2090         }
       
  2091     else
       
  2092         {
       
  2093         return CAknAppServer::CreateServiceL ( aServiceType );
       
  2094         }
       
  2095 	}
       
  2096 
       
  2097 // --------------------------------------------------------------------------
       
  2098 // CFotaServer::GetEikEnv
       
  2099 // Gets the EikonEnv object
       
  2100 // --------------------------------------------------------------------------
       
  2101 CEikonEnv* CFotaServer::GetEikEnv()
       
  2102 	{
       
  2103 	return iEikEnv;
       
  2104 	}
       
  2105 	
       
  2106 // --------------------------------------------------------------------------
       
  2107 // CFotaServer::StartNetworkMonitorL       
       
  2108 // Starts Network Monitoring operation for defined interval and retries (FotaNetworkRegMonitor.h)
       
  2109 // --------------------------------------------------------------------------
       
  2110 void CFotaServer::StartNetworkMonitorL()
       
  2111 	{
       
  2112 	FLOG(_L("CFotaServer::StartNetworkMonitorL >>"));
       
  2113 	if (!iMonitor)
       
  2114 		iMonitor = CFotaNetworkRegStatus::NewL (this);
       
  2115 	iMonitor->StartMonitoringL();
       
  2116 	
       
  2117 	FLOG(_L("CFotaServer::StartNetworkMonitorL <<"));
       
  2118 	}
       
  2119 	
       
  2120 // --------------------------------------------------------------------------
       
  2121 // CFotaServer::ReportNetworkStatus       
       
  2122 // called by CFotaNetworkRegStatus for reporting status
       
  2123 // --------------------------------------------------------------------------
       
  2124 void CFotaServer::ReportNetworkStatus(TBool status)
       
  2125 	{
       
  2126 	FLOG(_L("CFotaServer::ReportNetworkStatus, status = %d >>"),status);
       
  2127 	iRetryingGASend = EFalse;
       
  2128 	iNetworkAvailable = status;
       
  2129 	
       
  2130 	if (iNetworkAvailable)
       
  2131 		{
       
  2132 		TRAPD (err, CreateDeviceManagementSessionL (iStoredState));
       
  2133 		if (err!=KErrNone)
       
  2134 			{
       
  2135 			FLOG(_L("Error %d occured while sending GA after retries"),err);
       
  2136 			}
       
  2137 		}
       
  2138 	//No need of iMonitor anymore	
       
  2139     if ( iMonitor )    
       
  2140     	{
       
  2141     	delete iMonitor;
       
  2142     	iMonitor = NULL;
       
  2143     	}
       
  2144 
       
  2145 	FLOG(_L("CFotaServer::ReportNetworkStatus >>"));
       
  2146 	}
       
  2147 
       
  2148 // --------------------------------------------------------------------------
       
  2149 // CFotaServer::ShutApp 
       
  2150 // Shuts the DM App ui. This is used when End key is pressed during fota operation.
       
  2151 // --------------------------------------------------------------------------
       
  2152 //
       
  2153 void CFotaServer::ShutApp()
       
  2154 	{
       
  2155 	FLOG(_L("CFotaServer::ShutApp >>"));
       
  2156 	FLOG(_L("Ending DM UI...."));
       
  2157 	TApaTaskList taskList(GetEikEnv()->WsSession());
       
  2158 	TApaTask task=taskList.FindApp(TUid::Uid(KOmaDMAppUid));
       
  2159 	if(task.Exists())
       
  2160 		{
       
  2161 		task.EndTask();
       
  2162 		}
       
  2163 	FLOG(_L("CFotaServer::ShutApp <<"));
       
  2164 	}
       
  2165 
       
  2166 // --------------------------------------------------------------------------
       
  2167 // CFotaServer::StopDownload 
       
  2168 // Stops any ongoing download operation. Depending on the property of download, the later is either paused
       
  2169 // or cancelled.
       
  2170 // --------------------------------------------------------------------------
       
  2171 //
       
  2172 void CFotaServer::StopDownload(TInt aReason)
       
  2173 	{
       
  2174 	FLOG(_L("CFotaServer::StopDownload, aReason = %d >>"), aReason);
       
  2175 	iUserResume = KErrNotFound;
       
  2176 	iSessMode = KErrNotFound;
       
  2177     if (iDownloader)
       
  2178     	{
       
  2179         FLOG(_L("stopping fota download"));
       
  2180         iNeedToClose  = EFalse;
       
  2181         if (iDownloader->IsDownloadResumable())
       
  2182     		{
       
  2183     		TRAP_IGNORE(iDownloader->RunDownloadSuspendL(aReason));
       
  2184     		}
       
  2185    		else
       
  2186    			{
       
  2187    			TRAP_IGNORE(iDownloader->RunDownloadCancelL(aReason));
       
  2188    			}
       
  2189     	}	
       
  2190 	FLOG(_L("CFotaServer::StopDownload <<"));
       
  2191 	}
       
  2192 
       
  2193 // --------------------------------------------------------------------------
       
  2194 // CFotaServer::UpdateDBdataL 
       
  2195 // For OMA DM large object download failure, this method updates the database
       
  2196 // and sends the generic alert.
       
  2197 // --------------------------------------------------------------------------
       
  2198 //
       
  2199 void CFotaServer::UpdateDBdataL()
       
  2200 	{	
       
  2201 	TInt val(KErrNotFound),UserCancel(KErrNotFound);
       
  2202 	TInt err = RProperty::Get( TUid::Uid(KFotaServerUid),
       
  2203 			KFotaLrgObjDl, val);
       
  2204 	FLOG(_L("CFotaServer::UpdateDBdata KFotaLrgObjDl value & err is %d, %d "),val,err);	
       
  2205 	//val = 1 means LrgObj Download & its failed , -1 means not lrg object download / stream commited
       
  2206 	if( val == EOmaDmLrgObjDlFail ) 
       
  2207 		{
       
  2208 		err = RProperty::Get( TUid::Uid(KOmaDMAppUid),
       
  2209 				KDmJobCancel, UserCancel);
       
  2210 		FLOG(_L("CFotaServer::UpdateDBdataL KDmJobCancel value & err is %d, %d "),UserCancel,err);
       
  2211 		if( UserCancel == KErrCancel )
       
  2212 			{			
       
  2213 			TInt ProfId(KErrNotFound);
       
  2214 			err = RProperty::Get( TUid::Uid(KFotaServerUid),
       
  2215 					KFotaLrgObjProfileId, ProfId);
       
  2216 			FLOG(_L("CFotaServer::UpdateDBdataL KFotaLrgObjProfileId value & err is %d, %d,pkgid is %d "),
       
  2217 					ProfId,err,iStorageDownloadPackageId);
       
  2218 			if(iStorageDownloadPackageId > KErrNotFound && ProfId > KErrNotFound )
       
  2219 				{
       
  2220 				iDatabase->OpenDBL();
       
  2221 				FLOG(_L("CFotaServer::UpdateDBdataL after iDatabase->OpenDBL() "));
       
  2222 				TPackageState state;
       
  2223 				state.iPkgId = iStorageDownloadPackageId;
       
  2224 				state.iProfileId  = ProfId;
       
  2225 				state.iState = RFotaEngineSession::EDownloadFailed;
       
  2226 				state.iResult = RFotaEngineSession::EResUserCancelled;				
       
  2227 				iDatabase->SetStateL( state,KNullDesC8, EFDBState | EFDBResult ) ;
       
  2228 				FLOG(_L("CFotaServer::UpdateDBdataL after iDatabase->SetStateL"));
       
  2229 				iDatabase->CloseAndCommitDB();		
       
  2230 				FLOG(_L("CFotaServer::UpdateDBdataL after iDatabase->CloseAndCommitDB "));			    
       
  2231 				// Free resources
       
  2232 				iChunk.Close();
       
  2233 				FLOG(_L("CFotaServer::UpdateDBdataL ,chunk released "));
       
  2234 				iStorage->UpdatePackageDownloadCompleteL(iStorageDownloadPackageId);		    				
       
  2235 				CreateDeviceManagementSessionL(state);
       
  2236 				}
       
  2237 
       
  2238 			}
       
  2239 		}	
       
  2240 	}
       
  2241 // --------------------------------------------------------------------------
       
  2242 // CFotaServer::MonitorBatteryL()
       
  2243 // Monitors for the battery 
       
  2244 // 
       
  2245 // --------------------------------------------------------------------------
       
  2246 //
       
  2247 void CFotaServer::MonitorBattery(TInt aLevel)
       
  2248 {   FLOG(_L("CFotaServer::MonitorBatteryL(), level = %d >>"), aLevel);
       
  2249     SetStartupReason(EFotaUpdateInterrupted);
       
  2250 	RFMSClient fmsclient;
       
  2251 	TRAPD(err,fmsclient.OpenL());
       
  2252 	if(err == KErrNone)
       
  2253 	{ FLOG(_L("CFotaServer::going into FMS client side MonitorBatteryL() >>"));
       
  2254 		//fmsclient.Cancel();
       
  2255 	  TRAPD(err1,fmsclient.MonitorForBatteryL(aLevel));
       
  2256 	   if(err1)
       
  2257 	   {
       
  2258 	   	FLOG(_L("CFotaServer:: MonitorBatteryL() left with error %d  >>"), err1);
       
  2259 	   }
       
  2260 	  fmsclient.Close();
       
  2261 	
       
  2262 	}
       
  2263 	
       
  2264 	FLOG(_L("CFotaServer::MonitorBatteryL() <<"));
       
  2265   	
       
  2266 	
       
  2267 }
       
  2268 
       
  2269 // --------------------------------------------------------------------------
       
  2270 // CFotaServer::CheckIapExistsL 
       
  2271 // Checks for IAP Id exists or not in commsdb
       
  2272 // IAP Id used for resuming the download or for sending Generic alert
       
  2273 // --------------------------------------------------------------------------
       
  2274 //
       
  2275 TBool CFotaServer::CheckIapExistsL(TUint32 aIapId)
       
  2276     {
       
  2277     FLOG(_L("CFotaServer::CheckIapExistsL >>"));
       
  2278     CCommsDatabase* commDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
  2279     CleanupStack::PushL( commDb );
       
  2280     CApUtils* aputils = CApUtils::NewLC(*commDb);
       
  2281     TBool exists = aputils->IAPExistsL( aIapId);      
       
  2282     CleanupStack::PopAndDestroy( aputils );
       
  2283     CleanupStack::PopAndDestroy( commDb );
       
  2284     FLOG(_L("CFotaServer::CheckIapExistsL <<"));
       
  2285     return exists;
       
  2286     }
       
  2287 
       
  2288 // --------------------------------------------------------------------------
       
  2289 // CFotaServer::GetSoftwareVersion
       
  2290 // Gets the software version
       
  2291 // 
       
  2292 // --------------------------------------------------------------------------
       
  2293 //
       
  2294 TInt CFotaServer::GetSoftwareVersion(TDes& aVersion)
       
  2295     {
       
  2296     FLOG(_L("CFotaServer::GetSoftwareVersion >>"));
       
  2297     aVersion.Zero();
       
  2298     
       
  2299     SysVersionInfo::TVersionInfoType what = SysVersionInfo::EFWVersion;
       
  2300     TInt error (KErrNone);
       
  2301     error = SysVersionInfo::GetVersionInfo(what,aVersion);
       
  2302     FLOG(_L("CFotaServer::GetSoftwareVersion,SwV=%S <<"),&aVersion);
       
  2303     return error;
       
  2304     }
       
  2305     
       
  2306 // --------------------------------------------------------------------------
       
  2307 // CFotaServer::ResetFotaStateL
       
  2308 // Resets the Fotastate
       
  2309 // 
       
  2310 // --------------------------------------------------------------------------
       
  2311 //    
       
  2312 void CFotaServer::ResetFotaStateL(const TDownloadIPCParams& aParams)
       
  2313     {
       
  2314     FLOG(_L("CFotaServer::ResetFotaStateL >>"));
       
  2315 
       
  2316     TPackageState state;
       
  2317     if (!iDatabase->IsOpen()) iDatabase->OpenDBL();
       
  2318     //Fetch the software version that was before download from db.
       
  2319     state = iDatabase->GetStateL(aParams.iPkgId);
       
  2320     state.iState = RFotaEngineSession::EUpdateFailed;
       
  2321     state.iResult = RFotaEngineSession::EResPackageMismatch;
       
  2322     iDatabase->SetStateL( state,KNullDesC8, EFDBState | EFDBResult );
       
  2323     iDatabase->CloseAndCommitDB();
       
  2324     
       
  2325     StoragePluginL()->DeleteUpdatePackageL ( aParams.iPkgId );
       
  2326     
       
  2327     CreateDeviceManagementSessionL(state);
       
  2328     
       
  2329     FLOG(_L("CFotaServer::ResetFotaStateL <<"));
       
  2330     }
       
  2331 
       
  2332 // --------------------------------------------------------------------------
       
  2333 // CFotaServer::SetInstallUpdateClientL 
       
  2334 // Set's who is the client triggering the update
       
  2335 // --------------------------------------------------------------------------
       
  2336 //
       
  2337 void CFotaServer::SetInstallUpdateClientL(TInt aClient)
       
  2338     {    
       
  2339     iInstallupdClient = aClient;
       
  2340     FLOG(_L("CFotaServer::SetInstallUpdateClientL() client:%d<<"),iInstallupdClient);
       
  2341     }
       
  2342 
       
  2343 // --------------------------------------------------------------------------
       
  2344 // CFotaServer::GetInstallUpdateClientL 
       
  2345 // returns the client who triggered the update
       
  2346 // --------------------------------------------------------------------------
       
  2347 //
       
  2348 TInt CFotaServer::GetInstallUpdateClientL()
       
  2349     {
       
  2350     FLOG(_L("CFotaServer::GetInstallUpdateClientL() client:%d<<"),iInstallupdClient);
       
  2351     return iInstallupdClient ;
       
  2352     }
       
  2353 
       
  2354 // CFotaServer::NeedToDecryptL
       
  2355 // This method is called to check if decryption is needed.
       
  2356 // 
       
  2357 // --------------------------------------------------------------------------
       
  2358 // 
       
  2359 TBool CFotaServer::NeedToDecryptL(const TInt &aPkgId, TDriveNumber &aDrive)
       
  2360     {
       
  2361     FLOG(_L("CFotaServer::NeedToDecryptL >>"));
       
  2362     
       
  2363     TBool ret (EFalse);
       
  2364 
       
  2365     //Finding the drive number
       
  2366     TBuf8<KMaxPath> path8;
       
  2367     path8.Zero();
       
  2368     StoragePluginL()->GetUpdatePackageLocationL(aPkgId, path8);
       
  2369     TPath path16;
       
  2370     path16.Copy(path8);
       
  2371 
       
  2372 
       
  2373     TDriveNumber drive (EDriveC ); //Default drive is Phone Memory
       
  2374     TParse p;
       
  2375     if (!p.Set(path16,NULL,NULL))
       
  2376         {
       
  2377         TDriveName drivename(p.Drive());
       
  2378         TDriveUnit driveunit(drivename);
       
  2379         if (iFs.IsValidDrive((TInt) driveunit))
       
  2380             {
       
  2381             drive =  (TDriveNumber) driveunit.operator TInt();
       
  2382             iStorageDrive = drive;
       
  2383             }
       
  2384         }
       
  2385     else
       
  2386         {
       
  2387         FLOG(_L("Error while parsing for drive number! defaulting to Phone Memory (C)"));
       
  2388         }
       
  2389     FLOG(_L("Package storage drive is %d"), (TInt) drive);
       
  2390 
       
  2391     if (!iDEController)
       
  2392         {
       
  2393         TRAPD(err, iDEController = CDevEncController::NewL(this));
       
  2394         if (err == KErrNotSupported)
       
  2395             {
       
  2396             //Encryption feature is not on.
       
  2397             return EFalse;
       
  2398             }
       
  2399         else
       
  2400             {
       
  2401             __LEAVE_IF_ERROR(err);
       
  2402             }
       
  2403         }
       
  2404     TRAPD(err, ret = iDEController->NeedToDecryptL(drive));
       
  2405     
       
  2406     delete iDEController; iDEController = NULL;
       
  2407     
       
  2408     if (err == KErrNotSupported)
       
  2409         {
       
  2410         //Encryption feature is ON, but the encryption adaptation is note present.
       
  2411         ret = EFalse;
       
  2412         }
       
  2413     else
       
  2414         {
       
  2415         __LEAVE_IF_ERROR(err);
       
  2416         }
       
  2417    
       
  2418     //Set the appropriate drive when ret is true
       
  2419     if (ret)
       
  2420         {
       
  2421         aDrive = drive;
       
  2422         }
       
  2423     
       
  2424     FLOG(_L("CFotaServer::NeedToDecryptL ret = %d, drive = %d <<"), ret, drive);
       
  2425     return ret;
       
  2426 
       
  2427     }
       
  2428 
       
  2429 // --------------------------------------------------------------------------
       
  2430 // CFotaServer::DoStartDecryptionL
       
  2431 // This method is called to start the decryption operation.
       
  2432 // 
       
  2433 // --------------------------------------------------------------------------
       
  2434 // 
       
  2435 void CFotaServer::DoStartDecryptionL()
       
  2436     {
       
  2437     FLOG(_L("CFotaServer::DoStartDecryptionL >>"));
       
  2438     
       
  2439     if (!iDEController)
       
  2440         iDEController = CDevEncController::NewL(this);
       
  2441     
       
  2442     iDEController->DoStartDecryptionL(iStorageDrive);
       
  2443     
       
  2444     FLOG(_L("CFotaServer::DoStartDecryptionL <<"));
       
  2445     }
       
  2446 
       
  2447 // --------------------------------------------------------------------------
       
  2448 // CFotaServer::HandleDecryptionCompleteL
       
  2449 // This method is called to when decryption operation is complete.
       
  2450 // 
       
  2451 // --------------------------------------------------------------------------
       
  2452 // 
       
  2453 void CFotaServer::HandleDecryptionCompleteL(TInt aResult, TInt aValue)
       
  2454     {
       
  2455     FLOG(_L("CFotaServer::HandleDecryptionCompleteL, result = %d, value = %d >>"), aResult, aValue);
       
  2456     
       
  2457     if (aResult == KErrNone)
       
  2458         {
       
  2459         //Skip battery test as it is already performed before decryption
       
  2460         iUpdater->HandleUpdateAcceptStartL(ETrue);
       
  2461         }
       
  2462     else
       
  2463         {
       
  2464         FLOG(_L("Can't start update because of error %d"), aResult);
       
  2465         iUpdater->HandleUpdateErrorL(aResult, aValue);
       
  2466         }
       
  2467     
       
  2468     if (iDEController)
       
  2469         {
       
  2470         delete iDEController; iDEController = NULL;
       
  2471         }
       
  2472     
       
  2473     FLOG(_L("CFotaServer::HandleDecryptionCompleteL <<"));
       
  2474     }
       
  2475 
       
  2476 
       
  2477 // --------------------------------------------------------------------------
       
  2478 // CFotaServer::NeedToEncryptL
       
  2479 // This method is called to check if encryption is needed.
       
  2480 // 
       
  2481 // --------------------------------------------------------------------------
       
  2482 // 
       
  2483 TBool CFotaServer::NeedToEncryptL(TDriveNumber &aDrive)
       
  2484     {
       
  2485     FLOG(_L("CFotaServer::NeedToEncryptL >>"));
       
  2486     
       
  2487     TDriveNumber drive;
       
  2488     if (!iDEController)
       
  2489         {
       
  2490         TRAPD(err, iDEController = CDevEncController::NewL(this));
       
  2491         if (err == KErrNotSupported)
       
  2492             {
       
  2493             return EFalse;
       
  2494             }
       
  2495         else
       
  2496             {
       
  2497             __LEAVE_IF_ERROR(err);
       
  2498             }
       
  2499         }
       
  2500     
       
  2501     TBool ret = iDEController->NeedToEncryptL(drive);
       
  2502     delete iDEController; iDEController = NULL;
       
  2503     
       
  2504     if (ret)
       
  2505         {
       
  2506         aDrive = drive;
       
  2507         iStorageDrive = drive;
       
  2508         }
       
  2509     
       
  2510     FLOG(_L("CFotaServer::NeedToEncryptL, ret = %d drive = %d << "), ret, aDrive);
       
  2511     return ret;
       
  2512     }
       
  2513 
       
  2514 // --------------------------------------------------------------------------
       
  2515 // CFotaServer::DoStartEncryptionL
       
  2516 // This method is called to start the encryption operation.
       
  2517 // 
       
  2518 // --------------------------------------------------------------------------
       
  2519 // 
       
  2520 void CFotaServer::DoStartEncryptionL()
       
  2521     {
       
  2522     FLOG(_L("CFotaServer::DoStartEncryptionL >>"));
       
  2523     
       
  2524     if (!iDEController)
       
  2525         iDEController = CDevEncController::NewL(this);
       
  2526     
       
  2527     iDEController->DoStartEncryptionL(iStorageDrive);
       
  2528     
       
  2529     FLOG(_L("CFotaServer::DoStartEncryptionL <<"));
       
  2530     }
       
  2531 
       
  2532 // --------------------------------------------------------------------------
       
  2533 // CFotaServer::HandleEncryptionCompleteL
       
  2534 // This method is called when the encryption operation is complete.
       
  2535 // 
       
  2536 // --------------------------------------------------------------------------
       
  2537 // 
       
  2538 void CFotaServer::HandleEncryptionCompleteL(TInt aResult, TInt aValue)
       
  2539     {
       
  2540     FLOG(_L("CFotaServer::HandleEncryptionCompleteL, result = %d, value = %d >>"), aResult, aValue);
       
  2541     
       
  2542     if (aResult == KErrNone)
       
  2543         {
       
  2544         //Do nothing
       
  2545         }
       
  2546     else
       
  2547         {
       
  2548         FLOG(_L("Can't start update because of error %d"), aResult);
       
  2549         iUpdater->HandleEncryptionErrorL(aResult);
       
  2550         }
       
  2551     
       
  2552     if (iDEController)
       
  2553         {
       
  2554         delete iDEController; iDEController = NULL;
       
  2555         }
       
  2556     
       
  2557     FLOG(_L("CFotaServer::HandleEncryptionCompleteL <<"));
       
  2558     }
       
  2559 
       
  2560 
       
  2561 // --------------------------------------------------------------------------
       
  2562 // CFotaServer::GetDEOperation
       
  2563 // This method returns the device encryption operation.
       
  2564 // 
       
  2565 // --------------------------------------------------------------------------
       
  2566 // 
       
  2567 TInt CFotaServer::GetDEOperation()
       
  2568     {
       
  2569     FLOG(_L("CFotaServer::GetDEOperation >>"));
       
  2570     TInt ret (EIdle);
       
  2571 
       
  2572     if (iDEController)
       
  2573         ret = iDEController->GetDEOperation();
       
  2574     
       
  2575     FLOG(_L("CFotaServer::GetDEOperation, ret = %d <<"), ret);
       
  2576     return ret;
       
  2577     }
       
  2578