iaupdate/IAD/updater/src/iaupdaterinstaller.cpp
changeset 0 ba25891c3a9e
child 69 b18a4bf55ddb
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:   Installs self update. 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "iaupdaterinstaller.h"
       
    21 #include "iaupdatermngr.h"
       
    22 #include "iaupdatersilentlauncher.h"
       
    23 #include "iaupdaterdefs.h"
       
    24 #include "iaupdatedebug.h"
       
    25 
       
    26 
       
    27 // ======== LOCAL FUNCTIONS =========
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CIAUpdaterInstaller::NewL
       
    34 // Two phased construction 
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CIAUpdaterInstaller* CIAUpdaterInstaller::NewL( 
       
    38     RFs& aFs,
       
    39     CIAUpdaterMngr& aIAUpdater )
       
    40     {
       
    41     CIAUpdaterInstaller* self = 
       
    42         new (ELeave) CIAUpdaterInstaller( aFs, aIAUpdater );
       
    43     CleanupStack::PushL(self);
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48 	
       
    49  
       
    50 // -----------------------------------------------------------------------------
       
    51 // CIAUpdaterInstaller::CIAUpdaterInstaller() 
       
    52 // C++ constructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //	
       
    55 CIAUpdaterInstaller::CIAUpdaterInstaller( 
       
    56     RFs& aFs,
       
    57     CIAUpdaterMngr& aIAUpdater )
       
    58     : CActive( CActive::EPriorityStandard ),
       
    59     iFs( aFs ),
       
    60     iIAUpdater( aIAUpdater ),
       
    61     iState( EDSisInstallerStateIdle ),
       
    62     iInstallErr( KErrNone ),
       
    63     iFileIndex( 0 )       
       
    64     {
       
    65     CActiveScheduler::Add( this );
       
    66     }
       
    67 	
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CIAUpdaterInstaller::~CIAUpdaterInstaller()
       
    71 // Install Request destructor
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CIAUpdaterInstaller::~CIAUpdaterInstaller()
       
    75     {    
       
    76     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::~CIAUpdaterInstaller begin");
       
    77     
       
    78     CancelOperation();
       
    79     
       
    80     iTimer.Close();
       
    81             
       
    82     iFilesToInstall.ResetAndDestroy();
       
    83     delete iInstallLauncher;
       
    84 
       
    85     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::~CIAUpdaterInstaller end");
       
    86     }
       
    87 	
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CIAUpdaterInstaller::ConstructL()
       
    91 // Constructior
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CIAUpdaterInstaller::ConstructL()
       
    95     {
       
    96     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::ConstructL begin");       
       
    97     User::LeaveIfError( iTimer.CreateLocal() );
       
    98     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::ConstructL end");
       
    99     }
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CIAUpdaterInstaller::AddFileToInstallL()
       
   104 // Set the path of all sis files. 
       
   105 // -----------------------------------------------------------------------------
       
   106 //		
       
   107 void CIAUpdaterInstaller::AddFileToInstallL( const TDesC& aFileName )
       
   108     {
       
   109     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::AddFileToInstallL begin"); 
       
   110     HBufC* fileName = aFileName.AllocLC();
       
   111     IAUPDATE_TRACE_1("[IAUpdater] fileName: %S", fileName); 
       
   112     iFilesToInstall.AppendL( fileName );
       
   113     CleanupStack::Pop( fileName );
       
   114     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::AddFileToInstallL end"); 
       
   115     }
       
   116 	
       
   117 	
       
   118 // -----------------------------------------------------------------------------
       
   119 // CIAUpdaterInstaller::StartInstallingL()
       
   120 // Start installing
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CIAUpdaterInstaller::StartInstallingL()
       
   124     {
       
   125     IAUPDATE_TRACE("[IAUpdater] Installer::StartInstallingL begin"); 
       
   126         
       
   127     if ( !iFilesToInstall.Count() )
       
   128         {
       
   129         IAUPDATE_TRACE_1("[IAUpdater] Error No file to install: %d", KErrAbort );
       
   130         User::Leave( KErrAbort );
       
   131         }
       
   132 
       
   133     if ( iState != EDSisInstallerStateIdle )
       
   134         {
       
   135         // Leave, because installation operation is already on.
       
   136         User::Leave( KErrInUse );
       
   137         }
       
   138         
       
   139     if ( !iInstallLauncher )
       
   140         {
       
   141         IAUPDATE_TRACE("[IAUpdater] Create install launcher");
       
   142         iInstallLauncher = CIAUpdaterSilentLauncher::NewL( iFs );
       
   143         }   
       
   144 
       
   145 
       
   146     // Reset the error
       
   147     IAUPDATE_TRACE("[IAUpdater] Reset error and complete self");
       
   148     iInstallErr = KErrNone;        
       
   149     CompleteSelf();
       
   150 
       
   151 
       
   152     // Notice, that this will not return before 
       
   153     // CActiveSchedulerWait::AsyncStop() is called.
       
   154     // So, active object may do its job above 
       
   155     // and the code will continue after they
       
   156     // are finished and AsyncStop is called.
       
   157     IAUPDATE_TRACE("[IAUpdater] Active scheduler start waiting begins");
       
   158     iWaiter.Start();
       
   159     IAUPDATE_TRACE("[IAUpdater] Active scheduler start waiting ends");
       
   160 
       
   161     IAUPDATE_TRACE("[IAUpdater] Installer::StartInstallingL end"); 
       
   162     }
       
   163     
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CIAUpdaterInstaller::CompleteSelf()
       
   167 // Complete the request manually 
       
   168 // -----------------------------------------------------------------------------
       
   169 //		
       
   170 void CIAUpdaterInstaller::CompleteSelf()
       
   171     {
       
   172     IAUPDATE_TRACE("[IAUpdater] Installer::CompleteSelf begin");
       
   173     
       
   174     if ( !IsActive() )
       
   175         {        
       
   176         IAUPDATE_TRACE("[IAUpdater] SetActive");
       
   177         TRequestStatus* status = &iStatus;
       
   178         User::RequestComplete( status, KErrNone );
       
   179         SetActive();
       
   180         }    
       
   181 
       
   182     IAUPDATE_TRACE("[IAUpdater] Installer::CompleteSelf end");
       
   183     }
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CIAUpdaterInstaller::CancelOperation()
       
   188 // Cancel the active request and stop waiter.
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CIAUpdaterInstaller::CancelOperation()
       
   192     {
       
   193     IAUPDATE_TRACE("[IAUpdater] Installer::CancelOperation begin");
       
   194 
       
   195     // Use normal cancel to cancel possible active operation.
       
   196     Cancel();
       
   197 
       
   198 	// Stop active scheduler 
       
   199     if ( iWaiter.IsStarted() )
       
   200         {
       
   201         IAUPDATE_TRACE("[IAUpdater] Stop waiter.");
       
   202         iWaiter.AsyncStop();            
       
   203         }
       
   204 
       
   205     IAUPDATE_TRACE("[IAUpdater] Installer::CancelOperation end");
       
   206     }
       
   207 
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CIAUpdaterInstaller::DoCancel()
       
   211 // Cancel the active request.
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CIAUpdaterInstaller::DoCancel()
       
   215     {    
       
   216     IAUPDATE_TRACE("[IAUpdater] Installer::DoCancel begin");
       
   217     
       
   218     iTimer.Cancel();
       
   219 
       
   220     iFileIndex = 0;
       
   221     iFilesToInstall.ResetAndDestroy();
       
   222     
       
   223     if ( iState == EDSisInstallerStateInstalling )
       
   224         {                    
       
   225         iInstallLauncher->Cancel();
       
   226         }
       
   227     
       
   228     TRAP_IGNORE( iIAUpdater.SetProcessParametersL( KErrCancel ) );
       
   229     
       
   230     IAUPDATE_TRACE("[IAUpdater] Installer::DoCancel end");
       
   231     }
       
   232 	
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CIAUpdaterInstaller::RunL()
       
   236 //
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CIAUpdaterInstaller::RunL()
       
   240     {
       
   241     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::RunL() begin");
       
   242     IAUPDATE_TRACE_1("[IAUpdater] RunL(): iStatus = %d", iStatus.Int() );     
       
   243     
       
   244     switch ( iState )
       
   245         {      
       
   246         // Reached when installation is completed. Check result.
       
   247         case EDSisInstallerStateInstalling:
       
   248             { 
       
   249             IAUPDATE_TRACE("[IAUpdater] RunL() Sis Inst. state INSTALLING");                    
       
   250                                                                                      
       
   251             if ( iStatus.Int() == SwiUI::KSWInstErrBusy )
       
   252                 {
       
   253                 IAUPDATE_TRACE("[IAUpdater] RunL() SWInstaller Busy"); 
       
   254                 
       
   255                 // User might be installing something, wait before retrying 
       
   256                 TTimeIntervalMicroSeconds32 time( 
       
   257                     IAUpdaterDefs::KInstallRetryWaitTime );                        
       
   258                 iTimer.After( iStatus, time );                
       
   259                 iState = EDSisInstallerStateInstallerBusy;
       
   260                 SetActive();                        
       
   261                 break;                        
       
   262                 }                
       
   263             else if ( (iStatus.Int() == SwiUI::KSWInstErrSecurityFailure && 
       
   264                 iInstallErr == KErrNone) ||
       
   265                 (iStatus.Int() != KErrNone && 
       
   266                 iStatus.Int() != SwiUI::KSWInstErrSecurityFailure) )
       
   267                 {
       
   268                 IAUPDATE_TRACE("[IAUpdater] RunL() Ins. err or sec. failure"); 
       
   269                 
       
   270                 iInstallErr = iStatus.Int();                                      
       
   271                 }
       
   272                                                  
       
   273             // Check if we have more to install
       
   274             if ( iFileIndex < iFilesToInstall.Count() )
       
   275                 {
       
   276                 IAUPDATE_TRACE("[IAUpdater] RunL() Start next installation"); 
       
   277                                               
       
   278                 iState = EDSisInstallerStateIdle;               
       
   279                 CompleteSelf();
       
   280                 }   
       
   281             else
       
   282                 {                               
       
   283                 InstallationCompleted( iInstallErr );
       
   284                 } 
       
   285             }
       
   286             break;
       
   287 			
       
   288         // Install a file
       
   289         case EDSisInstallerStateIdle:
       
   290             { 
       
   291             IAUPDATE_TRACE("[IAUpdater] RunL() Sis Inst. state IDLE");  
       
   292             
       
   293             if ( iFileIndex < iFilesToInstall.Count() )
       
   294                 {                               
       
   295                 iSisFile.Copy( *iFilesToInstall[iFileIndex] );
       
   296                 ++iFileIndex;
       
   297 
       
   298                 IAUPDATE_TRACE_1("[IAUpdater] RunL() Start install %S", &iSisFile ); 
       
   299                 iInstallLauncher->InstallL( iSisFile, iStatus );                
       
   300                 iState = EDSisInstallerStateInstalling;                    
       
   301                 SetActive();
       
   302                 }
       
   303             else
       
   304                 {
       
   305                 InstallationCompleted( iInstallErr );                            
       
   306                 } 
       
   307             }                        
       
   308             break;
       
   309             
       
   310         case EDSisInstallerStateInstallerBusy:
       
   311             {
       
   312             IAUPDATE_TRACE("[IAUpdater] RunL() Sis Inst. state INSTALLER BUSY");  
       
   313             IAUPDATE_TRACE_1("[IAUpdater] RunL() Start install for %S", &iSisFile ); 
       
   314                         
       
   315             iInstallLauncher->InstallL( iSisFile, iStatus );
       
   316             iState = EDSisInstallerStateInstalling;
       
   317 
       
   318             SetActive();                 
       
   319             }
       
   320             break;                       
       
   321             
       
   322         // Active object in unknown state
       
   323         default:
       
   324             IAUPDATE_TRACE("[IAUpdater] RunL() Active object in unknown state"); 
       
   325             User::Panic( IAUpdaterDefs::KIAUpdaterInstaller, KErrNotSupported );
       
   326             break;
       
   327         }
       
   328 
       
   329     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::RunL() end");
       
   330     }
       
   331 	
       
   332  
       
   333 // -----------------------------------------------------------------------------
       
   334 // CIAUpdaterInstaller::RunError()
       
   335 // If RunL leaves then ignore errors
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 TInt CIAUpdaterInstaller::RunError( TInt aError )
       
   339     {
       
   340     IAUPDATE_TRACE_1("[IAUpdater] CIAUpdaterInstaller::RunError() error = %d", aError );            
       
   341     TInt err( KErrNone );
       
   342     InstallationCompleted( aError );                
       
   343     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::RunError() end");
       
   344     return err;
       
   345     }
       
   346     
       
   347     		
       
   348 // -----------------------------------------------------------------------------
       
   349 // CIAUpdaterInstaller::InstallationCompleted()
       
   350 // Stop active scheduler and stop installation.
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 void CIAUpdaterInstaller::InstallationCompleted( TInt aResult )
       
   354     {
       
   355     IAUPDATE_TRACE_1("[IAUpdater] Installation is completed. result = %d", aResult);        
       
   356     
       
   357     TRAP_IGNORE( iIAUpdater.SetProcessParametersL( aResult ) );    
       
   358         
       
   359     iState = EDSisInstallerStateIdle;    
       
   360     iInstallErr = KErrNone;    
       
   361     delete iInstallLauncher;
       
   362     iInstallLauncher = NULL;
       
   363     
       
   364     IAUPDATE_TRACE("[IAUpdater] Stop active scheduler"); 
       
   365 
       
   366     // Cancel outstanding requests.    
       
   367     CancelOperation();
       
   368 
       
   369     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterInstaller::InstallationCompleted() end");
       
   370     } 
       
   371 
       
   372 // ======== GLOBAL FUNCTIONS ========
       
   373     
       
   374 //EOF
       
   375 
       
   376 
       
   377 
       
   378 
       
   379