1 /* |
|
2 * Copyright (c) 2005 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: downloads upd pkg |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
22 #include <es_enum_internal.h> |
|
23 #endif |
|
24 #include <centralrepository.h> |
|
25 #include <f32file.h> |
|
26 #include <AknWaitDialog.h> |
|
27 #include <fotaserver.rsg> |
|
28 #include <eikprogi.h> |
|
29 #include <eikenv.h> |
|
30 #include <apgtask.h> |
|
31 #include <apgwgnam.h> |
|
32 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
33 #include <es_sock.h> |
|
34 #else |
|
35 #include <es_sock.h> |
|
36 #include <es_sock_partner.h> |
|
37 #endif |
|
38 #include <es_enum.h> |
|
39 //Commented for resolving APP dependencyy |
|
40 //#include <nsmldmsync.rsg> //OMA DM UI for reading resource |
|
41 //Comment ends here |
|
42 #include <bautils.h> |
|
43 #include <StringLoader.h> |
|
44 #include <DevManInternalCRKeys.h> //for reading san feature |
|
45 #include <e32property.h> |
|
46 #include "fotastorage.h" |
|
47 #include "FotaSrvApp.h" |
|
48 #include "fotadownload.h" |
|
49 #include "fotaserverPrivatePSKeys.h" |
|
50 #include "FotaNetworkRegStatus.h" |
|
51 #include <startupdomainpskeys.h> //globalrfsstates |
|
52 #define __LEAVE_IF_ERROR(x) if(KErrNone!=x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); } |
|
53 #define __LEAVE(x) {FLOG(_L("LEAVE in %s: %d"), __FILE__, __LINE__); User::Leave(x); } |
|
54 |
|
55 |
|
56 // -------------------------------------------------------------------------- |
|
57 // CFotaDownload::NewL |
|
58 // -------------------------------------------------------------------------- |
|
59 CFotaDownload* CFotaDownload::NewL (CFotaServer* aServer) |
|
60 { |
|
61 __ASSERT_ALWAYS( aServer, User::Panic(KFotaPanic, KErrArgument) ); |
|
62 CFotaDownload* ao = new (ELeave) CFotaDownload(); |
|
63 ao->iFotaServer = aServer; |
|
64 return ao; |
|
65 } |
|
66 |
|
67 |
|
68 // -------------------------------------------------------------------------- |
|
69 // CFotaDownload::RunL |
|
70 // Do operations started in HandleDmgrEvent |
|
71 // -------------------------------------------------------------------------- |
|
72 void CFotaDownload::RunL() |
|
73 { |
|
74 FLOG(_L( "[FotaServer] CFotaDownload::RunL() >>")); |
|
75 CancelDownload( ETrue ); |
|
76 CreateDownloadL(); |
|
77 FLOG(_L( "[FotaServer] CFotaDownload::RunL() <<" ) ); |
|
78 } |
|
79 |
|
80 |
|
81 // -------------------------------------------------------------------------- |
|
82 // CFotaDownload::DoCancel() |
|
83 // Cancel notifier request |
|
84 // -------------------------------------------------------------------------- |
|
85 // |
|
86 void CFotaDownload::DoCancel() |
|
87 { |
|
88 FLOG(_L("CFotaDownload::DoCancel() >>")); |
|
89 FLOG(_L("CFotaDownload::DoCancel() <<")); |
|
90 } |
|
91 |
|
92 |
|
93 // -------------------------------------------------------------------------- |
|
94 // CFotaDownload::RunError(TInt aError) |
|
95 // Handle active object run error. |
|
96 // -------------------------------------------------------------------------- |
|
97 // |
|
98 TInt CFotaDownload::RunError(TInt aError) |
|
99 { |
|
100 if(aError) |
|
101 { |
|
102 FLOG(_L(" CFotaDownload::RunError err %d"), aError ); |
|
103 } |
|
104 return aError; |
|
105 } |
|
106 |
|
107 |
|
108 // -------------------------------------------------------------------------- |
|
109 // CFotaDownload::CFotaDownload() |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 CFotaDownload::CFotaDownload() : CActive(EPriorityNormal) |
|
113 , iUpdateAfterDownload (EFalse), iUrl( NULL ), |
|
114 iDownload (NULL), |
|
115 iDownloadedContentSize(0), |
|
116 iPreviousContentSize ( 0 ), iShowOMACDUI(EFalse), iShowDLPrgUI(EFalse), |
|
117 iDownloadResumable (EFalse), |
|
118 iFMSEnabled (EFalse), |
|
119 iDownloadActive (EFalse), |
|
120 iFreshDL(ETrue), |
|
121 iUserInitiatedResume(EFalse), |
|
122 iSanValue(KErrNotFound), |
|
123 iDownloadFinalized(EFalse) |
|
124 { |
|
125 CActiveScheduler::Add( this ); |
|
126 FLOG(_L("CFotaDownload::CFotaDownload()")); |
|
127 } |
|
128 |
|
129 |
|
130 // -------------------------------------------------------------------------- |
|
131 // CFotaDownload::~CFotaDownload() |
|
132 // -------------------------------------------------------------------------- |
|
133 // |
|
134 CFotaDownload::~CFotaDownload() |
|
135 { |
|
136 FLOG(_L("CFotaDownload::~CFotaDownload() >>")); |
|
137 Cancel(); |
|
138 |
|
139 //Sets download state inactive if accidently closed. This is anyhow taken care in FinalizeDownload in Server. |
|
140 SetDownloadActive(EFalse); |
|
141 CancelDownload( ETrue ); |
|
142 if ( iUrl ) |
|
143 { |
|
144 delete iUrl; iUrl=NULL; |
|
145 } |
|
146 /* if ( iNotifHandler ) Deleted at server |
|
147 { |
|
148 iNotifHandler->Cancel(); |
|
149 delete iNotifHandler; |
|
150 }*/ |
|
151 if ( iDLProgressDlg ) |
|
152 { |
|
153 delete iDLProgressDlg; iDLProgressDlg=NULL; |
|
154 } |
|
155 |
|
156 if (iDownloadMgr.Handle()) |
|
157 iDownloadMgr.Close(); |
|
158 //don't delete iFotaServer as it doesn't belong here. |
|
159 |
|
160 FLOG(_L("CFotaDownload::~CFotaDownload() <<")); |
|
161 } |
|
162 |
|
163 |
|
164 // -------------------------------------------------------------------------- |
|
165 // CFotaDownload::CancelDownload |
|
166 // Cancel download |
|
167 // -------------------------------------------------------------------------- |
|
168 // |
|
169 void CFotaDownload::CancelDownload( const TBool aCancelProgressBar ) |
|
170 { |
|
171 FLOG(_L("CFotaDownload::CancelDownload() >>")); |
|
172 |
|
173 if( iDownloadMgr.Handle() ) |
|
174 { |
|
175 iDownloadMgr.Close(); |
|
176 } |
|
177 |
|
178 if ( aCancelProgressBar && iDLProgressDlg ) |
|
179 { |
|
180 TRAPD(err, iDLProgressDlg->ProcessFinishedL() ) ;// deletes |
|
181 if(err); // remove compiler warning |
|
182 delete iDLProgressDlg; |
|
183 iDLProgressDlg = NULL; |
|
184 } |
|
185 FLOG(_L("CFotaDownload::CancelDownload() <<")); |
|
186 } |
|
187 |
|
188 // -------------------------------------------------------------------------- |
|
189 // CFotaDownload::CreateDownloadL |
|
190 // Create download |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 void CFotaDownload::CreateDownloadL() |
|
194 { |
|
195 FLOG(_L("CFotaDownload::CreateDownloadL() >>") ); |
|
196 __ASSERT_ALWAYS( iDownloadMgr.Handle()==0, User::Leave(KErrAlreadyExists) ); |
|
197 RHttpDownload* d(NULL); |
|
198 iDLNeedsReset = EFalse; |
|
199 TBool created; |
|
200 iDownloadMgr.ConnectL( TUid::Uid(KFotaServerUid) , *this, EFalse); |
|
201 FLOG(_L("CFotaDownload::CreateDownloadL, Stage 1") ); |
|
202 iDownloadMgr.DeleteAll(); |
|
203 |
|
204 TRAPD(err, d = &iDownloadMgr.CreateDownloadL( *iUrl, created ) ); |
|
205 RFs fs; |
|
206 if(fs.Connect() == KErrNone) |
|
207 { |
|
208 RFile file; |
|
209 CleanupClosePushL( fs ); |
|
210 CleanupClosePushL( file ); |
|
211 err=fs.MkDir(KDDDirPath); |
|
212 FLOG(_L("creating directory err as %d"),err); |
|
213 err=fs.SetSessionPath(KDDDirPath); |
|
214 FLOG(_L("setting session path err as %d"),err); |
|
215 err=fs.ShareProtected(); |
|
216 FLOG(_L("ShareProtected err as %d"),err); |
|
217 err = file.Replace(fs,KDDFilename, EFileWrite|EFileShareAny); |
|
218 FLOG(_L("creating rfile err as %d"),err); |
|
219 err = d->SetFileHandleAttribute(file); |
|
220 FLOG(_L("setting dlmgr destfile attrib err as %d"),err); |
|
221 CleanupStack::PopAndDestroy( &file ); |
|
222 CleanupStack::PopAndDestroy( &fs ); |
|
223 } |
|
224 FLOG(_L("CFotaDownload::CreateDownloadL, Stage 2. err %d"),err); |
|
225 if ( err == KErrArgument ) User::Leave( KErrNotFound ); |
|
226 else if( err !=KErrNone) User::Leave( err ); |
|
227 |
|
228 if ( iDLState.iIapId > KErrNotFound ) |
|
229 { |
|
230 FLOG(_L(" Using internet access point iapid: %d"), iDLState.iIapId); |
|
231 err = iDownloadMgr.SetIntAttribute( EDlMgrIap, iDLState.iIapId); // IAP id |
|
232 User::LeaveIfError( err ); |
|
233 //At this point the iIapId used in the SyncML Session is presumed working. Hence |
|
234 //the same is stored in database for use during download. |
|
235 FLOG(_L("Setting IAPID=%d is FotaState"),iDLState.iIapId); |
|
236 iFotaServer->iDatabase->OpenDBL(); |
|
237 iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBIapId ); |
|
238 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
239 } |
|
240 FLOG(_L("CFotaDownload::CreateDownloadL, Stage 3") ); |
|
241 User::LeaveIfError( d->SetIntAttribute(EDlAttrFotaPckgId ,iDLState.iPkgId) ); |
|
242 FLOG(_L("CFotaDownload::CreateDownloadL, Stage 4") ); |
|
243 User::LeaveIfError( d->SetBoolAttribute(EDlAttrNoContentTypeCheck,ETrue) ); |
|
244 |
|
245 // If ui hidden or download restarting, do not show descriptor |
|
246 if ( !iShowOMACDUI || iRestartCounter > 0 ) |
|
247 { |
|
248 FLOG(_L("setting DD to hidden")); |
|
249 User::LeaveIfError(iDownloadMgr.SetBoolAttribute( EDlMgrSilentMode,ETrue )) ; |
|
250 } |
|
251 //It's a fresh download |
|
252 iFreshDL = ETrue; |
|
253 |
|
254 // Start download |
|
255 User::LeaveIfError(iDownloadMgr.StartAll()); |
|
256 FLOG(_L("CFotaDownload::CreateDownloadL, Stage 5") ); |
|
257 iDLProgress = EStarted; |
|
258 |
|
259 //This P&S Key is used to notify DM UI on any download event. key=0 for idle and key=1 for download |
|
260 err = RProperty::Set( TUid::Uid(KOmaDMAppUid), |
|
261 KFotaDMRefresh, |
|
262 ETrue ); |
|
263 FLOG(_L("RProperty KFotaDMRefresh Set Etrue, err = %d"), err); |
|
264 |
|
265 SetDownloadActive(ETrue); |
|
266 |
|
267 User::LeaveIfError(err); |
|
268 FLOG(_L("[FotaServer] CFotaDownload::CreateDownloadL <<")); |
|
269 } |
|
270 |
|
271 // -------------------------------------------------------------------------- |
|
272 // CFotaDownload::DownloadL |
|
273 // Start download of swupd package. |
|
274 // -------------------------------------------------------------------------- |
|
275 // |
|
276 void CFotaDownload::DownloadL(TDownloadIPCParams aParams,const TDesC8& aPkgURL |
|
277 ,TBool aUpdateAfterDownload,const TInt aIapid,const TInt aRestartDownload) |
|
278 { |
|
279 FLOG(_L("[FotaServer] CFotaDownload::DownloadL >> restart %d"),aRestartDownload); |
|
280 |
|
281 TInt err = RProperty::Define( TUid::Uid(KOmaDMAppUid), |
|
282 KFotaDMRefresh, |
|
283 RProperty::EInt,KReadPolicy,KWritePolicy); |
|
284 FLOG(_L("RProperty KFotaDMRefresh Define, err = %d"), err); |
|
285 if (err != KErrAlreadyExists ) |
|
286 { |
|
287 User::LeaveIfError(err); |
|
288 |
|
289 err = RProperty::Set( TUid::Uid(KOmaDMAppUid), |
|
290 KFotaDMRefresh, |
|
291 KErrNotFound ); |
|
292 |
|
293 FLOG(_L("RProperty KFotaDMRefresh Set KErrNotFound, err = %d"), err); |
|
294 User::LeaveIfError(err); |
|
295 } |
|
296 |
|
297 if ( iUrl ) {delete iUrl; iUrl=NULL;} |
|
298 iUrl = aPkgURL.Alloc(); |
|
299 iUpdateAfterDownload = aUpdateAfterDownload; |
|
300 iRestartCounter = aRestartDownload; |
|
301 |
|
302 iDLState = aParams; |
|
303 FLOG(_L("CFotaDownload::DownloadL, Stage 1") ); |
|
304 |
|
305 // Set state ------------------------------------------------------------- |
|
306 iDLState.iState = RFotaEngineSession::EStartingDownload; |
|
307 |
|
308 iDLState.iResult = KErrNotFound; |
|
309 iDLState.iUpdateLtr = aUpdateAfterDownload; |
|
310 iFotaServer->iDatabase->OpenDBL(); |
|
311 iFotaServer->iDatabase->SetStateL( iDLState, *iUrl,EFDBState|EFDBResult |
|
312 | EFDBProfileId|EFDBPkgUrl|EFDBPkgName|EFDBVersion|EFDBUpdateLtr); |
|
313 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
314 FLOG(_L("CFotaDownload::DownloadL, Stage 2, pkgid:%d"),iDLState.iPkgId); |
|
315 |
|
316 // 2. Get Iap Id to use for download. This would be set in iDLState.iIapId. |
|
317 SetIapToUseL(aParams, aIapid); |
|
318 |
|
319 // 3. Determine whether download should be visible or not |
|
320 // Autoaccepted profile? |
|
321 |
|
322 SetDownloadUiBehavior(ETrue); |
|
323 |
|
324 CancelDownload( ETrue ); |
|
325 |
|
326 FLOG(_L("Setting SessionType=%d in FotaState"),iDLState.iSessionType); |
|
327 iFotaServer->iDatabase->OpenDBL(); |
|
328 iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBSessionType ); |
|
329 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
330 FLOG(_L("CFotaDownload::DownloadL, Stage 3") ); |
|
331 //Called to read the download variations in Fota (resume support & FMS) |
|
332 CheckDownloadVariations(); |
|
333 |
|
334 //Create the download |
|
335 CreateDownloadL( ); |
|
336 FLOG(_L("[FotaServer] CFotaDownload::DownloadL <<")); |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 // CFotaDownload::HandleDLProgressDialogExitL |
|
341 // Handle canceling of download |
|
342 // --------------------------------------------------------------------------- |
|
343 TBool CFotaDownload::HandleDLProgressDialogExitL( TInt aButtonId ) |
|
344 { |
|
345 FLOG(_L("CFotaDownload::HandleDLProgressDialogExitL %d, note = %d >>"),aButtonId, iDLProgressDlg->iNoteType); |
|
346 // Cancel clicked during download |
|
347 if ( aButtonId == KErrNotFound ) |
|
348 { |
|
349 iRestartCounter = -1; |
|
350 FLOG(_L("[FotaServer] CFotaDownload::HandleDLProgressDialogExitL Hiding UI")); |
|
351 iFotaServer->iParentApp->SetUIVisibleL ( EFalse, ETrue ); |
|
352 iUpdateAfterDownload = EFalse; |
|
353 |
|
354 iDLState.iResult = RFotaEngineSession::EResUserCancelled; |
|
355 |
|
356 if (iDLProgressDlg->iNoteType == EConnectingNote) |
|
357 { |
|
358 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
359 |
|
360 TInt active (KErrNotFound); |
|
361 RProperty::Get( TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, active ); |
|
362 FLOG(_L("active = %d"),active); |
|
363 |
|
364 if (active) //Resume operation has just begun and download request is submitted to dlmgr. Hence need to suspend. |
|
365 { |
|
366 RunDownloadSuspendL(RFotaEngineSession::EResUserCancelled, ETrue); |
|
367 } |
|
368 else //Resume operation has just begun, but download request is not submitted to dlmgr |
|
369 { |
|
370 LaunchNotifierL( ESyncMLFwUpdOmaDLPostponed, EFalse, EFalse ); |
|
371 iFotaServer->FinalizeDownloadL( iDLState ); |
|
372 } |
|
373 } |
|
374 else if (iDLProgressDlg->iNoteType == EDownloadingNote) |
|
375 { |
|
376 if (iDownloadResumable) |
|
377 { |
|
378 //Resume is supported. Query user whether to postpone or cancel download. |
|
379 FLOG(_L("User pressed cancel. Resume is supported; hence pause download and query user if download has to be postponed or cancelled permanently.")); |
|
380 RunDownloadSuspendL(RFotaEngineSession::EResUserCancelled); |
|
381 } |
|
382 else |
|
383 { |
|
384 //Resume is not supported. Download is cancelled |
|
385 FLOG(_L("User pressed cancel. Resume is not supported & hence download has to be cancelled")); |
|
386 RunDownloadCancelL(RFotaEngineSession::EResUserCancelled); |
|
387 } |
|
388 } |
|
389 } |
|
390 FLOG(_L("CFotaDownload::HandleDLProgressDialogExitL <<")); |
|
391 return ETrue; |
|
392 } |
|
393 |
|
394 |
|
395 // -------------------------------------------------------------------------- |
|
396 // CFotaDownload::DoHandleDMgrEventL |
|
397 // Handles download events. Updates package state accordingly |
|
398 // -------------------------------------------------------------------------- |
|
399 void CFotaDownload::DoHandleDMgrEventL( RHttpDownload* aDownload |
|
400 , THttpDownloadEvent aEvent ) |
|
401 { |
|
402 __ASSERT_ALWAYS( aDownload, User::Panic(KFotaPanic, KErrArgument) ); |
|
403 TInt32 sysErrorId( KErrNone ); |
|
404 TInt32 contentsize; |
|
405 TInt32 downloadedsize; |
|
406 |
|
407 TInt32 tmp; |
|
408 THttpDownloadMgrError dlErrorId; |
|
409 iDownload = aDownload; |
|
410 // If DL is in final state (complete/fail), there's an error id available. |
|
411 User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrGlobalErrorId |
|
412 ,sysErrorId ) ); |
|
413 User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrDownloadedSize |
|
414 ,downloadedsize ) ); |
|
415 User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrLength |
|
416 ,contentsize ) ); |
|
417 User::LeaveIfError( aDownload->GetIntAttribute( EDlAttrErrorId |
|
418 ,tmp ) ); |
|
419 dlErrorId = (THttpDownloadMgrError)tmp; |
|
420 |
|
421 |
|
422 // Update progress dlg progress |
|
423 if ( !iDLProgressDlg && iRestartCounter>0) |
|
424 { |
|
425 FLOG(_L("reshowing progress...")); |
|
426 iDLProgressDlg = new(ELeave) CFotaDLProgressDlg((CEikDialog** ) &iDLProgressDlg , EFalse, this, EDownloadingNote ); |
|
427 iDLProgressDlg->PrepareLC( R_FOTASERVER_DL_PROGRESS_DIALOG ); |
|
428 iDLProgressDlg->RunLD(); |
|
429 } |
|
430 if (iDLProgressDlg) |
|
431 { |
|
432 CEikProgressInfo* progressInfo = iDLProgressDlg->GetProgressInfoL(); |
|
433 __ASSERT_ALWAYS( progressInfo, User::Panic(KFotaPanic, KErrBadHandle) ); |
|
434 if ( iPreviousContentSize!=contentsize ) |
|
435 { |
|
436 iPreviousContentSize = contentsize; |
|
437 if ( contentsize > 0 ) |
|
438 { |
|
439 progressInfo->SetFinalValue( contentsize ); |
|
440 } |
|
441 } |
|
442 TInt incr = downloadedsize - iDownloadedContentSize; |
|
443 if (incr<=0) incr=0; //Protection |
|
444 progressInfo->IncrementAndDraw(incr); |
|
445 iDownloadedContentSize = downloadedsize; |
|
446 } |
|
447 FLOG(_L("CFotaDownload::HandleDMgrEventL() >> DLstate:%d ProgressSt:%d\ |
|
448 globErr: %d DLError: %d (%d/%d)"),aEvent.iDownloadState |
|
449 ,aEvent.iProgressState,sysErrorId,dlErrorId,downloadedsize,contentsize ); |
|
450 |
|
451 if ( sysErrorId <= -25000) { FLOG(_L(" error %d interpreted as http \ |
|
452 error %d") , sysErrorId, sysErrorId + 25000 ); } |
|
453 |
|
454 switch ( aEvent.iDownloadState ) |
|
455 { |
|
456 case EHttpDlCreated: // 1 |
|
457 { |
|
458 FLOG(_L("Download State: EHttpDlCreated")); |
|
459 } |
|
460 break; |
|
461 case EHttpDlInprogress: // 2 |
|
462 { |
|
463 FLOG(_L("Download State: EHttpDlProgress")); |
|
464 |
|
465 |
|
466 if (aEvent.iProgressState == EHttpProgCodDescriptorDownloaded) |
|
467 { |
|
468 if (iShowOMACDUI || iShowDLPrgUI) |
|
469 { |
|
470 iFotaServer->iParentApp->SetUIVisibleL ( ETrue, EFalse); |
|
471 } |
|
472 } |
|
473 |
|
474 // Is ECodLoadEnd optimized out? |
|
475 if ( aEvent.iProgressState == EHttpProgCodLoadEnd ) // 2503 |
|
476 { |
|
477 TInt err; |
|
478 err = aDownload->Start(); // PPAR-6FRHFY fixed |
|
479 if(err) |
|
480 { |
|
481 FLOG(_L(" ERROR when restarting DL %d"),err); |
|
482 User::Leave(err); |
|
483 } |
|
484 FLOG( _L(" DL restarted") ); |
|
485 } |
|
486 |
|
487 // Should tell user to free disk space. But how do we know that disk space is about be exceeded? |
|
488 |
|
489 if ( iDLNeedsReset ) |
|
490 { |
|
491 FLOG(_L("aDownload->Reset();")); |
|
492 iDLNeedsReset = EFalse; |
|
493 iStatus = KRequestPending; |
|
494 SetActive(); |
|
495 TRequestStatus* status = &iStatus; |
|
496 User::RequestComplete( status, KErrNone ); |
|
497 User::LeaveIfError( aDownload->Reset() ); |
|
498 } |
|
499 |
|
500 // Body data of descriptor or payload pkg |
|
501 if ( aEvent.iProgressState == EHttpProgResponseBodyReceived && iDLProgress==EDescriptorDownloaded/*2500*/) |
|
502 { |
|
503 // Now pkg size can be retrieved. must check size. |
|
504 iDLState.iPkgSize = contentsize; |
|
505 FLOG(_L("Setting PkgSize=%d in FotaState"),contentsize); |
|
506 iFotaServer->iDatabase->OpenDBL(); |
|
507 iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBPkgSize ); |
|
508 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
509 |
|
510 |
|
511 TInt contentsize2 = contentsize; |
|
512 |
|
513 TInt dlsize (KErrNone); |
|
514 TInt tlsize (KErrNone); |
|
515 |
|
516 TRAPD(err, iFotaServer->GetDownloadUpdatePackageSizeL(iDLState.iPkgId, dlsize,tlsize)); |
|
517 if(err); // remove compiler warning |
|
518 contentsize2 -= dlsize; |
|
519 FLOG(_L("check pkg size = %d"),contentsize2 ); |
|
520 |
|
521 CFotaStorage::TFreeSpace avail = iFotaServer->StoragePluginL()->IsPackageStoreSizeAvailableL(contentsize2); |
|
522 |
|
523 iDLProgress = ESizeChecked; |
|
524 |
|
525 if ( avail==CFotaStorage::EDoesntFitToFileSystem ) |
|
526 { |
|
527 FLOG(_L("CFotaStorage::EDoesntFitToFileSystem")); |
|
528 if (iFreshDL) |
|
529 { |
|
530 if ( iShowDLPrgUI ) |
|
531 { |
|
532 FLOG(_L("iDLNeedsReset = ETrue;")); |
|
533 iDLNeedsReset = ETrue; |
|
534 LaunchNotifierL( ESyncMLFwUpdOmaDLNotEnoughMemory, KErrDiskFull,contentsize2 ); |
|
535 } |
|
536 else |
|
537 { |
|
538 iDLState.iResult = RFotaEngineSession::EResDLFailDueToDeviceOOM; |
|
539 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
540 iUpdateAfterDownload = EFalse; |
|
541 LaunchNotifierL( ESyncMLFwUpdErrorNote, KErrGeneral, contentsize2,ETrue ); |
|
542 } |
|
543 } |
|
544 else //resuming download |
|
545 { |
|
546 FLOG(_L("Memory need in order to resume. Notify user...")); |
|
547 LaunchNotifierL( ESyncMLFwUpdOmaDLNotEnoughMemory, KErrDiskFull,contentsize2 ); |
|
548 RunDownloadSuspendL(RFotaEngineSession::EResDLFailDueToDeviceOOM); |
|
549 } |
|
550 |
|
551 } |
|
552 } |
|
553 |
|
554 // OMA DD download completed , must hide progress |
|
555 if ( aEvent.iProgressState == EHttpProgContentTypeChanged ) // 2055 |
|
556 { |
|
557 if ( iDLProgressDlg ) |
|
558 { |
|
559 iDLProgressDlg->ProcessFinishedL(); // deletes itself |
|
560 delete iDLProgressDlg; |
|
561 iDLProgressDlg = NULL; |
|
562 } |
|
563 } |
|
564 // OMA DD accepted,show progress |
|
565 if ( aEvent.iProgressState == EHttpProgCodDescriptorAccepted ) // 2502 |
|
566 |
|
567 { |
|
568 iDLProgress = EDescriptorDownloaded; |
|
569 if ( iShowDLPrgUI ) |
|
570 { |
|
571 FLOG(_L("SHOW PROGRESS")); |
|
572 if ( iDLProgressDlg ) |
|
573 { |
|
574 FLOG(_L("Removing Connecting progress note...")); |
|
575 iDLProgressDlg->ProcessFinishedL(); |
|
576 delete iDLProgressDlg; |
|
577 iDLProgressDlg = NULL; |
|
578 } |
|
579 if (!iDLProgressDlg) |
|
580 { |
|
581 |
|
582 FLOG(_L("Creating iDLProgressDlg")); |
|
583 iDLProgressDlg = new(ELeave) CFotaDLProgressDlg((CEikDialog** ) &iDLProgressDlg , EFalse, this, EDownloadingNote ); |
|
584 iDLProgressDlg->PrepareLC( R_FOTASERVER_DL_PROGRESS_DIALOG ); |
|
585 iDLProgressDlg->RunLD(); |
|
586 } |
|
587 CEikProgressInfo* progressInfo = iDLProgressDlg->GetProgressInfoL(); |
|
588 progressInfo->SetFinalValue( 500 ); |
|
589 iPreviousContentSize = -1; |
|
590 iDownloadedContentSize = 0; |
|
591 iFotaServer->iParentApp->SetUIVisibleL ( ETrue , EFalse ); |
|
592 } |
|
593 if (iDownloadResumable) |
|
594 { |
|
595 FLOG(_L("Setting download as resumable")); |
|
596 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
597 iFotaServer->SetStartupReason(EFotaDownloadInterrupted); |
|
598 } |
|
599 else |
|
600 { |
|
601 FLOG(_L("Setting download as non resumable")); |
|
602 iDLState.iState = RFotaEngineSession::EDownloadProgressing; |
|
603 iFotaServer->SetStartupReason(EFotaPendingGenAlert); |
|
604 } |
|
605 iFotaServer->iDatabase->OpenDBL(); |
|
606 iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBState ); |
|
607 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
608 |
|
609 |
|
610 if (iDLState.iIapId <= 0) //Read the IAP ID when not known, and set it into db. |
|
611 { |
|
612 TInt32 usedapid (KErrNotFound); |
|
613 TInt er = iDownloadMgr.GetIntAttribute( EDlMgrIap, usedapid); |
|
614 iDLState.iIapId = usedapid; |
|
615 FLOG(_L("Setting IAPID=%d is FotaState"),iDLState.iIapId); |
|
616 iFotaServer->iDatabase->OpenDBL(); |
|
617 iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBIapId ); |
|
618 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
619 } |
|
620 } |
|
621 } |
|
622 break; |
|
623 case EHttpDlCompleted: // 4 |
|
624 { |
|
625 FLOG(_L("Download State: EHttpDlCompleted")); |
|
626 |
|
627 iRestartCounter = -1; |
|
628 if ( iDLProgressDlg ) |
|
629 { |
|
630 iDLProgressDlg->ProcessFinishedL(); // deletes itself |
|
631 delete iDLProgressDlg; |
|
632 iDLProgressDlg = NULL; |
|
633 } |
|
634 iDLState.iState = RFotaEngineSession::EDownloadComplete; |
|
635 |
|
636 if (iUpdateAfterDownload) |
|
637 iDLState.iResult = KErrNotFound; |
|
638 else |
|
639 iDLState.iResult = RFotaEngineSession::EResSuccessful; |
|
640 iFotaServer->FinalizeDownloadL( iDLState ); |
|
641 } |
|
642 break; |
|
643 case EHttpDlPaused: //Event thrown for any resumable download |
|
644 case EHttpDlFailed: //Event thrown for any non-resumable download or critical error on resumable download |
|
645 { |
|
646 |
|
647 if (aEvent.iProgressState != EHttpProgNone) //Accepting only events from COD |
|
648 return; |
|
649 |
|
650 if (aEvent.iDownloadState == EHttpDlPaused) |
|
651 { |
|
652 FLOG(_L("Download State: EHttpDlPaused")); |
|
653 if (iDownloadResumable) |
|
654 { |
|
655 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
656 } |
|
657 else |
|
658 { |
|
659 // iDownloadResumable remains 0 even for resumable download. |
|
660 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
661 } |
|
662 } |
|
663 else //aEvent.iDownloadState = EHttpDlFailed |
|
664 { |
|
665 FLOG(_L("Download State: EHttpDlFailed")); |
|
666 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
667 iDownloadResumable = EFalse; |
|
668 } |
|
669 //Remove the download progress bar |
|
670 if ( iDLProgressDlg && (iDLState.iResult != RFotaEngineSession::EResUserCancelled )) |
|
671 { |
|
672 FLOG(_L("Shd not come in EResUserCancelled")); |
|
673 iDLProgressDlg->ProcessFinishedL(); // deletes itself |
|
674 delete iDLProgressDlg; |
|
675 iDLProgressDlg = NULL; |
|
676 } |
|
677 // This is restarted download => decrement counter |
|
678 if ( iRestartCounter > 0 ) |
|
679 { |
|
680 --iRestartCounter; |
|
681 if ( iRestartCounter <=0 ) iRestartCounter = -1; |
|
682 FLOG(_L(" iRestartCounter to %d"),iRestartCounter ); |
|
683 } |
|
684 /*****************************/ |
|
685 //Handling all errors now...// |
|
686 /****************************/ |
|
687 TInt notifType (KErrNotFound); |
|
688 TInt notifParam (KErrNotFound); |
|
689 //Handling User Cancel of Download Descriptor |
|
690 if ( dlErrorId == EGeneral && (sysErrorId == KErrAbort || sysErrorId == KErrCancel )) |
|
691 { |
|
692 FLOG(_L("Reason: User cancelled download descriptor")); |
|
693 //LaunchNotifierL(ESyncMLFwUpdOmaDLCancelled, EFalse, EFalse); |
|
694 iRestartCounter = -1; |
|
695 iDLState.iResult = RFotaEngineSession::EResUserCancelled; |
|
696 notifType = ESyncMLFwUpdOmaDLCancelled; |
|
697 notifParam = KErrNone; |
|
698 } |
|
699 //Handling User Cancel |
|
700 else if ( iDLState.iResult == RFotaEngineSession::EResUserCancelled ) //This variable is set in RunDownloadCancelL or RunDownloadSuspendL |
|
701 { |
|
702 iRestartCounter = -1; |
|
703 //If initial pause is successful, query user if he wants to postpone or cancel permanently. |
|
704 iFotaServer->iDatabase->OpenDBL(); |
|
705 iFotaServer->iDatabase->SetStateL(iDLState,KNullDesC8, EFDBState); |
|
706 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
707 |
|
708 if (iDownloadResumable) |
|
709 { |
|
710 if (!iSilentOpn) |
|
711 { |
|
712 FLOG(_L("Download has been paused successful. Query user if he wants to postpone or cancel permanently")); |
|
713 LaunchNotifierL(ESyncMLFwUpdOmaDLUserCancel, KErrNone, KErrNone); |
|
714 break; |
|
715 } |
|
716 else |
|
717 { |
|
718 notifType = ESyncMLFwUpdOmaDLPostponed; |
|
719 notifParam = KErrNone; |
|
720 } |
|
721 } |
|
722 else |
|
723 { |
|
724 FLOG(_L("Error while initial pausing...%d Hence download has to be cancelled permanently!")); |
|
725 RunDownloadCancelL(RFotaEngineSession::EResUserCancelled); |
|
726 notifType = ESyncMLFwUpdOmaDLCancelled; |
|
727 notifParam = KErrNone; |
|
728 } |
|
729 } |
|
730 else if ( iDLState.iResult == RFotaEngineSession::EResDLFailDueToDeviceOOM ) |
|
731 { |
|
732 FLOG(_L("Reason: Not enough memory to perform resume")); |
|
733 iRestartCounter = -1; |
|
734 |
|
735 if (iDownloadResumable) |
|
736 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
737 else |
|
738 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
739 } |
|
740 //Handling user cancel IAP selection popup |
|
741 else if ( dlErrorId == EConnectionFailed && sysErrorId == KErrCancel) |
|
742 { |
|
743 FLOG(_L("Reason: User canceled IAP selection popup")); |
|
744 iDLState.iResult = RFotaEngineSession::EResUserCancelled; |
|
745 iRestartCounter = -1; |
|
746 |
|
747 notifType = ESyncMLFwUpdOmaDLPostponed; |
|
748 notifParam = KErrNone; |
|
749 } |
|
750 //Handling temproary network timeout. This may either try resume or restart based on download. |
|
751 /* else if ( dlErrorId == EGeneral && sysErrorId == KErrTimedOut ) |
|
752 { |
|
753 FLOG(_L("Reason: Network timeout")); |
|
754 // No restart issued yet, this is 1st download attempt |
|
755 if ( iRestartCounter == 0 ) |
|
756 { |
|
757 iRestartCounter = KFotaDownloadTimeoutRestartCount; |
|
758 iDLState.iState = RFotaEngineSession::EIdle; |
|
759 FLOG(_L("Trying to restart download (iRestartCounter=%d)"),iRestartCounter ); |
|
760 } |
|
761 |
|
762 }*/ |
|
763 //Handling all Network interrupts |
|
764 else if ( (dlErrorId == EConnectionFailed && sysErrorId == KErrCommsLineFail)|| |
|
765 dlErrorId == ETransactionFailed || |
|
766 (dlErrorId == KErrCodWapConnectionDropped && sysErrorId == KErrGeneral) || |
|
767 (dlErrorId == EGeneral && sysErrorId == KErrTimedOut) || |
|
768 (dlErrorId == EConnectionFailed && sysErrorId == KErrGprsServicesNotAllowed ) || |
|
769 (dlErrorId == EConnectionFailed && sysErrorId == KErrGsmMMNetworkFailure ) || |
|
770 (dlErrorId == EConnectionFailed && sysErrorId == KErrWlanNetworkNotFound ) |
|
771 ) |
|
772 { |
|
773 FLOG(_L("Reason: Network breakage")); |
|
774 iRestartCounter = -1; |
|
775 notifType = ESyncMLFwUpdErrorNote; |
|
776 if (iDownloadResumable) |
|
777 { |
|
778 notifParam = KErrCommsLineFail2; |
|
779 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
780 iDLState.iResult = RFotaEngineSession::EResDLFailDueToNWIssues; |
|
781 } |
|
782 else |
|
783 { |
|
784 notifParam = KErrCommsLineFail; |
|
785 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
786 iDLState.iResult = RFotaEngineSession::EResDLFailDueToNWIssues; |
|
787 } |
|
788 } |
|
789 //Handling Out Of Memory interrupt |
|
790 else if ((dlErrorId == EGeneral && sysErrorId == KErrDiskFull ) || sysErrorId == KErrCodInsufficientSpace) |
|
791 { |
|
792 FLOG(_L("Reason: Disk full")); |
|
793 iRestartCounter = -1; |
|
794 notifType = KErrNotFound; |
|
795 notifParam = KErrNotFound; // don't show anything |
|
796 iDLState.iResult = RFotaEngineSession::EResDLFailDueToDeviceOOM; |
|
797 } |
|
798 //Handle unclassified (general) interrupts |
|
799 else |
|
800 { |
|
801 iRestartCounter = -1; |
|
802 |
|
803 |
|
804 RProperty prop; |
|
805 TInt val = KErrNone; |
|
806 |
|
807 TInt err = prop.Get(KPSUidStartup, KPSGlobalSystemState, val); |
|
808 if (err==KErrNone && val!=ESwStateShuttingDown) |
|
809 { |
|
810 notifType = ESyncMLFwUpdErrorNote; |
|
811 } |
|
812 else |
|
813 { |
|
814 FLOG(_L("Phone is powering down...")); |
|
815 } |
|
816 |
|
817 if (iDownloadResumable) |
|
818 { |
|
819 notifParam = KErrGeneralResume; |
|
820 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
821 } |
|
822 else |
|
823 { |
|
824 notifParam = KErrGeneralNoResume; |
|
825 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
826 } |
|
827 |
|
828 |
|
829 SetDLResultdlErrorId(dlErrorId ,sysErrorId ); |
|
830 |
|
831 |
|
832 } |
|
833 if ( iRestartCounter <= 0) |
|
834 { |
|
835 iUpdateAfterDownload = EFalse; |
|
836 SetDownloadActive(EFalse); |
|
837 if ( iDLState.iSessionType!= ESanSilent && notifType!=KErrNotFound ) |
|
838 { |
|
839 if ( iShowDLPrgUI ) |
|
840 LaunchNotifierL( (TSyncMLFwUpdNoteTypes)notifType, notifParam,0 ); |
|
841 else |
|
842 LaunchNotifierL( (TSyncMLFwUpdNoteTypes)notifType, notifParam,0, ETrue); |
|
843 } |
|
844 FLOG(_L("Should come here for nonpausable ")); |
|
845 iDownloadFinalized = ETrue; |
|
846 iFotaServer->FinalizeDownloadL( iDLState ); |
|
847 } |
|
848 else |
|
849 { |
|
850 if (iDownloadResumable) |
|
851 { |
|
852 FLOG(_L("Resuming download...")); |
|
853 iDownload->Start(); |
|
854 } |
|
855 else |
|
856 { |
|
857 FLOG(_L("Restarting download...")); |
|
858 iFotaServer->FinalizeDownloadL( iDLState ); |
|
859 } |
|
860 } |
|
861 } |
|
862 break; |
|
863 |
|
864 case EHttpDlPausable: |
|
865 { |
|
866 FLOG(_L("Download State: EHttpDlPausable")); |
|
867 if (iDownloadResumable) //This is initially set by IsDownloadSuspendResumeSupported() |
|
868 { |
|
869 FLOG(_L("Download Suspend/Resume is supported!")); |
|
870 } |
|
871 else |
|
872 { |
|
873 FLOG(_L("Download Server support Suspend/Resume, but Fota doesn't!")); |
|
874 //retain the state iDownloadResumable = EOmaDLResumeNotSupported; |
|
875 } |
|
876 } |
|
877 break; |
|
878 |
|
879 case EHttpDlNonPausable: |
|
880 { |
|
881 FLOG(_L("Download State: EHttpDlNonPausable")); |
|
882 if (iDownloadResumable) //This is initially set by CheckDownloadVariations() |
|
883 { |
|
884 FLOG(_L("Download Server doesn't support Suspend/Resume, but Fota does!")); |
|
885 //Reset the state to not supported. |
|
886 iDownloadResumable = EFalse; |
|
887 } |
|
888 else |
|
889 { |
|
890 FLOG(_L("Download Server doesn't support Suspend/Resume, neither does Fota!")); |
|
891 } |
|
892 } |
|
893 break; |
|
894 case EHttpDlDeleting: //13 |
|
895 { |
|
896 FLOG(_L("Download State: EHttpDlDeleting")); |
|
897 } |
|
898 break; |
|
899 case EHttpDlDeleted: //11 |
|
900 { |
|
901 FLOG(_L("Download State: EHttpDlDeleted")); |
|
902 } |
|
903 break; |
|
904 default: |
|
905 { |
|
906 FLOG(_L("Default. No action performed for this Download State")); |
|
907 } |
|
908 break; |
|
909 } |
|
910 FLOG(_L("CFotaDownload::HandleDMgrEventL() <<")); |
|
911 } |
|
912 |
|
913 |
|
914 |
|
915 // -------------------------------------------------------------------------- |
|
916 // CFotaDownload::SetDLResultdlErrorId |
|
917 // Sets the appropriate error |
|
918 // -------------------------------------------------------------------------- |
|
919 // |
|
920 |
|
921 void CFotaDownload::SetDLResultdlErrorId( THttpDownloadMgrError adlErrorId, TInt32 asysErrorId) |
|
922 { |
|
923 if ( adlErrorId == EInternal) |
|
924 { |
|
925 FLOG(_L("Reason: error EInternal")); |
|
926 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
927 } |
|
928 else if ( adlErrorId == EContentFileIntegrity) |
|
929 { |
|
930 FLOG(_L("Reason: error EContentFileIntegrity")); |
|
931 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
932 } |
|
933 else if ( adlErrorId == EMMCRemoved) |
|
934 { |
|
935 FLOG(_L("Reason: error EMMCRemoved,")); |
|
936 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
937 } |
|
938 else if ( adlErrorId == EBadUrl) |
|
939 { |
|
940 FLOG(_L("Reason: error EBadUrl")); |
|
941 iDLState.iResult = RFotaEngineSession::EResMalformedOrBadURL; |
|
942 } |
|
943 else if ( adlErrorId == EHttpUnhandled) |
|
944 { |
|
945 FLOG(_L("Reason: error EHttpUnhandled, check global error id!")); |
|
946 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
947 } |
|
948 else if ( adlErrorId == EHttpAuthenticationFailed) |
|
949 { |
|
950 FLOG(_L("Reason: error EHttpAuthenticationFailed")); |
|
951 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
952 } |
|
953 else if ( adlErrorId == EObjectNotFound) |
|
954 { |
|
955 FLOG(_L("Reason: error EObjectNotFound")); |
|
956 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
957 } |
|
958 else if ( adlErrorId == EPartialContentModified) |
|
959 { |
|
960 FLOG(_L("Reason: error EPartialContentModified")); |
|
961 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
962 } |
|
963 else if ( adlErrorId == EContentExpired) |
|
964 { |
|
965 FLOG(_L("Reason: error EContentExpired")); |
|
966 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
967 } |
|
968 else if ( adlErrorId == EHttpRestartFailed) |
|
969 { |
|
970 FLOG(_L("Reason: error EHttpRestartFailed")); |
|
971 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
972 } |
|
973 else if ( asysErrorId == KErrCodInvalidDescriptor ) |
|
974 { |
|
975 FLOG(_L("Reason: error KErrCodInvalidDescriptor")); |
|
976 iDLState.iResult = RFotaEngineSession::EResMalformedOrBadURL; |
|
977 } |
|
978 else |
|
979 { |
|
980 FLOG(_L("Reason: unknown, check dlError!")); |
|
981 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
982 } |
|
983 |
|
984 } |
|
985 |
|
986 // -------------------------------------------------------------------------- |
|
987 // CFotaDownload::HandleDMgrEventL |
|
988 // -------------------------------------------------------------------------- |
|
989 // |
|
990 void CFotaDownload::HandleDMgrEventL( RHttpDownload& aDownload |
|
991 , THttpDownloadEvent aEvent ) |
|
992 { |
|
993 DoHandleDMgrEventL(&aDownload,aEvent); |
|
994 } |
|
995 |
|
996 |
|
997 // -------------------------------------------------------------------------- |
|
998 // CFotaDownload::LaunchNotifierL |
|
999 // Launches notifier. This method is also used to finalize erronous DL |
|
1000 // -------------------------------------------------------------------------- |
|
1001 // |
|
1002 void CFotaDownload::LaunchNotifierL( const TSyncMLFwUpdNoteTypes aNotetype |
|
1003 ,const TInt aIntParam |
|
1004 ,const TInt aMemoryNeeded |
|
1005 ,TBool aFinishOnly ) |
|
1006 { |
|
1007 if ( iNotifHandler ) iNotifHandler->Cancel(); |
|
1008 else iNotifHandler = CFotaDownloadNotifHandler::NewL(this); |
|
1009 iNotifHandler->LaunchNotifierL( aNotetype,aIntParam,aMemoryNeeded |
|
1010 ,aFinishOnly ); |
|
1011 } |
|
1012 |
|
1013 // -------------------------------------------------------------------------- |
|
1014 // CFotaDownload::CheckDownloadVariations |
|
1015 // Reads download variations - fota suspend & resume bahavior & FMS from cenrep keys |
|
1016 // -------------------------------------------------------------------------- |
|
1017 // |
|
1018 void CFotaDownload::CheckDownloadVariations() |
|
1019 { |
|
1020 FLOG(_L("CFotaDownload::CheckDownloadVariations >>")); |
|
1021 |
|
1022 CRepository* centrep( NULL); |
|
1023 TRAPD(err, centrep = CRepository::NewL( KCRUidFotaServer ) ); |
|
1024 if (err) FLOG(_L("Error reading FotaServer cenrep... %d"),err); |
|
1025 TInt supported(KErrNone); |
|
1026 if (centrep ) |
|
1027 { |
|
1028 err = centrep->Get( KSuspendResumeFeatureSupported, supported ); |
|
1029 if (err) FLOG(_L("Error reading cenrep key... %d"),err); |
|
1030 iDownloadResumable = (supported==1)? ETrue:EFalse; |
|
1031 |
|
1032 supported = KErrNone; |
|
1033 centrep->Get( KFotaMonitoryServiceEnabled, supported ); |
|
1034 if (err) FLOG(_L("Error reading cenrep key... %d"),err); |
|
1035 iFMSEnabled = (supported > 0)? ETrue:EFalse; |
|
1036 |
|
1037 delete centrep; |
|
1038 centrep = NULL; |
|
1039 } |
|
1040 |
|
1041 FLOG(_L("Susp&Resume feature supported = %d, FMS feature supported = %d"),iDownloadResumable,iFMSEnabled); |
|
1042 FLOG(_L("CFotaDownload::CheckDownloadVariations <<")); |
|
1043 } |
|
1044 |
|
1045 // -------------------------------------------------------------------------- |
|
1046 // CFotaDownload::RunDownloadCancelL |
|
1047 // Starts to cancel the download operation |
|
1048 // -------------------------------------------------------------------------- |
|
1049 // |
|
1050 void CFotaDownload::RunDownloadCancelL(const TInt aReason, TBool aSilent) |
|
1051 { |
|
1052 FLOG(_L("CFotaDownload::RunDownloadCancelL, reason = %d, silent = %d >>"), aReason, aSilent); |
|
1053 |
|
1054 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
1055 iDLState.iResult = aReason; |
|
1056 iSilentOpn = aSilent; |
|
1057 |
|
1058 iRestartCounter = -1; |
|
1059 iUpdateAfterDownload = EFalse; |
|
1060 |
|
1061 if (!iDownload) |
|
1062 { |
|
1063 //iDownload is null when user cancels the download permanently when prompted to resume. |
|
1064 //hence retrieve the download object first |
|
1065 iDownload = RetrieveDownloadL(); |
|
1066 } |
|
1067 TInt err = iDownload->Delete(); //or Cancel or Reset? |
|
1068 FLOG(_L("Error = %d"),err); |
|
1069 |
|
1070 if(iDownloadFinalized == EFalse) |
|
1071 { |
|
1072 iFotaServer->FinalizeDownloadL( iDLState ); |
|
1073 FLOG(_L("Should not come here fro nopausable ")); |
|
1074 if (aReason == RFotaEngineSession::EResUserCancelled) |
|
1075 LaunchNotifierL(ESyncMLFwUpdOmaDLCancelled, EFalse, EFalse); |
|
1076 else if (aReason == RFotaEngineSession::EResUndefinedError) |
|
1077 LaunchNotifierL(ESyncMLFwUpdErrorNote, KErrGeneralNoResume, EFalse ); |
|
1078 } |
|
1079 FLOG(_L("CFotaDownload::RunDownloadCancelL <<")); |
|
1080 } |
|
1081 |
|
1082 // -------------------------------------------------------------------------- |
|
1083 // CFotaDownload::RunDownloadSuspendL |
|
1084 // Starts to suspend the download operation |
|
1085 // -------------------------------------------------------------------------- |
|
1086 // |
|
1087 void CFotaDownload::RunDownloadSuspendL(const TInt aReason, TBool aSilent) |
|
1088 { |
|
1089 FLOG(_L("CFotaDownload::RunDownloadSuspendL, reason = %d, silent = %d >>"), aReason, aSilent); |
|
1090 |
|
1091 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
1092 iDLState.iResult = aReason; |
|
1093 iSilentOpn = aSilent; |
|
1094 //First pause download, and later ask for user action. |
|
1095 TInt err = iDownload->Pause(); |
|
1096 |
|
1097 if (err) |
|
1098 { |
|
1099 //initial pausing becomes a problem. |
|
1100 FLOG(_L("Error while initial pausing...%d Hence download has to be cancelled permanently!"),err); |
|
1101 RunDownloadCancelL(aReason); |
|
1102 } |
|
1103 |
|
1104 FLOG(_L("CFotaDownload::RunDownloadSuspendL <<")); |
|
1105 } |
|
1106 |
|
1107 // -------------------------------------------------------------------------- |
|
1108 // CFotaDownload::TryResumeDownloadL |
|
1109 // Tries to resume the download operation |
|
1110 // -------------------------------------------------------------------------- |
|
1111 // |
|
1112 void CFotaDownload::TryResumeDownloadL(TBool aUserInitiated) |
|
1113 { |
|
1114 FLOG(_L("CFotaDownload::TryResumeDownloadL >>")); |
|
1115 |
|
1116 iUserInitiatedResume = aUserInitiated; |
|
1117 TInt err = RProperty::Define( TUid::Uid(KOmaDMAppUid), |
|
1118 KFotaDMRefresh, |
|
1119 RProperty::EInt,KReadPolicy,KWritePolicy); |
|
1120 FLOG(_L("RProperty KFotaDMRefresh Define, err = %d"), err); |
|
1121 if (err != KErrAlreadyExists ) |
|
1122 { |
|
1123 User::LeaveIfError(err); |
|
1124 } |
|
1125 //This P&S Key is used to notify DM UI on any download event. key=0 for idle and key=1 for download |
|
1126 err = RProperty::Set( TUid::Uid(KOmaDMAppUid), |
|
1127 KFotaDMRefresh, |
|
1128 ETrue ); |
|
1129 FLOG(_L("RProperty KFotaDMRefresh Set ETrue, err = %d"), err); |
|
1130 |
|
1131 //Called to read the download variations in Fota (resume support & FMS) |
|
1132 CheckDownloadVariations(); |
|
1133 if (IsFMSEnabled() && iUserInitiatedResume) |
|
1134 iFotaServer->CancelFmsL(); |
|
1135 |
|
1136 //Query based on the type of DM session used earlier. |
|
1137 if (iUserInitiatedResume || iDLState.iSessionType != ESanSilent) |
|
1138 { |
|
1139 //Query user for resume |
|
1140 FLOG(_L("Quering user for resume...")); |
|
1141 if (iFotaServer->iNotifHandler) |
|
1142 { |
|
1143 iFotaServer->iNotifHandler->Cancel(); |
|
1144 delete iFotaServer->iNotifHandler; |
|
1145 iFotaServer->iNotifHandler = NULL; |
|
1146 } |
|
1147 iNotifHandler = CFotaDownloadNotifHandler::NewL(this); |
|
1148 |
|
1149 iNotifHandler->LaunchNotifierL(ESyncMLFwUpdOmaDLResume, EFalse, EFalse); |
|
1150 } |
|
1151 else //Only FMS initiated Silent Session download |
|
1152 { |
|
1153 //Resume directly |
|
1154 FLOG(_L("Resuming automatically...")); |
|
1155 ResumeDownloadL(); |
|
1156 } |
|
1157 FLOG(_L("CFotaDownload::TryResumeDownloadL <<")); |
|
1158 } |
|
1159 |
|
1160 // -------------------------------------------------------------------------- |
|
1161 // CFotaDownload::ResumeDownloadL |
|
1162 // Resume the download operation |
|
1163 // -------------------------------------------------------------------------- |
|
1164 // |
|
1165 void CFotaDownload::ResumeDownloadL() |
|
1166 { |
|
1167 FLOG(_L("CFotaDownload::ResumeDownloadL >>")); |
|
1168 TBool toresetdl (EFalse); |
|
1169 TBool downloadiapvalid (ETrue); |
|
1170 //Find the download ui behavior from fota cenrep |
|
1171 TInt behavior(KErrNotFound); |
|
1172 CRepository* centrep = NULL; |
|
1173 TRAPD(err, centrep = CRepository::NewL( KCRUidFotaServer ) ); |
|
1174 if (( centrep ) && ( err == KErrNone)) |
|
1175 { |
|
1176 centrep->Get( KSilentOmaDlUIBehavior, behavior ); |
|
1177 delete centrep; |
|
1178 } |
|
1179 centrep = NULL; |
|
1180 //Commented for resolving APP dependency |
|
1181 /* |
|
1182 if (iUserInitiatedResume || |
|
1183 (behavior == EOmacdOffdlprgOn || behavior == EOmacdOndlprgOn)) |
|
1184 { |
|
1185 FLOG(_L("Showing Connecting progress note...")); |
|
1186 iFotaServer->iParentApp->SetUIVisibleL ( ETrue , EFalse ); |
|
1187 |
|
1188 if ( !iDLProgressDlg ) |
|
1189 { |
|
1190 iDLProgressDlg = new(ELeave) CFotaDLProgressDlg((CEikDialog** ) &iDLProgressDlg , EFalse, this, EConnectingNote ); |
|
1191 iDLProgressDlg->PrepareLC( R_CONNECTION_NOTE ); |
|
1192 } |
|
1193 // Load the resource files |
|
1194 TInt err = KErrNone; |
|
1195 |
|
1196 // Localize the file name, and load the SCP resources |
|
1197 TFileName resFile; |
|
1198 resFile.Copy( KDriveZ ); |
|
1199 resFile.Append( KSCPResourceFilename ); |
|
1200 |
|
1201 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resFile ); |
|
1202 |
|
1203 TInt Res1(KErrNone); |
|
1204 TRAP( err, Res1 =CCoeEnv::Static()->AddResourceFileL( resFile ) ); |
|
1205 |
|
1206 HBufC* buf = StringLoader::LoadLC(R_SYNCSTATUS_SYNC_CONN); |
|
1207 |
|
1208 if( Res1 ) |
|
1209 { |
|
1210 iFotaServer->GetEikEnv()->DeleteResourceFile( Res1 ); |
|
1211 } |
|
1212 FLOG(_L("Reading txt as: %S"), &buf->Des()); |
|
1213 iDLProgressDlg->SetTextL(buf->Des()); |
|
1214 CleanupStack::PopAndDestroy(buf); |
|
1215 |
|
1216 iDLProgressDlg->RunLD(); |
|
1217 } |
|
1218 */ |
|
1219 //Comment ends here |
|
1220 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 1")); |
|
1221 |
|
1222 iDownload = RetrieveDownloadL(); |
|
1223 if (iDownload) |
|
1224 { |
|
1225 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 2: Successfully retrieved download object >>")); |
|
1226 |
|
1227 SetIapToUseL(iDLState, iDLState.iIapId); |
|
1228 |
|
1229 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 3: Using iapid %d for resume..."), iDLState.iIapId); |
|
1230 downloadiapvalid = iFotaServer->CheckIapExistsL(iDLState.iIapId); |
|
1231 if (iDLState.iIapId > 0 && downloadiapvalid) |
|
1232 { |
|
1233 if (!iMonitor) |
|
1234 { |
|
1235 iMonitor = CFotaNetworkRegStatus::NewL (iFotaServer); |
|
1236 } |
|
1237 TBool val = iMonitor->IsConnectionPossibleL(iDLState.iIapId); |
|
1238 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 4")); |
|
1239 delete iMonitor; iMonitor = NULL; |
|
1240 |
|
1241 #if defined(__WINS__) |
|
1242 val =ETrue; |
|
1243 #endif |
|
1244 if (!val) |
|
1245 { |
|
1246 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 5.1: Disallowing resume operation as connection not possible")); |
|
1247 |
|
1248 if ( !iShowDLPrgUI && iDLProgressDlg ) |
|
1249 { |
|
1250 FLOG(_L("Removing Connecting progress note...")); |
|
1251 |
|
1252 iDLProgressDlg->ProcessFinishedL(); |
|
1253 delete iDLProgressDlg; |
|
1254 iDLProgressDlg = NULL; |
|
1255 } |
|
1256 if (iUserInitiatedResume || iDLState.iSessionType!=ESanSilent) |
|
1257 LaunchNotifierL(ESyncMLFwUpdErrorNote, KErrCommsLineFail2,0); |
|
1258 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
1259 iDLState.iResult = RFotaEngineSession::EResDLFailDueToNWIssues; |
|
1260 iUpdateAfterDownload = EFalse; |
|
1261 iFotaServer->FinalizeDownloadL(iDLState); |
|
1262 return; |
|
1263 } |
|
1264 } |
|
1265 |
|
1266 if (iDLState.iIapId == KErrNotFound || !downloadiapvalid ) |
|
1267 { |
|
1268 iDLState.iIapId = KErrNotFound; |
|
1269 User::LeaveIfError( iDownloadMgr.SetIntAttribute( EDlMgrIap, 0)); // Download mgr interprets 0 for Always Ask |
|
1270 } |
|
1271 else |
|
1272 User::LeaveIfError( iDownloadMgr.SetIntAttribute( EDlMgrIap, iDLState.iIapId)); // IAP id |
|
1273 |
|
1274 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 5.2")); |
|
1275 SetDownloadUiBehavior(EFalse); |
|
1276 |
|
1277 if ( !iShowDLPrgUI && iDLProgressDlg ) |
|
1278 { |
|
1279 FLOG(_L("Removing Connecting progress note...")); |
|
1280 |
|
1281 iDLProgressDlg->ProcessFinishedL(); |
|
1282 delete iDLProgressDlg; |
|
1283 iDLProgressDlg = NULL; |
|
1284 } |
|
1285 TInt dlsize, tlsize; |
|
1286 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 6")); |
|
1287 iFotaServer->GetDownloadUpdatePackageSizeL(iDLState.iPkgId, dlsize,tlsize); |
|
1288 iDownloadedContentSize = dlsize; //for progress bar update only |
|
1289 iUpdateAfterDownload = iDLState.iUpdateLtr; //should update after reboot? |
|
1290 iRestartCounter = 0; |
|
1291 |
|
1292 //Set right states in fota db |
|
1293 iDLState.iState = RFotaEngineSession::EDownloadProgressingWithResume; |
|
1294 iDLState.iResult = KErrNotFound; |
|
1295 |
|
1296 iFotaServer->iDatabase->OpenDBL(); |
|
1297 iFotaServer->iDatabase->SetStateL( iDLState, KNullDesC8, EFDBState|EFDBResult); |
|
1298 iFotaServer->iDatabase->CloseAndCommitDB(); |
|
1299 iFreshDL = EFalse; |
|
1300 FLOG(_L("CFotaDownload::ResumeDownloadL, Stage 6: Starting to resume download now...")); |
|
1301 TInt err = iDownload->Start(); |
|
1302 if (err == KErrNone) |
|
1303 { |
|
1304 //Set the P&S Key to active... |
|
1305 FLOG(_L("Resume operation is success!")); |
|
1306 SetDownloadActive(ETrue); |
|
1307 } |
|
1308 else |
|
1309 { |
|
1310 FLOG(_L("An error occured during resume, err = %d"),err); |
|
1311 toresetdl = ETrue; |
|
1312 } |
|
1313 } |
|
1314 else |
|
1315 { |
|
1316 FLOG(_L("Failed to get the paused download object")); |
|
1317 if ( iDLProgressDlg ) |
|
1318 { |
|
1319 FLOG(_L("Removing Connecting progress note...")); |
|
1320 iDLProgressDlg->ProcessFinishedL(); // deletes itself |
|
1321 delete iDLProgressDlg; |
|
1322 iDLProgressDlg = NULL; |
|
1323 } |
|
1324 toresetdl = ETrue; |
|
1325 } |
|
1326 ReSetDownloadL( toresetdl); |
|
1327 |
|
1328 FLOG(_L("CFotaDownload::ResumeDownloadL <<")); |
|
1329 } |
|
1330 // -------------------------------------------------------------------------- |
|
1331 // CFotaDownload::ReSetDownloadL |
|
1332 // Sets the download state to failed |
|
1333 // -------------------------------------------------------------------------- |
|
1334 // |
|
1335 void CFotaDownload::ReSetDownloadL(TBool atoresetdl) |
|
1336 { |
|
1337 if (atoresetdl) |
|
1338 { |
|
1339 FLOG(_L("Resetting fota download !!!")); |
|
1340 if (iUserInitiatedResume || iDLState.iSessionType!=ESanSilent) |
|
1341 LaunchNotifierL(ESyncMLFwUpdErrorNote, KErrGeneralNoResume,0); |
|
1342 iDLState.iState = RFotaEngineSession::EDownloadFailed; |
|
1343 iDLState.iResult = RFotaEngineSession::EResUndefinedError; |
|
1344 iUpdateAfterDownload = EFalse; |
|
1345 iFotaServer->FinalizeDownloadL(iDLState); |
|
1346 } |
|
1347 } |
|
1348 |
|
1349 |
|
1350 |
|
1351 // -------------------------------------------------------------------------- |
|
1352 // CFotaDownload::IsFMSEnabled |
|
1353 // Returns FMS enabled state |
|
1354 // -------------------------------------------------------------------------- |
|
1355 // |
|
1356 TBool CFotaDownload::IsFMSEnabled() |
|
1357 { |
|
1358 FLOG(_L("CFotaDownload::IsFMSEnabled, iFMSEnabled = %d <<"), iFMSEnabled); |
|
1359 return iFMSEnabled; |
|
1360 } |
|
1361 |
|
1362 // -------------------------------------------------------------------------- |
|
1363 // CFotaDownload::IsDownloadResumable |
|
1364 // Returns whether the download is resumable or not. |
|
1365 // -------------------------------------------------------------------------- |
|
1366 // |
|
1367 TBool CFotaDownload::IsDownloadResumable() |
|
1368 { |
|
1369 FLOG(_L("CFotaDownload::IsDownloadResumable, iDownloadResumable = %d <<"), iDownloadResumable); |
|
1370 return iDownloadResumable; |
|
1371 } |
|
1372 |
|
1373 // -------------------------------------------------------------------------- |
|
1374 // CFotaDownload::SetIapToUseL |
|
1375 // Sets the IAP ID to use. This menthod is used in fresh and resume download. |
|
1376 // -------------------------------------------------------------------------- |
|
1377 // |
|
1378 void CFotaDownload::SetIapToUseL(TPackageState aParams, const TInt aIapid) |
|
1379 { |
|
1380 FLOG(_L("CFotaDownload::SetIapToUseL >>")); |
|
1381 |
|
1382 RSyncMLSession sml; |
|
1383 TInt profIapid( KErrNotFound ); |
|
1384 TInt sockIapid( KErrNotFound ); |
|
1385 TSmlServerAlertedAction saa(ESmlConfirmSync); |
|
1386 |
|
1387 CleanupClosePushL( sml ); |
|
1388 sml.OpenL(); |
|
1389 iFotaServer->GetProfileDataL(&sml,aParams.iProfileId, profIapid, saa |
|
1390 ,iIsjobStartedFromUI, iSanValue ); |
|
1391 CleanupStack::PopAndDestroy( &sml ); |
|
1392 |
|
1393 // 2/3 GET IAP FROM ESOCK ---------------------------------------------- |
|
1394 // resolve which accespoint is used for current DM session |
|
1395 if ( profIapid == KErrNotFound && aIapid==KErrNotFound) |
|
1396 { |
|
1397 RSocketServ serv; |
|
1398 CleanupClosePushL( serv ); |
|
1399 User::LeaveIfError( serv.Connect() ); |
|
1400 |
|
1401 RConnection conn; |
|
1402 CleanupClosePushL( conn ); |
|
1403 User::LeaveIfError( conn.Open( serv ) ); |
|
1404 |
|
1405 TUint count( 0 ); |
|
1406 User::LeaveIfError( conn.EnumerateConnections ( count ) ); |
|
1407 // enumerate connections |
|
1408 for( TUint idx=1; idx<=count; ++idx ) |
|
1409 { |
|
1410 TConnectionInfo connectionInfo; |
|
1411 TConnectionInfoBuf connInfo( connectionInfo ); |
|
1412 |
|
1413 TInt err = conn.GetConnectionInfo( idx, connInfo ); // iapid |
|
1414 if( err != KErrNone ) |
|
1415 { |
|
1416 CleanupStack::PopAndDestroy( 2 ); // conn, serv |
|
1417 User::Leave( err ); |
|
1418 } |
|
1419 // enumerate connectionclients |
|
1420 TConnectionEnumArg conArg; |
|
1421 conArg.iIndex = idx; |
|
1422 TConnEnumArgBuf conArgBuf(conArg); |
|
1423 err=conn.Control(KCOLConnection,KCoEnumerateConnectionClients |
|
1424 ,conArgBuf); |
|
1425 if( err != KErrNone ) |
|
1426 { |
|
1427 CleanupStack::PopAndDestroy( 2 ); // conn, serv |
|
1428 User::Leave( err ); |
|
1429 } |
|
1430 TInt cliCount = conArgBuf().iCount; |
|
1431 for ( TUint j=1; j<=cliCount ;++j ) |
|
1432 { |
|
1433 TConnectionGetClientInfoArg conCliInfo; |
|
1434 conCliInfo.iIndex = j; |
|
1435 TConnGetClientInfoArgBuf conCliInfoBuf(conCliInfo); |
|
1436 err=conn.Control(KCOLConnection, KCoGetConnectionClientInfo |
|
1437 , conCliInfoBuf); |
|
1438 |
|
1439 if( err != KErrNone ) |
|
1440 { |
|
1441 CleanupStack::PopAndDestroy( 2 ); // conn, serv |
|
1442 User::Leave( err ); |
|
1443 } |
|
1444 TConnectionClientInfo conCliInf = conCliInfoBuf().iClientInfo; |
|
1445 TUid uid = conCliInf.iUid; |
|
1446 if ( uid == TUid::Uid(KSosServerUid) ) |
|
1447 { |
|
1448 sockIapid = connInfo().iIapId; |
|
1449 FLOG(_L("[FotaServer] IAP found %x"),sockIapid); |
|
1450 } |
|
1451 |
|
1452 FLOG(_L("[FotaServer] CFotaDownload::DownloadL uid %x") |
|
1453 ,uid.iUid); |
|
1454 } |
|
1455 } |
|
1456 CleanupStack::PopAndDestroy( 2 ); // conn, serv |
|
1457 } |
|
1458 TInt newIapid( KErrNotFound ); |
|
1459 if ( sockIapid!=KErrNotFound ) newIapid = sockIapid; |
|
1460 if ( profIapid!=KErrNotFound ) newIapid = profIapid; |
|
1461 if ( aIapid !=KErrNotFound ) newIapid = aIapid; |
|
1462 |
|
1463 //Do some intelligent work during resume |
|
1464 /* Some rules.. |
|
1465 * 1. If IAP is always ask in DM profile, use the earlier set during FMS trigger |
|
1466 * 2. If IAP is always ask in DM profile, query user for IAP during user trigger |
|
1467 * 3. If IAP has changed in DM profile after suspend, use the newer one during resume |
|
1468 * 4. |
|
1469 */ |
|
1470 TInt active (KErrNotFound); |
|
1471 RProperty::Get( TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, active ); |
|
1472 FLOG(_L("active = %d"),active); |
|
1473 if (active==EFalse && iDLState.iState == RFotaEngineSession::EDownloadProgressingWithResume) |
|
1474 { |
|
1475 //Actual resume only |
|
1476 if (!iUserInitiatedResume && profIapid == KErrNotFound ) |
|
1477 { |
|
1478 //FMS triggered resume, apply Rule 1 |
|
1479 newIapid = iDLState.iIapId; |
|
1480 } |
|
1481 else if (profIapid == KErrNotFound) |
|
1482 { |
|
1483 //User triggered resume, apply Rule 2 |
|
1484 newIapid = KErrNotFound; |
|
1485 } |
|
1486 else if (profIapid != iDLState.iIapId) |
|
1487 { |
|
1488 //IAP has changed in DM profile, apply Rule 3 |
|
1489 newIapid = profIapid; |
|
1490 } |
|
1491 } |
|
1492 iDLState.iIapId = newIapid; |
|
1493 |
|
1494 |
|
1495 FLOG(_L("CFotaDownload::SetIapToUseL, iap = %d <<"), iDLState.iIapId); |
|
1496 } |
|
1497 |
|
1498 // -------------------------------------------------------------------------- |
|
1499 // CFotaDownload::SetDownloadUiBehavior |
|
1500 // Sets Download UI behavior. ex: DD display and Progress note |
|
1501 // -------------------------------------------------------------------------- |
|
1502 // |
|
1503 void CFotaDownload::SetDownloadUiBehavior(TBool aFreshDL) |
|
1504 { |
|
1505 FLOG(_L("CFotaDownload::SetDownloadUiBehavior, aFreshDL = %d >>"),aFreshDL); |
|
1506 |
|
1507 if (aFreshDL) //Fresh download |
|
1508 { |
|
1509 iDLState.iSessionType = iSanValue; |
|
1510 } |
|
1511 else //resuming download |
|
1512 { |
|
1513 iSanValue = iDLState.iSessionType; |
|
1514 } |
|
1515 |
|
1516 if ( !iIsjobStartedFromUI && iRestartCounter==0 ) //iRestartCounter to ensure that the UI behavior is read only once. |
|
1517 { |
|
1518 TInt behavior(KErrNotFound); |
|
1519 TInt sansupported(KErrNone); |
|
1520 |
|
1521 //Find whether SAN is supported or not |
|
1522 CRepository* centrep = NULL; |
|
1523 |
|
1524 TRAPD( err, centrep = CRepository::NewL( KCRUidDeviceManagementInternalKeys) ); |
|
1525 if( centrep ) centrep->Get( KDevManSANUIBitVariation, sansupported ); |
|
1526 delete centrep; centrep = NULL; |
|
1527 FLOG(_L("...1...")); |
|
1528 if (sansupported != 1) sansupported = 0; |
|
1529 |
|
1530 //Find the download ui behavior from fota cenrep |
|
1531 TRAP(err, centrep = CRepository::NewL( KCRUidFotaServer ) ); |
|
1532 if ( centrep ) centrep->Get( KSilentOmaDlUIBehavior, behavior ); |
|
1533 delete centrep; centrep = NULL; |
|
1534 |
|
1535 FLOG(_L("Values are... SAN enabled: %d, session type: %d, downloadbehavior: %d"),sansupported, iDLState.iSessionType,behavior); |
|
1536 |
|
1537 if (sansupported) //SAN is supported |
|
1538 { |
|
1539 |
|
1540 DetermineUISANON(behavior) ; |
|
1541 |
|
1542 } |
|
1543 else //SAN not supported |
|
1544 { |
|
1545 DetermineUISANOFF(behavior); |
|
1546 |
|
1547 } |
|
1548 } |
|
1549 else// if (iRestartCounter==0) //Started from DM UI, but not retry |
|
1550 { |
|
1551 iShowOMACDUI = ETrue; |
|
1552 iShowDLPrgUI = ETrue; |
|
1553 if (aFreshDL) |
|
1554 iDLState.iSessionType = KErrNotFound; |
|
1555 } |
|
1556 |
|
1557 TInt value (EFotaUpdateDM); |
|
1558 TInt err = RProperty::Get( KPSUidNSmlDMSyncApp, KNSmlCurrentFotaUpdateAppName, value ); |
|
1559 if (!err && ((value == EFotaUpdateNSC) || (value == EFotaUpdateNSCBg))) |
|
1560 { |
|
1561 iShowOMACDUI = EFalse; |
|
1562 iShowDLPrgUI = ETrue; |
|
1563 FLOG(_L("CFotaDownload::DownloadL UI will not be shown!")); |
|
1564 } |
|
1565 FLOG(_L("UI Behavior: OMA DD Display = %d, Download Progress = %d"),iShowOMACDUI,iShowDLPrgUI); |
|
1566 |
|
1567 FLOG(_L("CFotaDownload::SetDownloadUiBehavior <<")); |
|
1568 } |
|
1569 |
|
1570 |
|
1571 // -------------------------------------------------------------------------- |
|
1572 // CFotaDownload::DetermineUISANON |
|
1573 // Determine UI when SAN is ON |
|
1574 // -------------------------------------------------------------------------- |
|
1575 // |
|
1576 void CFotaDownload::DetermineUISANON(TInt aBehavior) |
|
1577 { |
|
1578 switch (aBehavior) |
|
1579 { |
|
1580 case EOmacdOffdlprgOff: //0 |
|
1581 { |
|
1582 iShowOMACDUI = EFalse; |
|
1583 iShowDLPrgUI = EFalse; |
|
1584 } |
|
1585 break; |
|
1586 case EOmacdOffdlprgOn: //1 |
|
1587 { |
|
1588 iShowOMACDUI = EFalse; |
|
1589 iShowDLPrgUI = ETrue; |
|
1590 } |
|
1591 break; |
|
1592 case EOmacdOndlprgOff: //2 |
|
1593 { |
|
1594 iShowOMACDUI = ETrue; |
|
1595 iShowDLPrgUI = EFalse; |
|
1596 } |
|
1597 break; |
|
1598 case EOmacdOndlprgOn: //3 |
|
1599 { |
|
1600 iShowOMACDUI = ETrue; |
|
1601 iShowDLPrgUI = ETrue; |
|
1602 } |
|
1603 break; |
|
1604 default: //includes EChooseFromSan |
|
1605 { |
|
1606 if(iSanValue == ESanSilent) |
|
1607 { |
|
1608 iShowOMACDUI = EFalse; |
|
1609 iShowDLPrgUI = EFalse; |
|
1610 } |
|
1611 else if (iSanValue == ESanInformative) |
|
1612 { |
|
1613 iShowOMACDUI = EFalse; |
|
1614 iShowDLPrgUI = ETrue; |
|
1615 } |
|
1616 else //includes ESanInteractive, ESanNotSpecified |
|
1617 { |
|
1618 iShowOMACDUI = ETrue; |
|
1619 iShowDLPrgUI = ETrue; |
|
1620 } |
|
1621 } |
|
1622 break; |
|
1623 } |
|
1624 |
|
1625 |
|
1626 } |
|
1627 |
|
1628 // -------------------------------------------------------------------------- |
|
1629 // CFotaDownload::DetermineUISANOFF |
|
1630 // Determine UI when SAN is OFF |
|
1631 // -------------------------------------------------------------------------- |
|
1632 // |
|
1633 |
|
1634 void CFotaDownload::DetermineUISANOFF(TInt aBehavior) |
|
1635 { |
|
1636 if (iSanValue==EAcceptedYes) //Accepted is Yes in Profile |
|
1637 { |
|
1638 switch (aBehavior) |
|
1639 { |
|
1640 case EOmacdOffdlprgOff: //0 |
|
1641 { |
|
1642 iShowOMACDUI = EFalse; |
|
1643 iShowDLPrgUI = EFalse; |
|
1644 } |
|
1645 break; |
|
1646 case EOmacdOffdlprgOn: //1 |
|
1647 { |
|
1648 iShowOMACDUI = EFalse; |
|
1649 iShowDLPrgUI = ETrue; |
|
1650 } |
|
1651 break; |
|
1652 case EOmacdOndlprgOff: //2 |
|
1653 { |
|
1654 iShowOMACDUI = ETrue; |
|
1655 iShowDLPrgUI = EFalse; |
|
1656 } |
|
1657 break; |
|
1658 default: //includes EOmacdOndlprgOn |
|
1659 { |
|
1660 iShowOMACDUI = ETrue; |
|
1661 iShowDLPrgUI = ETrue; |
|
1662 } |
|
1663 break; |
|
1664 } |
|
1665 } |
|
1666 else // includes iSanValue = EAcceptedNo (Accepted is No in profile) |
|
1667 { |
|
1668 iShowOMACDUI = ETrue; |
|
1669 iShowDLPrgUI = ETrue; |
|
1670 } |
|
1671 } |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 // -------------------------------------------------------------------------- |
|
1680 // CFotaDownload::RetrieveDownloadL |
|
1681 // Retrieves the RHttpDownload object from download manager during resume |
|
1682 // -------------------------------------------------------------------------- |
|
1683 // |
|
1684 RHttpDownload* CFotaDownload::RetrieveDownloadL() |
|
1685 { |
|
1686 FLOG(_L("CFotaDownload::RetrieveDownloadL >>")); |
|
1687 //Retrieve RHttpDownload object for the suspended download from Download Mgr. |
|
1688 if (!iDownloadMgr.Handle()) |
|
1689 iDownloadMgr.ConnectL( TUid::Uid(KFotaServerUid) , *this, EFalse); |
|
1690 const CDownloadArray& downloads = iDownloadMgr.CurrentDownloads(); |
|
1691 |
|
1692 TBuf8<KMaxPath> url8; |
|
1693 TInt32 val (KErrNone); |
|
1694 |
|
1695 RHttpDownload* aDownload (NULL); |
|
1696 for (TInt i = 0; i < downloads.Count(); i++ ) |
|
1697 { |
|
1698 User::LeaveIfError( downloads[i]->GetStringAttribute( EDlAttrCurrentUrl, url8 )); |
|
1699 User::LeaveIfError( downloads[i]->GetIntAttribute( EDlAttrFotaPckgId, val)); |
|
1700 |
|
1701 FLOG(_L("Current download(s) as per download mgr: %d, url = %S, pkgid = %d"), i+1, &url8, val); |
|
1702 |
|
1703 if (iDLState.iPkgId == val) |
|
1704 { |
|
1705 FLOG(_L("Successfully found the paused download object")); |
|
1706 aDownload = downloads[i]; |
|
1707 if ( iUrl ) {delete iUrl; iUrl=NULL;} |
|
1708 iUrl = url8.Alloc(); |
|
1709 |
|
1710 } |
|
1711 } |
|
1712 FLOG(_L("CFotaDownload::RetrieveDownloadL <<")); |
|
1713 return aDownload; |
|
1714 } |
|
1715 |
|
1716 // -------------------------------------------------------------------------- |
|
1717 // CFotaDownload::SetDownloadActive |
|
1718 // Sets the download activity state P&S key |
|
1719 // -------------------------------------------------------------------------- |
|
1720 // |
|
1721 void CFotaDownload::SetDownloadActive(TBool aValue) |
|
1722 { |
|
1723 FLOG(_L("CFotaDownload::SetDownloadActive, aValue = %d"),aValue); |
|
1724 iDownloadActive = aValue; |
|
1725 TBool val (EFalse); |
|
1726 TInt err = RProperty::Get(TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, val ); |
|
1727 |
|
1728 if (err == KErrNone && val != aValue) |
|
1729 { |
|
1730 err = RProperty::Set(TUid::Uid(KOmaDMAppUid), KFotaDownloadActive, aValue ); |
|
1731 FLOG(_L("RProperty KFotaDownloadActive Set %d, err = %d"), aValue, err); |
|
1732 } |
|
1733 |
|
1734 FLOG(_L("CFotaDownload::SetDownloadActive <<")); |
|
1735 } |
|
1736 |
|
1737 // -------------------------------------------------------------------------- |
|
1738 // IsDownloadActive |
|
1739 // Returns the activeness of the download |
|
1740 // -------------------------------------------------------------------------- |
|
1741 // |
|
1742 |
|
1743 TBool CFotaDownload::IsDownloadActive() |
|
1744 { |
|
1745 FLOG(_L("CFotaDownload::IsDownloadActive, value = %d"),iDownloadActive); |
|
1746 return iDownloadActive; |
|
1747 } |
|
1748 |
|
1749 |
|
1750 // -------------------------------------------------------------------------- |
|
1751 // CFotaDownloadNotifHandler::NewL |
|
1752 // -------------------------------------------------------------------------- |
|
1753 // |
|
1754 CFotaDownloadNotifHandler* CFotaDownloadNotifHandler::NewL (CFotaDownload* aDownload) |
|
1755 { |
|
1756 FLOG(_L("CFotaDownloadNotifHandler::NewL")); |
|
1757 __ASSERT_ALWAYS( aDownload, User::Panic(KFotaPanic, KErrArgument) ); |
|
1758 CFotaDownloadNotifHandler* h=new (ELeave)CFotaDownloadNotifHandler; |
|
1759 h->iDownload = aDownload; |
|
1760 h->iDownload->iFotaServer->iNotifHandler = h; |
|
1761 return h; |
|
1762 } |
|
1763 |
|
1764 // -------------------------------------------------------------------------- |
|
1765 CFotaDownloadNotifHandler::CFotaDownloadNotifHandler() : CActive(EPriorityNormal) |
|
1766 { |
|
1767 FLOG(_L("CFotaDownloadNotifHandler::CFotaDownloadNotifHandler()")); |
|
1768 CActiveScheduler::Add( this ); |
|
1769 } |
|
1770 |
|
1771 // -------------------------------------------------------------------------- |
|
1772 CFotaDownloadNotifHandler::~CFotaDownloadNotifHandler() |
|
1773 { |
|
1774 FLOG(_L("CFotaDownloadNotifHandler::~CFotaDownloadNotifHandler >>")); |
|
1775 iNotifier.Close(); |
|
1776 Cancel(); |
|
1777 FLOG(_L("CFotaDownloadNotifHandler::~CFotaDownloadNotifHandler <<")); |
|
1778 } |
|
1779 |
|
1780 // -------------------------------------------------------------------------- |
|
1781 void CFotaDownloadNotifHandler::RunL() |
|
1782 { |
|
1783 FLOG(_L("CFotaDownloadNotifHandler::RunL() note:%d, param:%d" ),iNotifParams.iNoteType, iNotifParams.iIntParam); |
|
1784 |
|
1785 TBool reset (ETrue); |
|
1786 |
|
1787 iNotifier.Close(); |
|
1788 |
|
1789 iDownload->SetDownloadActive(EFalse); |
|
1790 if ( iNotifParams.iNoteType == ESyncMLFwUpdErrorNote ) // 1 |
|
1791 { |
|
1792 //do nothing here |
|
1793 } |
|
1794 if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLNotEnoughMemory ) // 7 |
|
1795 { |
|
1796 //To be active as Flexible mem is in action. |
|
1797 if (iDownload->iFreshDL) |
|
1798 iDownload->SetDownloadActive(ETrue); |
|
1799 } |
|
1800 if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLUserCancel ) |
|
1801 { |
|
1802 //At this point Download Mgr has already paused the download successfully. |
|
1803 if (iStatus.Int() == KErrCancel) //RSK Press |
|
1804 { |
|
1805 //User wants to cancel download permanently. |
|
1806 FLOG(_L("User choose to cancel download permanently!")); |
|
1807 iDownload->RunDownloadCancelL(RFotaEngineSession::EResUserCancelled); |
|
1808 } |
|
1809 else |
|
1810 { |
|
1811 //Other keys pressed, like LSK or Call termination key |
|
1812 FLOG(_L("User choose to resume download later, key press = %d"),iStatus.Int()); |
|
1813 iDownload->iFotaServer->FinalizeDownloadL( iDownload->iDLState ); |
|
1814 if (iStatus.Int() == KErrNone) //RSK is pressed |
|
1815 { |
|
1816 LaunchNotifierL(ESyncMLFwUpdOmaDLPostponed, EFalse, EFalse); |
|
1817 reset = EFalse; |
|
1818 } |
|
1819 else |
|
1820 iDownload->iFotaServer->ShutApp(); |
|
1821 } |
|
1822 } |
|
1823 |
|
1824 if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLPostponed ) |
|
1825 { |
|
1826 //Nothing to do |
|
1827 } |
|
1828 |
|
1829 if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLCancelled ) |
|
1830 { |
|
1831 //Nothing to do |
|
1832 } |
|
1833 |
|
1834 if ( iNotifParams.iNoteType == ESyncMLFwUpdOmaDLResume ) |
|
1835 { |
|
1836 if (iStatus.Int() == KErrNone) // LSK Press |
|
1837 { |
|
1838 FLOG(_L("User choose to continue download now.")); |
|
1839 iNotifParams.iNoteType = ESyncMLFwUpdUnknown; |
|
1840 iNotifParams.iIntParam = 0; |
|
1841 iDownload->ResumeDownloadL(); |
|
1842 reset = EFalse; |
|
1843 } |
|
1844 else //RSK or any other key |
|
1845 { |
|
1846 FLOG(_L("User cancelled to continue download now, key press = %d."),iStatus.Int()); |
|
1847 if (iStatus.Int() == KErrCancel) //RSK is pressed |
|
1848 { |
|
1849 iDownload->iDLState.iResult = RFotaEngineSession::EResUserCancelled; |
|
1850 LaunchNotifierL(ESyncMLFwUpdOmaDLUserCancel, EFalse, EFalse); |
|
1851 reset = EFalse; |
|
1852 } |
|
1853 else |
|
1854 iDownload->iFotaServer->ShutApp(); |
|
1855 } |
|
1856 } |
|
1857 |
|
1858 if (reset) |
|
1859 { |
|
1860 iNotifParams.iNoteType = ESyncMLFwUpdUnknown; |
|
1861 iNotifParams.iIntParam = 0; |
|
1862 } |
|
1863 } |
|
1864 |
|
1865 // -------------------------------------------------------------------------- |
|
1866 TInt CFotaDownloadNotifHandler::RunError(TInt aError) |
|
1867 { |
|
1868 FLOG(_L("CFotaDownloadNotifHandler::RunError %d"),aError); |
|
1869 return aError; |
|
1870 } |
|
1871 |
|
1872 // -------------------------------------------------------------------------- |
|
1873 void CFotaDownloadNotifHandler::DoCancel() |
|
1874 { |
|
1875 FLOG(_L("CFotaDownloadNotifHandler::DoCancel >>")); |
|
1876 if (iNotifier.Handle()) |
|
1877 { |
|
1878 iNotifier.CancelNotifier( KSyncMLFwUpdNotifierUid ); |
|
1879 iNotifier.Close(); |
|
1880 } |
|
1881 FLOG(_L("CFotaDownloadNotifHandler::DoCancel <<")); |
|
1882 } |
|
1883 |
|
1884 // -------------------------------------------------------------------------- |
|
1885 void CFotaDownloadNotifHandler::LaunchNotifierL( const TSyncMLFwUpdNoteTypes aNotetype |
|
1886 ,const TInt aIntParam |
|
1887 , const TInt aMemoryNeeded |
|
1888 ,TBool aFinishOnly) |
|
1889 { |
|
1890 FLOG(_L("CFotaDownloadNotifHandler::LaunchNotifierL, aNoteType=%d, aParam=%d, aMemoryNeeded=%d aFinishOnly=%d >> "), aNotetype, aIntParam, aMemoryNeeded, aFinishOnly?1:0); |
|
1891 |
|
1892 __ASSERT_ALWAYS( iNotifier.Handle()==0, User::Leave(KErrAlreadyExists) ); |
|
1893 __ASSERT_ALWAYS( aMemoryNeeded>=0, User::Leave(KErrArgument) ); |
|
1894 |
|
1895 |
|
1896 // Launch notifier |
|
1897 TSyncMLFwUpdNotifParams params; |
|
1898 FLOG(_L(" 1")); |
|
1899 params.iNoteType = aNotetype; |
|
1900 params.iIntParam = aIntParam; |
|
1901 |
|
1902 TInt rem = 0; |
|
1903 rem = aMemoryNeeded % 1024 ; |
|
1904 if (rem) |
|
1905 { |
|
1906 params.iMemoryNeeded = (aMemoryNeeded /1024) + 1; |
|
1907 } |
|
1908 else |
|
1909 { |
|
1910 params.iMemoryNeeded = (aMemoryNeeded /1024) ; |
|
1911 } |
|
1912 |
|
1913 // #endif |
|
1914 TSyncMLFwUpdNotifParamsPckg pckg(params); |
|
1915 iNotifParams.iNoteType = params.iNoteType; |
|
1916 iNotifParams.iIntParam = params.iIntParam; |
|
1917 |
|
1918 iNotifParams.iMemoryNeeded = params.iMemoryNeeded; |
|
1919 |
|
1920 iDummyResponsePckg = TSyncMLFwUpdNotifRetValPckg(); |
|
1921 FLOG(_L(" 2")); |
|
1922 if ( !aFinishOnly ) |
|
1923 { |
|
1924 User::LeaveIfError( iNotifier.Connect() ); |
|
1925 iNotifier.StartNotifierAndGetResponse( iStatus, KSyncMLFwUpdNotifierUid |
|
1926 , pckg, iDummyResponsePckg ); |
|
1927 SetActive(); |
|
1928 } |
|
1929 else |
|
1930 { |
|
1931 iStatus = KRequestPending; |
|
1932 SetActive(); |
|
1933 TRequestStatus* status = &iStatus; |
|
1934 User::RequestComplete( status, KErrNone ); |
|
1935 } |
|
1936 FLOG(_L(" 3 %d"),iStatus.Int()); |
|
1937 FLOG(_L("CFotaDownloadNotifHandler::LaunchNotifierL() <<")); |
|
1938 } |
|
1939 |
|
1940 TBool CFotaDownloadNotifHandler::IsOpen() |
|
1941 { |
|
1942 FLOG(_L("Handle = %d"), iNotifier.Handle()); |
|
1943 return (iNotifier.Handle())? ETrue:EFalse; |
|
1944 } |
|