installationservices/swi/source/daemon/daemon.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 0 ba25891c3a9e
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
       
     1 /*
       
     2 * Copyright (c) 2004-2009 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 the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "daemon.h"
       
    20 #include "drivewatcher.h"
       
    21 #include "log.h"
       
    22 #include "securitypolicy.h"
       
    23 
       
    24 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    25 #include <e32property.h>
       
    26 #include <connect/sbdefs.h>
       
    27 #include <usif/sts/sts.h>
       
    28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    29 #include "stsrecovery.h"
       
    30 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
       
    31 #include "swiobserverclient.h"
       
    32 #else
       
    33 #include "sisregistrysession.h"
       
    34 #endif
       
    35 
       
    36 
       
    37 namespace Swi
       
    38 {
       
    39 // CDaemon
       
    40 
       
    41 /*static*/ CDaemon* CDaemon::NewL(MDaemonBehaviour& aBehaviour)
       
    42 	{
       
    43 	CDaemon* self=NewLC(aBehaviour);
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 /*static*/ CDaemon* CDaemon::NewLC(MDaemonBehaviour& aBehaviour)
       
    49 	{
       
    50 	CDaemon* self=new(ELeave) CDaemon(aBehaviour);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL();
       
    53 	return self;
       
    54 	}
       
    55 	
       
    56 CDaemon::~CDaemon()
       
    57 	{
       
    58 	iPolicyLockFile.Close();
       
    59 	iWatchers.ResetAndDestroy();
       
    60 	iFs.Close();
       
    61 	}
       
    62 
       
    63 CDaemon::CDaemon(MDaemonBehaviour& aBehaviour)
       
    64 	: iBehaviour(aBehaviour)
       
    65 	{
       
    66 	}
       
    67 
       
    68 void CDaemon::ConstructL()
       
    69 	{
       
    70 	User::LeaveIfError(iFs.Connect());
       
    71 	LockSensitiveFiles();
       
    72 	StartRecoveryL();
       
    73 	iBehaviour.StartupL();
       
    74 	StartWatchersL();
       
    75 	}
       
    76 
       
    77 void CDaemon::StartWatchersL()
       
    78 	{
       
    79 	RFs fs;
       
    80 	User::LeaveIfError(fs.Connect());
       
    81 	CleanupClosePushL(fs);
       
    82 	
       
    83 	User::LeaveIfError(fs.ShareProtected());
       
    84 	
       
    85 	TDriveList driveList;
       
    86 	
       
    87 	User::LeaveIfError(fs.DriveList(driveList));
       
    88 
       
    89 	for (TInt drive=0; drive < KMaxDrives; ++drive)
       
    90 		{
       
    91 		if (driveList[drive] == 0)
       
    92 			{
       
    93 			continue;
       
    94 			}
       
    95 		TDriveInfo info;
       
    96 		
       
    97 		// Ignore errors since the next drive might work
       
    98 		if (KErrNone != fs.Drive(info, drive))
       
    99 			{
       
   100 			DEBUG_PRINTF2(_L8("SWI Daemon - Not watching drive '%d', could not retrieve drive info."),
       
   101 				drive); 
       
   102 			continue;
       
   103 			}
       
   104 
       
   105 		if (info.iDriveAtt & KDriveAttRemovable)
       
   106 			{
       
   107 			DEBUG_PRINTF2(_L8("SWI Daemon - Watching removable drive '%d'"), drive);
       
   108 			CDriveWatcher* driveWatcher=CDriveWatcher::NewLC(iFs, drive, iBehaviour);
       
   109 			User::LeaveIfError(iWatchers.Append(driveWatcher));
       
   110 			CleanupStack::Pop(driveWatcher);
       
   111 			}
       
   112 		}
       
   113 	CleanupStack::PopAndDestroy(&fs);
       
   114 	} // StartWatchersL()
       
   115 
       
   116 void CDaemon::LockSensitiveFiles()
       
   117 	{
       
   118 	TInt error = iPolicyLockFile.Open(iFs, KSwisPolicyFile, EFileShareReadersOnly | EFileRead);
       
   119 	if (error != KErrNone)
       
   120 		{
       
   121 		DEBUG_PRINTF2(_L8("SWI Daemon - Could not open SWI policy file with error %d!"), error);
       
   122 		}	
       
   123 	}
       
   124 
       
   125 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   126 void CDaemon::StartRecoveryL()
       
   127 	{
       
   128 	DEBUG_PRINTF(_L("CDaemon::StartRecoveryL()"));
       
   129 
       
   130 	// Check to see if a backup is in progress...
       
   131 	TInt backup = 0;
       
   132 	User::LeaveIfError(RProperty::Get(KUidSystemCategory,conn::KUidBackupRestoreKey,backup));
       
   133 	
       
   134 	if(backup == conn::EBURUnset || (backup == (conn::EBURNormal | conn::ENoBackup))) //no backup or restore is in progress
       
   135 		{
       
   136 		//no recovery attempt is made during backup/restore as recovery may seriously affect the file system, which might impact backup/restore
       
   137 		//recovery will be made at next bootup
       
   138 		Usif::RStsRecoverySession stsRecoverySession;
       
   139 		// A recovery failure should not affect Daemon start up.
       
   140 		TRAPD(err, stsRecoverySession.RollbackAllPendingL());
       
   141 		if(err != KErrNone)
       
   142 			{
       
   143 			DEBUG_PRINTF2(_L("CDaemon::StartRecoveryL() - STS server failed to recover transactions. Error code: %d"), err);
       
   144 			}
       
   145 		//Start SWI Observer so that it can process the log files left from the previous session.
       
   146 		RSwiObserverSession swiObserver;
       
   147 		swiObserver.ProcessLogsL(iFs); 
       
   148 		swiObserver.Close();
       
   149 		}
       
   150 	}
       
   151 #else
       
   152 void CDaemon::StartRecoveryL()
       
   153 	{
       
   154 	DEBUG_PRINTF(_L8("SWI Daemon - Check to see if a recovery is needed"));
       
   155 	RSisRegistrySession registrySession;
       
   156 	User::LeaveIfError(registrySession.Connect());
       
   157 	CleanupClosePushL(registrySession);
       
   158 	
       
   159 	// A recovery failure should not affect SWI Daemon start up.
       
   160 	TRAP_IGNORE(registrySession.RecoverL());
       
   161 	
       
   162 	CleanupStack::PopAndDestroy(&registrySession);
       
   163 	DEBUG_PRINTF(_L8("SWI Daemon - Recovery check finished"));
       
   164 	}
       
   165 #endif
       
   166 
       
   167 } // namespace Swi