|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Implementation of applicationmanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 //#include <DownloadMgrClient.h> |
|
20 |
|
21 #include "AMDownloadManager.h" |
|
22 //#include "AMDownload.h" |
|
23 //#include "amdeploymentcomponent.h" |
|
24 #include "amsmlhelper.h" |
|
25 #include "debug.h" |
|
26 #include "AppMgmtSrvApp.h" |
|
27 #include <e32property.h> |
|
28 #include <aknnotewrappers.h> |
|
29 #include "ampskeys.h" |
|
30 #include "SyncService.h" |
|
31 #include "amprivateCRKeys.h" |
|
32 |
|
33 using namespace NApplicationManagement; |
|
34 |
|
35 // from THttpDownloadState |
|
36 const TText * KDownloadStates[] = |
|
37 { |
|
38 _S( "Empty" ), _S( "EHttpDlCreated" ), _S( "EHttpDlInprogress" ), _S( "EHttpDlPaused" ), _S( "EHttpDlCompleted" ), _S( "EHttpDlFailed" ), |
|
39 |
|
40 // The following states are temporary. |
|
41 // e.g. download adopt EHttpDlMoved state, |
|
42 // but right after that, it returns to the |
|
43 // original EHttpDlCompleted state |
|
44 |
|
45 // download is moved from one client instance to another one. |
|
46 _S( "EHttpDlMoved" ), |
|
47 // MMC card or other storage media is removed from the phone. |
|
48 _S( "EHttpDlMediaRemoved" ), |
|
49 // MMC card or other storage media inserted and |
|
50 // downloaded content file found on it. |
|
51 // If MMC card inserted, but (partially) downloaded content file |
|
52 // is not found on it, download is failed with error reason |
|
53 // EContentFileIntegrity. |
|
54 _S( "EHttpDlMediaInserted" ), |
|
55 // Download process can be paused again. This event only occurs after |
|
56 // EHttpDlNonPausable. |
|
57 _S( "EHttpDlPausable" ), |
|
58 // Download process cannot be paused, or the content will be lost. |
|
59 _S( "EHttpDlNonPausable" ), |
|
60 // Download is delete from another client instance. |
|
61 _S( "EHttpDlDeleted" ), |
|
62 // Download is started when it's already progressing |
|
63 _S( "EHttpDlAlreadyRunning" ), |
|
64 // Download is going to be deleted. |
|
65 _S( "EHttpDlDeleting" ), |
|
66 |
|
67 // Internally used download event. Do NOT deal with them |
|
68 _S( "EHttpDlCancelTransaction" ) |
|
69 }; |
|
70 |
|
71 // These enumarated values come with EHttpDlInprogress |
|
72 // The only exception is EHttpContentTypeReceived that pauses |
|
73 // the download until client app accepts and resumes, or |
|
74 // deletes/resets it. |
|
75 const TText * ProgStates(THttpProgressState state) |
|
76 { |
|
77 switch (state) |
|
78 { |
|
79 case EHttpProgNone: |
|
80 return _S( "EHttpProgNone" ); |
|
81 case EHttpStarted: |
|
82 return _S("EHttpStarted"); |
|
83 case EHttpProgCreatingConnection: |
|
84 return _S("EHttpProgCreatingConnection"); |
|
85 case EHttpProgConnectionNeeded: |
|
86 return _S("EHttpProgConnectionNeeded"); |
|
87 |
|
88 case EHttpProgConnected: |
|
89 return _S("EHttpProgConnected"); |
|
90 case EHttpProgConnectionSuspended: |
|
91 return _S("EHttpProgConnectionSuspended"); |
|
92 case EHttpProgDisconnected: |
|
93 return _S("EHttpProgDisconnected"); |
|
94 case EHttpProgDownloadStarted: |
|
95 return _S("EHttpProgDownloadStarted" ); |
|
96 case EHttpContentTypeRequested: |
|
97 return _S("EHttpContentTypeRequested" ); |
|
98 case EHttpContentTypeReceived: |
|
99 // Download status is EHttpDlPaused! |
|
100 // Application can check the received content type here |
|
101 // and decide whether to accept it or not. |
|
102 // Call Start again to carry on download, or |
|
103 // Delete to delete this download |
|
104 return _S("EHttpContentTypeReceived" ); |
|
105 case EHttpProgSubmitIssued: |
|
106 return _S("EHttpProgSubmitIssued" ); |
|
107 case EHttpProgResponseHeaderReceived: |
|
108 return _S("EHttpProgResponseHeaderReceived" ); |
|
109 case EHttpProgResponseBodyReceived: |
|
110 return _S("EHttpProgResponseBodyReceived" ); |
|
111 case EHttpProgRedirectedPermanently: |
|
112 return _S("EHttpProgRedirectedPermanently" ); |
|
113 case EHttpProgRedirectedTemporarily: |
|
114 return _S("EHttpProgRedirectedTemporarily" ); |
|
115 case EHttpProgMovingContentFile: |
|
116 return _S("EHttpProgMovingContentFile" ); |
|
117 case EHttpProgContentFileMoved: |
|
118 return _S("EHttpProgContentFileMoved" ); |
|
119 default: |
|
120 return _S( "Unknown" ); |
|
121 } |
|
122 } |
|
123 |
|
124 // ============================ MEMBER FUNCTIONS =============================== |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CAMDownloadManager::CAMDownloadManager |
|
128 // C++ default constructor can NOT contain any code, that |
|
129 // might leave. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 CAMDownloadManager::CAMDownloadManager(MDownloadMngrObserver& aObserver) : |
|
133 iObserver(aObserver) |
|
134 { |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CAMDownloadManager::ConstructL |
|
139 // Symbian 2nd phase constructor can leave. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CAMDownloadManager::ConstructL() |
|
143 { |
|
144 iOMASCOMOEnabled = ETrue; |
|
145 iNoteDisabled = EFalse; |
|
146 |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CAMDownloadManager::NewL |
|
151 // Two-phased constructor. |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 CAMDownloadManager* CAMDownloadManager::NewL(MDownloadMngrObserver& aObserver) |
|
155 { |
|
156 CAMDownloadManager* self = new( ELeave ) CAMDownloadManager( aObserver ); |
|
157 |
|
158 CleanupStack::PushL(self); |
|
159 self->ConstructL(); |
|
160 CleanupStack::Pop(); |
|
161 |
|
162 return self; |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // Destructor |
|
167 // --------------------------------------------------------------------------- |
|
168 CAMDownloadManager::~CAMDownloadManager() |
|
169 { |
|
170 RDEBUG_3( "CAMDownloadManager::~CAMDownloadManager 0x%X - 0x%X", reinterpret_cast<TUint>( this ), |
|
171 reinterpret_cast<TUint>(this)+sizeof( CAMDownloadManager ) ); |
|
172 |
|
173 iDownloads.ResetAndDestroy(); |
|
174 |
|
175 iPrevDownloads.ResetAndDestroy(); |
|
176 |
|
177 RDEBUG( "CAMDownloadManager::~CAMDownloadManager() - closing downloadmgr" ); |
|
178 if (iDownloadMgr.Handle()) |
|
179 iDownloadMgr.Close(); |
|
180 |
|
181 |
|
182 if (iServerId) |
|
183 delete iServerId; |
|
184 |
|
185 |
|
186 RDEBUG( "CAMDownloadManager::~CAMDownloadManager() - closed downloadmgr" ); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // CancelDownloads |
|
191 // --------------------------------------------------------------------------- |
|
192 /* |
|
193 void CAMDownloadManager::CancelDownloads() |
|
194 { |
|
195 TInt err = KErrNone; |
|
196 TRAP( err, CancelDownloadsL() ); |
|
197 RDEBUG_2("CAMDownloadManager::Cancel() ERR(%d)", err); |
|
198 User::LeaveIfError( err ); |
|
199 } |
|
200 */ |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CancelDownloads |
|
204 // --------------------------------------------------------------------------- |
|
205 /* |
|
206 void CAMDownloadManager::CancelDownloadsL() |
|
207 { |
|
208 } |
|
209 */ |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // CancelDownloadL |
|
213 // --------------------------------------------------------------------------- |
|
214 void CAMDownloadManager::CancelDownloadL(CAMDownload& aDownload) |
|
215 { |
|
216 RDEBUG("CAMDownloadManager::CancelDownloadL()"); |
|
217 ConnectHttpDownloadMgrL(); |
|
218 |
|
219 TInt delres(aDownload.StopDownload() ); |
|
220 if (delres != KErrNone) |
|
221 { |
|
222 RDEBUG8_3( "CAMDownloadManager::CancelDownloadL: ERROR Failed to delete download '%S': '%d'", |
|
223 &aDownload.DownloadURI(), delres ); |
|
224 } |
|
225 } |
|
226 |
|
227 // ------------------------------------------------------------------------------------------------ |
|
228 // CAMDownloadManager::ConnectHttpDownloadMgrL() |
|
229 // ------------------------------------------------------------------------------------------------ |
|
230 void CAMDownloadManager::ConnectHttpDownloadMgrL() |
|
231 { |
|
232 if ( !iDownloadMgrConnected) |
|
233 { |
|
234 const TUid KUid = |
|
235 { |
|
236 0x1020781C |
|
237 // ApplicationManagementServer |
|
238 }; |
|
239 |
|
240 iDownloadMgr.ConnectL(KUid, *this, EFalse); |
|
241 iDownloadMgrConnected = ETrue; |
|
242 RDEBUG( "CAMDownloadManager::ConnectHttpDownloadMgrL(): Connected to download manager" ); |
|
243 } |
|
244 } |
|
245 |
|
246 // ---------------------------------------------------------------------------------------- |
|
247 // CAMDownloadManager::AddDownloadL |
|
248 // ---------------------------------------------------------------------------------------- |
|
249 void CAMDownloadManager::AddDownloadL(CDeploymentComponent *aComponent) |
|
250 { |
|
251 RDEBUG("CAMDownloadManager::AddDownloadL Add new Download: "); |
|
252 TPtrC8 uriPtr(aComponent->DownloadURI() ); |
|
253 RDEBUG_HEX8(uriPtr.Ptr(), uriPtr.Size()); |
|
254 aComponent->SetCallback( this); |
|
255 CAMDownload* download = 0; |
|
256 download = FindDownload(aComponent->DownloadURI() ); |
|
257 if (download) |
|
258 { |
|
259 RDEBUG8_2("CAMDownloadManager::AddDownloadL Download already exist, cancelling: (%S)", &aComponent->DownloadURI()); |
|
260 CancelDownloadL( *download); |
|
261 } |
|
262 |
|
263 iNoteDisabled = EFalse; |
|
264 |
|
265 // DM session alive. Check the type of Server Alert |
|
266 // Silent or NOn-Silent |
|
267 |
|
268 |
|
269 // PubSub key used to share information about the |
|
270 // type of the server alert for device management session. |
|
271 // Contains the identifier of server alert type |
|
272 // started from DM Server |
|
273 |
|
274 |
|
275 TInt nonSilentOperation = KErrNotFound; |
|
276 RProperty::Get(KPSUidNSmlDMSyncApp, KSilentSession, nonSilentOperation); |
|
277 |
|
278 iOMASCOMOEnabled = IsOMASCOMOEnabledL(); |
|
279 |
|
280 // If OMA SCOMO is not enabled then default make the download operation silent |
|
281 if (!iOMASCOMOEnabled) |
|
282 nonSilentOperation = 0; |
|
283 |
|
284 // Get the type of session(silent or non-silent) from DM Session and store in AM server |
|
285 // P&S key since DM Session is terminated as soon as download starts. |
|
286 |
|
287 RProperty::Set(KUidPSApplicationManagementKeys, KAMOperationNonSilent, |
|
288 nonSilentOperation); |
|
289 |
|
290 // Set this P&S key so that DM UI will not be closed in case of server initiated session |
|
291 // applicable only for Interactive, Informative or Non specified |
|
292 |
|
293 TInt dmuinotclosed = 1; |
|
294 RProperty::Set(KUidPSApplicationManagementKeys, KDMUINotClosed, |
|
295 dmuinotclosed); |
|
296 |
|
297 RHttpDownload& httpdownload(CreateHttpDownloadL(aComponent) ); |
|
298 |
|
299 |
|
300 CAMDownload* newDL = CAMDownload::NewL(httpdownload, aComponent); |
|
301 CleanupStack::PushL(newDL); |
|
302 iDownloads.Append(newDL); |
|
303 |
|
304 // keep track of all the downloads in another array |
|
305 // to ensure that downloads are not missed from actual array |
|
306 // during cleanup |
|
307 |
|
308 iPrevDownloads.Append(newDL); |
|
309 |
|
310 // start the newly created download |
|
311 newDL->StartDownload(); |
|
312 aComponent->SetStatusNode(EDownload_DownloadProgress); |
|
313 TSmlProfileId ownerProfile; |
|
314 SyncMLCurrentProfileIdL(ownerProfile); |
|
315 aComponent->SetOwnerProfile(ownerProfile); |
|
316 CleanupStack::Pop(newDL); |
|
317 |
|
318 |
|
319 RDEBUG("CAMDownloadManager::AddDownloadL end"); |
|
320 } |
|
321 |
|
322 // ------------------------------------------------------------------------------------------------ |
|
323 // CAMDownloadManager::IsOMASCOMOEnabledL() |
|
324 // ------------------------------------------------------------------------------------------------ |
|
325 |
|
326 TBool CAMDownloadManager::IsOMASCOMOEnabledL() |
|
327 { |
|
328 TInt adapterValue; |
|
329 |
|
330 CRepository *repository = CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys ) ; |
|
331 repository->Get(KAMAdapterValue, adapterValue); |
|
332 CleanupStack::PopAndDestroy(); |
|
333 |
|
334 if(adapterValue ==0 || adapterValue == 1) |
|
335 return EFalse; |
|
336 else |
|
337 return ETrue; |
|
338 |
|
339 } |
|
340 |
|
341 |
|
342 // ---------------------------------------------------------------------------------------- |
|
343 // CAMDownloadManager::CreateHttpDownloadL |
|
344 // ---------------------------------------------------------------------------------------- |
|
345 RHttpDownload& CAMDownloadManager::CreateHttpDownloadL( |
|
346 CDeploymentComponent *aComponent) |
|
347 { |
|
348 RDEBUG( "CAMDownloadManager::CreateHttpDownload: start" ); |
|
349 ConnectHttpDownloadMgrL(); |
|
350 TBool dlCreated(EFalse); |
|
351 RHttpDownload &dl = iDownloadMgr.CreateDownloadL( |
|
352 aComponent->DownloadURI(), dlCreated); |
|
353 iServerId = SmlHelper::GetCurrentServerIDL(); |
|
354 if (dlCreated) |
|
355 { |
|
356 RDEBUG( "CAMDownloadManager::CreateHttpDownload: Created Download" ); |
|
357 dl.SetBoolAttribute(EDlAttrNoContentTypeCheck, ETrue); |
|
358 iDownloadMgr.SetBoolAttribute(EDlMgrSilentMode, ETrue); |
|
359 SetIAPL(aComponent); |
|
360 SetUserNamePassword(dl, aComponent); |
|
361 } |
|
362 else |
|
363 { |
|
364 RDEBUG( "CAMDownloadManager::CreateHttpDownload: Download already exists!" ); |
|
365 THttpDownloadState dlst; |
|
366 dl.GetIntAttribute(EDlAttrState, (TInt32&)dlst ); |
|
367 THttpProgressState prst; |
|
368 dl.GetIntAttribute(EDlAttrProgressState, (TInt32&)prst ); |
|
369 |
|
370 SetIAPL(aComponent); |
|
371 RDEBUG_3( "CAMDownloadManager::CreateHttpDownload: DownloadState: '%s', progstate: '%s'", KDownloadStates[dlst], ProgStates( prst ) ); |
|
372 |
|
373 if (dlst == EHttpDlPaused) |
|
374 { |
|
375 RDEBUG( "CAMDownloadManager::CreateHttpDownload: download paused" ); |
|
376 } |
|
377 else |
|
378 { |
|
379 RDEBUG( "CAMDownloadManager::CreateHttpDownload: resetting download!" ); |
|
380 dl.Reset(); |
|
381 } |
|
382 } |
|
383 RDEBUG( "CAMDownloadManager::CreateHttpDownload: end" ); |
|
384 return dl; |
|
385 } |
|
386 |
|
387 // ---------------------------------------------------------------------------------------- |
|
388 // CAMDownloadManager::SetIAPL |
|
389 // ---------------------------------------------------------------------------------------- |
|
390 void CAMDownloadManager::SetIAPL(CDeploymentComponent *aComponent) |
|
391 { |
|
392 RDEBUG( "CAMDownloadManager::SetIAPL: start" ); |
|
393 TInt iap(KErrNotFound); |
|
394 |
|
395 const TAMInstallOptions &opts = aComponent->InstallOpts(); |
|
396 RDEBUG_2( "CAMDownloadManager::SetIAPL : Setting Iap Id to %d ", opts.iIAP ); |
|
397 |
|
398 if (opts.iIAP == -1) |
|
399 { |
|
400 TRAPD( err, SmlHelper::GetDefaultIAPFromDMProfileL( iap ) ) |
|
401 ; |
|
402 if (err != KErrNone) |
|
403 { |
|
404 RDEBUG_2("CAMDownloadManager::SetIAPL: ERROR when trying to fetch DM profile default IAP: %d", err ); |
|
405 } |
|
406 } |
|
407 else |
|
408 { |
|
409 iap = opts.iIAP; |
|
410 } |
|
411 if (iap == -1) |
|
412 { |
|
413 iap = 0; //as DL mgr treats 0 (zero) as "Always Ask" |
|
414 } |
|
415 iapid = iap; |
|
416 TInt errDL(iDownloadMgr.SetIntAttribute(EDlMgrIap, iap) ); |
|
417 if (errDL != KErrNone) |
|
418 { |
|
419 RDEBUG_2("CAMDownloadManager::SetIAPL: ERROR when trying to set DownloadManager IAP: %d", errDL ); |
|
420 } |
|
421 else |
|
422 { |
|
423 RDEBUG_2( "CAMDownloadManager::SetIAPL: Set IAP Id to (%d) ", iap); |
|
424 } |
|
425 |
|
426 #ifdef _DEBUG |
|
427 TInt err(iDownloadMgr.SetIntAttribute(EDlMgrIap, 11) ); |
|
428 RDEBUG_2( "CAMDownloadManager::SetIAPL (debug only): WARNING Overriding IAP Id to 11 results %d", err ); |
|
429 #endif |
|
430 } |
|
431 |
|
432 // ---------------------------------------------------------------------------------------- |
|
433 // CAMDownloadManager::SetUserNamePassword |
|
434 // ---------------------------------------------------------------------------------------- |
|
435 void CAMDownloadManager::SetUserNamePassword(RHttpDownload& aDownload, |
|
436 CDeploymentComponent *aComponent) |
|
437 { |
|
438 RDEBUG( "CAMDownloadManager::SetUserNamePassword: start" ); |
|
439 const TAMInstallOptions &opts = aComponent->InstallOpts(); |
|
440 if (opts.iOptions.iPassword.Length() && opts.iOptions.iLogin.Length() ) |
|
441 { |
|
442 TBuf8<KMaxPath> password; |
|
443 TBuf8<KMaxPath> login; |
|
444 password.Copy(opts.iOptions.iPassword); |
|
445 login.Copy(opts.iOptions.iLogin); |
|
446 |
|
447 TInt err(aDownload.SetStringAttribute(EDlAttrPassword, password) ); |
|
448 RDEBUG8_3( "CAMDownloadManager::SetUserNamePassword: response to EDlAttrPassword set to '%S': %d", &password, err ); |
|
449 err = aDownload.SetStringAttribute(EDlAttrUsername, login); |
|
450 RDEBUG8_3( "CAMDownloadManager::SetUserNamePassword: response to EDlAttrUsername set to '%S': %d", &login, err ); |
|
451 } |
|
452 RDEBUG( "CAMDownloadManager::SetUserNamePassword: end" ); |
|
453 } |
|
454 |
|
455 // ---------------------------------------------------------------------------------------- |
|
456 // CAMDownloadManager::SyncMLCurrentProfileIdL |
|
457 // ---------------------------------------------------------------------------------------- |
|
458 void CAMDownloadManager::SyncMLCurrentProfileIdL(TSmlProfileId& aOwnerProfile) |
|
459 { |
|
460 RDEBUG( "CAMDownloadManager::SyncMLCurrentProfileIdL: start" ); |
|
461 #ifdef _DEBUG |
|
462 TRAPD( erx, SmlHelper::GetCurrentProfileIdL( aOwnerProfile ) ) |
|
463 ; |
|
464 if (erx != KErrNone) |
|
465 { |
|
466 RDEBUG_2( "CAMDownloadManager::SyncMLCurrentProfileIdL (debug): Failed to get profile id: %d", erx ); |
|
467 } |
|
468 else |
|
469 { |
|
470 RDEBUG_2( "CAMDownloadManager::SyncMLCurrentProfileIdL (debug): Using profile id: %d", aOwnerProfile ); |
|
471 } |
|
472 #else |
|
473 SmlHelper::GetCurrentProfileIdL( aOwnerProfile ); |
|
474 RDEBUG_2( "CAMDownloadManager::SyncMLCurrentProfileIdL: Find profile id: %d", aOwnerProfile ); |
|
475 #endif |
|
476 } |
|
477 |
|
478 // ---------------------------------------------------------------------------------------- |
|
479 // CAMDownloadManager::FindDownload |
|
480 // ---------------------------------------------------------------------------------------- |
|
481 CAMDownload* CAMDownloadManager::FindDownload(const TDesC8& aURI) |
|
482 { |
|
483 CAMDownload* download = 0; |
|
484 |
|
485 //find corresponding download from list |
|
486 for (TInt i(0); i < iDownloads.Count(); i++) |
|
487 { |
|
488 download = iDownloads[i]; |
|
489 if (download->DownloadURIMatch(aURI) ) |
|
490 { |
|
491 RDEBUG("CAMDownloadManager::FindDownload: Found valid download"); |
|
492 break; |
|
493 } |
|
494 download = 0; |
|
495 } |
|
496 return download; |
|
497 } |
|
498 |
|
499 // ---------------------------------------------------------------------------------------- |
|
500 // CAMDownloadManager::FindDownload |
|
501 // ---------------------------------------------------------------------------------------- |
|
502 CAMDownload* CAMDownloadManager::FindDownload(RHttpDownload& aDownload) |
|
503 { |
|
504 CAMDownload* download = 0; |
|
505 TBuf8<KMaxUrlLength> uri; |
|
506 DownloadURI(aDownload, uri); |
|
507 download = FindDownload(uri); |
|
508 return download; |
|
509 } |
|
510 |
|
511 // ---------------------------------------------------------------------------------------- |
|
512 // CAMDownloadManager::FindDownload |
|
513 // ---------------------------------------------------------------------------------------- |
|
514 CAMDownload* CAMDownloadManager::FindDownload( |
|
515 CDeploymentComponent *aComponent) |
|
516 { |
|
517 CAMDownload* download = 0; |
|
518 download = FindDownload(aComponent->DownloadURI() ); |
|
519 return download; |
|
520 } |
|
521 |
|
522 // ---------------------------------------------------------------------------------------- |
|
523 // CAMDownloadManager::DownloadURI |
|
524 // ---------------------------------------------------------------------------------------- |
|
525 void CAMDownloadManager::DownloadURI(RHttpDownload& aDownload, TDes8& aURI) |
|
526 { |
|
527 TInt err(aDownload.GetStringAttribute(EDlAttrReqUrl, aURI) ); |
|
528 RDEBUG_2("CAMDownloadManager::DownloadURI err: (%d)", err); |
|
529 } |
|
530 |
|
531 // ---------------------------------------------------------------------------------------- |
|
532 // CAMDownloadManager::HandleDMgrEventL |
|
533 // ---------------------------------------------------------------------------------------- |
|
534 void CAMDownloadManager::HandleDMgrEventL(RHttpDownload& aDownload, |
|
535 THttpDownloadEvent aEvent) |
|
536 { |
|
537 //RDEBUG_3( "CAMDownloadManager::HandleDMgrEventL: DownloadState: '%s', progstate: '%s'", |
|
538 // KDownloadStates[aEvent.iDownloadState], ProgStates( aEvent.iProgressState ) ); |
|
539 |
|
540 TInt32 contentsize; |
|
541 TInt32 downloadedsize; |
|
542 |
|
543 User::LeaveIfError(aDownload.GetIntAttribute(EDlAttrDownloadedSize, |
|
544 downloadedsize) ); |
|
545 User::LeaveIfError(aDownload.GetIntAttribute(EDlAttrLength, contentsize) ); |
|
546 |
|
547 CAMDownload* download = FindDownload(aDownload); |
|
548 |
|
549 if ( !download) |
|
550 { |
|
551 TBuf8<KMaxUrlLength> uri; |
|
552 DownloadURI(aDownload, uri); |
|
553 RDEBUG8_2("CAMDownloadManager::HandleDMgrEventL: Could not find download: (%S)", &uri); |
|
554 //User::Leave( KErrNotFound ); // Don't do this! DownloadMgrClient::HandleDMgrEventL does not handle leave correctly. |
|
555 } |
|
556 else |
|
557 { |
|
558 switch (aEvent.iDownloadState) |
|
559 { |
|
560 /* case EHttpDlPaused: |
|
561 HandlePausedEventL( *download); |
|
562 break;*/ |
|
563 case EHttpDlCreated: |
|
564 { |
|
565 if (aEvent.iProgressState == EHttpProgNone) |
|
566 { |
|
567 HandleNonProgEventL( *download); |
|
568 } |
|
569 } |
|
570 break; |
|
571 case EHttpDlInprogress: |
|
572 { |
|
573 HandleAlreadyRunningL(downloadedsize, contentsize, *download, aEvent.iProgressState); |
|
574 |
|
575 if (!iNoteDisabled) |
|
576 { |
|
577 CSyncService *syncService = |
|
578 CSyncService::NewL(NULL, KDevManServiceStart); |
|
579 if (syncService) |
|
580 { |
|
581 syncService->EnableProgressNoteL(EFalse); |
|
582 } |
|
583 |
|
584 delete syncService; |
|
585 iNoteDisabled = ETrue; |
|
586 } |
|
587 } |
|
588 break; |
|
589 case EHttpContentTypeReceived: |
|
590 HandleContentTypeRecEventL( *download); |
|
591 break; |
|
592 case EHttpDlCompleted: |
|
593 HandleDlCompletedEventL( *download); |
|
594 break; |
|
595 case EHttpDlPaused: |
|
596 case EHttpDlFailed: |
|
597 HandleDlFailedEventL( *download, aEvent.iDownloadState); |
|
598 break; |
|
599 case EHttpDlDeleting: |
|
600 case EHttpDlDeleted: |
|
601 HandleDlDeleteEventL(download); |
|
602 break; |
|
603 default: |
|
604 /* RDEBUG8_2( "CAMDownloadManager::HandleDMgrEventL: Not handled download event: (%S)", |
|
605 KDownloadStates[aEvent.iDownloadState] ); |
|
606 |
|
607 */ |
|
608 break; |
|
609 } |
|
610 } |
|
611 RDEBUG( "CAMDownloadManager::HandleDMgrEventL: end" ); |
|
612 } |
|
613 |
|
614 // ---------------------------------------------------------------------------------------- |
|
615 // CAMDownloadManager::HandlePausedEventL |
|
616 // ---------------------------------------------------------------------------------------- |
|
617 void CAMDownloadManager::HandlePausedEventL(CAMDownload& aDownload) |
|
618 { |
|
619 RDEBUG( "CAMDownloadManager::HandlePausedEventL" ); |
|
620 aDownload.ContinueDownload(); |
|
621 } |
|
622 |
|
623 // ---------------------------------------------------------------------------------------- |
|
624 // CAMDownloadManager::HandleNonProgEventL |
|
625 // ---------------------------------------------------------------------------------------- |
|
626 void CAMDownloadManager::HandleNonProgEventL(CAMDownload& aDownload) |
|
627 { |
|
628 RDEBUG( "CAMDownloadManager::HandleNonProgEventL" ); |
|
629 aDownload.ContinueDownload(); |
|
630 } |
|
631 |
|
632 // ---------------------------------------------------------------------------------------- |
|
633 // CAMDownloadManager::HandleContentTypeRecEventL |
|
634 // ---------------------------------------------------------------------------------------- |
|
635 void CAMDownloadManager::HandleContentTypeRecEventL(CAMDownload& aDownload) |
|
636 { |
|
637 RDEBUG( "CAMDownloadManager::HandleContentTypeRecEventL: EHttpContentTypeReceived " ); |
|
638 const TDesC8& mimetype(aDownload.ContentMimeType() ); |
|
639 RDEBUG8_2( "CAMDownloadManager::HandleContentTypeRecEventL: Content type: (%S)", &mimetype ); |
|
640 } |
|
641 |
|
642 // ---------------------------------------------------------------------------------------- |
|
643 // CAMDownloadManager::HandleDlCompletedEventL |
|
644 // ---------------------------------------------------------------------------------------- |
|
645 void CAMDownloadManager::HandleDlCompletedEventL(CAMDownload& aDownload) |
|
646 { |
|
647 RDEBUG( "CAMDownloadManager::HandleDlCompletedEventL" ); |
|
648 aDownload.DownloadCompleted(); |
|
649 } |
|
650 |
|
651 // ---------------------------------------------------------------------------------------- |
|
652 // CAMDownloadManager::HandleDlFailedEventL |
|
653 // ---------------------------------------------------------------------------------------- |
|
654 void CAMDownloadManager::HandleDlFailedEventL(CAMDownload& aDownload, THttpDownloadState aDownloadState) |
|
655 { |
|
656 RDEBUG( "CAMDownloadManager::HandleDlFailedEventL" ); |
|
657 aDownload.DownloadFailedL(aDownloadState); |
|
658 } |
|
659 |
|
660 // ---------------------------------------------------------------------------------------- |
|
661 // CAMDownloadManager::HandleDlDeleteEventL |
|
662 // ---------------------------------------------------------------------------------------- |
|
663 void CAMDownloadManager::HandleDlDeleteEventL(CAMDownload* aDownload) |
|
664 { |
|
665 RDEBUG( "CAMDownloadManager::HandleDlDeleteEventL - start" ); |
|
666 TInt idx(iDownloads.Find(aDownload) ); |
|
667 { |
|
668 RDEBUG_2( "CAMDownloadManager::HandleDlDeleteEventL found download: (%d) delete it", idx ); |
|
669 iDownloads.Remove(idx); |
|
670 // delete aDownload; |
|
671 } |
|
672 RDEBUG( "CAMDownloadManager::HandleDlDeleteEventL - end" ); |
|
673 } |
|
674 |
|
675 // ---------------------------------------------------------------------------------------- |
|
676 // CAMDownloadManager::DownloadComplete |
|
677 // ---------------------------------------------------------------------------------------- |
|
678 void CAMDownloadManager::DownloadComplete(CDeploymentComponent *aComponent, |
|
679 TInt aStatus) |
|
680 { |
|
681 RDEBUG_2( "CAMDownloadManager::DownloadComplete - start with status (%d)", aStatus ); |
|
682 TInt err(KErrNone); |
|
683 TRAP( err, DownloadCompleteL( aComponent )); |
|
684 RDEBUG_2( "CAMDownloadManager::DownloadComplete - end with status (%d)", err); |
|
685 } |
|
686 |
|
687 // ---------------------------------------------------------------------------------------- |
|
688 // CAMDownloadManager::DownloadCompleteL |
|
689 // ---------------------------------------------------------------------------------------- |
|
690 void CAMDownloadManager::DownloadCompleteL(CDeploymentComponent *aComponent) |
|
691 { |
|
692 RDEBUG( "CAMDownloadManager::DownloadComplete - start" ); |
|
693 __ASSERT_DEBUG( aComponent, User::Invariant() ); |
|
694 |
|
695 CAMDownload* dowload = FindDownload(aComponent); |
|
696 |
|
697 TInt idx(iDownloads.Find(dowload) ); |
|
698 if (dowload) |
|
699 dowload->StopDownload(); // delete RHttpDownload |
|
700 if (KErrNotFound != idx) |
|
701 { |
|
702 // NOTICE: Download is removed from downloadmanager AFTER receiving EHttpDlDeleting message |
|
703 // from RHttpDownload |
|
704 // Call server |
|
705 iObserver.ComponentDownloadComplete(aComponent, iapid, iServerId); |
|
706 } |
|
707 |
|
708 RDEBUG( "CAMDownloadManager::DownloadComplete - end" ); |
|
709 } |
|
710 |
|
711 // ---------------------------------------------------------------------------------------- |
|
712 // CAMDownloadManager::UidExistsL |
|
713 // ---------------------------------------------------------------------------------------- |
|
714 TBool CAMDownloadManager::UidExistsL(const TUid &aUid, |
|
715 CDeploymentComponent *& aCompo, CDeploymentComponent *aIgnored) |
|
716 { |
|
717 TBool uidExist(EFalse); |
|
718 uidExist = iObserver.HasUidL(aUid, aCompo, aIgnored); |
|
719 return uidExist; |
|
720 } |
|
721 |
|
722 // ---------------------------------------------------------------------------------------- |
|
723 // CAMDownloadManager::DownloadCount |
|
724 // ---------------------------------------------------------------------------------------- |
|
725 TInt CAMDownloadManager::DownloadCount() const |
|
726 { |
|
727 TInt count(0); |
|
728 count = iDownloads.Count(); |
|
729 RDEBUG_2( "CAMDownloadManager::DownloadCount: (%d)", count ); |
|
730 return count; |
|
731 } |
|
732 |
|
733 void CAMDownloadManager::HandleAlreadyRunningL(TInt32 aDownloadedSize, |
|
734 TInt32 aContentSize, CAMDownload& aDownload, THttpProgressState aState) |
|
735 { |
|
736 |
|
737 aDownload.ProgressDialogL(aDownloadedSize, aContentSize, aState); |
|
738 |
|
739 } |
|
740 |
|
741 // End of File |