|
1 /* |
|
2 * Copyright (c) 2009-2010 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 * CBootstrapAppUi class implementation. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <aknglobalnote.h> |
|
23 #include <stringloader.h> |
|
24 #include <swinstdefs.h> |
|
25 #include <swi/sisregistrysession.h> |
|
26 #include <swi/sisregistryentry.h> |
|
27 #include <swi/swispubsubdefs.h> |
|
28 #include <httpdownloadmgrcommon.h> |
|
29 #include <coeutils.h> |
|
30 #include <apgcli.h> |
|
31 |
|
32 #include <SenDomFragment.h> |
|
33 #include <SenXmlReader.h> |
|
34 #include <SenElement.h> |
|
35 |
|
36 #include <centralrepository.h> // CRepository |
|
37 #include <browseruisdkcrkeys.h> // KCRUidBrowser |
|
38 #include <httpdownloadmgrcommon.h> |
|
39 #include <es_enum.h> |
|
40 #include <rconnmon.h> |
|
41 |
|
42 #include "bootstrapapplication.h" |
|
43 #include "bootstrapappui.h" |
|
44 #include "bootstrapconst.h" |
|
45 #include "bootstrapglobalwaitnoteobserver.h" |
|
46 #include "bootstrapinstallationobserver.h" |
|
47 #include "debug.h" |
|
48 #include "globals.h" |
|
49 #include "macros.h" |
|
50 #include "config.h" |
|
51 |
|
52 // ADM binary name |
|
53 _LIT(KAdmExePath, "ADM.exe"); |
|
54 |
|
55 _LIT(KDownloadFolder,"?:\\ADM\\"); |
|
56 // Sis file extension |
|
57 _LIT(KSisExtn,".SIS"); |
|
58 _LIT(KSisxExtn,".SISX"); |
|
59 // Xml file extension |
|
60 _LIT(KXMLExtn,".XML"); |
|
61 // Dep file extension |
|
62 _LIT(KDepExtn,"_DEP"); |
|
63 // ADM changes file name |
|
64 _LIT8(KAdmChangesFile, "adm_changes.xml"); |
|
65 |
|
66 // Logging information |
|
67 _LIT(KADMLogDir, "ADM"); |
|
68 _LIT(KBootstrapLogFileName, "Bootstraplog.txt" ); |
|
69 _LIT(KBootstrapLogFile, "?:\\logs\\ADM\\Bootstraplog.txt"); |
|
70 |
|
71 // Private folder of SWI Daemon |
|
72 _LIT(KSWIDaemonPrivateFolder, "\\private\\10202dce\\"); |
|
73 _LIT8(KForwardSlash, "/"); |
|
74 |
|
75 // ADM Uid |
|
76 const TUid KUidAdm = { 0x2002CCCE }; |
|
77 // Max no of connection attempts to Installer |
|
78 const TInt KMaxInstallerConnectionAttempts = 6; |
|
79 |
|
80 // ============================ MEMBER FUNCTIONS =============================== |
|
81 void CBootstrapAppUi::ConstructL() |
|
82 { |
|
83 // Create the log |
|
84 INIT_DEBUG_LOG( KBootstrapLogFile(), KADMLogDir, KBootstrapLogFileName ); |
|
85 |
|
86 // Hide from application task list |
|
87 HideApplicationFromFSW(); |
|
88 |
|
89 // Send us to background |
|
90 SendToBackgroundL(); |
|
91 |
|
92 // Initialise app UI with standard value. |
|
93 BaseConstructL( ENoScreenFurniture /* CAknAppUi::EAknEnableSkin */ ); |
|
94 |
|
95 StatusPane()->MakeVisible(EFalse); |
|
96 |
|
97 // Wait for the installer to be free |
|
98 WaitForInstallCompleteL(); |
|
99 |
|
100 // Bring us to foreground |
|
101 SendToBackgroundL(EFalse); |
|
102 |
|
103 // Get the Uid of the latest installed package |
|
104 iWrapperPackageUid = GetLatestInstalledL(); |
|
105 |
|
106 // Connect to the Download Manager |
|
107 TBool masterInstance( !iEikonEnv->StartedAsServerApp() ); |
|
108 iDownloadManager.ConnectL( KUidBootstrapApp, *this, masterInstance ); |
|
109 |
|
110 // Read the config file |
|
111 ReadConfigurationL(); |
|
112 |
|
113 // Get the dep file and actual application name(if present) |
|
114 TRAPD(err, SetFileNameInfoL()); |
|
115 if (err != KErrNone) |
|
116 { |
|
117 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
118 } |
|
119 |
|
120 #ifdef FEATURE_BOOTSTRAP_SETIAP |
|
121 SetIAPL(); |
|
122 #endif |
|
123 |
|
124 ShowGlobalWaitNoteL(); |
|
125 |
|
126 // Create view object |
|
127 |
|
128 User::LeaveIfError(iLauncher.Connect()); |
|
129 |
|
130 LOG("Checking ADM presence in the device"); |
|
131 iIsAdmInstalled = IsPackagePresentL(KUidAdm, iAdmInstalledVersion); |
|
132 |
|
133 LOG( "* State changed to EChangesDownloadState" ); |
|
134 iAppState = EChangesDownloadState; |
|
135 DownloadL(); |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CBootstrapAppUi::CBootstrapAppUi() |
|
140 // C++ default constructor can NOT contain any code, that might leave. |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 CBootstrapAppUi::CBootstrapAppUi(): |
|
144 iAllowForeground(EFalse), |
|
145 iIsAdmInstalled(EFalse), |
|
146 iAdmChangesInfo() |
|
147 { |
|
148 LOG ( "SmartInstaller starts"); |
|
149 // disable possible transition effects |
|
150 SetFullScreenApp(EFalse); |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CBootstrapAppUi::~CBootstrapAppUi() |
|
155 // Destructor. |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 CBootstrapAppUi::~CBootstrapAppUi() |
|
159 { |
|
160 LOG( "Bootstrap App ends"); |
|
161 DELETE_IF_NONNULL( iDepFilename ); |
|
162 DELETE_IF_NONNULL( iSisFileName ); |
|
163 delete iGlobalWaitNoteObserver; |
|
164 delete iGlobalWaitNote; |
|
165 delete iInstallObsrv; |
|
166 delete iConfigUrl; |
|
167 delete iUrl; |
|
168 delete iDownloadFileName; |
|
169 |
|
170 iDownloadManager.DeleteAll(); |
|
171 iDownloadManager.Close(); |
|
172 |
|
173 iLauncher.Close(); |
|
174 |
|
175 CLOSE_DEBUG_LOG; |
|
176 } |
|
177 |
|
178 void CBootstrapAppUi::HandleGlobalWaitNoteCancel(const TInt& aStatus) |
|
179 { |
|
180 LOG3( "+ Cancel note %d, %d", iAppState, aStatus ); |
|
181 |
|
182 // Do the cleanup based on the state |
|
183 if (aStatus == -1) |
|
184 { |
|
185 iGlobalWaitNoteId = -1; |
|
186 |
|
187 switch(iAppState) |
|
188 { |
|
189 case EInitialState: |
|
190 // No CleanUp required here |
|
191 break; |
|
192 |
|
193 case EChangesDownloadState: |
|
194 { |
|
195 // Cancel download |
|
196 iDownloadManager.ResetAll(); |
|
197 break; |
|
198 } |
|
199 |
|
200 case EChangesParseState: |
|
201 { |
|
202 // Delete the downloaded dep file |
|
203 if (iDownloadFileName) |
|
204 { |
|
205 DeleteFile(*iDownloadFileName); |
|
206 } |
|
207 } |
|
208 // fall-through |
|
209 |
|
210 case EADMDownloadState: |
|
211 { |
|
212 // Cancel download |
|
213 iDownloadManager.ResetAll(); |
|
214 break; |
|
215 } |
|
216 |
|
217 case EADMInstallState: |
|
218 { |
|
219 // Cancel installation |
|
220 iLauncher.CancelAsyncRequest(SwiUI::ERequestSilentInstall); |
|
221 // Delete the downloaded sis file. |
|
222 if (iDownloadFileName) |
|
223 { |
|
224 DeleteFile(*iDownloadFileName); |
|
225 } |
|
226 } |
|
227 // fall-through |
|
228 |
|
229 case EADMLaunchState: |
|
230 // No CleanUp required here |
|
231 break; |
|
232 |
|
233 default: |
|
234 break; |
|
235 } |
|
236 |
|
237 TRAP_IGNORE( |
|
238 ShowNoteL(EAknGlobalErrorNote, R_INSTALLATION_CANCELLED); |
|
239 ); |
|
240 |
|
241 // Always delete the dep file in case of failure in |
|
242 // bootstrap to ensure correct dep file is picked up |
|
243 // when the outer package is installed. |
|
244 if((KBootstrapVersion == 3)&&(iDepFilename)) |
|
245 { |
|
246 DeleteFile(*iDepFilename); |
|
247 } |
|
248 else if((KBootstrapVersion == 4)&&(iSisFileName)) |
|
249 { |
|
250 DeleteFile(*iSisFileName); |
|
251 } |
|
252 |
|
253 // Close the bootstrap application |
|
254 CloseApp(); |
|
255 } |
|
256 LOG3( "- Cancel note %d, %d", iAppState, aStatus ); |
|
257 } |
|
258 |
|
259 void CBootstrapAppUi::ParseChangesInfoL( const TDesC& aChangesFileName ) |
|
260 { |
|
261 LOG2("+ Parse File ('%S')", &aChangesFileName); |
|
262 |
|
263 // Initailize the parser |
|
264 CSenXmlReader* XmlReader = CSenXmlReader::NewLC(EErrorOnUnrecognisedTags); |
|
265 CSenDomFragment* DomFragment = CSenDomFragment::NewL(); |
|
266 CleanupStack::PushL(DomFragment); |
|
267 |
|
268 XmlReader->SetContentHandler(*DomFragment); |
|
269 DomFragment->SetReader(*XmlReader); |
|
270 |
|
271 // Parse the provided changes file |
|
272 XmlReader->ParseL(CEikonEnv::Static()->FsSession(), aChangesFileName); |
|
273 |
|
274 // Get package version |
|
275 CSenElement* packageElement; |
|
276 packageElement = DomFragment->AsElement().Element(KFieldVersion); |
|
277 if (packageElement == NULL) |
|
278 { |
|
279 User::Leave(EMissingVersion); |
|
280 } |
|
281 else |
|
282 { |
|
283 TPtrC8 versionPtr = packageElement->Content(); |
|
284 TVersion ver; |
|
285 if (SetVersion(versionPtr, iAdmChangesInfo.iVersion) == EFalse) |
|
286 { |
|
287 User::Leave(EInvalidVersion); |
|
288 } |
|
289 } |
|
290 |
|
291 // Get the ADM sis file name |
|
292 packageElement = DomFragment->AsElement().Element(KFieldSisName); |
|
293 if (packageElement) |
|
294 { |
|
295 TPtrC8 sisNamePtr = packageElement->Content(); |
|
296 iAdmChangesInfo.iSisName = sisNamePtr.AllocL(); |
|
297 } |
|
298 else |
|
299 { |
|
300 User::Leave(EMissingSisFileName); |
|
301 } |
|
302 |
|
303 //URL read from ADM changes file is disabled. |
|
304 //ADM.sis will be fetched from the default config url always...same as ADM_changes.xml |
|
305 #if 0 |
|
306 // Get the optional URL |
|
307 packageElement = DomFragment->AsElement().Element(KFieldUrl); |
|
308 if (packageElement) |
|
309 { |
|
310 TPtrC8 urlPtr = packageElement->Content(); |
|
311 iAdmChangesInfo.iUrl = urlPtr.AllocL(); |
|
312 } |
|
313 #endif |
|
314 |
|
315 CleanupStack::PopAndDestroy( DomFragment ) ; |
|
316 CleanupStack::PopAndDestroy( XmlReader ) ; |
|
317 |
|
318 LOG( "- ParseChangesInfoL()" ); |
|
319 } |
|
320 |
|
321 #ifdef FEATURE_BOOTSTRAP_SETIAP |
|
322 void CBootstrapAppUi::SetIAPL() |
|
323 { |
|
324 LOG( "+ CBootstrapAppUi::SetIAPL()" ); |
|
325 // Use the browser default IAP, if available |
|
326 CRepository *repository = CRepository::NewLC( KCRUidBrowser ); |
|
327 TInt ret, browserIAP; |
|
328 ret = repository->Get( KBrowserDefaultAccessPoint, browserIAP ); |
|
329 CleanupStack::PopAndDestroy( repository ); |
|
330 |
|
331 LOG3("Browser IAP ID = %d, ret = %d ", browserIAP, ret); |
|
332 if ( ( ret != KErrNone ) || ( browserIAP < 0 ) ) |
|
333 { |
|
334 |
|
335 browserIAP = 0; |
|
336 |
|
337 } |
|
338 |
|
339 //No Browser default IAP. Fetch from connection monitor |
|
340 RConnectionMonitor monitor; |
|
341 CleanupClosePushL(monitor); |
|
342 |
|
343 TUint count; |
|
344 TRequestStatus status; |
|
345 |
|
346 monitor.ConnectL(); |
|
347 monitor.GetConnectionCount( count, status ); |
|
348 LOG2("ConnMon connCount = %d", count); |
|
349 User::WaitForRequest( status ); |
|
350 if ( status.Int() != KErrNone ) |
|
351 { |
|
352 // error |
|
353 LOG2("ConnMon.ConnCount() ret = %d, ignoring.", status.Int() ); |
|
354 } |
|
355 |
|
356 // get all available IAPs |
|
357 TConnMonIapInfoBuf iapBuf; |
|
358 |
|
359 monitor.GetPckgAttribute( EBearerIdAll, 0, KIapAvailability, iapBuf, status ); |
|
360 User::WaitForRequest( status ) ; |
|
361 |
|
362 if ( status.Int() != KErrNone ) |
|
363 { |
|
364 LOG2("ConnMon.GetAttr() ret = %d, ignoring.", ret); |
|
365 } |
|
366 else |
|
367 { |
|
368 TInt countIaps = iapBuf().iCount; |
|
369 LOG2("IAP count %d", countIaps); |
|
370 |
|
371 // Get the IAPId of the first IAP in the buffer. |
|
372 iIAP = iapBuf().iIap[ 0 ].iIapId; |
|
373 |
|
374 LOG2("IAP ID[0] is %d", iIAP); |
|
375 |
|
376 //Now check whether any IAPId matches BrowserIAP, if yes then set the browserIAP as iIAP |
|
377 while( countIaps > 0) |
|
378 { |
|
379 LOG3("IAP %d: ID = %d", countIaps, iapBuf().iIap[ countIaps ].iIapId); |
|
380 if( iapBuf().iIap[ countIaps ].iIapId == browserIAP) |
|
381 { |
|
382 iIAP = browserIAP; |
|
383 break; |
|
384 } |
|
385 countIaps--; |
|
386 } |
|
387 |
|
388 LOG2("IAP ID after comparison %d", iIAP); |
|
389 } |
|
390 |
|
391 |
|
392 |
|
393 if ( iIAP > 0) |
|
394 { |
|
395 #ifdef DO_LOG |
|
396 TBuf<64> iapName; |
|
397 monitor.GetStringAttribute( iIAP, 0, KIAPName, iapName, status ); |
|
398 User::WaitForRequest( status ); |
|
399 if ( status.Int() != KErrNone ) |
|
400 { |
|
401 LOG2( "ConnMon.GetStrAttr() ret = %d, ignoring.", status.Int() ); |
|
402 } |
|
403 LOG3( "Setting DownloadManager IAP to %d ('%S'). No user prompt for IAP.", iIAP, &iapName ); |
|
404 #endif |
|
405 // Set the download manager to silent mode |
|
406 iDownloadManager.SetBoolAttribute( EDlMgrSilentMode, ETrue ); |
|
407 iDownloadManager.SetIntAttribute( EDlMgrIap, iIAP ); |
|
408 } |
|
409 //else implies user will be prompted. |
|
410 CleanupStack::PopAndDestroy( &monitor ); |
|
411 } |
|
412 |
|
413 LOG( "- CBootstrapAppUi::SetIAPL()" ); |
|
414 } |
|
415 #endif |
|
416 void CBootstrapAppUi::DownloadL() |
|
417 { |
|
418 LOG2( "+ Download(): %d,", iAppState ); |
|
419 |
|
420 TPtrC8 filename(NULL,0); |
|
421 HBufC8* Url = NULL; |
|
422 |
|
423 // Set the download filename and Url based |
|
424 // on the state. |
|
425 switch(iAppState) |
|
426 { |
|
427 case EChangesDownloadState: |
|
428 { |
|
429 filename.Set(KAdmChangesFile); |
|
430 Url = iConfigUrl; |
|
431 break; |
|
432 } |
|
433 case EADMDownloadState: |
|
434 { |
|
435 User::LeaveIfNull(iAdmChangesInfo.iSisName); |
|
436 filename.Set((iAdmChangesInfo.iSisName)->Des()); |
|
437 // If the Url is not provided as part of the changes file, |
|
438 // take the default Url |
|
439 Url = (iAdmChangesInfo.iUrl==NULL) ?iConfigUrl :iAdmChangesInfo.iUrl; |
|
440 break; |
|
441 } |
|
442 default: |
|
443 { |
|
444 LOG2( "! Unexpected state: %d", iAppState ); |
|
445 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
446 } |
|
447 } |
|
448 |
|
449 // Create the full URL for download |
|
450 DELETE_IF_NONNULL( iUrl); |
|
451 iUrl = HBufC8::NewL(Url->Length() + filename.Length() + KForwardSlash().Length() ); |
|
452 *iUrl = *Url; |
|
453 TPtr8 ptr(iUrl->Des()); |
|
454 |
|
455 // Append forward slash if that's missing |
|
456 if (ptr.Right(1) != KForwardSlash) |
|
457 { |
|
458 ptr.Append(KForwardSlash); |
|
459 } |
|
460 ptr.Append(filename); |
|
461 |
|
462 |
|
463 // Set download file name along with path |
|
464 TChar systemDrive; |
|
465 RFs::DriveToChar(RFs::GetSystemDrive(),systemDrive); |
|
466 |
|
467 DELETE_IF_NONNULL( iDownloadFileName ); |
|
468 iDownloadFileName = HBufC::NewL(KDownloadFolder().Length() + filename.Length()); |
|
469 |
|
470 *iDownloadFileName = KDownloadFolder; |
|
471 iDownloadFileName->Des()[0] = systemDrive; |
|
472 |
|
473 TPtr responseFilenamePtr = iDownloadFileName->Des(); |
|
474 |
|
475 HBufC* filename16 = HBufC::NewLC(filename.Length()); |
|
476 filename16->Des().Copy(filename); |
|
477 responseFilenamePtr.Append(*filename16); |
|
478 CleanupStack::PopAndDestroy(filename16); |
|
479 |
|
480 iPausable = EFalse; |
|
481 iConnectionAttempts = 0; |
|
482 |
|
483 // Create new download |
|
484 LOG8_2( "Downloading from URL: '%S'", iUrl ); |
|
485 LOG2(" Download begins for '%S'", iDownloadFileName ); |
|
486 TBool isNewDl = ETrue; |
|
487 RHttpDownload& dl = iDownloadManager.CreateDownloadL( *iUrl, isNewDl ); |
|
488 |
|
489 ConeUtils::EnsurePathExistsL(*iDownloadFileName); |
|
490 if(isNewDl) |
|
491 { |
|
492 LOG2( "Response body filename is '%S'", iDownloadFileName ); |
|
493 dl.SetStringAttribute( EDlAttrDestFilename, *iDownloadFileName ); |
|
494 dl.Start(); |
|
495 } |
|
496 |
|
497 LOG( "- Download()" ); |
|
498 } |
|
499 |
|
500 void CBootstrapAppUi::WaitForInstallCompleteL() |
|
501 { |
|
502 LOG( "+ WaitForInstallCompleteL()" ); |
|
503 |
|
504 // Use publish and subscribe mechanism to |
|
505 // get notified when installer is free. |
|
506 RProperty installComplete; |
|
507 User::LeaveIfError( installComplete.Attach(KUidSystemCategory, Swi::KUidSoftwareInstallKey) ); |
|
508 |
|
509 TInt value; |
|
510 if ( installComplete.Get( KUidSystemCategory, Swi::KUidSoftwareInstallKey, value ) == KErrNotFound ) |
|
511 { |
|
512 LOG( "! Could not get installer" ); |
|
513 installComplete.Close(); |
|
514 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
515 } |
|
516 else if ( (value & Swi::KSwisOperationMask) == Swi::ESwisNone ) |
|
517 { |
|
518 // Installer is idle. |
|
519 } |
|
520 else |
|
521 { |
|
522 LOG( "Waiting for the Installer to finish installation" ); |
|
523 TRequestStatus status; |
|
524 installComplete.Subscribe(status); |
|
525 User::WaitForRequest(status); |
|
526 } |
|
527 |
|
528 iAllowForeground = ETrue; |
|
529 LOG( "Installer is idle" ); |
|
530 installComplete.Close(); |
|
531 LOG( "- WaitForInstallCompleteL()" ); |
|
532 } |
|
533 |
|
534 TUint32 CBootstrapAppUi::GetLatestInstalledL() |
|
535 { |
|
536 LOG( "+ GetLatestInstalledL()" ); |
|
537 |
|
538 // Use publish and subscribe mechanism to |
|
539 // get Uid of the latest installed package. |
|
540 RProperty lastInstall; |
|
541 User::LeaveIfError(lastInstall.Attach(KUidSystemCategory, KUidSwiLatestInstallation)); |
|
542 |
|
543 TInt value = -1; |
|
544 if (lastInstall.Get( KUidSystemCategory, KUidSwiLatestInstallation, value ) == KErrNotFound) |
|
545 { |
|
546 LOG( "! Could not get installer" ); |
|
547 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
548 } |
|
549 LOG2( "- GetLatestInstalled(): wrapper=0x%08x", value ); |
|
550 return value; |
|
551 } |
|
552 |
|
553 void CBootstrapAppUi::ShowGlobalWaitNoteL() |
|
554 { |
|
555 |
|
556 // Allocate TBuf with constant length. |
|
557 TBuf<KMaxMsgSize> text( NULL ); |
|
558 |
|
559 // Reads a resource into a descriptor. |
|
560 CEikonEnv::Static()->ReadResource( text, R_ADM_ENV_CREATION_WAIT_TEXT ); |
|
561 |
|
562 // Create new CAknGlobalNote instance. |
|
563 iGlobalWaitNote = CAknGlobalNote::NewL(); |
|
564 |
|
565 iGlobalWaitNoteObserver = new (ELeave) CGlobalWaitNoteObserver(this); |
|
566 iGlobalWaitNoteObserver->iStatus = KRequestPending; |
|
567 iGlobalWaitNoteObserver->Start(); |
|
568 |
|
569 iGlobalWaitNoteId = iGlobalWaitNote->ShowNoteL( |
|
570 iGlobalWaitNoteObserver->iStatus, |
|
571 EAknGlobalWaitNote, |
|
572 text ); |
|
573 } |
|
574 |
|
575 void CBootstrapAppUi::StopGlobalWaitNoteL() |
|
576 { |
|
577 LOG2( "+ CBootstrapAppUi::StopGlobalWaitNoteL(): %d", iGlobalWaitNoteId ); |
|
578 if(iGlobalWaitNote && (iGlobalWaitNoteId >= 0)) |
|
579 { |
|
580 iGlobalWaitNote->CancelNoteL(iGlobalWaitNoteId); |
|
581 } |
|
582 iGlobalWaitNoteId = -1; |
|
583 |
|
584 DELETE_IF_NONNULL( iGlobalWaitNote ); |
|
585 DELETE_IF_NONNULL( iGlobalWaitNoteObserver ); |
|
586 LOG( "- CBootstrapAppUi::StopGlobalWaitNoteL()" ); |
|
587 } |
|
588 |
|
589 void CBootstrapAppUi::HandleDMgrEventL( RHttpDownload& aDownload, THttpDownloadEvent aEvent ) |
|
590 { |
|
591 LOG3("+HandleDMgrEventL(): DlState=%d, ProgState=%d", aEvent.iDownloadState, aEvent.iProgressState); |
|
592 |
|
593 TInt32 tmp; |
|
594 THttpDownloadMgrError dlErrorId; |
|
595 TInt32 sysErrorId( KErrNone ); |
|
596 |
|
597 // If DL is in final state (complete/fail), there's an error id available. |
|
598 // TODO: Handle error condition |
|
599 TInt sysErr = aDownload.GetIntAttribute( EDlAttrGlobalErrorId ,sysErrorId ); |
|
600 TInt dlErr = aDownload.GetIntAttribute( EDlAttrErrorId ,tmp ); |
|
601 dlErrorId = (THttpDownloadMgrError)tmp; |
|
602 |
|
603 //TODO: Include Log5 |
|
604 //LOG5( "SysErrId=%d, DlErrId=%d. DlSize=%d, CntSize=%d.", sysErrorId, dlErrorId, downloadedsize, contentsize ); |
|
605 |
|
606 switch ( aEvent.iDownloadState ) |
|
607 { |
|
608 case EHttpDlCreated: |
|
609 { |
|
610 break; |
|
611 } |
|
612 case EHttpDlInprogress: |
|
613 { |
|
614 switch ( aEvent.iProgressState) |
|
615 { |
|
616 case EHttpProgCreatingConnection: |
|
617 { |
|
618 break; |
|
619 } |
|
620 case EHttpProgConnected: |
|
621 { |
|
622 break; |
|
623 } |
|
624 case EHttpProgConnectionSuspended: |
|
625 case EHttpProgDisconnected: |
|
626 { |
|
627 // Try to reconnect if: |
|
628 // 1. No of connection attempts is less than KMaxDlConnectionAttempts |
|
629 // 2. IAP selection dialog is not cancelled. |
|
630 if ((iConnectionAttempts < KMaxDlConnectionAttempts) |
|
631 && !(dlErrorId == EConnectionFailed && sysErrorId == KErrCancel)) |
|
632 { |
|
633 ++iConnectionAttempts; |
|
634 LOG2("Restart attempt is '%d'",iConnectionAttempts); |
|
635 aDownload.Start(); |
|
636 } |
|
637 break; |
|
638 } |
|
639 case EHttpProgDownloadStarted: |
|
640 { |
|
641 break; |
|
642 } |
|
643 case EHttpContentTypeRequested: |
|
644 { |
|
645 break; |
|
646 } |
|
647 case EHttpProgResponseHeaderReceived: |
|
648 { |
|
649 break; |
|
650 } |
|
651 case EHttpProgResponseBodyReceived: |
|
652 { |
|
653 break; |
|
654 } |
|
655 default : |
|
656 break; |
|
657 } |
|
658 break; |
|
659 } |
|
660 case EHttpDlPausable: |
|
661 { |
|
662 iPausable = ETrue; |
|
663 break; |
|
664 } |
|
665 case EHttpDlNonPausable: |
|
666 { |
|
667 iPausable = EFalse; |
|
668 break; |
|
669 } |
|
670 case EHttpDlCompleted: |
|
671 { |
|
672 iDownloadManager.GetIntAttribute( EDlMgrIap, iIAP ); |
|
673 LOG2("IAP set to %d", iIAP); |
|
674 |
|
675 HandleHttpFetchCompleteL(EFalse); |
|
676 break; |
|
677 } |
|
678 case EHttpDlPaused: |
|
679 { |
|
680 if((dlErrorId == EConnectionFailed) && (sysErrorId == KErrCancel)) |
|
681 { |
|
682 isIapCancelled = 1; |
|
683 } |
|
684 |
|
685 // Continue dowload if paused in EHttpContentTypeReceived |
|
686 if(aEvent.iProgressState == EHttpContentTypeReceived) |
|
687 { |
|
688 aDownload.Start(); |
|
689 } |
|
690 // Try to reconnect if: |
|
691 // 1. No of connection attempts is less than KMaxDlConnectionAttempts |
|
692 // 2. IAP selection dialog is not cancelled. |
|
693 else if((iConnectionAttempts < KMaxDlConnectionAttempts) |
|
694 && (!isIapCancelled)) |
|
695 { |
|
696 aDownload.Start(); |
|
697 } |
|
698 else if(iPausable) |
|
699 { |
|
700 aDownload.Start(); |
|
701 } |
|
702 else |
|
703 { |
|
704 HandleHttpFetchCompleteL(ETrue); |
|
705 } |
|
706 break; |
|
707 } |
|
708 case EHttpDlFailed: |
|
709 { |
|
710 if((dlErrorId == EConnectionFailed) && (sysErrorId == KErrCancel)) |
|
711 { |
|
712 isIapCancelled = 1; |
|
713 } |
|
714 |
|
715 HandleHttpFetchCompleteL(ETrue); |
|
716 break; |
|
717 } |
|
718 case EHttpDlDeleting: |
|
719 { |
|
720 break; |
|
721 } |
|
722 case EHttpDlDeleted: |
|
723 { |
|
724 break; |
|
725 } |
|
726 default: |
|
727 { |
|
728 break; |
|
729 } |
|
730 } |
|
731 } |
|
732 |
|
733 |
|
734 void CBootstrapAppUi::HandleHttpFetchCompleteL(const TBool& aStatus) |
|
735 { |
|
736 LOG3( "+ Fetch(): s=%d, a=%d", aStatus, iAppState ); |
|
737 |
|
738 User::LeaveIfNull(iDownloadFileName); |
|
739 |
|
740 if (aStatus == EFalse) |
|
741 { |
|
742 switch(iAppState) |
|
743 { |
|
744 case EChangesDownloadState: |
|
745 { |
|
746 // Parse downloaded changes file |
|
747 iAppState = EChangesParseState; |
|
748 LOG("* State changed to EChangesParseState"); |
|
749 |
|
750 TRAPD(err, ParseChangesInfoL(*iDownloadFileName)); |
|
751 LOG2( "Changes file parsing completed with status: %d", err); |
|
752 |
|
753 // Delete no longer required changes file |
|
754 DeleteFile(*iDownloadFileName); |
|
755 |
|
756 // 1. Install ADM if not already present |
|
757 // 2. Upgrade ADM if higher version is available |
|
758 // 3. If the upgrade fails, launch the current version |
|
759 // of ADM in device. |
|
760 TBool isAdmDownloadRequired = CompareVersions(iAdmInstalledVersion, iAdmChangesInfo.iVersion) |
|
761 == EGreaterSecondVersion; |
|
762 |
|
763 if ((err==KErrNone) && isAdmDownloadRequired) |
|
764 { |
|
765 LOG( "* Changing state to EADMDownloadState" ); |
|
766 iAppState = EADMDownloadState; |
|
767 DownloadL(); |
|
768 } |
|
769 else if (iIsAdmInstalled) |
|
770 { |
|
771 LOG( "* Changing state to EADMLaunchState" ); |
|
772 iAppState = EADMLaunchState; |
|
773 TRAPD( err, LaunchAdmL() ); |
|
774 if (err != KErrNone) |
|
775 { |
|
776 LOG2( "ADM launch fail %d", err ); |
|
777 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
778 } |
|
779 LOG( "ADM launched OK, exiting! 1" ); |
|
780 TRAP_IGNORE( StopGlobalWaitNoteL() ); |
|
781 CloseApp(); |
|
782 } |
|
783 else |
|
784 { |
|
785 // Adm changes file parse error |
|
786 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
787 } |
|
788 break; |
|
789 } |
|
790 |
|
791 case EADMDownloadState: |
|
792 { |
|
793 LOG2( "ADM downloaded OK: '%S'", iDownloadFileName); |
|
794 |
|
795 iAppState = EADMInstallState; |
|
796 LOG( "* State changed to EADMInstallState" ); |
|
797 AsyncInstallPackageL(*iDownloadFileName); |
|
798 break; |
|
799 } |
|
800 |
|
801 default: |
|
802 { |
|
803 LOG2( "Unexpected state %d", iAppState ); |
|
804 // Unexpected State |
|
805 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
806 } |
|
807 } |
|
808 } |
|
809 else |
|
810 { |
|
811 // Launch existing version of ADM (if present) in device |
|
812 // in case of download failure. |
|
813 if (iIsAdmInstalled && (!isIapCancelled)) |
|
814 { |
|
815 LOG( "* Changing state to EADMLaunchState" ); |
|
816 iAppState = EADMLaunchState; |
|
817 TRAPD(err, LaunchAdmL()); |
|
818 if (err != KErrNone) |
|
819 { |
|
820 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
821 } |
|
822 LOG( "ADM launched OK, exiting! 2" ); |
|
823 TRAP_IGNORE( StopGlobalWaitNoteL() ); |
|
824 CloseApp(); |
|
825 } |
|
826 else |
|
827 { |
|
828 LOG( "! ADM download failed!" ); |
|
829 ExitWithError(R_HTTP_TRANSACTION_ERR); |
|
830 } |
|
831 } |
|
832 |
|
833 LOG( "- Fetch complete "); |
|
834 } |
|
835 |
|
836 void CBootstrapAppUi::SetFileNameInfoL() |
|
837 { |
|
838 LOG( "+ SetFileNameInfoL()" ); |
|
839 LOG2( "Bootstrap version: %d", KBootstrapVersion); |
|
840 |
|
841 if(KBootstrapVersion<1 && KBootstrapVersion>4) |
|
842 { |
|
843 // Unsupported Bootstrap version |
|
844 User::Leave(KErrNotSupported); |
|
845 } |
|
846 |
|
847 // Connect to SisRegistry to fetch Package info |
|
848 Swi::RSisRegistrySession registrySession; |
|
849 User::LeaveIfError(registrySession.Connect()); |
|
850 CleanupClosePushL(registrySession); |
|
851 |
|
852 Swi::RSisRegistryEntry entry; |
|
853 |
|
854 // Open registry entry |
|
855 User::LeaveIfError(entry.Open(registrySession, TUid::Uid(iWrapperPackageUid))); |
|
856 CleanupClosePushL(entry); |
|
857 |
|
858 RPointerArray<HBufC> packageFiles; |
|
859 entry.FilesL(packageFiles); |
|
860 const TInt filesCount(packageFiles.Count()); |
|
861 |
|
862 // look into the files installed as part of the package, |
|
863 // to find the dep file name and actuall application file name. |
|
864 for (TInt i=0; i<filesCount; i++) |
|
865 { |
|
866 TParse parse; |
|
867 TInt err = parse.Set(packageFiles[i]->Des(), NULL, NULL); |
|
868 if (err != KErrNone) |
|
869 { |
|
870 continue; |
|
871 } |
|
872 TPtrC orgExtn = parse.Ext(); |
|
873 |
|
874 if (orgExtn.Length() == 0) |
|
875 { |
|
876 continue; |
|
877 } |
|
878 |
|
879 HBufC* extn = orgExtn.AllocLC(); |
|
880 TPtr extnPtr = extn->Des(); |
|
881 extnPtr.UpperCase(); |
|
882 |
|
883 if(KBootstrapVersion != 3) |
|
884 { |
|
885 if ((extnPtr.Compare(KSisExtn) == 0)||(extnPtr.Compare(KSisxExtn) == 0)) |
|
886 { |
|
887 TPtrC privatePath( KNullDesC ); |
|
888 const TInt driveLength = 2; |
|
889 if (packageFiles[i]->Length() > (KSWIDaemonPrivateFolder().Length() + driveLength)) |
|
890 { |
|
891 privatePath.Set( packageFiles[i]->Des().Mid( driveLength ) ); |
|
892 privatePath.Set( privatePath.Left( KSWIDaemonPrivateFolder().Length() ) ); |
|
893 } |
|
894 |
|
895 // Ignore if its a Stub Sis file |
|
896 if(privatePath.CompareF(KSWIDaemonPrivateFolder)) |
|
897 { |
|
898 if (iSisFileName == NULL) |
|
899 { |
|
900 iSisFileName = packageFiles[i]->AllocL(); |
|
901 LOG2( "Actual application name is '%S'", iSisFileName); |
|
902 } |
|
903 else |
|
904 // More than one sis present in the Wrapper Pkg |
|
905 { |
|
906 LOG2( "! More than one sis file present: '%S'. LEAVE.", packageFiles[i] ); |
|
907 |
|
908 User::Leave(KErrNotSupported); |
|
909 } |
|
910 } |
|
911 }//end of sis extension |
|
912 }//end of Bootstrapversion 2 |
|
913 if (KBootstrapVersion != 4) |
|
914 { |
|
915 if(extnPtr.Compare(KXMLExtn) == 0) |
|
916 { |
|
917 TPtrC orgName = parse.Name(); |
|
918 const TInt namelength = orgName.Length(); |
|
919 const TInt depSuffixlength = KDepExtn().Length(); |
|
920 |
|
921 if (namelength > depSuffixlength) |
|
922 { |
|
923 TPtrC depSuffix = orgName.Mid((namelength-depSuffixlength), depSuffixlength); |
|
924 |
|
925 HBufC* name = depSuffix.AllocLC(); |
|
926 TPtr namePtr = name->Des(); |
|
927 namePtr.UpperCase(); |
|
928 |
|
929 if (namePtr.Compare(KDepExtn) == 0) |
|
930 { |
|
931 if (iDepFilename == NULL) |
|
932 { |
|
933 iDepFilename = packageFiles[i]->AllocL(); |
|
934 LOG2( "Dep file name is '%S'", iDepFilename); |
|
935 } |
|
936 else |
|
937 // More than one dep file present in the Wrapper Pkg |
|
938 { |
|
939 LOG2( "! More than one dep file present: '%S'. LEAVE.", packageFiles[i] ); |
|
940 User::Leave(KErrNotSupported); |
|
941 } |
|
942 } |
|
943 CleanupStack::PopAndDestroy(name); |
|
944 } |
|
945 } |
|
946 } |
|
947 CleanupStack::PopAndDestroy(extn); |
|
948 } |
|
949 |
|
950 packageFiles.ResetAndDestroy(); |
|
951 packageFiles.Close(); |
|
952 |
|
953 if(KBootstrapVersion != 3) |
|
954 { |
|
955 User::LeaveIfNull(iSisFileName); |
|
956 if (!(ConeUtils::FileExists(*iSisFileName))) |
|
957 { |
|
958 User::Leave(KErrNotFound); |
|
959 } |
|
960 } |
|
961 if(KBootstrapVersion != 4) |
|
962 { |
|
963 User::LeaveIfNull(iDepFilename); |
|
964 } |
|
965 |
|
966 CleanupStack::PopAndDestroy(&entry); |
|
967 CleanupStack::PopAndDestroy(®istrySession); |
|
968 |
|
969 LOG( "- SetFileNameInfoL()" ); |
|
970 } |
|
971 |
|
972 TInt CBootstrapAppUi::LaunchAdmL() |
|
973 { |
|
974 LOG( "+ LaunchAdmL()" ); |
|
975 |
|
976 // In case of approach 3 , cleanup of only BootStrap |
|
977 // is required. |
|
978 if (KBootstrapVersion == 3) |
|
979 { |
|
980 iWrapperPackageUid = KUidBootstrapApp.iUid; |
|
981 } |
|
982 |
|
983 #ifdef __USE_RAPA |
|
984 HBufC *processArgs = HBufC::NewLC(iDepFilename->Length() + iSisFileName->Length() + 10 + 3 + 2); |
|
985 TPtr cmdLineParams = processArgs->Des(); |
|
986 cmdLineParams.Append(iDepFilename->Des()); |
|
987 cmdLineParams.Append(' '); |
|
988 cmdLineParams.Append(iSisFileName->Des()); |
|
989 cmdLineParams.Append(' '); |
|
990 cmdLineParams.AppendNum(iWrapperPackageUid); |
|
991 cmdLineParams.Append(' '); |
|
992 cmdLineParams.AppendNum(iIAP); |
|
993 HBufC *tmp = HBufC::NewLC( cmdLineParams.Length() ); |
|
994 tmp->Des().Copy( cmdLineParams ); |
|
995 LOG2( "cmdLineParams '%S'", tmp ); |
|
996 CleanupStack::PopAndDestroy(tmp); |
|
997 TApaAppInfo appInfo; |
|
998 RProcess process; |
|
999 RApaLsSession appArcSession; |
|
1000 User::LeaveIfError( appArcSession.Connect() ); |
|
1001 LOG("RApaLsSession.Connect() OK"); |
|
1002 CleanupClosePushL<RProcess>( process ); |
|
1003 CleanupClosePushL<RApaLsSession>( appArcSession ); |
|
1004 User::LeaveIfError( appArcSession.GetAppInfo( appInfo, KUidAdm ) ); |
|
1005 LOG("RApaLsSession.GetAppInfo() OK"); |
|
1006 TFileName appName = appInfo.iFullName; |
|
1007 LOG2("RApaLsSession: iFullName='%S'", &appName); |
|
1008 User::LeaveIfError( process.Create( appName, processArgs->Des() ) ); |
|
1009 HBufC8 *tail = HBufC8::NewLC( processArgs->Length() ); |
|
1010 tail->Des().Copy(processArgs->Des()); |
|
1011 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
1012 cmdLine->SetExecutableNameL( appName ); |
|
1013 cmdLine->SetCommandL( EApaCommandBackground ); |
|
1014 cmdLine->SetTailEndL( tail->Des() ); |
|
1015 cmdLine->SetProcessEnvironmentL( process ); |
|
1016 LOG("RApaLsSession: going to launch"); |
|
1017 User::LeaveIfError( appArcSession.StartApp( *cmdLine ) ); |
|
1018 process.Resume(); |
|
1019 CleanupStack::PopAndDestroy( cmdLine ); |
|
1020 CleanupStack::PopAndDestroy( tail ); |
|
1021 CleanupStack::PopAndDestroy( &appArcSession ); |
|
1022 CleanupStack::PopAndDestroy( &process ); |
|
1023 CleanupStack::PopAndDestroy( processArgs ); |
|
1024 LOG("launch OK"); |
|
1025 #else |
|
1026 // Create ADM command line: |
|
1027 // adm.exe dependency_filename sis_filename uid_in_dec |
|
1028 // |
|
1029 // Size of 32-bit Bootstrap Version Value is 10 characters |
|
1030 // Size of 32-bit UID when converted to numeric string is 10 characters (4294967295) |
|
1031 // Max size of iIAP(TInt) when converted to numeric string is 10 characters |
|
1032 // Size of 2 spaces is 2 characters |
|
1033 const TInt mandatoryOptionsLength = 10+ 10+ 10+ 2; |
|
1034 TBufC<mandatoryOptionsLength> mandatoryOptions; |
|
1035 TPtr mandatoryOptionsPtr = mandatoryOptions.Des(); |
|
1036 |
|
1037 mandatoryOptionsPtr.AppendNum(KBootstrapVersion); |
|
1038 mandatoryOptionsPtr.Append(' '); |
|
1039 mandatoryOptionsPtr.AppendNum(iWrapperPackageUid); |
|
1040 mandatoryOptionsPtr.Append(' '); |
|
1041 mandatoryOptionsPtr.AppendNum(iIAP); |
|
1042 |
|
1043 HBufC *processArgs = NULL; |
|
1044 |
|
1045 switch (KBootstrapVersion) |
|
1046 { |
|
1047 case 1: |
|
1048 case 2: |
|
1049 { |
|
1050 User::LeaveIfNull(iSisFileName); |
|
1051 User::LeaveIfNull(iDepFilename); |
|
1052 // Size of 2 spaces is 2 characters |
|
1053 processArgs = HBufC::NewLC( |
|
1054 mandatoryOptionsLength + |
|
1055 iDepFilename->Length() + |
|
1056 iSisFileName->Length() + |
|
1057 2); |
|
1058 TPtr cmdLine = processArgs->Des(); |
|
1059 cmdLine.Append(mandatoryOptionsPtr); |
|
1060 cmdLine.Append(' '); |
|
1061 cmdLine.Append(*iDepFilename); |
|
1062 cmdLine.Append(' '); |
|
1063 cmdLine.Append(*iSisFileName); |
|
1064 break; |
|
1065 } |
|
1066 case 3: |
|
1067 { |
|
1068 User::LeaveIfNull(iDepFilename); |
|
1069 // Size of 1 spaces is 1 characters |
|
1070 processArgs = HBufC::NewLC( |
|
1071 mandatoryOptionsLength + |
|
1072 iDepFilename->Length() + |
|
1073 1); |
|
1074 TPtr cmdLine = processArgs->Des(); |
|
1075 cmdLine.Append(mandatoryOptionsPtr); |
|
1076 cmdLine.Append(' '); |
|
1077 cmdLine.Append(*iDepFilename); |
|
1078 break; |
|
1079 } |
|
1080 case 4: |
|
1081 { |
|
1082 User::LeaveIfNull(iSisFileName); |
|
1083 // Size of 1 spaces is 1 characters |
|
1084 processArgs = HBufC::NewLC( |
|
1085 mandatoryOptionsLength + |
|
1086 iSisFileName->Length() + |
|
1087 1); |
|
1088 TPtr cmdLine = processArgs->Des(); |
|
1089 cmdLine.Append(mandatoryOptionsPtr); |
|
1090 cmdLine.Append(' '); |
|
1091 cmdLine.Append(*iSisFileName); |
|
1092 break; |
|
1093 } |
|
1094 default: |
|
1095 // Unsupported Bootstrap Version |
|
1096 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
1097 break; |
|
1098 } |
|
1099 |
|
1100 // Launch ADM |
|
1101 LOG3( "Launching %S '%S'", &KAdmExePath, processArgs); |
|
1102 |
|
1103 RProcess process; |
|
1104 CleanupClosePushL<RProcess>( process ); |
|
1105 |
|
1106 const TInt err = process.Create( KAdmExePath, processArgs->Des() ); |
|
1107 if (err != KErrNone) |
|
1108 { |
|
1109 LOG2( "ADM launch failed with error: %d", err ); |
|
1110 CleanupStack::PopAndDestroy( &process ); |
|
1111 CleanupStack::PopAndDestroy( processArgs ); |
|
1112 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
1113 } |
|
1114 |
|
1115 process.SetPriority( EPriorityBackground ); |
|
1116 process.Resume(); |
|
1117 #if 0 |
|
1118 const TInt type = process.ExitType(); |
|
1119 const TInt reason = process.ExitReason(); |
|
1120 TExitCategoryName cat = process.ExitCategory(); |
|
1121 LOG4( "Exit type %d, reason %d, cat '%S'", type, reason, &cat); |
|
1122 #endif |
|
1123 CleanupStack::PopAndDestroy( &process ); |
|
1124 CleanupStack::PopAndDestroy( processArgs ); |
|
1125 |
|
1126 #endif // if __USE_RAPA |
|
1127 LOG2( "- LaunchAdmL(): %d", err ); |
|
1128 return KErrNone; |
|
1129 } |
|
1130 |
|
1131 void CBootstrapAppUi::AsyncInstallPackageL(const TDesC& aResponseFilename) |
|
1132 { |
|
1133 SwiUI::TInstallOptions Options; |
|
1134 |
|
1135 Options.iUpgrade = SwiUI::EPolicyAllowed; |
|
1136 Options.iOCSP = SwiUI::EPolicyNotAllowed; |
|
1137 Options.iDrive = 'c'; |
|
1138 Options.iUntrusted = SwiUI::EPolicyNotAllowed; |
|
1139 Options.iCapabilities = SwiUI::EPolicyNotAllowed; |
|
1140 Options.iOverwrite = SwiUI::EPolicyAllowed; |
|
1141 |
|
1142 iOptionsPckg = Options; |
|
1143 |
|
1144 if (iInstallObsrv == NULL) |
|
1145 { |
|
1146 iInstallObsrv = new (ELeave) CInstallObserver(this); |
|
1147 } |
|
1148 iInstallObsrv->iStatus = KRequestPending; |
|
1149 iInstallObsrv->Start(); |
|
1150 // Start asynchronous installation |
|
1151 iLauncher.SilentInstall(iInstallObsrv->iStatus, aResponseFilename, iOptionsPckg); |
|
1152 } |
|
1153 |
|
1154 void CBootstrapAppUi::HandleInstallCompleteL(const TInt& aStatus) |
|
1155 { |
|
1156 LOG2("+ HandleInstallCompleteL(%d)", aStatus); |
|
1157 User::LeaveIfNull(iDownloadFileName); |
|
1158 |
|
1159 // If the install server is busy , try connecting multiple times. |
|
1160 if (aStatus == SwiUI::KSWInstErrBusy && ((++iInstallAttempt) <= KMaxInstallerConnectionAttempts)) |
|
1161 { |
|
1162 LOG2( "Retrying installation %d", aStatus ); |
|
1163 AsyncInstallPackageL(*iDownloadFileName); |
|
1164 } |
|
1165 else |
|
1166 { |
|
1167 LOG2("ADM installation status: %d", aStatus); |
|
1168 |
|
1169 LOG("Deleting ADM sis file"); |
|
1170 // Delete no longer required sis file. |
|
1171 DeleteFile(*iDownloadFileName); |
|
1172 |
|
1173 if (aStatus == KErrNone || iIsAdmInstalled) |
|
1174 { |
|
1175 iAppState = EADMLaunchState; |
|
1176 TRAPD( err, LaunchAdmL() ); |
|
1177 if ( err != KErrNone ) |
|
1178 { |
|
1179 LOG2( "ADM launch failed %d", err ); |
|
1180 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
1181 } |
|
1182 LOG2( "ADM launched OK %d", err ); |
|
1183 TRAP_IGNORE( StopGlobalWaitNoteL() ); |
|
1184 CloseApp(); |
|
1185 } |
|
1186 else |
|
1187 { |
|
1188 ExitWithError(R_INSTALLATION_FAILURE_ERR); |
|
1189 } |
|
1190 } |
|
1191 LOG("- HandleInstallCompleteL()"); |
|
1192 } |
|
1193 |
|
1194 TBool CBootstrapAppUi::IsPackagePresentL(const TUid& aUid, TVersion& aVersion) |
|
1195 { |
|
1196 LOG( "+ ADMPresent()"); |
|
1197 |
|
1198 // Connect to SisRegistry to find if the package is |
|
1199 // already installed. |
|
1200 Swi::RSisRegistrySession registrySession; |
|
1201 |
|
1202 User::LeaveIfError(registrySession.Connect()); |
|
1203 CleanupClosePushL(registrySession); |
|
1204 |
|
1205 const TBool isPkgInstalled = registrySession.IsInstalledL(aUid); |
|
1206 |
|
1207 if (isPkgInstalled) |
|
1208 { |
|
1209 Swi::RSisRegistryEntry entry; |
|
1210 |
|
1211 // Open registry entry |
|
1212 User::LeaveIfError(entry.Open(registrySession, aUid)); |
|
1213 CleanupClosePushL(entry); |
|
1214 aVersion = entry.VersionL(); |
|
1215 |
|
1216 CleanupStack::PopAndDestroy(&entry); |
|
1217 } |
|
1218 |
|
1219 CleanupStack::PopAndDestroy(®istrySession); |
|
1220 |
|
1221 LOG3( "- ADMPresent(): 0x%x = %d", aUid.iUid, isPkgInstalled ); |
|
1222 |
|
1223 return isPkgInstalled; |
|
1224 } |
|
1225 |
|
1226 void CBootstrapAppUi::DeleteFile(const TDesC& aFileName) |
|
1227 { |
|
1228 CCoeEnv::Static()->FsSession().Delete(aFileName); |
|
1229 } |
|
1230 |
|
1231 void CBootstrapAppUi::ShowNoteL( const TAknGlobalNoteType& aType , const TInt& aResourceId ) |
|
1232 { |
|
1233 // Allocate TBuf with constant length. |
|
1234 TBuf<KMaxMsgSize> text; |
|
1235 |
|
1236 // Reads a resource into a descriptor. |
|
1237 CEikonEnv::Static()->ReadResource( text, aResourceId ); |
|
1238 |
|
1239 // Create new CAknGlobalNote instance. |
|
1240 CAknGlobalNote* globalNote = CAknGlobalNote::NewLC(); |
|
1241 globalNote->ShowNoteL( aType , text ); |
|
1242 CleanupStack::PopAndDestroy(globalNote); |
|
1243 } |
|
1244 |
|
1245 void CBootstrapAppUi::ExitWithError(const TInt& aResourceId ) |
|
1246 { |
|
1247 LOG2( "+ ExitWithError(): 0x%08x", aResourceId ); |
|
1248 |
|
1249 // Display error message |
|
1250 TRAP_IGNORE( |
|
1251 StopGlobalWaitNoteL(); |
|
1252 ShowNoteL(EAknGlobalErrorNote, aResourceId); |
|
1253 ); |
|
1254 |
|
1255 // Delete the dep file is present |
|
1256 if((KBootstrapVersion == 3)&&(iDepFilename)) |
|
1257 { |
|
1258 DeleteFile(*iDepFilename); |
|
1259 } |
|
1260 else if((KBootstrapVersion == 4)&&(iSisFileName)) |
|
1261 { |
|
1262 DeleteFile(*iSisFileName); |
|
1263 } |
|
1264 |
|
1265 RunAppShutter(); |
|
1266 Exit(); |
|
1267 |
|
1268 LOG( "- ExitWithError()" ); |
|
1269 } |
|
1270 |
|
1271 void CBootstrapAppUi::CloseApp() |
|
1272 { |
|
1273 LOG( "+ CloseApp()" ); |
|
1274 |
|
1275 RunAppShutter(); |
|
1276 Exit(); |
|
1277 |
|
1278 LOG( "- CloseApp()" ); |
|
1279 } |
|
1280 |
|
1281 void CBootstrapAppUi::HandleForegroundEventL(TBool aForeground) |
|
1282 { |
|
1283 LOG3("+ CBootstrapAppUi::HandleForegroundEventL(%d): allow=%d", aForeground, iAllowForeground); |
|
1284 CAknAppUi::HandleForegroundEventL(aForeground); |
|
1285 if (aForeground && !iAllowForeground) |
|
1286 { |
|
1287 SendToBackgroundL(); |
|
1288 } |
|
1289 LOG("- CBootstrapAppUi::HandleForegroundEventL()" ); |
|
1290 } |
|
1291 |
|
1292 // --------------------------------------------------------------------------- |
|
1293 // |
|
1294 // --------------------------------------------------------------------------- |
|
1295 void CBootstrapAppUi::SendToBackgroundL(TBool aBackground) |
|
1296 { |
|
1297 LOG2( "+ SendToBackgroundL(%d)", aBackground ); |
|
1298 // We have gained the focus |
|
1299 RWsSession aWsSession; |
|
1300 User::LeaveIfError( aWsSession.Connect() ); |
|
1301 TApaTask task(aWsSession); |
|
1302 |
|
1303 // Initialise the object with the window group id of |
|
1304 // our application (so that it represent our app) |
|
1305 task.SetWgId(CEikonEnv::Static()->RootWin().Identifier()); |
|
1306 if (aBackground) |
|
1307 { |
|
1308 task.SendToBackground(); |
|
1309 } |
|
1310 else |
|
1311 { |
|
1312 task.BringToForeground(); |
|
1313 } |
|
1314 aWsSession.Close(); |
|
1315 LOG( "- SendToBackgroundL() "); |
|
1316 } |
|
1317 |
|
1318 void CBootstrapAppUi::HandleCommandL(TInt aCommand) |
|
1319 { |
|
1320 switch (aCommand) |
|
1321 { |
|
1322 case EEikCmdExit: |
|
1323 case EAknSoftkeyExit: |
|
1324 Exit(); |
|
1325 break; |
|
1326 |
|
1327 default: |
|
1328 break; |
|
1329 } |
|
1330 } |
|
1331 |
|
1332 // --------------------------------------------------------------------------- |
|
1333 // CBootstrapAppUi::ReadConfigurationL |
|
1334 // Leaves if runs out of memory |
|
1335 // |
|
1336 // @return KErrNone if configuration was read correctly, error code otherwise |
|
1337 // --------------------------------------------------------------------------- |
|
1338 // |
|
1339 TInt CBootstrapAppUi::ReadConfigurationL() |
|
1340 { |
|
1341 TFileName configFile; |
|
1342 RArray< TPtrC > lineBuffer; |
|
1343 TInt ret( KErrNone ); |
|
1344 RFs& rfs = CEikonEnv::Static()->FsSession(); |
|
1345 |
|
1346 // Find the configuration file from the private directory |
|
1347 ret = rfs.PrivatePath(configFile); |
|
1348 if (ret == KErrNone) |
|
1349 { |
|
1350 TBuf<2> appDrive; |
|
1351 // Insert the drive of the running application |
|
1352 appDrive.Copy(Application()->AppFullName().Left(2)); |
|
1353 configFile.Insert(0, appDrive); |
|
1354 // Append the configuration file name |
|
1355 configFile.Append(KConfigFile); |
|
1356 |
|
1357 LOG2( "configFile = %S", &configFile ); |
|
1358 |
|
1359 HBufC* buffer = ReadConfigFile(rfs, configFile, lineBuffer, ret ); |
|
1360 |
|
1361 if ( buffer && ret == KErrNone ) |
|
1362 { |
|
1363 // Get Url from the config file |
|
1364 TPtrC urlLine = GetConfigValue( KCfgTagUrl, lineBuffer, ret ); |
|
1365 if ( ret == KErrNone ) |
|
1366 { |
|
1367 iConfigUrl = HBufC8::NewL(urlLine.Length()); |
|
1368 iConfigUrl->Des().Copy(urlLine); |
|
1369 LOG8_2( "configUrl = %S", iConfigUrl ); |
|
1370 } |
|
1371 delete buffer; |
|
1372 } |
|
1373 } |
|
1374 if ( !iConfigUrl ) |
|
1375 { |
|
1376 // Error occured while reading the configuration, use default URL |
|
1377 iConfigUrl = HBufC8::NewL(KDefaultDepServerUrl().Length()); |
|
1378 *iConfigUrl = KDefaultDepServerUrl; |
|
1379 LOG8_2( "configUrl = %S (default)", iConfigUrl ); |
|
1380 } |
|
1381 |
|
1382 lineBuffer.Close(); |
|
1383 |
|
1384 return ret; |
|
1385 } |