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