|
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: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * T_caapphandlerplugin.cpp |
|
19 * |
|
20 * Created on: 2009-09-16 |
|
21 * Author: |
|
22 */ |
|
23 |
|
24 // CLASS HEADER |
|
25 |
|
26 #include <w32std.h> |
|
27 #include <apgtask.h> |
|
28 #include <apgcli.h> |
|
29 #include <mmf/common/mmfcontrollerpluginresolver.h> |
|
30 #include <usif/scr/scr.h> |
|
31 #include <usif/sif/sifcommon.h> |
|
32 #include <usif/scr/screntries.h> |
|
33 #include <qservicemanager.h> |
|
34 #include <QProcess> |
|
35 #include <qservicemanager.h> |
|
36 |
|
37 #include <cadefs.h> |
|
38 |
|
39 #include "T_caapphandlerplugin.h" |
|
40 #include "waitactive.h" |
|
41 #include "catasklist.h" |
|
42 #include "caapphandler.h" |
|
43 #include "caapphandlerplugin.h" |
|
44 #include "caentry.h" |
|
45 #include "caclient_defines.h" |
|
46 #include "t_cainstaller.h" |
|
47 |
|
48 template <typename RClass> |
|
49 struct RClassDeleter |
|
50 { |
|
51 static inline void cleanup(RClass *ptr) |
|
52 { |
|
53 ptr->Close(); |
|
54 } |
|
55 }; |
|
56 |
|
57 |
|
58 typedef RClassDeleter< RBuf > RBufDeleter; |
|
59 typedef QScopedPointer< RBuf, RBufDeleter > |
|
60 RBufPointer; |
|
61 |
|
62 |
|
63 QTM_USE_NAMESPACE |
|
64 |
|
65 static const char caTypeApp[] = "application"; |
|
66 static const char caTypePackage[] = "package"; |
|
67 static const char caTypeWidget[] = "widget"; |
|
68 static const char caAttrView[] = "view"; |
|
69 static const char caCmdClose[] = "close"; |
|
70 static const char caAttrWindowGroupId[] = "window_group_id"; |
|
71 static const char caAttrComponentId[] = "component_id"; |
|
72 static const char caUidAttribute[] = "application:uid"; |
|
73 |
|
74 T_CaHandler::T_CaHandler(): |
|
75 iAppHandler(NULL) |
|
76 { |
|
77 } |
|
78 |
|
79 void T_CaHandler::cleanup() |
|
80 { |
|
81 delete iAppHandler; |
|
82 iAppHandler = NULL; |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 void T_CaHandler::initTestCase() |
|
89 { |
|
90 QStringList pluginPaths; |
|
91 QString xmlName("caapphandlerplugin.xml"); |
|
92 |
|
93 pluginPaths.append("c:/resource/qt/plugins/commandhandler"); |
|
94 pluginPaths.append("z:/resource/qt/plugins/commandhandler"); |
|
95 |
|
96 QServiceManager serviceManager; |
|
97 foreach (QString path, pluginPaths) { |
|
98 QApplication::addLibraryPath(path); |
|
99 QDir dir(path); |
|
100 if (dir.exists(xmlName)) { |
|
101 serviceManager.addService(dir.absoluteFilePath(xmlName)); |
|
102 } |
|
103 } |
|
104 |
|
105 Usif::RSoftwareInstall sif; |
|
106 CleanupClosePushL( sif ); |
|
107 User::LeaveIfError( sif.Connect() ); |
|
108 |
|
109 // Install the component |
|
110 _LIT16( KHelloJarPath, "c:\\testing\\data\\t_caapphandler\\installs\\hello.jar" ); |
|
111 Usif::COpaqueNamedParams* arguments = NULL; |
|
112 Usif::COpaqueNamedParams* results = NULL; |
|
113 arguments = Usif::COpaqueNamedParams::NewLC(); |
|
114 results = Usif::COpaqueNamedParams::NewLC(); |
|
115 arguments->AddIntL( Usif::KSifInParam_InstallSilently, 1 ); |
|
116 TRequestStatus status; |
|
117 sif.Install( KHelloJarPath, *arguments, *results, status, EFalse ); |
|
118 User::WaitForRequest( status ); |
|
119 User::LeaveIfError( status.Int() ); |
|
120 |
|
121 CleanupStack::PopAndDestroy( results ); |
|
122 CleanupStack::PopAndDestroy( arguments ); |
|
123 |
|
124 // Disconnect from the SIF server |
|
125 CleanupStack::PopAndDestroy( &sif ); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 void T_CaHandler::appHandlerConstruction() |
|
133 { |
|
134 iAppHandler = new CaAppHandler(); |
|
135 QVERIFY(iAppHandler); |
|
136 } |
|
137 |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void T_CaHandler::appHandlerMultipleLoad() |
|
144 { |
|
145 RPointerArray<CaAppHandler> handlerArray; |
|
146 |
|
147 bool foundNull(false); |
|
148 TRAPD(err, |
|
149 CleanupResetAndDestroyPushL(handlerArray); |
|
150 for (TInt i(0); i < 10; ++i) { |
|
151 handlerArray.AppendL(new CaAppHandler()); |
|
152 if (handlerArray[i] == 0) { |
|
153 foundNull = true; |
|
154 break; |
|
155 } |
|
156 } |
|
157 CleanupStack::PopAndDestroy(&handlerArray); |
|
158 ); |
|
159 QCOMPARE(err, KErrNone); |
|
160 QVERIFY(!foundNull); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 void T_CaHandler::appHandlerMultipleLoadAndDelete() |
|
168 { |
|
169 CaAppHandler *handlerPtr(NULL); |
|
170 for (TInt i(0); i < 10; ++i) { |
|
171 handlerPtr = new CaAppHandler(); |
|
172 delete handlerPtr; |
|
173 handlerPtr = NULL; |
|
174 } |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void T_CaHandler::appHandlerOpenFails() |
|
182 { |
|
183 appHandlerConstruction(); |
|
184 |
|
185 TInt unsuportedCommandResult(KErrNone); |
|
186 TInt unexistingEntryOpenResult(KErrNone); |
|
187 TInt corruptedEntryOpenResult(KErrNone); |
|
188 TInt unsupportedEntryTypeOpenResult(KErrNone); |
|
189 |
|
190 CaEntry *entry = new CaEntry(); |
|
191 |
|
192 // valid entry type name |
|
193 entry->setEntryTypeName(caTypeApp); |
|
194 |
|
195 unsuportedCommandResult = |
|
196 iAppHandler->execute(*entry, "unsupported_command_name"); |
|
197 // invalid UID |
|
198 entry->setAttribute(APPLICATION_UID_ATTRIBUTE_NAME, "11111"); |
|
199 |
|
200 unexistingEntryOpenResult = iAppHandler->execute(*entry, caCmdOpen); |
|
201 |
|
202 // invalid view ID |
|
203 entry->setAttribute(caAttrView, "not_a_hex_value"); |
|
204 |
|
205 corruptedEntryOpenResult = iAppHandler->execute(*entry, caCmdOpen); |
|
206 |
|
207 // invalid entry type name |
|
208 entry->setEntryTypeName("unsupported_entry_type_name"); |
|
209 |
|
210 unsupportedEntryTypeOpenResult = |
|
211 iAppHandler->execute(*entry, caCmdOpen); |
|
212 |
|
213 delete entry; |
|
214 entry = NULL; |
|
215 QCOMPARE(unsuportedCommandResult, KErrNotSupported); |
|
216 QCOMPARE(unexistingEntryOpenResult, KErrNotFound); |
|
217 QCOMPARE(corruptedEntryOpenResult, KErrGeneral); |
|
218 QCOMPARE(unsupportedEntryTypeOpenResult, KErrNotSupported); |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 // --------------------------------------------------------------------------- |
|
224 // |
|
225 void T_CaHandler::appHandlerRemoveFails() |
|
226 { |
|
227 appHandlerConstruction(); |
|
228 TInt unpermittedRemovalResult(KErrNone); |
|
229 TInt unexistingEntryRemovalResult(KErrNone); |
|
230 |
|
231 CaEntry *entry = new CaEntry(); |
|
232 entry->setEntryTypeName(caTypeApp); |
|
233 |
|
234 // invalid flags (should be removable) |
|
235 entry->setFlags(0); |
|
236 |
|
237 unpermittedRemovalResult = |
|
238 iAppHandler->execute(*entry, caCmdRemove); |
|
239 |
|
240 // set correct flags |
|
241 entry->setFlags(RemovableEntryFlag); |
|
242 |
|
243 // invalid UID |
|
244 entry->setAttribute(APPLICATION_UID_ATTRIBUTE_NAME, "0"); |
|
245 |
|
246 unexistingEntryRemovalResult = |
|
247 iAppHandler->execute(*entry, caCmdRemove); |
|
248 delete entry; |
|
249 entry = NULL; |
|
250 |
|
251 QCOMPARE(unpermittedRemovalResult, KErrAccessDenied); |
|
252 QCOMPARE(unexistingEntryRemovalResult, KErrNotFound); |
|
253 } |
|
254 |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 // --------------------------------------------------------------------------- |
|
258 // |
|
259 void T_CaHandler::appHandlerClose() |
|
260 { |
|
261 TInt errorClose1(KErrNone); |
|
262 TInt errorClose2(KErrNone); |
|
263 TInt errorOpen(KErrNone); |
|
264 bool wasRunning(false); |
|
265 bool closedRunning(false); |
|
266 |
|
267 const TInt KPhonebookUid(0x20022EF9); |
|
268 |
|
269 RWsSession wsSession; |
|
270 TRAPD(err, |
|
271 CleanupClosePushL(wsSession); |
|
272 User::LeaveIfError(wsSession.Connect()); |
|
273 |
|
274 TApaTaskList taskList(wsSession); |
|
275 TApaTask taskBefore = taskList.FindApp(TUid::Uid(KPhonebookUid)); |
|
276 if (taskBefore.Exists()) { |
|
277 taskBefore.EndTask(); |
|
278 } |
|
279 |
|
280 appHandlerConstruction(); |
|
281 |
|
282 CaEntry *entry = new CaEntry(); |
|
283 entry->setEntryTypeName(caTypeApp); |
|
284 entry->setAttribute(APPLICATION_UID_ATTRIBUTE_NAME, |
|
285 QString::number(KPhonebookUid, 10)); |
|
286 |
|
287 errorClose1 = iAppHandler->execute(*entry, caCmdClose); |
|
288 QTest::qWait(10000); |
|
289 errorOpen = iAppHandler->execute(*entry, caCmdOpen); |
|
290 |
|
291 QTest::qWait(10000); |
|
292 TApaTask taskAfter = taskList.FindApp(TUid::Uid(KPhonebookUid)); |
|
293 TInt id = taskAfter.WgId(); |
|
294 QString numBuf; |
|
295 numBuf = QString::number(id); |
|
296 entry->setFlags(entry->flags() | RunningEntryFlag); |
|
297 entry->setAttribute(caAttrWindowGroupId, numBuf); |
|
298 |
|
299 wasRunning = taskAfter.Exists(); |
|
300 |
|
301 errorClose2 = iAppHandler->execute(*entry, caCmdClose); |
|
302 |
|
303 QTest::qWait(10000); |
|
304 closedRunning = !taskList.FindApp(TUid::Uid(KPhonebookUid)).Exists(); |
|
305 delete entry; |
|
306 entry = NULL; |
|
307 CleanupStack::PopAndDestroy(&wsSession); |
|
308 ); |
|
309 QCOMPARE(err, KErrNone); |
|
310 QCOMPARE(errorClose1, KErrGeneral); |
|
311 QCOMPARE(errorOpen, KErrNone); |
|
312 QCOMPARE(errorClose2, KErrNone); |
|
313 QVERIFY(wasRunning); |
|
314 QVERIFY(closedRunning); |
|
315 } |
|
316 |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 // --------------------------------------------------------------------------- |
|
320 // |
|
321 void T_CaHandler::appHandlerRunApplication() |
|
322 { |
|
323 |
|
324 TInt error(KErrNone); |
|
325 bool started(false); |
|
326 // we will run calculator app |
|
327 const TInt KPhonebookUid(0x20022EF9); |
|
328 |
|
329 RWsSession wsSession; |
|
330 |
|
331 TRAPD(err, |
|
332 CleanupClosePushL(wsSession); |
|
333 User::LeaveIfError(wsSession.Connect()); |
|
334 |
|
335 TApaTaskList taskList(wsSession); |
|
336 TApaTask taskBefore = taskList.FindApp(TUid::Uid(KPhonebookUid)); |
|
337 if (taskBefore.Exists()) { |
|
338 taskBefore.EndTask(); |
|
339 } |
|
340 |
|
341 appHandlerConstruction(); |
|
342 |
|
343 CaEntry *entry = new CaEntry(); |
|
344 entry->setEntryTypeName(caTypeApp); |
|
345 entry->setAttribute(APPLICATION_UID_ATTRIBUTE_NAME, |
|
346 QString::number(KPhonebookUid)); |
|
347 |
|
348 error = iAppHandler->execute(*entry, caCmdOpen); |
|
349 |
|
350 QTest::qWait(1000); |
|
351 TApaTask taskAfter = taskList.FindApp(TUid::Uid(KPhonebookUid)); |
|
352 started = taskAfter.Exists(); |
|
353 taskAfter.EndTask(); |
|
354 |
|
355 delete entry; |
|
356 entry = NULL; |
|
357 CleanupStack::PopAndDestroy(&wsSession); |
|
358 ); |
|
359 QCOMPARE(err, KErrNone); |
|
360 QCOMPARE(error, KErrNone); |
|
361 QVERIFY(started); |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------------------------- |
|
365 // |
|
366 // --------------------------------------------------------------------------- |
|
367 // |
|
368 void T_CaHandler::appHandlerRemoveApplication() |
|
369 { |
|
370 bool leaveOnRemove(true); |
|
371 bool removed(false); |
|
372 |
|
373 _LIT(KSapiPackageFileName, |
|
374 "c:\\testing\\data\\t_apphandler\\installs\\sapiapp_S60_3_X_v_1_0_0.sisx"); |
|
375 _LIT(KSapiAppFileName, "c:\\sys\\bin\\sapiapp.exe"); |
|
376 const TUid KSapiAppUid(TUid::Uid(0xe6bc1167)); |
|
377 |
|
378 T_CaInstaller *installer = NULL; |
|
379 installer = T_CaInstaller::NewL(); |
|
380 CleanupStack::PushL(installer); |
|
381 TRAPD(err, installer->InstallL(KSapiPackageFileName)); |
|
382 QCOMPARE(err, KErrNone); |
|
383 QTest::qWait(20000); |
|
384 |
|
385 Usif::TComponentId componentId(0); |
|
386 TRAP(err, componentId = installer->GetComponentIdL(KSapiAppFileName)); |
|
387 QCOMPARE(err, KErrNone); |
|
388 |
|
389 appHandlerConstruction(); |
|
390 |
|
391 CaEntry *entry = new CaEntry(); |
|
392 |
|
393 entry->setEntryTypeName(caTypeApp); |
|
394 entry->setFlags(RemovableEntryFlag); |
|
395 entry->setAttribute(APPLICATION_UID_ATTRIBUTE_NAME, |
|
396 QString::number(KSapiAppUid.iUid)); |
|
397 |
|
398 entry->setAttribute(caAttrComponentId, |
|
399 QString::number(componentId)); |
|
400 |
|
401 TRAP(err, iAppHandler->execute(*entry, caCmdRemove)); |
|
402 QCOMPARE(err, KErrNone); |
|
403 QTest::qWait(20000); |
|
404 delete entry; |
|
405 entry = NULL; |
|
406 |
|
407 // check again if installed, should be gone |
|
408 TRAP(err, componentId = installer->GetComponentIdL(KSapiAppFileName)) |
|
409 QCOMPARE(err, KErrNone); |
|
410 QCOMPARE(componentId, 0); |
|
411 CleanupStack::PopAndDestroy(installer); |
|
412 |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 void T_CaHandler::appHandlerRemoveJavaApplication() |
|
420 { |
|
421 const int javaAppUid = 0x101251BB;// |
|
422 bool removed(false); |
|
423 int error(KErrNone); |
|
424 |
|
425 TRAPD(err, |
|
426 QVERIFY(javaAppInstalled(javaAppUid)); |
|
427 |
|
428 appHandlerConstruction(); |
|
429 |
|
430 CaEntry *entry = new CaEntry(); |
|
431 entry->setEntryTypeName(caTypeApp); |
|
432 entry->setFlags(RemovableEntryFlag); |
|
433 entry->setAttribute(APPLICATION_UID_ATTRIBUTE_NAME, |
|
434 QString::number(javaAppUid)); |
|
435 |
|
436 Usif::RSoftwareComponentRegistry scr; |
|
437 CleanupClosePushL(scr); |
|
438 User::LeaveIfError(scr.Connect()); |
|
439 TUid uid; |
|
440 Usif::TComponentId componentId = |
|
441 scr.GetComponentIdForAppL( uid.Uid( javaAppUid ) ); |
|
442 |
|
443 if (componentId > 0) { |
|
444 entry->setAttribute(caAttrComponentId, QString::number(componentId)); |
|
445 } |
|
446 |
|
447 CleanupStack::PopAndDestroy(&scr); |
|
448 |
|
449 error = iAppHandler->execute(*entry, caCmdRemove); |
|
450 QTest::qWait(20000); |
|
451 delete entry; |
|
452 entry = NULL; |
|
453 ) |
|
454 QVERIFY(!javaAppInstalled(javaAppUid)); |
|
455 QCOMPARE(err, KErrNone); |
|
456 QCOMPARE(error, KErrNone); |
|
457 } |
|
458 |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 // --------------------------------------------------------------------------- |
|
462 // |
|
463 TBool T_CaHandler::javaAppInstalled(TInt32 aUid) |
|
464 { |
|
465 TBool result = EFalse; |
|
466 Usif::RSoftwareComponentRegistry scr; |
|
467 CleanupClosePushL(scr); |
|
468 scr.Connect(); |
|
469 TUid uid; |
|
470 TInt err; |
|
471 Usif::TComponentId componentId( 0 ); |
|
472 TRAP(err, componentId = |
|
473 scr.GetComponentIdForAppL( |
|
474 uid.Uid( aUid ) ) ) |
|
475 if (componentId > 0 && err == KErrNone) |
|
476 { |
|
477 result = ETrue; |
|
478 } |
|
479 CleanupStack::PopAndDestroy(&scr); |
|
480 return result; |
|
481 } |
|
482 |
|
483 |
|
484 // --------------------------------------------------------------------------- |
|
485 // |
|
486 // --------------------------------------------------------------------------- |
|
487 // |
|
488 void T_CaHandler::testCCaTaskList() |
|
489 { |
|
490 RWsSession wsSession; |
|
491 User::LeaveIfError( wsSession.Connect() ); |
|
492 CleanupClosePushL<RWsSession>( wsSession ); |
|
493 |
|
494 CCaTaskList* taskList = CCaTaskList::NewL( wsSession ); |
|
495 taskList->UpdateListL(); |
|
496 QVERIFY(taskList->IsRootWindowGroup(-1) == EFalse); |
|
497 delete taskList; |
|
498 CleanupStack::PopAndDestroy( &wsSession ); |
|
499 } |
|
500 |
|
501 // --------------------------------------------------------------------------- |
|
502 // |
|
503 // --------------------------------------------------------------------------- |
|
504 // |
|
505 void T_CaHandler::appHandlerCreateInstance() |
|
506 { |
|
507 QServiceManager serviceManager; |
|
508 CaAppHandlerPlugin plugin; |
|
509 QServiceFilter serviceFilter("com.nokia.homescreen.ICommandHandler"); |
|
510 serviceFilter.setCustomAttribute("entryTypeName", "application"); |
|
511 QList<QServiceInterfaceDescriptor> serviceInterfaceDescriptorList = |
|
512 serviceManager.findInterfaces(serviceFilter); |
|
513 int len = serviceInterfaceDescriptorList.size(); |
|
514 QVERIFY(len>0); |
|
515 QServiceInterfaceDescriptor serviceInterfaceDescriptor = |
|
516 serviceInterfaceDescriptorList[0]; |
|
517 QObject *handler = plugin.createInstance( |
|
518 serviceInterfaceDescriptor, NULL, NULL); |
|
519 QVERIFY(handler); |
|
520 delete handler; |
|
521 } |
|
522 |
|
523 QTEST_MAIN(T_CaHandler) |