installationservices/swi/source/sisregistry/server/sisregistryserversession.cpp
changeset 60 245df5276b97
parent 53 ae54820ef82c
child 67 3a625661d1ce
--- a/installationservices/swi/source/sisregistry/server/sisregistryserversession.cpp	Tue Jul 06 14:23:31 2010 +0300
+++ b/installationservices/swi/source/sisregistry/server/sisregistryserversession.cpp	Wed Aug 18 09:55:45 2010 +0300
@@ -65,6 +65,7 @@
 #include "sisinstallblock.h"
 #include "sisregistryfiledescription.h"
 #include "sisregistrywritablesession.h"  
+#include "securitycheckutil.h"
 
 using namespace Swi;
 using namespace Usif;
@@ -99,7 +100,7 @@
 	if (KAppArcSID.iId == iClientSid.iId)
 	    {
         DEBUG_PRINTF(_L8("SIS Registry Server: Init for a connection from AppArc"));
-        ProcessRomApplicationsL();
+        ProcessApplicationsL();
 	    }
 	else
 	    {
@@ -186,7 +187,7 @@
     DEBUG_PRINTF(_L8("SIS Registry Server - Completed processing of ROM Stub sis files"));
     }
 
-void CSisRegistrySession::ProcessRomApplicationsL()
+void CSisRegistrySession::ProcessApplicationsL()
     {
     TComponentId compId = 0;
     DEBUG_PRINTF(_L8("SIS Registry Server - Deleteing all existing ROM applications."));
@@ -194,17 +195,36 @@
     
     //Register all apps found in \private\10003a3f\apps
     TDriveUnit romDrive(SisRegistryUtil::SystemRomDrive());
-    RBuf romApparcRegFilePath;
-    romApparcRegFilePath.CreateL(romDrive.Name(), KMaxPath);
-    CleanupClosePushL(romApparcRegFilePath);
-    romApparcRegFilePath.Append(KApparcRegFilePath);
-    RegisterAllInRomAppL(romApparcRegFilePath);
+    RBuf apparcRegFilePath;
+    apparcRegFilePath.CreateL(romDrive.Name(), KMaxPath);
+    CleanupClosePushL(apparcRegFilePath);
+    apparcRegFilePath.Append(KApparcRegFilePath);
+    
+	//Create a single transaction to register all in rom apps
+	iScrSession.CreateTransactionL();
+	RegisterAllAppL(apparcRegFilePath);
 
     //Register all apps found in \private\10003a3f\import\apps
-    romApparcRegFilePath = romDrive.Name();
-    romApparcRegFilePath.Append(KApparcRegFileImportPath);
-    RegisterAllInRomAppL(romApparcRegFilePath);
-    CleanupStack::PopAndDestroy(&romApparcRegFilePath);
+    apparcRegFilePath = romDrive.Name();
+    apparcRegFilePath.Append(KApparcRegFileImportPath);
+    RegisterAllAppL(apparcRegFilePath);
+    
+	//Register all apps found in UDA
+	TDriveUnit systemDrive(iSystemDrive);
+
+	//Register all apps found in <systemdrive>\private\10003a3f\apps
+	apparcRegFilePath = systemDrive.Name();	
+	apparcRegFilePath.Append(KApparcRegFilePath);
+	RegisterAllAppL(apparcRegFilePath);
+
+	//Register all apps found in <systemdrive>\private\10003a3f\import\apps
+    apparcRegFilePath = systemDrive.Name();
+    apparcRegFilePath.Append(KApparcRegFileImportPath);
+    RegisterAllAppL(apparcRegFilePath);
+	
+	iScrSession.CommitTransactionL();    
+	
+	CleanupStack::PopAndDestroy(&apparcRegFilePath);
     
     DEBUG_PRINTF(_L8("SIS Registry Server - Completed processing of all existing ROM applications."));
     }
@@ -217,7 +237,7 @@
 	// Add the ROM installed stub details to SCR
 	// Create an SCR transaction, so that entries won't be added to the SCR if the function leaves
     TInt value(EIdlePhase1NOK);
-    RProperty::Get(KPSUidStartup, KPSIdlePhase1Ok, value);
+    TInt ret = RProperty::Get(KPSUidStartup, KPSIdlePhase1Ok, value);
 	
     TBool isFromSWIDaemon = EFalse;
     _LIT_SECURE_ID(KSWIDaemonSID, 0x10202DCE);
@@ -225,6 +245,17 @@
         { 
         isFromSWIDaemon = ETrue;
         }
+	
+	//If the image is NCP 'KPSUidStartup' property is not set, hence settig it explicitly for processing stubs
+	if(ret == KErrNotFound)
+		{
+		DEBUG_PRINTF(_L8("SIS Registry Server - 'KPSUidStartup' property is not set"));
+		value = EIdlePhase1Ok;
+		}
+	else
+		{
+		DEBUG_PRINTF(_L8("SIS Registry Server - 'KPSUidStartup' property is set"));
+		}
 	if ((value == EIdlePhase1Ok || isFromSWIDaemon) && iIsFirstInit)
 	    {
         ProcessRomStubsL();
@@ -242,7 +273,7 @@
         iFs.Delete(fileName);
         CleanupStack::PopAndDestroy(&fileName);
 
-        ProcessRomApplicationsL();
+        ProcessApplicationsL();
 	    }
 	}
 
