installationservices/swi/source/swis/server/restoreprocessor.cpp
branchRCL_3
changeset 25 7333d7932ef7
parent 0 ba25891c3a9e
child 26 8b7f4e561641
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
     1 /*
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2004-2010 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".
    20 
    20 
    21 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    21 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    22 #include <usif/sts/sts.h>
    22 #include <usif/sts/sts.h>
    23 #include "swtypereginfo.h"
    23 #include "swtypereginfo.h"
    24 #include "installswtypehelper.h"
    24 #include "installswtypehelper.h"
       
    25 #include "cleanuputils.h"
    25 #else
    26 #else
    26 #include "integrityservices.h"
    27 #include "integrityservices.h"
    27 #endif
    28 #endif
    28 
    29 
    29 #include "application.h"
    30 #include "application.h"
    36 #include "sistruststatus.h"
    37 #include "sistruststatus.h"
    37 #include "log.h"
    38 #include "log.h"
    38 #include "securitycheckutil.h"
    39 #include "securitycheckutil.h"
    39 #include "sidcache.h"
    40 #include "sidcache.h"
    40 #include <f32file.h>
    41 #include <f32file.h>
       
    42 #include "userselections.h"
       
    43 #include "sissupportedlanguages.h"
    41 
    44 
    42 using namespace Swi; 
    45 using namespace Swi; 
    43 
    46 
    44 
    47 
    45 //
    48 //
    46 // CRestoreProcessor
    49 // CRestoreProcessor
    47 //
    50 //
    48 	
    51 
       
    52 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    53 _LIT(KApparcRegDir, "\\private\\10003a3f\\import\\apps\\");
       
    54 #endif
       
    55 
    49 CRestoreProcessor::CRestoreProcessor(const CPlan& aPlan, const TDesC8& aControllerBuffer,
    56 CRestoreProcessor::CRestoreProcessor(const CPlan& aPlan, const TDesC8& aControllerBuffer,
    50 	CSecurityManager& aSecurityManager,	
    57 	CSecurityManager& aSecurityManager,	
    51 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    58 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    52 	Usif::RStsSession& aStsSession, RSisRegistryWritableSession& aRegistrySession,
    59 	Usif::RStsSession& aStsSession, RSisRegistryWritableSession& aRegistrySession, RArray<TAppUpdateInfo>& aAppInfo,
    53 #else
    60 #else
    54 	CIntegrityServices& aIntegrityServices,
    61 	CIntegrityServices& aIntegrityServices,
    55 #endif
    62 #endif
    56 	const RPointerArray<CRestoreController::CSisCertificateVerifier>& aVerifiers,RSwiObserverSession& aObserver)
    63 	const RPointerArray<CRestoreController::CSisCertificateVerifier>& aVerifiers, RSwiObserverSession& aObserver)
    57 	: CActive(CActive::EPriorityStandard),
    64 	: CActive(CActive::EPriorityStandard),
    58 	  iVerifiers(aVerifiers),
    65 	  iVerifiers(aVerifiers),
    59 	  iSecurityManager(aSecurityManager),
    66 	  iSecurityManager(aSecurityManager),
    60 	  iControllerBuffer(aControllerBuffer),	  
    67 	  iControllerBuffer(aControllerBuffer),	  
    61 	  iPlan(aPlan),
    68 	  iPlan(aPlan),	  
    62 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    69 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    63 	  iStsSession(aStsSession),
    70 	  iStsSession(aStsSession),
    64 	  iRegistrySession(aRegistrySession),
    71 	  iRegistrySession(aRegistrySession),
       
    72 	  iAppInfo(aAppInfo),
    65 #else
    73 #else
    66 	  iIntegrityServices(aIntegrityServices),
    74 	  iIntegrityServices(aIntegrityServices),
    67 #endif
    75 #endif
    68 	  iSystemDriveChar(RFs::GetSystemDriveChar()),
    76 	  iSystemDriveChar(RFs::GetSystemDriveChar()),
    69 	  iObserver(aObserver)
    77 	  iObserver(aObserver)
    71 	CActiveScheduler::Add(this);	
    79 	CActiveScheduler::Add(this);	
    72 	}
    80 	}
    73 		
    81 		
    74 CRestoreProcessor* CRestoreProcessor::NewL(const CPlan& aPlan, const TDesC8& aControllerBuffer, CSecurityManager& aSecurityManager,
    82 CRestoreProcessor* CRestoreProcessor::NewL(const CPlan& aPlan, const TDesC8& aControllerBuffer, CSecurityManager& aSecurityManager,
    75 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    83 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    76 	Usif::RStsSession& aStsSession, RSisRegistryWritableSession& aRegistrySession,
    84 	Usif::RStsSession& aStsSession, RSisRegistryWritableSession& aRegistrySession, RArray<TAppUpdateInfo>& aAppInfo,
    77 #else
    85 #else
    78 	CIntegrityServices& aIntegrityServices,
    86 	CIntegrityServices& aIntegrityServices,
    79 #endif
    87 #endif
    80 	const RPointerArray<CRestoreController::CSisCertificateVerifier>& aVerifiers,
    88 	const RPointerArray<CRestoreController::CSisCertificateVerifier>& aVerifiers,
    81 	RArray<TUid>& aSids, RSwiObserverSession& aObserver)
    89 	RArray<TUid>& aSids, RSwiObserverSession& aObserver)
    82 	{
    90 	{
    83 	CRestoreProcessor* self = CRestoreProcessor::NewLC(aPlan, aControllerBuffer, aSecurityManager,
    91 	CRestoreProcessor* self = CRestoreProcessor::NewLC(aPlan, aControllerBuffer, aSecurityManager,
    84 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    92 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    85 			aStsSession, aRegistrySession,
    93 			aStsSession, aRegistrySession,aAppInfo,
    86 #else
    94 #else
    87 			aIntegrityServices, 
    95 			aIntegrityServices, 
    88 #endif
    96 #endif
    89 			aVerifiers, aSids, aObserver);
    97 			aVerifiers, aSids, aObserver);
    90 	CleanupStack::Pop(self);
    98 	CleanupStack::Pop(self);
    91 	return self;
    99 	return self;
    92 	}
   100 	}
    93 		
   101 		
    94 CRestoreProcessor* CRestoreProcessor::NewLC(const CPlan& aPlan, const TDesC8& aControllerBuffer, CSecurityManager& aSecurityManager,
   102 CRestoreProcessor* CRestoreProcessor::NewLC(const CPlan& aPlan, const TDesC8& aControllerBuffer, CSecurityManager& aSecurityManager,
    95 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   103 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    96 	Usif::RStsSession& aStsSession, RSisRegistryWritableSession& aRegistrySession,
   104 	Usif::RStsSession& aStsSession, RSisRegistryWritableSession& aRegistrySession, RArray<TAppUpdateInfo>& aAppInfo,
    97 #else
   105 #else
    98 	CIntegrityServices& aIntegrityServices,
   106 	CIntegrityServices& aIntegrityServices,
    99 #endif
   107 #endif
   100 	const RPointerArray<CRestoreController::CSisCertificateVerifier>& aVerifiers,
   108 	const RPointerArray<CRestoreController::CSisCertificateVerifier>& aVerifiers,
   101 	RArray<TUid>& aSids, RSwiObserverSession& aObserver)
   109 	RArray<TUid>& aSids, RSwiObserverSession& aObserver)
   102 	{
   110 	{
   103 	CRestoreProcessor* self = new (ELeave) CRestoreProcessor(aPlan, aControllerBuffer, aSecurityManager,
   111 	CRestoreProcessor* self = new (ELeave) CRestoreProcessor(aPlan, aControllerBuffer, aSecurityManager,
   104 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   112 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   105 		aStsSession, aRegistrySession,
   113 		aStsSession, aRegistrySession,aAppInfo,
   106 #else
   114 #else
   107 		aIntegrityServices, 
   115 		aIntegrityServices, 
   108 #endif
   116 #endif
   109 		aVerifiers, aObserver);
   117 		aVerifiers, aObserver);
   110 	CleanupStack::PushL(self);
   118 	CleanupStack::PushL(self);
   254 			iObserver.AddHeaderL(*header);
   262 			iObserver.AddHeaderL(*header);
   255 			CleanupStack::PopAndDestroy(header);
   263 			CleanupStack::PopAndDestroy(header);
   256 			}
   264 			}
   257 			
   265 			
   258 		//Get file description	
   266 		//Get file description	
   259 		CSisRegistryFileDescription* regFileDes = iApplication->FilesToAdd()[iCurrent++];											
   267 		CSisRegistryFileDescription* regFileDes = iApplication->FilesToAdd()[iCurrent++];
       
   268 
       
   269 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK 		
       
   270 		// Add apparc registerd files in list.
       
   271 		AddApparcFilesInListL(regFileDes->Target(), *iApplication);
       
   272 #endif
       
   273 		
   260 		//Complete actual file installation
   274 		//Complete actual file installation
   261 		InstallFileL(*regFileDes);
   275 		InstallFileL(*regFileDes);
   262 		TUint8 fileFlag(EFileAdded);
   276 		TUint8 fileFlag(EFileAdded);
   263 		if(regFileDes->Sid().iUid)
   277 		if(regFileDes->Sid().iUid)
   264 			{//if the file has a SID, it can be exe or dll
   278 			{//if the file has a SID, it can be exe or dll
   286 		}
   300 		}
   287 	}
   301 	}
   288 	
   302 	
   289 TBool CRestoreProcessor::DoStateUpdateRegistryL()
   303 TBool CRestoreProcessor::DoStateUpdateRegistryL()
   290 	{
   304 	{
       
   305 	
       
   306 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK 
       
   307     // Taking the previous controller's affected apps
       
   308     RArray<TAppUpdateInfo>& affectedApps = iAppInfo;        
       
   309     const CApplication& application = *iApplication;   // current application
       
   310 	//if there are reg files in the package or if its an upgrade (in case of SA (with app) over SA(with no app))
       
   311     if(iApparcRegFilesForParsing.Count() != 0 || application.IsUpgrade())
       
   312         {
       
   313         //Create the list of Application Uids which are affected by the Restore                   
       
   314         Usif::TComponentId componentId = 0;
       
   315         RArray<Usif::TComponentId> componentIds;
       
   316         CleanupClosePushL(componentIds);
       
   317         RArray<TUid> existingAppUids;
       
   318         CleanupClosePushL(existingAppUids);
       
   319         TAppUpdateInfo existingAppInfo;     
       
   320         TUid packageUid = application.ControllerL().Info().Uid().Uid();
       
   321         
       
   322         if(application.IsUpgrade())
       
   323             {           
       
   324             //Get all componentIds
       
   325             iRegistrySession.GetComponentIdsForUidL(packageUid, componentIds);            
       
   326             TInt count = componentIds.Count();
       
   327             if(0 == count)
       
   328                 {
       
   329                 DEBUG_PRINTF(_L("ComponentIDs not found for the base package"));
       
   330                 User::Leave(KErrNotFound);
       
   331                 }
       
   332                                 
       
   333             //SA over SA
       
   334             if(application.ControllerL().Info().InstallType() == Sis::EInstInstallation )
       
   335                 {        
       
   336                 //Get the compid for base package
       
   337                 componentId = iRegistrySession.GetComponentIdForUidL(packageUid);              
       
   338                       
       
   339                 TInt index = componentIds.Find(componentId);
       
   340              
       
   341                 //Exclude the Base SA compId from the list 
       
   342                 componentIds.Remove(index);
       
   343              
       
   344                 //Get the apps for Base SA compId and mark them as to be deleted
       
   345                 existingAppUids.Reset();
       
   346                 TRAPD(err,iRegistrySession.GetAppUidsForComponentL(componentId, existingAppUids);)  
       
   347                 //If Base Package does not contain any app then GetAppUidsForComponentL will return KErrNotFound, ignore the error else leave
       
   348                 if (KErrNone != err && KErrNotFound != err)
       
   349                     {
       
   350                     User::Leave(err);
       
   351                     }
       
   352                 
       
   353                 for(TInt i = 0 ; i < existingAppUids.Count(); ++i)
       
   354                     {
       
   355                     existingAppInfo = TAppUpdateInfo(existingAppUids[i], EAppUninstalled);    
       
   356                     affectedApps.AppendL(existingAppInfo);
       
   357                     }                
       
   358                 //Get the apps for Remaining CompIds(SP's) and mark them as to be upgraded               
       
   359                 for(TInt i = 0 ; i < componentIds.Count(); ++i)
       
   360                     {
       
   361                     existingAppUids.Reset();             
       
   362                     //If there are no apps within the components (SP's) then it will return KErrNotFound
       
   363                     TRAP(err, iRegistrySession.GetAppUidsForComponentL(componentIds[i], existingAppUids);) 
       
   364                     if (KErrNone != err && KErrNotFound != err)
       
   365                         {
       
   366                         User::Leave(err);
       
   367                         }
       
   368                     
       
   369                     for(TInt k = 0 ; k < existingAppUids.Count(); ++k)
       
   370                         {
       
   371                         existingAppInfo = TAppUpdateInfo(existingAppUids[i], EAppInstalled);    
       
   372                         affectedApps.AppendL(existingAppInfo);
       
   373                         }
       
   374                     }                                
       
   375                 }
       
   376                 
       
   377             //SP over SP
       
   378             if(application.ControllerL().Info().InstallType() == Sis::EInstAugmentation)
       
   379                 {
       
   380                 componentId = iRegistrySession.GetComponentIdForPackageL(application.PackageL().Name(), application.PackageL().Vendor());                
       
   381                 //Get the apps for Base SP compId and mark them as to be deleted
       
   382                 existingAppUids.Reset();
       
   383                 TRAPD(err, iRegistrySession.GetAppUidsForComponentL(componentId, existingAppUids);) 
       
   384                 if (KErrNone != err && KErrNotFound != err)
       
   385                     {
       
   386                     User::Leave(err);
       
   387                     }
       
   388                 
       
   389                 for(TInt k = 0 ; k < existingAppUids.Count(); ++k)
       
   390                    {
       
   391                    // Search for the app in the existing set of affected apps, if already present mark them as UnInstalled else add a new entry
       
   392                    TInt index = FindAppEntry(affectedApps, existingAppUids[k]);
       
   393                    if (KErrNotFound != index)
       
   394                        {
       
   395                        affectedApps[index].iAction = EAppUninstalled;
       
   396                        }
       
   397                    else
       
   398                        {
       
   399                        existingAppInfo = TAppUpdateInfo(existingAppUids[k], EAppUninstalled);    
       
   400                        affectedApps.AppendL(existingAppInfo);
       
   401                        }                   
       
   402                    }                                  
       
   403                 }        
       
   404             }                   
       
   405         CleanupStack::PopAndDestroy(2, &componentIds);   
       
   406         }       
       
   407 #endif
       
   408 	
   291 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   409 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   292 	RSisRegistryWritableSession session;
   410 	RSisRegistryWritableSession session;
   293 	User::LeaveIfError(session.Connect());
   411 	User::LeaveIfError(session.Connect());
   294 	CleanupClosePushL(session);
   412 	CleanupClosePushL(session);
   295 #endif
   413 #endif
   317 			}
   435 			}
   318 		else
   436 		else
   319 			{
   437 			{
   320 			iRegistrySession.UpdateEntryL(*iApplication, iControllerBuffer, iStsSession.TransactionIdL());
   438 			iRegistrySession.UpdateEntryL(*iApplication, iControllerBuffer, iStsSession.TransactionIdL());
   321 			}
   439 			}
       
   440 		TInt count = iApparcRegFileData.Count();
       
   441         for (int i = 0; i < count; i++)
       
   442             {
       
   443             iRegistrySession.UpdateEntryL(*iApplication, *iApparcRegFileData[i], iApparcRegFilesForParsing[i]->GetSisRegistryPackage());
       
   444             }
   322 #else
   445 #else
   323  		session.UpdateEntryL(*iApplication, iControllerBuffer, iIntegrityServices.TransactionId());
   446  		session.UpdateEntryL(*iApplication, iControllerBuffer, iIntegrityServices.TransactionId());
   324 #endif
   447 #endif
   325  		}
   448  		}
   326  	else
   449  	else
   332 			}
   455 			}
   333 		else
   456 		else
   334 			{
   457 			{
   335 			iRegistrySession.AddEntryL(*iApplication, iControllerBuffer, iStsSession.TransactionIdL());
   458 			iRegistrySession.AddEntryL(*iApplication, iControllerBuffer, iStsSession.TransactionIdL());
   336 			}
   459 			}
       
   460 		TInt count = iApparcRegFileData.Count();
       
   461         for (int i = 0; i < count; i++)
       
   462             {
       
   463             iRegistrySession.AddEntryL(*iApparcRegFileData[i], iApparcRegFilesForParsing[i]->GetSisRegistryPackage());
       
   464             }
   337 #else
   465 #else
   338  		session.AddEntryL(*iApplication, iControllerBuffer, iIntegrityServices.TransactionId());
   466  		session.AddEntryL(*iApplication, iControllerBuffer, iIntegrityServices.TransactionId());
   339 #endif
   467 #endif
   340  		}
   468  		}
   341 
   469 
   342 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   470 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   343 	// Registration of MIME types of the software types being installed to AppArc
   471 	// Registration of MIME types of the software types being installed to AppArc
   344 	InstallSoftwareTypeHelper::RegisterMimeTypesL(iSoftwareTypeRegInfoArray);
   472 	InstallSoftwareTypeHelper::RegisterMimeTypesL(iSoftwareTypeRegInfoArray);
       
   473 	
       
   474 	//if there are reg files in the package or if its an upgrade (in case of SA (with app) over SA(with no app))
       
   475 	if(iApparcRegFilesForParsing.Count() != 0 || application.IsUpgrade())
       
   476 	        {
       
   477 	        //Create the list of Application Uids which are affected by the Restore                            
       
   478 	        RArray<Usif::TComponentId> componentIds;
       
   479 	        CleanupClosePushL(componentIds);
       
   480 	        RArray<TUid> newAppUids;    
       
   481 	        CleanupClosePushL(newAppUids);
       
   482 	        TAppUpdateInfo existingAppInfo, newAppInfo;     
       
   483 	        TUid packageUid = application.ControllerL().Info().Uid().Uid();
       
   484 	        //Get all componentIds for the application
       
   485 	        componentIds.Reset();
       
   486 	        iRegistrySession.GetComponentIdsForUidL(packageUid, componentIds);
       
   487 	        TInt count = componentIds.Count();
       
   488 	        
       
   489 	        //Get the apps for All CompIds               
       
   490 	        for(TInt i = 0 ; i < count; i++)
       
   491 	            {
       
   492 	            newAppUids.Reset();                    
       
   493 	            TRAPD(err,iRegistrySession.GetAppUidsForComponentL(componentIds[i], newAppUids))
       
   494 	            if (KErrNone != err && KErrNotFound != err)
       
   495 	                {
       
   496 	                User::Leave(err);
       
   497 	                }
       
   498 	            
       
   499 	            for(TInt i = 0 ; i < newAppUids.Count(); ++i)
       
   500 	                {	               	                
       
   501 	                TInt index = 0;		
       
   502 	                // Search for the app in the existing set of affected apps, if already present mark them as UnInstalled else add a new entry
       
   503 	                index = FindAppEntry(affectedApps, newAppUids[i]);
       
   504 	                if(index != KErrNotFound)
       
   505 	                    {
       
   506 	                    affectedApps[index].iAction = EAppInstalled;
       
   507 	                    }
       
   508 	                else
       
   509 	                    {
       
   510 	                    existingAppInfo = TAppUpdateInfo(newAppUids[i], EAppInstalled);
       
   511 	                    affectedApps.AppendL(existingAppInfo);
       
   512 	                    }
       
   513 	                }  		           
       
   514 	            }
       
   515 	        
       
   516 	        //Compare the new affected apps with the existing affected apps and update the existing affected apps if alredy present or 
       
   517             //add to the list if it is a new app.
       
   518             RArray<TAppUpdateInfo> existingAffectedApps;
       
   519             CleanupClosePushL(existingAffectedApps);
       
   520             const_cast<CPlan&>(iPlan).GetAffectedApps(existingAffectedApps);
       
   521             TInt appCount = affectedApps.Count();
       
   522             for(TInt k = 0; k < appCount ; ++k)
       
   523                 {
       
   524                 TInt count = existingAffectedApps.Count();
       
   525                 TUid appUid = affectedApps[k].iAppUid;
       
   526                 for(TInt index = 0; index < count ; ++index)
       
   527                    {
       
   528                    if(appUid == existingAffectedApps[index].iAppUid)
       
   529                        {           
       
   530                        existingAffectedApps.Remove(index);                                    
       
   531                        }
       
   532                    }
       
   533                 existingAffectedApps.AppendL(affectedApps[k]);
       
   534                 }
       
   535 	        const_cast<CPlan&>(iPlan).ResetAffectedApps();
       
   536 	        const_cast<CPlan&>(iPlan).SetAffectedApps(affectedApps);
       
   537 	        
       
   538 	        CleanupStack::PopAndDestroy(3, &componentIds);
       
   539 	        }
       
   540 	
   345 #else
   541 #else
   346 	CleanupStack::PopAndDestroy(&session);
   542 	CleanupStack::PopAndDestroy(&session);
   347 #endif
   543 #endif
   348 	return ETrue;
   544 	return ETrue;
   349 	}
   545 	}
       
   546 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   547 TInt CRestoreProcessor::FindAppEntry(RArray<TAppUpdateInfo>& aAffectedApps, TUid& aNewAppUid)
       
   548     {
       
   549     TInt count = aAffectedApps.Count();
       
   550     for(TInt index = 0; index < count ; index++)
       
   551         {
       
   552         if(aAffectedApps[index].iAppUid == aNewAppUid)
       
   553             {           
       
   554             return index;
       
   555             }
       
   556         }
       
   557     return KErrNotFound;
       
   558     }
       
   559 #endif
       
   560 
   350 
   561 
   351 TBool CRestoreProcessor::DoStateProcessFilesL()
   562 TBool CRestoreProcessor::DoStateProcessFilesL()
   352 	{
   563 	{
   353 	if (iCurrent < iApplication->FilesToAdd().Count())
   564 	if (iCurrent < iApplication->FilesToAdd().Count())
   354 		{
   565 		{
   403   			}  			
   614   			}  			
   404 		SwitchState(ECurrentState);
   615 		SwitchState(ECurrentState);
   405 		return EFalse;		
   616 		return EFalse;		
   406 		}
   617 		}
   407 	else 
   618 	else 
   408 		{			
   619 		{
       
   620 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK                
       
   621         // Find out all the regisration resource files associated with this package UID and add to the list of 
       
   622         // files to be processed later for parsing      
       
   623         TRAPD(err, AddAppArcRegResourceFilesL());
       
   624         if ( err != KErrNotFound && err != KErrNone)
       
   625             {
       
   626             User::Leave(err);
       
   627             }
       
   628 #endif
   409 		iCurrent = 0;
   629 		iCurrent = 0;
   410 		return ETrue;		
   630 		return ETrue;		
   411 		}		
   631 		}		
   412 	}
   632 	}
   413 	
   633 	
       
   634 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   635 void CRestoreProcessor::AddAppArcRegResourceFilesL()
       
   636     {
       
   637     RSisRegistryEntry entry;
       
   638     TInt err = KErrNone;
       
   639     if (!iApplication->IsUninstall())
       
   640         err = entry.Open(iRegistrySession, iApplication->ControllerL().Info().Uid().Uid());
       
   641     else
       
   642         return;
       
   643     
       
   644     User::LeaveIfError(err);
       
   645     CleanupClosePushL(entry);
       
   646     AddAppArcRegResourceFilesForRegEntryL(entry);
       
   647     
       
   648     RPointerArray<CSisRegistryPackage> augmentationArray;
       
   649     CleanupResetAndDestroyPushL(augmentationArray);
       
   650     entry.AugmentationsL(augmentationArray);
       
   651     CleanupStack::Pop(&augmentationArray);
       
   652     CleanupStack::PopAndDestroy(&entry);    
       
   653         
       
   654     CleanupResetAndDestroyPushL(augmentationArray);
       
   655     TInt count = augmentationArray.Count();
       
   656     for ( TInt i=0; i < count; ++i)
       
   657         {
       
   658         TInt err = entry.OpenL(iRegistrySession,*augmentationArray[i]);
       
   659         User::LeaveIfError(err);
       
   660         CleanupClosePushL(entry);
       
   661         AddAppArcRegResourceFilesForRegEntryL(entry);
       
   662         CleanupStack::PopAndDestroy(&entry);
       
   663         }
       
   664     
       
   665     CleanupStack::PopAndDestroy(&augmentationArray);
       
   666     }
       
   667 
       
   668 void CRestoreProcessor::AddAppArcRegResourceFilesForRegEntryL(RSisRegistryEntry& aEntry)
       
   669     {
       
   670     RPointerArray<HBufC> filesArray;
       
   671     CleanupResetAndDestroyPushL(filesArray);
       
   672     aEntry.FilesL(filesArray);    
       
   673     TInt count = filesArray.Count();
       
   674     CSisRegistryPackage *regPkg = aEntry.PackageL();
       
   675     CleanupStack::PushL(regPkg);
       
   676     
       
   677     for (TInt i=0; i<count; ++i)
       
   678         {
       
   679         if (FileIsApparcReg(*filesArray[i]))
       
   680             {
       
   681             CAppRegFileData *tmpAppRegFileData = CAppRegFileData::NewLC(*filesArray[i],*regPkg);
       
   682             iApparcRegFilesForParsing.AppendL(tmpAppRegFileData);
       
   683             CleanupStack::Pop(tmpAppRegFileData);
       
   684             }
       
   685         }
       
   686     CleanupStack::PopAndDestroy(2,&filesArray);
       
   687     }
       
   688 #endif
       
   689 
       
   690 
   414 TBool CRestoreProcessor::DoStateVerifyPathsL() 
   691 TBool CRestoreProcessor::DoStateVerifyPathsL() 
   415 	{
   692 	{
   416 	if (iCurrent < iApplication->FilesToAdd().Count())
   693 	if (iCurrent < iApplication->FilesToAdd().Count())
   417 		{		
   694 		{		
   418 		CSisRegistryFileDescription* fileToProcess = iApplication->FilesToAdd()[iCurrent++];
   695 		CSisRegistryFileDescription* fileToProcess = iApplication->FilesToAdd()[iCurrent++];
   473 		break;
   750 		break;
   474 
   751 
   475 	case EInstallFiles:
   752 	case EInstallFiles:
   476 		if (DoStateInstallFilesL())
   753 		if (DoStateInstallFilesL())
   477 			{
   754 			{
       
   755 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK           
       
   756             SwitchState(EParseApplicationRegistrationFiles);
       
   757 #else
       
   758             SwitchState(EUpdateRegistry);
       
   759 #endif          
       
   760             }
       
   761         break;
       
   762 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   763     case EParseApplicationRegistrationFiles:
       
   764         if (DoParseApplicationRegistrationFilesL())
       
   765             {
   478 			SwitchState(EUpdateRegistry);
   766 			SwitchState(EUpdateRegistry);
   479 			}
   767 			}
   480 		break;
   768 		break;
   481 
   769 #endif
   482 	case EUpdateRegistry:
   770 	case EUpdateRegistry:
   483 		if (DoStateUpdateRegistryL())
   771 		if (DoStateUpdateRegistryL())
   484 			{
   772 			{
   485 			SwitchState(EFinished);
   773 			SwitchState(EFinished);
   486 			}
   774 			}
   546 CRestoreProcessor::~CRestoreProcessor()
   834 CRestoreProcessor::~CRestoreProcessor()
   547 	{
   835 	{
   548 	delete iFileMan;
   836 	delete iFileMan;
   549 	iFs.Close();
   837 	iFs.Close();
   550 	iSids.Close();
   838 	iSids.Close();
   551 	
   839 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   552 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   840     iSoftwareTypeRegInfoArray.Close();  
   553 	iSoftwareTypeRegInfoArray.Close();
   841     iApparcRegFilesForParsing.ResetAndDestroy();
   554 #endif
   842     iApparcRegFileData.ResetAndDestroy();
   555 	}
   843     delete iAppRegExtractor;   
       
   844     iAppInfo.Close();
       
   845 #endif
       
   846 	}
       
   847 
       
   848 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   849 
       
   850 TBool CRestoreProcessor::ParseRegistrationResourceFileL(const TDesC& aTargetFileName)
       
   851     {
       
   852     DEBUG_PRINTF2(_L("Restore Processor - ParseRegistrationResourceFileL - Parsing '%S' registration resource file"), &aTargetFileName);
       
   853  
       
   854     if ( NULL == iAppRegExtractor )
       
   855         {
       
   856         DEBUG_PRINTF(_L("Restore Processor - ParseRegistrationResourceFileL - Creating CAppRegExtractor for async parsing of registration resource file"));
       
   857         CApplication& app = const_cast<CApplication&>(*iApplication);
       
   858         const RArray<TInt>& matchingLanguages = app.GetMatchingDeviceLanguages();        
       
   859         TInt userSelectedLanguage = (TInt)iApplication->UserSelections().Language();
       
   860         TInt res = matchingLanguages.Find(userSelectedLanguage);
       
   861         if(res == KErrNotFound)
       
   862             {
       
   863             app.PopulateMatchingDeviceLanguagesL(userSelectedLanguage);
       
   864             }            
       
   865         const RArray<TInt>& matchingLanguages1 = app.GetMatchingDeviceLanguages();        
       
   866         RArray<TLanguage> devLanguages;
       
   867         CleanupClosePushL(devLanguages);       
       
   868         TInt count = matchingLanguages1.Count();
       
   869         DEBUG_PRINTF2(_L("Restore Processor - ParseRegistrationResourceFileL - %d matching languages found"),count);
       
   870         for ( TInt i=0; i<count; i++)
       
   871             {
       
   872             devLanguages.Append((TLanguage)matchingLanguages1[i]);            
       
   873             }
       
   874         
       
   875         iAppRegExtractor = CAppRegExtractor::NewL(iFs,devLanguages,iApparcRegFileData);
       
   876         CleanupStack::Pop(&devLanguages);            
       
   877         }
       
   878         
       
   879     iAppRegExtractor->ExtractAppRegInfoSizeL(aTargetFileName, iStatus);
       
   880     return EFalse;
       
   881     }
       
   882 
       
   883 TBool CRestoreProcessor::DoParseApplicationRegistrationFilesL()
       
   884     {
       
   885     if (iCurrent == 0)
       
   886         DEBUG_PRINTF2(_L("Restore Processor - DoParseApplicationRegistrationFilesL - Number of Application registration resource files to be parsed %d"), iApparcRegFilesForParsing.Count());
       
   887     
       
   888     if (iAppRegExtractor != NULL)
       
   889         {
       
   890         if (iAppRegExtractor->GetErrorCode() == KErrCorrupt)
       
   891             {
       
   892             delete iApparcRegFilesForParsing[--iCurrent];
       
   893             iApparcRegFilesForParsing.Remove(iCurrent);
       
   894             }
       
   895         }
       
   896     
       
   897     if (iCurrent < iApparcRegFilesForParsing.Count())
       
   898         { 
       
   899         TDesC& fileDescription = (iApparcRegFilesForParsing[iCurrent++]->GetAppRegFile());   
       
   900         // Continue processing the next file if a registration resource file is not found(in case of SA over SA)
       
   901         TRAPD(err,ParseRegistrationResourceFileL(fileDescription));        
       
   902         if(KErrNotFound == err || KErrPathNotFound == err)
       
   903             {               
       
   904             delete iApparcRegFilesForParsing[--iCurrent];
       
   905             iApparcRegFilesForParsing.Remove(iCurrent); 
       
   906             TRequestStatus* status = &iStatus;
       
   907             User::RequestComplete(status, KErrNone);     
       
   908             SetActive();
       
   909             }
       
   910         else if(KErrNone != err )
       
   911             {
       
   912             User::Leave(err);
       
   913             }
       
   914         else
       
   915             {
       
   916             SetActive();
       
   917             }
       
   918         return EFalse;
       
   919         }
       
   920     else
       
   921         {
       
   922         iCurrent = 0;
       
   923         return ETrue;
       
   924         }
       
   925     }
       
   926 
       
   927 TBool CRestoreProcessor::FileIsApparcReg(const TDesC& aFilename) const
       
   928     {
       
   929     TParsePtrC filename(aFilename);
       
   930     return filename.Path().CompareF(KApparcRegDir) == 0;
       
   931     }
       
   932 	
       
   933 void CRestoreProcessor::AddApparcFilesInListL(const TDesC& aTargetFileName, const CApplication& aApplication)
       
   934     {    
       
   935     if (FileIsApparcReg(aTargetFileName))
       
   936         {
       
   937         // we're installing a reg file so add it to our list for parsing it and 
       
   938         // populating SCR in EParseApplicationRegistrationFiles state of CProcessor     
       
   939         TInt index = UserSelectedLanguageIndexL(aApplication);
       
   940         CSisRegistryPackage *regPkg = CSisRegistryPackage::NewLC(aApplication.ControllerL().Info().Uid().Uid(),\
       
   941                 aApplication.ControllerL().Info().Names()[index]->Data(),\
       
   942                 aApplication.ControllerL().Info().UniqueVendorName().Data());
       
   943         CAppRegFileData *appRegData =CAppRegFileData::NewLC(aTargetFileName,*regPkg);
       
   944         iApparcRegFilesForParsing.AppendL(appRegData);
       
   945         CleanupStack::Pop(appRegData);  
       
   946         CleanupStack::PopAndDestroy(regPkg);
       
   947         }
       
   948     }
       
   949 
       
   950 TInt CRestoreProcessor::UserSelectedLanguageIndexL(const CApplication& aApplication) const
       
   951 // used to find out which is the index of the selected language, 
       
   952 // based on the language selection. This will be used for the relevant package and vendor names
       
   953     {
       
   954     TLanguage language = aApplication.UserSelections().Language();
       
   955     
       
   956     TInt index = KErrNotFound;
       
   957     for (TInt i = 0; i < aApplication.ControllerL().SupportedLanguages().Count(); i++)
       
   958         {
       
   959         if (aApplication.ControllerL().SupportedLanguages()[i] == language)
       
   960             {
       
   961             index = i;
       
   962             break;  
       
   963             }
       
   964         }
       
   965     User::LeaveIfError(index);
       
   966     return index;
       
   967     }   
       
   968 #endif
       
   969