applicationmanagement/server/src/AMDownloadManager.cpp
branchRCL_3
changeset 25 5b858729772b
equal deleted inserted replaced
24:6757f1e2efd2 25:5b858729772b
       
     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     RDEBUG_2( "CAMDownloadManager::SetIAPL: Set IAP Id value to (%d) ", iap);
       
   412     
       
   413     if (iap <= -1)
       
   414         {
       
   415         iap = 0; //as DL mgr treats 0 (zero) as "Always Ask"
       
   416         }
       
   417     iapid = iap;
       
   418     TInt errDL(iDownloadMgr.SetIntAttribute(EDlMgrIap, iap) );
       
   419     if (errDL != KErrNone)
       
   420         {
       
   421         RDEBUG_2("CAMDownloadManager::SetIAPL: ERROR when trying to set DownloadManager IAP: %d", errDL );
       
   422         }
       
   423     else
       
   424         {
       
   425         RDEBUG_2( "CAMDownloadManager::SetIAPL: Set IAP Id to (%d) ", iap);
       
   426         }
       
   427 
       
   428 #ifdef _DEBUG
       
   429     TInt err(iDownloadMgr.SetIntAttribute(EDlMgrIap, 0) );
       
   430     RDEBUG_2( "CAMDownloadManager::SetIAPL (debug only): WARNING Overriding IAP Id to 11 results %d", err );
       
   431 #endif		
       
   432     }
       
   433 
       
   434 // ----------------------------------------------------------------------------------------
       
   435 // CAMDownloadManager::SetUserNamePassword
       
   436 // ----------------------------------------------------------------------------------------	
       
   437 void CAMDownloadManager::SetUserNamePassword(RHttpDownload& aDownload,
       
   438         CDeploymentComponent *aComponent)
       
   439     {
       
   440     RDEBUG( "CAMDownloadManager::SetUserNamePassword: start" );
       
   441     const TAMInstallOptions &opts = aComponent->InstallOpts();
       
   442     if (opts.iOptions.iPassword.Length() && opts.iOptions.iLogin.Length() )
       
   443         {
       
   444         TBuf8<KMaxPath> password;
       
   445         TBuf8<KMaxPath> login;
       
   446         password.Copy(opts.iOptions.iPassword);
       
   447         login.Copy(opts.iOptions.iLogin);
       
   448 
       
   449         TInt err(aDownload.SetStringAttribute(EDlAttrPassword, password) );
       
   450         RDEBUG8_3( "CAMDownloadManager::SetUserNamePassword: response to EDlAttrPassword set to '%S': %d", &password, err );
       
   451         err = aDownload.SetStringAttribute(EDlAttrUsername, login);
       
   452         RDEBUG8_3( "CAMDownloadManager::SetUserNamePassword: response to EDlAttrUsername set to '%S': %d", &login, err );
       
   453         }
       
   454     RDEBUG( "CAMDownloadManager::SetUserNamePassword: end" );
       
   455     }
       
   456 
       
   457 // ----------------------------------------------------------------------------------------
       
   458 // CAMDownloadManager::SyncMLCurrentProfileIdL
       
   459 // ----------------------------------------------------------------------------------------	
       
   460 void CAMDownloadManager::SyncMLCurrentProfileIdL(TSmlProfileId& aOwnerProfile)
       
   461     {
       
   462     RDEBUG( "CAMDownloadManager::SyncMLCurrentProfileIdL: start" );
       
   463 #ifdef _DEBUG
       
   464     TRAPD( erx, SmlHelper::GetCurrentProfileIdL( aOwnerProfile ) )
       
   465     ;
       
   466     if (erx != KErrNone)
       
   467         {
       
   468         RDEBUG_2( "CAMDownloadManager::SyncMLCurrentProfileIdL (debug): Failed to get profile id: %d", erx );
       
   469         }
       
   470     else
       
   471         {
       
   472         RDEBUG_2( "CAMDownloadManager::SyncMLCurrentProfileIdL (debug): Using profile id: %d", aOwnerProfile );
       
   473         }
       
   474 #else
       
   475     SmlHelper::GetCurrentProfileIdL( aOwnerProfile );
       
   476     RDEBUG_2( "CAMDownloadManager::SyncMLCurrentProfileIdL: Find profile id: %d", aOwnerProfile );
       
   477 #endif
       
   478     }
       
   479 
       
   480 // ----------------------------------------------------------------------------------------
       
   481 // CAMDownloadManager::FindDownload
       
   482 // ----------------------------------------------------------------------------------------	
       
   483 CAMDownload* CAMDownloadManager::FindDownload(const TDesC8& aURI)
       
   484     {
       
   485     CAMDownload* download = 0;
       
   486 
       
   487     //find corresponding download from list
       
   488     for (TInt i(0); i < iDownloads.Count(); i++)
       
   489         {
       
   490         download = iDownloads[i];
       
   491         if (download->DownloadURIMatch(aURI) )
       
   492             {
       
   493             RDEBUG("CAMDownloadManager::FindDownload: Found valid download");
       
   494             break;
       
   495             }
       
   496         download = 0;
       
   497         }
       
   498     return download;
       
   499     }
       
   500 
       
   501 // ----------------------------------------------------------------------------------------
       
   502 // CAMDownloadManager::FindDownload
       
   503 // ----------------------------------------------------------------------------------------	
       
   504 CAMDownload* CAMDownloadManager::FindDownload(RHttpDownload& aDownload)
       
   505     {
       
   506     CAMDownload* download = 0;
       
   507     TBuf8<KMaxUrlLength> uri;
       
   508     DownloadURI(aDownload, uri);
       
   509     download = FindDownload(uri);
       
   510     return download;
       
   511     }
       
   512 
       
   513 // ----------------------------------------------------------------------------------------
       
   514 // CAMDownloadManager::FindDownload
       
   515 // ----------------------------------------------------------------------------------------	
       
   516 CAMDownload* CAMDownloadManager::FindDownload(
       
   517         CDeploymentComponent *aComponent)
       
   518     {
       
   519     CAMDownload* download = 0;
       
   520     download = FindDownload(aComponent->DownloadURI() );
       
   521     return download;
       
   522     }
       
   523 
       
   524 // ----------------------------------------------------------------------------------------
       
   525 // CAMDownloadManager::DownloadURI
       
   526 // ----------------------------------------------------------------------------------------	
       
   527 void CAMDownloadManager::DownloadURI(RHttpDownload& aDownload, TDes8& aURI)
       
   528     {
       
   529     TInt err(aDownload.GetStringAttribute(EDlAttrReqUrl, aURI) );
       
   530     RDEBUG_2("CAMDownloadManager::DownloadURI err: (%d)", err);
       
   531     }
       
   532 
       
   533 // ----------------------------------------------------------------------------------------
       
   534 // CAMDownloadManager::HandleDMgrEventL
       
   535 // ----------------------------------------------------------------------------------------	
       
   536 void CAMDownloadManager::HandleDMgrEventL(RHttpDownload& aDownload,
       
   537         THttpDownloadEvent aEvent)
       
   538     {
       
   539     //RDEBUG_3( "CAMDownloadManager::HandleDMgrEventL: DownloadState: '%s', progstate: '%s'", 
       
   540     //	KDownloadStates[aEvent.iDownloadState], ProgStates( aEvent.iProgressState ) );
       
   541 
       
   542     TInt32 contentsize;
       
   543     TInt32 downloadedsize;
       
   544 
       
   545     User::LeaveIfError(aDownload.GetIntAttribute(EDlAttrDownloadedSize,
       
   546             downloadedsize) );
       
   547     User::LeaveIfError(aDownload.GetIntAttribute(EDlAttrLength, contentsize) );
       
   548 
       
   549     CAMDownload* download = FindDownload(aDownload);
       
   550 
       
   551     if ( !download)
       
   552         {
       
   553         TBuf8<KMaxUrlLength> uri;
       
   554         DownloadURI(aDownload, uri);
       
   555         RDEBUG8_2("CAMDownloadManager::HandleDMgrEventL: Could not find download: (%S)", &uri);
       
   556         //User::Leave( KErrNotFound );	// Don't do this! DownloadMgrClient::HandleDMgrEventL does not handle leave correctly.
       
   557         }
       
   558     else
       
   559         {
       
   560         switch (aEvent.iDownloadState)
       
   561             {
       
   562            /* case EHttpDlPaused:
       
   563                 HandlePausedEventL( *download);
       
   564                 break;*/
       
   565             case EHttpDlCreated:
       
   566                 {
       
   567                 if (aEvent.iProgressState == EHttpProgNone)
       
   568                     {
       
   569                     HandleNonProgEventL( *download);
       
   570                     }
       
   571                 }
       
   572                 break;
       
   573             case EHttpDlInprogress:
       
   574                 {
       
   575                 HandleAlreadyRunningL(downloadedsize, contentsize, *download, aEvent.iProgressState);
       
   576 
       
   577                 if (!iNoteDisabled)
       
   578                     {
       
   579                     CSyncService *syncService =
       
   580                             CSyncService::NewL(NULL, KDevManServiceStart);
       
   581                     if (syncService)
       
   582                         {
       
   583                         syncService->EnableProgressNoteL(EFalse);
       
   584                         }
       
   585 
       
   586                     delete syncService;
       
   587                     iNoteDisabled = ETrue;
       
   588                     }
       
   589                 }
       
   590                 break;
       
   591             case EHttpContentTypeReceived:
       
   592                 HandleContentTypeRecEventL( *download);
       
   593                 break;
       
   594             case EHttpDlCompleted:
       
   595                 HandleDlCompletedEventL( *download);
       
   596                 break;
       
   597             case EHttpDlPaused:
       
   598             case EHttpDlFailed:
       
   599                 HandleDlFailedEventL( *download, aEvent.iDownloadState);
       
   600                 break;
       
   601             case EHttpDlDeleting:
       
   602             case EHttpDlDeleted:
       
   603                 HandleDlDeleteEventL(download);
       
   604                 break;
       
   605             default:
       
   606                 /*			RDEBUG8_2( "CAMDownloadManager::HandleDMgrEventL: Not handled download event: (%S)",
       
   607                  KDownloadStates[aEvent.iDownloadState] ); 
       
   608                  
       
   609                  */
       
   610                 break;
       
   611             }
       
   612         }
       
   613     RDEBUG( "CAMDownloadManager::HandleDMgrEventL: end" );
       
   614     }
       
   615 
       
   616 // ----------------------------------------------------------------------------------------
       
   617 // CAMDownloadManager::HandlePausedEventL
       
   618 // ----------------------------------------------------------------------------------------	
       
   619 void CAMDownloadManager::HandlePausedEventL(CAMDownload& aDownload)
       
   620     {
       
   621     RDEBUG( "CAMDownloadManager::HandlePausedEventL" );
       
   622     aDownload.ContinueDownload();
       
   623     }
       
   624 
       
   625 // ----------------------------------------------------------------------------------------
       
   626 // CAMDownloadManager::HandleNonProgEventL
       
   627 // ----------------------------------------------------------------------------------------	
       
   628 void CAMDownloadManager::HandleNonProgEventL(CAMDownload& aDownload)
       
   629     {
       
   630     RDEBUG( "CAMDownloadManager::HandleNonProgEventL" );
       
   631     aDownload.ContinueDownload();
       
   632     }
       
   633 
       
   634 // ----------------------------------------------------------------------------------------
       
   635 // CAMDownloadManager::HandleContentTypeRecEventL
       
   636 // ----------------------------------------------------------------------------------------	
       
   637 void CAMDownloadManager::HandleContentTypeRecEventL(CAMDownload& aDownload)
       
   638     {
       
   639     RDEBUG( "CAMDownloadManager::HandleContentTypeRecEventL: EHttpContentTypeReceived " );
       
   640     const TDesC8& mimetype(aDownload.ContentMimeType() );
       
   641     RDEBUG8_2( "CAMDownloadManager::HandleContentTypeRecEventL: Content type: (%S)", &mimetype );
       
   642     }
       
   643 
       
   644 // ----------------------------------------------------------------------------------------
       
   645 // CAMDownloadManager::HandleDlCompletedEventL
       
   646 // ----------------------------------------------------------------------------------------	
       
   647 void CAMDownloadManager::HandleDlCompletedEventL(CAMDownload& aDownload)
       
   648     {
       
   649     RDEBUG( "CAMDownloadManager::HandleDlCompletedEventL" );
       
   650     aDownload.DownloadCompleted();
       
   651     }
       
   652 
       
   653 // ----------------------------------------------------------------------------------------
       
   654 // CAMDownloadManager::HandleDlFailedEventL
       
   655 // ----------------------------------------------------------------------------------------	
       
   656 void CAMDownloadManager::HandleDlFailedEventL(CAMDownload& aDownload, THttpDownloadState aDownloadState)
       
   657     {
       
   658     RDEBUG( "CAMDownloadManager::HandleDlFailedEventL" );
       
   659     aDownload.DownloadFailedL(aDownloadState);
       
   660     }
       
   661 
       
   662 // ----------------------------------------------------------------------------------------
       
   663 // CAMDownloadManager::HandleDlDeleteEventL
       
   664 // ----------------------------------------------------------------------------------------	
       
   665 void CAMDownloadManager::HandleDlDeleteEventL(CAMDownload* aDownload)
       
   666     {
       
   667     RDEBUG( "CAMDownloadManager::HandleDlDeleteEventL - start" );
       
   668     TInt idx(iDownloads.Find(aDownload) );
       
   669         {
       
   670         RDEBUG_2( "CAMDownloadManager::HandleDlDeleteEventL found download: (%d) delete it", idx );
       
   671         iDownloads.Remove(idx);
       
   672         //	delete aDownload;
       
   673         }
       
   674     RDEBUG( "CAMDownloadManager::HandleDlDeleteEventL - end" );
       
   675     }
       
   676 
       
   677 // ----------------------------------------------------------------------------------------
       
   678 // CAMDownloadManager::DownloadComplete
       
   679 // ----------------------------------------------------------------------------------------	
       
   680 void CAMDownloadManager::DownloadComplete(CDeploymentComponent *aComponent,
       
   681         TInt aStatus)
       
   682     {
       
   683     RDEBUG_2( "CAMDownloadManager::DownloadComplete - start with status (%d)", aStatus );
       
   684     TInt err(KErrNone);
       
   685     TRAP( err, DownloadCompleteL( aComponent ));
       
   686     RDEBUG_2( "CAMDownloadManager::DownloadComplete - end with status (%d)", err);
       
   687     }
       
   688 
       
   689 // ----------------------------------------------------------------------------------------
       
   690 // CAMDownloadManager::DownloadCompleteL
       
   691 // ----------------------------------------------------------------------------------------	
       
   692 void CAMDownloadManager::DownloadCompleteL(CDeploymentComponent *aComponent)
       
   693     {
       
   694     RDEBUG( "CAMDownloadManager::DownloadComplete - start" );
       
   695     __ASSERT_DEBUG( aComponent, User::Invariant() );
       
   696 
       
   697     CAMDownload* dowload = FindDownload(aComponent);
       
   698 
       
   699     TInt idx(iDownloads.Find(dowload) );
       
   700     if (dowload)
       
   701         dowload->StopDownload(); // delete RHttpDownload
       
   702     if (KErrNotFound != idx)
       
   703         {
       
   704         // NOTICE: Download is removed from downloadmanager AFTER receiving EHttpDlDeleting message
       
   705         //         from RHttpDownload
       
   706         // Call server
       
   707         iObserver.ComponentDownloadComplete(aComponent, iapid, iServerId);
       
   708         }
       
   709 
       
   710     RDEBUG( "CAMDownloadManager::DownloadComplete - end" );
       
   711     }
       
   712 
       
   713 // ----------------------------------------------------------------------------------------
       
   714 // CAMDownloadManager::UidExistsL
       
   715 // ----------------------------------------------------------------------------------------	
       
   716 TBool CAMDownloadManager::UidExistsL(const TUid &aUid,
       
   717         CDeploymentComponent *& aCompo, CDeploymentComponent *aIgnored)
       
   718     {
       
   719     TBool uidExist(EFalse);
       
   720     uidExist = iObserver.HasUidL(aUid, aCompo, aIgnored);
       
   721     return uidExist;
       
   722     }
       
   723 
       
   724 // ----------------------------------------------------------------------------------------
       
   725 // CAMDownloadManager::DownloadCount
       
   726 // ----------------------------------------------------------------------------------------	
       
   727 TInt CAMDownloadManager::DownloadCount() const
       
   728     {
       
   729     TInt count(0);
       
   730     count = iDownloads.Count();
       
   731     RDEBUG_2( "CAMDownloadManager::DownloadCount: (%d)", count );
       
   732     return count;
       
   733     }
       
   734 
       
   735 void CAMDownloadManager::HandleAlreadyRunningL(TInt32 aDownloadedSize,
       
   736         TInt32 aContentSize, CAMDownload& aDownload, THttpProgressState aState)
       
   737     {
       
   738 
       
   739     aDownload.ProgressDialogL(aDownloadedSize, aContentSize, aState);
       
   740 
       
   741     }
       
   742 
       
   743 //  End of File