|
1 /* |
|
2 * Copyright (c) 2002 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: Implementation of applicationmanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32svr.h> |
|
22 #include <StifParser.h> |
|
23 #include <Stiftestinterface.h> |
|
24 #include "amtest.h" |
|
25 #include "applicationmanagementclient.h" |
|
26 #include <e32math.h> |
|
27 #include <f32file.h> |
|
28 #include <swinstapi.h> |
|
29 |
|
30 |
|
31 using namespace NApplicationManagement; |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // Camtest::Delete |
|
37 // Delete here all resources allocated and opened from test methods. |
|
38 // Called from destructor. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 void Camtest::Delete() |
|
42 { |
|
43 |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // Camtest::RunMethodL |
|
48 // Run specified method. Contains also table of test mothods and their names. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 TInt Camtest::RunMethodL( |
|
52 CStifItemParser& aItem ) |
|
53 { |
|
54 |
|
55 TStifFunctionInfo const KFunctions[] = |
|
56 { |
|
57 // Copy this line for every implemented function. |
|
58 // First string is the function name used in TestScripter script file. |
|
59 // Second is the actual implementation member function. |
|
60 ENTRY( "DDFStructure", Camtest::DDFStructureL), |
|
61 ENTRY( "List", Camtest::ExampleL ), |
|
62 ENTRY( "Deliver", Camtest::DeliverL ), |
|
63 ENTRY( "Details", Camtest::DetailsL ), |
|
64 ENTRY( "Install", Camtest::InstallL ), |
|
65 ENTRY( "BareInstall", Camtest::BareInstallL ), |
|
66 ENTRY( "FetchNode", Camtest::FetchNodeL ), |
|
67 ENTRY( "FetchLeaf", Camtest::FetchLeafL ), |
|
68 ENTRY( "FetchLeafObjectSizeL", Camtest::FetchLeafObjectSizeL ), |
|
69 //ENTRY( "CompleteCommands", Cdmatest::CompleteCommandsL ), |
|
70 ENTRY( "AddNode", Camtest::AddNodeL ), |
|
71 ENTRY( "UpdateLeaf", Camtest::UpdateLeafL ), |
|
72 ENTRY( "UpdateLeafData", Camtest::UpdateLeafDataL ), |
|
73 ENTRY( "UpdateLeafDataURI", Camtest::UpdateLeafDataURLL ), |
|
74 ENTRY( "Execute", Camtest::ExecuteLeafL ), |
|
75 ENTRY( "ExecuteData", Camtest::ExecuteLeafDataL ), |
|
76 ENTRY( "DeleteNode", Camtest::DeleteObjectL ), |
|
77 ENTRY( "StartAtomic", Camtest::StartAtomicL), |
|
78 ENTRY( "CommitAtomic", Camtest::CommitAtomicL), |
|
79 ENTRY( "RollbackAtomic", Camtest::RollbackAtomicL), |
|
80 //Newly addded |
|
81 ENTRY( "AddLeafNode", Camtest::AddLeafNode), |
|
82 ENTRY( "InstallActivate", Camtest::InstallActivate), |
|
83 //Newly ended |
|
84 // ENTRY( "BareAppInstall", Camtest::BareAppInstallL), |
|
85 /* ENTRY( "DDFStructure", Camtest::DDFStructureL),*///BareAppInstallL |
|
86 }; |
|
87 |
|
88 const TInt count = sizeof( KFunctions ) / |
|
89 sizeof( TStifFunctionInfo ); |
|
90 |
|
91 return RunInternalL( KFunctions, count, aItem ); |
|
92 |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // Camtest::ExampleL |
|
97 // Example test method function. |
|
98 // (other items were commented in a header). |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TInt Camtest::ExampleL( CStifItemParser& /*aItem*/ ) |
|
102 { |
|
103 |
|
104 // Print to UI |
|
105 TestModuleIf().Printf( 0, _L("amtest"), _L("In Example") ); |
|
106 // Print to log file |
|
107 iLog->Log(_L("In Example")); |
|
108 |
|
109 RApplicationManagement ams ; |
|
110 TInt err( ams.Connect() ); |
|
111 |
|
112 if ( err == KErrNone ) |
|
113 { |
|
114 RElementIdArray array; |
|
115 ams.DeploymentComponentIdsL(array); |
|
116 iLog->Log( _L( "Found %d Ids" ), array.Count() ); |
|
117 for ( TInt i = 0; i < array.Count(); i++ ) |
|
118 { |
|
119 iLog->Log( _L( " Id %d: %d" ), i, array[i] ); |
|
120 } |
|
121 |
|
122 |
|
123 TDeploymentComponent comp ; |
|
124 comp.iId = _L8( "Iidee" ); |
|
125 TBuf8<10> buf; |
|
126 TTime tm; |
|
127 tm.HomeTime(); |
|
128 TInt64 rn = tm.Int64() ; |
|
129 TInt rand = Math::Rand( rn ) ; |
|
130 buf.NumFixedWidth( rand, EHex, 10); |
|
131 |
|
132 comp.iId.Append( buf ); |
|
133 comp.iVersion = _L8( "2.3" ); |
|
134 comp.iName = _L8( "Nimi" ); |
|
135 |
|
136 err = ams.DeliverL(/*_L8("Leaf"), */comp.iId/*, comp.iName, comp.iVersion, EDCSDelivered, _L8("datadatadatadata"), _L8("iopts"), _L8("meta") */) ; |
|
137 iLog->Log( _L( " Deliver response: %d, state: %d" ), err, comp.iState ); |
|
138 User::LeaveIfError ( err ); |
|
139 err = KErrNone; |
|
140 |
|
141 array.Reset(); |
|
142 ams.DeploymentComponentIdsL(array); |
|
143 iLog->Log( _L( "Found 2ndtime %d Ids" ), array.Count() ); |
|
144 for ( TInt i = 0; i < array.Count(); i++ ) |
|
145 { |
|
146 iLog->Log( _L( " Id %d: %d" ), i, array[i] ); |
|
147 |
|
148 TDeploymentComponent comp2 ; |
|
149 err = ams.DeploymentComponent(array[i], comp); |
|
150 iLog->Log( _L( " DeploymentComponent response: %d, state: %d" ), err, comp.iState ); |
|
151 if ( err == KErrNone ) |
|
152 { |
|
153 HBufC *b = HBufC::NewLC( comp.iId.Length() ); |
|
154 TPtr p( b->Des() ); |
|
155 p.Copy( comp.iId ); |
|
156 |
|
157 iLog->Log( _L( "CompId: %S" ), &p ); |
|
158 CleanupStack::PopAndDestroy(); |
|
159 } |
|
160 else |
|
161 { |
|
162 |
|
163 } |
|
164 } |
|
165 ams.Close(); |
|
166 } |
|
167 else |
|
168 { |
|
169 iLog->Log( _L( "Failed to connect: %d" ), err); |
|
170 } |
|
171 |
|
172 return err; |
|
173 |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // Camtest::ExampleL |
|
178 // Example test method function. |
|
179 // (other items were commented in a header). |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 TInt Camtest::DetailsL( CStifItemParser& aItem ) |
|
183 { |
|
184 |
|
185 // Print to UI |
|
186 TestModuleIf().Printf( 0, _L("amtest"), _L("In DetailsL") ); |
|
187 // Print to log file |
|
188 iLog->Log(_L("In DetailsL")); |
|
189 |
|
190 RApplicationManagement ams ; |
|
191 TInt err( ams.Connect() ); |
|
192 |
|
193 if ( err == KErrNone ) |
|
194 { |
|
195 |
|
196 TInt i( 0 ); |
|
197 TInt nodename; |
|
198 i = aItem.GetNextInt ( nodename ) ; |
|
199 if ( i != KErrNone ) |
|
200 { |
|
201 iLog->Log( _L( "ERROR Reading id argument: 0x%X"), i); |
|
202 //return i; |
|
203 } |
|
204 else |
|
205 { |
|
206 iLog->Log( _L("id: %d"), nodename); |
|
207 } |
|
208 |
|
209 RElementIdArray array; |
|
210 ams.DeploymentComponentIdsL(array); |
|
211 iLog->Log( _L( "Found %d Ids" ), array.Count() ); |
|
212 for ( TInt i = 0; i < array.Count(); i++ ) |
|
213 { |
|
214 |
|
215 iLog->Log( _L( " Id %d: %d" ), i, array[i] ); |
|
216 |
|
217 TDeploymentComponent comp2 ; |
|
218 err = ams.DeploymentComponent(array[i], comp2); |
|
219 iLog->Log( _L( " DeploymentComponent response: %d, state: %d" ), err, comp2.iState ); |
|
220 if ( err == KErrNone ) |
|
221 { |
|
222 HBufC *b = HBufC::NewLC( comp2.iId.Length() ); |
|
223 TPtr p( b->Des() ); |
|
224 p.Copy( comp2.iId ); |
|
225 |
|
226 iLog->Log( _L( "CompId: %S" ), &p ); |
|
227 CleanupStack::PopAndDestroy(); |
|
228 } |
|
229 else |
|
230 { |
|
231 |
|
232 } |
|
233 } |
|
234 User::LeaveIfError ( err ); |
|
235 err = KErrNone; |
|
236 ams.Close(); |
|
237 } |
|
238 else |
|
239 { |
|
240 iLog->Log( _L( "Failed to connect: %d" ), err); |
|
241 } |
|
242 return err; |
|
243 } |
|
244 |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // Camtest::InstallL |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 TInt Camtest::InstallL( CStifItemParser& aItem ) |
|
251 { |
|
252 |
|
253 // Print to UI |
|
254 TestModuleIf().Printf( 0, _L("amtest"), _L("In InstallL") ); |
|
255 // Print to log file |
|
256 |
|
257 iLog->Log(_L("In DetailsL")); |
|
258 TCertInfo info ; |
|
259 info.iFingerprint =_L8("finger"); |
|
260 info.iSerialNo = _L8("serial"); |
|
261 |
|
262 RApplicationManagement ams ; |
|
263 TInt err( ams.Connect( info ) ); |
|
264 |
|
265 |
|
266 if ( err == KErrNone ) |
|
267 { |
|
268 |
|
269 TInt i( 0 ); |
|
270 TUint32 nodename; |
|
271 i = aItem.GetNextInt ( (TInt&)nodename ) ; |
|
272 if ( i != KErrNone ) |
|
273 { |
|
274 iLog->Log( _L( "ERROR Reading id argument: 0x%X"), i); |
|
275 //return i; |
|
276 } |
|
277 else |
|
278 { |
|
279 iLog->Log( _L("id: %d"), nodename); |
|
280 } |
|
281 |
|
282 /* RElementIdArray array; |
|
283 ams.DeploymentComponentIdsL(array); |
|
284 iLog->Log( _L( "Found %d Ids" ), array.Count() ); |
|
285 for ( TInt i = 0; i < array.Count(); i++ ) |
|
286 { |
|
287 |
|
288 iLog->Log( _L( " Id %d: %d" ), i, array[i] ); |
|
289 |
|
290 TDeploymentComponent comp2 ; |
|
291 err = ams.DeploymentComponent(array[i], comp2); |
|
292 iLog->Log( _L( " DeploymentComponent response: %d, state: %d" ), err, comp2.iState ); |
|
293 if ( err == KErrNone ) |
|
294 { |
|
295 HBufC *b = HBufC::NewLC( comp2.iId.Length() ); |
|
296 TPtr p( b->Des() ); |
|
297 p.Copy( comp2.iId ); |
|
298 |
|
299 iLog->Log( _L( "CompId: %S" ), &p ); |
|
300 CleanupStack::PopAndDestroy(); |
|
301 |
|
302 } |
|
303 else |
|
304 { |
|
305 |
|
306 } |
|
307 |
|
308 if ( nodename == array[i] ) |
|
309 { |
|
310 iLog->Log( _L( "CompId: %S" ), &p ); |
|
311 } |
|
312 } |
|
313 */ |
|
314 ams.InstallL( nodename ) ; |
|
315 User::LeaveIfError ( err ); |
|
316 err = KErrNone; |
|
317 |
|
318 ams.Close(); |
|
319 } |
|
320 else |
|
321 { |
|
322 iLog->Log( _L( "Failed to connect: %d" ), err); |
|
323 } |
|
324 return err; |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // Camtest::InstallL |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 TInt Camtest::BareInstallL( CStifItemParser& aItem ) |
|
332 { |
|
333 |
|
334 // Print to UI |
|
335 TestModuleIf().Printf( 0, _L("amtest"), _L("In InstallL") ); |
|
336 // Print to log file |
|
337 iLog->Log(_L("In DetailsL")); |
|
338 |
|
339 /*void CAmAdapter::InstallL( |
|
340 TUint aLuidi, |
|
341 const TDesC8& aURI, |
|
342 const TDesC8& aLUID, |
|
343 const TDeploymentComponentState aTargetState, |
|
344 TError &aRet |
|
345 TInt aluidi( 0 ); |
|
346 TUint32 aLuidInt; |
|
347 aluidi = aItem.GetNextInt ( (TInt&)aLuidInt ) ; |
|
348 |
|
349 |
|
350 TPtrC8 nodename( GetNextStringLC ( aItem, _L("Node name") )->Des() ) ; |
|
351 |
|
352 |
|
353 SetURIL( nodename ); |
|
354 |
|
355 HBufC8 *luid = GetLuidAllocLC( *iURI ); |
|
356 TError ret( EError ); |
|
357 |
|
358 TRAPD( err, Adapter()->InstallL(aluidi,*iURI, *luid,3 ,ret));*/ |
|
359 |
|
360 //using namespace SwiUI; |
|
361 SwiUI::RSWInstLauncher ams ; |
|
362 TInt err( ams.Connect() ); |
|
363 |
|
364 if ( err == KErrNone ) |
|
365 { |
|
366 CleanupClosePushL( ams ); |
|
367 iLog->Log( _L( "Connected!" )); |
|
368 TPtrC filename ; |
|
369 User::LeaveIfError( aItem.GetNextString( filename ) ); |
|
370 |
|
371 |
|
372 |
|
373 TRequestStatus stat; |
|
374 |
|
375 ams.Install( stat, filename ); |
|
376 User::WaitForRequest( stat ); |
|
377 CleanupStack::Pop(); |
|
378 |
|
379 ams.Close(); |
|
380 } |
|
381 else |
|
382 { |
|
383 iLog->Log( _L( "Failed to connect: %d" ), err); |
|
384 } |
|
385 return err; |
|
386 } |
|
387 |
|
388 |
|
389 HBufC8 *Camtest::GetNextStringLC ( CStifItemParser& aItem, const TDesC &aName ) |
|
390 { |
|
391 TPtrC nodename; |
|
392 nodename.Set( KNullDesC ); |
|
393 |
|
394 TInt i( aItem.GetNextString ( nodename ) ); |
|
395 if ( i != KErrNone ) |
|
396 { |
|
397 iLog->Log( _L( "ERROR Reading '%S' argument: 0x%X" ), &aName, i ); |
|
398 } |
|
399 else |
|
400 { |
|
401 iLog->Log( _L("%S: %S"), &aName, &nodename); |
|
402 } |
|
403 |
|
404 HBufC8 *buf = HBufC8::NewLC( nodename.Length() ) ; |
|
405 buf->Des().Copy( nodename ); |
|
406 |
|
407 return buf; |
|
408 } |
|
409 |
|
410 |
|
411 HBufC8 *LoadFileL( const TDesC8 &aDataFile ) |
|
412 { |
|
413 RFs fs ; |
|
414 User::LeaveIfError( fs.Connect() ); |
|
415 CleanupClosePushL( fs ); // 1 |
|
416 RFile file ; |
|
417 TFileName fn; |
|
418 fn.Copy( aDataFile ); |
|
419 User::LeaveIfError ( file.Open( fs, fn, EFileRead ) ); |
|
420 CleanupClosePushL( file ); // 2 |
|
421 TInt size; |
|
422 User::LeaveIfError( file.Size( size ) ); |
|
423 |
|
424 HBufC8 *res = HBufC8::NewLC( size ); //3 |
|
425 TPtr8 p( res->Des() ); |
|
426 User::LeaveIfError( file.Read( p ) ); |
|
427 CleanupStack::Pop(); // res |
|
428 CleanupStack::PopAndDestroy( 2 ); // file, fs |
|
429 CleanupStack::PushL( res ); |
|
430 return res ; |
|
431 } |
|
432 |
|
433 // ----------------------------------------------------------------------------- |
|
434 // Camtest::ExampleL |
|
435 // Example test method function. |
|
436 // (other items were commented in a header). |
|
437 // ----------------------------------------------------------------------------- |
|
438 // |
|
439 TInt Camtest::DeliverL( CStifItemParser& aItem ) |
|
440 { |
|
441 |
|
442 // Print to UI |
|
443 TestModuleIf().Printf( 0, _L("amtest"), _L("In DeliverL") ); |
|
444 // Print to log file |
|
445 iLog->Log(_L("In DeliverL")); |
|
446 |
|
447 RApplicationManagement ams ; |
|
448 TInt err( ams.Connect() ); |
|
449 |
|
450 if ( err == KErrNone ) |
|
451 { |
|
452 CleanupClosePushL( ams ); |
|
453 HBufC8 *id = GetNextStringLC ( aItem, _L("Id") ) ; |
|
454 HBufC8 *name = GetNextStringLC( aItem, _L( "Name" ) ) ; |
|
455 HBufC8 *version = GetNextStringLC ( aItem, _L( "Version" ) ) ; |
|
456 HBufC8 *data = GetNextStringLC ( aItem, _L( "data" ) ) ; |
|
457 HBufC8 *instopt = GetNextStringLC (aItem, _L( "InstOpts" ) ) ; |
|
458 if ( data != NULL ) |
|
459 { |
|
460 //HBufC8 *datat = NULL; |
|
461 HBufC8 *datat = LoadFileL( *data ); |
|
462 RElementIdArray array; |
|
463 ams.DeploymentComponentIdsL(array); |
|
464 iLog->Log( _L( "Found %d Ids" ), array.Count() ); |
|
465 for ( TInt i = 0; i < array.Count(); i++ ) |
|
466 { |
|
467 iLog->Log( _L( " Id %d: %d" ), i, array[i] ); |
|
468 } |
|
469 |
|
470 TDeploymentComponent comp ; |
|
471 comp.iId = *id; |
|
472 comp.iVersion = *version; |
|
473 comp.iName = *name; |
|
474 |
|
475 err = ams.DeliverL(/*_L8("Jee"),*/ comp.iId/*, comp.iName, comp.iVersion, EDCSDelivered , *datat, *instopt, _L8("meta") */) ; |
|
476 iLog->Log( _L( " Deliver response: %d, state: %d" ), err, comp.iState ); |
|
477 User::LeaveIfError ( err ); |
|
478 err = KErrNone; |
|
479 |
|
480 array.Reset(); |
|
481 ams.DeploymentComponentIdsL(array); |
|
482 iLog->Log( _L( "Found 2ndtime %d Ids" ), array.Count() ); |
|
483 for ( TInt i = 0; i < array.Count(); i++ ) |
|
484 { |
|
485 iLog->Log( _L( " Id %d: %d" ), i, array[i] ); |
|
486 } |
|
487 |
|
488 CleanupStack::PopAndDestroy( datat ); |
|
489 } |
|
490 CleanupStack::PopAndDestroy( instopt ); |
|
491 CleanupStack::PopAndDestroy( data ); |
|
492 CleanupStack::PopAndDestroy( version ); |
|
493 CleanupStack::PopAndDestroy( name ); |
|
494 CleanupStack::PopAndDestroy( id ); |
|
495 CleanupStack::PopAndDestroy( ); //ams |
|
496 } |
|
497 else |
|
498 { |
|
499 iLog->Log( _L( "Failed to connect: %d" ), err); |
|
500 } |
|
501 |
|
502 return err; |
|
503 |
|
504 } |
|
505 |
|
506 |
|
507 // End of File |