1 /* |
|
2 * Copyright (c) 2010 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 "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: Startup list updater test module. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mt_startuplistupdater.h" // CTestStartupListUpdater |
|
19 #include "cleanupresetanddestroy.h" // CleanupResetAndDestroyPushL |
|
20 #include <StifParser.h> // CStifItemParser |
|
21 #include <usif/sif/sif.h> // Usif::RSoftwareInstall |
|
22 #include <usif/scr/scr.h> // Usif::RSoftwareComponentRegistry |
|
23 #include <dscstore.h> // RDscStore |
|
24 #include <dscitem.h> // CDscItem |
|
25 |
|
26 const TInt KMaxLineLength = 256; |
|
27 |
|
28 _LIT( KTestTag, "SLU" ); |
|
29 _LIT( KTestStartFormat, "%S: start" ); |
|
30 _LIT( KTestParamFormatArg, "%S: %S => %d"); |
|
31 _LIT( KTestDoneFormat, "%S: done" ); |
|
32 |
|
33 using namespace Usif; |
|
34 |
|
35 |
|
36 // ======== LOCAL FUNCTIONS ======== |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // FileNamesEqual() |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 TBool FileNamesEqual( const HBufC& aFile1, const HBufC& aFile2 ) |
|
43 { |
|
44 return ( aFile1.CompareF( aFile2 ) == 0 ); |
|
45 } |
|
46 |
|
47 |
|
48 // ======== MEMBER FUNCTIONS ======== |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CTestStartupListUpdater::Delete |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CTestStartupListUpdater::Delete() |
|
55 { |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CTestStartupListUpdater::Print() |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CTestStartupListUpdater::Print( const TInt aPriority, |
|
63 TRefByValue<const TDesC> aFmt, ... ) |
|
64 { |
|
65 VA_LIST list; |
|
66 VA_START( list, aFmt ); |
|
67 TBuf<KMaxLineLength> buf; |
|
68 buf.FormatList( aFmt, list ); |
|
69 iLog->Log( buf ); |
|
70 TestModuleIf().Printf( aPriority, KTestTag, buf ); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CTestStartupListUpdater::RunMethodL |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 TInt CTestStartupListUpdater::RunMethodL( CStifItemParser& aItem ) |
|
78 { |
|
79 static TStifFunctionInfo const KFunctions[] = |
|
80 { |
|
81 ENTRY( "Install", CTestStartupListUpdater::InstallL ), |
|
82 ENTRY( "Remove", CTestStartupListUpdater::RemoveL ), |
|
83 ENTRY( "InStartList", CTestStartupListUpdater::CheckStartListContainsL ), |
|
84 ENTRY( "NotInStartList", CTestStartupListUpdater::CheckStartListDoesNotContainL ) |
|
85 }; |
|
86 |
|
87 const TInt count = sizeof( KFunctions ) / sizeof( TStifFunctionInfo ); |
|
88 return RunInternalL( KFunctions, count, aItem ); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CTestStartupListUpdater::InstallL |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 TInt CTestStartupListUpdater::InstallL( CStifItemParser& aItem ) |
|
96 { |
|
97 _LIT( KTestName, "Install" ); |
|
98 Print( 0, KTestStartFormat, &KTestName ); |
|
99 TInt testResult = KErrNone; |
|
100 |
|
101 RSoftwareInstall installer; |
|
102 User::LeaveIfError( installer.Connect() ); |
|
103 CleanupClosePushL( installer ); |
|
104 |
|
105 TPtrC param; |
|
106 while ( aItem.GetNextString ( param ) == KErrNone ) |
|
107 { |
|
108 COpaqueNamedParams* args = COpaqueNamedParams::NewLC(); |
|
109 COpaqueNamedParams* results = COpaqueNamedParams::NewLC(); |
|
110 args->AddIntL( KSifInParam_InstallSilently, 1 ); |
|
111 |
|
112 TRequestStatus status; |
|
113 installer.Install( param, *args, *results, status ); |
|
114 User::WaitForRequest( status ); |
|
115 testResult = status.Int(); |
|
116 |
|
117 CleanupStack::PopAndDestroy( 2, args ); |
|
118 |
|
119 Print( 1, KTestParamFormatArg, &KTestName, ¶m, testResult ); |
|
120 } |
|
121 |
|
122 CleanupStack::PopAndDestroy( &installer ); |
|
123 |
|
124 Print( 0, KTestDoneFormat, &KTestName ); |
|
125 return testResult; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CTestStartupListUpdater::RemoveL() |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CTestStartupListUpdater::RemoveL( CStifItemParser& aItem ) |
|
133 { |
|
134 _LIT( KTestName, "Remove" ); |
|
135 Print( 0, KTestStartFormat, &KTestName ); |
|
136 TInt testResult = KErrNone; |
|
137 |
|
138 RSoftwareComponentRegistry registry; |
|
139 User::LeaveIfError( registry.Connect() ); |
|
140 CleanupClosePushL( registry ); |
|
141 |
|
142 // Get installed application TComponentIds and TUids |
|
143 RArray<TUid> uidList; |
|
144 CleanupClosePushL( uidList ); |
|
145 RArray<TComponentId> componentIdList; |
|
146 CleanupClosePushL( componentIdList ); |
|
147 |
|
148 registry.GetComponentIdsL( componentIdList ); |
|
149 for( TInt i = 0; i < componentIdList.Count(); ++i ) { |
|
150 TComponentId compId = componentIdList[ i ]; |
|
151 CComponentEntry *compEntry = CComponentEntry::NewLC(); |
|
152 if( registry.GetComponentL( compId, *compEntry ) ) { |
|
153 if( compEntry->IsRemovable() && compEntry->SoftwareType() == KSoftwareTypeNative ) |
|
154 { |
|
155 _LIT(KCompUid, "CompUid"); |
|
156 CPropertyEntry *property = registry.GetComponentPropertyL( compId, KCompUid ); |
|
157 CleanupStack::PushL( property ); |
|
158 CIntPropertyEntry* intProperty = dynamic_cast<CIntPropertyEntry*>( property ); |
|
159 uidList.AppendL( TUid::Uid( intProperty->IntValue() ) ); |
|
160 CleanupStack::PopAndDestroy( property ); |
|
161 } else { |
|
162 uidList.AppendL( KNullUid ); |
|
163 } |
|
164 |
|
165 } |
|
166 CleanupStack::PopAndDestroy( compEntry ); |
|
167 } |
|
168 if( uidList.Count() != componentIdList.Count() ) |
|
169 { |
|
170 _LIT( KFailedToGetIds, "Failed to get IDs" ); |
|
171 Print( 0, KTestStartFormat, &KFailedToGetIds ); |
|
172 testResult = KErrGeneral; |
|
173 } |
|
174 |
|
175 // Uninstall TUid apps listed in parameters |
|
176 TPtrC param; |
|
177 while( aItem.GetNextString ( param ) == KErrNone && testResult == KErrNone ) |
|
178 { |
|
179 const TUint KMaxLimit = 0xFFFFFFFF; |
|
180 TLex lex( param ); |
|
181 TUint32 intVal = 0; |
|
182 |
|
183 _LIT( KHexPrefix, "0x" ); |
|
184 if( param.Left( KHexPrefix().Length() ) == KHexPrefix ) |
|
185 { |
|
186 lex.Inc( KHexPrefix().Length() ); |
|
187 testResult = lex.BoundedVal( intVal, EHex, KMaxLimit ); |
|
188 } |
|
189 else |
|
190 { |
|
191 testResult = lex.BoundedVal( intVal, EDecimal, KMaxLimit ); |
|
192 } |
|
193 |
|
194 if( testResult == KErrNone ) |
|
195 { |
|
196 TUid uid( TUid::Uid( intVal ) ); |
|
197 if( uid != KNullUid ) |
|
198 { |
|
199 TInt index = uidList.Find( uid ); |
|
200 if( index >= 0 && index < componentIdList.Count() ) |
|
201 { |
|
202 TComponentId componentId = componentIdList[ index ]; |
|
203 |
|
204 RSoftwareInstall installer; |
|
205 User::LeaveIfError( installer.Connect() ); |
|
206 CleanupClosePushL( installer ); |
|
207 |
|
208 TRequestStatus status; |
|
209 installer.Uninstall( componentId, status ); |
|
210 User::WaitForRequest( status ); |
|
211 testResult = status.Int(); |
|
212 |
|
213 CleanupStack::PopAndDestroy( &installer ); |
|
214 } |
|
215 else |
|
216 { |
|
217 testResult = KErrNotFound; |
|
218 } |
|
219 } |
|
220 else |
|
221 { |
|
222 testResult = KErrUnknown; |
|
223 } |
|
224 } |
|
225 Print( 1, KTestParamFormatArg, &KTestName, ¶m, testResult ); |
|
226 } |
|
227 |
|
228 CleanupStack::PopAndDestroy( 3, ®istry ); // componentIdList, uidList, registry |
|
229 Print( 0, KTestDoneFormat, &KTestName ); |
|
230 return testResult; |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CTestStartupListUpdater::CheckStartListContainsL() |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 TInt CTestStartupListUpdater::CheckStartListContainsL( CStifItemParser& aItem ) |
|
238 { |
|
239 _LIT( KTestName, "InStartList" ); |
|
240 Print( 0, KTestStartFormat, &KTestName ); |
|
241 TInt testResult = KErrNone; |
|
242 |
|
243 RPointerArray<HBufC> startupList; |
|
244 CleanupResetAndDestroyPushL( startupList ); |
|
245 GetStartupListL( startupList ); |
|
246 |
|
247 TIdentityRelation<HBufC> compareFileNames( FileNamesEqual ); |
|
248 |
|
249 TPtrC param; |
|
250 while( aItem.GetNextString ( param ) == KErrNone ) |
|
251 { |
|
252 HBufC* buf = param.AllocLC(); |
|
253 if( startupList.Find( buf, compareFileNames ) == KErrNotFound ) |
|
254 { |
|
255 testResult = KErrNotFound; |
|
256 } |
|
257 CleanupStack::PopAndDestroy( buf ); |
|
258 Print( 1, KTestParamFormatArg, &KTestName, ¶m, testResult ); |
|
259 } |
|
260 |
|
261 CleanupStack::PopAndDestroy( &startupList ); |
|
262 |
|
263 Print( 0, KTestDoneFormat, &KTestName ); |
|
264 return testResult; |
|
265 } |
|
266 |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CTestStartupListUpdater::CheckStartListDoesNotContainL() |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 TInt CTestStartupListUpdater::CheckStartListDoesNotContainL( CStifItemParser& aItem ) |
|
273 { |
|
274 _LIT( KTestName, "NotInStartList" ); |
|
275 Print( 0, KTestStartFormat, &KTestName ); |
|
276 TInt testResult = KErrNone; |
|
277 |
|
278 RPointerArray<HBufC> startupList; |
|
279 CleanupResetAndDestroyPushL( startupList ); |
|
280 GetStartupListL( startupList ); |
|
281 |
|
282 TIdentityRelation<HBufC> compareFileNames( FileNamesEqual ); |
|
283 |
|
284 TPtrC param; |
|
285 while( aItem.GetNextString ( param ) == KErrNone ) |
|
286 { |
|
287 HBufC* buf = param.AllocLC(); |
|
288 if( startupList.Find( buf, compareFileNames ) >= 0 ) |
|
289 { |
|
290 testResult = KErrAlreadyExists; |
|
291 } |
|
292 CleanupStack::PopAndDestroy( buf ); |
|
293 Print( 1, KTestParamFormatArg, &KTestName, ¶m, testResult ); |
|
294 } |
|
295 |
|
296 CleanupStack::PopAndDestroy( &startupList ); |
|
297 |
|
298 Print( 0, KTestDoneFormat, &KTestName ); |
|
299 return testResult; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CTestStartupListUpdater::GetStartupListL() |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CTestStartupListUpdater::GetStartupListL( RPointerArray<HBufC>& aStartupList ) |
|
307 { |
|
308 RDscStore dscStore; |
|
309 dscStore.OpenL(); |
|
310 CleanupClosePushL( dscStore ); |
|
311 if( !dscStore.DscExistsL() ) |
|
312 { |
|
313 dscStore.CreateDscL(); |
|
314 } |
|
315 dscStore.EnumOpenLC(); |
|
316 |
|
317 while( CDscItem* item = dscStore.EnumReadNextL() ) |
|
318 { |
|
319 CleanupStack::PushL( item ); |
|
320 aStartupList.AppendL( item->FileName().AllocL() ); |
|
321 CleanupStack::PopAndDestroy( item ); |
|
322 } |
|
323 |
|
324 CleanupStack::PopAndDestroy( 2, &dscStore ); // EnumClose, dscStore |
|
325 } |
|