installationservices/swi/source/sisregistry/client/sisregistrywritablesession.cpp
changeset 0 ba25891c3a9e
child 25 7333d7932ef7
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 * sisregistry - restricted client registry session interface implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22  @released
       
    23  @internalTechnology
       
    24 */
       
    25 
       
    26 #include <s32mem.h>
       
    27 #include "sisregistrywritablesession.h"
       
    28 #include "sisregistryobject.h"
       
    29 #include "sisregistryclientserver.h"
       
    30 #include "application.h"
       
    31 #include "siscontroller.h"
       
    32 #include "sisinfo.h"
       
    33 #include "sisuid.h"
       
    34 #include "cleanuputils.h"
       
    35 #include "arrayutils.h"
       
    36 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    37 #include "swtypereginfo.h"
       
    38 #endif
       
    39 
       
    40 using namespace Swi;
       
    41 
       
    42 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    43 EXPORT_C void RSisRegistryWritableSession::CreateTransactionL()
       
    44 	{
       
    45 	User::LeaveIfError(SendReceive(ECreateTransaction));
       
    46 	}
       
    47 
       
    48 EXPORT_C void RSisRegistryWritableSession::CommitTransactionL()
       
    49 	{
       
    50 	User::LeaveIfError(SendReceive(ECommitTransaction));
       
    51 	}
       
    52 
       
    53 EXPORT_C void RSisRegistryWritableSession::RollbackTransactionL()
       
    54 	{
       
    55 	User::LeaveIfError(SendReceive(ERollbackTransaction));
       
    56 	}
       
    57 #endif
       
    58 
       
    59 void RSisRegistryWritableSession::AddEntryImplL(TInt aMessage,
       
    60 												const CApplication& aApplication,
       
    61 												const TDesC8& aController, 
       
    62 												TInt64 aTransactionID,
       
    63 												TIpcArgs& aIpcArgs)
       
    64 	{
       
    65 	CBufFlat* tempBuffer = CBufFlat::NewL(KDefaultBufferSize);
       
    66 	CleanupStack::PushL(tempBuffer);
       
    67 	
       
    68 	CSisRegistryObject* object = CSisRegistryObject::NewLC();
       
    69 	object->ProcessApplicationL(aApplication, aController);
       
    70 	
       
    71 	RBufWriteStream stream(*tempBuffer);
       
    72  	CleanupClosePushL(stream);
       
    73  	
       
    74 	object->ExternalizeL(stream);
       
    75 	
       
    76 	CleanupStack::PopAndDestroy(2, object); // stream
       
    77 	
       
    78 	// Now, create an HBufC8 from the stream buf's length, and copy 
       
    79 	// the stream buffer into this descriptor
       
    80 	HBufC8* buffer = HBufC8::NewLC(tempBuffer->Size());
       
    81 	TPtr8 ptr(buffer->Des());
       
    82 	tempBuffer->Read(0, ptr, tempBuffer->Size());
       
    83 	
       
    84 	TPckgC<TInt64> transactionID(aTransactionID);
       
    85 	
       
    86 	aIpcArgs.Set(0, &ptr);
       
    87 	aIpcArgs.Set(1, &transactionID);
       
    88 	aIpcArgs.Set(2, &aController);
       
    89 	
       
    90 	User::LeaveIfError(SendReceive(aMessage, aIpcArgs));
       
    91 	
       
    92 	CleanupStack::PopAndDestroy(2, tempBuffer); // buffer
       
    93 	}
       
    94 
       
    95 EXPORT_C void RSisRegistryWritableSession::AddEntryL(const CApplication& aApplication,
       
    96 													 const TDesC8& aController, 
       
    97 													 TInt64 aTransactionID)
       
    98 	{
       
    99 	TIpcArgs ipcArgs;
       
   100 	AddEntryImplL(EAddEntry, aApplication, aController, aTransactionID, ipcArgs);
       
   101 	}
       
   102 
       
   103 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   104 EXPORT_C void RSisRegistryWritableSession::AddEntryL(const CApplication& aApplication,
       
   105 													 const TDesC8& aController,
       
   106 													 const RPointerArray<CSoftwareTypeRegInfo>& aSwTypeRegInfoArray,
       
   107 													 TInt64 aTransactionID)
       
   108 	{
       
   109 	RBuf8 serializedArray;
       
   110 	serializedArray.CleanupClosePushL();
       
   111 	SoftwareTypeRegInfoUtils::SerializeArrayL(aSwTypeRegInfoArray, serializedArray);
       
   112 	TIpcArgs ipcArgs;
       
   113 	ipcArgs.Set(3, &serializedArray);
       
   114 
       
   115 	AddEntryImplL(EAddSoftwareTypeEntry, aApplication, aController, aTransactionID, ipcArgs);
       
   116 
       
   117 	CleanupStack::PopAndDestroy(&serializedArray);
       
   118 	}
       
   119 #endif
       
   120 
       
   121 void RSisRegistryWritableSession::UpdateEntryImplL(TInt aMessage,
       
   122 												   const CApplication& aApplication, 
       
   123 												   const TDesC8& aController, 
       
   124 												   TInt64 aTransactionID,
       
   125 												   TIpcArgs& aIpcArgs)
       
   126 	{
       
   127 	CSisRegistryObject* object;
       
   128 	
       
   129 	// create a buffer for the final extenalisation
       
   130 	CBufFlat* tempBuffer = CBufFlat::NewL(KDefaultBufferSize);
       
   131 	CleanupStack::PushL(tempBuffer);
       
   132 	
       
   133 	// check whether it is full or partial upgrade
       
   134 	if (aApplication.IsPartialUpgrade())
       
   135 		{
       
   136 		TUid uid = aApplication.ControllerL().Info().Uid().Uid();
       
   137 		TPckg<TUid> packageUid(uid);
       
   138 		// request the copy of the object across IPC
       
   139 		HBufC8* buffer = SendReceiveBufferLC(EGetEntry, packageUid);
       
   140 
       
   141 		// create a stream based on the buffer
       
   142 		RDesReadStream stream(*buffer);
       
   143 		CleanupClosePushL(stream);
       
   144 		
       
   145 		// reassemble the object from the stream
       
   146 		object = CSisRegistryObject::NewLC(stream);
       
   147 		CleanupStack::Pop(object);
       
   148 		
       
   149 		CleanupStack::PopAndDestroy(2, buffer); // buffer, stream
       
   150 		CleanupStack::PushL(object);
       
   151 		// update the entry using the application stuff
       
   152 		object->UpgradeApplicationL(aApplication, aController);
       
   153 		}
       
   154 	else
       
   155 		{
       
   156 		// create a new object
       
   157 		object = CSisRegistryObject::NewLC();
       
   158 		object->ProcessApplicationL(aApplication, aController);
       
   159 		}
       
   160 
       
   161 	// create a stream to extenalise to
       
   162 	RBufWriteStream stream(*tempBuffer);
       
   163  	CleanupClosePushL(stream);
       
   164 
       
   165 	object->ExternalizeL(stream);
       
   166 	
       
   167 	CleanupStack::PopAndDestroy(2, object); // stream
       
   168 	
       
   169 	// create an HBufC8 from the stream buf's length, and copy 
       
   170 	// the stream buffer into this descriptor
       
   171 	HBufC8* buffer = HBufC8::NewLC(tempBuffer->Size());
       
   172 	TPtr8 ptr(buffer->Des());
       
   173 	tempBuffer->Read(0, ptr, tempBuffer->Size());
       
   174 	
       
   175 	// pass the transasction Id
       
   176 	TPckgC<TInt64> transactionID(aTransactionID);
       
   177 	
       
   178 	aIpcArgs.Set(0, &ptr);
       
   179 	aIpcArgs.Set(1, &transactionID);
       
   180 	aIpcArgs.Set(2, &aController);
       
   181 	
       
   182 	User::LeaveIfError(SendReceive(aMessage, aIpcArgs));
       
   183 
       
   184 	CleanupStack::PopAndDestroy(2, tempBuffer); // buffer 
       
   185 	}
       
   186 
       
   187 EXPORT_C void RSisRegistryWritableSession::UpdateEntryL(const CApplication& aApplication, 
       
   188 														const TDesC8& aController, 
       
   189 														TInt64 aTransactionID)
       
   190 	{
       
   191 	TIpcArgs ipcArgs;
       
   192 	UpdateEntryImplL(EUpdateEntry, aApplication, aController, aTransactionID, ipcArgs);
       
   193 	}
       
   194 
       
   195 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   196 EXPORT_C void RSisRegistryWritableSession::UpdateEntryL(const CApplication& aApplication, 
       
   197 														const TDesC8& aController,
       
   198 														const RPointerArray<CSoftwareTypeRegInfo>& aSwTypeRegInfoArray,
       
   199 														TInt64 aTransactionID)
       
   200 	{
       
   201 	RBuf8 serializedArray;
       
   202 	serializedArray.CleanupClosePushL();
       
   203 	SoftwareTypeRegInfoUtils::SerializeArrayL(aSwTypeRegInfoArray, serializedArray);
       
   204 	TIpcArgs ipcArgs;
       
   205 	ipcArgs.Set(3, &serializedArray);
       
   206 	
       
   207 	UpdateEntryImplL(EUpdateSoftwareTypeEntry, aApplication, aController, aTransactionID, ipcArgs);
       
   208 	
       
   209 	CleanupStack::PopAndDestroy(&serializedArray);
       
   210 	}
       
   211 #endif
       
   212 
       
   213 EXPORT_C void RSisRegistryWritableSession::DeleteEntryL(const CSisRegistryPackage& aPackage, TInt64 aTransactionID)
       
   214 	{
       
   215 	TPckgC<TUid> packageUid(aPackage.Uid());
       
   216 	TPckgC<TInt64> transactionID(aTransactionID);
       
   217 
       
   218 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   219 	TPckgC<TInt> packageIndex(aPackage.Index());
       
   220 	User::LeaveIfError(SendReceive(EDeleteEntry, TIpcArgs(&packageUid, &packageIndex, &transactionID)));
       
   221 #else
       
   222 	User::LeaveIfError(SendReceive(EDeleteEntry, TIpcArgs(&packageUid, &aPackage.Name(), &aPackage.Vendor(), &transactionID)));
       
   223 #endif
       
   224 	}
       
   225 
       
   226 EXPORT_C void RSisRegistryWritableSession::AddDriveL(const TInt aDrive)
       
   227 	{
       
   228 	TPckgC<TInt> packageDrive(aDrive);
       
   229 	User::LeaveIfError(SendReceive(EAddDrive, TIpcArgs(&packageDrive)));	
       
   230 	}
       
   231 
       
   232 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   233 EXPORT_C void RSisRegistryWritableSession::RemoveDriveL(const TInt aDrive)
       
   234 	{
       
   235 	TPckgC<TInt> packageDrive(aDrive);
       
   236 	User::LeaveIfError(SendReceive(ERemoveDrive, TIpcArgs(&packageDrive)));	
       
   237 	}
       
   238 
       
   239 EXPORT_C void RSisRegistryWritableSession::RegenerateCacheL()
       
   240 	{
       
   241 	User::LeaveIfError(SendReceive(ERegenerateCache));
       
   242 	}
       
   243 #endif
       
   244 
       
   245 /**
       
   246 * Returns ETrue if any ROM stub in the filesystem has the package uid specified
       
   247 * in aPackageId 
       
   248 * With the addition of SA upgrades to ROM, a package may be both in ROM, upgraded 
       
   249 * on another drive and this method can be used to check for the presence 
       
   250 * of an upgraded ROM package.
       
   251 *
       
   252 *
       
   253 * @param aPackageId		Package Id to be searched in the ROM stub files.
       
   254 *
       
   255 * @return ETrue if it can find the aPackageId or aFileName in any of the ROM stub SIS.
       
   256 *         EFalse otherwise
       
   257 */
       
   258 
       
   259 EXPORT_C TBool RSisRegistryWritableSession::PackageExistsInRomL(const TUid& aPackageId)
       
   260 	{
       
   261 	TPckgBuf<TBool> present;	
       
   262 	TPckgC<TUid> tuid(aPackageId);
       
   263 	TInt returnCode = SendReceive(EPackageExistsInRom, TIpcArgs(&tuid, &present));
       
   264 	User::LeaveIfError(returnCode);
       
   265 		
       
   266 	return present();
       
   267 	}
       
   268 
       
   269 
       
   270 /**
       
   271 * Gets all the eclipsable file's entries from the ROM stub file of a ROM based package.
       
   272 *
       
   273 * @param aUid		Package UId to identify the right stub file.
       
   274 *
       
   275 * @param aFiles		A pointer array of file names to be populated.
       
   276 *
       
   277 */
       
   278 EXPORT_C void RSisRegistryWritableSession::GetFilesForRomApplicationL(const TUid& aUid, RPointerArray<HBufC>& aFiles)
       
   279 	{
       
   280 	TInt startingFile = 0;
       
   281 	TPckgBuf<TInt> filesCount;
       
   282 	TPckgC<TInt> pckgStartingFile(startingFile);
       
   283 	TStubExtractionMode operationMode = EGetCount;
       
   284 	
       
   285 	// Get the total file count.	
       
   286 	TPckgC<TUid> packageUid(aUid);
       
   287 	TPckgC<TStubExtractionMode> packageMode(operationMode);
       
   288 	
       
   289 	TInt result = SendReceive(EStubFileEntries, TIpcArgs(&packageUid, &packageMode, &filesCount));
       
   290 	User::LeaveIfError(result);	
       
   291 	
       
   292 	TInt totalFilesCount = filesCount();
       
   293 	operationMode = EGetFiles;	
       
   294 	
       
   295 	do
       
   296 		{	
       
   297 		HBufC8* buffer = HBufC8::NewLC(KDefaultBufferSize);
       
   298 	
       
   299 		TPtr8 pOutput(buffer->Des());
       
   300 		
       
   301 		// Fetch the files.	
       
   302 		TInt result=SendReceive(EStubFileEntries, TIpcArgs(&packageUid, &packageMode, &pckgStartingFile, &pOutput));
       
   303 		User::LeaveIfError(result);
       
   304 		
       
   305 		// create a stream based on the buffer
       
   306 		RDesReadStream stream(*buffer);
       
   307 		CleanupClosePushL(stream);
       
   308 		
       
   309 		// reassemble the array from the stream
       
   310 		InternalizePointerArrayL(aFiles, stream);
       
   311 		
       
   312 		CleanupStack::PopAndDestroy(2, buffer); // buffer, stream
       
   313 		startingFile = aFiles.Count();	
       
   314 		} while (startingFile < totalFilesCount);	
       
   315 	}
       
   316 
       
   317 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   318 EXPORT_C void RSisRegistryWritableSession::ActivateComponentL(TComponentId aComponentId)
       
   319 	{
       
   320 	SetComponentStateL(aComponentId, Usif::EActivated);
       
   321 	}
       
   322 
       
   323 EXPORT_C void RSisRegistryWritableSession::DeactivateComponentL(TComponentId aComponentId)
       
   324 	{
       
   325 	SetComponentStateL(aComponentId, Usif::EDeactivated);
       
   326 	}
       
   327 
       
   328 void RSisRegistryWritableSession::SetComponentStateL(TComponentId aComponentId, TScomoState aState)
       
   329 	{
       
   330 	TPckgC<TComponentId> packageComponentId(aComponentId);
       
   331 	TPckgC<TScomoState> packageState(aState);	
       
   332 	TInt returnCode = SendReceive(ESetComponentState, TIpcArgs(&packageComponentId, &packageState));
       
   333 	User::LeaveIfError(returnCode);
       
   334 	}
       
   335 #endif