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: HtiAppControl implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <apacmdln.h> |
|
21 #include <apgtask.h> |
|
22 #include <apgwgnam.h> |
|
23 #include <apmstd.h> |
|
24 |
|
25 #include <badesca.h> |
|
26 #include <f32file.h> |
|
27 |
|
28 #include "HtiAppControl.h" |
|
29 #include <HtiDispatcherInterface.h> |
|
30 #include <HtiLogging.h> |
|
31 |
|
32 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
33 #include <SWInstApi.h> |
|
34 #include <swi/sisregistrysession.h> |
|
35 #include <swi/sisregistrypackage.h> |
|
36 #include <widgetregistryclient.h> |
|
37 #else |
|
38 #include <usif/sif/sif.h> |
|
39 #include <usif/scr/scr.h> //RSoftwareComponentRegistry |
|
40 #endif |
|
41 #include <javaregistryincludes.h> |
|
42 |
|
43 using namespace Java; |
|
44 #if ( SYMBIAN_VERSION_SUPPORT >= SYMBIAN_4 ) |
|
45 _LIT8( KSisxMimeType, "x-epoc/x-sisx-app" ); |
|
46 _LIT8( KSisMimeType, "application/vnd.symbian.install" ); |
|
47 _LIT8( KPipMimeType, "application/x-pip" ); |
|
48 _LIT8( KJadMIMEType, "text/vnd.sun.j2me.app-descriptor" ); |
|
49 _LIT8( KJarMIMEType, "application/java-archive" ); |
|
50 _LIT8( KJavaMIMEType, "application/java"); |
|
51 _LIT8( KJarxMIMEType, "application/x-java-archive"); |
|
52 _LIT8( KWidgetMime, "application/x-nokia-widget"); |
|
53 #endif |
|
54 |
|
55 // CONSTANTS |
|
56 const static TUid KAppServiceUid = { 0x1020DEC7 }; //This is Uid of AppServiceOS |
|
57 |
|
58 //error descriptions |
|
59 _LIT8( KErrDescrNoMemory, "No memory" ); |
|
60 _LIT8( KErrDescrInvalidCmd, "Invalid command" ); |
|
61 _LIT8( KErrDescrInvalidArguments, "Invalid arguments" ); |
|
62 _LIT8( KErrDescrFailedCreateProcess, "Failed create process" ); |
|
63 _LIT8( KErrDescrNotSupported, "Command not supported" ); |
|
64 |
|
65 _LIT8( KErrDescrFailedStartApp, "Failed start app" ); |
|
66 _LIT8( KErrDescrInvalidUid, "Invalid application uid" ); |
|
67 _LIT8( KErrDescrFailedFindApp, "Failed find app" ); |
|
68 |
|
69 _LIT8( KErrDescrFailedConnectSilentInstaller, "Failed to connect to silent installer" ); |
|
70 _LIT8( KErrDescrFailedInstall, "Failed to install" ); |
|
71 _LIT8( KErrDescrFailedUnInstall, "Failed to uninstall" ); |
|
72 _LIT8( KErrDescrFailedFindPackage, "Failed to find the package" ); |
|
73 #if ( SYMBIAN_VERSION_SUPPORT >= SYMBIAN_4 ) |
|
74 _LIT8( KErrDescrBadComponentId, "Bad component id"); |
|
75 #endif |
|
76 _LIT8( KErrDescrFailedListInstApps, "Failed to list installed apps" ); |
|
77 |
|
78 const static TUint8 KUnicodeMask = 0x01; |
|
79 const static TInt KTerminateReason = 0; |
|
80 const static TInt KTUintLength = sizeof(TUint); |
|
81 const static TInt KCloseTaskDelay = 250000; // microseconds |
|
82 |
|
83 // MACROS |
|
84 |
|
85 // LOCAL CONSTANTS AND MACROS |
|
86 |
|
87 // MODULE DATA STRUCTURES |
|
88 |
|
89 // LOCAL FUNCTION PROTOTYPES |
|
90 |
|
91 // FORWARD DECLARATIONS |
|
92 |
|
93 // ============================ MEMBER FUNCTIONS =============================== |
|
94 CHtiAppControl* CHtiAppControl::NewL() |
|
95 { |
|
96 CHtiAppControl* self = new ( ELeave ) CHtiAppControl; |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL(); |
|
99 CleanupStack::Pop(); |
|
100 return self; |
|
101 } |
|
102 |
|
103 // Constructor |
|
104 CHtiAppControl::CHtiAppControl():iIsAppCmdsSupported( EFalse ) |
|
105 { |
|
106 } |
|
107 |
|
108 EXPORT_C CHtiAppControl* NewHtiAppControl() |
|
109 { |
|
110 return CHtiAppControl::NewL(); |
|
111 } |
|
112 |
|
113 CHtiAppControl::~CHtiAppControl() |
|
114 { |
|
115 HTI_LOG_FUNC_IN( "~CHtiAppControl" ); |
|
116 |
|
117 for ( TInt i = 0; i < iProcessHandleArray.Count(); i++ ) |
|
118 { |
|
119 iProcessHandleArray[i].Close(); |
|
120 } |
|
121 iProcessHandleArray.Close(); |
|
122 |
|
123 iAppServer.Close(); |
|
124 iWs.Close(); |
|
125 |
|
126 if ( iMimeTypes ) |
|
127 { |
|
128 iMimeTypes->Reset(); |
|
129 delete iMimeTypes; |
|
130 } |
|
131 |
|
132 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
133 iAugmentations.ResetAndDestroy(); |
|
134 #endif |
|
135 |
|
136 HTI_LOG_FUNC_OUT( "~CHtiAppControl" ); |
|
137 } |
|
138 |
|
139 // Second phase construction. |
|
140 void CHtiAppControl::ConstructL() |
|
141 { |
|
142 HTI_LOG_FUNC_IN( "CHtiAppControl::ConstructL" ); |
|
143 iMimeTypes = new (ELeave) CDesC8ArrayFlat( 8 ); |
|
144 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
145 iMimeTypes->AppendL( SwiUI::KSisxMimeType() ); |
|
146 iMimeTypes->AppendL( SwiUI::KSisMimeType() ); |
|
147 iMimeTypes->AppendL( SwiUI::KPipMimeType() ); |
|
148 iMimeTypes->AppendL( SwiUI::KJadMIMEType() ); |
|
149 iMimeTypes->AppendL( SwiUI::KJarMIMEType() ); |
|
150 iMimeTypes->AppendL( SwiUI::KJavaMIMEType() ); |
|
151 iMimeTypes->AppendL( SwiUI::KJarxMIMEType() ); |
|
152 #else |
|
153 iMimeTypes->AppendL( KSisxMimeType() ); |
|
154 iMimeTypes->AppendL( KSisMimeType() ); |
|
155 iMimeTypes->AppendL( KPipMimeType() ); |
|
156 iMimeTypes->AppendL( KJadMIMEType() ); |
|
157 iMimeTypes->AppendL( KJarMIMEType() ); |
|
158 iMimeTypes->AppendL( KJavaMIMEType() ); |
|
159 iMimeTypes->AppendL( KJarxMIMEType() ); |
|
160 #endif |
|
161 iMimeTypes->AppendL( KWidgetMime() ); // from widgetregistryconstants.h |
|
162 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
163 iAugmentationIndex = 0; |
|
164 #endif |
|
165 |
|
166 TInt err = iAppServer.Connect(); |
|
167 if ( err == KErrNone ) |
|
168 { |
|
169 err = iWs.Connect(); |
|
170 } |
|
171 if ( err == KErrNone ) |
|
172 { |
|
173 iIsAppCmdsSupported = ETrue; |
|
174 } |
|
175 else |
|
176 { |
|
177 iAppServer.Close(); |
|
178 } |
|
179 HTI_LOG_FUNC_OUT( "CHtiAppControl::ConstructL" ); |
|
180 } |
|
181 |
|
182 TInt CHtiAppControl::ParseString( const TDesC8& aRequest, |
|
183 TInt anOffset, |
|
184 TBool aUnicode, |
|
185 TDes& aResult ) |
|
186 { |
|
187 HTI_LOG_FUNC_IN( "CHtiAppControl::ParseString" ); |
|
188 //validate parameters |
|
189 //if offset outside the string return empty string |
|
190 if ( anOffset >= aRequest.Size() ) |
|
191 { |
|
192 return anOffset; |
|
193 } |
|
194 |
|
195 TInt len = aRequest[anOffset]; |
|
196 HTI_LOG_FORMAT( "length %d", len ); |
|
197 |
|
198 if ( len > aResult.MaxLength() ) |
|
199 { |
|
200 return KErrBadDescriptor; |
|
201 } |
|
202 |
|
203 TInt nextOffset = ( aUnicode ? len * 2 : len ) + anOffset + 1; |
|
204 HTI_LOG_FORMAT( "nextOffset %d", nextOffset ); |
|
205 HTI_LOG_FORMAT( "reqSize %d", aRequest.Size() ); |
|
206 if ( nextOffset > aRequest.Size() ) |
|
207 { |
|
208 return KErrArgument; |
|
209 } |
|
210 |
|
211 if ( aUnicode ) |
|
212 { |
|
213 const TPtrC8 aFrom( aRequest.Mid( anOffset + 1, len * 2 ) ); |
|
214 aResult.SetLength( len ); |
|
215 for ( TInt i = 0; i < len; ++i ) |
|
216 { |
|
217 aResult[i] = ( TUint16 ) aFrom[i << 1] + |
|
218 ( ( ( TUint16 ) aFrom[( i << 1 ) + 1] ) << 8 ); |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 aResult.Copy( aRequest.Mid( anOffset + 1, len ) ); |
|
224 } |
|
225 |
|
226 HTI_LOG_FUNC_OUT( "CHtiAppControl::ParseString" ); |
|
227 return nextOffset; |
|
228 } |
|
229 |
|
230 void CHtiAppControl::ProcessMessageL( const TDesC8& aMessage, |
|
231 THtiMessagePriority /*aPriority*/ ) |
|
232 { |
|
233 HTI_LOG_FUNC_IN( "CHtiAppControl::ProcessMessage" ); |
|
234 if ( aMessage.Length() < 1 ) |
|
235 { |
|
236 // no command |
|
237 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
238 return; |
|
239 } |
|
240 |
|
241 if ( aMessage.Length() < 2 && |
|
242 aMessage[0] != EListInstalledApps && |
|
243 aMessage[0] != EListInstalledApps_u) |
|
244 { |
|
245 // parameter is required with all commands except |
|
246 // listing processes or installed applications |
|
247 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
248 return; |
|
249 } |
|
250 |
|
251 HTI_LOG_FORMAT( "cmd %d", aMessage[0] ); |
|
252 |
|
253 if ( aMessage[0] > EProcessLastCommand && |
|
254 aMessage[0] < EAppLastCommand) |
|
255 { |
|
256 if ( iIsAppCmdsSupported ) |
|
257 { |
|
258 HandleAppControlL( aMessage ); |
|
259 } |
|
260 else |
|
261 { |
|
262 SendErrorMsg( KErrNotSupported, KErrDescrNotSupported ); |
|
263 } |
|
264 } |
|
265 else if ( aMessage[0] > EAppLastCommand && |
|
266 aMessage[0] < ESisLastCommand ) |
|
267 { |
|
268 HandleInstallerControlL( aMessage ); |
|
269 } |
|
270 else |
|
271 { |
|
272 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
273 } |
|
274 HTI_LOG_FUNC_OUT( "CHtiAppControl::ProcessMessage" ); |
|
275 } |
|
276 |
|
277 void CHtiAppControl::HandleAppControlL( const TDesC8& aMessage ) |
|
278 { |
|
279 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleAppControl" ); |
|
280 |
|
281 TBool unicode = aMessage[0] & KUnicodeMask; |
|
282 |
|
283 HTI_LOG_FORMAT( "unicode %d", unicode ); |
|
284 |
|
285 TApaAppInfo appInfo; |
|
286 TFileName appName; |
|
287 TFileName docName; |
|
288 |
|
289 switch ( aMessage[0] ) |
|
290 { |
|
291 case EStartApp_uid: |
|
292 case EStartApp_uid_u: |
|
293 { |
|
294 TPtrC8 parameters = aMessage.Mid( 1 ); |
|
295 if ( parameters.Length() >= 4 ) |
|
296 { |
|
297 TInt32 uid = Parse32<TInt32>( parameters ); |
|
298 |
|
299 TInt offset = ParseString( parameters, 4, unicode, docName ); |
|
300 if ( offset >= 0) |
|
301 { |
|
302 if ( FindAppL( appInfo, uid ) ) |
|
303 { |
|
304 HandleStartAppL( appInfo, docName ); |
|
305 } |
|
306 } |
|
307 else |
|
308 { |
|
309 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
310 } |
|
311 } |
|
312 else |
|
313 { |
|
314 SendErrorMsg( KErrArgument , KErrDescrInvalidUid ); |
|
315 } |
|
316 } |
|
317 break; |
|
318 case EStartApp: |
|
319 case EStartApp_u: |
|
320 { |
|
321 TInt offset = ParseString( aMessage, 1, unicode, appName ); |
|
322 if ( offset >= 0 ) |
|
323 { |
|
324 offset = ParseString( aMessage, offset, unicode, docName ); |
|
325 if ( offset >= 0 ) |
|
326 { |
|
327 //find appInfo by app full name |
|
328 if ( FindAppL( appInfo, appName ) ) |
|
329 { |
|
330 HTI_LOG_TEXT( "call HandleStartAppL" ); |
|
331 HandleStartAppL( appInfo, docName ); |
|
332 } |
|
333 } |
|
334 } |
|
335 |
|
336 if ( offset < 0 ) |
|
337 { |
|
338 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
339 } |
|
340 } |
|
341 break; |
|
342 case EStartDoc: |
|
343 case EStartDoc_u: |
|
344 { |
|
345 TInt offset = ParseString( aMessage, 1, unicode, docName ); |
|
346 if ( offset >= 0 ) |
|
347 { |
|
348 HandleStartAppL( appInfo, docName ); //appInfo is empty |
|
349 } |
|
350 else |
|
351 { |
|
352 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
353 } |
|
354 } |
|
355 break; |
|
356 case EStatusApp_uid: |
|
357 { |
|
358 TPtrC8 appUid8 = aMessage.Mid( 1 ); |
|
359 if ( appUid8.Length() == 4 ) |
|
360 { |
|
361 TApaTaskList tl( iWs ); |
|
362 TInt32 appUid = Parse32<TInt32>( appUid8 ); |
|
363 TApaTask task = tl.FindApp( TUid::Uid( appUid ) ); |
|
364 if ( task.Exists() ) |
|
365 { |
|
366 SendMessageL( ERunning ); |
|
367 } |
|
368 else |
|
369 { |
|
370 SendMessageL( ENotFound ); |
|
371 } |
|
372 } |
|
373 else |
|
374 { |
|
375 SendErrorMsg( KErrArgument, KErrDescrInvalidUid ); |
|
376 } |
|
377 } |
|
378 break; |
|
379 case EStatusApp: |
|
380 case EStatusApp_u: |
|
381 { |
|
382 TInt offset = ParseString( aMessage, 1, unicode, appName ); |
|
383 if ( offset >= 0 ) |
|
384 { |
|
385 TApaTaskList tl( iWs ); |
|
386 TApaTask task = tl.FindApp( appName ); |
|
387 if ( task.Exists() ) |
|
388 { |
|
389 SendMessageL( ERunning ); |
|
390 break; // we are done |
|
391 } |
|
392 |
|
393 // Maybe the user gave path or filename instead of caption |
|
394 if ( FindAppL( appInfo, appName ) ) |
|
395 { |
|
396 TApaTask task2 = tl.FindApp( appInfo.iUid ); |
|
397 if ( task2.Exists() ) |
|
398 { |
|
399 SendMessageL( ERunning ); |
|
400 } |
|
401 else |
|
402 { |
|
403 SendMessageL( ENotFound ); |
|
404 } |
|
405 } |
|
406 // If app was not found by FindAppL method, a response message |
|
407 // has already been sent there - no need to send anything here. |
|
408 } |
|
409 else |
|
410 { |
|
411 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
412 } |
|
413 } |
|
414 break; |
|
415 case EStatusDoc: |
|
416 case EStatusDoc_u: |
|
417 { |
|
418 TInt offset = ParseString( aMessage, 1, unicode, docName ); |
|
419 if ( offset >= 0 ) |
|
420 { |
|
421 TApaTaskList tl( iWs ); |
|
422 TApaTask task = tl.FindDoc( docName ); |
|
423 if ( task.Exists() ) |
|
424 { |
|
425 SendMessageL( ERunning ); |
|
426 } |
|
427 else |
|
428 { |
|
429 SendMessageL( ENotFound ); |
|
430 } |
|
431 } |
|
432 else |
|
433 { |
|
434 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
435 } |
|
436 } |
|
437 break; |
|
438 case EStopApp: |
|
439 case EStopApp_u: |
|
440 { |
|
441 TInt offset = ParseString( aMessage, 1, unicode, appName ); |
|
442 if ( offset >= 0 ) |
|
443 { |
|
444 TApaTaskList tl( iWs ); |
|
445 TApaTask task = tl.FindApp( appName ); |
|
446 if ( task.Exists() ) |
|
447 { |
|
448 task.EndTask(); |
|
449 User::After( KCloseTaskDelay ); |
|
450 TApaTask task = tl.FindApp( appName ); |
|
451 if ( task.Exists() ) |
|
452 { |
|
453 task.KillTask(); |
|
454 } |
|
455 SendMessageL( EOk ); |
|
456 break; // we are done |
|
457 } |
|
458 |
|
459 // Maybe the user gave path or filename instead of caption |
|
460 if ( FindAppL( appInfo, appName ) ) |
|
461 { |
|
462 TApaTask task2 = tl.FindApp( appInfo.iUid ); |
|
463 if ( task2.Exists() ) |
|
464 { |
|
465 task2.EndTask(); |
|
466 User::After( KCloseTaskDelay ); |
|
467 TApaTask task2 = tl.FindApp( appInfo.iUid ); |
|
468 if ( task2.Exists() ) |
|
469 { |
|
470 task2.KillTask(); |
|
471 } |
|
472 SendMessageL( EOk ); |
|
473 } |
|
474 else |
|
475 { |
|
476 SendMessageL( ENotFound ); |
|
477 } |
|
478 } |
|
479 // If app was not found by FindAppL method, a response message |
|
480 // has already been sent there - no need to send anything here. |
|
481 } |
|
482 else |
|
483 { |
|
484 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
485 } |
|
486 } |
|
487 break; |
|
488 case EStopDoc: |
|
489 case EStopDoc_u: |
|
490 { |
|
491 TInt offset = ParseString( aMessage, 1, unicode, docName ); |
|
492 if ( offset >= 0 ) |
|
493 { |
|
494 TApaTaskList tl( iWs ); |
|
495 TApaTask task = tl.FindDoc( docName ); |
|
496 if ( task.Exists() ) |
|
497 { |
|
498 task.EndTask(); |
|
499 User::After( KCloseTaskDelay ); |
|
500 TApaTask task = tl.FindDoc( docName ); |
|
501 if ( task.Exists() ) |
|
502 { |
|
503 task.KillTask(); |
|
504 } |
|
505 SendMessageL( EOk ); |
|
506 } |
|
507 else |
|
508 { |
|
509 SendMessageL( ENotFound ); |
|
510 } |
|
511 } |
|
512 else |
|
513 { |
|
514 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
515 } |
|
516 } |
|
517 break; |
|
518 case EStopApp_uid: |
|
519 { |
|
520 TPtrC8 appUid8 = aMessage.Mid( 1 ); |
|
521 if ( appUid8.Length() == 4 ) |
|
522 { |
|
523 TApaTaskList tl( iWs ); |
|
524 TInt32 appUid = Parse32<TInt32>( appUid8 ); |
|
525 TApaTask task = tl.FindApp( TUid::Uid( appUid ) ); |
|
526 if ( task.Exists() ) |
|
527 { |
|
528 task.EndTask(); |
|
529 User::After(KCloseTaskDelay); |
|
530 TApaTask task = tl.FindApp( TUid::Uid( appUid ) ); |
|
531 if ( task.Exists() ) |
|
532 { |
|
533 task.KillTask(); |
|
534 } |
|
535 SendMessageL( EOk ); |
|
536 } |
|
537 else |
|
538 { |
|
539 SendMessageL( ENotFound ); |
|
540 } |
|
541 } |
|
542 else |
|
543 { |
|
544 SendErrorMsg( KErrArgument , KErrDescrInvalidUid ); |
|
545 } |
|
546 } |
|
547 break; |
|
548 case EListApps: |
|
549 case EListApps_u: |
|
550 { |
|
551 if ( aMessage.Length() != 3 ) |
|
552 { |
|
553 SendErrorMsg( KErrArgument, KErrDescrInvalidArguments ); |
|
554 } |
|
555 else |
|
556 { |
|
557 HandleListAppsL( aMessage[1], aMessage[2], unicode ); |
|
558 } |
|
559 } |
|
560 break; |
|
561 case EListInstalledApps: |
|
562 case EListInstalledApps_u: |
|
563 { |
|
564 if ( aMessage.Length() != 1 ) |
|
565 { |
|
566 SendErrorMsg( KErrArgument, KErrDescrInvalidArguments ); |
|
567 } |
|
568 else |
|
569 { |
|
570 HandleListInstalledAppsL( unicode ); |
|
571 } |
|
572 } |
|
573 break; |
|
574 default: |
|
575 { |
|
576 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
577 } |
|
578 } |
|
579 |
|
580 HTI_LOG_FUNC_OUT("CHtiAppControl::HandleAppControl"); |
|
581 } |
|
582 |
|
583 void CHtiAppControl::HandleInstallerControlL( const TDesC8& aMessage ) |
|
584 { |
|
585 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleInstallerControlL" ); |
|
586 |
|
587 if ( aMessage.Length() < 2 ) |
|
588 { |
|
589 HTI_LOG_TEXT( "Command parameters missing" ); |
|
590 SendErrorMsg( KErrArgument , KErrDescrInvalidCmd ); |
|
591 return; |
|
592 } |
|
593 |
|
594 TBool unicode = aMessage[0] & KUnicodeMask; |
|
595 HTI_LOG_FORMAT( "Unicode flag: %d", unicode ); |
|
596 |
|
597 TFileName path; |
|
598 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
599 TBuf<SwiUI::KSWInstMaxPasswordLength> login; |
|
600 TBuf<SwiUI::KSWInstMaxPasswordLength> password; |
|
601 #endif |
|
602 |
|
603 switch ( aMessage[0] ) |
|
604 { |
|
605 case EInstall: |
|
606 case EInstall_u: |
|
607 { |
|
608 TPtrC8 parameters = aMessage.Mid( 1 ); |
|
609 if ( ValidateInstallParams( parameters, unicode ) ) |
|
610 { |
|
611 TInt offset = ParseString( parameters, 0, unicode, path ); |
|
612 |
|
613 HTI_LOG_TEXT( "Parsed path to install package:" ); |
|
614 HTI_LOG_DES( path ) |
|
615 |
|
616 if ( offset >= 0) |
|
617 { |
|
618 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
619 iInstOpts = SwiUI::TInstallOptions(); |
|
620 |
|
621 iInstOpts.iUpgrade = ConvertToPolicy( parameters[offset] ); offset++; |
|
622 iInstOpts.iOptionalItems = ConvertToPolicy( parameters[offset] ); offset++; |
|
623 iInstOpts.iOCSP = ConvertToPolicy( parameters[offset] ); offset++; |
|
624 iInstOpts.iIgnoreOCSPWarnings = ConvertToPolicy( parameters[offset] ); offset++; |
|
625 iInstOpts.iUntrusted = ConvertToPolicy( parameters[offset] ); offset++; |
|
626 iInstOpts.iPackageInfo = ConvertToPolicy( parameters[offset] ); offset++; |
|
627 iInstOpts.iCapabilities = ConvertToPolicy( parameters[offset] ); offset++; |
|
628 iInstOpts.iKillApp = ConvertToPolicy( parameters[offset] ); offset++; |
|
629 iInstOpts.iOverwrite = ConvertToPolicy( parameters[offset] ); offset++; |
|
630 iInstOpts.iDownload = ConvertToPolicy( parameters[offset] ); offset++; |
|
631 |
|
632 HTI_LOG_FORMAT( "iUpgrade: %d", iInstOpts.iUpgrade ); |
|
633 HTI_LOG_FORMAT( "iOptionalItems: %d", iInstOpts.iOptionalItems ); |
|
634 HTI_LOG_FORMAT( "iOCSP: %d", iInstOpts.iOCSP ); |
|
635 HTI_LOG_FORMAT( "iIgnoreOCSPWarnings: %d", iInstOpts.iIgnoreOCSPWarnings ); |
|
636 HTI_LOG_FORMAT( "iUntrusted: %d", iInstOpts.iUntrusted ); |
|
637 HTI_LOG_FORMAT( "iPackageInfo: %d", iInstOpts.iPackageInfo ); |
|
638 HTI_LOG_FORMAT( "iCapabilities: %d", iInstOpts.iCapabilities ); |
|
639 HTI_LOG_FORMAT( "iKillApp: %d", iInstOpts.iKillApp ); |
|
640 HTI_LOG_FORMAT( "iOverwrite: %d", iInstOpts.iOverwrite ); |
|
641 HTI_LOG_FORMAT( "iDownload: %d", iInstOpts.iDownload ); |
|
642 |
|
643 offset = ParseString( parameters, offset, unicode, login ); |
|
644 iInstOpts.iLogin.Copy( login ); |
|
645 HTI_LOG_TEXT( "Parsed login:" ); |
|
646 HTI_LOG_DES( login ) |
|
647 |
|
648 offset = ParseString( parameters, offset, unicode, password ); |
|
649 iInstOpts.iPassword.Copy( password ); |
|
650 HTI_LOG_TEXT( "Parsed password:" ); |
|
651 HTI_LOG_DES( password ) |
|
652 |
|
653 iInstOpts.iDrive = (TChar) parameters[offset]; offset++; |
|
654 iInstOpts.iLang = (TLanguage) parameters[offset]; offset++; |
|
655 iInstOpts.iUsePhoneLang = (TBool) parameters[offset]; offset++; |
|
656 iInstOpts.iUpgradeData = ConvertToPolicy( parameters[offset] ); |
|
657 offset++; |
|
658 HTI_LOG_FORMAT( "parameters length: %d", parameters.Length()); |
|
659 HTI_LOG_FORMAT( "next offset: %d", offset); |
|
660 |
|
661 if(parameters.Length() > offset) |
|
662 { |
|
663 TInt language = iInstOpts.iLang; |
|
664 if (parameters.Length() == offset+2) |
|
665 { |
|
666 language = parameters[offset] + (parameters[offset+1]<<8); |
|
667 } |
|
668 if (parameters.Length() == offset+1) |
|
669 { |
|
670 language = parameters[offset]; |
|
671 } |
|
672 if ((language > ELangTest) && (language < ELangMaximum)) |
|
673 { |
|
674 iInstOpts.iLang = (TLanguage) language; |
|
675 } |
|
676 } |
|
677 HTI_LOG_FORMAT( "iDrive: %c", iInstOpts.iDrive.GetLowerCase() ); |
|
678 HTI_LOG_FORMAT( "iLang: %d", iInstOpts.iLang ); |
|
679 HTI_LOG_FORMAT( "iUsePhoneLang: %d", iInstOpts.iUsePhoneLang ); |
|
680 HTI_LOG_FORMAT( "iUpgradeData: %d", iInstOpts.iUpgradeData ); |
|
681 |
|
682 iInstOptsPckg = iInstOpts; |
|
683 |
|
684 // Connect to silent installer |
|
685 SwiUI::RSWInstSilentLauncher launcher; |
|
686 TInt err = launcher.Connect(); |
|
687 if ( err ) |
|
688 { |
|
689 HTI_LOG_FORMAT( "Error connecting to silent installer, err: %d", err ); |
|
690 SendErrorMsg( err , KErrDescrFailedConnectSilentInstaller ); |
|
691 break; |
|
692 } |
|
693 |
|
694 err = launcher.SilentInstall( path, iInstOptsPckg ); |
|
695 if ( err ) |
|
696 { |
|
697 HTI_LOG_FORMAT( "Error installing software, err: %d", err ); |
|
698 launcher.Close(); |
|
699 SendErrorMsg( err , KErrDescrFailedInstall ); |
|
700 break; |
|
701 } |
|
702 |
|
703 launcher.Close(); |
|
704 SendMessageL( EOk ); |
|
705 #else |
|
706 HTI_LOG_TEXT( "============RSoftwareInstall::Install=============" ); |
|
707 Usif::RSoftwareInstall installer; |
|
708 TInt err = installer.Connect(); |
|
709 if(err) |
|
710 { |
|
711 SendErrorMsg( err , KErrDescrFailedConnectSilentInstaller ); |
|
712 HTI_LOG_FORMAT("cannot connect to SIF server, err %d", err); |
|
713 User::Leave(err); |
|
714 } |
|
715 CleanupClosePushL(installer); |
|
716 TRequestStatus status; |
|
717 Usif::COpaqueNamedParams *arguments = Usif::COpaqueNamedParams::NewL(); |
|
718 CleanupStack::PushL(arguments); |
|
719 Usif::COpaqueNamedParams *results = Usif::COpaqueNamedParams::NewL(); |
|
720 CleanupStack::PushL(results); |
|
721 |
|
722 arguments->AddIntL(Usif::KSifInParam_InstallSilently, ETrue); |
|
723 |
|
724 TInt intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
725 if(intValue != Usif::EAllowed) |
|
726 arguments->AddIntL(Usif::KSifInParam_AllowUpgrade, intValue); |
|
727 HTI_LOG_FORMAT( "iUpgrade: %d", intValue ); |
|
728 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
729 if(intValue != Usif::EAllowed) |
|
730 arguments->AddIntL(Usif::KSifInParam_InstallOptionalItems, intValue); |
|
731 HTI_LOG_FORMAT( "iOptionalItems: %d", intValue ); |
|
732 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
733 if(intValue != Usif::EAllowed) |
|
734 arguments->AddIntL(Usif::KSifInParam_PerformOCSP, intValue); |
|
735 HTI_LOG_FORMAT( "iOCSP: %d", intValue ); |
|
736 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
737 if(intValue != Usif::EAllowed) |
|
738 arguments->AddIntL(Usif::KSifInParam_IgnoreOCSPWarnings, intValue); |
|
739 HTI_LOG_FORMAT( "iIgnoreOCSPWarnings: %d", intValue ); |
|
740 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
741 if(intValue != Usif::ENotAllowed) |
|
742 arguments->AddIntL(Usif::KSifInParam_AllowUntrusted, intValue); |
|
743 HTI_LOG_FORMAT( "iUntrusted: %d", intValue ); |
|
744 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
745 if(intValue != Usif::EAllowed) |
|
746 arguments->AddIntL(Usif::KSifInParam_PackageInfo, intValue); |
|
747 HTI_LOG_FORMAT( "iPackageInfo: %d", intValue ); |
|
748 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
749 if(intValue != Usif::EAllowed) |
|
750 arguments->AddIntL(Usif::KSifInParam_GrantCapabilities,intValue); |
|
751 HTI_LOG_FORMAT( "iCapabilities: %d", intValue ); |
|
752 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
753 if(intValue != Usif::EAllowed) |
|
754 arguments->AddIntL(Usif::KSifInParam_AllowAppShutdown,intValue); |
|
755 HTI_LOG_FORMAT( "iKillApp: %d", intValue ); |
|
756 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
757 if(intValue != Usif::EAllowed) |
|
758 arguments->AddIntL(Usif::KSifInParam_AllowOverwrite,intValue); |
|
759 HTI_LOG_FORMAT( "iOverwrite: %d", intValue ); |
|
760 intValue = ConvertToSifPolicy(parameters[offset]); offset++; |
|
761 if(intValue != Usif::EAllowed) |
|
762 arguments->AddIntL(Usif::KSifInParam_AllowDownload, intValue); |
|
763 HTI_LOG_FORMAT( "iDownload: %d", intValue ); |
|
764 |
|
765 TBuf<32> login; |
|
766 offset = ParseString( parameters, offset, unicode, login ); |
|
767 HTI_LOG_FORMAT( "login length: %d", login.Length() ); |
|
768 if(login != KNullDesC) |
|
769 { |
|
770 arguments->AddStringL(Usif::KSifInParam_UserName, login); |
|
771 } |
|
772 HTI_LOG_TEXT( "Parsed login:" ); |
|
773 HTI_LOG_DES( login ) |
|
774 |
|
775 TBuf<32> password; |
|
776 offset = ParseString( parameters, offset, unicode, password ); |
|
777 HTI_LOG_FORMAT( "password length: %d", password.Length() ); |
|
778 if(password != KNullDesC) |
|
779 { |
|
780 arguments->AddStringL(Usif::KSifInParam_Password, password ); |
|
781 } |
|
782 HTI_LOG_TEXT( "Parsed password:" ); |
|
783 HTI_LOG_DES( password ) |
|
784 |
|
785 TChar driver = (TChar) parameters[offset]; offset++; |
|
786 if(driver >= 'A' && driver <= 'Z') |
|
787 { |
|
788 intValue = driver - (TChar)'A'; |
|
789 arguments->AddIntL(Usif::KSifInParam_Drive, intValue); |
|
790 HTI_LOG_FORMAT( "iDrive: %c", intValue + 'a' ); |
|
791 } |
|
792 else if(driver >= 'a' && driver <= 'z') |
|
793 { |
|
794 intValue = driver - (TChar)'a'; |
|
795 arguments->AddIntL(Usif::KSifInParam_Drive, intValue); |
|
796 HTI_LOG_FORMAT( "iDrive: %c", intValue + 'a' ); |
|
797 } |
|
798 |
|
799 TLanguage oldFormatLanuage = (TLanguage)parameters[offset]; offset++; |
|
800 |
|
801 TBool usePhoneLang = (TBool)parameters[offset]; offset++; |
|
802 HTI_LOG_FORMAT( "iUsePhoneLang: %d", usePhoneLang ); |
|
803 |
|
804 intValue = ConvertToSifPolicy( parameters[offset] );offset++; |
|
805 /*if(intValue != Usif::EAllowed) |
|
806 arguments->AddIntL(Usif::KSifInParam_AllowUpgrade, intValue);*/ |
|
807 HTI_LOG_FORMAT( "iUpgradeData: %d", intValue ); |
|
808 |
|
809 HTI_LOG_FORMAT( "parameters length: %d", parameters.Length()); |
|
810 HTI_LOG_FORMAT( "next offset: %d", offset); |
|
811 |
|
812 if(usePhoneLang == EFalse) |
|
813 { |
|
814 if(parameters.Length() > offset) |
|
815 { |
|
816 TLanguage language = ELangTest; |
|
817 if (parameters.Length() == offset+2) |
|
818 { |
|
819 language = (TLanguage)(parameters[offset] + (parameters[offset+1]<<8)); |
|
820 } |
|
821 else if (parameters.Length() == offset+1) |
|
822 { |
|
823 language = (TLanguage)(parameters[offset]); |
|
824 } |
|
825 if ((language > ELangTest) && (language < ELangMaximum)) |
|
826 { |
|
827 arguments->AddIntL(Usif::KSifInParam_Languages, language); |
|
828 HTI_LOG_FORMAT( "iLang: %d", language ); |
|
829 } |
|
830 } |
|
831 else |
|
832 { |
|
833 arguments->AddIntL(Usif::KSifInParam_Languages, oldFormatLanuage); |
|
834 HTI_LOG_FORMAT( "iLang0: %d", oldFormatLanuage ); |
|
835 } |
|
836 } |
|
837 |
|
838 installer.Install(path, *arguments, *results, status); |
|
839 User::WaitForRequest(status); |
|
840 HTI_LOG_FORMAT("install status: %d", status.Int()); |
|
841 TInt componentId = 0; |
|
842 TBool idExisted = results->GetIntByNameL(Usif::KSifOutParam_ComponentId, componentId); |
|
843 if ( idExisted ) |
|
844 { |
|
845 HTI_LOG_FORMAT( "componentId:%d", componentId); |
|
846 } |
|
847 CleanupStack::PopAndDestroy(3); |
|
848 if (status != KErrNone) |
|
849 { |
|
850 SendErrorMsg( status.Int(), KErrDescrFailedInstall ); |
|
851 break; |
|
852 } |
|
853 SendMessageL( EOk ); |
|
854 #endif |
|
855 } |
|
856 else |
|
857 { |
|
858 HTI_LOG_TEXT( "Error parsing path" ); |
|
859 SendErrorMsg( offset , KErrDescrInvalidArguments ); |
|
860 } |
|
861 } |
|
862 else |
|
863 { |
|
864 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
865 } |
|
866 } |
|
867 break; |
|
868 |
|
869 case EUnInstall: |
|
870 case EUnInstallName: |
|
871 case EUnInstallName_u: |
|
872 { |
|
873 TPtrC8 parameters = aMessage.Mid( 1 ); |
|
874 if ( ( aMessage[0] == EUnInstall && parameters.Length() != 7 ) || |
|
875 ( aMessage[0] == EUnInstallName && |
|
876 parameters.Length() != parameters[0] + 4 ) || |
|
877 ( aMessage[0] == EUnInstallName_u && |
|
878 parameters.Length() != parameters[0] * 2 + 4 ) ) |
|
879 { |
|
880 HTI_LOG_FORMAT( "Invalid command length: %d", |
|
881 parameters.Length() ); |
|
882 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
883 break; |
|
884 } |
|
885 |
|
886 TInt offset = 0; |
|
887 TInt32 uid = KErrNotFound; |
|
888 HBufC* packageName = NULL; |
|
889 #if ( SYMBIAN_VERSION_SUPPORT >= SYMBIAN_4 ) |
|
890 Usif::TComponentId cid = KErrNotFound; |
|
891 HTI_LOG_TEXT( "============RSoftwareInstall::Uninstall=============" ); |
|
892 Usif::RSoftwareInstall installer; |
|
893 TInt err = installer.Connect(); |
|
894 if(err) |
|
895 { |
|
896 SendErrorMsg( err , KErrDescrFailedConnectSilentInstaller ); |
|
897 HTI_LOG_FORMAT("cannot connect to SIF server, err %d", err); |
|
898 User::Leave(err); |
|
899 } |
|
900 CleanupClosePushL(installer); |
|
901 TRequestStatus status; |
|
902 Usif::COpaqueNamedParams *arguments = Usif::COpaqueNamedParams::NewL(); |
|
903 CleanupStack::PushL(arguments); |
|
904 Usif::COpaqueNamedParams *results = Usif::COpaqueNamedParams::NewL(); |
|
905 CleanupStack::PushL(results); |
|
906 #endif |
|
907 if ( aMessage[0] == EUnInstall ) |
|
908 { |
|
909 uid = Parse32<TInt32>( parameters ); |
|
910 offset += 4; |
|
911 HTI_LOG_FORMAT( "Uninstall by uid: %d", uid ); |
|
912 #if ( SYMBIAN_VERSION_SUPPORT >= SYMBIAN_4 ) |
|
913 cid = GetComponentIdFromUid(uid); |
|
914 if ( cid == KErrNotFound ) |
|
915 { |
|
916 HTI_LOG_FORMAT( "cid: %d", cid ); |
|
917 SendErrorMsg( KErrNotFound, KErrDescrBadComponentId ); |
|
918 CleanupStack::PopAndDestroy(3); //results, arguments, installer |
|
919 break; |
|
920 } |
|
921 #endif |
|
922 } |
|
923 else |
|
924 { |
|
925 packageName = HBufC::NewLC( parameters[offset] ); |
|
926 TPtr namePtr = packageName->Des(); |
|
927 offset = ParseString( parameters, offset, unicode, namePtr ); |
|
928 HTI_LOG_FORMAT( "Uninstall by name: %S", packageName ); |
|
929 #if ( SYMBIAN_VERSION_SUPPORT >= SYMBIAN_4 ) |
|
930 cid = GetComponentIdFromPackageName(*packageName); |
|
931 CleanupStack::PopAndDestroy(); // packageName |
|
932 if ( cid == KErrNotFound ) |
|
933 { |
|
934 HTI_LOG_FORMAT( "cid: %d", cid ); |
|
935 SendErrorMsg( KErrNotFound, KErrDescrFailedFindPackage ); |
|
936 CleanupStack::PopAndDestroy(3); //results, arguments, installer |
|
937 break; |
|
938 } |
|
939 #endif |
|
940 } |
|
941 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
942 iUnInstOpts = SwiUI::TUninstallOptions(); |
|
943 iUnInstOpts.iKillApp = ConvertToPolicy( parameters[offset] ); |
|
944 offset++; |
|
945 iUnInstOpts.iBreakDependency = ConvertToPolicy( parameters[offset] ); |
|
946 offset++; |
|
947 HTI_LOG_FORMAT( "iKillApp: %d", iUnInstOpts.iKillApp ); |
|
948 HTI_LOG_FORMAT( "iBreakDependency: %d", iUnInstOpts.iBreakDependency ); |
|
949 |
|
950 TInt mimeIndex = parameters[offset]; |
|
951 if ( mimeIndex > iMimeTypes->Count() - 1 ) |
|
952 { |
|
953 HTI_LOG_FORMAT( "Invalid mime type: %d", mimeIndex ); |
|
954 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
955 break; |
|
956 } |
|
957 |
|
958 HTI_LOG_TEXT( "Uninstall mime type:" ); |
|
959 HTI_LOG_DES( (*iMimeTypes)[mimeIndex] ); |
|
960 |
|
961 TInt err = KErrNone; |
|
962 iAugmentationIndex = 0; |
|
963 if ( packageName ) |
|
964 { |
|
965 TRAP( err, uid = GetPackageUidL( *packageName, mimeIndex ) ); |
|
966 CleanupStack::PopAndDestroy(); // packageName |
|
967 iAugmentations.ResetAndDestroy(); |
|
968 if ( err != KErrNone ) |
|
969 { |
|
970 SendErrorMsg( err, KErrDescrFailedFindPackage ); |
|
971 break; |
|
972 } |
|
973 } |
|
974 HTI_LOG_FORMAT( "UID = %d", uid ); |
|
975 |
|
976 iUnInstOptsPckg = iUnInstOpts; |
|
977 |
|
978 // Connect to silent installer |
|
979 SwiUI::RSWInstSilentLauncher launcher; |
|
980 err = launcher.Connect(); |
|
981 if ( err ) |
|
982 { |
|
983 HTI_LOG_FORMAT( "Error connecting to silent installer, err: %d", err ); |
|
984 SendErrorMsg( err , KErrDescrFailedConnectSilentInstaller ); |
|
985 break; |
|
986 } |
|
987 |
|
988 if ( iAugmentationIndex > 0 ) |
|
989 { |
|
990 SwiUI::TOpUninstallIndexParam params; |
|
991 params.iUid = TUid::Uid( uid ); |
|
992 params.iIndex = iAugmentationIndex; |
|
993 SwiUI::TOpUninstallIndexParamPckg paramPckg( params ); |
|
994 SwiUI::TOperation operation( SwiUI::EOperationUninstallIndex ); |
|
995 err = launcher.SilentCustomUninstall( operation, iUnInstOptsPckg, |
|
996 paramPckg, (*iMimeTypes)[mimeIndex] ); |
|
997 } |
|
998 else |
|
999 { |
|
1000 err = launcher.SilentUninstall( TUid::Uid( uid ), iUnInstOptsPckg, |
|
1001 (*iMimeTypes)[mimeIndex] ); |
|
1002 } |
|
1003 |
|
1004 if ( err ) |
|
1005 { |
|
1006 HTI_LOG_FORMAT( "Error uninstalling software, err: %d", err ); |
|
1007 launcher.Close(); |
|
1008 SendErrorMsg( err , KErrDescrFailedUnInstall ); |
|
1009 break; |
|
1010 } |
|
1011 |
|
1012 launcher.Close(); |
|
1013 #else |
|
1014 |
|
1015 TInt intValue = ConvertToSifPolicy( parameters[offset] ); |
|
1016 offset++; |
|
1017 arguments->AddIntL(Usif::KSifInParam_AllowAppShutdown, intValue); |
|
1018 HTI_LOG_FORMAT( "iKillApp: %d", intValue ); |
|
1019 intValue = ConvertToSifPolicy( parameters[offset] ); |
|
1020 offset++; |
|
1021 arguments->AddIntL(Usif::KSifInParam_AllowAppBreakDependency, intValue); |
|
1022 HTI_LOG_FORMAT( "iBreakDependency: %d", intValue ); |
|
1023 |
|
1024 TInt mimeIndex = parameters[offset]; |
|
1025 if ( mimeIndex > iMimeTypes->Count() - 1 ) |
|
1026 { |
|
1027 HTI_LOG_FORMAT( "Invalid mime type: %d", mimeIndex ); |
|
1028 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
1029 break; |
|
1030 } |
|
1031 |
|
1032 HTI_LOG_TEXT( "Uninstall mime type:" ); |
|
1033 HTI_LOG_DES( (*iMimeTypes)[mimeIndex] ); |
|
1034 |
|
1035 HBufC* buf = HBufC::NewLC((*iMimeTypes)[mimeIndex].Length()); |
|
1036 TPtr ptr = buf->Des(); |
|
1037 ptr.Copy((*iMimeTypes)[mimeIndex]); |
|
1038 arguments->AddStringL(Usif::KSifInParam_MimeType, *buf); |
|
1039 CleanupStack::PopAndDestroy(); // buf |
|
1040 |
|
1041 HTI_LOG_FORMAT( "Component ID = %d", cid ); |
|
1042 |
|
1043 arguments->AddIntL(Usif::KSifInParam_InstallSilently, ETrue); |
|
1044 |
|
1045 installer.Uninstall(cid, *arguments, *results, status, EFalse); |
|
1046 User::WaitForRequest(status); |
|
1047 HTI_LOG_FORMAT("uninstall status:%d", status.Int()); |
|
1048 CleanupStack::PopAndDestroy(3); //results, arguments, installer |
|
1049 if (status != KErrNone) |
|
1050 { |
|
1051 SendErrorMsg(status.Int(), KErrDescrFailedUnInstall); |
|
1052 break; |
|
1053 } |
|
1054 #endif |
|
1055 SendMessageL( EOk ); |
|
1056 } |
|
1057 break; |
|
1058 |
|
1059 default: |
|
1060 { |
|
1061 SendErrorMsg( KErrArgument, KErrDescrInvalidCmd ); |
|
1062 } |
|
1063 } |
|
1064 |
|
1065 HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleInstallerControlL" ); |
|
1066 } |
|
1067 |
|
1068 |
|
1069 void CHtiAppControl::HandleStartProcessL( const TDesC& aProgramName, |
|
1070 const TDesC& aCmdLine, |
|
1071 TBool aStoreProcessHandle ) |
|
1072 { |
|
1073 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleStartProcessL" ); |
|
1074 HTI_LOG_FORMAT( "progr name %d", aProgramName.Length() ); |
|
1075 HTI_LOG_DES( aProgramName ); |
|
1076 |
|
1077 RProcess process; |
|
1078 TInt err = process.Create( aProgramName, aCmdLine ); // command parameters |
|
1079 |
|
1080 if ( err == KErrNone ) |
|
1081 { |
|
1082 CleanupClosePushL( process ); |
|
1083 |
|
1084 //convert process id to binary des |
|
1085 TUint processId = process.Id(); |
|
1086 HTI_LOG_FORMAT( "process id %d", processId ); |
|
1087 |
|
1088 TBuf8<KTUintLength> processIdDes; |
|
1089 processIdDes.Append( |
|
1090 ( TUint8* )( &processId ), KTUintLength ); |
|
1091 |
|
1092 SendMessageL( EOk, processIdDes ); |
|
1093 |
|
1094 process.Resume(); |
|
1095 |
|
1096 if ( aStoreProcessHandle ) |
|
1097 { |
|
1098 HTI_LOG_TEXT( "Storing the process handle" ); |
|
1099 iProcessHandleArray.Append( process ); |
|
1100 CleanupStack::Pop(); |
|
1101 } |
|
1102 else |
|
1103 { |
|
1104 CleanupStack::PopAndDestroy(); |
|
1105 } |
|
1106 } |
|
1107 else if ( err == KErrNotFound ) |
|
1108 { |
|
1109 SendMessageL( ENotFound ); |
|
1110 } |
|
1111 else |
|
1112 { |
|
1113 SendErrorMsg( err ,KErrDescrFailedCreateProcess ); |
|
1114 } |
|
1115 |
|
1116 HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleStartProcessL" ); |
|
1117 } |
|
1118 |
|
1119 void CHtiAppControl::HandleStopProcessL( RProcess& aProcess ) |
|
1120 { |
|
1121 if ( aProcess.ExitType() == EExitPending ) |
|
1122 { |
|
1123 aProcess.Kill( KTerminateReason ); |
|
1124 SendMessageL( EOk ); |
|
1125 } |
|
1126 else |
|
1127 { |
|
1128 SendMessageL( EAlreadyStopped ); |
|
1129 } |
|
1130 } |
|
1131 |
|
1132 void CHtiAppControl::HandleStatusProcessL( RProcess& aProcess ) |
|
1133 { |
|
1134 TExitType exT = aProcess.ExitType(); |
|
1135 |
|
1136 switch ( exT ) |
|
1137 { |
|
1138 case EExitPending: |
|
1139 { |
|
1140 SendMessageL( ERunning ); |
|
1141 } |
|
1142 break; |
|
1143 case EExitKill: |
|
1144 case EExitTerminate: |
|
1145 { |
|
1146 SendMessageL( EKilled ); |
|
1147 } |
|
1148 break; |
|
1149 case EExitPanic: |
|
1150 { |
|
1151 SendMessageL( EPanic ); |
|
1152 } |
|
1153 break; |
|
1154 }; |
|
1155 } |
|
1156 |
|
1157 |
|
1158 void CHtiAppControl::HandleListProcessesL( const TDesC& aMatch ) |
|
1159 { |
|
1160 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListProcessesL" ); |
|
1161 |
|
1162 RProcess process; |
|
1163 TFullName processName; |
|
1164 TUint processId; |
|
1165 TBuf8<KTUintLength> processIdDes; |
|
1166 TExitType exitType; |
|
1167 |
|
1168 TBuf8<128> buf; |
|
1169 CBufFlat* processListBuf = NULL; |
|
1170 TRAPD( err, processListBuf = CBufFlat::NewL( 128 ) ); |
|
1171 if ( err ) |
|
1172 { |
|
1173 SendErrorMsg( err ,KErrDescrNoMemory ); |
|
1174 return; |
|
1175 } |
|
1176 |
|
1177 CleanupStack::PushL( processListBuf ); |
|
1178 |
|
1179 // The default match pattern is the single character * |
|
1180 TFindProcess finder; |
|
1181 |
|
1182 // if some real match pattern is defined, use it |
|
1183 if ( aMatch.Length() > 0 ) |
|
1184 { |
|
1185 HTI_LOG_TEXT( "Match pattern was given:" ); |
|
1186 HTI_LOG_DES( aMatch ); |
|
1187 finder.Find( aMatch ); |
|
1188 } |
|
1189 |
|
1190 TInt pos = 0; |
|
1191 TUint numberOfEntries = 0; |
|
1192 |
|
1193 while ( finder.Next( processName ) == KErrNone ) |
|
1194 { |
|
1195 err = process.Open( finder ); |
|
1196 |
|
1197 //convert process id to binary des |
|
1198 processId = process.Id(); |
|
1199 processIdDes.Append( ( TUint8* ) ( &processId ), KTUintLength ); |
|
1200 buf.Append( processIdDes ); |
|
1201 |
|
1202 // status |
|
1203 exitType = process.ExitType(); |
|
1204 switch ( exitType ) |
|
1205 { |
|
1206 case EExitPending: |
|
1207 { |
|
1208 buf.Append( ERunning ); |
|
1209 } |
|
1210 break; |
|
1211 case EExitKill: |
|
1212 case EExitTerminate: |
|
1213 { |
|
1214 buf.Append( EKilled ); |
|
1215 } |
|
1216 break; |
|
1217 case EExitPanic: |
|
1218 { |
|
1219 buf.Append( EPanic ); |
|
1220 } |
|
1221 break; |
|
1222 }; |
|
1223 |
|
1224 // name length |
|
1225 buf.Append( processName.Length() ); |
|
1226 |
|
1227 // name |
|
1228 buf.Append( processName ); |
|
1229 |
|
1230 process.Close(); |
|
1231 |
|
1232 TRAP( err, processListBuf->ExpandL( pos, buf.Length() ) ); |
|
1233 if ( err ) |
|
1234 { |
|
1235 SendErrorMsg( err , KErrDescrNoMemory ); |
|
1236 delete processListBuf; |
|
1237 return; |
|
1238 } |
|
1239 processListBuf->Write( pos, buf, buf.Length() ); |
|
1240 |
|
1241 pos += buf.Length(); |
|
1242 buf.Zero(); |
|
1243 processIdDes.Zero(); |
|
1244 numberOfEntries++; |
|
1245 } |
|
1246 |
|
1247 // insert the number of entries in the beginning |
|
1248 TBuf8<2> entries; |
|
1249 entries.Append( ( TUint8* ) ( &numberOfEntries ), 2 ); |
|
1250 processListBuf->ExpandL( 0, 2 ); |
|
1251 processListBuf->Write( 0, entries, 2 ); |
|
1252 |
|
1253 SendMessageL( EOk, processListBuf->Ptr( 0 ) ); |
|
1254 |
|
1255 CleanupStack::PopAndDestroy( processListBuf ); |
|
1256 |
|
1257 HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleListProcessesL" ); |
|
1258 } |
|
1259 |
|
1260 |
|
1261 void CHtiAppControl::HandleStartAppL( TApaAppInfo &aAppInfo, |
|
1262 const TDesC& aDocName ) |
|
1263 { |
|
1264 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleStartAppL" ); |
|
1265 |
|
1266 // Check if app is running as a root app (not embedded) |
|
1267 TApaTask task = FindRunningRootApp( aAppInfo.iUid ); |
|
1268 if ( task.Exists() ) |
|
1269 { |
|
1270 User::ResetInactivityTime(); |
|
1271 task.BringToForeground(); |
|
1272 SendMessageL( EAlreadyRunning ); |
|
1273 } |
|
1274 else |
|
1275 { |
|
1276 TThreadId threadId; |
|
1277 TInt err = KErrNone; |
|
1278 if ( aAppInfo.iUid != TUid::Null() ) |
|
1279 { |
|
1280 TApaAppCapabilityBuf capBuf; |
|
1281 err = iAppServer.GetAppCapability( capBuf, aAppInfo.iUid ); |
|
1282 TApaAppCapability& caps = capBuf(); |
|
1283 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
1284 cmdLine->SetExecutableNameL( aAppInfo.iFullName ); |
|
1285 if ( caps.iLaunchInBackground ) |
|
1286 { |
|
1287 cmdLine->SetCommandL( EApaCommandBackground ); |
|
1288 HTI_LOG_TEXT( "Launching in background" ); |
|
1289 } |
|
1290 else |
|
1291 { |
|
1292 if ( aDocName != KNullDesC ) |
|
1293 { |
|
1294 cmdLine->SetCommandL( EApaCommandOpen ); |
|
1295 cmdLine->SetDocumentNameL( aDocName ); |
|
1296 HTI_LOG_TEXT( "Launching with document" ); |
|
1297 } |
|
1298 else |
|
1299 { |
|
1300 cmdLine->SetCommandL( EApaCommandRun ); |
|
1301 HTI_LOG_TEXT( "Launching without document" ); |
|
1302 } |
|
1303 } |
|
1304 err = iAppServer.StartApp( *cmdLine, threadId ); |
|
1305 CleanupStack::PopAndDestroy( cmdLine ); |
|
1306 } |
|
1307 else if ( aDocName != KNullDesC ) |
|
1308 { |
|
1309 HTI_LOG_TEXT( "Launching a document" ); |
|
1310 /* |
|
1311 * If the app that should handle the doc is already running, we |
|
1312 * try to switch the open file and bring it to foreground. Whether |
|
1313 * switching the file works depends on the application: It must |
|
1314 * implement CEikAppUi::OpenFileL() or CAknAppUi::OpenFileL() in S60. |
|
1315 */ |
|
1316 TUid appUid; |
|
1317 TDataType dataType; |
|
1318 err = iAppServer.AppForDocument( aDocName, appUid, dataType ); |
|
1319 if ( err == KErrNone ) |
|
1320 { |
|
1321 TApaTask task = FindRunningRootApp( appUid ); |
|
1322 if ( task.Exists() ) |
|
1323 { |
|
1324 HTI_LOG_TEXT( "App for doc already running, switch file" ); |
|
1325 err = task.SwitchOpenFile( aDocName ); |
|
1326 task.BringToForeground(); |
|
1327 } |
|
1328 else |
|
1329 { |
|
1330 err = iAppServer.StartDocument( aDocName, threadId ); |
|
1331 } |
|
1332 } |
|
1333 } |
|
1334 else |
|
1335 { |
|
1336 User::Leave( KErrArgument ); |
|
1337 } |
|
1338 |
|
1339 if ( err == KErrNone ) |
|
1340 { |
|
1341 User::ResetInactivityTime(); |
|
1342 //convert thread id to string |
|
1343 TUint threadIdUint = threadId; //cast to UInt |
|
1344 TBuf8<KTUintLength> threadIdDes; |
|
1345 threadIdDes.Append( ( TUint8* )( &threadIdUint ), KTUintLength ); |
|
1346 SendMessageL( EOk, threadIdDes ); |
|
1347 } |
|
1348 else if ( err == KErrNotFound ) |
|
1349 { |
|
1350 SendMessageL( ENotFound ); |
|
1351 } |
|
1352 else |
|
1353 { |
|
1354 SendErrorMsg( err, KErrDescrFailedStartApp ); |
|
1355 } |
|
1356 } |
|
1357 HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleStartAppL" ); |
|
1358 } |
|
1359 |
|
1360 void CHtiAppControl::HandleListInstalledAppsL( TBool aUnicode ) |
|
1361 { |
|
1362 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListInstalledAppsL" ); |
|
1363 |
|
1364 // max file name + max caption + max short caption + 7 constant bytes |
|
1365 TInt bufSize = KMaxFileName + 2 * KApaMaxAppCaption + 7; |
|
1366 if ( aUnicode ) |
|
1367 { |
|
1368 bufSize *= 2; |
|
1369 } |
|
1370 |
|
1371 CBufFlat* appListBuf = CBufFlat::NewL( bufSize ); |
|
1372 CleanupStack::PushL( appListBuf ); |
|
1373 |
|
1374 HBufC8* appsArray = HBufC8::NewLC( bufSize ); |
|
1375 TPtr8 appsArrayPtr = appsArray->Des(); |
|
1376 |
|
1377 TInt err = KErrNone; |
|
1378 err = iAppServer.GetAllApps(); |
|
1379 if ( err != KErrNone ) |
|
1380 { |
|
1381 SendErrorMsg( err, KErrDescrFailedListInstApps ); |
|
1382 } |
|
1383 else |
|
1384 { |
|
1385 TApaAppInfo appInfo; |
|
1386 TInt pos( 0 ); |
|
1387 |
|
1388 // Add application count |
|
1389 TInt numOfEntries = 0; |
|
1390 iAppServer.AppCount( numOfEntries ); |
|
1391 |
|
1392 appsArrayPtr.Append( ( TUint8*) ( &numOfEntries ), 2 ); |
|
1393 |
|
1394 while ( iAppServer.GetNextApp( appInfo ) == KErrNone ) |
|
1395 { |
|
1396 TUint appUidUint = appInfo.iUid.iUid; |
|
1397 appsArrayPtr.Append( ( TUint8* ) &appUidUint, KTUintLength ); |
|
1398 |
|
1399 // Add length of full name |
|
1400 appsArrayPtr.Append( appInfo.iFullName.Length() ); |
|
1401 // Add full name if there is one |
|
1402 if ( appInfo.iFullName.Length() > 0 ) |
|
1403 { |
|
1404 if ( aUnicode ) |
|
1405 { |
|
1406 appsArrayPtr.Append( ( TUint8* ) appInfo.iFullName.Ptr(), |
|
1407 appInfo.iFullName.Length() * 2 ); |
|
1408 } |
|
1409 else |
|
1410 { |
|
1411 appsArrayPtr.Append( appInfo.iFullName ); |
|
1412 } |
|
1413 } |
|
1414 |
|
1415 // Add length of caption |
|
1416 appsArrayPtr.Append( appInfo.iCaption.Length() ); |
|
1417 // Add caption if there is one |
|
1418 if ( appInfo.iCaption.Length() > 0 ) |
|
1419 { |
|
1420 if ( aUnicode ) |
|
1421 { |
|
1422 appsArrayPtr.Append( ( TUint8* ) appInfo.iCaption.Ptr(), |
|
1423 appInfo.iCaption.Length() * 2 ); |
|
1424 } |
|
1425 else |
|
1426 { |
|
1427 appsArrayPtr.Append( appInfo.iCaption ); |
|
1428 } |
|
1429 } |
|
1430 |
|
1431 // Add length of short caption |
|
1432 appsArrayPtr.Append( appInfo.iShortCaption.Length() ); |
|
1433 // Add short caption if there is one |
|
1434 if ( appInfo.iShortCaption.Length() > 0 ) |
|
1435 { |
|
1436 if ( aUnicode ) |
|
1437 { |
|
1438 appsArrayPtr.Append( ( TUint8* ) appInfo.iShortCaption.Ptr(), |
|
1439 appInfo.iCaption.Length() * 2 ); |
|
1440 } |
|
1441 else |
|
1442 { |
|
1443 appsArrayPtr.Append( appInfo.iShortCaption ); |
|
1444 } |
|
1445 } |
|
1446 |
|
1447 // Add app info to response buffer |
|
1448 appListBuf->ExpandL( pos, appsArray->Length() ); |
|
1449 appListBuf->Write( pos, *appsArray, appsArray->Length() ); |
|
1450 |
|
1451 pos += appsArray->Length(); |
|
1452 appsArrayPtr.Zero(); |
|
1453 } |
|
1454 |
|
1455 SendMessageL( EOk, appListBuf->Ptr( 0 ) ); |
|
1456 } |
|
1457 |
|
1458 CleanupStack::PopAndDestroy( 2 ); //appListBuf, appsArray |
|
1459 |
|
1460 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListInstalledAppsL" ); |
|
1461 } |
|
1462 |
|
1463 void CHtiAppControl::HandleListAppsL( TBool aIncludeHidden, |
|
1464 TBool aIncludeSystem, |
|
1465 TBool aUnicode ) |
|
1466 { |
|
1467 HTI_LOG_FUNC_IN( "CHtiAppControl::HandleListAppsL" ); |
|
1468 |
|
1469 RArray<RWsSession::TWindowGroupChainInfo>* wgChain = new ( ELeave ) |
|
1470 RArray<RWsSession::TWindowGroupChainInfo>( 12 ); |
|
1471 CleanupDeletePushL( wgChain ); |
|
1472 CleanupClosePushL( *wgChain ); |
|
1473 User::LeaveIfError( iWs.WindowGroupList( 0, wgChain ) ); |
|
1474 TInt wgCount = wgChain->Count(); |
|
1475 |
|
1476 HTI_LOG_FORMAT( "%d Window Groups in the chain", wgCount ); |
|
1477 |
|
1478 TInt bufSize = 2 * KMaxFileName + 11; // caption & document + 11 constant bytes |
|
1479 if ( aUnicode ) |
|
1480 { |
|
1481 bufSize *= 2; |
|
1482 } |
|
1483 CBufFlat* appListBuf = CBufFlat::NewL( bufSize ); |
|
1484 CleanupStack::PushL( appListBuf ); |
|
1485 HBufC8* buf = HBufC8::NewLC( bufSize ); |
|
1486 TPtr8 bufPtr = buf->Des(); |
|
1487 |
|
1488 TInt pos = 0; |
|
1489 TInt numOfEntries = 0; |
|
1490 |
|
1491 for ( TInt i = 0; i < wgCount; i++ ) |
|
1492 { |
|
1493 const RWsSession::TWindowGroupChainInfo& info = ( *wgChain )[i]; |
|
1494 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( iWs, info.iId ); |
|
1495 |
|
1496 HTI_LOG_FORMAT( "WG ID: %d", info.iId ); |
|
1497 HTI_LOG_DES( wgName->WindowGroupName() ); |
|
1498 |
|
1499 // Info is returned only from root tasks and system and hidden tasks |
|
1500 // are included only if requested. |
|
1501 if ( info.iParentId <= 0 && |
|
1502 ( !wgName->IsSystem() || aIncludeSystem ) && |
|
1503 ( !wgName->Hidden() || aIncludeHidden ) ) |
|
1504 { |
|
1505 // Add application UID |
|
1506 TUint appUidUint = wgName->AppUid().iUid; |
|
1507 bufPtr.Append( ( TUint8* ) &appUidUint, KTUintLength ); |
|
1508 |
|
1509 // Add caption |
|
1510 TPtrC caption = wgName->Caption(); |
|
1511 bufPtr.Append( caption.Length() ); |
|
1512 if ( caption.Length() > 0 ) |
|
1513 { |
|
1514 if ( aUnicode ) |
|
1515 { |
|
1516 bufPtr.Append( |
|
1517 ( TUint8* ) caption.Ptr(), caption.Length() * 2 ); |
|
1518 } |
|
1519 else |
|
1520 { |
|
1521 bufPtr.Append( caption ); |
|
1522 } |
|
1523 } |
|
1524 |
|
1525 // Add document name |
|
1526 TPtrC document = wgName->DocName(); |
|
1527 bufPtr.Append( document.Length() ); |
|
1528 if ( document.Length() > 0 ) |
|
1529 { |
|
1530 if ( aUnicode ) |
|
1531 { |
|
1532 bufPtr.Append( |
|
1533 ( TUint8* ) document.Ptr(), document.Length() * 2 ); |
|
1534 } |
|
1535 else |
|
1536 { |
|
1537 bufPtr.Append( document ); |
|
1538 } |
|
1539 } |
|
1540 |
|
1541 // Add Hidden flag |
|
1542 if ( wgName->Hidden() ) |
|
1543 bufPtr.Append( 1 ); |
|
1544 else |
|
1545 bufPtr.Append( 0 ); |
|
1546 |
|
1547 // Add System flag |
|
1548 if ( wgName->IsSystem() ) |
|
1549 bufPtr.Append( 1 ); |
|
1550 else |
|
1551 bufPtr.Append( 0 ); |
|
1552 |
|
1553 // Add Ready flag |
|
1554 if ( wgName->IsAppReady() ) |
|
1555 bufPtr.Append( 1 ); |
|
1556 else |
|
1557 bufPtr.Append( 0 ); |
|
1558 |
|
1559 // Add Busy flag |
|
1560 if ( wgName->IsBusy() ) |
|
1561 bufPtr.Append( 1 ); |
|
1562 else |
|
1563 bufPtr.Append( 0 ); |
|
1564 |
|
1565 // Add Shutdown response flag |
|
1566 if ( wgName->RespondsToShutdownEvent() ) |
|
1567 bufPtr.Append( 1 ); |
|
1568 else |
|
1569 bufPtr.Append( 0 ); |
|
1570 |
|
1571 // Add this task's info to response buffer |
|
1572 appListBuf->ExpandL( pos, buf->Length() ); |
|
1573 appListBuf->Write( pos, *buf, buf->Length() ); |
|
1574 |
|
1575 pos += buf->Length(); |
|
1576 bufPtr.Zero(); |
|
1577 numOfEntries++; |
|
1578 } // if |
|
1579 CleanupStack::PopAndDestroy(); // wgName |
|
1580 } // for |
|
1581 |
|
1582 CleanupStack::PopAndDestroy(); // buf |
|
1583 |
|
1584 // Add number of entries to the beginning of the response |
|
1585 TBuf8<2> entries; |
|
1586 entries.Append( ( TUint8* ) ( &numOfEntries ), 2 ); |
|
1587 appListBuf->ExpandL( 0, 2 ); |
|
1588 appListBuf->Write( 0, entries, 2 ); |
|
1589 |
|
1590 SendMessageL( EOk, appListBuf->Ptr( 0 ) ); |
|
1591 |
|
1592 CleanupStack::PopAndDestroy( 3 ); // appListBuf, wgChain Close, wgChain delete |
|
1593 |
|
1594 HTI_LOG_FUNC_OUT( "CHtiAppControl::HandleListAppsL" ); |
|
1595 } |
|
1596 |
|
1597 TBool CHtiAppControl::FindAppL( TApaAppInfo& aAppInfo, |
|
1598 const TDesC& aAppFullName ) |
|
1599 { |
|
1600 HTI_LOG_FUNC_IN( "CHtiAppControl::FindAppL name" ); |
|
1601 TInt err = KErrNone; |
|
1602 err = iAppServer.GetAllApps(); |
|
1603 if ( err != KErrNone ) |
|
1604 { |
|
1605 SendErrorMsg( err, KErrDescrFailedFindApp ); |
|
1606 return EFalse; |
|
1607 } |
|
1608 |
|
1609 TParse toFind; |
|
1610 err = toFind.SetNoWild( aAppFullName, NULL, NULL ); |
|
1611 if ( err != KErrNone ) |
|
1612 { |
|
1613 SendErrorMsg( err, KErrDescrFailedFindApp ); |
|
1614 return EFalse; |
|
1615 } |
|
1616 |
|
1617 TBool isFullName = ( toFind.DrivePresent() && toFind.PathPresent() ); |
|
1618 |
|
1619 while ( ( err = iAppServer.GetNextApp( aAppInfo) ) == KErrNone ) |
|
1620 { |
|
1621 if ( isFullName ) // assume that full path has been given |
|
1622 { |
|
1623 if ( !aAppFullName.CompareF( aAppInfo.iFullName ) ) |
|
1624 { |
|
1625 return ETrue; |
|
1626 } |
|
1627 } |
|
1628 else // assume that only filename has been given |
|
1629 { |
|
1630 TParsePtrC current( aAppInfo.iFullName ); |
|
1631 |
|
1632 // does the given filename contain extension |
|
1633 if ( toFind.ExtPresent() ) |
|
1634 { |
|
1635 // compare with filename + extension |
|
1636 if ( !toFind.NameAndExt().CompareF( current.NameAndExt() ) ) |
|
1637 { |
|
1638 return ETrue; |
|
1639 } |
|
1640 } |
|
1641 else |
|
1642 { |
|
1643 // compare with filename only |
|
1644 if ( !toFind.Name().CompareF( current.Name() ) ) |
|
1645 { |
|
1646 return ETrue; |
|
1647 } |
|
1648 // Try to match the caption. |
|
1649 // For Java MIDlets the full name is like C:\270194328.fakeapp |
|
1650 // so we have to use caption to find MIDlets. |
|
1651 if ( !toFind.Name().CompareF( aAppInfo.iCaption ) ) |
|
1652 { |
|
1653 return ETrue; |
|
1654 } |
|
1655 } |
|
1656 } |
|
1657 } |
|
1658 |
|
1659 if ( err == RApaLsSession::ENoMoreAppsInList ) |
|
1660 { |
|
1661 SendMessageL( ENotFound ); |
|
1662 } |
|
1663 else if ( err != KErrNone ) |
|
1664 { |
|
1665 SendErrorMsg( err,KErrDescrFailedFindApp ); |
|
1666 } |
|
1667 HTI_LOG_FUNC_OUT( "CHtiAppControl::FindAppL name" ); |
|
1668 return EFalse; |
|
1669 } |
|
1670 |
|
1671 TBool CHtiAppControl::FindAppL( TApaAppInfo &aAppInfo, |
|
1672 const TInt32 aUid ) |
|
1673 { |
|
1674 HTI_LOG_FUNC_IN( "CHtiAppControl::FindAppL uid" ); |
|
1675 TInt err = iAppServer.GetAppInfo( aAppInfo, TUid::Uid( aUid ) ); |
|
1676 if ( err == KErrNone ) |
|
1677 { |
|
1678 return ETrue; |
|
1679 } |
|
1680 else if ( err == KErrNotFound ) |
|
1681 { |
|
1682 SendMessageL( ENotFound ); |
|
1683 } |
|
1684 else |
|
1685 { |
|
1686 SendErrorMsg( err , KErrDescrFailedFindApp ); |
|
1687 } |
|
1688 HTI_LOG_FUNC_OUT( "CHtiAppControl::FindAppL uid" ); |
|
1689 return EFalse; |
|
1690 } |
|
1691 |
|
1692 TApaTask CHtiAppControl::FindRunningRootApp( TUid aAppUid ) |
|
1693 { |
|
1694 HTI_LOG_FUNC_IN( "CHtiAppControl::FindRunningRootApp" ); |
|
1695 TApaTask task( iWs ); |
|
1696 task.SetWgId( 0 ); // initialize to empty task |
|
1697 |
|
1698 TInt wgId = 0; // on first call to FindByAppUid wgId must be zero |
|
1699 CApaWindowGroupName::FindByAppUid( aAppUid, iWs, wgId ); |
|
1700 HTI_LOG_FORMAT( "FindByAppUid returned WG ID: %d", wgId ); |
|
1701 |
|
1702 RArray<RWsSession::TWindowGroupChainInfo> wgs; |
|
1703 TInt err = KErrNone; |
|
1704 TInt wgCount = 0; |
|
1705 if ( wgId != KErrNotFound ) |
|
1706 { |
|
1707 // Get a list of Window Group Chain Infos |
|
1708 err = iWs.WindowGroupList( 0, &wgs ); // get only priority 0 WGs |
|
1709 wgCount = wgs.Count(); |
|
1710 HTI_LOG_FORMAT( "WindowGroupList returned %d WGs", wgCount ); |
|
1711 } |
|
1712 while ( wgId != KErrNotFound && task.WgId() == 0 && err == KErrNone ) |
|
1713 { |
|
1714 // App was found - check if it is root by looping through the |
|
1715 // WG chain infos to find the one with out wgId |
|
1716 TInt i = 0; |
|
1717 while ( task.WgId() == 0 && i < wgCount ) |
|
1718 { |
|
1719 const RWsSession::TWindowGroupChainInfo& info = wgs[i]; |
|
1720 if ( info.iId == wgId && info.iParentId <= 0 ) |
|
1721 { |
|
1722 // This is the one and it is root (does not have parent) |
|
1723 task.SetWgId( wgId ); |
|
1724 } |
|
1725 i++; |
|
1726 } |
|
1727 if ( task.WgId() == 0 ) |
|
1728 { |
|
1729 // This was not root - check if there's more instances of the app |
|
1730 CApaWindowGroupName::FindByAppUid( aAppUid, iWs, wgId ); |
|
1731 HTI_LOG_FORMAT( "FindByAppUid returned WG ID: %d", wgId ); |
|
1732 } |
|
1733 } |
|
1734 |
|
1735 wgs.Close(); |
|
1736 HTI_LOG_FORMAT( "Returning task with WG ID %d", task.WgId() ); |
|
1737 HTI_LOG_FUNC_OUT( "CHtiAppControl::FindRunningRootApp" ); |
|
1738 return task; |
|
1739 } |
|
1740 |
|
1741 TInt CHtiAppControl::OpenProcessL( RProcess& aProcess, |
|
1742 const TDesC& aMatch ) |
|
1743 { |
|
1744 HTI_LOG_FUNC_IN( "CHtiAppControl::OpenProcessL" ); |
|
1745 TFullName processName; |
|
1746 TInt err = KErrNone; |
|
1747 TFindProcess finder( aMatch ); |
|
1748 |
|
1749 err = finder.Next( processName ); |
|
1750 if ( err == KErrNone ) |
|
1751 { |
|
1752 err = aProcess.Open( finder ); |
|
1753 } |
|
1754 |
|
1755 HTI_LOG_FUNC_OUT( "CHtiAppControl::OpenProcessL" ); |
|
1756 return err; |
|
1757 } |
|
1758 |
|
1759 template<class T> T CHtiAppControl::Parse32( |
|
1760 const TDesC8& a32int ) |
|
1761 { |
|
1762 //manually construct TUint or TInt32 |
|
1763 return T( a32int[0] + ( a32int[1] << 8 ) + |
|
1764 ( a32int[2] << 16) + ( a32int[3] << 24) ); |
|
1765 } |
|
1766 |
|
1767 void CHtiAppControl::SendMessageL( TAppCommand aResponseCode, |
|
1768 const TDesC8& aMsg ) |
|
1769 { |
|
1770 HTI_LOG_FORMAT( "SendMessage %d", aResponseCode ); |
|
1771 HTI_LOG_FORMAT( "Message len %d", aMsg.Length() ); |
|
1772 HBufC8* sendMsg = HBufC8::NewL( 1 + aMsg.Length() ); |
|
1773 CleanupStack::PushL( sendMsg ); |
|
1774 sendMsg->Des().Append( aResponseCode ); |
|
1775 sendMsg->Des().Append( aMsg ); |
|
1776 |
|
1777 User::LeaveIfError( iDispatcher->DispatchOutgoingMessage( |
|
1778 sendMsg, |
|
1779 KAppServiceUid ) ); |
|
1780 CleanupStack::Pop(); |
|
1781 } |
|
1782 |
|
1783 inline TInt CHtiAppControl::SendErrorMsg( TInt anError, |
|
1784 const TDesC8& aMsg ) |
|
1785 { |
|
1786 return iDispatcher->DispatchOutgoingErrorMessage( anError, |
|
1787 aMsg, |
|
1788 KAppServiceUid ); |
|
1789 } |
|
1790 |
|
1791 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
1792 SwiUI::TPolicy CHtiAppControl::ConvertToPolicy( const TInt8 aValue ) |
|
1793 { |
|
1794 if ( aValue == 0 ) return SwiUI::EPolicyNotAllowed; |
|
1795 |
|
1796 return SwiUI::EPolicyAllowed; |
|
1797 } |
|
1798 #else |
|
1799 Usif::TSifPolicy CHtiAppControl::ConvertToSifPolicy( const TInt8 aValue ) |
|
1800 { |
|
1801 if ( aValue == 0 ) return Usif::ENotAllowed; |
|
1802 |
|
1803 return Usif::EAllowed; |
|
1804 } |
|
1805 #endif |
|
1806 |
|
1807 TBool CHtiAppControl::ValidateInstallParams( const TDesC8& aParams, TBool aIsUnicode ) |
|
1808 { |
|
1809 HTI_LOG_FORMAT( "ValidateInstallParams => length: %d", aParams.Length() ); |
|
1810 if ( aParams.Length() > 0 ) |
|
1811 { |
|
1812 TInt offset = 0; |
|
1813 TInt length = aParams[offset]; // inst package path length; |
|
1814 if ( aIsUnicode ) length *= 2; |
|
1815 offset++; |
|
1816 if ( aParams.Length() < offset + length ) |
|
1817 { |
|
1818 HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in inst pkg path" ); |
|
1819 return EFalse; |
|
1820 } |
|
1821 |
|
1822 offset += length; // skip over inst package path |
|
1823 offset += 10; // skip over the following one byte params |
|
1824 |
|
1825 if ( aParams.Length() < offset ) |
|
1826 { |
|
1827 HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in one byte params" ); |
|
1828 return EFalse; |
|
1829 } |
|
1830 |
|
1831 length = aParams[offset]; // login username length; |
|
1832 if ( aIsUnicode ) length *= 2; |
|
1833 offset++; |
|
1834 if ( aParams.Length() < offset + length ) |
|
1835 { |
|
1836 HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in username" ); |
|
1837 return EFalse; |
|
1838 } |
|
1839 |
|
1840 offset += length; // skip over login username |
|
1841 |
|
1842 length = aParams[offset]; // password length; |
|
1843 if ( aIsUnicode ) length *= 2; |
|
1844 offset++; |
|
1845 if ( aParams.Length() < offset + length ) |
|
1846 { |
|
1847 HTI_LOG_TEXT( "ValidateInstallParams: Failed, data missing in password" ); |
|
1848 return EFalse; |
|
1849 } |
|
1850 |
|
1851 offset += length; // skip over password |
|
1852 offset += 4; // the last one byte params |
|
1853 |
|
1854 if ( aParams.Length() < offset || aParams.Length() > offset + 2) |
|
1855 { |
|
1856 HTI_LOG_TEXT( "ValidateInstallParams: Failed, final length incorrect" ); |
|
1857 return EFalse; |
|
1858 } |
|
1859 |
|
1860 return ETrue; |
|
1861 } |
|
1862 |
|
1863 return EFalse; |
|
1864 } |
|
1865 |
|
1866 #if ( SYMBIAN_VERSION_SUPPORT < SYMBIAN_4 ) |
|
1867 TInt CHtiAppControl::GetPackageUidL( const TDesC& aPackageName, |
|
1868 TInt aMimeIndex ) |
|
1869 { |
|
1870 HTI_LOG_FUNC_IN( "CHtiAppControl::GetPackageUidL" ); |
|
1871 |
|
1872 if ( aMimeIndex >= 0 && aMimeIndex < 2 ) // SIS |
|
1873 { |
|
1874 Swi::RSisRegistrySession regSession; |
|
1875 User::LeaveIfError( regSession.Connect() ); |
|
1876 CleanupClosePushL( regSession ); |
|
1877 |
|
1878 RArray<TUid> uids; |
|
1879 CleanupClosePushL( uids ); |
|
1880 regSession.InstalledUidsL( uids ); |
|
1881 TInt count = uids.Count(); |
|
1882 HTI_LOG_FORMAT( "Found %d SISx installations", count ); |
|
1883 for ( TInt i = 0; i < count; i++ ) |
|
1884 { |
|
1885 Swi::RSisRegistryEntry entry; |
|
1886 CleanupClosePushL( entry ); |
|
1887 User::LeaveIfError( entry.Open( regSession, uids[i] ) ); |
|
1888 if ( !entry.IsInRomL() && entry.IsPresentL() ) |
|
1889 { |
|
1890 if ( aPackageName.Compare( *( entry.PackageNameL() ) ) == 0 ) |
|
1891 { |
|
1892 HTI_LOG_TEXT( "Matching SIS package found" ); |
|
1893 TInt uid = entry.UidL().iUid; |
|
1894 CleanupStack::PopAndDestroy( 3 ); // entry, uids, regSession |
|
1895 return uid; |
|
1896 } |
|
1897 } |
|
1898 // Check augmentations of this entry |
|
1899 entry.AugmentationsL( iAugmentations ); |
|
1900 TInt augCount = iAugmentations.Count(); |
|
1901 for ( TInt j = 0; j < augCount; j++ ) |
|
1902 { |
|
1903 Swi::RSisRegistryEntry augmentation; |
|
1904 CleanupClosePushL( augmentation ); |
|
1905 augmentation.OpenL( regSession, *iAugmentations[j] ); |
|
1906 if ( aPackageName.Compare( |
|
1907 *( augmentation.PackageNameL() ) ) == 0 ) |
|
1908 { |
|
1909 if ( !augmentation.IsInRomL() && augmentation.IsPresentL() ) |
|
1910 { |
|
1911 HTI_LOG_TEXT( "Matching SIS augmentation found" ); |
|
1912 TInt uid = augmentation.UidL().iUid; |
|
1913 Swi::CSisRegistryPackage* pkg = augmentation.PackageL(); |
|
1914 iAugmentationIndex = pkg->Index(); |
|
1915 delete pkg; |
|
1916 HTI_LOG_FORMAT( "Aug. index %d", iAugmentationIndex ); |
|
1917 CleanupStack::PopAndDestroy( 4 ); // augmentation, entry, uids, regSession |
|
1918 return uid; |
|
1919 } |
|
1920 } |
|
1921 CleanupStack::PopAndDestroy(); // augmentation |
|
1922 } // for j |
|
1923 iAugmentations.ResetAndDestroy(); |
|
1924 CleanupStack::PopAndDestroy(); // entry |
|
1925 } // for i |
|
1926 User::Leave( KErrNotFound ); |
|
1927 } |
|
1928 |
|
1929 else if ( aMimeIndex > 2 && aMimeIndex < 7 ) // Java |
|
1930 { |
|
1931 RArray<TUid> uids; |
|
1932 CleanupClosePushL( uids ); |
|
1933 |
|
1934 CJavaRegistry* javaRegistry = CJavaRegistry::NewLC(); |
|
1935 javaRegistry->GetRegistryEntryUidsL( uids ); |
|
1936 |
|
1937 TInt uid = KErrNotFound; |
|
1938 TInt count = uids.Count(); |
|
1939 HTI_LOG_FORMAT( "Found %d Java installations", count ); |
|
1940 for ( TInt i = 0; i < count; i++ ) |
|
1941 { |
|
1942 CJavaRegistryEntry* entry = javaRegistry->RegistryEntryL( uids[i] ); |
|
1943 if ( entry ) |
|
1944 { |
|
1945 CleanupStack::PushL( entry ); |
|
1946 if ( entry->Type() >= EGeneralPackage && |
|
1947 entry->Type() < EGeneralApplication ) |
|
1948 { |
|
1949 // entry was a package (MIDlet suite) |
|
1950 CJavaRegistryPackageEntry* packageEntry = |
|
1951 ( CJavaRegistryPackageEntry* ) entry; |
|
1952 if ( aPackageName.Compare( packageEntry->Name() ) == 0 ) |
|
1953 { |
|
1954 HTI_LOG_TEXT( "Matching Java installation found" ); |
|
1955 uid = packageEntry->Uid().iUid; |
|
1956 CleanupStack::PopAndDestroy( entry ); |
|
1957 break; |
|
1958 } |
|
1959 } |
|
1960 CleanupStack::PopAndDestroy( entry ); |
|
1961 } |
|
1962 } |
|
1963 CleanupStack::PopAndDestroy( javaRegistry ); |
|
1964 CleanupStack::PopAndDestroy( &uids ); |
|
1965 User::LeaveIfError( uid ); |
|
1966 return uid; |
|
1967 } |
|
1968 |
|
1969 else if ( aMimeIndex == 7 ) // Widget |
|
1970 { |
|
1971 RWidgetRegistryClientSession widgetRegistry; |
|
1972 User::LeaveIfError( widgetRegistry.Connect() ); |
|
1973 |
|
1974 RWidgetInfoArray widgets; |
|
1975 TRAPD( err, widgetRegistry.InstalledWidgetsL( widgets ) ); |
|
1976 if ( err != KErrNone ) |
|
1977 { |
|
1978 HTI_LOG_FORMAT( "Failed to get installed widgets %d", err ); |
|
1979 widgets.ResetAndDestroy(); |
|
1980 widgetRegistry.Disconnect(); |
|
1981 User::Leave( err ); |
|
1982 } |
|
1983 |
|
1984 TInt uid = KErrNotFound; |
|
1985 TInt count = widgets.Count(); |
|
1986 HTI_LOG_FORMAT( "Found %d Widget installations", count ); |
|
1987 for ( TInt i = 0; i < count; i++ ) |
|
1988 { |
|
1989 CWidgetInfo* widgetInfo = widgets[i]; |
|
1990 HTI_LOG_DES( *( widgetInfo->iBundleName ) ); |
|
1991 if ( aPackageName.Compare( *( widgetInfo->iBundleName ) ) == 0 ) |
|
1992 { |
|
1993 HTI_LOG_TEXT( "Matching Widget installation found" ); |
|
1994 uid = widgetInfo->iUid.iUid; |
|
1995 break; |
|
1996 } |
|
1997 } |
|
1998 widgets.ResetAndDestroy(); |
|
1999 widgetRegistry.Disconnect(); |
|
2000 User::LeaveIfError( uid ); |
|
2001 return uid; |
|
2002 } |
|
2003 |
|
2004 else // invalid mime index |
|
2005 { |
|
2006 User::Leave( KErrArgument ); |
|
2007 } |
|
2008 |
|
2009 return KErrNone; // never returns from here |
|
2010 } |
|
2011 #else |
|
2012 TInt CHtiAppControl::GetComponentIdFromUid(const TInt32 aUid) |
|
2013 { |
|
2014 TInt cid = KErrNotFound; |
|
2015 Usif::RSoftwareComponentRegistry registry; |
|
2016 User::LeaveIfError(registry.Connect()); |
|
2017 CleanupClosePushL(registry); |
|
2018 RArray<TUid> uidList; |
|
2019 CleanupClosePushL(uidList); |
|
2020 RArray<Usif::TComponentId> componentIdList; |
|
2021 CleanupClosePushL(componentIdList); |
|
2022 registry.GetComponentIdsL(componentIdList); |
|
2023 for(TInt i = 0; i < componentIdList.Count(); i++) |
|
2024 { |
|
2025 Usif::TComponentId compId = componentIdList[i]; |
|
2026 Usif::CComponentEntry *compEntry = Usif::CComponentEntry::NewLC(); |
|
2027 if(registry.GetComponentL(compId, *compEntry)) |
|
2028 { |
|
2029 /*if(compEntry->IsRemovable() && |
|
2030 compEntry->SoftwareType() == Usif::KSoftwareTypeNative)*/ |
|
2031 if(compEntry->IsRemovable()) |
|
2032 { |
|
2033 _LIT(KCompUid, "CompUid"); |
|
2034 Usif::CPropertyEntry *property = |
|
2035 registry.GetComponentPropertyL(compId, KCompUid); |
|
2036 CleanupStack::PushL(property); |
|
2037 Usif::CIntPropertyEntry* intProperty = |
|
2038 dynamic_cast<Usif::CIntPropertyEntry*>(property); |
|
2039 uidList.AppendL(TUid::Uid(intProperty->IntValue())); |
|
2040 CleanupStack::PopAndDestroy(property); |
|
2041 } |
|
2042 else |
|
2043 { |
|
2044 uidList.AppendL(KNullUid); |
|
2045 } |
|
2046 } |
|
2047 CleanupStack::PopAndDestroy( compEntry ); |
|
2048 } |
|
2049 TUid tuid(TUid::Uid(aUid)); |
|
2050 if(tuid != KNullUid) |
|
2051 { |
|
2052 TInt index = uidList.Find(tuid); |
|
2053 if(index >= 0 && index < componentIdList.Count()) |
|
2054 { |
|
2055 cid = componentIdList[index]; |
|
2056 } |
|
2057 } |
|
2058 CleanupStack::PopAndDestroy( 3, ®istry );// componentIdList, uidList, registry |
|
2059 return cid; |
|
2060 } |
|
2061 |
|
2062 TInt CHtiAppControl::GetComponentIdFromPackageName(const TDesC& aPackageName) |
|
2063 { |
|
2064 TInt cid = KErrNotFound; |
|
2065 Usif::RSoftwareComponentRegistry registry; |
|
2066 User::LeaveIfError(registry.Connect()); |
|
2067 CleanupClosePushL(registry); |
|
2068 RArray<Usif::TComponentId> componentIdList; |
|
2069 CleanupClosePushL(componentIdList); |
|
2070 registry.GetComponentIdsL(componentIdList); |
|
2071 TInt count = componentIdList.Count(); |
|
2072 for(TInt i = 0; i < count; i++) |
|
2073 { |
|
2074 Usif::TComponentId compId = componentIdList[i]; |
|
2075 Usif::CComponentEntry *compEntry = Usif::CComponentEntry::NewLC(); |
|
2076 if(registry.GetComponentL(compId, *compEntry)) |
|
2077 { |
|
2078 if(compEntry->IsRemovable()) |
|
2079 { |
|
2080 if ( aPackageName.Compare( compEntry->Name() ) == 0 ) |
|
2081 { |
|
2082 cid = compId; |
|
2083 CleanupStack::PopAndDestroy( compEntry ); |
|
2084 break; |
|
2085 } |
|
2086 } |
|
2087 } |
|
2088 CleanupStack::PopAndDestroy( compEntry ); |
|
2089 } |
|
2090 CleanupStack::PopAndDestroy( 2, ®istry );// componentIdList, registry |
|
2091 return cid; |
|
2092 } |
|
2093 |
|
2094 #endif |
|
2095 // End of File |
|