sysstatemgmt/systemstateplugins/gsapolicy/src/gsastatepolicystartup.cpp
changeset 70 653a8b91b95e
parent 0 4e1aa6a622a0
equal deleted inserted replaced
64:61992147389a 70:653a8b91b95e
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    17 #include <barsread2.h>
    17 #include <barsread2.h>
    18 #include <e32property.h>
    18 #include <e32property.h>
    19 #include <e32uid.h>
    19 #include <e32uid.h>
    20 #include <e32std.h>
    20 #include <e32std.h>
    21 #include <bautils.h>
    21 #include <bautils.h>
       
    22 #include <centralrepository.h>
    22 
    23 
    23 #include <ssm/ssmcmd.hrh>
    24 #include <ssm/ssmcmd.hrh>
    24 #include <ssm/ssmsubstates.hrh>
    25 #include <ssm/ssmsubstates.hrh>
    25 #ifdef SYMBIAN_SSM_GRACEFUL_SHUTDOWN
    26 #ifdef SYMBIAN_SSM_GRACEFUL_SHUTDOWN
    26 #include <ssm/ssmpatchableconstants.h>
    27 #include <ssm/ssmpatchableconstants.h>
    27 #include <ssm/conditiontypes.hrh>
    28 #include <ssm/conditiontypes.hrh>
    28 #endif
    29 #endif
    29 
    30 
    30 #include <ssm/ssmstatetransition.h>
    31 #include <ssm/ssmstatetransition.h>
    31 #include <ssm/ssmcommandlistresourcereader.h>
    32 #include <ssm/ssmcommandlistresourcereader.h>
    32 #include <ssm/ssmmaxbootattempts_patch.h>
       
    33 
    33 
    34 #include "gsastatepolicystartup.h"
    34 #include "gsastatepolicystartup.h"
    35 #include "ssmdebug.h"
    35 #include "ssmdebug.h"
    36 #include "ssmpanic.h" 
    36 #include "ssmpanic.h" 
    37 #include "s32file.h" 
    37 #include "s32file.h" 
    38 
    38 #include "ssmpolicypluginsprivatecrkeys.h"
    39 _LIT(KBootUpFile, ":\\private\\2000d75b\\bootupinfo\\bootupcount.bin");
       
    40 
       
    41 /**
       
    42  Attempt to reboot the device (forever) on boot failure. Used when KSsmMaxBootAttempts is set to '0xFFFFFFFF'.
       
    43 */
       
    44 const TInt KSsmAttemptRebootForever = 0xFFFFFFFF;
       
    45 
    39 
    46 /**
    40 /**
    47 Panic used by Startup policy plug-in when resource reader is invalid.
    41 Panic used by Startup policy plug-in when resource reader is invalid.
    48 Strings must not be longer than 16 characters or they will be truncated by User::Panic()
    42 Strings must not be longer than 16 characters or they will be truncated by User::Panic()
    49 */
    43 */
   292 			DEBUGPRINT1(_L("Startup Policy : Emulator (__WINS__) does not support a re-start, so Fail Policy is not invoked."));
   286 			DEBUGPRINT1(_L("Startup Policy : Emulator (__WINS__) does not support a re-start, so Fail Policy is not invoked."));
   293 			PanicNow(KPanicGsaStartupState, EEmulatorPowerOff);
   287 			PanicNow(KPanicGsaStartupState, EEmulatorPowerOff);
   294 			}
   288 			}
   295 #else	// on hardware/device
   289 #else	// on hardware/device
   296 			{
   290 			{
   297 			aNextState = TSsmState(ESsmFail, ESsmFailSubStateRestart);
   291 			TInt resetLimit = -1;
   298 			if (KSsmAttemptRebootForever != KSsmMaxBootAttempts)
   292 			TInt bootCount = -1;
       
   293 			TRAPD( err, GetStartupCountAndMaxbootLimitL(bootCount, resetLimit) );
       
   294 			if (bootCount < resetLimit && KErrNone == err)
   299 				{
   295 				{
   300 				// Get number of boot attempts made till now from bootup log file
   296 				aNextState = TSsmState(ESsmFail, ESsmFailSubStateRestart);
   301 				TInt bootCount = -1;
   297 				}
   302 				TRAPD(err, bootCount = GetBootupCountL());	// ignore failure and restart the device, we should get the value next time.
   298 			else	// Maximum allowed boot attempts has been made. Device needs a poweroff. Probable candidate for a reset/reflash.
   303 				if (err!=KErrNone)
   299 				{
   304 					{
   300 				aNextState = TSsmState(ESsmFail, ESsmFailSubStatePowerOff);
   305 					DEBUGPRINT2(_L("Startup Policy : GetBootupCountL() failed with (error: %d), error is deliberately ignored."), aError);
       
   306 					}
       
   307 				if (bootCount < KSsmMaxBootAttempts)
       
   308 					{
       
   309 					aNextState = TSsmState(ESsmFail, ESsmFailSubStateRestart);
       
   310 					}
       
   311 				else	// Maximum allowed boot attempts has been made. Device needs a poweroff. Probable candidate for a reset/reflash.
       
   312 					{
       
   313 					aNextState = TSsmState(ESsmFail, ESsmFailSubStatePowerOff);
       
   314 					}
       
   315 				}
   301 				}
   316 	#ifdef _DEBUG
   302 	#ifdef _DEBUG
   317 			TSsmStateName name = aNextState.Name();
   303 			TSsmStateName name = aNextState.Name();
   318 			DEBUGPRINT3(_L("Startup Policy : CLE returned with (error : %d) so moving to Fail State : %S."), aError, &name);
   304 			DEBUGPRINT3(_L("Startup Policy : CLE returned with (error : %d) so moving to Fail State : %S."), aError, &name);
   319 	#endif
   305 	#endif
   450 		iLaunchSysStart = ETrue;	// launch 'sysstart.exe'
   436 		iLaunchSysStart = ETrue;	// launch 'sysstart.exe'
   451 		}
   437 		}
   452 	}
   438 	}
   453 
   439 
   454 /*
   440 /*
   455 Helper function to get the boot count
   441 Helper function to get the startup boot count and maximum boot attempts limit 
   456 */
   442 from the central repository
   457 TInt CGsaStatePolicyStartup::GetBootupCountL()
   443 */
   458 	{
   444 void CGsaStatePolicyStartup::GetStartupCountAndMaxbootLimitL(TInt &aBootcount, TInt &aResetLimit)
   459 	RBuf bootupInfoPath;
   445 	{
   460 	CleanupClosePushL(bootupInfoPath);
   446 	CRepository* repository = CRepository::NewLC( KCRUidSsmStartupPolicy );
   461 	const TChar drive = RFs::GetSystemDriveChar();
   447 	User::LeaveIfError( repository->Get( KSsmStartupErrorResetLimit, aResetLimit ) );
   462 	TInt length = KBootUpFile().Length() + 1; /* for RFs::GetSystemDriveChar() */
   448 	DEBUGPRINT2( _L("Reset limit is %d"), aResetLimit );
   463 	bootupInfoPath.CreateL(length);
   449 	User::LeaveIfError( repository->Get( KSsmStartupErrorResetCounter, aBootcount ) );
   464 	bootupInfoPath.Append(drive);
   450 	DEBUGPRINT2( _L("Reset count is %d"), aBootcount );
   465 	bootupInfoPath.Append(KBootUpFile());
   451 	CleanupStack::Pop(repository);
   466 	TBool found = BaflUtils::FileExists(iFs, bootupInfoPath);
   452 	}
   467  	if(!found)
       
   468  		{
       
   469 		User::Leave(EBootupCountFileNotFound);
       
   470 		}
       
   471 
       
   472 	RFileReadStream file;
       
   473 	CleanupClosePushL(file);
       
   474 	User::LeaveIfError(file.Open(iFs, bootupInfoPath, EFileRead));
       
   475 	TInt bootCount = file.ReadUint8L();
       
   476 	CleanupStack::PopAndDestroy(&file);
       
   477 	CleanupStack::PopAndDestroy(&bootupInfoPath);
       
   478 	return bootCount;
       
   479 	}
       
   480