installationservices/swi/test/tuiscriptadaptors/forceremove.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22 
       
    23 #include "forceremove.h"
       
    24 
       
    25 #include "testutilclientswi.h"
       
    26 
       
    27 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    28 #include "cleanuputils.h"
       
    29 #include "swi/sisregistryentry.h"
       
    30 #include "swi/sisregistrypackage.h"
       
    31 #include "swi/sisregistrysession.h"
       
    32 #include "sisregistryaccess_client.h"
       
    33 #endif
       
    34 
       
    35 TVerdict CForceRemove::doTestStepL()
       
    36 	{
       
    37 
       
    38 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    39 	// Wait up to 30 seconds to ensure both SWIS and the sisregistry server
       
    40 	// have shut down
       
    41 	_LIT(KSisRegistryServerName, "!SisRegistryServer");
       
    42 	_LIT(KInstallServerName, "!InstallServer");
       
    43 	TInt delaytime = 30; 
       
    44 
       
    45 	while (delaytime-- > 0)
       
    46 		{
       
    47 		TFullName serverName;
       
    48 		TFindServer find(KInstallServerName);
       
    49 		if (KErrNotFound == find.Next(serverName))
       
    50 			{
       
    51 			find.Find(KSisRegistryServerName);
       
    52 			if (KErrNotFound == find.Next(serverName))
       
    53 				{
       
    54 				break;
       
    55 				}
       
    56 			}
       
    57 		User::After(1000000); // wait a second until the next test
       
    58 		}
       
    59 #endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    60 	
       
    61 	TPtrC name;
       
    62 	RTestUtilSessionSwi testutil;
       
    63 	User::LeaveIfError(testutil.Connect());
       
    64 	CleanupClosePushL(testutil);
       
    65 	
       
    66 	// If file deletion fails we'll try moving the file to a temp directory
       
    67 	// for another process to clean up later.
       
    68 	
       
    69 	TTime currentTime;
       
    70 	currentTime.UniversalTime();
       
    71 	
       
    72 	_LIT(KTempPathFormat, "\\temp\\%Lu");
       
    73 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
    74 	TBuf<128> tempPathFormat(sysDrive.Name());
       
    75 	tempPathFormat.Append(KTempPathFormat);
       
    76 	
       
    77 	TFileName targetPath;
       
    78 	targetPath.Format(tempPathFormat, currentTime.Int64());
       
    79 	
       
    80 	_LIT(KNumFiles, "numfiles");
       
    81 
       
    82 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
    83 	RArray<TUint> removeUids;
       
    84 	CleanupClosePushL(removeUids);
       
    85 #endif
       
    86 
       
    87 	TInt num(0);
       
    88 	GetIntFromConfig(ConfigSection(), KNumFiles, num);
       
    89 
       
    90 	// Get the file names and use testutil to remove them
       
    91 	for (TInt i = 0; i < num; ++i)
       
    92 		{
       
    93 		_LIT(KFile, "file");
       
    94 		TBuf<32> key(KFile);
       
    95 		key.AppendNum(i);
       
    96 		
       
    97 		if (!GetStringFromConfig(ConfigSection(), key, name))
       
    98 			continue;
       
    99 			
       
   100 		INFO_PRINTF2(_L("ForceRemove - trying to delete file %S"), &name);
       
   101 
       
   102 		TInt err = testutil.Delete(name);
       
   103 		if (err != KErrNone && err != KErrNotFound && err != KErrPathNotFound)
       
   104 			{
       
   105 			INFO_PRINTF3(_L("RTestUtilSessionSwi::Delete(%S) returned %d, attempting move instead."), &name, err);
       
   106 			TFileName source(name);
       
   107 			TParsePtr parse(source);
       
   108 			TFileName dest(targetPath);
       
   109 			dest.Append(parse.Path());
       
   110 			if (parse.DrivePresent())
       
   111 				{
       
   112 				dest[0] = source[0];
       
   113 				}
       
   114 			testutil.MkDirAll(dest);
       
   115 			dest.Append(parse.NameAndExt());
       
   116 
       
   117 			err = testutil.Move(source, dest);
       
   118 			
       
   119 			if (err != KErrNone)
       
   120 				{
       
   121 				INFO_PRINTF4(_L("Attempt to move from %S to %S returned %d"),
       
   122 							&source, &dest, err);
       
   123 				}
       
   124 			}
       
   125 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   126 		_LIT(KRegistryPath, "\\sys\\install\\sisregistry\\");
       
   127 		if (name.FindF(KRegistryPath) == KErrNotFound)
       
   128 			continue;
       
   129 
       
   130 		// Extract the uid and add it to our list
       
   131 		TInt slashPos = name.LocateReverse('\\');
       
   132 		TPtrC ptrUid = name.Mid(slashPos + 1);
       
   133 		if (ptrUid.Length() != 8)
       
   134 			continue;
       
   135 
       
   136 		TUint uid = 0; 
       
   137 		TLex lex(ptrUid);
       
   138 		if (lex.Val(uid, EHex) == KErrNone)
       
   139 			{
       
   140 			removeUids.InsertInOrder(uid);	// Will not allow duplicates
       
   141 			}
       
   142 #endif
       
   143 		}
       
   144 
       
   145 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   146 	// Use the sisregistry folder uid to remove the package entries from SCR
       
   147 	// Note that we remove packages present in ROM too due to two reasons:
       
   148 	// This is exactly what ForceRemove used to do (delete entire registry folder containing ALL reg files)
       
   149 	// After deleting an entry SWIRegistry re-registers ROM apps (missing ones)
       
   150 	TInt count = removeUids.Count();
       
   151 
       
   152 	RSisRegistryAccessSession regWrite;
       
   153 	TInt err = regWrite.Connect();
       
   154 	User::LeaveIfError(err);
       
   155 	CleanupClosePushL(regWrite);
       
   156 
       
   157 	Swi::RSisRegistrySession regRead;
       
   158 	User::LeaveIfError(regRead.Connect());
       
   159 	CleanupClosePushL(regRead);
       
   160 	for (TInt i = 0; i < count; ++i)
       
   161 		{ 
       
   162 		TUid uid = TUid::Uid(removeUids[i]);
       
   163 		Swi::RSisRegistryEntry entry;
       
   164 		CleanupClosePushL(entry);
       
   165 		if (entry.Open(regRead, uid) == KErrNone)
       
   166 			{
       
   167 			// Get its augmentations
       
   168 			RPointerArray<Swi::CSisRegistryPackage> augmentations;
       
   169 			CleanupResetAndDestroy<RPointerArray<Swi::CSisRegistryPackage> >::PushL(augmentations);
       
   170 			
       
   171 			entry.AugmentationsL(augmentations);
       
   172 			TInt augCount = augmentations.Count();
       
   173 			for (TInt j = 0; j < augCount; ++j)
       
   174 				{
       
   175 				// Remove it
       
   176 				TInt dummyTime;
       
   177 				regWrite.DeleteEntryL(*augmentations[j], dummyTime);
       
   178 				}
       
   179 			// Finally remove the base package entry
       
   180 			Swi::CSisRegistryPackage* package = entry.PackageL();
       
   181 			CleanupStack::PushL(package);
       
   182 			TInt dummyTime;
       
   183 			regWrite.DeleteEntryL(*package,dummyTime);
       
   184 			CleanupStack::PopAndDestroy(2, &augmentations); // package
       
   185 			}
       
   186 		CleanupStack::PopAndDestroy(&entry);
       
   187 		}
       
   188 	CleanupStack::PopAndDestroy(3, &removeUids);	// regWrite, regRead
       
   189 #endif
       
   190 	
       
   191 	CleanupStack::PopAndDestroy(&testutil);
       
   192 	
       
   193 	return EPass;
       
   194 	}