|
1 /* |
|
2 * Copyright (c) 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 "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: Simple application for testing Sif API |
|
15 * (install, uninstall, get component info) |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 #include <e32property.h> |
|
23 #include <stdio.h> |
|
24 #include <s60commonutils.h> |
|
25 |
|
26 #include <usif/sif/sif.h> |
|
27 |
|
28 |
|
29 #include "logger.h" |
|
30 |
|
31 using namespace Usif; |
|
32 |
|
33 _LIT(KTestMIDlet, "E:\\stopwatch10midp2.jad"); |
|
34 //_LIT(KTestMIDlet, "C:\\data\\installs\\DS_Snow.jad"); |
|
35 |
|
36 /** |
|
37 * Installs a component by file name |
|
38 */ |
|
39 static void sifSimplestInstallL() |
|
40 { |
|
41 LOG(EJavaConverters, EInfo, |
|
42 "testsifapi: sifInstallL: Called"); |
|
43 |
|
44 RSoftwareInstall installer; |
|
45 TInt err = installer.Connect(); |
|
46 if (KErrNone != err) |
|
47 { |
|
48 ELOG1(EJavaConverters, |
|
49 "testsifapi: sifInstallL: Cannot connect to RSoftwareInstall, err %d", err); |
|
50 User::Leave(err); |
|
51 } |
|
52 CleanupClosePushL(installer); |
|
53 |
|
54 TRequestStatus status; |
|
55 |
|
56 installer.Install(KTestMIDlet, status); |
|
57 |
|
58 User::WaitForRequest(status); |
|
59 |
|
60 LOG1(EJavaConverters, EInfo, |
|
61 "testsifapi: sifInstallL: The return status of install operation was %d", status.Int()); |
|
62 |
|
63 // free resources before returning |
|
64 CleanupStack::PopAndDestroy(1); |
|
65 } |
|
66 |
|
67 /** |
|
68 * Installs a component by file handle using opaque arguments/results |
|
69 */ |
|
70 static TInt sifByHandleAndArgsAndResultsInstallL() |
|
71 { |
|
72 // Open file handle to the installation file |
|
73 RFs fs; |
|
74 TInt err = fs.Connect(); |
|
75 if (KErrNone != err) |
|
76 { |
|
77 ELOG1(EJavaConverters, |
|
78 "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot connect to RFs, err %d", err); |
|
79 User::Leave(err); |
|
80 } |
|
81 CleanupClosePushL(fs); |
|
82 |
|
83 // If the file server session is not shared, USIF server crashes with KERN-EXEC 44 |
|
84 err = fs.ShareProtected(); |
|
85 if (KErrNone != err) |
|
86 { |
|
87 ELOG1(EJavaConverters, |
|
88 "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot share RFs, err %d", err); |
|
89 User::Leave(err); |
|
90 } |
|
91 |
|
92 RFile installFile; |
|
93 err = installFile.Open(fs, KTestMIDlet, EFileShareReadersOnly | EFileRead); |
|
94 if (KErrNone != err) |
|
95 { |
|
96 ELOG1(EJavaConverters, |
|
97 "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot open " |
|
98 "E:\\stopwatch10midp2.jad, err %d", err); |
|
99 User::Leave(err); |
|
100 } |
|
101 CleanupClosePushL(installFile); |
|
102 |
|
103 LOG(EJavaConverters, EInfo, |
|
104 "testsifapi: sifByHandleAndArgsAndResultsInstallL: installFile handle opened"); |
|
105 |
|
106 RSoftwareInstall installer; |
|
107 err = installer.Connect(); |
|
108 if (KErrNone != err) |
|
109 { |
|
110 ELOG1(EJavaConverters, |
|
111 "testsifapi: sifByHandleAndArgsAndResultsInstallL: Cannot connect to RSoftwareInstall, err %d", err); |
|
112 User::Leave(err); |
|
113 } |
|
114 CleanupClosePushL(installer); |
|
115 |
|
116 LOG(EJavaConverters, EInfo, |
|
117 "testsifapi: sifByHandleAndArgsAndResultsInstallL: RSoftwareInstall connected"); |
|
118 |
|
119 TRequestStatus status; |
|
120 COpaqueNamedParams *arguments = COpaqueNamedParams::NewL(); |
|
121 CleanupStack::PushL(arguments); |
|
122 COpaqueNamedParams *results = COpaqueNamedParams::NewL(); |
|
123 CleanupStack::PushL(results); |
|
124 |
|
125 // Silent installation request |
|
126 arguments->AddIntL(KSifInParam_InstallSilently, 1); |
|
127 |
|
128 LOG(EJavaConverters, EInfo, |
|
129 "testsifapi: sifByHandleAndArgsAndResultsInstallL: arguments created"); |
|
130 |
|
131 installer.Install(installFile, *arguments, *results, status); |
|
132 |
|
133 User::WaitForRequest(status); |
|
134 |
|
135 LOG1(EJavaConverters, EInfo, |
|
136 "testsifapi: sifByHandleAndArgsAndResultsInstallL: The return status of install operation was %d", status.Int()); |
|
137 |
|
138 |
|
139 TInt componentId = 0; |
|
140 TBool idExisted = results->GetIntByNameL(KSifOutParam_ComponentId, componentId); |
|
141 if ( idExisted ) |
|
142 { |
|
143 LOG1(EJavaConverters, EInfo, |
|
144 "testsifapi: sifByHandleAndArgsAndResultsInstallL: Component id was %d", componentId); |
|
145 } |
|
146 else |
|
147 { |
|
148 LOG(EJavaConverters, EInfo, |
|
149 "testsifapi: sifByHandleAndArgsAndResultsInstallL: No component id was returned"); |
|
150 } |
|
151 |
|
152 // free resources before returning |
|
153 CleanupStack::PopAndDestroy(5); |
|
154 |
|
155 return componentId; |
|
156 } |
|
157 |
|
158 |
|
159 static void sifUninstallL(TInt &aComponentId) |
|
160 { |
|
161 LOG1(EJavaConverters, EInfo, |
|
162 "testsifapi: sifUninstallL: Uninstall component (id %d)", aComponentId); |
|
163 |
|
164 RSoftwareInstall installer; |
|
165 TInt err = installer.Connect(); |
|
166 if (KErrNone != err) |
|
167 { |
|
168 ELOG1(EJavaConverters, |
|
169 "testsifapi: sifUninstallL: Cannot connect to RSoftwareInstall, err %d", err); |
|
170 User::Leave(err); |
|
171 } |
|
172 CleanupClosePushL(installer); |
|
173 |
|
174 TRequestStatus status; |
|
175 COpaqueNamedParams *arguments = COpaqueNamedParams::NewL(); |
|
176 CleanupStack::PushL(arguments); |
|
177 COpaqueNamedParams *results = COpaqueNamedParams::NewL(); |
|
178 CleanupStack::PushL(results); |
|
179 |
|
180 // Silent uninstallation request |
|
181 arguments->AddIntL(KSifInParam_InstallSilently, 1); |
|
182 |
|
183 installer.Uninstall(aComponentId, *arguments, *results, status, EFalse); |
|
184 |
|
185 User::WaitForRequest(status); |
|
186 |
|
187 LOG1(EJavaConverters, EInfo, |
|
188 "testsifapi: sifUninstallL: The return status of uinstall operation was %d", status.Int()); |
|
189 |
|
190 // free resources before returning |
|
191 CleanupStack::PopAndDestroy(3); |
|
192 } |
|
193 |
|
194 |
|
195 static void logComponentInfoNode(const CComponentInfo::CNode& aNode) |
|
196 { |
|
197 std::wstring buf((wchar_t*) aNode.SoftwareTypeName().Ptr(), aNode.SoftwareTypeName().Length()); |
|
198 LOG1WSTR(EJavaConverters, EInfo, |
|
199 "SoftwareTypeName is %s", |
|
200 buf.c_str()); |
|
201 |
|
202 std::wstring buf2((wchar_t*) aNode.ComponentName().Ptr(), aNode.ComponentName().Length()); |
|
203 LOG1WSTR(EJavaConverters, EInfo, |
|
204 "ComponentName is %s", |
|
205 buf2.c_str()); |
|
206 |
|
207 std::wstring buf3((wchar_t*) aNode.Version().Ptr(), aNode.Version().Length()); |
|
208 LOG1WSTR(EJavaConverters, EInfo, |
|
209 "Version is %s", |
|
210 buf3.c_str()); |
|
211 |
|
212 std::wstring buf4((wchar_t*) aNode.Vendor().Ptr(), aNode.Vendor().Length()); |
|
213 LOG1WSTR(EJavaConverters, EInfo, |
|
214 "Vendor is %s", |
|
215 buf4.c_str()); |
|
216 |
|
217 LOG1(EJavaConverters, EInfo, |
|
218 "ScomoState is %d", |
|
219 aNode.ScomoState()); |
|
220 |
|
221 LOG1(EJavaConverters, EInfo, |
|
222 "Install status of component is %d", |
|
223 aNode.InstallStatus()); |
|
224 |
|
225 LOG1(EJavaConverters, EInfo, |
|
226 "Component id is %d", |
|
227 aNode.ComponentId()); |
|
228 |
|
229 std::wstring buf5((wchar_t*) aNode.GlobalComponentId().Ptr(), aNode.GlobalComponentId().Length()); |
|
230 LOG1WSTR(EJavaConverters, EInfo, |
|
231 "GlobalComponentId is %s", |
|
232 buf5.c_str()); |
|
233 |
|
234 LOG1(EJavaConverters, EInfo, |
|
235 "Authenticity is %d", |
|
236 aNode.Authenticity()); |
|
237 |
|
238 LOG1(EJavaConverters, EInfo, |
|
239 "MaxInstalledSize is %d", |
|
240 aNode.MaxInstalledSize()); |
|
241 } |
|
242 |
|
243 static void logApplicationInfo(const CComponentInfo::CApplicationInfo& aApplication) |
|
244 { |
|
245 LOG1(EJavaConverters, EInfo, "Application uid is 0x%x", aApplication.AppUid()); |
|
246 |
|
247 std::wstring buf((wchar_t*) aApplication.Name().Ptr(), aApplication.Name().Length()); |
|
248 LOG1WSTR(EJavaConverters, EInfo, "Application name is %s", buf.c_str()); |
|
249 } |
|
250 |
|
251 static void sifGetComponentInfoL() |
|
252 { |
|
253 LOG(EJavaConverters, EInfo, |
|
254 "testsifapi: sifGetComponentInfoL: Called"); |
|
255 |
|
256 RSoftwareInstall installer; |
|
257 TInt err = installer.Connect(); |
|
258 if (KErrNone != err) |
|
259 { |
|
260 ELOG1(EJavaConverters, |
|
261 "testsifapi: sifGetComponentInfoL: Cannot connect to RSoftwareInstall, err %d", err); |
|
262 User::Leave(err); |
|
263 } |
|
264 CleanupClosePushL(installer); |
|
265 |
|
266 TRequestStatus status; |
|
267 CComponentInfo *info = CComponentInfo::NewL(); |
|
268 CleanupStack::PushL(info); |
|
269 |
|
270 installer.GetComponentInfo(KTestMIDlet, *info, status); |
|
271 |
|
272 User::WaitForRequest(status); |
|
273 |
|
274 LOG1(EJavaConverters, EInfo, |
|
275 "testsifapi: sifGetComponentInfoL: The return status of get " |
|
276 "component info operation was %d", status.Int()); |
|
277 |
|
278 LOG(EJavaConverters, EInfo, |
|
279 "testsifapi: sifGetComponentInfoL: Logging root node (suite)"); |
|
280 |
|
281 logComponentInfoNode(info->RootNodeL()); |
|
282 |
|
283 LOG(EJavaConverters, EInfo, |
|
284 "testsifapi: sifGetComponentInfoL: Logging child nodes (MIDlets)"); |
|
285 |
|
286 TInt nMIDlets = info->RootNodeL().Children().Count(); |
|
287 TInt nInd; |
|
288 for (nInd = 0; nInd < nMIDlets; nInd++) |
|
289 { |
|
290 logComponentInfoNode(*(info->RootNodeL().Children()[nInd])); |
|
291 } |
|
292 |
|
293 nMIDlets = info->RootNodeL().Applications().Count(); |
|
294 for (nInd = 0; nInd < nMIDlets; nInd++) |
|
295 { |
|
296 logApplicationInfo(*(info->RootNodeL().Applications()[nInd])); |
|
297 } |
|
298 |
|
299 // free resources before returning |
|
300 CleanupStack::PopAndDestroy(2); |
|
301 } |
|
302 |
|
303 |
|
304 static void sifActivationTestL(TInt &aComponentId) |
|
305 { |
|
306 LOG1(EJavaConverters, EInfo, |
|
307 "testsifapi: sifActivationTestL: Deactivate component (id %d)", aComponentId); |
|
308 |
|
309 RSoftwareInstall installer; |
|
310 TInt err = installer.Connect(); |
|
311 if (KErrNone != err) |
|
312 { |
|
313 ELOG1(EJavaConverters, |
|
314 "testsifapi: sifActivationTestL: Cannot connect to RSoftwareInstall, err %d", err); |
|
315 User::Leave(err); |
|
316 } |
|
317 CleanupClosePushL(installer); |
|
318 |
|
319 TRequestStatus status; |
|
320 |
|
321 installer.Deactivate(aComponentId, status); |
|
322 |
|
323 User::WaitForRequest(status); |
|
324 |
|
325 LOG1(EJavaConverters, EInfo, |
|
326 "testsifapi: sifActivationTestL: The return status of deactivation operation was %d", status.Int()); |
|
327 |
|
328 User::After(1000000); |
|
329 |
|
330 |
|
331 LOG1(EJavaConverters, EInfo, |
|
332 "testsifapi: sifActivationTestL: Activate component (id %d)", aComponentId); |
|
333 |
|
334 TRequestStatus status2; |
|
335 |
|
336 installer.Activate(aComponentId, status2); |
|
337 |
|
338 User::WaitForRequest(status2); |
|
339 |
|
340 LOG1(EJavaConverters, EInfo, |
|
341 "testsifapi: sifActivationTestL: The return status of activation operation was %d", status2.Int()); |
|
342 |
|
343 // free resources before returning |
|
344 CleanupStack::PopAndDestroy(1); |
|
345 } |
|
346 |
|
347 |
|
348 int cancelFunction(void *installer) |
|
349 { |
|
350 LOG(EJavaConverters, EInfo, |
|
351 "testsifapi: cancelFunction: Called"); |
|
352 |
|
353 // Wait for 6 seconds so that the operation to be cancelled |
|
354 // has had time to really do something already |
|
355 User::After(6000000); |
|
356 |
|
357 LOG(EJavaConverters, EInfo, |
|
358 "testsifapi: cancelFunction: Waiting for 6 seconds done"); |
|
359 |
|
360 ((RSoftwareInstall *)installer)->CancelOperation(); |
|
361 |
|
362 LOG(EJavaConverters, EInfo, |
|
363 "testsifapi: cancelFunction: CancelOperation() was called"); |
|
364 |
|
365 return 0; |
|
366 } |
|
367 |
|
368 static void cancelFromOtherThread(RSoftwareInstall &aInstaller) |
|
369 { |
|
370 RThread cancelThread; |
|
371 |
|
372 TInt err = cancelThread.Create(_L("CancelThread"), cancelFunction, 0x4000, 0, &aInstaller); |
|
373 if (err == KErrNone) |
|
374 { |
|
375 cancelThread.Resume(); |
|
376 } |
|
377 else |
|
378 { |
|
379 ELOG1(EJavaConverters, |
|
380 "testsifapi: cancelFromOtherThread: Cannot create cancel thread, err %d", err); |
|
381 } |
|
382 cancelThread.Close(); |
|
383 } |
|
384 |
|
385 static void cancelFromSameThread(RSoftwareInstall &aInstaller) |
|
386 { |
|
387 LOG(EJavaConverters, EInfo, "testsifapi: cancelFromSameThread: Called"); |
|
388 |
|
389 // Wait for 13 seconds so that the operation to be cancelled |
|
390 // has had time to really do something already |
|
391 User::After(13000000); |
|
392 |
|
393 LOG(EJavaConverters, EInfo, |
|
394 "testsifapi: cancelFromSameThread: Waited 13 seconds"); |
|
395 |
|
396 aInstaller.CancelOperation(); |
|
397 |
|
398 LOG(EJavaConverters, EInfo, |
|
399 "testsifapi: cancelFromSameThread: CancelOperation() returned"); |
|
400 } |
|
401 |
|
402 static void cancelInstallL() |
|
403 { |
|
404 LOG(EJavaConverters, EInfo, |
|
405 "testsifapi: cancelInstall: Called"); |
|
406 |
|
407 RSoftwareInstall installer; |
|
408 TInt err = installer.Connect(); |
|
409 if (KErrNone != err) |
|
410 { |
|
411 ELOG1(EJavaConverters, |
|
412 "testsifapi: sifInstallL: Cannot connect to RSoftwareInstall, err %d", err); |
|
413 User::Leave(err); |
|
414 } |
|
415 CleanupClosePushL(installer); |
|
416 |
|
417 TRequestStatus status; |
|
418 |
|
419 installer.Install(KTestMIDlet, status); |
|
420 |
|
421 LOG(EJavaConverters, EInfo, |
|
422 "testsifapi: cancelInstall: Install started"); |
|
423 |
|
424 // cancelFromOtherThread(installer); |
|
425 |
|
426 cancelFromSameThread(installer); |
|
427 |
|
428 LOG(EJavaConverters, EInfo, |
|
429 "testsifapi: cancelInstall: cancelFrom<X>Thread returned"); |
|
430 |
|
431 User::WaitForRequest(status); |
|
432 |
|
433 LOG1(EJavaConverters, EInfo, |
|
434 "testsifapi: cancelInstall: The return status of install operation was %d", status.Int()); |
|
435 |
|
436 // free resources before returning |
|
437 CleanupStack::PopAndDestroy(1); |
|
438 |
|
439 } |
|
440 |
|
441 |
|
442 /** |
|
443 * Create cleanup stack and run the cleaner code inside TRAP harness |
|
444 * to log unexpected leaves. |
|
445 */ |
|
446 TInt E32Main() |
|
447 { |
|
448 /* |
|
449 ELOG2(EJavaConverters, |
|
450 "testsifapi: Starting testing long long long long long long long long long long " |
|
451 "long long long long long long long long long long long long long long long long " |
|
452 "long long long long long long long long long long long long long long long long " |
|
453 "long long long long long long long long long long long long long buffer %d %d", 0, 1); |
|
454 |
|
455 LOG(EJavaConverters, EInfo, |
|
456 "testsifapi: sifByHandleAndArgsAndResultsInstallL: Called"); |
|
457 */ |
|
458 |
|
459 __UHEAP_MARK; |
|
460 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
461 |
|
462 TInt err = KErrNone; |
|
463 |
|
464 |
|
465 /* |
|
466 TRAP(err, cancelInstallL()); |
|
467 if (KErrNone != err) |
|
468 { |
|
469 ELOG1(EJavaConverters, "testsifapi: cancelInstallL leaved with err %d", err); |
|
470 } |
|
471 |
|
472 // Wait for a moment |
|
473 User::After(500000); |
|
474 */ |
|
475 |
|
476 |
|
477 TRAP(err, sifSimplestInstallL()); |
|
478 if (KErrNone != err) |
|
479 { |
|
480 ELOG1(EJavaConverters, "testsifapi: sifSimplestInstallL leaved with err %d", err); |
|
481 } |
|
482 |
|
483 // Wait for a moment |
|
484 User::After(500000); |
|
485 |
|
486 |
|
487 TInt componentId = 0; |
|
488 |
|
489 TRAP(err, componentId = sifByHandleAndArgsAndResultsInstallL()); |
|
490 if (KErrNone != err) |
|
491 { |
|
492 ELOG1(EJavaConverters, |
|
493 "testsifapi: sifByHandleAndArgsAndResultsInstallL leaved with err %d", err); |
|
494 } |
|
495 // Wait for a moment |
|
496 User::After(500000); |
|
497 |
|
498 // TODO: if this fails, it leaks memory |
|
499 TRAP(err, sifGetComponentInfoL()); |
|
500 if (KErrNone != err) |
|
501 { |
|
502 ELOG1(EJavaConverters, "testsifapi: sifGetComponentInfoL leaved with err %d", err); |
|
503 } |
|
504 |
|
505 // Wait for a moment |
|
506 User::After(500000); |
|
507 |
|
508 TRAP(err, sifActivationTestL(componentId)); |
|
509 if (KErrNone != err) |
|
510 { |
|
511 ELOG1(EJavaConverters, |
|
512 "testsifapi: sifActivationTestL leaved with err %d", err); |
|
513 } |
|
514 |
|
515 // Wait for a moment |
|
516 User::After(500000); |
|
517 |
|
518 |
|
519 // TODO: if this fails, it leaks memory |
|
520 if (0 != componentId) |
|
521 { |
|
522 TRAP(err, sifUninstallL(componentId)); |
|
523 if (KErrNone != err) |
|
524 { |
|
525 ELOG1(EJavaConverters, |
|
526 "testsifapi: sifUninstallL leaved with err %d", err); |
|
527 } |
|
528 |
|
529 // Wait for a moment |
|
530 User::After(500000); |
|
531 } |
|
532 |
|
533 delete cleanupStack; |
|
534 // __UHEAP_MARKEND; |
|
535 __UHEAP_MARKENDC(1); |
|
536 return KErrNone; |
|
537 } |