appinstaller/AppinstUi/Server/Src/SWInstInstallRequest.cpp
changeset 80 9dcba1ee99f7
parent 77 d1838696558c
equal deleted inserted replaced
77:d1838696558c 80:9dcba1ee99f7
     1 /*
       
     2 * Copyright (c) 2002-2010 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:   This module contains the implementation of 
       
    15 *                CSWInstInstallRequest class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <DRMHelper.h>
       
    23 #include <aknnotewrappers.h>
       
    24 #include <StringLoader.h>
       
    25 #include <SWInstSvrUI.rsg>
       
    26 #include <SWInstCommonUI.rsg>
       
    27 #include <SWInstTaskManager.h>
       
    28 #include <caf/caf.h>
       
    29 #include <coemain.h>
       
    30 #include <sysutil.h>
       
    31 
       
    32 #include "SWInstInstallRequest.h"
       
    33 #include "SWInstUIPluginAPI.h"
       
    34 #include "SWInstServerPanic.h"
       
    35 #include "CUIDialogs.h"
       
    36 
       
    37 using namespace SwiUI;
       
    38 
       
    39 const TInt KSystemFileRequirement = 4096; // 4 KB
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CSWInstInstallRequest::CSWInstInstallRequest
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CSWInstInstallRequest::CSWInstInstallRequest( const RMessage2& aMessage )
       
    50     : CSWInstRequestObject( aMessage )
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CSWInstInstallRequest::CSWInstInstallRequest
       
    56 // C++ default constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSWInstInstallRequest::CSWInstInstallRequest( TInt aObjectId )
       
    61     : CSWInstRequestObject( aObjectId )
       
    62     {
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSWInstInstallRequest::ConstructL
       
    67 // Symbian 2nd phase constructor can leave.
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CSWInstInstallRequest::ConstructL()
       
    71     {
       
    72     BaseConstructL();    
       
    73     User::LeaveIfError( iFs.Connect() );    
       
    74     iFs.ShareProtected();    
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSWInstInstallRequest::NewL
       
    79 // Two-phased constructor.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CSWInstInstallRequest* CSWInstInstallRequest::NewL( const RMessage2& aMessage )
       
    83     {
       
    84     CSWInstInstallRequest* self = new ( ELeave ) CSWInstInstallRequest( aMessage );
       
    85     CleanupStack::PushL( self );
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop( self );
       
    88     return self; 
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CSWInstInstallRequest::NewL
       
    93 // Two-phased constructor.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CSWInstInstallRequest* CSWInstInstallRequest::NewL( TInt aObjectId )
       
    97     {
       
    98     CSWInstInstallRequest* self = new ( ELeave ) CSWInstInstallRequest( aObjectId );
       
    99     CleanupStack::PushL( self );
       
   100     self->ConstructL();
       
   101     CleanupStack::Pop( self );
       
   102     return self; 
       
   103     }
       
   104     
       
   105 // Destructor
       
   106 CSWInstInstallRequest::~CSWInstInstallRequest()
       
   107     {
       
   108     iFile.Close();    
       
   109     iFs.Close();    
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CSWInstInstallRequest::Install
       
   114 // Perform installation
       
   115 // (other items were commented in a header).
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CSWInstInstallRequest::Install( RFile& aFile, const TInstallReq& aParams )
       
   119     {
       
   120     iIsSilent = EFalse;
       
   121     iParams = aParams;
       
   122     iFile = aFile;
       
   123 
       
   124     TRAPD( err, DoInstallL( aFile ) );
       
   125 
       
   126     if ( err != KErrNone )
       
   127         {
       
   128         CompleteSelf( err );        
       
   129         }
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CSWInstInstallRequest::Install
       
   134 // Perform installation
       
   135 // (other items were commented in a header).
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CSWInstInstallRequest::Install( const TDesC& aFileName, const TInstallReq& aParams )
       
   139     {
       
   140     iIsSilent = EFalse;
       
   141     iParams = aParams;
       
   142 
       
   143     // Copy the package path to source url
       
   144     if ( !iParams.iSourceURL.Length() )
       
   145         {
       
   146         iParams.iSourceURL = TParsePtrC( aFileName ).DriveAndPath();        
       
   147         }   
       
   148 
       
   149     // Open file handle to the package
       
   150     TInt err = iFile.Open( iFs, aFileName, EFileRead | EFileShareReadersOnly );
       
   151     if ( err == KErrNone )
       
   152         {
       
   153         TRAP( err, DoInstallL( iFile ) );
       
   154         }    
       
   155 
       
   156     if ( err != KErrNone )
       
   157         {
       
   158         CompleteSelf( err );    
       
   159         }   
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CSWInstInstallRequest::SilentInstall
       
   164 // Perform silent installation
       
   165 // (other items were commented in a header).
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CSWInstInstallRequest::SilentInstall( RFile& aFile,
       
   169                                            const TInstallReq& aParams, 
       
   170                                            const TInstallOptions& aOptions )
       
   171     {
       
   172     iIsSilent = ETrue;
       
   173     iParams = aParams;
       
   174     iOptions = aOptions;
       
   175     iFile = aFile;    
       
   176 
       
   177     TRAPD( err, DoInstallL( aFile ) );
       
   178 
       
   179     if ( err != KErrNone )
       
   180         {
       
   181         CompleteSelf( err );        
       
   182         }
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CSWInstInstallRequest::SilentInstall
       
   187 // Perform silent installation
       
   188 // (other items were commented in a header).
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CSWInstInstallRequest::SilentInstall( const TDesC& aFileName,
       
   192                                            const TInstallReq& aParams, 
       
   193                                            const TInstallOptions& aOptions )
       
   194     {
       
   195     iIsSilent = ETrue;
       
   196     iParams = aParams;
       
   197     iOptions = aOptions;
       
   198 
       
   199     // Copy the package path to source url
       
   200     if ( !iParams.iSourceURL.Length() )
       
   201         {
       
   202         iParams.iSourceURL = TParsePtrC( aFileName ).DriveAndPath();        
       
   203         }    
       
   204     
       
   205     // Open file handle to the package
       
   206     TInt err = iFile.Open( iFs, aFileName, EFileRead | EFileShareReadersOnly );
       
   207     if ( err == KErrNone )
       
   208         {
       
   209         TRAP( err, DoInstallL( iFile ) );   
       
   210         }    
       
   211     
       
   212     if ( err != KErrNone )
       
   213         {
       
   214         CompleteSelf( err );    
       
   215         }   
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CSWInstInstallRequest::CancelRequest
       
   220 // Cancels the current request.
       
   221 // (other items were commented in a header).
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 void CSWInstInstallRequest::CancelRequest()
       
   225     {
       
   226     // If we have a pending install request, cancel it
       
   227     if ( iUIPlugin )
       
   228         {
       
   229         iUIPlugin->Cancel();
       
   230         }
       
   231     }
       
   232       
       
   233 // -----------------------------------------------------------------------------
       
   234 // CSWInstInstallRequest::RequestCompleteL
       
   235 // Gets called when the request is completed.
       
   236 // (other items were commented in a header).
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CSWInstInstallRequest::RequestCompleteL( TInt aResult )
       
   240     {
       
   241     // First see if we even have a ui plugin
       
   242     if ( iUIPlugin )
       
   243         {        
       
   244         // Run outstanding tasks
       
   245         TRAP_IGNORE( iTaskManager->ExecutePendingTasksL() );
       
   246         
       
   247         // Inform the ui
       
   248         iUIPlugin->CompleteL();
       
   249         
       
   250         // Delete the plugin and try to run outstanding tasks once again.
       
   251         delete iUIPlugin;
       
   252         iUIPlugin = NULL;
       
   253         TRAP_IGNORE( iTaskManager->ExecutePendingTasksL() );
       
   254         }    
       
   255 
       
   256     iFile.Close();
       
   257     
       
   258     // Complete the client message
       
   259     Complete( aResult );        
       
   260     }
       
   261       
       
   262 // -----------------------------------------------------------------------------
       
   263 // CSWInstInstallRequest::HandleNotSupportedL
       
   264 // Handles the error when installation of the given package is not supported.
       
   265 // (other items were commented in a header).
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CSWInstInstallRequest::HandleNotSupportedL( const TDesC& aFileName ) const
       
   269     {    
       
   270     if ( !iIsSilent )
       
   271         {        
       
   272         // Display an error to the user
       
   273         HBufC* errorString = StringLoader::LoadLC( R_SWINSTSVRUI_NOT_SUPP, 
       
   274                                                    TParsePtrC( aFileName ).NameAndExt() );
       
   275         CommonUI::CCUIDialogs* commonDlgs = CommonUI::CCUIDialogs::NewL();  
       
   276         CleanupStack::PushL( commonDlgs );
       
   277         commonDlgs->ShowErrorNoteL( *errorString );
       
   278         CleanupStack::PopAndDestroy( 2, errorString );
       
   279         }    
       
   280     User::Leave( KSWInstErrPackageNotSupported );
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // CSWInstInstallRequest::DoInstallL
       
   285 // Performs the actual installation.
       
   286 // (other items were commented in a header).
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 void CSWInstInstallRequest::DoInstallL( RFile& aFile )
       
   290     {
       
   291     // Check that no instances of installer is running
       
   292     LeaveIfInUseL();    
       
   293 
       
   294     // Try to recover in case of old fatal error
       
   295     TRAP_IGNORE( iTaskManager->ExecuteRecoveryTasksL() );
       
   296 
       
   297     // If there is no mime type in the parameters try to get it based on content.
       
   298     // If mime is supplied in parameters, it is always used first!
       
   299     if ( !iParams.iMIME.Length() )
       
   300         {        
       
   301         ContentAccess::CContent* content = ContentAccess::CContent::NewLC( aFile );
       
   302         GetMIMETypeL( *content, iParams.iMIME );        
       
   303         CleanupStack::PopAndDestroy( content );
       
   304         }
       
   305 
       
   306     // If the mime could not be detected, cancel the installation.
       
   307     if ( !iParams.iMIME.Length() )
       
   308         {        
       
   309         TFileName name;
       
   310         aFile.Name( name );        
       
   311         HandleNotSupportedL( name );
       
   312         }        
       
   313     else
       
   314         {        
       
   315         // Make sure that we are not running out of disk space. 
       
   316         // We need to make sure that there is enough space at least for possible
       
   317         // persistent tasks.
       
   318         if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFs, KSystemFileRequirement ) )
       
   319             {
       
   320             if ( !iIsSilent )
       
   321                 {                
       
   322                 CommonUI::CCUIDialogs* commonDlgs = CommonUI::CCUIDialogs::NewL();  
       
   323                 CleanupStack::PushL( commonDlgs );
       
   324                 commonDlgs->ShowErrorNoteL( R_SWCOMMON_NOT_ENOUGH_MEMORY );
       
   325                 CleanupStack::PopAndDestroy( commonDlgs );
       
   326                 }
       
   327             User::Leave( KSWInstErrInsufficientMemory );            
       
   328             }        
       
   329         TInt err = 0; 
       
   330         // Try to create the plugin based on the MIME type   
       
   331         TRAP( err, CreatePluginL( iParams.iMIME ) );
       
   332         if ( err == KErrNotFound ) //lets try again by asking mime type from the content
       
   333             {
       
   334             ContentAccess::CContent* content = ContentAccess::CContent::NewLC( aFile );
       
   335             GetMIMETypeL( *content, iParams.iMIME );        
       
   336             CleanupStack::PopAndDestroy( content );	
       
   337             TRAP( err, CreatePluginL( iParams.iMIME ) );
       
   338             }
       
   339         if ( err == KErrNotFound )
       
   340             {
       
   341             TFileName name;
       
   342             aFile.Name( name );            
       
   343             HandleNotSupportedL( name ); 
       
   344             }    
       
   345         else if ( err != KErrNone )
       
   346             {
       
   347             User::Leave( err );        
       
   348             }
       
   349         else
       
   350             {   
       
   351             TInt isProtected( EFalse );
       
   352             
       
   353             // See if this is protected content    
       
   354             ContentAccess::CContent* content = ContentAccess::CContent::NewLC( aFile );
       
   355             content->GetAttribute( ContentAccess::EIsProtected, isProtected );
       
   356             CleanupStack::PopAndDestroy( content );
       
   357 
       
   358             // We can launch the installation if this is not protected or
       
   359             // rights exist for the protected content.
       
   360             if ( !isProtected || HandleProtectedContentL( aFile ) )
       
   361                 {     
       
   362                 if ( !iIsSilent )
       
   363                     {            
       
   364                     iUIPlugin->InstallL( aFile, iParams, isProtected, iStatus );
       
   365                     }
       
   366                 else
       
   367                     {
       
   368                     iUIPlugin->SilentInstallL( aFile, iParams, isProtected, iOptions, iStatus );
       
   369                     }       
       
   370  
       
   371                 SetActive();
       
   372                 }
       
   373             else
       
   374                 {
       
   375                 User::Leave( KSWInstErrNoRights );              
       
   376                 }  
       
   377             }    
       
   378         }    
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CSWInstInstallRequest::GetMIMETypeL
       
   383 // Gets MIME type of the package.
       
   384 // (other items were commented in a header).
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CSWInstInstallRequest::GetMIMETypeL( const ContentAccess::CContent& aContent, 
       
   388                                           TDes8& aMIME )
       
   389     {
       
   390     HBufC* tmpMIME = HBufC::NewLC( KMaxDataTypeLength );
       
   391     TPtr mimePtr( tmpMIME->Des() );            
       
   392     User::LeaveIfError( aContent.GetStringAttribute( ContentAccess::EMimeType, mimePtr ) );
       
   393     aMIME.Copy( *tmpMIME );
       
   394     CleanupStack::PopAndDestroy( tmpMIME );
       
   395     }
       
   396 
       
   397 // -----------------------------------------------------------------------------
       
   398 // CSWInstInstallRequest::HandleProtectedContentL
       
   399 // Helper to handle protected content.
       
   400 // (other items were commented in a header).
       
   401 // -----------------------------------------------------------------------------
       
   402 //
       
   403 TBool CSWInstInstallRequest::HandleProtectedContentL( RFile& aFile )
       
   404     {
       
   405     TBool result( EFalse );
       
   406     
       
   407     // Try to open the content, if we get an error, let the DRMHelper handle it
       
   408     ContentAccess::CContent* content = ContentAccess::CContent::NewLC( aFile );
       
   409     CData* pkgData = NULL;
       
   410     TRAPD( err, pkgData = content->OpenContentL( ContentAccess::EExecute ) ); // Install needs EExecute
       
   411     delete pkgData;
       
   412     pkgData = NULL;        
       
   413     CleanupStack::PopAndDestroy( content );    
       
   414     
       
   415     if ( err != KErrNone && !iIsSilent )
       
   416         {      
       
   417         CDRMHelper* drmHelper = CDRMHelper::NewL( *CCoeEnv::Static() );
       
   418         TRAPD( helperErr, drmHelper->HandleErrorL( err, aFile ) );
       
   419         delete drmHelper;
       
   420         drmHelper = NULL;
       
   421         
       
   422         if ( helperErr != KErrNone )
       
   423             {
       
   424             // Some error from helper
       
   425             CommonUI::CCUIDialogs* commonDlgs = CommonUI::CCUIDialogs::NewL();  
       
   426             CleanupStack::PushL( commonDlgs );
       
   427             commonDlgs->ShowErrorNoteL( R_SWINSTSVRUI_NO_RIGHTS );
       
   428             CleanupStack::PopAndDestroy( commonDlgs );
       
   429             }      
       
   430         }
       
   431     else if ( err == KErrNone )
       
   432         {
       
   433         // We have rights
       
   434         result = ETrue;        
       
   435         }
       
   436 
       
   437     return result;   
       
   438     }
       
   439 
       
   440 //  End of File