@@ -501,7 +532,13 @@
         break;
 	case EComponentIdsForPackageUid:	    
         GetComponentIdsForUidL(aMessage);        
-        break;	    
+        break;
+	case EAddAppRegInfo:
+	    AddAppRegInfoL(aMessage);
+	    break;
+	case ERemoveAppRegInfo:
+	    RemoveAppRegInfoL(aMessage);
+	    break;
 	default:
 		PanicClient(aMessage,EPanicIllegalFunction);
 		break;
@@ -750,13 +787,13 @@
 			// DEF085506 fix. remove control files (Previous SA and any of PUs) also while SA upgrading.
 			if (object->InstallType() == Sis::EInstInstallation)
 				{
-				RemoveEntryL(*existingObject);
+				RemoveEntryL(compId);
 				RemoveCleanupInfrastructureL(*existingObject, stsSession);	
 				}
 			else // PartialUpgarde case remove only registry file.
 				{
 				// Essentially, this is an uninstall except we leave the controller file intact.
-				RemoveEntryL(*existingObject);
+				RemoveEntryL(compId);
 				}
 			CleanupStack::PopAndDestroy(existingObject);
 			}
@@ -879,33 +916,40 @@
 	TInt64 transactionID;
 	TPckg<TInt64> pkgTransactionID(transactionID);
 	aMessage.ReadL(EIpcArgument2, pkgTransactionID);
-	
-	// create a integrity service object
-	Usif::RStsSession stssession;
-	stssession.OpenTransactionL(transactionID);
-	CleanupClosePushL(stssession);
+		
+	DeleteEntryL(*object, transactionID, ETrue);
 	
-	RemoveEntryL(*object);
-	RemoveCleanupInfrastructureL(*object, stssession);
-
-	// If removal is for ROM upgrade type, after removing the existing registry entry set,
-	// regenerate the Registry Entry Cache. 
-	// If any of the ROM based stub doesn't have its registry set 
-	// in appropriate path, it will create them (SCR entry & . ctl) 
-	// from the ROM based stub sis file.	
-	if ((object->InstallType() == Sis::EInstInstallation || 
-		 object->InstallType() == Sis::EInstPartialUpgrade) &&	
-		SisRegistryUtil::RomBasedPackageL(object->Uid()))
-		{	
-		// Re-add the ROM installed stub details to SCR (only those missing will be added)
-		ProcessRomDriveL();
-		}
-	
- 	CleanupStack::PopAndDestroy(2, object);// STS 
+ 	CleanupStack::PopAndDestroy(object);
 	
 	aMessage.Complete(KErrNone);
 	}
 
