iaupdate/IAD/engine/controller/src/iaupdateservicepacknode.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <ncdnode.h>
       
    21 #include <ncdnodeinstall.h>
       
    22 
       
    23 #include "iaupdateservicepacknode.h"
       
    24 #include "iaupdatecontrollerimpl.h"
       
    25 #include "iaupdatecontentoperationmanager.h"
       
    26 #include "iaupdatenodedetails.h"
       
    27 #include "iaupdatenodedependencyimpl.h"
       
    28 #include "iaupdatectrlnodeconsts.h"
       
    29 #include "iaupdateutils.h"
       
    30 
       
    31 #include "iaupdatedebug.h"
       
    32 
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // CIAUpdateServicePackNode::NewLC
       
    36 // 
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CIAUpdateServicePackNode* CIAUpdateServicePackNode::NewLC( 
       
    40     MNcdNode* aNode,
       
    41     CIAUpdateController& aController )
       
    42     {
       
    43     CIAUpdateServicePackNode* self( 
       
    44         new( ELeave ) CIAUpdateServicePackNode( aController ) );
       
    45     CleanupStack::PushL( self );    
       
    46     self->ConstructL( aNode );
       
    47     return self;
       
    48     }
       
    49   
       
    50     
       
    51 // ---------------------------------------------------------------------------
       
    52 // CIAUpdateServicePackNode::NewL
       
    53 // 
       
    54 // ---------------------------------------------------------------------------
       
    55 //    
       
    56 CIAUpdateServicePackNode* CIAUpdateServicePackNode::NewL( 
       
    57     MNcdNode* aNode,
       
    58     CIAUpdateController& aController )
       
    59     {
       
    60     CIAUpdateServicePackNode* self(
       
    61         CIAUpdateServicePackNode::NewLC( aNode, aController ) );
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CIAUpdateServicePackNode::CIAUpdateServicePackNode
       
    69 // 
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CIAUpdateServicePackNode::CIAUpdateServicePackNode( 
       
    73     CIAUpdateController& aController ) 
       
    74 : CIAUpdateNode( aController )
       
    75     {
       
    76     }
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CIAUpdateServicePackNode::ConstructL
       
    81 // 
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CIAUpdateServicePackNode::ConstructL( MNcdNode* aNode )
       
    85     {
       
    86     CIAUpdateNode::ConstructL( aNode );
       
    87     }
       
    88 
       
    89     
       
    90 // ---------------------------------------------------------------------------
       
    91 // CIAUpdateServicePackNode::~CIAUpdateServicePackNode
       
    92 // 
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 CIAUpdateServicePackNode::~CIAUpdateServicePackNode()
       
    96     {
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CIAUpdateServicePackNode::SetInstallStatusToPurchaseHistoryL
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CIAUpdateServicePackNode::SetInstallStatusToPurchaseHistoryL( 
       
   106     TInt aErrorCode, TBool aForceVisibleInHistory )
       
   107     {
       
   108     IAUPDATE_TRACE_2("[IAUPDATE] CIAUpdateServicePackNode::SetInstallStatusToPurchaseHistoryL() begin: %d, %d",
       
   109                      aErrorCode, aForceVisibleInHistory);
       
   110 
       
   111     // Make sure that error code does not contain any base error value.
       
   112     TInt errorCode( 
       
   113         CIAUpdateContentOperationManager::CheckErrorCode( 
       
   114             aErrorCode ) );
       
   115 
       
   116     // Now update the error code with the correct base error value.
       
   117     // This base value will be used later to know that the last operation has been
       
   118     // install operation. This is service pack specific .
       
   119     errorCode += IAUpdateCtrlNodeConsts::KErrBaseServicePackInstall;
       
   120 
       
   121     IAUPDATE_TRACE_1("[IAUPDATE] Error code: %d", errorCode);
       
   122 
       
   123     SetIdleErrorToPurchaseHistoryL( 
       
   124         errorCode, aForceVisibleInHistory );
       
   125 
       
   126     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateServicePackNode::SetInstallStatusToPurchaseHistoryL() end");
       
   127     }
       
   128 
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CIAUpdateServicePackNode::SetIdleErrorToPurchaseHistoryL
       
   132 // 
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void CIAUpdateServicePackNode::SetIdleErrorToPurchaseHistoryL( 
       
   136         TInt aError, TBool aForceVisibleInHistory )
       
   137     {
       
   138     IAUPDATE_TRACE_2("[IAUPDATE] CIAUpdateServicePackNode::SetIdleErrorToPurchaseHistoryL() begin: %d, %d",
       
   139                      aError, aForceVisibleInHistory);
       
   140 
       
   141     TInt newError( aError );
       
   142 
       
   143     TInt decodedError( 
       
   144         CIAUpdateContentOperationManager::CheckErrorCode( aError ) );
       
   145 
       
   146     // If aError already contains the base value, then the given value
       
   147     // can be directly saved into the purchase history.
       
   148     if ( newError == decodedError )
       
   149         {
       
   150         // Because error values were same, it means that aError did not contain
       
   151         // any base value. So, check if the base value should be included.
       
   152         
       
   153         // Get the last operation error code from the purchase history.
       
   154         TInt lastErrorCode( 
       
   155             LastUpdateErrorCodeFromPurchaseHistoryL() );
       
   156 
       
   157         // Get the decoded value of the error code.
       
   158         // So, it will not contain any base value.
       
   159         TInt decodedHistoryError(
       
   160             CIAUpdateContentOperationManager::CheckErrorCode( 
       
   161                 lastErrorCode ) );
       
   162 
       
   163         // By subtracting the decoded error from the last purchase history error,
       
   164         // we get the error base value. Then, we can add the newly given error value
       
   165         // to the base value. Also, newly given error value is decoded before using it.
       
   166         newError =
       
   167             lastErrorCode - decodedHistoryError 
       
   168             + decodedError;
       
   169         }
       
   170 
       
   171     CIAUpdateNode::SetIdleErrorToPurchaseHistoryL(
       
   172         newError, aForceVisibleInHistory );
       
   173 
       
   174     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateServicePackNode::SetIdleErrorToPurchaseHistoryL() end");
       
   175     }
       
   176 
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CIAUpdateServicePackNode::Type
       
   180 // 
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 MIAUpdateNode::TPackageType CIAUpdateServicePackNode::Type() const
       
   184     {
       
   185     return MIAUpdateNode::EPackageTypeServicePack;
       
   186     }
       
   187 
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CIAUpdateServicePackNode::IsPurchasedL
       
   191 // 
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TBool CIAUpdateServicePackNode::IsPurchasedL() const
       
   195     {
       
   196     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateServicePackNode::IsPurchasedL()");
       
   197 
       
   198     // Notice, this function should not be called before dependency chains
       
   199     // are created.
       
   200     
       
   201     // Notice, that service pack itself is never purchased but its dependency
       
   202     // items are. Here we trust that the node dependency chains have already
       
   203     // been created. So, we use the dependency nodes to check if this
       
   204     // service pack can be thought as purchased. Also, this function trusts
       
   205     // that while dependency chains were created also loops were removed.
       
   206 
       
   207     TBool purchased( ETrue );
       
   208 
       
   209     RPointerArray< CIAUpdateNode > dependencies;
       
   210     CleanupClosePushL( dependencies );
       
   211 
       
   212     // Accept hidden and visible nodes here.
       
   213     // So, if IAD is shown in the UI but it depends on the hidden
       
   214     // self updater, the self updater is still included inside the
       
   215     // service pack.
       
   216     CIAUpdateContentOperationManager::GetOperationNodesL(
       
   217         *this, dependencies, ETrue, ETrue );
       
   218 
       
   219     for ( TInt i = 0; i < dependencies.Count(); ++i )
       
   220         {
       
   221         CIAUpdateNode& node( *dependencies[ i ] );
       
   222         // Notice, that if the dependency node is a service pack itself
       
   223         // then its dependencies are checked like its done in here.
       
   224         // Notice! Here we skip self update nodes because at the moment
       
   225         // IAD Engine does not support self updates inside service packs.
       
   226         // Self update nodes are always shown outside of service pack in 
       
   227         // the UI.
       
   228         // Because we have the whole hierarchy already in dependencies array,
       
   229         // do not call IsPurchased function for other sub service packs.
       
   230         if ( MIAUpdateNode::EPackageTypeServicePack != node.Type() 
       
   231              && !node.IsSelfUpdate()
       
   232              && !node.IsPurchased() )
       
   233             {
       
   234             IAUPDATE_TRACE("[IAUPDATE] Item not downloaded."); 
       
   235             // At least one dependency node was not purchased.
       
   236             // So, think service pack as not purchased also.
       
   237             purchased = EFalse;
       
   238             break;
       
   239             }
       
   240         }
       
   241 
       
   242     CleanupStack::PopAndDestroy( &dependencies );    
       
   243 
       
   244     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateServicePackNode::IsPurchasedL() end: %d",
       
   245                      purchased);
       
   246 
       
   247     return purchased;
       
   248     }
       
   249 
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CIAUpdateServicePackNode::IsDownloadedL
       
   253 // 
       
   254 // ---------------------------------------------------------------------------
       
   255 //
       
   256 TBool CIAUpdateServicePackNode::IsDownloadedL() const
       
   257     {
       
   258     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateServicePackNode::IsDownloadedL() begin");
       
   259 
       
   260     // Notice, this function should not be called before dependency chains
       
   261     // are created.
       
   262 
       
   263     // Notice, that service pack itself is never downloaded but its dependency
       
   264     // items are. Here we trust that the node dependency chains have already
       
   265     // been created. So, we use the dependency nodes to check if this
       
   266     // service pack can be thought as downloaded. Also, this function trusts
       
   267     // that while dependency chains were created also loops were removed.
       
   268 
       
   269     TBool downloaded( ETrue );
       
   270 
       
   271     RPointerArray< CIAUpdateNode > dependencies;
       
   272     CleanupClosePushL( dependencies );
       
   273 
       
   274     // Accept hidden and visible nodes here.
       
   275     // So, if IAD is shown in the UI but it depends on the hidden
       
   276     // self updater, the self updater is still included inside the
       
   277     // service pack.
       
   278     CIAUpdateContentOperationManager::GetOperationNodesL(
       
   279         *this, dependencies, ETrue, ETrue );
       
   280 
       
   281     for ( TInt i = 0; i < dependencies.Count(); ++i )
       
   282         {
       
   283         CIAUpdateNode& node( *dependencies[ i ] );
       
   284         // Notice! Here we skip self update nodes because at the moment
       
   285         // IAD Engine does not support self updates inside service packs.
       
   286         // Self update nodes are always shown outside of service pack in 
       
   287         // the UI.
       
   288         // Because we have the whole hierarchy already in dependencies array,
       
   289         // do not call IsDownloaded function for other sub service packs.
       
   290         if ( MIAUpdateNode::EPackageTypeServicePack != node.Type() 
       
   291              && !node.IsSelfUpdate()
       
   292              && !node.IsDownloaded() )
       
   293             {
       
   294             IAUPDATE_TRACE("[IAUPDATE] Item not downloaded."); 
       
   295             // At least one dependency node was not downloaded.
       
   296             // So, think service pack as not downloaded also.
       
   297             downloaded = EFalse;
       
   298             break;
       
   299             }
       
   300         }
       
   301 
       
   302     CleanupStack::PopAndDestroy( &dependencies );    
       
   303 
       
   304     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateServicePackNode::IsDownloadedL() end: %d",
       
   305                      downloaded);
       
   306 
       
   307     return downloaded;
       
   308     }
       
   309 
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CIAUpdateServicePackNode::IsInstalledL
       
   313 // 
       
   314 // ---------------------------------------------------------------------------
       
   315 //
       
   316 TBool CIAUpdateServicePackNode::IsInstalledL() const
       
   317     {
       
   318     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateServicePackNode::IsInstalledL() begin");
       
   319 
       
   320     // Notice, this function should not be called before dependency chains
       
   321     // are created.
       
   322 
       
   323     // Notice, that service pack itself is never installed but its dependency
       
   324     // items are. While operations are done, the state and the error code
       
   325     // will be updated for the service pack in purchase history.
       
   326     // With this implementation if the service pack is successfully installed
       
   327     // and after that some of its items are uninstalled, the service pack will
       
   328     // still be shown in the UI instead of the items.
       
   329     // Notice, that here we suppose that if some dependency node is uninstalled,
       
   330     // then all its dependants are also been uninstalled by the installer. Therefore,
       
   331     // this information will be known also in head service pack, when installation
       
   332     // status is checked. 
       
   333     // Notice, here we trust that while dependency chains were created also loops 
       
   334     // were removed.
       
   335 
       
   336     TBool installed( ETrue );
       
   337 
       
   338     RPointerArray< CIAUpdateNode > dependencies;
       
   339     CleanupClosePushL( dependencies );
       
   340 
       
   341     // Accept hidden and visible nodes here.
       
   342     // So, if IAD is shown in the UI but it depends on the hidden
       
   343     // self updater, the self updater is still included inside the
       
   344     // service pack.
       
   345     CIAUpdateContentOperationManager::GetOperationNodesL(
       
   346         *this, dependencies, ETrue, ETrue );
       
   347 
       
   348     for ( TInt i = 0; i < dependencies.Count(); ++i )
       
   349         {
       
   350         CIAUpdateNode& node( *dependencies[ i ] );
       
   351         // Because we have the whole hierarchy already in dependencies array,
       
   352         // do not call IsInstalled function for other sub service packs.
       
   353         if ( MIAUpdateNode::EPackageTypeServicePack != node.Type()
       
   354              && !node.IsSelfUpdate()
       
   355              && !node.IsInstalled() )
       
   356             {
       
   357             IAUPDATE_TRACE("[IAUPDATE] Item not installed."); 
       
   358 
       
   359             // If we come here at least one dependency node was not thougth as
       
   360             // installed. So, think service pack as not installed also.
       
   361 
       
   362             // Notice! Here we skip self update nodes because at the moment
       
   363             // IAD Engine does not support self updates inside service packs.
       
   364             // Self update nodes are always shown outside of service pack in 
       
   365             // the UI. So, if all the nodes inside service pack are self
       
   366             // updates, think service pack as installed. Then, seemingly empty
       
   367             // service pack itself will be left out of the UI but the
       
   368             // self update items would be anyways shown in the UI and they
       
   369             // are still available.
       
   370             // When service pack has an item that does not require self update,
       
   371             // it is not thought as empty any more.
       
   372             installed = EFalse;
       
   373             break;
       
   374             }
       
   375         }
       
   376 
       
   377     CleanupStack::PopAndDestroy( &dependencies );
       
   378     
       
   379     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateServicePackNode::IsInstalledL() end: %d",
       
   380                      installed);
       
   381 
       
   382     return installed;
       
   383     }
       
   384 
       
   385