installationservices/swi/source/swis/server/uninstallmachine.cpp
changeset 0 ba25891c3a9e
child 22 0817e13c927e
child 25 98b66e4fb0be
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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 "uninstallmachine.h"
       
    20 #include "uninstallationplanner.h"
       
    21 #include "uninstallationprocessor.h"
       
    22 #include "log.h"
       
    23 #include "sisregistrypackage.h"
       
    24 #include "sisregistryentry.h"
       
    25 #include "sisregistrysession.h"
       
    26 #include "plan.h"
       
    27 #include "swispubsubdefs.h"
       
    28 
       
    29 #include <s32mem.h>
       
    30 
       
    31 using namespace Swi;
       
    32 
       
    33 //
       
    34 // TUninstallState
       
    35 //
       
    36 
       
    37 CUninstallMachine::TUninstallState::TUninstallState(CUninstallMachine& aUninstallMachine)
       
    38 	: iUninstallMachine(aUninstallMachine)
       
    39 	{
       
    40 	}
       
    41 
       
    42 //
       
    43 // TRegistrationState
       
    44 //
       
    45 
       
    46 CUninstallMachine::TRegistrationState::TRegistrationState(
       
    47 	CUninstallMachine& aUninstallMachine)
       
    48 /**
       
    49 	Constructor.
       
    50  */
       
    51 :   CUninstallMachine::TUninstallState(aUninstallMachine)
       
    52 	{
       
    53 	}
       
    54 
       
    55 void CUninstallMachine::TRegistrationState::EnterL()
       
    56 /**
       
    57 	Send registration request to the SWI Observer and then activate the
       
    58 	installation machine.
       
    59  */
       
    60 	{
       
    61 	DEBUG_PRINTF(_L8("Uninstall Machine - Entering Registration State"));
       
    62 
       
    63 	//connect to the SWI Observer
       
    64 	User::LeaveIfError(iUninstallMachine.Observer().Connect());
       
    65 	
       
    66 	//Register to the SWI Observer; which completes this request 
       
    67 	//when the SWI Observer Processor is idle.
       
    68 	iUninstallMachine.Observer().Register(iUninstallMachine.iStatus);
       
    69 	iUninstallMachine.SetActive();
       
    70 	}
       
    71 
       
    72 CUninstallMachine::TState* CUninstallMachine::TRegistrationState::CompleteL()
       
    73 /**
       
    74 	Obtains the log file handle and its name from the SWI Observer.
       
    75 	Adds the log file to the transaction
       
    76  */
       
    77 	{
       
    78 	DEBUG_PRINTF(_L8("Uninstall Machine - Registration State complete"));
       
    79 	RBuf logFileName;
       
    80 	logFileName.CreateL(KMaxFileName);
       
    81 	logFileName.CleanupClosePushL();
       
    82 	
       
    83 	//Get created a log file and obtains its full name.
       
    84 	iUninstallMachine.Observer().GetFileHandleL(logFileName);
       
    85 
       
    86 	//Add the log file to the transaction
       
    87 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    88 	iUninstallMachine.TransactionSession().RegisterNewL(logFileName);
       
    89 #else
       
    90 	iUninstallMachine.IntegrityServicesL().AddL(logFileName);
       
    91 #endif
       
    92 
       
    93 	CleanupStack::PopAndDestroy(&logFileName);
       
    94 	// Get Controllers.
       
    95 	return static_cast<TState*>(&iUninstallMachine.iConfirmationState);
       
    96 	}
       
    97 	
       
    98 CUninstallMachine::TState* CUninstallMachine::TRegistrationState::ErrorL(TInt aCode)
       
    99 /**
       
   100 	If there is any error, closes the SWI Observer connection.
       
   101  */
       
   102 	{
       
   103 	DEBUG_PRINTF2(_L8("Uninstall Machine - Registration State failed with code '%d'"), aCode);
       
   104 	User::Leave(aCode);
       
   105 	return NULL;
       
   106 	}
       
   107 
       
   108 void CUninstallMachine::TRegistrationState::Cancel()
       
   109 /**
       
   110 	Cancels the registration request.
       
   111  */
       
   112 	{
       
   113 	DEBUG_PRINTF(_L8("Uninstall Machine - Registration State cancelled!"));
       
   114 	iUninstallMachine.Observer().CancelRegistration();	
       
   115 	}
       
   116 	
       
   117 //
       
   118 // TConfirmationState
       
   119 //
       
   120 
       
   121 CUninstallMachine::TConfirmationState::TConfirmationState(
       
   122 	CUninstallMachine& aUninstallMachine)
       
   123 	: CUninstallMachine::TUninstallState(aUninstallMachine)
       
   124 	{
       
   125 	}
       
   126 
       
   127 // Calls Uninstall dialog.
       
   128 void CUninstallMachine::TConfirmationState::EnterL()
       
   129 	{
       
   130 	DEBUG_PRINTF(_L8("Uninstall Machine - Entering Confirmation State"));
       
   131 	
       
   132 	// Construct a TAppInfo object for the dialog. For that we need app name, 
       
   133 	// vendor name, and version. The first two are already supplied in the 
       
   134 	// \e iPackage member which is a pointer to CSisRegistryPackage object. 
       
   135 	// Getting package version involves more work.
       
   136 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   137 	RSisRegistrySession regSession;
       
   138 	User::LeaveIfError(regSession.Connect());
       
   139 	CleanupClosePushL(regSession);
       
   140 #endif
       
   141 	RSisRegistryEntry regEntry;
       
   142 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   143 	User::LeaveIfError(regEntry.OpenL(iUninstallMachine.RegistryWrapper().RegistrySession(), *iUninstallMachine.iPackage));
       
   144 #else
       
   145 	User::LeaveIfError(regEntry.OpenL(regSession, *iUninstallMachine.iPackage));
       
   146 #endif
       
   147 	CleanupClosePushL(regEntry);
       
   148 	TVersion ver=regEntry.VersionL();
       
   149 	HBufC* localizedVendorName=regEntry.LocalizedVendorNameL();
       
   150 	CleanupStack::PushL(localizedVendorName);
       
   151 
       
   152 	// At last we have everything to construct TAppInfo object.
       
   153 	TAppInfo appInfo(iUninstallMachine.iPackage->Name(),
       
   154 		*localizedVendorName,ver);
       
   155 	
       
   156 	// Construct and execute uninstall dialog command.
       
   157 	CDisplayUninstall* cmd=CDisplayUninstall::NewLC(appInfo);
       
   158 	iUninstallMachine.UiHandler().ExecuteL(*cmd);
       
   159 	TBool rv=cmd->ReturnResult();
       
   160 	CleanupStack::PopAndDestroy(cmd);
       
   161 	
       
   162 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   163 	CleanupStack::PopAndDestroy(2, &regEntry); // regEntry, localizedVendorName
       
   164 #else
       
   165 	CleanupStack::PopAndDestroy(3, &regSession); // regEntry, localizedVendorName
       
   166 #endif
       
   167 	// Make the decision and leave if the user cancelled uninstallation.
       
   168 	if (!rv)
       
   169 		User::Leave(KErrCancel);
       
   170 	
       
   171 	// Continue uninstallation.	
       
   172 	iUninstallMachine.CompleteSelf();
       
   173 	iUninstallMachine.SetActive();
       
   174 	
       
   175 	// The user hasn't cancelled so mark the un-installation as confirmed. This
       
   176 	// will allow the registry cache to be regenerated further on during the
       
   177 	// un-installation process.
       
   178 	iUninstallMachine.iOperationConfirmed = ETrue;
       
   179 	}
       
   180 
       
   181 // The next state will be planning uninstallation.
       
   182 CUninstallMachine::TState* CUninstallMachine::TConfirmationState::CompleteL()
       
   183 	{
       
   184 	DEBUG_PRINTF(_L8("Uninstall Machine - Completed Confirmation State"));
       
   185 	return static_cast<TState*>(&iUninstallMachine.iPlanUninstallationState);
       
   186 	}
       
   187 
       
   188 CUninstallMachine::TState* CUninstallMachine::TConfirmationState::ErrorL(
       
   189 	TInt aCode)
       
   190 	{
       
   191 	DEBUG_PRINTF2(_L8("Uninstall Machine - Confimation State failed with code %d"), aCode);
       
   192 	User::Leave(aCode);
       
   193 	return NULL;
       
   194 	}
       
   195 
       
   196 void CUninstallMachine::TConfirmationState::Cancel()
       
   197 	{
       
   198 	}
       
   199 
       
   200 //
       
   201 // TPlanUninstallationState
       
   202 //
       
   203 
       
   204 CUninstallMachine::TPlanUninstallationState::TPlanUninstallationState(CUninstallMachine& aUninstallMachine)
       
   205 	: CUninstallMachine::TUninstallState(aUninstallMachine)
       
   206 	{
       
   207 	}
       
   208 
       
   209 void CUninstallMachine::TPlanUninstallationState::EnterL()
       
   210 	{
       
   211 	DEBUG_PRINTF(_L8("Uninstall Machine - Entering Uninstallation Planning State"));
       
   212 	
       
   213 	// Create result.
       
   214 	iUninstallMachine.iResult=CInstallationResult::NewL();
       
   215 	
       
   216 	// Call uninstallation planner and plan the uninstallation
       
   217 	iUninstallMachine.iPlanner=CUninstallationPlanner::NewL(
       
   218 		iUninstallMachine.UiHandler(), *iUninstallMachine.iResult);
       
   219 
       
   220 	// The following function may leave either because of an error or because 
       
   221 	// the user cancelled uninstallation (a dialog), in which case it notifies 
       
   222 	// the UI sothat we don't need to display anything (cancellation is not an
       
   223 	// error). See RunError() for more details.
       
   224 	iUninstallMachine.iPlanner->PlanUninstallationL(*iUninstallMachine.iPackage);
       
   225 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK	
       
   226 	iUninstallMachine.SetFinalProgressBarValue(iUninstallMachine.iPlanner->FinalProgressBarValue());
       
   227 #endif	
       
   228 	iUninstallMachine.iPlan=iUninstallMachine.iPlanner->TransferPlanOwnership();
       
   229 	iUninstallMachine.CompleteSelf();
       
   230 	iUninstallMachine.SetActive();
       
   231 	}
       
   232 
       
   233 // The next state will be interfacing with transaction support
       
   234 CUninstallMachine::TState* CUninstallMachine::TPlanUninstallationState::CompleteL()
       
   235 	{
       
   236 	DEBUG_PRINTF(_L8("Uninstall Machine - Completed Uninstallation Planning State"));
       
   237 	return static_cast<TState*>(&iUninstallMachine.iIntegritySupportState);
       
   238 	}
       
   239 
       
   240 CUninstallMachine::TState* CUninstallMachine::TPlanUninstallationState::ErrorL(TInt aCode)
       
   241 	{
       
   242 	DEBUG_PRINTF2(_L8("Uninstall Machine - Uninstallation Planning State failed with code %d"), aCode);
       
   243 	User::Leave(aCode);
       
   244 	return NULL;
       
   245 	}
       
   246 
       
   247 void CUninstallMachine::TPlanUninstallationState::Cancel()
       
   248 	{
       
   249 	}
       
   250 
       
   251 //
       
   252 // TIntegritySupportState
       
   253 //
       
   254 
       
   255 CUninstallMachine::TIntegritySupportState::TIntegritySupportState(
       
   256 	CUninstallMachine& aUninstallMachine)
       
   257 :   CUninstallMachine::TUninstallState(aUninstallMachine)
       
   258 	{
       
   259 	}
       
   260 
       
   261 void CUninstallMachine::TIntegritySupportState::EnterL()
       
   262 	{
       
   263 	DEBUG_PRINTF(_L8("Uninstall Machine - Entering Integrity Support State"));
       
   264 	
       
   265 	// create a processor
       
   266 	iUninstallMachine.iProcessor = CUninstallationProcessor::NewL(
       
   267 		*iUninstallMachine.iPlan, iUninstallMachine.UiHandler(),
       
   268 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   269 		iUninstallMachine.TransactionSession(), iUninstallMachine.RegistryWrapper(), 
       
   270 #else
       
   271 		iUninstallMachine.IntegrityServicesL(),
       
   272 #endif
       
   273 		iUninstallMachine.Observer());
       
   274 	
       
   275 	// execute the plan install files, update registry, all in one step
       
   276 	iUninstallMachine.iProcessor->ProcessPlanL(iUninstallMachine.iStatus);
       
   277 	
       
   278 	//run the RBS executables , before entering the processor state.
       
   279 	iUninstallMachine.iProcessor->RunBeforeShutdown();
       
   280 	iUninstallMachine.SetActive();
       
   281 	}
       
   282 
       
   283 CUninstallMachine::TState* 
       
   284 CUninstallMachine::TIntegritySupportState::CompleteL()
       
   285 	{
       
   286 	DEBUG_PRINTF(_L8("Uninstall Machine - Completed Integrity Support State"));
       
   287 	return static_cast<TState*>(&iUninstallMachine.iFinalState);
       
   288 	}
       
   289 	
       
   290 CUninstallMachine::TState* CUninstallMachine::TIntegritySupportState::ErrorL(
       
   291 	TInt aCode)
       
   292 	{
       
   293 	DEBUG_PRINTF2(_L8("Uninstall Machine - Integrity Support State failed with code %d"), aCode);
       
   294 	User::Leave(aCode);
       
   295 	return NULL;
       
   296 	}
       
   297 
       
   298 void CUninstallMachine::TIntegritySupportState::Cancel()
       
   299 	{
       
   300 	}
       
   301 
       
   302 //
       
   303 // TFinalState
       
   304 //
       
   305 
       
   306 CUninstallMachine::TFinalState::TFinalState(
       
   307 	CUninstallMachine& aUninstallMachine)
       
   308 :   CUninstallMachine::TUninstallState(aUninstallMachine)
       
   309 	{
       
   310 	}
       
   311 
       
   312 void CUninstallMachine::TFinalState::EnterL()
       
   313 	{
       
   314 	DEBUG_PRINTF(_L8("Uninstall Machine - Entering Final State"));
       
   315 	
       
   316 	TUid pubsubCategory;
       
   317 	pubsubCategory.iUid = KUidSystemCategoryValue;
       
   318 	TInt err = RProperty::Set(pubsubCategory, KUidSoftwareInstallKey, ESwisStatusSuccess | ESwisUninstall);
       
   319 	User::LeaveIfError(err);
       
   320 	
       
   321 	iUninstallMachine.CompleteSelf();
       
   322 	iUninstallMachine.SetActive();
       
   323 	}
       
   324 
       
   325 CUninstallMachine::TState* CUninstallMachine::TFinalState::CompleteL()
       
   326 	{
       
   327 	DEBUG_PRINTF(_L8("Uninstall Machine - Completed Final State"));
       
   328 	return NULL;
       
   329 	}
       
   330 	
       
   331 CUninstallMachine::TState* CUninstallMachine::TFinalState::ErrorL(
       
   332 	TInt aCode)
       
   333 	{
       
   334 	DEBUG_PRINTF2(_L8("Uninstall Machine - Final State failed with code %d"), aCode);
       
   335 	User::Leave(aCode);
       
   336 	return NULL;
       
   337 	}
       
   338 
       
   339 void CUninstallMachine::TFinalState::Cancel()
       
   340 	{
       
   341 	}
       
   342 
       
   343 //
       
   344 // CUninstallMachine
       
   345 //
       
   346 
       
   347 // Constructor, sets this pointer into the state objects
       
   348 CUninstallMachine::CUninstallMachine(const RMessage2& aMessage)
       
   349 :   CSwisStateMachine(aMessage),
       
   350 	iRegistrationState(*this),
       
   351 	iConfirmationState(*this),
       
   352     iPlanUninstallationState(*this),
       
   353     iIntegritySupportState(*this),
       
   354     iFinalState(*this)
       
   355 	{
       
   356 	}
       
   357 
       
   358 void CUninstallMachine::ConstructL()
       
   359 	{
       
   360 	DEBUG_PRINTF(_L8("Constructing new Uninstall Machine"));
       
   361 	
       
   362 	// Call base class' ConstructL() which inits transaction service
       
   363 	CSwisStateMachine::ConstructL();
       
   364 	
       
   365 	TInt length=Message().GetDesLengthL(0);
       
   366 	HBufC8* packageBuffer=HBufC8::NewMaxLC(length);
       
   367 	TPtr8 p=packageBuffer->Des();
       
   368 	
       
   369 	Message().ReadL(0, p); 
       
   370 	RMemReadStream readStream;
       
   371 	readStream.Open(p.Ptr(), length);
       
   372 	CleanupClosePushL(readStream);
       
   373 	
       
   374 	iPackage=CSisRegistryPackage::NewL(readStream);
       
   375 
       
   376 	CleanupStack::PopAndDestroy(2, packageBuffer);
       
   377 	}
       
   378 
       
   379 /*static*/ CUninstallMachine* CUninstallMachine::NewL(const RMessage2& aMessage)
       
   380 	{
       
   381 	CUninstallMachine* self=new(ELeave) CUninstallMachine(aMessage);
       
   382 	CleanupStack::PushL(self);
       
   383 	self->ConstructL();
       
   384 	CleanupStack::Pop(self);
       
   385 	return self;
       
   386 	}
       
   387 
       
   388 TInt CUninstallMachine::Start()
       
   389 	{
       
   390 	DEBUG_PRINTF(_L8("Starting Uninstall"));
       
   391 	return CSwisStateMachine::Start();
       
   392 	}
       
   393 
       
   394 // Delete objects, close connection to the servers
       
   395 CUninstallMachine::~CUninstallMachine()
       
   396 	{
       
   397 	DEBUG_PRINTF(_L8("Destroying Uninstall Machine"));
       
   398 	delete iPlan;
       
   399 	delete iPlanner;
       
   400 	delete iResult;
       
   401 	delete iProcessor;
       
   402 	delete iPackage;
       
   403 	}
       
   404 
       
   405 CUninstallMachine::TState* CUninstallMachine::FirstState()
       
   406 	{
       
   407 	return &iRegistrationState;
       
   408 	}
       
   409 
       
   410 // This is called from RunL() whenever a state leaves
       
   411 CUninstallMachine::TState* CUninstallMachine::ErrorOnStateEntryL(TInt aError)
       
   412 	{
       
   413 	return CurrentState()->ErrorL(aError);
       
   414 	}
       
   415 
       
   416 void CUninstallMachine::SignalCompletedL()
       
   417 	{
       
   418 	HandleInstallationEventL(iPlan, EEventCompletedUnInstall);
       
   419 	}
       
   420