iaupdate/IAD/engine/controller/src/iaupdatenodefactory.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 <ncdnodecontentinfo.h>
       
    21 #include <ncdnode.h>
       
    22 #include <catalogsuids.h>
       
    23 
       
    24 #include "iaupdatenodefactory.h"
       
    25 #include "iaupdatenodeimpl.h"
       
    26 #include "iaupdatefwnodeimpl.h"
       
    27 #include "iaupdatespecialnode.h"
       
    28 #include "iaupdateservicepacknode.h"
       
    29 #include "iaupdateruids.h"
       
    30 #include "iaupdatectrlnodeconsts.h"
       
    31 #include "iaupdateprotocolconsts.h"
       
    32 #include "iaupdatedebug.h"
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // IAUpdateNodeFactory::CreateNodeLC
       
    37 // 
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CIAUpdateNode* IAUpdateNodeFactory::CreateNodeLC( 
       
    41     MNcdNode* aNode,
       
    42     CIAUpdateController& aController )
       
    43     {
       
    44     CIAUpdateNode* updateNode( 
       
    45         IAUpdateNodeFactory::CreateNodeL( aNode, aController ) );
       
    46     CleanupStack::PushL( updateNode );
       
    47     return updateNode;
       
    48     }
       
    49     
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // IAUpdateNodeFactory::CreateNodeL
       
    53 // 
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CIAUpdateNode* IAUpdateNodeFactory::CreateNodeL( 
       
    57     MNcdNode* aNode, 
       
    58     CIAUpdateController& aController )
       
    59     {
       
    60     if ( !aNode )
       
    61         {
       
    62         User::Leave( KErrArgument );
       
    63         }
       
    64 
       
    65     CIAUpdateNode* updateNode( NULL );
       
    66 
       
    67     TUid nodeUid( TUid::Null() ); 
       
    68     TBool isServicePack( EFalse );
       
    69 
       
    70     // Put the node into the cleanup stack.
       
    71     // So, it will be released if update node creation fails.
       
    72     CleanupReleasePushL( *aNode );
       
    73 
       
    74     // Get information from content info.
       
    75     MNcdNodeContentInfo* contentInfo( 
       
    76         aNode->QueryInterfaceLC< MNcdNodeContentInfo >() );
       
    77     if ( contentInfo )
       
    78         {
       
    79         // Notice, check if the node is actually a firmware node.
       
    80         // Do not accept them. Content info is used to check this.
       
    81         // Because content info exists, also checking can be done here without
       
    82         // leaving because content info did not exist.
       
    83         if ( IsFwUpdateL( *aNode ) )
       
    84             {
       
    85             User::Leave( KErrArgument );
       
    86             }
       
    87 
       
    88         nodeUid = contentInfo->Uid(); 
       
    89         isServicePack = IsServicePack( contentInfo->MimeType() );
       
    90 
       
    91         // Release content info.
       
    92         // So, we can later check if it still exists and then get 
       
    93         // new one if it exists.
       
    94         CleanupStack::PopAndDestroy( contentInfo );
       
    95         contentInfo = NULL;
       
    96         }
       
    97 
       
    98     if ( IsSelfUpdate( nodeUid ) )
       
    99         {
       
   100         // Node contents require special install handling. 
       
   101         // So, create special node.
       
   102         updateNode = CIAUpdateSpecialNode::NewL( aNode, aController );
       
   103         }
       
   104     else if ( isServicePack )
       
   105         {
       
   106         // The node is actually service pack.
       
   107         // Notice, that the service pack should not contain any content
       
   108         // itself. Instead, content is provided via dependencies.
       
   109         // So, self update nodes should never be service packs themselves.
       
   110         // So, they can be handled separately above in if-clause.
       
   111         updateNode = CIAUpdateServicePackNode::NewL( aNode, aController );
       
   112         }
       
   113     else
       
   114         {
       
   115         // Normal node.
       
   116         updateNode = CIAUpdateNode::NewL( aNode, aController );       
       
   117         }
       
   118 
       
   119     // The update node took the ownership. So, it is safe to pop.        
       
   120     CleanupStack::Pop( aNode );
       
   121         
       
   122     return updateNode;
       
   123     }
       
   124 
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // IAUpdateNodeFactory::IsSelfUpdate
       
   128 // 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TBool IAUpdateNodeFactory::IsSelfUpdate( const TUid& aUid )
       
   132     {
       
   133     // The UI, that uses this iaupdate engine dll, is thought as a special content.
       
   134     // Iaupdate uses NCD Engine to install itself. So, it requires also special installer.
       
   135     // These special cases should be installed by using updater.
       
   136 
       
   137     if ( IsIad( aUid ) || IsNcd( aUid ) )    
       
   138         {
       
   139         // Special installing is required.
       
   140         return ETrue;
       
   141         }
       
   142 
       
   143     return EFalse;
       
   144     }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // IAUpdateNodeFactory::IsIad
       
   149 // 
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 TBool IAUpdateNodeFactory::IsIad( const TUid& aUid )
       
   153     {
       
   154     RProcess process;
       
   155     TUid uiUid( process.SecureId() );
       
   156     
       
   157     if ( aUid == uiUid )
       
   158         {
       
   159         // UID matched the IAD UID.
       
   160         return ETrue;
       
   161         }
       
   162 
       
   163     return EFalse;
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // IAUpdateNodeFactory::IsNcd
       
   169 // 
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 TBool IAUpdateNodeFactory::IsNcd( const TUid& aUid )
       
   173     {
       
   174     if ( aUid.iUid == KCatalogsServerUid
       
   175          || aUid.iUid == KNcdProviderUid
       
   176          || aUid.iUid == KCatalogsEngineUid
       
   177          || aUid.iUid == KCatalogsEngineInterfaceUid
       
   178          || aUid.iUid == KCatalogsEngineImplementationUid )
       
   179         {
       
   180         // UID matched to one NCD UID.
       
   181         return ETrue;
       
   182         }
       
   183 
       
   184     return EFalse;
       
   185     }
       
   186 
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // IAUpdateNodeFactory::IsUpdater
       
   190 // 
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 TBool IAUpdateNodeFactory::IsUpdater( const TUid& aUid )
       
   194     {
       
   195     if ( aUid.iUid == KIAUpdaterUid )
       
   196         {
       
   197         // UID matched the self updater UID.
       
   198         return ETrue;
       
   199         }
       
   200 
       
   201     return EFalse;
       
   202     }
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 // IAUpdateNodeFactory::CreateFwNodeLC
       
   207 // 
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 CIAUpdateFwNode* IAUpdateNodeFactory::CreateFwNodeLC( 
       
   211     MNcdNode* aNode,
       
   212     CIAUpdateController& aController )
       
   213     {
       
   214     CIAUpdateFwNode* updateNode( 
       
   215         IAUpdateNodeFactory::CreateFwNodeL( aNode, aController ) );
       
   216     CleanupStack::PushL( updateNode );
       
   217     return updateNode;
       
   218     }
       
   219     
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // IAUpdateNodeFactory::CreateFwNodeL
       
   223 // 
       
   224 // ---------------------------------------------------------------------------
       
   225 //    
       
   226 CIAUpdateFwNode* IAUpdateNodeFactory::CreateFwNodeL( 
       
   227     MNcdNode* aNode, 
       
   228     CIAUpdateController& aController )
       
   229     {
       
   230     IAUPDATE_TRACE("[IAUPDATE] IAUpdateNodeFactory::CreateFwNodeL() begin");
       
   231     
       
   232     if ( !aNode )
       
   233         {
       
   234         IAUPDATE_TRACE("[IAUPDATE] ERROR: NULL node");
       
   235         User::Leave( KErrArgument );
       
   236         }
       
   237 
       
   238     CIAUpdateFwNode* updateNode( NULL );
       
   239 
       
   240     // Put the node into the cleanup stack.
       
   241     // So, it will be released if update node creation fails.
       
   242     CleanupReleasePushL( *aNode );
       
   243 
       
   244     MNcdNodeContentInfo* contentInfo(
       
   245         aNode->QueryInterfaceLC< MNcdNodeContentInfo >() );
       
   246     if ( contentInfo )
       
   247         {
       
   248         IAUPDATE_TRACE("[IAUPDATE] Node has content info");
       
   249         
       
   250         const TDesC& mime( contentInfo->MimeType() );
       
   251         IAUPDATE_TRACE_1("[IAUPDATE] Mime: %S", &mime);        
       
   252         
       
   253         if ( mime == IAUpdateProtocolConsts::KMimeFotaDp2 )
       
   254             {
       
   255             IAUPDATE_TRACE("[IAUPDATE] Fota Dp2");
       
   256             updateNode = 
       
   257                 CIAUpdateFwNode::NewL( 
       
   258                     aNode, aController, MIAUpdateFwNode::EFotaDp2 );
       
   259             }
       
   260         else if ( mime == IAUpdateProtocolConsts::KMimeFotiNsu )
       
   261             {
       
   262             IAUPDATE_TRACE("[IAUPDATE] Foti Nsu");
       
   263             updateNode = 
       
   264                 CIAUpdateFwNode::NewL( 
       
   265                     aNode, aController, MIAUpdateFwNode::EFotiNsu );
       
   266             }
       
   267         else
       
   268             {
       
   269             // Unknown firmware mime type
       
   270             IAUPDATE_TRACE("[IAUPDATE] ERROR: Unknown MIME for fw");
       
   271             User::Leave( KErrArgument );
       
   272             }
       
   273 
       
   274         // Firmware item should always have content info available.
       
   275         CleanupStack::PopAndDestroy( contentInfo );
       
   276         }
       
   277     else
       
   278         {
       
   279         IAUPDATE_TRACE("[IAUPDATE] ERROR: Firmware item did not have content info");
       
   280         User::Leave( KErrNotFound );
       
   281         }
       
   282                      
       
   283     // The update node took the ownership. So, it is safe to pop.        
       
   284     CleanupStack::Pop( aNode );
       
   285 
       
   286     IAUPDATE_TRACE("[IAUPDATE] IAUpdateNodeFactory::CreateFwNodeL() end");
       
   287         
       
   288     return updateNode;
       
   289     }
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // IAUpdateNodeFactory::IsFwUpdateL
       
   294 // 
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 TBool IAUpdateNodeFactory::IsFwUpdateL( MNcdNode& aNode )
       
   298     {
       
   299     IAUPDATE_TRACE("[IAUPDATE] IAUpdateNodeFactory::IsFwUpdateL() begin");
       
   300     
       
   301     TBool isFwUpdate( EFalse );
       
   302 
       
   303     MNcdNodeContentInfo* contentInfo(
       
   304         aNode.QueryInterfaceLC< MNcdNodeContentInfo >() );
       
   305     if ( contentInfo )
       
   306         {
       
   307         IAUPDATE_TRACE("[IAUPDATE] Node has content info");
       
   308 
       
   309         const TDesC& mime( contentInfo->MimeType() );
       
   310         IAUPDATE_TRACE_1("[IAUPDATE] Mime: %S", &mime);
       
   311 
       
   312         isFwUpdate = IsFwUpdate( mime );
       
   313 
       
   314         // Firmware item should always have content info available.
       
   315         CleanupStack::PopAndDestroy( contentInfo );
       
   316         }
       
   317     else
       
   318         {
       
   319         IAUPDATE_TRACE("[IAUPDATE] ERROR: Firmware item did not have content info");
       
   320         User::Leave( KErrNotFound );
       
   321         }
       
   322 
       
   323     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateNodeFactory::IsFwUpdateL() end: %d",
       
   324                      isFwUpdate);
       
   325 
       
   326     return isFwUpdate;
       
   327     }
       
   328 
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // IAUpdateNodeFactory::IsFwUpdate
       
   332 // 
       
   333 // ---------------------------------------------------------------------------
       
   334 //
       
   335 TBool IAUpdateNodeFactory::IsFwUpdate( const TDesC& aMime )
       
   336     {
       
   337     IAUPDATE_TRACE("[IAUPDATE] IAUpdateNodeFactory::IsFwUpdate() begin");
       
   338     
       
   339     TBool isFwUpdate( EFalse );
       
   340     
       
   341     if ( aMime == IAUpdateProtocolConsts::KMimeFotaDp2
       
   342          || aMime == IAUpdateProtocolConsts::KMimeFotiNsu )
       
   343         {
       
   344         isFwUpdate = ETrue;
       
   345         }
       
   346 
       
   347     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateNodeFactory::IsFwUpdate() end: %d",
       
   348                      isFwUpdate);
       
   349     
       
   350     return isFwUpdate;
       
   351     }
       
   352 
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // IAUpdateNodeFactory::IsServicePack
       
   356 // 
       
   357 // ---------------------------------------------------------------------------
       
   358 //     
       
   359 TBool IAUpdateNodeFactory::IsServicePack( const TDesC& aMime )
       
   360     {
       
   361     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateNodeFactory::IsServicePack: %d",
       
   362                      ( aMime.Match( IAUpdateProtocolConsts::KMimeServicePackPattern() )
       
   363                        != KErrNotFound ));
       
   364 
       
   365     // Notice, that here we compare the beginning of the MIME.
       
   366     // So, the end of the MIME may contain some postfix, for example,
       
   367     // IAUpdateCtrlNodeConsts::KMimeServicePackDependencyPostfix. But,
       
   368     // we always interpret the item as service pack if the MIME so 
       
   369     // suggests. So, even if this service pack is a service pack inside
       
   370     // another service pack. This is still service pack.
       
   371     return ( aMime.Match( IAUpdateProtocolConsts::KMimeServicePackPattern() )
       
   372              != KErrNotFound );
       
   373     }
       
   374 
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // IAUpdateNodeFactory::IsHidden
       
   378 // 
       
   379 // ---------------------------------------------------------------------------
       
   380 //     
       
   381 TBool IAUpdateNodeFactory::IsHidden( const TDesC& aMime )
       
   382     {
       
   383     IAUPDATE_TRACE_1("[IAUPDATE] IAUpdateNodeFactory::IsHidden(): %d",
       
   384                      ( aMime.Match( IAUpdateCtrlNodeConsts::KMimeHiddenPostfixPattern() )
       
   385                        != KErrNotFound ));
       
   386 
       
   387     // Notice, that here we compare the end of the MIME.
       
   388     // The end of the MIME may contain some postfix, for example,
       
   389     // IAUpdateCtrlNodeConsts::KMimeHiddenPostfix.
       
   390     // So, if correct postfix is found, then this is a hidden node.
       
   391     return ( aMime.Match( IAUpdateCtrlNodeConsts::KMimeHiddenPostfixPattern() )
       
   392              != KErrNotFound );
       
   393     }