+void CSisRegistrySession::DeleteEntryL(const CSisRegistryObject& aObject, TInt64 aTransactionId, TBool aCleanupRequired/*=ETrue*/)
+    {
+    // create a integrity service object
+    Usif::RStsSession stssession;
+    stssession.OpenTransactionL(aTransactionId);
+    CleanupClosePushL(stssession);
+        
+    RemoveEntryL(aObject);
+    RemoveCleanupInfrastructureL(aObject, stssession);
+    
+    // If removal is for ROM upgrade type, after removing the existing registry entry set,
+    // regenerate the Registry Entry Cache. 
+    // If any of the ROM based stub doesn't have its registry set 
+    // in appropriate path, it will create them (SCR entry & . ctl) 
+    // from the ROM based stub sis file.    
+    if ((aObject.InstallType() == Sis::EInstInstallation || 
+            aObject.InstallType() == Sis::EInstPartialUpgrade) &&  
+                SisRegistryUtil::RomBasedPackageL(aObject.Uid()) && 
+                    aCleanupRequired)
+        {   
+        // Re-add the ROM installed stub details to SCR (only those missing will be added)
+        ProcessRomDriveL();
+        }    
+    CleanupStack::PopAndDestroy(&stssession);
+    }
+
 void CSisRegistrySession::OpenRegistryUidEntryL(const RMessage2& aMessage)
 	{
 	// expects a UID as an arg 0
@@ -1035,8 +1079,8 @@
 	RPointerArray<HBufC> fileNames;
 	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(fileNames);
 	                    
-	TInt ret = GetStubFileInfoL(tUid, tMode, startingFileNo, fileCount, fileNames);
-	if (KErrNone == ret)
+	TRAPD(errCode, GetStubFileInfoL(tUid, tMode, startingFileNo, fileCount, fileNames));
+	if (KErrNone == errCode)
 	    {
 	    if (tMode == EGetFiles)
 	        {
@@ -1059,12 +1103,12 @@
 	    }
 	else
 	    {
-	    aMessage.Complete(ret);
+	    aMessage.Complete(errCode);
 	    }
 	CleanupStack::PopAndDestroy();
 	}
 
-TInt CSisRegistrySession::GetStubFilesL(const TDesC& aFileName, RPointerArray<HBufC>& aFileNames)
+void CSisRegistrySession::GetStubFilesL(const TDesC& aFileName, RPointerArray<HBufC>& aFileNames)
     {
     // Read the ROM stub controller
     CFileSisDataProvider* fileProvider = CFileSisDataProvider::NewLC(iFs, aFileName);
@@ -1075,31 +1119,31 @@
         // Ignore the broken stub file under the ROM stub directory.
         DEBUG_PRINTF2(_L8("Sis Registry Server - Failed to read the stub controller. Error code %d."), errCode);
         CleanupStack::PopAndDestroy(fileProvider);
-        return errCode;
+        User::Leave(errCode);
         }
     CleanupStack::PushL(stubController);
-    const RPointerArray<Sis::CFileDescription>& depArray = stubController->InstallBlock().FileDescriptions();
-    // Get as many number of files as possible that can be accomodate in client allocated buffer.
-    TInt totalDepArrayCount = depArray.Count();
+    const RPointerArray<Sis::CFileDescription>& filesArray = stubController->InstallBlock().FileDescriptions();
+    TInt totalFileCount = filesArray.Count();
     // Populate the files in to a temporary array.
-    for(TInt fileCount = 0; fileCount < totalDepArrayCount; ++fileCount )
+    for(TInt fileCount = 0; fileCount < totalFileCount; ++fileCount )
         {
-        // Only create a TPtrC when we know we have space available
-        HBufC* fileName = depArray[fileCount]->Target().Data().AllocL();
+        HBufC* fileName = filesArray[fileCount]->Target().Data().AllocLC();
         // Adding drive letter of rom if not mentioned in stub sis file
         TPtr a=fileName->Des();
         if (a[0] == '!')
-            a[0] = 'z';                        
-                                       
-		CleanupStack::PushL(fileName);
+            {
+            TChar driveChar;
+            iFs.DriveToChar(EDriveZ, driveChar);
+            a[0] = driveChar;
+            }
+
 		aFileNames.AppendL(fileName);
 		CleanupStack::Pop(fileName);
 		}
     CleanupStack::PopAndDestroy(2, fileProvider);
-    return KErrNone;
     }
 
