1 /* |
|
2 * Copyright (c) 2005-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: CSConAppInstaller implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <s32mem.h> // For RBufWriteStream |
|
21 #include <utf.h> // for CnvUtfConverter |
|
22 //#include <pathinfo.h> |
|
23 #include <usif/sif/sifcommon.h> |
|
24 |
|
25 using namespace Usif; |
|
26 |
|
27 #include "debug.h" |
|
28 #include "sconinstaller.h" |
|
29 #include "sconpcdconsts.h" |
|
30 #include "sconpcdutility.h" |
|
31 |
|
32 |
|
33 const TInt KSConSeConUidValue = 0x101f99f6; |
|
34 const TUid KSConSeConUid = {KSConSeConUidValue}; |
|
35 |
|
36 _LIT8(KValSep, "="); |
|
37 _LIT8(KComma, ","); |
|
38 _LIT8(KLineEnd, "\r\n"); |
|
39 |
|
40 // ============================= MEMBER FUNCTIONS =============================== |
|
41 |
|
42 CSConAppInstaller* CSConAppInstaller::NewL( CSConInstallerQueue* aQueue, RFs& aFs ) |
|
43 { |
|
44 CSConAppInstaller* self = new (ELeave) CSConAppInstaller( aQueue, aFs ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSConAppInstaller::CSConAppInstaller( CSConInstallerQueue* aQueue ) |
|
52 // Constructor |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 CSConAppInstaller::CSConAppInstaller( CSConInstallerQueue* aQueue, RFs& aFs ) : |
|
56 CActive( EPriorityStandard ), iQueue( aQueue ), iFs( aFs ) |
|
57 { |
|
58 CActiveScheduler::Add( this ); |
|
59 } |
|
60 |
|
61 void CSConAppInstaller::ConstructL() |
|
62 { |
|
63 iSifOptions = COpaqueNamedParams::NewL(); |
|
64 iSifResults = COpaqueNamedParams::NewL(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSConAppInstaller::~CSConAppInstaller() |
|
69 // Destructor |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CSConAppInstaller::~CSConAppInstaller() |
|
73 { |
|
74 TRACE_FUNC; |
|
75 Cancel(); |
|
76 iSwInstaller.Close(); |
|
77 delete iSifOptions; |
|
78 delete iSifResults; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CSConAppInstaller::StartInstaller( TInt& aTaskId ) |
|
83 // Starts the installer task |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CSConAppInstaller::StartInstaller( TInt& aTaskId ) |
|
87 { |
|
88 TRACE_FUNC_ENTRY; |
|
89 CSConTask* task = NULL; |
|
90 TRequestStatus* status = NULL; |
|
91 TInt err( KErrNone ); |
|
92 |
|
93 TInt ret = iQueue->GetTask( aTaskId, task ); |
|
94 |
|
95 if( aTaskId > 0 && ret != KErrNotFound ) |
|
96 { |
|
97 if ( IsActive() ) |
|
98 { |
|
99 LOGGER_WRITE("WARNING! SConAppInstaller was not on idle state!"); |
|
100 iQueue->CompleteTask( aTaskId, KErrInUse ); |
|
101 TRACE_FUNC_EXIT; |
|
102 return; |
|
103 } |
|
104 |
|
105 |
|
106 iCurrentTask = aTaskId; |
|
107 iQueue->SetTaskProgress( aTaskId, KSConCodeProcessingStarted ); |
|
108 |
|
109 switch( task->GetServiceId() ) |
|
110 { |
|
111 case EInstall : |
|
112 iQueue->ChangeQueueProcessStatus(); |
|
113 err = iSwInstaller.Connect(); |
|
114 if( err == KErrNone ) |
|
115 { |
|
116 TRAP(err, ProcessInstallL( *task->iInstallParams )); |
|
117 if( err != KErrNone ) |
|
118 { |
|
119 LOGGER_WRITE_1( "StartInstaller ProcessInstallL err: %d", err ); |
|
120 iStatus = KRequestPending; |
|
121 SetActive(); |
|
122 status = &iStatus; |
|
123 User::RequestComplete( status, err ); |
|
124 } |
|
125 } |
|
126 |
|
127 break; |
|
128 case EUninstall : |
|
129 iQueue->ChangeQueueProcessStatus(); |
|
130 err = iSwInstaller.Connect(); |
|
131 if( err == KErrNone ) |
|
132 { |
|
133 LOGGER_WRITE( "Begin to uninstall.. " ); |
|
134 |
|
135 TRAP( err, ProcessUninstallL( *task->iUninstallParams ) ); |
|
136 if( err != KErrNone ) |
|
137 { |
|
138 LOGGER_WRITE_1( "StartInstaller ProcessUninstallL err: %d", err ); |
|
139 iStatus = KRequestPending; |
|
140 SetActive(); |
|
141 status = &iStatus; |
|
142 User::RequestComplete( status, err ); |
|
143 } |
|
144 } |
|
145 |
|
146 break; |
|
147 case EListInstalledApps : |
|
148 iQueue->ChangeQueueProcessStatus(); |
|
149 iStatus = KRequestPending; |
|
150 SetActive(); |
|
151 TRAP( err, ProcessListInstalledAppsL() ); |
|
152 status = &iStatus; |
|
153 User::RequestComplete( status, err ); |
|
154 break; |
|
155 default : |
|
156 break; |
|
157 } |
|
158 } |
|
159 TRACE_FUNC_EXIT; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CSConAppInstaller::StopInstaller( TInt& aTaskId ) |
|
164 // Stops the installer task |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CSConAppInstaller::StopInstaller( TInt& aTaskId ) |
|
168 { |
|
169 TRACE_FUNC_ENTRY; |
|
170 //If the task is the current task, cancel it first |
|
171 if( iCurrentTask == aTaskId ) |
|
172 { |
|
173 Cancel(); |
|
174 iSwInstaller.Close(); |
|
175 } |
|
176 TRACE_FUNC_EXIT; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // TBool CSConAppInstaller::InstallerActive() |
|
181 // returns installer activity status |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 TBool CSConAppInstaller::InstallerActive() const |
|
185 { |
|
186 return IsActive(); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CSConAppInstaller::DoCancel() |
|
191 // Implementation of CActive::DoCancel() |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CSConAppInstaller::DoCancel() |
|
195 { |
|
196 TRACE_FUNC_ENTRY; |
|
197 |
|
198 LOGGER_WRITE("Cancel iSwInstaller"); |
|
199 iSwInstaller.CancelOperation(); |
|
200 /* |
|
201 // find and complete current task |
|
202 CSConTask* task = NULL; |
|
203 TInt ret = iQueue->GetTask( iCurrentTask, task ); |
|
204 |
|
205 if ( iCurrentTask > 0 && ret != KErrNotFound ) |
|
206 { |
|
207 |
|
208 switch( task->GetServiceId() ) |
|
209 { |
|
210 case EInstall : |
|
211 iQueue->CompleteTask( iCurrentTask, KErrCancel ); |
|
212 break; |
|
213 case EUninstall : |
|
214 iQueue->CompleteTask( iCurrentTask, KErrCancel ); |
|
215 break; |
|
216 default : |
|
217 break; |
|
218 } |
|
219 } |
|
220 */ |
|
221 TRACE_FUNC_EXIT; |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CSConAppInstaller::RunL() |
|
226 // Implementation of CActive::RunL() |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CSConAppInstaller::RunL() |
|
230 { |
|
231 TRACE_FUNC_ENTRY; |
|
232 iSwInstaller.Close(); |
|
233 iQueue->ChangeQueueProcessStatus(); |
|
234 TInt err( iStatus.Int() ); |
|
235 LOGGER_WRITE_1( "CSConAppInstaller::RunL() iStatus.Int() : returned %d", err ); |
|
236 |
|
237 CSConTask* task = NULL; |
|
238 TInt taskErr = iQueue->GetTask( iCurrentTask, task ); |
|
239 if( taskErr == KErrNone ) |
|
240 { |
|
241 if ( task->GetServiceId() == EInstall || task->GetServiceId() == EUninstall ) |
|
242 { |
|
243 TRAPD(dataErr, WriteTaskDataL( *task )); |
|
244 if (dataErr) |
|
245 { |
|
246 LOGGER_WRITE_1("WriteTaskDataL err: %d", dataErr); |
|
247 } |
|
248 } |
|
249 |
|
250 if( task->GetServiceId() == EInstall && err == KErrNone ) |
|
251 { |
|
252 LOGGER_WRITE( "CSConAppInstaller::RunL() : before DeleteFile" ); |
|
253 //delete sis after succesfull install |
|
254 DeleteFile( task->iInstallParams->iPath ); |
|
255 } |
|
256 } |
|
257 |
|
258 iQueue->CompleteTask( iCurrentTask, err ); |
|
259 TRACE_FUNC_EXIT; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CSConAppInstaller::WriteTaskDataL() |
|
264 // Writes data to task |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 void CSConAppInstaller::WriteTaskDataL( CSConTask& aTask ) |
|
268 { |
|
269 TRACE_FUNC_ENTRY; |
|
270 CBufFlat* buffer = CBufFlat::NewL(200); |
|
271 CleanupStack::PushL(buffer); |
|
272 RBufWriteStream stream( *buffer ); |
|
273 CleanupClosePushL( stream ); |
|
274 |
|
275 ExternalizeResultArrayIntValL( KSifOutParam_ComponentId , stream); |
|
276 ExternalizeResultIntValL( KSifOutParam_ErrCategory , stream); |
|
277 ExternalizeResultIntValL( KSifOutParam_ErrCode , stream); |
|
278 ExternalizeResultIntValL( KSifOutParam_ExtendedErrCode , stream); |
|
279 ExternalizeResultStringValL( KSifOutParam_ErrMessage , stream); |
|
280 ExternalizeResultStringValL( KSifOutParam_ErrMessageDetails , stream); |
|
281 |
|
282 stream.CommitL(); |
|
283 |
|
284 buffer->Compress(); |
|
285 |
|
286 HBufC8* data = HBufC8::NewL( buffer->Size() ); |
|
287 TPtr8 dataPtr = data->Des(); |
|
288 buffer->Read( 0, dataPtr, buffer->Size() ); |
|
289 |
|
290 if ( aTask.GetServiceId() == EInstall ) |
|
291 { |
|
292 if ( aTask.iInstallParams->iData ) |
|
293 { |
|
294 delete aTask.iInstallParams->iData; |
|
295 aTask.iInstallParams->iData = NULL; |
|
296 } |
|
297 aTask.iInstallParams->iData = data; |
|
298 data = NULL; |
|
299 } |
|
300 else if ( aTask.GetServiceId() == EUninstall ) |
|
301 { |
|
302 if ( aTask.iUninstallParams->iData ) |
|
303 { |
|
304 delete aTask.iUninstallParams->iData; |
|
305 aTask.iUninstallParams->iData = NULL; |
|
306 } |
|
307 aTask.iUninstallParams->iData = data; |
|
308 data = NULL; |
|
309 } |
|
310 else |
|
311 { |
|
312 delete data; |
|
313 data = NULL; |
|
314 } |
|
315 |
|
316 CleanupStack::PopAndDestroy( &stream ); |
|
317 CleanupStack::PopAndDestroy( buffer ); |
|
318 TRACE_FUNC_EXIT; |
|
319 } |
|
320 |
|
321 void CSConAppInstaller::ExternalizeResultArrayIntValL( const TDesC& aName, RWriteStream& aStream ) |
|
322 { |
|
323 TRACE_FUNC_ENTRY; |
|
324 RArray<TInt> valueArray; |
|
325 TRAPD(err, valueArray = iSifResults->IntArrayByNameL(aName)); |
|
326 if ( !err && valueArray.Count() > 0 ) |
|
327 { |
|
328 LOGGER_WRITE_1("count: %d", valueArray.Count()); |
|
329 TBuf8<100> nameBuf; |
|
330 err = CnvUtfConverter::ConvertFromUnicodeToUtf8( nameBuf, aName ); |
|
331 if (!err) |
|
332 { |
|
333 LOGGER_WRITE("2"); |
|
334 aStream.WriteL( nameBuf, nameBuf.Length() ); |
|
335 aStream.WriteL( KValSep, 1 ); |
|
336 aStream.WriteInt32L( valueArray[0] ); |
|
337 for (TInt i=1; i<valueArray.Count(); i++) |
|
338 { |
|
339 aStream.WriteL( KComma, 1 ); |
|
340 aStream.WriteInt32L( valueArray[i] ); |
|
341 } |
|
342 aStream.WriteL( KLineEnd, 2 ); |
|
343 } |
|
344 } |
|
345 TRACE_FUNC_EXIT; |
|
346 } |
|
347 // ----------------------------------------------------------------------------- |
|
348 // CSConAppInstaller::ExternalizeResultIntValL() |
|
349 // Read integer value and write it to stream |
|
350 // ----------------------------------------------------------------------------- |
|
351 // |
|
352 void CSConAppInstaller::ExternalizeResultIntValL( const TDesC& aName, RWriteStream& aStream ) |
|
353 { |
|
354 TRACE_FUNC_ENTRY; |
|
355 TInt value; |
|
356 TBool found(EFalse); |
|
357 found = iSifResults->GetIntByNameL(aName, value); |
|
358 |
|
359 if (found) |
|
360 { |
|
361 TBuf8<100> nameBuf; |
|
362 TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8( nameBuf, aName ); |
|
363 if (!err) |
|
364 { |
|
365 aStream.WriteL( nameBuf, nameBuf.Length() ); |
|
366 aStream.WriteL( KValSep, 1 ); |
|
367 aStream.WriteInt32L( value ); |
|
368 aStream.WriteL( KLineEnd, 2 ); |
|
369 } |
|
370 } |
|
371 TRACE_FUNC_EXIT; |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CSConAppInstaller::ExternalizeResultStringValL() |
|
376 // Read string value and write it to stream |
|
377 // ----------------------------------------------------------------------------- |
|
378 // |
|
379 void CSConAppInstaller::ExternalizeResultStringValL( const TDesC& aName, RWriteStream& aStream ) |
|
380 { |
|
381 TRACE_FUNC_ENTRY; |
|
382 const TDesC& strValue = iSifResults->StringByNameL( aName ); |
|
383 if (strValue.Length() > 0) |
|
384 { |
|
385 TBuf8<100> nameBuf; |
|
386 TInt err = CnvUtfConverter::ConvertFromUnicodeToUtf8( nameBuf, aName ); |
|
387 if (!err) |
|
388 { |
|
389 HBufC8* nameVal = CnvUtfConverter::ConvertFromUnicodeToUtf8L( strValue ); |
|
390 CleanupStack::PushL( nameVal ); |
|
391 aStream.WriteL( nameBuf, nameBuf.Length() ); |
|
392 aStream.WriteL( KValSep, 1 ); |
|
393 aStream.WriteL( nameVal->Des(), nameVal->Length() ); |
|
394 aStream.WriteL( KLineEnd, 2 ); |
|
395 CleanupStack::PopAndDestroy( nameVal ); |
|
396 } |
|
397 } |
|
398 TRACE_FUNC_EXIT; |
|
399 } |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CSConAppInstaller::ProcessInstallL() |
|
403 // Executes Install task |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 void CSConAppInstaller::ProcessInstallL( const CSConInstall& aInstallParams ) |
|
407 { |
|
408 TRACE_FUNC_ENTRY; |
|
409 iSifOptions->Cleanup(); |
|
410 iSifResults->Cleanup(); |
|
411 |
|
412 if ( aInstallParams.iMode == ESilentInstall ) |
|
413 { |
|
414 LOGGER_WRITE( "Begin silent installation.. " ); |
|
415 |
|
416 iSifOptions->AddIntL( Usif::KSifInParam_InstallSilently, ETrue ); |
|
417 iSifOptions->AddIntL( Usif::KSifInParam_PerformOCSP, EFalse ); |
|
418 // Note if upgrade is allowed, see NeedsInstallingL function. |
|
419 iSifOptions->AddIntL( Usif::KSifInParam_AllowUpgrade, ETrue ); |
|
420 iSifOptions->AddIntL( Usif::KSifInParam_AllowUntrusted, EFalse ); |
|
421 iSifOptions->AddIntL( Usif::KSifInParam_GrantCapabilities, EFalse ); |
|
422 // Defined for the install. |
|
423 iSifOptions->AddIntL( Usif::KSifInParam_InstallOptionalItems, ETrue ); |
|
424 iSifOptions->AddIntL( Usif::KSifInParam_IgnoreOCSPWarnings, ETrue ); |
|
425 iSifOptions->AddIntL( Usif::KSifInParam_AllowAppShutdown, ETrue ); |
|
426 iSifOptions->AddIntL( Usif::KSifInParam_AllowDownload, ETrue ); |
|
427 iSifOptions->AddIntL( Usif::KSifInParam_AllowOverwrite, ETrue ); |
|
428 |
|
429 iSwInstaller.Install( aInstallParams.iPath, *iSifOptions, |
|
430 *iSifResults, iStatus, ETrue ); |
|
431 } |
|
432 else |
|
433 { |
|
434 LOGGER_WRITE( "Begin to install.. " ); |
|
435 |
|
436 iSwInstaller.Install( aInstallParams.iPath, *iSifOptions, |
|
437 *iSifResults, iStatus, ETrue ); |
|
438 } |
|
439 SetActive(); |
|
440 TRACE_FUNC_EXIT; |
|
441 } |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CSConAppInstaller::ProcessUninstallL( const CSConUninstall& aUninstallParams ) |
|
445 // Executes UnInstall task |
|
446 // ----------------------------------------------------------------------------- |
|
447 // |
|
448 void CSConAppInstaller::ProcessUninstallL( const CSConUninstall& aUninstallParams ) |
|
449 { |
|
450 TRACE_FUNC_ENTRY; |
|
451 LOGGER_WRITE_1( "aUid: 0x%08x", aUninstallParams.iUid.iUid ); |
|
452 LOGGER_WRITE_1( "aName: %S", &aUninstallParams.iName ); |
|
453 LOGGER_WRITE_1( "aVendor: %S", &aUninstallParams.iVendor ); |
|
454 LOGGER_WRITE_1( "aType: %d", aUninstallParams.iType ); |
|
455 LOGGER_WRITE_1( "aMode: %d", aUninstallParams.iMode ); |
|
456 |
|
457 if ( aUninstallParams.iUid == KSConSeConUid ) |
|
458 { |
|
459 LOGGER_WRITE("Cannot uninstall itself, leave"); |
|
460 // cannot uninstall itself |
|
461 User::Leave( KErrInUse ); //SwiUI::KSWInstErrFileInUse ); |
|
462 } |
|
463 TComponentId componentId = aUninstallParams.iUid.iUid; |
|
464 iSifOptions->Cleanup(); |
|
465 iSifResults->Cleanup(); |
|
466 |
|
467 if ( aUninstallParams.iMode == ESilentInstall) |
|
468 { |
|
469 iSifOptions->AddIntL( Usif::KSifInParam_InstallSilently, ETrue ); |
|
470 iSwInstaller.Uninstall( componentId, *iSifOptions, *iSifResults, iStatus, ETrue ); |
|
471 } |
|
472 else |
|
473 { |
|
474 iSwInstaller.Uninstall( componentId, *iSifOptions, *iSifResults, iStatus, ETrue ); |
|
475 } |
|
476 SetActive(); |
|
477 TRACE_FUNC_EXIT; |
|
478 } |
|
479 |
|
480 //-------------------------------------------------------------------------------- |
|
481 //void CSConAppInstaller::ProcessListInstalledAppsL() |
|
482 //-------------------------------------------------------------------------------- |
|
483 // |
|
484 void CSConAppInstaller::ProcessListInstalledAppsL() |
|
485 { |
|
486 TRACE_FUNC_ENTRY; |
|
487 |
|
488 CSConTask* task = NULL; |
|
489 User::LeaveIfError( iQueue->GetTask( iCurrentTask, task ) ); |
|
490 |
|
491 SConPcdUtility::ProcessListInstalledAppsL( task ); |
|
492 |
|
493 TRACE_FUNC_EXIT; |
|
494 } |
|
495 |
|
496 // ----------------------------------------------------------------------------- |
|
497 // CSConAppInstaller::DeleteFile( const TDesC& aPath ) |
|
498 // Deletes a file |
|
499 // ----------------------------------------------------------------------------- |
|
500 // |
|
501 void CSConAppInstaller::DeleteFile( const TDesC& aPath ) |
|
502 { |
|
503 TRACE_FUNC; |
|
504 iFs.Delete( aPath ); |
|
505 } |
|
506 // End of file |
|