installationservices/swi/source/sisregistry/server/sisregistryserversession.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
     1 /*
     2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    29 #include <connect/sbdefs.h>
    29 #include <connect/sbdefs.h>
    30 #include <miscutil.h>
    30 #include <miscutil.h>
    31 #include <swi/sistruststatus.h>
    31 #include <swi/sistruststatus.h>
    32 #include <swi/sisregistrylog.h>
    32 #include <swi/sisregistrylog.h>
    33 #include <scs/ipcstream.h>
    33 #include <scs/ipcstream.h>
    34 #include <startupdomainpskeys.h>
    34 
    35 #include <e32const.h>
    35 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    36 
       
    37 #include "sislauncherclient.h"
    36 #include "sislauncherclient.h"
    38 #include "swtypereginfo.h"
    37 #include "swtypereginfo.h"
       
    38 #endif
       
    39 
    39 #include "scrhelperutil.h"
    40 #include "scrhelperutil.h"
    40 #include "scrdbconstants.h"
    41 #include "scrdbconstants.h"
    41 #include "log.h"
    42 #include "log.h"
    42 #include "swi/siscontroller.h"
    43 #include "swi/siscontroller.h"
    43 #include "sisregistryserversession.h"
    44 #include "sisregistryserversession.h"
    63 #include "securitymanager.h"
    64 #include "securitymanager.h"
    64 #include "siscontrollerverifier.h"
    65 #include "siscontrollerverifier.h"
    65 #include "sisinstallblock.h"
    66 #include "sisinstallblock.h"
    66 #include "sisregistryfiledescription.h"
    67 #include "sisregistryfiledescription.h"
    67 #include "sisregistrywritablesession.h"  
    68 #include "sisregistrywritablesession.h"  
    68 #include "securitycheckutil.h"
       
    69 
    69 
    70 using namespace Swi;
    70 using namespace Swi;
    71 using namespace Usif;
    71 using namespace Usif;
    72 
    72 
    73 const TInt KUidHexLength = 8;
    73 const TInt KUidHexLength = 8;
    74 _LIT(KSWIRegFirstInitFile, "\\sys\\install\\sisregistry\\swiregfirstinit.log");
    74 _LIT(KSWIRegFirstInitFile, "\\sys\\install\\sisregistry\\swiregfirstinit.log");
    75 _LIT(KApparcRegFileNameFormat, "*10003a3f*");
       
    76 
    75 
    77 // Function to panic an offending client
    76 // Function to panic an offending client
    78 void CSisRegistrySession::PanicClient(const RMessagePtr2& aMessage, Swi::TSisRegistryPanic aPanic)
    77 void CSisRegistrySession::PanicClient(const RMessagePtr2& aMessage, Swi::TSisRegistryPanic aPanic)
    79 	{
    78 	{
    80 	aMessage.Panic(KSisRegistryShortName, aPanic);
    79 	aMessage.Panic(KSisRegistryShortName, aPanic);
    91 	iSystemDrive = iFs.GetSystemDrive();
    90 	iSystemDrive = iFs.GetSystemDrive();
    92 
    91 
    93 	// Create a session with the Software Component Registry
    92 	// Create a session with the Software Component Registry
    94 	User::LeaveIfError(iScrSession.Connect());
    93 	User::LeaveIfError(iScrSession.Connect());
    95 
    94 
    96 	iIsFirstInit = IsFirstInvocationL();
       
    97 	
       
    98 #ifdef __WINSCW__
       
    99 	_LIT_SECURE_ID(KAppArcSID, 0x10003A3F);
       
   100 	if (KAppArcSID.iId == iClientSid.iId)
       
   101 	    {
       
   102         DEBUG_PRINTF(_L8("SIS Registry Server: Init for a connection from AppArc"));
       
   103         ProcessApplicationsL();
       
   104 	    }
       
   105 	else
       
   106 	    {
       
   107         if (iIsFirstInit)
       
   108             {
       
   109             DEBUG_PRINTF2(_L8("SIS Registry Server: Init for a connection from SID 0x%X"), iClientSid.iId);
       
   110             ProcessRomStubsL();
       
   111             }
       
   112 	    }
       
   113 #else
       
   114 	TInt res = KErrNone;
    95 	TInt res = KErrNone;
   115 	TRAP(res , res = IsFirmwareUpdatedL());
    96 	TRAP(res , res = IsFirmwareUpdatedL());
   116 		
    97 	
   117 	if (iIsFirstInit || res)
    98 	if (IsFirstInvocationL() || res )
   118 		{
    99 		{
   119 		if (res)
   100 		isFwUpdated = ETrue;
   120 		    {
       
   121 		    iIsFwUpdated = ETrue;
       
   122 		    }
       
   123 
       
   124 		FirstInvocationInitL();
   101 		FirstInvocationInitL();
   125 		if (iIsFwUpdated)
   102 		}
   126 		    {
   103 		
   127 			TRAP(res, UpdateRecentFWVersionL());
   104     TRAP(res, UpdateRecentFWVersionL(););
   128 			if (res != KErrNone)
   105     if (res != KErrNone)
   129                 {
   106         {
   130                 DEBUG_PRINTF2(_L8("Updating recent Firmware Version failed with error code = %d."), res);
   107         // log that
   131                 }
   108         DEBUG_PRINTF2(_L8("Updating recent Firmware Version failed with error code = %d."), res);
   132 		    }		
   109         }
   133 		}
       
   134 #endif
       
   135 	}
   110 	}
   136 
   111 
   137 CSisRegistrySession::~CSisRegistrySession()
   112 CSisRegistrySession::~CSisRegistrySession()
   138 	{
   113 	{
   139 	Server().DropSession();
   114 	Server().DropSession();
   161 		}
   136 		}
   162 	CleanupStack::PopAndDestroy(&fileName);
   137 	CleanupStack::PopAndDestroy(&fileName);
   163 	return firstInvocation;
   138 	return firstInvocation;
   164 	}
   139 	}
   165 
   140 
   166 void CSisRegistrySession::ProcessRomStubsL()
       
   167     {
       
   168     DEBUG_PRINTF(_L8("SIS Registry Server - Starting processing of ROM Stub sis files"));
       
   169     iScrSession.CreateTransactionL();
       
   170     ProcessRomDriveL();
       
   171     iScrSession.CommitTransactionL();       
       
   172         
       
   173     // Create a file in <systemdrive>:\sys to mark a successful initialization
       
   174     // so that we don't come here again (unless firmware is upgraded in which case <systemdrive>:\sys 
       
   175     // should be cleaned
       
   176     RBuf fileName;
       
   177     CleanupClosePushL(fileName);
       
   178     fileName.CreateL(KMaxPath);
       
   179     TDriveUnit drive(iSystemDrive);
       
   180     fileName = drive.Name();
       
   181     fileName.Append(KSWIRegFirstInitFile);
       
   182     RFile file;
       
   183     CleanupClosePushL(file);
       
   184     file.Replace(iFs, fileName, EFileWrite | EFileShareAny);
       
   185     CleanupStack::PopAndDestroy(2, &fileName);  // file
       
   186     
       
   187     DEBUG_PRINTF(_L8("SIS Registry Server - Completed processing of ROM Stub sis files"));
       
   188     }
       
   189 
       
   190 void CSisRegistrySession::ProcessApplicationsL()
       
   191     {
       
   192     TComponentId compId = 0;
       
   193     DEBUG_PRINTF(_L8("SIS Registry Server - Deleteing all existing ROM applications."));
       
   194     ScrHelperUtil::DeleteApplicationEntriesL(iScrSession, compId);
       
   195     
       
   196     //Register all apps found in \private\10003a3f\apps
       
   197     TDriveUnit romDrive(SisRegistryUtil::SystemRomDrive());
       
   198     RBuf apparcRegFilePath;
       
   199     apparcRegFilePath.CreateL(romDrive.Name(), KMaxPath);
       
   200     CleanupClosePushL(apparcRegFilePath);
       
   201     apparcRegFilePath.Append(KApparcRegFilePath);
       
   202     
       
   203 	//Create a single transaction to register all in rom apps
       
   204 	iScrSession.CreateTransactionL();
       
   205 	RegisterAllAppL(apparcRegFilePath);
       
   206 
       
   207     //Register all apps found in \private\10003a3f\import\apps
       
   208     apparcRegFilePath = romDrive.Name();
       
   209     apparcRegFilePath.Append(KApparcRegFileImportPath);
       
   210     RegisterAllAppL(apparcRegFilePath);
       
   211     
       
   212 	//Register all apps found in UDA
       
   213 	TDriveUnit systemDrive(iSystemDrive);
       
   214 
       
   215 	//Register all apps found in <systemdrive>\private\10003a3f\apps
       
   216 	apparcRegFilePath = systemDrive.Name();	
       
   217 	apparcRegFilePath.Append(KApparcRegFilePath);
       
   218 	RegisterAllAppL(apparcRegFilePath);
       
   219 
       
   220 	//Register all apps found in <systemdrive>\private\10003a3f\import\apps
       
   221     apparcRegFilePath = systemDrive.Name();
       
   222     apparcRegFilePath.Append(KApparcRegFileImportPath);
       
   223     RegisterAllAppL(apparcRegFilePath);
       
   224 	
       
   225 	iScrSession.CommitTransactionL();    
       
   226 	
       
   227 	CleanupStack::PopAndDestroy(&apparcRegFilePath);
       
   228     
       
   229     DEBUG_PRINTF(_L8("SIS Registry Server - Completed processing of all existing ROM applications."));
       
   230     }
       
   231 
       
   232 // Does initialization required when run after very first boot of phone (or after firmware upgrade)
   141 // Does initialization required when run after very first boot of phone (or after firmware upgrade)
   233 // Method is only invoked when such a state is detected (only in device, NOT in emulator)
   142 // Method is only invoked when such a state is detected
   234 // Leaves behind a file in <systemdrive>:\sys to mark a successful initialization 
   143 // Leaves behind a file in <systemdrive>:\sys to mark a successful initialization 
   235 void CSisRegistrySession::FirstInvocationInitL()
   144 void CSisRegistrySession::FirstInvocationInitL()
   236 	{
   145 	{
   237 	// Add the ROM installed stub details to SCR
   146 	// Add the ROM installed stub details to SCR
   238 	// Create an SCR transaction, so that entries won't be added to the SCR if the function leaves
   147 	// Create an SCR transaction, so that entries won't be added to the SCR if the function leaves
   239     TInt value(EIdlePhase1NOK);
   148 	iScrSession.CreateTransactionL();
   240     TInt ret = RProperty::Get(KPSUidStartup, KPSIdlePhase1Ok, value);
   149 	ProcessRomDriveL();
   241 	
   150 	iScrSession.CommitTransactionL();
   242     TBool isFromSWIDaemon = EFalse;
   151 	// Create a file in <systemdrive>:\sys to mark a successful initialization
   243     _LIT_SECURE_ID(KSWIDaemonSID, 0x10202DCE);
   152 	// so that we don't come here again (unless firmware is upgraded in which case <systemdrive>:\sys 
   244     if (KSWIDaemonSID.iId == iClientSid.iId)
   153 	// should be cleaned
   245         { 
   154 	RBuf fileName;
   246         isFromSWIDaemon = ETrue;
   155 	CleanupClosePushL(fileName);
   247         }
   156 	fileName.CreateL(KMaxPath);
   248 	
   157 	TDriveUnit drive(iSystemDrive);
   249 	//If the image is NCP 'KPSUidStartup' property is not set, hence settig it explicitly for processing stubs
   158 	fileName = drive.Name();
   250 	if(ret == KErrNotFound)
   159 	fileName.Append(KSWIRegFirstInitFile);
   251 		{
   160 	RFile file;
   252 		DEBUG_PRINTF(_L8("SIS Registry Server - 'KPSUidStartup' property is not set"));
   161 	CleanupClosePushL(file);
   253 		value = EIdlePhase1Ok;
   162 	file.Replace(iFs, fileName, EFileWrite | EFileShareAny);
   254 		}
   163 	CleanupStack::PopAndDestroy(2, &fileName);	// file
   255 	else
       
   256 		{
       
   257 		DEBUG_PRINTF(_L8("SIS Registry Server - 'KPSUidStartup' property is set"));
       
   258 		}
       
   259 	if ((value == EIdlePhase1Ok || isFromSWIDaemon) && iIsFirstInit)
       
   260 	    {
       
   261         ProcessRomStubsL();
       
   262 	    }
       
   263 
       
   264 	if (iIsFwUpdated)
       
   265 	    {
       
   266 		// Delete the SisRegistry marker file
       
   267         RBuf fileName;
       
   268         CleanupClosePushL(fileName);
       
   269         fileName.CreateL(KMaxPath);
       
   270         TDriveUnit drive(iSystemDrive);
       
   271         fileName = drive.Name();
       
   272         fileName.Append(KSWIRegFirstInitFile);
       
   273         iFs.Delete(fileName);
       
   274         CleanupStack::PopAndDestroy(&fileName);
       
   275 
       
   276         ProcessApplicationsL();
       
   277 	    }
       
   278 	}
   164 	}
   279 
   165 
   280 //
   166 //
   281 // Handle a client request.
   167 // Handle a client request.
   282 // Leaving is handled by CSisRegistry::ServiceError() which reports
   168 // Leaving is handled by CSisRegistry::ServiceError() which reports
   444 		RegisterEntryL(aMessage, ETrue, EFalse);
   330 		RegisterEntryL(aMessage, ETrue, EFalse);
   445 		break;
   331 		break;
   446 	case EAddSoftwareTypeEntry:
   332 	case EAddSoftwareTypeEntry:
   447 		RegisterEntryL(aMessage, ETrue, ETrue);
   333 		RegisterEntryL(aMessage, ETrue, ETrue);
   448 		break;
   334 		break;
   449     case EAddAppRegEntry:
       
   450         AppRegInfoEntryL(aMessage);
       
   451         break;
       
   452     case EUpdateAppRegEntry:
       
   453         AppRegInfoEntryL(aMessage);
       
   454         break;
       
   455 	case EUpdateEntry:
   335 	case EUpdateEntry:
   456 		RegisterEntryL(aMessage, EFalse, EFalse);
   336 		RegisterEntryL(aMessage, EFalse, EFalse);
   457 		break;
   337 		break;
   458 	case EUpdateSoftwareTypeEntry:
   338 	case EUpdateSoftwareTypeEntry:
   459 		RegisterEntryL(aMessage, EFalse, ETrue);
   339 		RegisterEntryL(aMessage, EFalse, ETrue);
   512 	case ESignedBySuCert:
   392 	case ESignedBySuCert:
   513 		SubsessionL(aMessage.Int3()).SignedBySuCertRegistryEntryL(aMessage);
   393 		SubsessionL(aMessage.Int3()).SignedBySuCertRegistryEntryL(aMessage);
   514  		break;	
   394  		break;	
   515 	case ESetComponentState:
   395 	case ESetComponentState:
   516  		SetComponentStateL(aMessage);
   396  		SetComponentStateL(aMessage);
   517  		break;
   397  		break;	
   518 	case ESetComponentPresence:
       
   519 	    SetComponentPresenceL(aMessage);
       
   520 	    break;
       
   521 	case EIsFileRegistered:
   398 	case EIsFileRegistered:
   522  		IsFileRegisteredL(aMessage);
   399  		IsFileRegisteredL(aMessage);
   523  		break;			
   400  		break;			
   524 	case EComponentIdForUid:
   401 	case EComponentIdForUid:
   525 		GetComponentIdForUidL(aMessage);
   402 		GetComponentIdForUidL(aMessage);
   526 		break;
   403 		break;
   527 	case EComponentIdForPackage:
       
   528         GetComponentIdForPackageL(aMessage);
       
   529         break;
       
   530 	case EAppUidsForComponent:
       
   531 	    GetAppUidsForComponentL(aMessage);
       
   532         break;
       
   533 	case EComponentIdsForPackageUid:	    
       
   534         GetComponentIdsForUidL(aMessage);        
       
   535         break;
       
   536 	case EAddAppRegInfo:
       
   537 	    AddAppRegInfoL(aMessage);
       
   538 	    break;
       
   539 	case ERemoveAppRegInfo:
       
   540 	    RemoveAppRegInfoL(aMessage);
       
   541 	    break;
       
   542 	default:
   404 	default:
   543 		PanicClient(aMessage,EPanicIllegalFunction);
   405 		PanicClient(aMessage,EPanicIllegalFunction);
   544 		break;
   406 		break;
   545 		}
   407 		}
   546 	}
   408 	}
   689 	{
   551 	{
   690 	RIpcReadStream readStream;
   552 	RIpcReadStream readStream;
   691 	readStream.Open(aMessage, 3);
   553 	readStream.Open(aMessage, 3);
   692 	CleanupClosePushL(readStream);
   554 	CleanupClosePushL(readStream);
   693 	
   555 	
   694 	RCPointerArray<Usif::CSoftwareTypeRegInfo> swTypeRegInfoArray;
   556 	RCPointerArray<CSoftwareTypeRegInfo> swTypeRegInfoArray;
   695 	CleanupClosePushL(swTypeRegInfoArray);
   557 	CleanupClosePushL(swTypeRegInfoArray);
   696 	SoftwareTypeRegInfoUtils::UnserializeArrayL(readStream, swTypeRegInfoArray);
   558 	SoftwareTypeRegInfoUtils::UnserializeArrayL(readStream, swTypeRegInfoArray);
   697 	
   559 	
   698 	for (TInt i=0; i<swTypeRegInfoArray.Count(); ++i)
   560 	for (TInt i=0; i<swTypeRegInfoArray.Count(); ++i)
   699 		{
   561 		{
   700 		iScrSession.AddSoftwareTypeL(*swTypeRegInfoArray[i]);
   562 		const CSoftwareTypeRegInfo& info = *swTypeRegInfoArray[i];
       
   563 		const RPointerArray<CLocalizedSoftwareTypeName>& locSwTypeNames = info.LocalizedSoftwareTypeNames();
       
   564 		RCPointerArray<Usif::CLocalizedSoftwareTypeName> scrSwTypeNames;
       
   565 		CleanupClosePushL(scrSwTypeNames);
       
   566 		for (TInt i=0; i<locSwTypeNames.Count(); ++i)
       
   567 			{
       
   568 			scrSwTypeNames.AppendL(Usif::CLocalizedSoftwareTypeName::NewLC(locSwTypeNames[i]->Name(), locSwTypeNames[i]->Locale()));
       
   569 			CleanupStack::Pop();
       
   570 			}
       
   571 
       
   572 		DEBUG_PRINTF2(_L("Sis Registry Server - Adding software type: %S"), &info.UniqueSoftwareTypeName());
       
   573 
       
   574 		iScrSession.AddSoftwareTypeL(info.UniqueSoftwareTypeName(),
       
   575 									 info.SifPluginUid(),
       
   576 									 info.InstallerSecureId(),
       
   577 									 info.ExecutionLayerSecureId(),
       
   578 									 info.MimeTypes(),
       
   579 									 &scrSwTypeNames);
       
   580 		CleanupStack::PopAndDestroy(&scrSwTypeNames);
   701 		}
   581 		}
   702 	
   582 	
   703 	RBuf uniqueNames;
   583 	RBuf uniqueNames;
   704 	uniqueNames.CleanupClosePushL();
   584 	uniqueNames.CleanupClosePushL();
   705 	SoftwareTypeRegInfoUtils::SerializeUniqueSwTypeNamesL(swTypeRegInfoArray, uniqueNames);
   585 	SoftwareTypeRegInfoUtils::SerializeUniqueSwTypeNamesL(swTypeRegInfoArray, uniqueNames);
   785 			ScrHelperUtil::GetComponentL(iScrSession, compId, *existingObject);
   665 			ScrHelperUtil::GetComponentL(iScrSession, compId, *existingObject);
   786 	
   666 	
   787 			// DEF085506 fix. remove control files (Previous SA and any of PUs) also while SA upgrading.
   667 			// DEF085506 fix. remove control files (Previous SA and any of PUs) also while SA upgrading.
   788 			if (object->InstallType() == Sis::EInstInstallation)
   668 			if (object->InstallType() == Sis::EInstInstallation)
   789 				{
   669 				{
   790 				RemoveEntryL(compId);
   670 				RemoveEntryL(*existingObject);
   791 				RemoveCleanupInfrastructureL(*existingObject, stsSession);	
   671 				RemoveCleanupInfrastructureL(*existingObject, stsSession);	
   792 				}
   672 				}
   793 			else // PartialUpgarde case remove only registry file.
   673 			else // PartialUpgarde case remove only registry file.
   794 				{
   674 				{
   795 				// Essentially, this is an uninstall except we leave the controller file intact.
   675 				// Essentially, this is an uninstall except we leave the controller file intact.
   796 				RemoveEntryL(compId);
   676 				RemoveEntryL(*existingObject);
   797 				}
   677 				}
   798 			CleanupStack::PopAndDestroy(existingObject);
   678 			CleanupStack::PopAndDestroy(existingObject);
   799 			}
   679 			}
   800 		// get the current controller from client space
   680 		// get the current controller from client space
   801 		// check the size of the descriptor in client space
   681 		// check the size of the descriptor in client space
   914 	
   794 	
   915 	// transaction ID - ipc(2)
   795 	// transaction ID - ipc(2)
   916 	TInt64 transactionID;
   796 	TInt64 transactionID;
   917 	TPckg<TInt64> pkgTransactionID(transactionID);
   797 	TPckg<TInt64> pkgTransactionID(transactionID);
   918 	aMessage.ReadL(EIpcArgument2, pkgTransactionID);
   798 	aMessage.ReadL(EIpcArgument2, pkgTransactionID);
   919 		
   799 	
   920 	DeleteEntryL(*object, transactionID, ETrue);
   800 	// create a integrity service object
   921 	
   801 	Usif::RStsSession stssession;
   922  	CleanupStack::PopAndDestroy(object);
   802 	stssession.OpenTransactionL(transactionID);
       
   803 	CleanupClosePushL(stssession);
       
   804 	
       
   805 	RemoveEntryL(*object);
       
   806 	RemoveCleanupInfrastructureL(*object, stssession);
       
   807 
       
   808 	// If removal is for ROM upgrade type, after removing the existing registry entry set,
       
   809 	// regenerate the Registry Entry Cache. 
       
   810 	// If any of the ROM based stub doesn't have its registry set 
       
   811 	// in appropriate path, it will create them (SCR entry & . ctl) 
       
   812 	// from the ROM based stub sis file.	
       
   813 	if ((object->InstallType() == Sis::EInstInstallation || 
       
   814 		 object->InstallType() == Sis::EInstPartialUpgrade) &&	
       
   815 		SisRegistryUtil::RomBasedPackageL(object->Uid()))
       
   816 		{	
       
   817 		// Re-add the ROM installed stub details to SCR (only those missing will be added)
       
   818 		ProcessRomDriveL();
       
   819 		}
       
   820  	CleanupStack::PopAndDestroy(2, object);// STS 
   923 	
   821 	
   924 	aMessage.Complete(KErrNone);
   822 	aMessage.Complete(KErrNone);
   925 	}
   823 	}
   926 
       
   927 void CSisRegistrySession::DeleteEntryL(const CSisRegistryObject& aObject, TInt64 aTransactionId, TBool aCleanupRequired/*=ETrue*/)
       
   928     {
       
   929     // create a integrity service object
       
   930     Usif::RStsSession stssession;
       
   931     stssession.OpenTransactionL(aTransactionId);
       
   932     CleanupClosePushL(stssession);
       
   933         
       
   934     RemoveEntryL(aObject);
       
   935     RemoveCleanupInfrastructureL(aObject, stssession);
       
   936     
       
   937     // If removal is for ROM upgrade type, after removing the existing registry entry set,
       
   938     // regenerate the Registry Entry Cache. 
       
   939     // If any of the ROM based stub doesn't have its registry set 
       
   940     // in appropriate path, it will create them (SCR entry & . ctl) 
       
   941     // from the ROM based stub sis file.    
       
   942     if ((aObject.InstallType() == Sis::EInstInstallation || 
       
   943             aObject.InstallType() == Sis::EInstPartialUpgrade) &&  
       
   944                 SisRegistryUtil::RomBasedPackageL(aObject.Uid()) && 
       
   945                     aCleanupRequired)
       
   946         {   
       
   947         // Re-add the ROM installed stub details to SCR (only those missing will be added)
       
   948         ProcessRomDriveL();
       
   949         }    
       
   950     CleanupStack::PopAndDestroy(&stssession);
       
   951     }
       
   952 
   824 
   953 void CSisRegistrySession::OpenRegistryUidEntryL(const RMessage2& aMessage)
   825 void CSisRegistrySession::OpenRegistryUidEntryL(const RMessage2& aMessage)
   954 	{
   826 	{
   955 	// expects a UID as an arg 0
   827 	// expects a UID as an arg 0
   956 	TUid uid;
   828 	TUid uid;
  1058 
   930 
  1059 // Gets the total number of files in a stub file and all the entries as well.
   931 // Gets the total number of files in a stub file and all the entries as well.
  1060 // The output will be based on the request parameters (operational mode) sent as input.
   932 // The output will be based on the request parameters (operational mode) sent as input.
  1061 void CSisRegistrySession::RequestStubFileEntriesL(const RMessage2& aMessage)
   933 void CSisRegistrySession::RequestStubFileEntriesL(const RMessage2& aMessage)
  1062 	{
   934 	{
       
   935 	TBool stubNotFound(ETrue);
       
   936 	
  1063 	TUid tUid;	
   937 	TUid tUid;	
  1064 	TPckg<TUid> packageUid(tUid);
   938 	TPckg<TUid> packageUid(tUid);
  1065 	aMessage.ReadL(EIpcArgument0, packageUid, 0);
   939 	aMessage.ReadL(EIpcArgument0, packageUid, 0);
  1066 	
   940 	
  1067 	TStubExtractionMode tMode;
   941 	TStubExtractionMode tMode;
  1068 	TPckg<TStubExtractionMode> packageMode(tMode);
   942 	TPckg<TStubExtractionMode> packageMode(tMode);
  1069 	aMessage.ReadL(EIpcArgument1, packageMode, 0);
   943 	aMessage.ReadL(EIpcArgument1, packageMode, 0);
  1070 	
   944 	
  1071 	TInt startingFileNo = 0;
   945 	// Prepare the stub file path.
  1072 	if (tMode == EGetFiles)
   946 	TDriveUnit romDrive(EDriveZ);
  1073 	    {
   947 	RBuf romRegistryPath;
  1074         TPckg<TInt> start(startingFileNo);
   948 	romRegistryPath.CreateL(romDrive.Name(), KMaxPath);
  1075         aMessage.ReadL(EIpcArgument2, start, 0);
   949 	CleanupClosePushL(romRegistryPath);
  1076 	    }
   950 	romRegistryPath.Append(KPreInstalledPath);	
  1077 	
   951 
  1078 	TInt fileCount = 0;
   952 	RFs tFs;
  1079 	RPointerArray<HBufC> fileNames;
   953 	CDir* dir;
  1080 	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(fileNames);
   954 	
  1081 	                    
   955 	// Get stub files under the ROM stub directory (Z:\system\install\).
  1082 	TRAPD(errCode, GetStubFileInfoL(tUid, tMode, startingFileNo, fileCount, fileNames));
   956 	User::LeaveIfError(tFs.Connect());
  1083 	if (KErrNone == errCode)
   957 	CleanupClosePushL(tFs);
  1084 	    {
   958 		
  1085 	    if (tMode == EGetFiles)
   959 	TInt err = tFs.GetDir(romRegistryPath, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir);
  1086 	        {
   960 
  1087 	        // Stream via multiple IPC writes instead of
   961 	if (err == KErrNone)
  1088 	        // copying to a buffer and streaming from there.
   962 		{
  1089 	        RIpcWriteStream ipcstream;
   963 		CleanupStack::PushL(dir);	
  1090 	        ipcstream.Open(aMessage, EIpcArgument3);
   964 		TInt count(dir->Count());
  1091 	        CleanupClosePushL(ipcstream);
   965 		RBuf controllerFileName;
  1092 	        ExternalizePointerArrayL(fileNames,ipcstream);
   966 		controllerFileName.CreateL(KMaxFileName);
  1093 	        ipcstream.CommitL();
   967 		CleanupClosePushL(controllerFileName);
  1094 	        aMessage.Complete(KErrNone);
   968 		for (TInt index = 0; index < count; ++index)
  1095 	        CleanupStack::PopAndDestroy(&ipcstream);
   969 			{
  1096 	        }
   970 			controllerFileName = romRegistryPath;
  1097 	    else if (tMode == EGetCount)
   971 			controllerFileName.Append((*dir)[index].iName);
  1098 	        {
   972 
  1099 	        TPckgBuf<TInt> fileCnt(fileCount);
   973 			// Read the ROM stub controller
  1100 	        aMessage.WriteL(EIpcArgument2, fileCnt);
   974   			CFileSisDataProvider* fileProvider = CFileSisDataProvider::NewLC(tFs, controllerFileName);
  1101             aMessage.Complete(KErrNone);      
   975   			Swi::Sis::CController* stubController = NULL;
  1102 	        }
   976   			TRAPD(errCode, stubController = Swi::Sis::CController::NewL(*fileProvider));
  1103 	    }
   977   			if (errCode != KErrNone)
  1104 	else
   978 	  			{
  1105 	    {
   979 	  			// Ignore the broken stub file under the ROM stub directory.
  1106 	    aMessage.Complete(errCode);
   980 	  			DEBUG_PRINTF2(_L8("Sis Registry Server - Failed to read the stub controller. Error code %d."), errCode);
  1107 	    }
   981 	  			CleanupStack::PopAndDestroy(fileProvider);
  1108 	CleanupStack::PopAndDestroy();
   982 	  			continue;
  1109 	}
   983 	  			}
  1110 
   984   			CleanupStack::PushL(stubController);
  1111 void CSisRegistrySession::GetStubFilesL(const TDesC& aFileName, RPointerArray<HBufC>& aFileNames)
   985   			
  1112     {
   986   			// If the UID in a stub file matches the current package's UID,
  1113     // Read the ROM stub controller
   987   			// populate the list of eclipsable files from the same stub file.
  1114     CFileSisDataProvider* fileProvider = CFileSisDataProvider::NewLC(iFs, aFileName);
   988   			if ( stubController->Info().Uid().Uid() == tUid )
  1115     Swi::Sis::CController* stubController = NULL;
   989   				{
  1116     TRAPD(errCode, stubController = Swi::Sis::CController::NewL(*fileProvider));
   990   				stubNotFound = EFalse;
  1117     if (errCode != KErrNone)
   991   				const RPointerArray<Sis::CFileDescription>& depArray = stubController->InstallBlock().FileDescriptions();
  1118         {
   992   				// Get as many number of files as possible that can be accomodate in client allocated buffer.
  1119         // Ignore the broken stub file under the ROM stub directory.
   993   				if (tMode == EGetFiles)
  1120         DEBUG_PRINTF2(_L8("Sis Registry Server - Failed to read the stub controller. Error code %d."), errCode);
   994   					{
  1121         CleanupStack::PopAndDestroy(fileProvider);
   995   					TInt sizeRed = 0;
  1122         User::Leave(errCode);
   996   					TInt startingFileNo;	
  1123         }
   997 					TPckg<TInt> start(startingFileNo);
  1124     CleanupStack::PushL(stubController);
   998 					aMessage.ReadL(EIpcArgument2, start, 0);
  1125     const RPointerArray<Sis::CFileDescription>& filesArray = stubController->InstallBlock().FileDescriptions();
   999   						
  1126     TInt totalFileCount = filesArray.Count();
  1000   					RPointerArray<TPtrC> fileNames;
  1127     // Populate the files in to a temporary array.
  1001   					CleanupResetAndDestroy<RPointerArray<TPtrC> >::PushL(fileNames);
  1128     for(TInt fileCount = 0; fileCount < totalFileCount; ++fileCount )
  1002 
  1129         {
  1003   					TInt totalDepArrayCount = depArray.Count();
  1130         HBufC* fileName = filesArray[fileCount]->Target().Data().AllocLC();
  1004   					// Populate the files in to a temporary array.
  1131         // Adding drive letter of rom if not mentioned in stub sis file
  1005   					for(TInt fileCount = startingFileNo; fileCount < totalDepArrayCount; ++fileCount )
  1132         TPtr a=fileName->Des();
  1006   						{
  1133         if (a[0] == '!')
  1007   						sizeRed += depArray[fileCount]->Target().Data().Size();
  1134             {
  1008   						// If amount of data red exceeds the client buffer size, break reading.
  1135             TChar driveChar;
  1009   						if (sizeRed > KDefaultBufferSize)
  1136             User::LeaveIfError(iFs.DriveToChar(EDriveZ, driveChar));
  1010   							{
  1137             a[0] = driveChar;
  1011   							break;
  1138             }
  1012   							}
  1139 
  1013   							
  1140 		aFileNames.AppendL(fileName);
  1014   						// Only create a TPtrC when we know we have space available
  1141 		CleanupStack::Pop(fileName);
  1015   						TPtrC* fileName = new(ELeave) TPtrC(depArray[fileCount]->Target().Data());
  1142 		}
  1016   						CleanupStack::PushL(fileName);
  1143     CleanupStack::PopAndDestroy(2, fileProvider);
  1017   						fileNames.AppendL(fileName);
  1144     }
  1018   						CleanupStack::Pop(fileName);   						
  1145 
  1019 	  					}	  	
  1146 void CSisRegistrySession::GetStubFileInfoL(TUid aUid, TStubExtractionMode aMode, TInt aStartingFileNo, TInt& aFileCount, RPointerArray<HBufC>& aFileNames)
  1020   					// Stream via multiple IPC writes instead of
  1147     {
  1021   					// copying to a buffer and streaming from there.
  1148     TBool stubNotFound(ETrue);
  1022   					RIpcWriteStream ipcstream;
  1149     
  1023   					ipcstream.Open(aMessage, EIpcArgument3);
  1150     // Prepare the stub file path.
  1024   					CleanupClosePushL(ipcstream);
  1151     TDriveUnit romDrive(EDriveZ);
  1025   					ExternalizePointerArrayL(fileNames,ipcstream);
  1152     RBuf romRegistryPath;
  1026   					ipcstream.CommitL();
  1153     romRegistryPath.CreateL(romDrive.Name(), KMaxPath);
  1027   					aMessage.Complete(KErrNone);
  1154     CleanupClosePushL(romRegistryPath);
  1028   					CleanupStack::PopAndDestroy(&ipcstream);
  1155     romRegistryPath.Append(KPreInstalledPath);  
  1029   					CleanupStack::PopAndDestroy(&fileNames);					
  1156 
  1030   					}
  1157     RFs tFs;
  1031   				// If only the count needed, send the stub file's total entrie's count.
  1158     CDir* dir;
  1032   				else if (tMode == EGetCount)
  1159         
  1033   					{
  1160     // Get stub files under the ROM stub directory (Z:\system\install\).
  1034   					TPckgBuf<TInt> fileCount(depArray.Count());
  1161     User::LeaveIfError(tFs.Connect());
  1035 					aMessage.WriteL(EIpcArgument2, fileCount);
  1162     CleanupClosePushL(tFs);
  1036 					aMessage.Complete(KErrNone);					
  1163     
  1037   					}  				
  1164     TInt err = tFs.GetDir(romRegistryPath, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir);
  1038 	  			CleanupStack::PopAndDestroy(2, fileProvider);
  1165 
  1039 	  			break;	
  1166     if (err == KErrNone)
  1040   				}
  1167         {
  1041   			CleanupStack::PopAndDestroy(2, fileProvider);  		
  1168         CleanupStack::PushL(dir);   
  1042 			}
  1169         TInt count(dir->Count());
  1043 		CleanupStack::PopAndDestroy(2, dir); // controllerFileName
  1170         RBuf controllerFileName;
  1044 		// If the stub file itself not found, leave with the same error info'
  1171         controllerFileName.CreateL(KMaxFileName);
  1045 		if (stubNotFound)
  1172         CleanupClosePushL(controllerFileName);
  1046   			{
  1173         for (TInt index = 0; index < count; ++index)
  1047   			aMessage.Complete(KErrNotFound);
  1174             {
  1048   			}		
  1175             controllerFileName = romRegistryPath;
  1049 		}
  1176             controllerFileName.Append((*dir)[index].iName);
  1050 	else if(err != KErrPathNotFound)
  1177 
  1051 		{
  1178             // Read the ROM stub controller
  1052 		aMessage.Complete(err);		
  1179             CFileSisDataProvider* fileProvider = CFileSisDataProvider::NewLC(tFs, controllerFileName);
  1053 		}
  1180             Swi::Sis::CController* stubController = NULL;
  1054 	CleanupStack::PopAndDestroy(2, &romRegistryPath); // tFs
  1181             TRAPD(errCode, stubController = Swi::Sis::CController::NewL(*fileProvider));
  1055 	}
  1182             if (errCode != KErrNone)
       
  1183                 {
       
  1184                 // Ignore the broken stub file under the ROM stub directory.
       
  1185                 DEBUG_PRINTF2(_L8("Sis Registry Server - Failed to read the stub controller. Error code %d."), errCode);
       
  1186                 CleanupStack::PopAndDestroy(fileProvider);
       
  1187                 continue;
       
  1188                 }
       
  1189             CleanupStack::PushL(stubController);
       
  1190                 
       
  1191             // If the UID in a stub file matches the current package's UID,
       
  1192             // populate the list of eclipsable files from the same stub file.
       
  1193             if ( stubController->Info().Uid().Uid() == aUid )
       
  1194                 {
       
  1195                 stubNotFound = EFalse;
       
  1196                 const RPointerArray<Sis::CFileDescription>& filesArray = stubController->InstallBlock().FileDescriptions();
       
  1197                 // Get as many number of files as possible that can be accomodate in client allocated buffer.
       
  1198                 if (aMode == EGetFiles)
       
  1199                     {
       
  1200                     TInt sizeRed = 0;
       
  1201                     TInt totalFileCount = filesArray.Count();
       
  1202                     // Populate the files in to a temporary array.
       
  1203                     for(TInt fileCount = aStartingFileNo; fileCount < totalFileCount; ++fileCount )
       
  1204                         {
       
  1205                         sizeRed += filesArray[fileCount]->Target().Data().Size();
       
  1206                         // If amount of data red exceeds the client buffer size, break reading.
       
  1207                         if (sizeRed > KDefaultBufferSize)
       
  1208                             {
       
  1209                             break;
       
  1210                             }
       
  1211                                 
       
  1212                         // Only create a TPtrC when we know we have space available
       
  1213                         HBufC* fileName = filesArray[fileCount]->Target().Data().AllocLC();
       
  1214 						// Adding drive letter of rom if not mentioned in stub sis file
       
  1215                         TPtr a=fileName->Des();
       
  1216                         if (a[0] == '!')
       
  1217                             {
       
  1218                             TChar driveChar;
       
  1219                             User::LeaveIfError(iFs.DriveToChar(EDriveZ, driveChar));
       
  1220                             a[0] = driveChar;
       
  1221                             }                        
       
  1222                        
       
  1223                         aFileNames.AppendL(fileName);
       
  1224                         CleanupStack::Pop(fileName);                        
       
  1225                         } 
       
  1226                     }
       
  1227                 // If only the count needed, send the stub file's total entrie's count.
       
  1228                 else if (aMode == EGetCount)
       
  1229                     {
       
  1230                     aFileCount = filesArray.Count();
       
  1231                     }               
       
  1232                 CleanupStack::PopAndDestroy(2, fileProvider);
       
  1233                 break;  
       
  1234                 }
       
  1235             CleanupStack::PopAndDestroy(2, fileProvider);       
       
  1236             }
       
  1237         CleanupStack::PopAndDestroy(2, dir); // controllerFileName
       
  1238         // If the stub file itself not found, leave with the same error info'
       
  1239         
       
  1240         if (stubNotFound)
       
  1241             {  
       
  1242 			CleanupStack::PopAndDestroy(2, &romRegistryPath); // tFs          
       
  1243             User::Leave(KErrNotFound);
       
  1244             }       
       
  1245         }
       
  1246     else if(err != KErrPathNotFound)
       
  1247         {     
       
  1248 		CleanupStack::PopAndDestroy(2, &romRegistryPath); // tFs   
       
  1249 		User::Leave(err);
       
  1250         }
       
  1251 	CleanupStack::PopAndDestroy(2, &romRegistryPath); // tFs	
       
  1252     }
       
  1253 
  1056 
  1254 void CSisRegistrySession::RequestRegistryEntryL(const RMessage2& aMessage)
  1057 void CSisRegistrySession::RequestRegistryEntryL(const RMessage2& aMessage)
  1255 	{
  1058 	{
  1256     TUid uid; 
  1059     TUid uid; 
  1257 	TPckg<TUid> packageUid(uid);
  1060 	TPckg<TUid> packageUid(uid);
  1269 	CleanupStack::PopAndDestroy(object);
  1072 	CleanupStack::PopAndDestroy(object);
  1270 	}
  1073 	}
  1271 
  1074 
  1272 void CSisRegistrySession::AddDriveL(const RMessage2& aMessage)
  1075 void CSisRegistrySession::AddDriveL(const RMessage2& aMessage)
  1273 	{
  1076 	{
  1274 	TInt addedDrive;
  1077 	TInt drive;
  1275 	TPckg<TInt> pkgDrive(addedDrive);
  1078 	TPckg<TInt> pkgDrive(drive);
  1276 	aMessage.ReadL(EIpcArgument0, pkgDrive);
  1079 	aMessage.ReadL(EIpcArgument0, pkgDrive);
  1277 
  1080 
  1278 	DEBUG_PRINTF2(_L8("Sis Registry Server - Removable drive %d added."), addedDrive);
  1081 	DEBUG_PRINTF2(_L8("Sis Registry Server - Removable drive %d added."), drive);
  1279 	    
  1082 
  1280 	// Get the drive character.
       
  1281 	TChar drive;
       
  1282 	User::LeaveIfError(iFs.DriveToChar(addedDrive, drive));
       
  1283 	TUint driveChar(drive);
       
  1284 	    
       
  1285 	// Retrieve drive info.
       
  1286 	TDriveInfo driveInfo;
       
  1287 	User::LeaveIfError(iFs.Drive(driveInfo, addedDrive));
       
  1288 #ifndef __WINSCW__	   
       
  1289 	if(driveInfo.iDriveAtt & KDriveAttLogicallyRemovable)
       
  1290 #endif	    
       
  1291 	    {
       
  1292 	    /*
       
  1293 	    In case a logically removable drive is added,
       
  1294 	    Look for the presence of the first boot marker file corresponding to it in the sisregistry private
       
  1295 	    folder in C drive. If absent, assume first boot and create the marker file. 
       
  1296 	    Also added a marker file in the <drive>\sys\install directory which would be used to detect a format. 
       
  1297 	         
       
  1298 	    Subsequent boots would look for the drive format marker to check if a format has occured and delete
       
  1299 	    the registry entries.
       
  1300 	    */
       
  1301 	    
       
  1302 	    // Create first boot marker path.
       
  1303 	    _LIT(KFirstBootMarkerFilePath, "%c:%SfirstBootMarkerFileFor%c");
       
  1304 	    RBuf privatePath;
       
  1305 		privatePath.CreateL(KMaxPath);
       
  1306 	    CleanupClosePushL(privatePath);
       
  1307 	    User::LeaveIfError(iFs.PrivatePath(privatePath));
       
  1308 
       
  1309 	    RBuf firstBootMarkerFilePath;
       
  1310 		firstBootMarkerFilePath.CreateL(KMaxPath);
       
  1311 	    CleanupClosePushL(firstBootMarkerFilePath);
       
  1312 
       
  1313 	    TChar systemDrive = RFs::GetSystemDriveChar();
       
  1314 	    firstBootMarkerFilePath.Format(KFirstBootMarkerFilePath, static_cast<TUint>(systemDrive), &privatePath, driveChar); 
       
  1315 	        
       
  1316 	    // Create drive format marker path.
       
  1317 	    _LIT(KFormatMarkerPath, "%c:\\sys\\install\\formatMarkerFile");
       
  1318 	    
       
  1319 		RBuf formatMarkerPath;
       
  1320 		formatMarkerPath.CreateL(KMaxPath);
       
  1321 	    CleanupClosePushL(formatMarkerPath);
       
  1322 		formatMarkerPath.Format(KFormatMarkerPath, driveChar); 
       
  1323 	       
       
  1324 		// The drive marker files are marked hidden and read-only.
       
  1325         TUint fileAttributes = KEntryAttReadOnly | KEntryAttHidden;
       
  1326 
       
  1327 	    if(!SisRegistryUtil::FileExistsL(iFs, firstBootMarkerFilePath))
       
  1328 	        {
       
  1329 	        // First boot detected. Add the first boot marker file as well as the format marker on the drive.
       
  1330 	        SisRegistryUtil::CreateFileWithAttributesL(iFs, firstBootMarkerFilePath);
       
  1331 	        TRAPD(err,SisRegistryUtil::CreateFileWithAttributesL(iFs, formatMarkerPath, fileAttributes);)
       
  1332 			if (err != KErrNone && err != KErrAlreadyExists)
       
  1333 				{
       
  1334 				User::Leave(err);
       
  1335 				}   
       
  1336 	        }
       
  1337 	    else
       
  1338 	        {
       
  1339 	        // Subsequent boot. Check for the presence of a marker file <drive>\sys\install directory.
       
  1340 	        // If absent, assume format.
       
  1341 	        if(!SisRegistryUtil::FileExistsL(iFs, formatMarkerPath))
       
  1342 	            {
       
  1343 	            DriveFormatDetectedL(TDriveUnit(addedDrive));
       
  1344 	            //Add missing format marker file
       
  1345 	            SisRegistryUtil::CreateFileWithAttributesL(iFs, formatMarkerPath, fileAttributes);
       
  1346 	            }           
       
  1347 	        }
       
  1348 		CleanupStack::PopAndDestroy(3, &privatePath);
       
  1349 	    }
       
  1350 	    
       
  1351 	// Find flagging controllers for non-preinstalled packages on
  1083 	// Find flagging controllers for non-preinstalled packages on
  1352 	// this drive and do cleanup if necessary
  1084 	// this drive and do cleanup if necessary
  1353 	ProcessRemovableDriveL(addedDrive);
  1085 	ProcessRemovableDriveL(drive);
  1354 
  1086 
  1355 	aMessage.Complete(KErrNone);
  1087 	aMessage.Complete(KErrNone);
  1356 	}
  1088 	}
  1357 
  1089 
  1358 void CSisRegistrySession::RequestSidToPackageL(const RMessage2& aMessage)
  1090 void CSisRegistrySession::RequestSidToPackageL(const RMessage2& aMessage)
  1360 	TUid sid; 
  1092 	TUid sid; 
  1361 	TPckg<TUid> executableSid(sid);
  1093 	TPckg<TUid> executableSid(sid);
  1362 	
  1094 	
  1363 	aMessage.ReadL(EIpcArgument0, executableSid);
  1095 	aMessage.ReadL(EIpcArgument0, executableSid);
  1364 
  1096 
  1365 	// Retrieve the component Id's list for the Sid.
  1097 	// componentId and index of the first matching Sid in CompSID<index> array gets populated 
  1366 	RArray<TComponentId> componentIdList;
  1098 	// by call to GetCompIdAndCompSidIndexL().The value of index is redundant here.
  1367 	CleanupClosePushL(componentIdList);
  1099 	TComponentId componentId = 0;
  1368 	
  1100 	TInt index = 0;
  1369 	GetComponentIdsForSidL(sid, componentIdList);
  1101 	GetCompIdAndCompSidIndexL(sid, componentId, index);
  1370 	
  1102 	
  1371 	if(componentIdList.Count() == 0)
  1103 	if(componentId == KErrNotFound)
  1372 		{
  1104 		{
  1373 		User::Leave(KErrNotFound);
  1105 		User::Leave(KErrNotFound);
  1374 		}
  1106 		}
  1375 		
  1107 		
  1376 	CSisRegistryPackage *package = NULL;
  1108 	CSisRegistryPackage *package = NULL;
  1377 	ScrHelperUtil::ReadFromScrL(iScrSession, componentIdList[0], package);
  1109 	ScrHelperUtil::ReadFromScrL(iScrSession, componentId, package);
  1378 	CleanupStack::PushL(package);
  1110 	CleanupStack::PushL(package);
  1379 	
  1111 	
  1380 	DEBUG_PRINTF5(_L("Sis Registry Server - SID 0x%08x is owned by package UID: 0x%08x, Name: %S, Vendor: %S."),
  1112 	DEBUG_PRINTF5(_L("Sis Registry Server - SID 0x%08x is owned by package UID: 0x%08x, Name: %S, Vendor: %S."),
  1381 		sid.iUid, package->Uid().iUid, &(package->Name()), &(package->Vendor()));
  1113 		sid.iUid, package->Uid().iUid, &(package->Name()), &(package->Vendor()));
  1382 	
  1114 	
  1383 	SisRegistryUtil::SendDataL(aMessage, *package, EIpcArgument1);
  1115 	SisRegistryUtil::SendDataL(aMessage, *package, EIpcArgument1);
  1384 	CleanupStack::PopAndDestroy(2, &componentIdList);
  1116 	CleanupStack::PopAndDestroy(package);
  1385 	
  1117 	
  1386 	}
  1118 	}
  1387 
  1119 
  1388 void CSisRegistrySession::RequestSidToFileNameL(const RMessage2& aMessage)
  1120 void CSisRegistrySession::RequestSidToFileNameL(const RMessage2& aMessage)
  1389 	{
  1121 	{
  1390 	TInt thirdParameter; 
  1122 	TInt thirdParameter; 
       
  1123 	TDriveUnit expectedDrive;
  1391 	TUid sid;
  1124 	TUid sid;
  1392 	TPckg<TUid> fileSid(sid);
  1125 	TPckg<TUid> fileSid(sid);
  1393 
  1126 
  1394 	// Obtain the sid from argument slot 0 from the client
  1127 	// Obtain the sid from argument slot 0 from the client
  1395 	aMessage.ReadL(EIpcArgument0, fileSid);
  1128 	aMessage.ReadL(EIpcArgument0, fileSid);
  1398 	// This parameter will be set to -1 if user did not specified a drive with this request.
  1131 	// This parameter will be set to -1 if user did not specified a drive with this request.
  1399 	thirdParameter = aMessage.Int2(); 
  1132 	thirdParameter = aMessage.Int2(); 
  1400 
  1133 
  1401 	// Obtain the componentId and array index of CompSID<index> custom property matching a given aSid.
  1134 	// Obtain the componentId and array index of CompSID<index> custom property matching a given aSid.
  1402 	TComponentId componentId = 0;
  1135 	TComponentId componentId = 0;
  1403 	HBufC* fileName = SidToFileNameL(sid, componentId, thirdParameter);
  1136 	TInt index = 0;
       
  1137 	GetCompIdAndCompSidIndexL(sid, componentId, index, thirdParameter);
  1404 	
  1138 	
  1405 	if(componentId == KErrNotFound)
  1139 	if(componentId == KErrNotFound)
  1406 		{
  1140 		{
  1407 		User::Leave(KErrNotFound);
  1141 		User::Leave(KErrNotFound);
  1408 		}
  1142 		}
  1409 	
  1143 
       
  1144   	// retrieve the CompSidFileName property value , based on the index obtained.
       
  1145   	TBuf<KSmlBufferSize> compSidFileName(KEmptyString);
       
  1146   	compSidFileName.Format(KCompSidFileNameFormat, index);
       
  1147 		
       
  1148 	HBufC* fileName = GetStrPropertyValueL(iScrSession, componentId, compSidFileName);
  1410 	CleanupStack::PushL(fileName);
  1149 	CleanupStack::PushL(fileName);
  1411 	DEBUG_PRINTF3(_L("Sis Registry Server - SID 0x%08x maps to file '%S'."),
  1150 	DEBUG_PRINTF3(_L("Sis Registry Server - SID 0x%08x maps to file '%S'."),
  1412 		sid.iUid, fileName);
  1151 		sid.iUid, fileName);
  1413 	
  1152 	
  1414 	// Send the filename back to the client in argument slot 1
  1153 	// Send the filename back to the client in argument slot 1
  1481 		} 
  1220 		} 
  1482 		
  1221 		
  1483 	TPckgC<Usif::TComponentId> componentIdPckg(componentId);
  1222 	TPckgC<Usif::TComponentId> componentIdPckg(componentId);
  1484 	aMessage.WriteL(EIpcArgument1, componentIdPckg);
  1223 	aMessage.WriteL(EIpcArgument1, componentIdPckg);
  1485 	aMessage.Complete(KErrNone);
  1224 	aMessage.Complete(KErrNone);
  1486 	}	
  1225 	}
  1487 
  1226 	
  1488 void CSisRegistrySession::RequestHashL(const RMessage2& aMessage)
  1227 void CSisRegistrySession::RequestHashL(const RMessage2& aMessage)
  1489 	{
  1228 	{
  1490 	// get file name
  1229 	// get file name
  1491 	TUint srcLen = aMessage.GetDesLengthL(EIpcArgument0);
  1230 	TUint srcLen = aMessage.GetDesLengthL(EIpcArgument0);
  1492 	HBufC* fileName = HBufC::NewLC(srcLen);
  1231 	HBufC* fileName = HBufC::NewLC(srcLen);
  1539 	{
  1278 	{
  1540 	TPckgBuf<TUid> uid;
  1279 	TPckgBuf<TUid> uid;
  1541 	aMessage.ReadL(EIpcArgument0, uid);
  1280 	aMessage.ReadL(EIpcArgument0, uid);
  1542 	
  1281 	
  1543 	TBool isPresent = EFalse;
  1282 	TBool isPresent = EFalse;
  1544 	RArray<TComponentId> componentIdList;
  1283 	TComponentId componentId = 0;
  1545 	CleanupClosePushL(componentIdList);
  1284 	TInt index = 0;
  1546 	
  1285 	
  1547 	// If the supplied SID is present in SCR, then a call to GetComponentIdsForSidL succeeds.
  1286 	// If the supplied SID is present in SCR, then a call to GetCompIdAndCompSidIndexL succeeds.
  1548 	// Else componentIdList would be empty.	
  1287 	// Else the componenetId will result in KErrNotFound.	
  1549 	GetComponentIdsForSidL(uid(), componentIdList);
  1288 	GetCompIdAndCompSidIndexL(uid(), componentId, index);
  1550 	
  1289 	if(componentId != KErrNotFound)
  1551 	if(componentIdList.Count() != 0)
       
  1552 		{
  1290 		{
  1553 		isPresent = ETrue;
  1291 		isPresent = ETrue;
  1554 		}
  1292 		}
  1555 	CleanupStack::PopAndDestroy(&componentIdList);
  1293 
  1556 	DEBUG_CODE_SECTION(
  1294 	DEBUG_CODE_SECTION(
  1557 		if (isPresent)
  1295 		if (isPresent)
  1558 			{
  1296 			{
  1559 			DEBUG_PRINTF2(_L8("Sis Registry Server - SID 0x%08x is present in registry."),
  1297 			DEBUG_PRINTF2(_L8("Sis Registry Server - SID 0x%08x is present in registry."),
  1560 				uid().iUid);
  1298 				uid().iUid);
  1641 	aMessage.ReadL(EIpcArgument1, pkgState, 0);
  1379 	aMessage.ReadL(EIpcArgument1, pkgState, 0);
  1642 	iScrSession.SetScomoStateL(pkgComponentId(), pkgState());
  1380 	iScrSession.SetScomoStateL(pkgComponentId(), pkgState());
  1643 	aMessage.Complete(KErrNone);
  1381 	aMessage.Complete(KErrNone);
  1644 	}
  1382 	}
  1645 
  1383 
  1646 void CSisRegistrySession::SetComponentPresenceL(const RMessage2& aMessage)
       
  1647     {
       
  1648     TPckgBuf<Usif::TComponentId> componentId;
       
  1649     TPckgBuf<TBool> componentPresence;
       
  1650     aMessage.ReadL(EIpcArgument0, componentId, 0);
       
  1651     aMessage.ReadL(EIpcArgument1, componentPresence, 0);
       
  1652     iScrSession.SetIsComponentPresentL(componentId(), componentPresence());
       
  1653     aMessage.Complete(KErrNone);
       
  1654     }
       
  1655 
       
  1656 // Helper methods
  1384 // Helper methods
  1657 
  1385 
  1658 TBool CSisRegistrySession::IsRegisteredL(const TUid& aUid)
  1386 TBool CSisRegistrySession::IsRegisteredL(const TUid& aUid)
  1659 	{
  1387 	{
  1660 	return ScrHelperUtil::IsUidPresentL(iScrSession, aUid);
  1388 	return ScrHelperUtil::IsUidPresentL(iScrSession, aUid);
  1710 TBool CSisRegistrySession::IsRegisteredL(const TUid& aUid, const TDesC& aPackageName)
  1438 TBool CSisRegistrySession::IsRegisteredL(const TUid& aUid, const TDesC& aPackageName)
  1711 	{
  1439 	{
  1712 	return ScrHelperUtil::IsUidAndNamePresentL(iScrSession, aUid, aPackageName);
  1440 	return ScrHelperUtil::IsUidAndNamePresentL(iScrSession, aUid, aPackageName);
  1713 	}
  1441 	}
  1714 
  1442 
  1715 
       
  1716 void CSisRegistrySession::RemoveEntryL(const TComponentId aCompId)
       
  1717     {
       
  1718     iScrSession.DeleteApplicationEntriesL(aCompId);
       
  1719     iScrSession.DeleteComponentL(aCompId);
       
  1720     }
       
  1721 
       
  1722 void CSisRegistrySession::RemoveEntryL(const CSisRegistryPackage& aPackage)
  1443 void CSisRegistrySession::RemoveEntryL(const CSisRegistryPackage& aPackage)
  1723 	{
  1444 	{
  1724 	DEBUG_PRINTF4(_L("Sis Registry Server - Removing the entry from Software Component Registry of package : UID: 0x%08x, Name: %S, Vendor: %S ."),
  1445 	DEBUG_PRINTF4(_L("Sis Registry Server - Removing the entry from Software Component Registry of package : UID: 0x%08x, Name: %S, Vendor: %S ."),
  1725 			aPackage.Uid().iUid, &aPackage.Name(), &aPackage.Vendor());
  1446 			aPackage.Uid().iUid, &aPackage.Name(), &aPackage.Vendor());
  1726 
  1447 
  1731 		//if aPackage is not present in the database , then display the message and leave
  1452 		//if aPackage is not present in the database , then display the message and leave
  1732 		DEBUG_PRINTF4(_L("Component Entry : UID: 0x%08x, Name: %S, Vendor: %S , not found in Software Component Registry"),
  1453 		DEBUG_PRINTF4(_L("Component Entry : UID: 0x%08x, Name: %S, Vendor: %S , not found in Software Component Registry"),
  1733 			aPackage.Uid().iUid, &aPackage.Name(), &aPackage.Vendor());
  1454 			aPackage.Uid().iUid, &aPackage.Name(), &aPackage.Vendor());
  1734 		User::Leave(KErrNotFound);
  1455 		User::Leave(KErrNotFound);
  1735 		}
  1456 		}
  1736 	
  1457 
  1737 	RemoveEntryL(compId);
  1458 	iScrSession.DeleteComponentL(compId);
  1738 	}
  1459 	}
  1739 
  1460 
  1740 void CSisRegistrySession::RemoveCleanupInfrastructureL(const CSisRegistryObject& aObject, RStsSession& aStsSession)
  1461 void CSisRegistrySession::RemoveCleanupInfrastructureL(const CSisRegistryObject& aObject, RStsSession& aStsSession)
  1741 	{
  1462 	{
  1742 	DEBUG_PRINTF(_L8("Sis Registry Server - Removing cleanup infrastructure."));
  1463 	DEBUG_PRINTF(_L8("Sis Registry Server - Removing cleanup infrastructure."));
  1905 		}
  1626 		}
  1906 	
  1627 	
  1907 	// Store the SIS Registry Object in to the Software Component Registry.
  1628 	// Store the SIS Registry Object in to the Software Component Registry.
  1908 	TComponentId compId = 0;
  1629 	TComponentId compId = 0;
  1909 	ScrHelperUtil::AddComponentL(iScrSession, compId, aObject, aOpType);
  1630 	ScrHelperUtil::AddComponentL(iScrSession, compId, aObject, aOpType);
  1910 	
       
  1911 	
       
  1912 	
       
  1913 	// Set SCOMO state to activated - when SWI Registry supports de-activation, should be changed accordingly
  1631 	// Set SCOMO state to activated - when SWI Registry supports de-activation, should be changed accordingly
  1914 	iScrSession.SetScomoStateL(compId, EActivated);
  1632 	iScrSession.SetScomoStateL(compId, EActivated);
  1915 	
  1633 	
  1916 	return compId;
  1634 	return compId;
  1917 	}
  1635 	}
  1918 	
  1636 	
  1919 void CSisRegistrySession::AddAppsFromStubL(TComponentId aCompId, const TDesC& aFileName)
       
  1920     {
       
  1921     RPointerArray<HBufC> romFiles;
       
  1922     CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(romFiles);
       
  1923     GetStubFilesL(aFileName, romFiles);
       
  1924     RPointerArray<HBufC> apparcRegFiles;
       
  1925     CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(apparcRegFiles);
       
  1926        
       
  1927     for(TInt i=0; i< romFiles.Count(); i++)
       
  1928         {
       
  1929         TInt ret = romFiles[i]->Match(KApparcRegFileNameFormat);
       
  1930         
       
  1931         TBuf<100> fileName(*romFiles[i]);
       
  1932         if (KErrNotFound != ret)
       
  1933             {
       
  1934             HBufC* file = romFiles[i]->AllocL();
       
  1935             apparcRegFiles.Append(file);
       
  1936             }
       
  1937         }
       
  1938              
       
  1939 	const TInt appCount = apparcRegFiles.Count();
       
  1940 	if (appCount)
       
  1941 		{
       
  1942 		RSisLauncherSession launcher;
       
  1943 		CleanupClosePushL(launcher);
       
  1944 		User::LeaveIfError(launcher.Connect());
       
  1945 		RFs fs;
       
  1946 		CleanupClosePushL(fs);
       
  1947 		User::LeaveIfError(fs.Connect());
       
  1948 		User::LeaveIfError(fs.ShareProtected());
       
  1949 		RArray<TLanguage> appLanguages;
       
  1950 		CleanupClosePushL(appLanguages);
       
  1951 		appLanguages.AppendL(User::Language());
       
  1952     
       
  1953 		for (TInt i=0; i<appCount; ++i)
       
  1954 			{
       
  1955 			TInt bufLen = apparcRegFiles[i]->Size();
       
  1956 			HBufC* buf = HBufC::NewLC(bufLen);
       
  1957 			TPtr appFile = buf->Des();
       
  1958 			appFile.Format(_L("%S"), apparcRegFiles[i]);
       
  1959 			appFile.Replace(0, 1, _L("z"));
       
  1960 			
       
  1961 			RFile file;
       
  1962 			CleanupClosePushL(file);
       
  1963 			User::LeaveIfError(file.Open(fs, appFile, EFileRead));
       
  1964 			Usif::CApplicationRegistrationData* appRegData  = launcher.SyncParseResourceFileL(file, appLanguages);
       
  1965 			CleanupStack::PushL(appRegData);
       
  1966 			
       
  1967 			TRAPD(err, ScrHelperUtil::AddApplicationEntryL(iScrSession, aCompId, *appRegData));
       
  1968 			if (err == KErrAlreadyExists)
       
  1969                 {
       
  1970                 // Delete the existing application entry, which is not associated with any package 
       
  1971                 ScrHelperUtil::DeleteApplicationEntryL(iScrSession, appRegData->AppUid());
       
  1972                 ScrHelperUtil::AddApplicationEntryL(iScrSession, aCompId, *appRegData);
       
  1973                 }
       
  1974 			
       
  1975 			CleanupStack::PopAndDestroy(appRegData);
       
  1976 			CleanupStack::PopAndDestroy(2, buf);
       
  1977 			}
       
  1978 		CleanupStack::PopAndDestroy(3, &launcher); 
       
  1979 		}
       
  1980 	CleanupStack::PopAndDestroy(2, &romFiles);        
       
  1981     }
       
  1982 
       
  1983 void CSisRegistrySession::AddControllerL(const CSisRegistryObject& aObject, 
  1637 void CSisRegistrySession::AddControllerL(const CSisRegistryObject& aObject, 
  1984 							RStsSession& aStsSession, const TDesC8& aBuffer, const TInt aDrive)		
  1638 							RStsSession& aStsSession, const TDesC8& aBuffer, const TInt aDrive)		
  1985 	{
  1639 	{
  1986 	HBufC* name = SisRegistryUtil::BuildControllerFileNameLC(aObject.Uid(), aObject.Index(), aObject.ControllerInfo().Count()-1, aDrive);
  1640 	HBufC* name = SisRegistryUtil::BuildControllerFileNameLC(aObject.Uid(), aObject.Index(), aObject.ControllerInfo().Count()-1, aDrive);
  1987 	DEBUG_PRINTF2(_L("Sis Registry Server - Installing controller file to '%S'."), name);
  1641 	DEBUG_PRINTF2(_L("Sis Registry Server - Installing controller file to '%S'."), name);
  2441 		}
  2095 		}
  2442 
  2096 
  2443 	CleanupStack::PopAndDestroy(&entryList);
  2097 	CleanupStack::PopAndDestroy(&entryList);
  2444 	}
  2098 	}
  2445 
  2099 
  2446 void CSisRegistrySession::GetComponentIdsForSidL(TUid aSid, RArray<TComponentId>& aComponentIds)
  2100 void CSisRegistrySession::GetCompIdAndCompSidIndexL(const TUid& aSid, TComponentId& aComponentId, TInt& aIndex, TInt aExpectedDrive)
  2447 	{   
  2101 	{
  2448     _LIT(KComponentSidPropertyRegex, "CompSid%");
       
  2449 	CComponentFilter* componentFilter = CComponentFilter::NewLC();
  2102 	CComponentFilter* componentFilter = CComponentFilter::NewLC();
  2450 	componentFilter->SetSoftwareTypeL(KSoftwareTypeNative);	
  2103 	componentFilter->SetSoftwareTypeL(KSoftwareTypeNative);	
  2451 	componentFilter->AddPropertyL(KComponentSidPropertyRegex, static_cast<TUint>(aSid.iUid), CComponentFilter::ELike, CComponentFilter::EEqual);		
  2104 	componentFilter->AddPropertyL(KCompSidsPresent, 1);
  2452 	
  2105 		
  2453 	// Retrieve all component Id's 
  2106 	// Retrieve the componentId of all the components with SIDs from the SCR.
  2454 	iScrSession.GetComponentIdsL(aComponentIds, componentFilter);
  2107 	RArray<TComponentId> componentIdList;
  2455 	
  2108 	CleanupClosePushL(componentIdList);
  2456 	CleanupStack::PopAndDestroy(componentFilter);
  2109 	iScrSession.GetComponentIdsL(componentIdList, componentFilter);
  2457 	}
  2110 		
  2458 	
  2111 	TInt componentCount = componentIdList.Count();
  2459 
  2112 	RArray<TUid> sidArray;
  2460 HBufC* CSisRegistrySession::SidToFileNameL(TUid aSid, TComponentId& aComponentId, TInt aExpectedDrive)
  2113 	CleanupClosePushL(sidArray);
  2461     {    
  2114 	TBool sidMatchFound = EFalse;
  2462     aComponentId = KErrNotFound;
  2115 
  2463     RArray<TComponentId> componentIdList;
  2116 	for(TInt i = 0; i < componentCount && !sidMatchFound; ++i)
  2464     CleanupClosePushL(componentIdList);
  2117 		{
  2465     
  2118 		TComponentId componentId = componentIdList[i];
  2466     // Retrieve the component Id's.
  2119 		sidArray.Reset();
  2467     GetComponentIdsForSidL(aSid, componentIdList);
  2120 		ScrHelperUtil::InternalizeSidArrayL(iScrSession, componentId, sidArray);
  2468     
  2121 		
  2469     if(componentIdList.Count() == 0)
  2122 		// index of the first matching SID in the array.
  2470         {
  2123 		aIndex = sidArray.Find(aSid);	
  2471         CleanupStack::PopAndDestroy(&componentIdList);
  2124 		if(aIndex == KErrNotFound)
  2472         return NULL;
  2125 			continue;
  2473         }
  2126 
  2474     
  2127 		// If the search is narrowed to a particular drive, get the file name and check whether it matches the drive
  2475     RArray<TUid> sidArray;
  2128 		if (aExpectedDrive != -1)
  2476     CleanupClosePushL(sidArray);
  2129 			{
  2477     TInt index(0);
  2130 			TBuf<KSmlBufferSize> compSidFileName(KEmptyString);
  2478     TBuf<KSmlBufferSize> compSidFileName(KEmptyString);
  2131 			compSidFileName.Format(KCompSidFileNameFormat, aIndex);
  2479     HBufC* fileName = NULL;
       
  2480     
       
  2481     
       
  2482     if(aExpectedDrive == -1)
       
  2483         {
       
  2484         // No drive specified, just return the first component Id and the corresponding Sid index.  
       
  2485         aComponentId = componentIdList[0];
       
  2486         sidArray.Reset();
       
  2487         ScrHelperUtil::InternalizeSidArrayL(iScrSession, aComponentId, sidArray);
       
  2488         index = sidArray.Find(aSid);   
       
  2489         compSidFileName.Format(KCompSidFileNameFormat, index);   
       
  2490         fileName = GetStrPropertyValueL(iScrSession, aComponentId, compSidFileName); 
       
  2491         }
       
  2492     else
       
  2493         {
       
  2494         // If the search is narrowed to a particular drive, get the file name and check whether it matches the drive
       
  2495     
       
  2496         for(TInt i=0; i<componentIdList.Count(); ++i)
       
  2497             {
       
  2498             sidArray.Reset();
       
  2499             ScrHelperUtil::InternalizeSidArrayL(iScrSession, componentIdList[i], sidArray);
       
  2500             index = sidArray.Find(aSid);
       
  2501             
       
  2502             compSidFileName.Format(KCompSidFileNameFormat, index); 
       
  2503             fileName = GetStrPropertyValueL(iScrSession, componentIdList[i], compSidFileName);   
       
  2504 			CleanupStack::PushL(fileName);
       
  2505           
       
  2506             if (fileName->Length() == 0)
       
  2507                 {
       
  2508 				 CleanupStack::PopAndDestroy(fileName);
       
  2509                  fileName = NULL;
       
  2510                  continue;
       
  2511                 }
       
  2512             
       
  2513             TInt drive; 
       
  2514             User::LeaveIfError(RFs::CharToDrive((*fileName)[0], drive));
       
  2515             if(drive != aExpectedDrive)
       
  2516                 {
       
  2517                 CleanupStack::PopAndDestroy(fileName);
       
  2518                 fileName = NULL;
       
  2519                 continue;
       
  2520                 }        
       
  2521             
       
  2522             //Expected drive found !
       
  2523             aComponentId = componentIdList[i];
       
  2524 			CleanupStack::Pop(fileName);
       
  2525             break;
       
  2526             }     
       
  2527         } 	
       
  2528 	CleanupStack::PopAndDestroy(2, &componentIdList);	
       
  2529 	return fileName; // Ownership with caller.
       
  2530 			
  2132 			
       
  2133 			HBufC* fileName = GetStrPropertyValueL(iScrSession, componentId, compSidFileName);
       
  2134 			CleanupStack::PushL(fileName);			
       
  2135 			if (fileName->Length() == 0)
       
  2136 				{
       
  2137 				CleanupStack::PopAndDestroy(fileName);
       
  2138 				continue;
       
  2139 				}
       
  2140 			TInt drive; 
       
  2141  			User::LeaveIfError(RFs::CharToDrive((*fileName)[0], drive));
       
  2142  			if(drive != aExpectedDrive)
       
  2143  				{
       
  2144 				CleanupStack::PopAndDestroy(fileName);
       
  2145  				continue;
       
  2146  				}			
       
  2147 			CleanupStack::PopAndDestroy(fileName);
       
  2148 			}
       
  2149 			
       
  2150 		aComponentId = componentId;
       
  2151 		sidMatchFound = ETrue;
       
  2152 		}
       
  2153 	
       
  2154 	CleanupStack::PopAndDestroy(3, componentFilter); // componentIdList and sidArray.
       
  2155 	if(!sidMatchFound)
       
  2156 		{
       
  2157 		// No component contains aSid.
       
  2158 		aComponentId = KErrNotFound;
       
  2159 		}
  2531 	}
  2160 	}
  2532 
  2161 
  2533 TBool CSisRegistrySession::ModifiableL(const TDesC& aFileName)
  2162 TBool CSisRegistrySession::ModifiableL(const TDesC& aFileName)
  2534 	{
  2163 	{
  2535 	// Retrieve the list of components which contain aFileName.
  2164 	// Retrieve the list of components which contain aFileName.
  2706 	
  2335 	
  2707 
  2336 
  2708 	TBool overwriteRegEntry = EFalse;
  2337 	TBool overwriteRegEntry = EFalse;
  2709 	
  2338 	
  2710     TBool isStubRegistered = IsRegisteredL(object->Uid(), object->Name());
  2339     TBool isStubRegistered = IsRegisteredL(object->Uid(), object->Name());
  2711     if ( iIsFirstInit && isStubRegistered )
  2340     if ( isFwUpdated && isStubRegistered )
  2712 	    {
  2341 	    {
  2713 		TComponentId compId = ScrHelperUtil::GetComponentIdL(iScrSession, object->Uid(), object->Index());
  2342 		TComponentId compId = ScrHelperUtil::GetComponentIdL(iScrSession, object->Uid(), object->Index());
  2714 		TSisPackageTrust trustStatus;
  2343 		TSisPackageTrust trustStatus;
  2715 		trustStatus = static_cast<TSisPackageTrust>(GetIntPropertyValueL(iScrSession, compId, KCompTrust,  EFalse, KDefaultTrustValue));
  2344 		trustStatus = static_cast<TSisPackageTrust>(GetIntPropertyValueL(iScrSession, compId, KCompTrust,  EFalse, KDefaultTrustValue));
       
  2345 		//ScrHelperUtil::ReadFromScrL(iSession.ScrSession(), iComponentId, trustStatus);
  2716 	    if ( ESisPackageBuiltIntoRom == trustStatus )
  2346 	    if ( ESisPackageBuiltIntoRom == trustStatus )
  2717 	        {
  2347 	        {
  2718             DEBUG_PRINTF2(_L8("Sis Registry Server - Attempting to delete registry entry 0x%08x as a firmware update detected"), object->Uid().iUid);
  2348             DEBUG_PRINTF2(_L8("Sis Registry Server - Attempting to delete registry entry 0x%08x as a firmware update detected"), object->Uid().iUid);
  2719             
  2349             
  2720             // If the component being removed has registered software types, unregister them now.
  2350             // If the component being removed has registered software types, unregister them now.
  2721             // This operation deletes MIME types mapping from AppArc and therefore is not transactional.
  2351             // This operation deletes MIME types mapping from AppArc and therefore is not transactional.
  2722             UnregisterSoftwareTypesL(compId);
  2352             UnregisterSoftwareTypesL(compId);
       
  2353 
       
  2354             CSisRegistryObject* object = CSisRegistryObject::NewLC();
       
  2355             ScrHelperUtil::GetComponentL(iScrSession, compId, *object);
       
  2356 
       
  2357             DEBUG_PRINTF4(_L("Sis Registry Server - Removing package registry entry for UID: %08x, Name: %S, Vendor %S."),
       
  2358                 object->Uid().iUid, &(object->Name()), &(object->Vendor()));
  2723                 
  2359                 
  2724             RemoveEntryL(compId);           
  2360             RemoveEntryL(*object);           
  2725 
  2361 
       
  2362             CleanupStack::PopAndDestroy();
  2726             overwriteRegEntry = ETrue;
  2363             overwriteRegEntry = ETrue;
  2727 	        }
  2364 	        }
  2728 	    }
  2365 	    }
  2729 
  2366 
  2730 
  2367 
  2731 	if ( !isStubRegistered || overwriteRegEntry )
  2368 	if ( !isStubRegistered || overwriteRegEntry )
  2732 		{
  2369 		{
  2733 		// update cache or just call refresh
  2370 		// update cache or just call refresh
  2734 		TComponentId compId = AddEntryL(*object, Usif::EScrCompHidden); // EScrCompHidden is supplied not to create any log for the ROM controller on the SCR side.
  2371 		AddEntryL(*object, Usif::EScrCompHidden); // EScrCompHidden is supplied not to create any log for the ROM controller on the SCR side.
  2735 		AddAppsFromStubL(compId, aFileName);
       
  2736 		
  2372 		
  2737 		// store a copy of the controller
  2373 		// store a copy of the controller
  2738 		HBufC* name = SisRegistryUtil::BuildControllerFileNameLC(object->Uid(), object->Index(),
  2374 		HBufC* name = SisRegistryUtil::BuildControllerFileNameLC(object->Uid(), object->Index(),
  2739 				0);
  2375 				0);
  2740 		
  2376 		
  2996     return EFalse;
  2632     return EFalse;
  2997     }
  2633     }
  2998 
  2634 
  2999 void CSisRegistrySession::UpdateRecentFWVersionL()
  2635 void CSisRegistrySession::UpdateRecentFWVersionL()
  3000     {
  2636     {
  3001     //Write a cache of the ROM version to a separate stream
  2637         //Write a cache of the ROM version to a separate stream
  3002     //Build the filename for the cache file
  2638         //Build the filename for the cache file
  3003     TChar sysDrive = RFs::GetSystemDriveChar();
  2639         TChar sysDrive = RFs::GetSystemDriveChar();
  3004     TInt maxSizeofFileName = KROMVersionStringCacheDir().Length() + KROMVersionStringCacheFileName().Length() + 1;
  2640         TInt maxSizeofFileName = KROMVersionStringCacheDir().Length() + KROMVersionStringCacheFileName().Length() + 1;
  3005     RBuf romVersionCacheFileName;
  2641         RBuf romVersionCacheFileName;
  3006     romVersionCacheFileName.CreateL(maxSizeofFileName);
  2642         romVersionCacheFileName.CreateL(maxSizeofFileName);
  3007     romVersionCacheFileName.CleanupClosePushL();
  2643         romVersionCacheFileName.CleanupClosePushL();
  3008     romVersionCacheFileName.Append(sysDrive);
  2644         romVersionCacheFileName.Append(sysDrive);
  3009     romVersionCacheFileName.Append(KROMVersionStringCacheDir());
  2645         romVersionCacheFileName.Append(KROMVersionStringCacheDir());
  3010     romVersionCacheFileName.Append(KROMVersionStringCacheFileName());
  2646         romVersionCacheFileName.Append(KROMVersionStringCacheFileName());
  3011     
  2647         
  3012     iFs.MkDirAll(romVersionCacheFileName);
  2648         //Read the length & value from it, if any.
  3013     //Read the length & value from it, if any.
  2649         RFileWriteStream romVerStream;
  3014     RFileWriteStream romVerStream;
  2650         User::LeaveIfError(romVerStream.Replace(iFs,romVersionCacheFileName,EFileWrite));
  3015     User::LeaveIfError(romVerStream.Replace(iFs,romVersionCacheFileName,EFileWrite));
  2651         CleanupClosePushL(romVerStream);
  3016     CleanupClosePushL(romVerStream);
  2652         TBuf<KInfoBufLength> version;
  3017     TBuf<KInfoBufLength> version;
  2653         GetSWVersion(version);
  3018     GetSWVersion(version);
  2654 
  3019 
  2655         // Write even if SysUtil returns err since all conditions are taken care during restore.
  3020     // Write even if SysUtil returns err since all conditions are taken care during restore.
  2656         romVerStream.WriteUint32L(version.Length());
  3021     romVerStream.WriteUint32L(version.Length());
  2657         romVerStream.WriteL(version);
  3022     romVerStream.WriteL(version);
  2658         CleanupStack::PopAndDestroy(2); //romVerStream, romVersionCacheFileName
  3023     CleanupStack::PopAndDestroy(2); //romVerStream, romVersionCacheFileName
       
  3024     }
  2659     }
  3025 
  2660 
  3026 void CSisRegistrySession::AppRegInfoEntryL(const RMessage2& aMessage)
       
  3027     {
       
  3028     Usif::TComponentId componentId = aMessage.Int0();
       
  3029 
       
  3030 	RIpcReadStream stream;
       
  3031 	CleanupClosePushL(stream);
       
  3032 	stream.Open(aMessage, 1);
       
  3033 	CApplicationRegistrationData *applicationData = CApplicationRegistrationData::NewL(stream);
       
  3034 	CleanupStack::PopAndDestroy(&stream);
       
  3035 	CleanupStack::PushL(applicationData);
       
  3036 
       
  3037     TRAPD(err, ScrHelperUtil::AddApplicationEntryL(iScrSession, componentId, *applicationData));
       
  3038     if (err == KErrAlreadyExists)
       
  3039         {
       
  3040         //Delete the existing application
       
  3041         ScrHelperUtil::DeleteApplicationEntryL(iScrSession, applicationData->AppUid());
       
  3042         err = KErrNone;
       
  3043         TRAP(err, ScrHelperUtil::AddApplicationEntryL(iScrSession, componentId, *applicationData));
       
  3044         }
       
  3045     aMessage.Complete(err);
       
  3046     CleanupStack::PopAndDestroy(applicationData);
       
  3047     }
       
  3048 
       
  3049 void CSisRegistrySession::GetComponentIdForPackageL(const RMessage2& aMessage)
       
  3050     {
       
  3051     Usif::TComponentId componentId(0);
       
  3052     TInt strLen = aMessage.GetDesLengthL(EIpcArgument0);
       
  3053     HBufC* packageName = HBufC::NewLC(strLen);
       
  3054     TPtr pkgname = packageName->Des();
       
  3055     aMessage.ReadL(EIpcArgument0, pkgname, 0);
       
  3056     
       
  3057     strLen = aMessage.GetDesLengthL(EIpcArgument1);
       
  3058     HBufC* vendorName = HBufC::NewLC(strLen);
       
  3059     TPtr vndrname = vendorName->Des();
       
  3060     aMessage.ReadL(EIpcArgument1, vndrname, 0);
       
  3061     componentId = ScrHelperUtil::GetComponentIdL(iScrSession, *packageName, *vendorName);
       
  3062     if (!componentId)
       
  3063         {
       
  3064         DEBUG_PRINTF2(_L8("Sis Registry Server - Component id for package Name %S was not found."), packageName);
       
  3065         User::Leave(KErrNotFound);
       
  3066         } 
       
  3067     CleanupStack::PopAndDestroy(2, packageName); //vendorName
       
  3068     TPckgC<Usif::TComponentId> componentIdPckg(componentId);
       
  3069     aMessage.WriteL(EIpcArgument2, componentIdPckg);
       
  3070     aMessage.Complete(KErrNone);
       
  3071     }
       
  3072 
       
  3073 void CSisRegistrySession::GetAppUidsForComponentL(const RMessage2& aMessage)
       
  3074     {
       
  3075     Usif::TComponentId compId;
       
  3076     TPckg<Usif::TComponentId> componentId(compId);
       
  3077     RArray<TUid> appUids;
       
  3078     CleanupClosePushL(appUids);
       
  3079     aMessage.ReadL(EIpcArgument0, componentId);
       
  3080     iScrSession.GetAppUidsForComponentL(compId, appUids);        
       
  3081     SisRegistryUtil::SendDataArrayL(aMessage, appUids, EIpcArgument1);        
       
  3082     CleanupStack::PopAndDestroy(&appUids);
       
  3083     }
       
  3084 
       
  3085 void CSisRegistrySession::GetComponentIdsForUidL(const RMessage2& aMessage)
       
  3086     {
       
  3087     TUid Uid;
       
  3088     TPckg<TUid> pkgUid(Uid);
       
  3089     aMessage.ReadL(EIpcArgument0, pkgUid);
       
  3090     
       
  3091     // Setup a filter based on the input parameters
       
  3092     Usif::CComponentFilter* compFilter = Usif::CComponentFilter::NewLC();
       
  3093     compFilter->AddPropertyL(KCompUid, Uid.iUid);   
       
  3094     compFilter->SetSoftwareTypeL(Usif::KSoftwareTypeNative);    
       
  3095     RArray<Usif::TComponentId> componentIdList;
       
  3096     CleanupClosePushL(componentIdList);
       
  3097     iScrSession.GetComponentIdsL(componentIdList, compFilter);    
       
  3098     if(componentIdList.Count() == 0)
       
  3099         {
       
  3100         // No components are found in the SCR. So, return false
       
  3101         CleanupStack::PopAndDestroy(2, compFilter); // componentIdList
       
  3102         DEBUG_PRINTF2(_L8("Sis Registry Server - Unable to find component for UID: %x"), Uid.iUid);  
       
  3103         SisRegistryUtil::SendDataArrayL(aMessage, componentIdList, EIpcArgument1);
       
  3104         return;
       
  3105         }
       
  3106     SisRegistryUtil::SendDataArrayL(aMessage, componentIdList, EIpcArgument1);        
       
  3107     CleanupStack::PopAndDestroy(2, compFilter);    
       
  3108     }
       
  3109 
       
  3110 void CSisRegistrySession::RegisterAllAppL(RBuf& aApparcRegFilePath)
       
  3111     {
       
  3112 	CDir* dir;
       
  3113 	TInt err = iFs.GetDir(aApparcRegFilePath, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir);	
       
  3114 	DEBUG_PRINTF3(_L("Sis Registry Server - Reading apparc registration file directory(%S) returned %d."), &aApparcRegFilePath, err);
       
  3115 	
       
  3116 	if (err == KErrNone)
       
  3117 		{
       
  3118 		CleanupStack::PushL(dir);
       
  3119 
       
  3120 		TInt count(dir->Count());
       
  3121 		RBuf appRegFileName;
       
  3122 		appRegFileName.CreateL(KMaxFileName);
       
  3123 		CleanupClosePushL(appRegFileName);
       
  3124 		RSisLauncherSession launcher;
       
  3125 		CleanupClosePushL(launcher);
       
  3126 		User::LeaveIfError(launcher.Connect());
       
  3127 		RFs fs;
       
  3128 		CleanupClosePushL(fs);
       
  3129 		User::LeaveIfError(fs.Connect());
       
  3130 		User::LeaveIfError(fs.ShareProtected());
       
  3131 		RArray<TLanguage> appLanguages;
       
  3132 		CleanupClosePushL(appLanguages);
       
  3133 		appLanguages.AppendL(User::Language());
       
  3134 		for (TInt index = 0; index < count; ++index)
       
  3135 			{
       
  3136 			appRegFileName = TParsePtrC(aApparcRegFilePath).DriveAndPath();
       
  3137 			appRegFileName.Append((*dir)[index].iName);
       
  3138 			RFile file;
       
  3139 			CleanupClosePushL(file);
       
  3140 			User::LeaveIfError(file.Open(fs, appRegFileName, EFileRead));
       
  3141 			
       
  3142 			Usif::CApplicationRegistrationData* appRegData = NULL;			
       
  3143 			TRAPD(result, appRegData = launcher.SyncParseResourceFileL(file, appLanguages));
       
  3144 			if (result == KErrNone)
       
  3145 			    {
       
  3146                 CleanupStack::PushL(appRegData);
       
  3147                 TComponentId compId = 0; // ROM application
       
  3148                 TRAPD(res, ScrHelperUtil::AddApplicationEntryL(iScrSession, compId, *appRegData););
       
  3149                 if (res != KErrNone)
       
  3150                     {
       
  3151                     // log it only, we cannot stop as the next might be ok
       
  3152                     DEBUG_PRINTF3(_L("Sis Registry Server - Failed to register in ROM application %S. Error code %d."), &appRegFileName, res);
       
  3153                     }
       
  3154                 CleanupStack::PopAndDestroy(appRegData);
       
  3155 			    }
       
  3156 			else
       
  3157 			    DEBUG_PRINTF2(_L8("Sis Registry Server - Parsing in ROM application . Error code %d."), result);
       
  3158 			                
       
  3159 			CleanupStack::PopAndDestroy(&file);
       
  3160 			}
       
  3161 
       
  3162 		CleanupStack::PopAndDestroy(5, dir); // appRegFileName, launcher, fs, appLanguages
       
  3163 		}
       
  3164 	else if(err != KErrPathNotFound)
       
  3165 		{
       
  3166 		User::Leave(err);
       
  3167 		}
       
  3168     }
       
  3169 
       
  3170 void CSisRegistrySession::DriveFormatDetectedL(TDriveUnit aDrive)
       
  3171     {
       
  3172     DEBUG_PRINTF2(_L("Sis Registry Server - Drive format detected for drive %d"), static_cast<TInt>(aDrive));
       
  3173     
       
  3174     Usif::RStsSession stsSession;
       
  3175     TInt64 transactionId = stsSession.CreateTransactionL();
       
  3176     CleanupClosePushL(stsSession);
       
  3177     
       
  3178 	//Create SCR Transaction
       
  3179     iScrSession.CreateTransactionL();
       
  3180     
       
  3181     RArray<TComponentId> foundComponentIds;
       
  3182     CleanupClosePushL(foundComponentIds);
       
  3183         
       
  3184     TDriveList filterFormatDrive;
       
  3185     filterFormatDrive.FillZ(KMaxDrives);
       
  3186     filterFormatDrive[static_cast<TInt>(aDrive)] = 1;
       
  3187     
       
  3188     CComponentFilter* componentFilter = CComponentFilter::NewLC();
       
  3189     componentFilter->SetInstalledDrivesL(filterFormatDrive);
       
  3190         
       
  3191     iScrSession.GetComponentIdsL(foundComponentIds, componentFilter);
       
  3192     
       
  3193     TBool processRomDrive = EFalse;
       
  3194     for(TInt i=0; i < foundComponentIds.Count(); ++i)
       
  3195         {
       
  3196         CSisRegistryObject* object = CSisRegistryObject::NewLC();
       
  3197         ScrHelperUtil::GetComponentL(iScrSession, foundComponentIds[i], *object);
       
  3198         TUint installedDrives = object->Drives();
       
  3199             
       
  3200         if(installedDrives & (1 << aDrive))
       
  3201             {
       
  3202             if (!processRomDrive && 
       
  3203                     (object->InstallType() == Sis::EInstInstallation || object->InstallType() == Sis::EInstPartialUpgrade) &&
       
  3204                         SisRegistryUtil::RomBasedPackageL(object->Uid()))
       
  3205                 {   
       
  3206                 processRomDrive = ETrue;                   
       
  3207                 }  
       
  3208                     
       
  3209             // Retrieve all the associated files.
       
  3210             RPointerArray<CSisRegistryFileDescription>& fileDescriptions = object->FileDescriptions();
       
  3211             _LIT(KHashPathFormat, "%c:\\sys\\hash\\%S");
       
  3212             for(TInt j=0; j<fileDescriptions.Count(); ++j)
       
  3213                 {
       
  3214                 const TDesC& targetPath = fileDescriptions[j]->Target();
       
  3215                         
       
  3216                 // Get the drive on which the file is present.
       
  3217                 TInt drive; 
       
  3218                 User::LeaveIfError(RFs::CharToDrive(targetPath[0], drive));
       
  3219                         
       
  3220                 // If the file is a binary ( present in \sys\bin), delete the corresponding hash present in 
       
  3221                 // C:\sys\hash
       
  3222                         
       
  3223                 if(KErrNotFound != targetPath.FindF(KBinPath))
       
  3224                     {
       
  3225                     // Retrieve the filename from the target path.
       
  3226                     TParsePtrC parser(targetPath);
       
  3227 					HBufC* fileName = parser.NameAndExt().AllocLC();
       
  3228                     
       
  3229                     TChar systemDrive = RFs::GetSystemDriveChar();
       
  3230                     
       
  3231 					// Create the hash file path.
       
  3232                     RBuf hashFilePath;
       
  3233                     hashFilePath.CreateL(KMaxPath);
       
  3234                     CleanupClosePushL(hashFilePath);
       
  3235                     hashFilePath.Format(KHashPathFormat, static_cast<TUint>(systemDrive), fileName);
       
  3236                             
       
  3237                     // Delete hash file.
       
  3238                     SisRegistryUtil::DeleteFile(iFs, hashFilePath); //Ignore return code.
       
  3239                     
       
  3240 					CleanupStack::PopAndDestroy(2, fileName);
       
  3241 					}
       
  3242                         
       
  3243                 if(aDrive == TDriveUnit(drive))
       
  3244                     {
       
  3245                     // File does not exist on disk as the drive is assumed to have been formatted.
       
  3246                     continue;
       
  3247                     }
       
  3248                 SisRegistryUtil::DeleteFile(iFs, targetPath); //Ignore return code.           
       
  3249                 }
       
  3250                     
       
  3251             DeleteEntryL(*object, transactionId, EFalse);
       
  3252             CleanupStack::PopAndDestroy(object);
       
  3253             }
       
  3254         }
       
  3255 
       
  3256     if(processRomDrive)
       
  3257         {
       
  3258         // Re-add the ROM installed stub details to SCR (only those missing will be added)
       
  3259         ProcessRomDriveL();
       
  3260         }
       
  3261     
       
  3262     //Commit the changes.
       
  3263     stsSession.CommitL();
       
  3264     iScrSession.CommitTransactionL();
       
  3265 
       
  3266     CleanupStack::PopAndDestroy(3, &stsSession);
       
  3267     }
       
  3268 
       
  3269 void CSisRegistrySession::AddAppRegInfoL(const RMessage2& aMessage)
       
  3270     {   
       
  3271     //This API is for use during development/debug use only; not used in production software
       
  3272     
       
  3273     TUint regFileNameLen = aMessage.GetDesLengthL(EIpcArgument0);
       
  3274     HBufC* regFileName = HBufC::NewLC(regFileNameLen);
       
  3275     TPtr namePtr = regFileName->Des();
       
  3276     aMessage.ReadL(EIpcArgument0, namePtr);
       
  3277     
       
  3278     Usif::CApplicationRegistrationData* appRegData = NULL;
       
  3279     //Check if the file name passed is valid reg file or not , if valid then parse
       
  3280     TRAPD(result, ValidateAndParseAppRegFileL(*regFileName, appRegData, EFalse));
       
  3281     
       
  3282     if (result == KErrNone)
       
  3283         {
       
  3284         CleanupStack::PushL(appRegData);
       
  3285         TComponentId compId = 0; 
       
  3286         TUid appUid = appRegData->AppUid();
       
  3287         //Check if component exists for the appUid, if then append the app reg info to the same compId(base)        
       
  3288         TRAP_IGNORE(compId = iScrSession.GetComponentIdForAppL(appUid));
       
  3289         TRAPD(res, ScrHelperUtil::AddApplicationEntryL(iScrSession, compId, *appRegData));
       
  3290         if (res != KErrNone && res != KErrAlreadyExists )
       
  3291             {
       
  3292             DEBUG_PRINTF2(_L("Sis Registry Server - Failed to add app registration data of in the SCR . Error code %d."), res);
       
  3293             CleanupStack::PopAndDestroy(2, regFileName); //appRegData
       
  3294             aMessage.Complete(res);
       
  3295             return;
       
  3296             }        
       
  3297         else if (res == KErrAlreadyExists)
       
  3298             {   
       
  3299             // Delete the existing application entry, which is not associated with any package 
       
  3300             ScrHelperUtil::DeleteApplicationEntryL(iScrSession, appUid);            
       
  3301             ScrHelperUtil::AddApplicationEntryL(iScrSession, compId, *appRegData);
       
  3302             }
       
  3303         
       
  3304         //Notify Apparc of the new app
       
  3305         RSisLauncherSession launcher;
       
  3306         CleanupClosePushL(launcher);
       
  3307         User::LeaveIfError(launcher.Connect());
       
  3308         TAppUpdateInfo newAppInfo;
       
  3309         RArray<TAppUpdateInfo> affectedApps;    
       
  3310         CleanupClosePushL(affectedApps);
       
  3311         newAppInfo = TAppUpdateInfo(appUid, EAppInstalled);
       
  3312         affectedApps.AppendL(newAppInfo);
       
  3313         launcher.NotifyNewAppsL(affectedApps);
       
  3314         CleanupStack::PopAndDestroy(3, appRegData); // affectedApps, launcher
       
  3315         }
       
  3316     else
       
  3317         {
       
  3318         DEBUG_PRINTF2(_L8("Sis Registry Server - Parsing application registration info. Error code %d."), result);
       
  3319         }
       
  3320     
       
  3321     CleanupStack::PopAndDestroy(regFileName);
       
  3322     aMessage.Complete(result);
       
  3323     }
       
  3324 
       
  3325 void CSisRegistrySession::RemoveAppRegInfoL(const RMessage2& aMessage)
       
  3326     {
       
  3327     //This API is for use during development/debug use only; not used in production software
       
  3328     
       
  3329     TUint regFileNameLen = aMessage.GetDesLengthL(EIpcArgument0);
       
  3330     HBufC* regFileName = HBufC::NewLC(regFileNameLen);
       
  3331     TPtr namePtr = regFileName->Des();
       
  3332     aMessage.ReadL(EIpcArgument0, namePtr);
       
  3333     
       
  3334     Usif::CApplicationRegistrationData* appRegData = NULL;
       
  3335     // Check if the file name passed is valid reg file or not , if valid then parse it
       
  3336     TRAPD(result, ValidateAndParseAppRegFileL(*regFileName, appRegData, EFalse));
       
  3337     
       
  3338     if(result == KErrNone)
       
  3339         {
       
  3340         TUid appUid = appRegData->AppUid();
       
  3341         delete appRegData;
       
  3342         appRegData = NULL;
       
  3343     
       
  3344         // Check if component exists for the appUid
       
  3345         TComponentId compId(0);
       
  3346         TRAPD(err,compId = iScrSession.GetComponentIdForAppL(appUid));
       
  3347         
       
  3348         // Check if appUid(reg file data to be removed) is registered with scr 
       
  3349         if(err != KErrNone)
       
  3350             {
       
  3351             DEBUG_PRINTF2(_L8("Sis Registry Server -Reg file (%S) not registered with scr"), &regFileName);
       
  3352             User::Leave(KErrNotFound);
       
  3353             }
       
  3354         
       
  3355         TBool isAppReRegistered(ETrue);
       
  3356         if(compId == 0)                                   // If component Id is 0 i.e. for in-rom *_reg.rsc files(without stub association) or inserted using AddAppRegInfoL().
       
  3357             {                        
       
  3358             TDriveUnit romDrive(SisRegistryUtil::SystemRomDrive());
       
  3359             RBuf romRegFilesPath;
       
  3360             CleanupClosePushL(romRegFilesPath);
       
  3361             romRegFilesPath.CreateL(romDrive.Name(), KMaxPath);            
       
  3362             romRegFilesPath.Append(KApparcRegFilePath);
       
  3363            
       
  3364             /* Scan the reg files in apparc's pvt folder's in rom, and compare their app uid with the uid of the reg file to be removed, 
       
  3365              * if found register the reg file present in rom replacing the existing app
       
  3366              */
       
  3367             TRAPD(err, ReRegisterAppRegFileL(romRegFilesPath, appUid));
       
  3368             CleanupStack::PopAndDestroy(&romRegFilesPath);
       
  3369                         
       
  3370             if(err == KErrNotFound)                       //If reg file is not found, search it in under "\\private\\10003a3f\\import\\apps\\*.rsc" path
       
  3371                 {
       
  3372                 RBuf romRegImportFilesPath;
       
  3373                 CleanupClosePushL(romRegImportFilesPath);
       
  3374                 romRegImportFilesPath.CreateL(romDrive.Name(), KMaxPath);                
       
  3375                 romRegImportFilesPath.Append(KApparcRegFileImportPath);
       
  3376                 err = 0; 
       
  3377                 TRAP(err, ReRegisterAppRegFileL(romRegImportFilesPath,appUid));
       
  3378                 CleanupStack::PopAndDestroy(&romRegImportFilesPath);
       
  3379                 }
       
  3380             
       
  3381             if(err == KErrNotFound)                       // Since _reg.rsc file doesn't exists in rom and it is registered in scr, remove it                        
       
  3382                 {
       
  3383                 // Delete the existing application entry, which is not associated with any package 
       
  3384                 ScrHelperUtil::DeleteApplicationEntryL(iScrSession, appUid); 
       
  3385                 isAppReRegistered = EFalse;
       
  3386                 }   
       
  3387             
       
  3388             else if(err != KErrNone && err != KErrNotFound)     
       
  3389                 {
       
  3390                 DEBUG_PRINTF2(_L8("Sis Registry Server - Error in removing reg file (%S)"), &regFileName);
       
  3391                 User::Leave(err);
       
  3392                 }                                            
       
  3393             }
       
  3394         else           // else if compId is not 0 i.e. either appUid is associated with stub in rom or any other package in other drive
       
  3395             {            
       
  3396             CSisRegistryObject* object = CSisRegistryObject::NewLC();
       
  3397             ScrHelperUtil::GetComponentL(iScrSession, compId, *object);            
       
  3398             if (object->InRom())            // If its a rom based pkg which has not been eclipsed then we can go back to the stubs
       
  3399                 {   
       
  3400                 RemoveEntryL(compId);
       
  3401                 // Re-add the ROM installed stub details to SCR (only those missing will be added)
       
  3402                 ProcessRomDriveL();
       
  3403                 }    
       
  3404             else
       
  3405                 {
       
  3406                 // Delete the existing application entry, which is not associated with any package 
       
  3407                 ScrHelperUtil::DeleteApplicationEntryL(iScrSession, appUid);
       
  3408                 // Register the reg files of the applications, only the unregistered reg file data will be added(the association of reg file with stub will be lost) 
       
  3409                 ProcessApplicationsL();
       
  3410                 }
       
  3411             CleanupStack::PopAndDestroy(object);
       
  3412             }
       
  3413         
       
  3414         //Notify Apparc of the app being removed      
       
  3415         RSisLauncherSession launcher;
       
  3416         CleanupClosePushL(launcher);
       
  3417         User::LeaveIfError(launcher.Connect());
       
  3418         RArray<TAppUpdateInfo> affectedApps; 
       
  3419         CleanupClosePushL(affectedApps);
       
  3420         TAppUpdateInfo newAppInfo;
       
  3421         if(isAppReRegistered)       // If App reg data in rom is registerted again(i.e overwrites the existing one) we notify apparc of Installed app else Uninstalled app
       
  3422             {
       
  3423             newAppInfo = TAppUpdateInfo(appUid, EAppInstalled);
       
  3424             }
       
  3425         else
       
  3426             {
       
  3427             newAppInfo = TAppUpdateInfo(appUid, EAppUninstalled);
       
  3428             }
       
  3429         affectedApps.AppendL(newAppInfo);        
       
  3430         launcher.NotifyNewAppsL(affectedApps);
       
  3431         CleanupStack::PopAndDestroy(2, &launcher); // affectedApps        
       
  3432         }
       
  3433     else
       
  3434         {
       
  3435         DEBUG_PRINTF2(_L8("Sis Registry Server - Parsing application registration info. Error code %d."), result);
       
  3436         }
       
  3437     CleanupStack::PopAndDestroy(regFileName);
       
  3438     aMessage.Complete(result);
       
  3439     }
       
  3440 
       
  3441 void CSisRegistrySession::ValidateAndParseAppRegFileL(const TDesC& aRegFileName, Usif::CApplicationRegistrationData*& aAppRegData,TBool aInternal)
       
  3442     {
       
  3443     
       
  3444     TParsePtrC filename(aRegFileName);
       
  3445     if(!aInternal)                               //check if called for API and regFile path is "\\private\\10003a3f\\import\\apps\\"
       
  3446         {
       
  3447         if (filename.Path().Left(KApparcRegImportDir().Length()).CompareF(KApparcRegImportDir) != 0)
       
  3448             {
       
  3449             User::Leave(KErrNotSupported);
       
  3450             }
       
  3451         }
       
  3452     
       
  3453     RFs fs;
       
  3454     CleanupClosePushL(fs);
       
  3455     User::LeaveIfError(fs.Connect());
       
  3456     User::LeaveIfError(fs.ShareProtected());
       
  3457     RFile file;
       
  3458     CleanupClosePushL(file);
       
  3459     User::LeaveIfError(file.Open(fs, aRegFileName, EFileRead));
       
  3460     
       
  3461     // Reading the TUidType information fron the reg rsc file header
       
  3462     TBuf8<sizeof(TCheckedUid)> uidBuf;
       
  3463     TInt err = file.Read(0, uidBuf, sizeof(TCheckedUid));
       
  3464     if (err != KErrNone)
       
  3465         {
       
  3466         CleanupStack::PopAndDestroy(2, &fs);  //file
       
  3467         User::Leave(KErrNotSupported);
       
  3468         }
       
  3469     
       
  3470     if(uidBuf.Size() != sizeof(TCheckedUid))
       
  3471         {
       
  3472         DEBUG_PRINTF(_L("The file is not a valid registration resource file"));
       
  3473         CleanupStack::PopAndDestroy(2, &fs);  // file
       
  3474         User::Leave(KErrNotSupported);
       
  3475         }
       
  3476     TCheckedUid uid(uidBuf);
       
  3477     
       
  3478     //check the uid of the reg file to be parsed 
       
  3479     if(!(uid.UidType()[1] == KUidAppRegistrationFile))
       
  3480         {
       
  3481         CleanupStack::PopAndDestroy(2, &fs);  //file
       
  3482         User::Leave(KErrNotSupported);
       
  3483         }
       
  3484     
       
  3485     RSisLauncherSession launcher;
       
  3486     CleanupClosePushL(launcher);
       
  3487     User::LeaveIfError(launcher.Connect());
       
  3488     RArray<TLanguage> appLanguages;
       
  3489     CleanupClosePushL(appLanguages);
       
  3490     appLanguages.AppendL(User::Language());         
       
  3491     aAppRegData = launcher.SyncParseResourceFileL(file, appLanguages);
       
  3492     CleanupStack::PopAndDestroy(4, &fs);  //appLanguages, launcher, file
       
  3493     }
       
  3494 
       
  3495 void CSisRegistrySession::ReRegisterAppRegFileL(const TDesC& aRegFileDrivePath, const TUid& aAppUid)
       
  3496     {
       
  3497     /* 
       
  3498      * Reads and parses the *_reg.rsc files in the aRegFileDrivePath path and compare uid of each with the aAppUid, if matched remove the existing i.e. aAppUid
       
  3499      * and register the one found in the path.
       
  3500      */
       
  3501     
       
  3502     // open the directory
       
  3503     CDir* dir;
       
  3504     TInt err = iFs.GetDir(aRegFileDrivePath, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir);
       
  3505     
       
  3506     if (err == KErrNone)
       
  3507         {
       
  3508         CleanupStack::PushL(dir);
       
  3509         TInt count(dir->Count());
       
  3510         TBool foundAndReplaced(EFalse);
       
  3511         // scan through all the *_reg.rsc files
       
  3512         for (TInt index = 0; index < count; ++index)
       
  3513             {
       
  3514             RBuf regResourceFileName;
       
  3515             CleanupClosePushL(regResourceFileName);
       
  3516             regResourceFileName.CreateL(KMaxFileName);            
       
  3517             //construct the app reg file present in rom
       
  3518             regResourceFileName = TParsePtrC(aRegFileDrivePath).DriveAndPath();
       
  3519             regResourceFileName.Append((*dir)[index].iName);
       
  3520            //validate and parse the app reg file
       
  3521             Usif::CApplicationRegistrationData* appRegData = NULL;
       
  3522             TRAPD(res,ValidateAndParseAppRegFileL(regResourceFileName, appRegData, ETrue));
       
  3523             CleanupStack::PopAndDestroy(&regResourceFileName); 
       
  3524             CleanupStack::PushL(appRegData);
       
  3525             
       
  3526             if(res != KErrNone)
       
  3527                 {
       
  3528                 // log it only, we cannot stop as the next might be ok
       
  3529                 DEBUG_PRINTF2(_L8("Sis Registry Server - Failed to register in ROM controller. Error code %d."), res); 
       
  3530                 CleanupStack::Pop(appRegData);
       
  3531                 continue;
       
  3532                 }
       
  3533             
       
  3534             /* If appuid of the current processing reg file is same as of the reg file to be removed, delete existing app reg data and 
       
  3535              * add the reg entry of _reg.rsc file currently processed.
       
  3536              */
       
  3537             if(aAppUid == appRegData->AppUid())
       
  3538                 {                        
       
  3539                 TComponentId compId(0);
       
  3540                 // Delete the existing application entry, which is not associated with any package 
       
  3541                 ScrHelperUtil::DeleteApplicationEntryL(iScrSession, aAppUid); 
       
  3542                 ScrHelperUtil::AddApplicationEntryL(iScrSession, compId, *appRegData);    
       
  3543                 CleanupStack::PopAndDestroy(appRegData);
       
  3544                 foundAndReplaced = ETrue;
       
  3545                 break;
       
  3546                 }    
       
  3547             CleanupStack::PopAndDestroy(appRegData); 
       
  3548             }
       
  3549         if(!foundAndReplaced)
       
  3550             {
       
  3551             User::Leave(KErrNotFound);
       
  3552             }
       
  3553         CleanupStack::PopAndDestroy(dir); 
       
  3554         }
       
  3555     else
       
  3556     	{
       
  3557     	User::Leave(KErrNotFound);
       
  3558     	}
       
  3559     }