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