-TInt CSisRegistrySession::GetStubFileInfoL(TUid aUid, TStubExtractionMode aMode, TInt aStartingFileNo, TInt& aFileCount, RPointerArray<HBufC>& aFileNames)
+void CSisRegistrySession::GetStubFileInfoL(TUid aUid, TStubExtractionMode aMode, TInt aStartingFileNo, TInt& aFileCount, RPointerArray<HBufC>& aFileNames)
     {
     TBool stubNotFound(ETrue);
     
@@ -1149,16 +1193,16 @@
             if ( stubController->Info().Uid().Uid() == aUid )
                 {
                 stubNotFound = EFalse;
-                const RPointerArray<Sis::CFileDescription>& depArray = stubController->InstallBlock().FileDescriptions();
+                const RPointerArray<Sis::CFileDescription>& filesArray = stubController->InstallBlock().FileDescriptions();
                 // Get as many number of files as possible that can be accomodate in client allocated buffer.
                 if (aMode == EGetFiles)
                     {
                     TInt sizeRed = 0;
-                    TInt totalDepArrayCount = depArray.Count();
+                    TInt totalFileCount = filesArray.Count();
                     // Populate the files in to a temporary array.
-                    for(TInt fileCount = aStartingFileNo; fileCount < totalDepArrayCount; ++fileCount )
+                    for(TInt fileCount = aStartingFileNo; fileCount < totalFileCount; ++fileCount )
                         {
-                        sizeRed += depArray[fileCount]->Target().Data().Size();
+                        sizeRed += filesArray[fileCount]->Target().Data().Size();
                         // If amount of data red exceeds the client buffer size, break reading.
                         if (sizeRed > KDefaultBufferSize)
                             {
@@ -1166,13 +1210,16 @@
                             }
                                 
                         // Only create a TPtrC when we know we have space available
-                        HBufC* fileName = depArray[fileCount]->Target().Data().AllocL();
+                        HBufC* fileName = filesArray[fileCount]->Target().Data().AllocLC();
 						// Adding drive letter of rom if not mentioned in stub sis file
                         TPtr a=fileName->Des();
                         if (a[0] == '!')
-							a[0] = 'z';                        
+                            {
+                            TChar driveChar;
+                            iFs.DriveToChar(EDriveZ, driveChar);
+                            a[0] = driveChar;
+                            }                        
                        
-						CleanupStack::PushL(fileName);
                         aFileNames.AppendL(fileName);
                         CleanupStack::Pop(fileName);                        
                         } 
@@ -1180,7 +1227,7 @@
                 // If only the count needed, send the stub file's total entrie's count.
                 else if (aMode == EGetCount)
                     {
-                    aFileCount = depArray.Count();
+                    aFileCount = filesArray.Count();
                     }               
                 CleanupStack::PopAndDestroy(2, fileProvider);
                 break;  
@@ -1193,16 +1240,15 @@
         if (stubNotFound)
             {  
 			CleanupStack::PopAndDestroy(2, &romRegistryPath); // tFs          
-            return (KErrNotFound);
+            User::Leave(KErrNotFound);
             }       
         }
     else if(err != KErrPathNotFound)
         {     
 		CleanupStack::PopAndDestroy(2, &romRegistryPath); // tFs   
-        return err;
+		User::Leave(err);
         }
 	CleanupStack::PopAndDestroy(2, &romRegistryPath); // tFs	
-    return KErrNone;
     }
 
 void CSisRegistrySession::RequestRegistryEntryL(const RMessage2& aMessage)
@@ -1225,15 +1271,82 @@
 
 void CSisRegistrySession::AddDriveL(const RMessage2& aMessage)
 	{
-	TInt drive;
-	TPckg<TInt> pkgDrive(drive);
+	TInt addedDrive;
+	TPckg<TInt> pkgDrive(addedDrive);
 	aMessage.ReadL(EIpcArgument0, pkgDrive);
 
-	DEBUG_PRINTF2(_L8("Sis Registry Server - Removable drive %d added."), drive);
+	DEBUG_PRINTF2(_L8("Sis Registry Server - Removable drive %d added."), addedDrive);
+	    
+	// Get the drive character.
+	TChar drive;
+	User::LeaveIfError(iFs.DriveToChar(addedDrive, drive));
+	TUint driveChar(drive);
+	    
+	// Retrieve drive info.
+	TDriveInfo driveInfo;
+	User::LeaveIfError(iFs.Drive(driveInfo, addedDrive));
+#ifndef __WINSCW__	   
+	if(driveInfo.iDriveAtt & KDriveAttLogicallyRemovable)
+#endif	    
+	    {
+	    /*
+	    In case a logically removable drive is added,
+	    Look for the presence of the first boot marker file corresponding to it in the sisregistry private
+	    folder in C drive. If absent, assume first boot and create the marker file. 
+	    Also added a marker file in the <drive>\sys\install directory which would be used to detect a format. 
+	         
+	    Subsequent boots would look for the drive format marker to check if a format has occured and delete
+	    the registry entries.
+	    */
+	    
+	    // Create first boot marker path.
+	    _LIT(KFirstBootMarkerFilePath, "%c:%SfirstBootMarkerFileFor%c");
+	    RBuf privatePath;
+		privatePath.CreateL(KMaxPath);
+	    CleanupClosePushL(privatePath);
+	    User::LeaveIfError(iFs.PrivatePath(privatePath));
+
+	    RBuf firstBootMarkerFilePath;
+		firstBootMarkerFilePath.CreateL(KMaxPath);
+	    CleanupClosePushL(firstBootMarkerFilePath);
 
+	    TChar systemDrive = RFs::GetSystemDriveChar();
+	    firstBootMarkerFilePath.Format(KFirstBootMarkerFilePath, static_cast<TUint>(systemDrive), &privatePath, driveChar); 
+	        
+	    // Create drive format marker path.
+	    _LIT(KFormatMarkerPath, "%c:\\sys\\install\\formatMarkerFile");
+	    
+		RBuf formatMarkerPath;
+		formatMarkerPath.CreateL(KMaxPath);
+	    CleanupClosePushL(formatMarkerPath);
+		formatMarkerPath.Format(KFormatMarkerPath, driveChar); 
+	       
+		// The drive marker files are marked hidden and read-only.
+        TUint fileAttributes = KEntryAttReadOnly | KEntryAttHidden;
+
+	    if(!SisRegistryUtil::FileExistsL(iFs, firstBootMarkerFilePath))
+	        {
+	        // First boot detected. Add the first boot marker file as well as the format marker on the drive.
+	        SisRegistryUtil::CreateFileWithAttributesL(iFs, firstBootMarkerFilePath);
+	        SisRegistryUtil::CreateFileWithAttributesL(iFs, formatMarkerPath, fileAttributes);
+	        }
+	    else
+	        {
+	        // Subsequent boot. Check for the presence of a marker file <drive>\sys\install directory.
+	        // If absent, assume format.
+	        if(!SisRegistryUtil::FileExistsL(iFs, formatMarkerPath))
+	            {
+	            DriveFormatDetectedL(TDriveUnit(addedDrive));
+	            //Add missing format marker file
+	            SisRegistryUtil::CreateFileWithAttributesL(iFs, formatMarkerPath, fileAttributes);
+	            }           
+	        }
+		CleanupStack::PopAndDestroy(3, &privatePath);
+	    }
+	    
 	// Find flagging controllers for non-preinstalled packages on
 	// this drive and do cleanup if necessary
-	ProcessRemovableDriveL(drive);
+	ProcessRemovableDriveL(addedDrive);
 
 	aMessage.Complete(KErrNone);
 	}
@@ -1803,7 +1916,7 @@
     {
     RPointerArray<HBufC> romFiles;
     CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(romFiles);
-    TInt ret = GetStubFilesL(aFileName, romFiles);
+    GetStubFilesL(aFileName, romFiles);
     RPointerArray<HBufC> apparcRegFiles;
     CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(apparcRegFiles);
        
@@ -2596,7 +2709,6 @@
 		TComponentId compId = ScrHelperUtil::GetComponentIdL(iScrSession, object->Uid(), object->Index());
 		TSisPackageTrust trustStatus;
 		trustStatus = static_cast<TSisPackageTrust>(GetIntPropertyValueL(iScrSession, compId, KCompTrust,  EFalse, KDefaultTrustValue));
-		//ScrHelperUtil::ReadFromScrL(iSession.ScrSession(), iComponentId, trustStatus);
 	    if ( ESisPackageBuiltIntoRom == trustStatus )
 	        {
             DEBUG_PRINTF2(_L8("Sis Registry Server - Attempting to delete registry entry 0x%08x as a firmware update detected"), object->Uid().iUid);
@@ -2991,11 +3103,11 @@
     CleanupStack::PopAndDestroy(2, compFilter);    
     }
 
-void CSisRegistrySession::RegisterAllInRomAppL(RBuf& aRomApparcRegFilePath)
+void CSisRegistrySession::RegisterAllAppL(RBuf& aApparcRegFilePath)
     {
 	CDir* dir;
-	TInt err = iFs.GetDir(aRomApparcRegFilePath, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir);	
-	DEBUG_PRINTF2(_L8("Sis Registry Server - Reading ROM apparc registration file directory returned %d."), err);
+	TInt err = iFs.GetDir(aApparcRegFilePath, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir);	
+	DEBUG_PRINTF3(_L("Sis Registry Server - Reading apparc registration file directory(%S) returned %d."), &aApparcRegFilePath, err);
 	
 	if (err == KErrNone)
 		{
@@ -3017,7 +3129,7 @@
 		appLanguages.AppendL(User::Language());
 		for (TInt index = 0; index < count; ++index)
 			{
-			appRegFileName = TParsePtrC(aRomApparcRegFilePath).DriveAndPath();
+			appRegFileName = TParsePtrC(aApparcRegFilePath).DriveAndPath();
 			appRegFileName.Append((*dir)[index].iName);
 			RFile file;
 			CleanupClosePushL(file);
@@ -3050,3 +3162,394 @@
 		User::Leave(err);
 		}
     }
+
+void CSisRegistrySession::DriveFormatDetectedL(TDriveUnit aDrive)
+    {
+    DEBUG_PRINTF2(_L("Sis Registry Server - Drive format detected for drive %d"), static_cast<TInt>(aDrive));
+    
+    Usif::RStsSession stsSession;
+    TInt64 transactionId = stsSession.CreateTransactionL();
+    CleanupClosePushL(stsSession);
+    
+	//Create SCR Transaction
+    iScrSession.CreateTransactionL();
+    
+    RArray<TComponentId> foundComponentIds;
+    CleanupClosePushL(foundComponentIds);
+        
+    TDriveList filterFormatDrive;
+    filterFormatDrive.FillZ(KMaxDrives);
+    filterFormatDrive[static_cast<TInt>(aDrive)] = 1;
+    
+    CComponentFilter* componentFilter = CComponentFilter::NewLC();
+    componentFilter->SetInstalledDrivesL(filterFormatDrive);
+        
+    iScrSession.GetComponentIdsL(foundComponentIds, componentFilter);
+    
+    TBool processRomDrive = EFalse;
+    for(TInt i=0; i < foundComponentIds.Count(); ++i)
+        {
+        CSisRegistryObject* object = CSisRegistryObject::NewLC();
+        ScrHelperUtil::GetComponentL(iScrSession, foundComponentIds[i], *object);
+        TUint installedDrives = object->Drives();
+            
+        if(installedDrives & (1 << aDrive))
+            {
+            if (!processRomDrive && 
+                    (object->InstallType() == Sis::EInstInstallation || object->InstallType() == Sis::EInstPartialUpgrade) &&
+                        SisRegistryUtil::RomBasedPackageL(object->Uid()))
+                {   
+                processRomDrive = ETrue;                   
+                }  
+                    
+            // Retrieve all the associated files.
+            RPointerArray<CSisRegistryFileDescription>& fileDescriptions = object->FileDescriptions();
+            _LIT(KHashPathFormat, "%c:\\sys\\hash\\%S");
+            for(TInt j=0; j<fileDescriptions.Count(); ++j)
+                {
+                const TDesC& targetPath = fileDescriptions[j]->Target();
+                        
+                // Get the drive on which the file is present.
+                TInt drive; 
+                User::LeaveIfError(RFs::CharToDrive(targetPath[0], drive));
+                        
+                // If the file is a binary ( present in \sys\bin), delete the corresponding hash present in 
+                // C:\sys\hash
+                        
+                if(KErrNotFound != targetPath.FindF(KBinPath))
+                    {
+                    // Retrieve the filename from the target path.
+                    TParsePtrC parser(targetPath);
+					HBufC* fileName = parser.NameAndExt().AllocLC();
+                    
+                    TChar systemDrive = RFs::GetSystemDriveChar();
+                    
+					// Create the hash file path.
+                    RBuf hashFilePath;
+                    hashFilePath.CreateL(KMaxPath);
+                    CleanupClosePushL(hashFilePath);
+                    hashFilePath.Format(KHashPathFormat, static_cast<TUint>(systemDrive), fileName);
+                            
+                    // Delete hash file.
+                    SisRegistryUtil::DeleteFile(iFs, hashFilePath); //Ignore return code.
+                    
+					CleanupStack::PopAndDestroy(2, fileName);
+					}
+                        
+                if(aDrive == TDriveUnit(drive))
+                    {
+                    // File does not exist on disk as the drive is assumed to have been formatted.
+                    continue;
+                    }
+                SisRegistryUtil::DeleteFile(iFs, targetPath); //Ignore return code.           
+                }
+                    
+            DeleteEntryL(*object, transactionId, EFalse);
+            CleanupStack::PopAndDestroy(object);
+            }
+        }
+
+    if(processRomDrive)
+        {
+        // Re-add the ROM installed stub details to SCR (only those missing will be added)
+        ProcessRomDriveL();
+        }
+    
+    //Commit the changes.
+    stsSession.CommitL();
+    iScrSession.CommitTransactionL();
+
+    CleanupStack::PopAndDestroy(3, &stsSession);
+    }
+
+void CSisRegistrySession::AddAppRegInfoL(const RMessage2& aMessage)
+    {   
+    //This API is for use during development/debug use only; not used in production software
+    
+    TUint regFileNameLen = aMessage.GetDesLengthL(EIpcArgument0);
+    HBufC* regFileName = HBufC::NewLC(regFileNameLen);
+    TPtr namePtr = regFileName->Des();
+    aMessage.ReadL(EIpcArgument0, namePtr);
+    
+    Usif::CApplicationRegistrationData* appRegData = NULL;
+    //Check if the file name passed is valid reg file or not , if valid then parse
+    TRAPD(result, ValidateAndParseAppRegFileL(*regFileName, appRegData, EFalse));
+    
+    if (result == KErrNone)
+        {
+        CleanupStack::PushL(appRegData);
+        TComponentId compId = 0; 
+        TUid appUid = appRegData->AppUid();
+        //Check if component exists for the appUid, if then append the app reg info to the same compId(base)        
+        TRAP_IGNORE(compId = iScrSession.GetComponentIdForAppL(appUid));
+        TRAPD(res, ScrHelperUtil::AddApplicationEntryL(iScrSession, compId, *appRegData));
+        if (res != KErrNone && res != KErrAlreadyExists )
+            {
+            DEBUG_PRINTF2(_L("Sis Registry Server - Failed to add app registration data of in the SCR . Error code %d."), res);
+            CleanupStack::PopAndDestroy(2, regFileName); //appRegData
+            aMessage.Complete(res);
+            return;
+            }        
+        else if (res == KErrAlreadyExists)
+            {   
+            // Delete the existing application entry, which is not associated with any package 
+            ScrHelperUtil::DeleteApplicationEntryL(iScrSession, appUid);            
+            ScrHelperUtil::AddApplicationEntryL(iScrSession, compId, *appRegData);
+            }
+        
+        //Notify Apparc of the new app
+        RSisLauncherSession launcher;
+        CleanupClosePushL(launcher);
+        User::LeaveIfError(launcher.Connect());
+        TAppUpdateInfo newAppInfo;
+        RArray<TAppUpdateInfo> affectedApps;    
+        CleanupClosePushL(affectedApps);
+        newAppInfo = TAppUpdateInfo(appUid, EAppInstalled);
+        affectedApps.AppendL(newAppInfo);
+        launcher.NotifyNewAppsL(affectedApps);
+        CleanupStack::PopAndDestroy(3, appRegData); // affectedApps, launcher
+        }
+    else
+        {
+        DEBUG_PRINTF2(_L8("Sis Registry Server - Parsing application registration info. Error code %d."), result);
+        }
+    
+    CleanupStack::PopAndDestroy(regFileName);
+    aMessage.Complete(result);
+    }
+
+void CSisRegistrySession::RemoveAppRegInfoL(const RMessage2& aMessage)
+    {
+    //This API is for use during development/debug use only; not used in production software
+    
+    TUint regFileNameLen = aMessage.GetDesLengthL(EIpcArgument0);
+    HBufC* regFileName = HBufC::NewLC(regFileNameLen);
+    TPtr namePtr = regFileName->Des();
+    aMessage.ReadL(EIpcArgument0, namePtr);
+    
+    Usif::CApplicationRegistrationData* appRegData = NULL;
+    // Check if the file name passed is valid reg file or not , if valid then parse it
+    TRAPD(result, ValidateAndParseAppRegFileL(*regFileName, appRegData, EFalse));
+    
+    if(result == KErrNone)
+        {
+        TUid appUid = appRegData->AppUid();
+        delete appRegData;
+        appRegData = NULL;
+    
+        // Check if component exists for the appUid
+        TComponentId compId(0);
+        TRAPD(err,compId = iScrSession.GetComponentIdForAppL(appUid));
+        
+        // Check if appUid(reg file data to be removed) is registered with scr 
+        if(err != KErrNone)
+            {
+            DEBUG_PRINTF2(_L8("Sis Registry Server -Reg file (%S) not registered with scr"), &regFileName);
+            User::Leave(KErrNotFound);
+            }
+        
+        TBool isAppReRegistered(ETrue);
+        if(compId == 0)                                   // If component Id is 0 i.e. for in-rom *_reg.rsc files(without stub association) or inserted using AddAppRegInfoL().
+            {                        
+            TDriveUnit romDrive(SisRegistryUtil::SystemRomDrive());
+            RBuf romRegFilesPath;
+            CleanupClosePushL(romRegFilesPath);
+            romRegFilesPath.CreateL(romDrive.Name(), KMaxPath);            
+            romRegFilesPath.Append(KApparcRegFilePath);
+           
+            /* 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, 
+             * if found register the reg file present in rom replacing the existing app
+             */
+            TRAPD(err, ReRegisterAppRegFileL(romRegFilesPath, appUid));
+            CleanupStack::PopAndDestroy(&romRegFilesPath);
+                        
+            if(err == KErrNotFound)                       //If reg file is not found, search it in under "\\private\\10003a3f\\import\\apps\\*.rsc" path
+                {
+                RBuf romRegImportFilesPath;
+                CleanupClosePushL(romRegImportFilesPath);
+                romRegImportFilesPath.CreateL(romDrive.Name(), KMaxPath);                
+                romRegImportFilesPath.Append(KApparcRegFileImportPath);
+                err = 0; 
+                TRAP(err, ReRegisterAppRegFileL(romRegImportFilesPath,appUid));
+                CleanupStack::PopAndDestroy(&romRegImportFilesPath);
+                }
+            
+            if(err == KErrNotFound)                       // Since _reg.rsc file doesn't exists in rom and it is registered in scr, remove it                        
+                {
+                // Delete the existing application entry, which is not associated with any package 
+                ScrHelperUtil::DeleteApplicationEntryL(iScrSession, appUid); 
+                isAppReRegistered = EFalse;
+                }   
+            
+            else if(err != KErrNone && err != KErrNotFound)     
+                {
+                DEBUG_PRINTF2(_L8("Sis Registry Server - Error in removing reg file (%S)"), &regFileName);
+                User::Leave(err);
+                }                                            
+            }
+        else           // else if compId is not 0 i.e. either appUid is associated with stub in rom or any other package in other drive
+            {            
+            CSisRegistryObject* object = CSisRegistryObject::NewLC();
+            ScrHelperUtil::GetComponentL(iScrSession, compId, *object);            
+            if (object->InRom())            // If its a rom based pkg which has not been eclipsed then we can go back to the stubs
+                {   
+                RemoveEntryL(compId);
+                // Re-add the ROM installed stub details to SCR (only those missing will be added)
+                ProcessRomDriveL();
+                }    
+            else
+                {
+                // Delete the existing application entry, which is not associated with any package 
+                ScrHelperUtil::DeleteApplicationEntryL(iScrSession, appUid);
+                // 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) 
+                ProcessApplicationsL();
+                }
+            CleanupStack::PopAndDestroy(object);
+            }
+        
+        //Notify Apparc of the app being removed      
+        RSisLauncherSession launcher;
+        CleanupClosePushL(launcher);
+        User::LeaveIfError(launcher.Connect());
+        RArray<TAppUpdateInfo> affectedApps; 
+        CleanupClosePushL(affectedApps);
+        TAppUpdateInfo newAppInfo;
+        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
+            {
+            newAppInfo = TAppUpdateInfo(appUid, EAppInstalled);
+            }
+        else
+            {
+            newAppInfo = TAppUpdateInfo(appUid, EAppUninstalled);
+            }
+        affectedApps.AppendL(newAppInfo);        
+        launcher.NotifyNewAppsL(affectedApps);
+        CleanupStack::PopAndDestroy(2, &launcher); // affectedApps        
+        }
+    else
+        {
+        DEBUG_PRINTF2(_L8("Sis Registry Server - Parsing application registration info. Error code %d."), result);
+        }
+    CleanupStack::PopAndDestroy(regFileName);
+    aMessage.Complete(result);
+    }
+
+void CSisRegistrySession::ValidateAndParseAppRegFileL(const TDesC& aRegFileName, Usif::CApplicationRegistrationData*& aAppRegData,TBool aInternal)
+    {
+    
+    TParsePtrC filename(aRegFileName);
+    if(!aInternal)                               //check if called for API and regFile path is "\\private\\10003a3f\\import\\apps\\"
+        {
+        if (filename.Path().Left(KApparcRegImportDir().Length()).CompareF(KApparcRegImportDir) != 0)
+            {
+            User::Leave(KErrNotSupported);
+            }
+        }
+    
+    RFs fs;
+    CleanupClosePushL(fs);
+    User::LeaveIfError(fs.Connect());
+    User::LeaveIfError(fs.ShareProtected());
+    RFile file;
+    CleanupClosePushL(file);
+    User::LeaveIfError(file.Open(fs, aRegFileName, EFileRead));
+    
+    // Reading the TUidType information fron the reg rsc file header
+    TBuf8<sizeof(TCheckedUid)> uidBuf;
+    TInt err = file.Read(0, uidBuf, sizeof(TCheckedUid));
+    if (err != KErrNone)
+        {
+        CleanupStack::PopAndDestroy(2, &fs);  //file
+        User::Leave(KErrNotSupported);
+        }
+    
+    if(uidBuf.Size() != sizeof(TCheckedUid))
+        {
+        DEBUG_PRINTF(_L("The file is not a valid registration resource file"));
+        CleanupStack::PopAndDestroy(2, &fs);  // file
+        User::Leave(KErrNotSupported);
+        }
+    TCheckedUid uid(uidBuf);
+    
+    //check the uid of the reg file to be parsed 
+    if(!(uid.UidType()[1] == KUidAppRegistrationFile))
+        {
+        CleanupStack::PopAndDestroy(2, &fs);  //file
+        User::Leave(KErrNotSupported);
+        }
+    
+    RSisLauncherSession launcher;
+    CleanupClosePushL(launcher);
+    User::LeaveIfError(launcher.Connect());
+    RArray<TLanguage> appLanguages;
+    CleanupClosePushL(appLanguages);
+    appLanguages.AppendL(User::Language());         
+    aAppRegData = launcher.SyncParseResourceFileL(file, appLanguages);
+    CleanupStack::PopAndDestroy(4, &fs);  //appLanguages, launcher, file
+    }
+
+void CSisRegistrySession::ReRegisterAppRegFileL(const TDesC& aRegFileDrivePath, const TUid& aAppUid)
+    {
+    /* 
+     * 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
+     * and register the one found in the path.
+     */
+    
+    // open the directory
+    CDir* dir;
+    TInt err = iFs.GetDir(aRegFileDrivePath, KEntryAttMatchExclude | KEntryAttDir, ESortNone, dir);
+    
+    if (err == KErrNone)
+        {
+        CleanupStack::PushL(dir);
+        TInt count(dir->Count());
+        TBool foundAndReplaced(EFalse);
+        // scan through all the *_reg.rsc files
+        for (TInt index = 0; index < count; ++index)
+            {
+            RBuf regResourceFileName;
+            CleanupClosePushL(regResourceFileName);
+            regResourceFileName.CreateL(KMaxFileName);            
+            //construct the app reg file present in rom
+            regResourceFileName = TParsePtrC(aRegFileDrivePath).DriveAndPath();
+            regResourceFileName.Append((*dir)[index].iName);
+           //validate and parse the app reg file
+            Usif::CApplicationRegistrationData* appRegData = NULL;
+            TRAPD(res,ValidateAndParseAppRegFileL(regResourceFileName, appRegData, ETrue));
+            CleanupStack::PopAndDestroy(&regResourceFileName); 
+            CleanupStack::PushL(appRegData);
+            
+            if(res != KErrNone)
+                {
+                // log it only, we cannot stop as the next might be ok
+                DEBUG_PRINTF2(_L8("Sis Registry Server - Failed to register in ROM controller. Error code %d."), res); 
+                CleanupStack::Pop(appRegData);
+                continue;
+                }
+            
+            /* If appuid of the current processing reg file is same as of the reg file to be removed, delete existing app reg data and 
+             * add the reg entry of _reg.rsc file currently processed.
+             */
+            if(aAppUid == appRegData->AppUid())
+                {                        
+                TComponentId compId(0);
+                // Delete the existing application entry, which is not associated with any package 
+                ScrHelperUtil::DeleteApplicationEntryL(iScrSession, aAppUid); 
+                ScrHelperUtil::AddApplicationEntryL(iScrSession, compId, *appRegData);    
+                CleanupStack::PopAndDestroy(appRegData);
+                foundAndReplaced = ETrue;
+                break;
+                }    
+            CleanupStack::PopAndDestroy(appRegData); 
+            }
+        if(!foundAndReplaced)
+            {
+            User::Leave(KErrNotFound);
+            }
+        CleanupStack::PopAndDestroy(dir); 
+        }
+    else
+    	{
+    	User::Leave(KErrNotFound);
+    	}
+    }