appinstaller/AppinstUi/Daemon/Src/daemoninstaller.cpp
changeset 25 98b66e4fb0be
parent 0 ba25891c3a9e
child 29 26b6f0522fd8
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
     1 /*
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <usif/scr/scr.h>
       
    19 #include <usif/scr/screntries.h>
    18 
    20 
    19 #include "daemoninstaller.h"
    21 #include "daemoninstaller.h"
    20 #include "DialogWrapper.h"
    22 #include "DialogWrapper.h"
    21 #include "swispubsubdefs.h"
    23 #include "swispubsubdefs.h"
    22 
    24 
    45 // For uninstaller
    47 // For uninstaller
    46 const static TInt KWaitUninstallerTime = 1000000; // 1 secs  
    48 const static TInt KWaitUninstallerTime = 1000000; // 1 secs  
    47 
    49 
    48 _LIT(KMCSisInstaller,"Daemon-Installer"); // Minor-Component name
    50 _LIT(KMCSisInstaller,"Daemon-Installer"); // Minor-Component name
    49 
    51 
       
    52 
       
    53 // -----------------------------------------------------------------------
    50 // Two phased construction
    54 // Two phased construction
    51 
    55 // -----------------------------------------------------------------------
       
    56 // 
    52 CSisInstaller* CSisInstaller::NewL(    
    57 CSisInstaller* CSisInstaller::NewL(    
    53    MDaemonInstallBehaviour* aDaemonBehaviour, 
    58    MDaemonInstallBehaviour* aDaemonBehaviour, 
    54    CProgramStatus& aMainStatus)
    59    CProgramStatus& aMainStatus)
    55     {
    60     {
    56     CSisInstaller* self = new (ELeave) CSisInstaller( aDaemonBehaviour );
    61     CSisInstaller* self = new (ELeave) CSisInstaller( aDaemonBehaviour );
    58     self->ConstructL( aMainStatus ); // For uninstaller
    63     self->ConstructL( aMainStatus ); // For uninstaller
    59     CleanupStack::Pop(self);
    64     CleanupStack::Pop(self);
    60     return self;
    65     return self;
    61     }
    66     }
    62 	
    67 	
       
    68 // -----------------------------------------------------------------------
    63 // Install Request constructor
    69 // Install Request constructor
    64 	
    70 // -----------------------------------------------------------------------
       
    71 //	
    65 CSisInstaller::CSisInstaller( MDaemonInstallBehaviour* aDaemonBehaviour ) 
    72 CSisInstaller::CSisInstaller( MDaemonInstallBehaviour* aDaemonBehaviour ) 
    66     : CActive(CActive::EPriorityStandard),
    73     : CActive(CActive::EPriorityStandard),
    67     iDaemonBehaviour( aDaemonBehaviour ),
    74     iDaemonBehaviour( aDaemonBehaviour ),
    68     iState(EDSisInstallerStateIdle),
    75     iState(EDSisInstallerStateIdle),
    69     iFileIndex(0),
    76     iFileIndex(0),
    70     iInstallErr( KErrNone )
    77     iInstallErr( KErrNone )
    71     {
    78     {
    72     CActiveScheduler::Add(this);
    79     CActiveScheduler::Add(this);    
    73 #ifdef RD_MULTIPLE_DRIVE      
    80     iInstallerState = EDSisInstallerStateIdle;       
    74     iInstallerState = EDSisInstallerStateIdle;
    81     }
    75 #endif       
    82 	
    76     }
    83 // -----------------------------------------------------------------------
    77 	
    84 // Destructor
    78 // Install Request destructor
    85 // -----------------------------------------------------------------------
    79 
    86 //
    80 CSisInstaller::~CSisInstaller()
    87 CSisInstaller::~CSisInstaller()
    81     {
    88     {
    82     Cancel();
    89     Cancel();
    83     iTimer.Close();
    90     iTimer.Close();
    84     iFilesToInstall.ResetAndDestroy();
    91     iFilesToInstall.ResetAndDestroy();
    90     delete iPreviouslyInstalledAppsCache;
    97     delete iPreviouslyInstalledAppsCache;
    91     delete iInstallationFailedAppsCache;  
    98     delete iInstallationFailedAppsCache;  
    92     delete iShutdownWatcher;  
    99     delete iShutdownWatcher;  
    93     }
   100     }
    94 	
   101 	
       
   102 // -----------------------------------------------------------------------
    95 // 2nd phase construction
   103 // 2nd phase construction
    96 
   104 // -----------------------------------------------------------------------
       
   105 //
    97 void CSisInstaller::ConstructL( CProgramStatus& aMainStatus )
   106 void CSisInstaller::ConstructL( CProgramStatus& aMainStatus )
    98     {
   107     {
    99     User::LeaveIfError( iTimer.CreateLocal() );
   108     User::LeaveIfError( iTimer.CreateLocal() );
   100     User::LeaveIfError( iFs.Connect() );
   109     User::LeaveIfError( iFs.Connect() );
   101     User::LeaveIfError( iApaSession.Connect() );
   110     User::LeaveIfError( iApaSession.Connect() );
   109     // SisInstaller do not own this so do not delete.     
   118     // SisInstaller do not own this so do not delete.     
   110     iProgramStatus = &aMainStatus;  
   119     iProgramStatus = &aMainStatus;  
   111     iUpdateCache = ETrue;       
   120     iUpdateCache = ETrue;       
   112     }
   121     }
   113 		
   122 		
       
   123 // -----------------------------------------------------------------------
       
   124 // CSisInstaller::AddFileToInstallL
   114 // Set the location of all sis files and the list of them
   125 // Set the location of all sis files and the list of them
   115 // also take ownership of the pointers to memory
   126 // also take ownership of the pointers to memory
   116 		
   127 // -----------------------------------------------------------------------
       
   128 //		
   117 void CSisInstaller::AddFileToInstallL(const TDesC& aFileName)
   129 void CSisInstaller::AddFileToInstallL(const TDesC& aFileName)
   118     {
   130     {
   119     HBufC* fileName = aFileName.AllocLC();
   131     HBufC* fileName = aFileName.AllocLC();
   120     iFilesToInstall.AppendL( fileName );
   132     iFilesToInstall.AppendL( fileName );
   121     CleanupStack::Pop( fileName );
   133     CleanupStack::Pop( fileName );
   122     }
   134     }
   123 	
   135 	
       
   136 
       
   137 // -----------------------------------------------------------------------
       
   138 // CSisInstaller::StartInstallingL
   124 // Start the request to process the Sisx file
   139 // Start the request to process the Sisx file
   125 
   140 // -----------------------------------------------------------------------
       
   141 //
   126 void CSisInstaller::StartInstallingL()
   142 void CSisInstaller::StartInstallingL()
   127     {
   143     {
   128     FLOG( _L("Daemon: StartInstallingL") );
   144     FLOG( _L("Daemon: StartInstallingL") );
   129 
   145 
   130     if(!iFilesToInstall.Count())
   146     if(!iFilesToInstall.Count())
   157         }   
   173         }   
   158 
   174 
   159     if ( iState == EDSisInstallerStateIdle )
   175     if ( iState == EDSisInstallerStateIdle )
   160         {
   176         {
   161         // Reset the error
   177         // Reset the error
   162         iInstallErr = KErrNone;        
   178         iInstallErr = KErrNone; 
       
   179         // Update cache so we do not try to start install for
       
   180         // components which are installed.
       
   181         FLOG( _L("Daemon: StartInstallingL: Update installed cache") );
       
   182         TRAP_IGNORE( iPreviouslyInstalledAppsCache->UpdateAllL() );
       
   183         TRAP_IGNORE( iPreviouslyInstalledAppsCache->FlushToDiskL() );    
       
   184         
   163         CompleteSelf();
   185         CompleteSelf();
   164         }
   186         }
   165     }
   187     }
   166     
   188     
   167 #ifdef RD_MULTIPLE_DRIVE 
   189 // -----------------------------------------------------------------------
       
   190 // CSisInstaller::IsInstalling
   168 // Returns state of Installer. 
   191 // Returns state of Installer. 
   169 
   192 // -----------------------------------------------------------------------
       
   193 //
   170 TBool CSisInstaller::IsInstalling()
   194 TBool CSisInstaller::IsInstalling()
   171     {
   195     {
   172     if ( iInstallerState == EDSisInstallerStateCompleted )
   196     if ( iInstallerState == EDSisInstallerStateCompleted )
   173         {
   197         {
   174         return EFalse;
   198         return EFalse;
   176     else
   200     else
   177         {
   201         {
   178         return ETrue;
   202         return ETrue;
   179         }    
   203         }    
   180     }  
   204     }  
   181 #endif //RD_MULTIPLE_DRIVE       
   205        
   182 
   206 // -----------------------------------------------------------------------
       
   207 // CSisInstaller::CompleteSelf
   183 // Complete the request manually
   208 // Complete the request manually
   184 		
   209 // -----------------------------------------------------------------------
       
   210 //		
   185 void CSisInstaller::CompleteSelf()
   211 void CSisInstaller::CompleteSelf()
   186     {
   212     {
       
   213     FLOG( _L("Daemon: CSisInstaller::CompleteSelf") );
   187     if ( !IsActive() )
   214     if ( !IsActive() )
   188         {        
   215         {        
   189         TRequestStatus* status = &iStatus;
   216         TRequestStatus* status = &iStatus;
   190         User::RequestComplete(status,KErrNone);
   217         User::RequestComplete(status,KErrNone);
   191         SetActive();
   218         SetActive();
   192         }    
   219         }    
   193     }
   220     }
   194 
   221 
       
   222 // -----------------------------------------------------------------------
       
   223 // CSisInstaller::DoCancel
   195 // Cancel the active request
   224 // Cancel the active request
   196 
   225 // -----------------------------------------------------------------------
       
   226 //
   197 void CSisInstaller::DoCancel()
   227 void CSisInstaller::DoCancel()
   198     {
   228     {
       
   229     FLOG( _L("Daemon: CSisInstaller::DoCancel") ); 
   199     iTimer.Cancel();
   230     iTimer.Cancel();
   200 
   231 
   201     iFileIndex = 0;
   232     iFileIndex = 0;
   202     iFilesToInstall.ResetAndDestroy();
   233     iFilesToInstall.ResetAndDestroy();
   203     if ( iState == EDSisInstallerStateInstalling )
   234     if ( iState == EDSisInstallerStateInstalling )
   217         FLOG( _L("Daemon: DoCancel: Set EStateIdle") );
   248         FLOG( _L("Daemon: DoCancel: Set EStateIdle") );
   218         iProgramStatus->SetProgramStatusToIdle();
   249         iProgramStatus->SetProgramStatusToIdle();
   219         }    
   250         }    
   220     }
   251     }
   221 	
   252 	
   222 // When the software installer has changed state
   253 // -----------------------------------------------------------------------
   223 // attemp to install a sisx file
   254 // CSisInstaller::RunL
   224 
   255 // When the software installer has changed state attemp to install a 
       
   256 // sisx file
       
   257 // -----------------------------------------------------------------------
       
   258 //
   225 void CSisInstaller::RunL()
   259 void CSisInstaller::RunL()
   226     {
   260     {
   227     FLOG_2( _L("Daemon: Installer RunL status:%d, state:%d"), iStatus.Int(), iState );                
   261     FLOG_2( _L("Daemon: Installer RunL status:%d, state:%d"), iStatus.Int(), iState );                
   228     
   262     
   229     // For uninstaller
   263     // For uninstaller
   233         // If uninstaller is running already let's wait.
   267         // If uninstaller is running already let's wait.
   234         FLOG( _L("Daemon: RunL: EStateUninstalling -> wait") );                        
   268         FLOG( _L("Daemon: RunL: EStateUninstalling -> wait") );                        
   235         TTimeIntervalMicroSeconds32 time( KWaitUninstallerTime );                        
   269         TTimeIntervalMicroSeconds32 time( KWaitUninstallerTime );                        
   236         iTimer.After(iStatus,time);          
   270         iTimer.After(iStatus,time);          
   237         // Set to idle, installer has not yet started.
   271         // Set to idle, installer has not yet started.
   238         iState = EDSisInstallerStateIdle;
   272         iState = EDSisInstallerStateIdle;                
   239  #ifdef RD_MULTIPLE_DRIVE                
   273         iInstallerState = iState;                                 
   240         iInstallerState = iState;
       
   241  #endif                                
       
   242         SetActive();                                
   274         SetActive();                                
   243         }    
   275         }    
   244     else
   276     else
   245         {
   277         {
   246         // Ok uninstaller is in idle, run installing.
   278         // Ok uninstaller is in idle, run installing.
   259                     {
   291                     {
   260                     FLOG( _L("Daemon: RunL: iStatus: KSWInstErrBusy") );
   292                     FLOG( _L("Daemon: RunL: iStatus: KSWInstErrBusy") );
   261                     // User might be installing something, wait before retrying 
   293                     // User might be installing something, wait before retrying 
   262                     TTimeIntervalMicroSeconds32 time( KInstallRetryWaitTime );                        
   294                     TTimeIntervalMicroSeconds32 time( KInstallRetryWaitTime );                        
   263                     iTimer.After(iStatus,time);
   295                     iTimer.After(iStatus,time);
   264                     iState = EDSisInstallerStateInstallerBusy;
   296                     iState = EDSisInstallerStateInstallerBusy;               
   265     #ifdef RD_MULTIPLE_DRIVE                
   297                     iInstallerState = iState;                                  
   266                     iInstallerState = iState;
       
   267     #endif                                
       
   268                     SetActive();                        
   298                     SetActive();                        
   269                     break;                        
   299                     break;                        
   270                     }                
   300                     }                
   271                 else if ( (iStatus.Int() == SwiUI::KSWInstErrSecurityFailure && iInstallErr == KErrNone) ||
   301                 else if ( (iStatus.Int() == SwiUI::KSWInstErrSecurityFailure && iInstallErr == KErrNone) ||
   272                           (iStatus.Int() != KErrNone && iStatus.Int() != SwiUI::KSWInstErrSecurityFailure) )
   302                           (iStatus.Int() != KErrNone && iStatus.Int() != SwiUI::KSWInstErrSecurityFailure) )
   301     
   331     
   302                 // Check if we have more to install
   332                 // Check if we have more to install
   303                 if ( iFileIndex < iFilesToInstall.Count() )
   333                 if ( iFileIndex < iFilesToInstall.Count() )
   304                     {
   334                     {
   305                     // Kick of the next installation
   335                     // Kick of the next installation
   306                     iState = EDSisInstallerStateIdle;
   336                     iState = EDSisInstallerStateIdle;                  
   307     #ifdef RD_MULTIPLE_DRIVE                
   337                     iInstallerState = iState;                                       
   308                     iInstallerState = iState;
       
   309     #endif                
       
   310                     
       
   311                     CompleteSelf();
   338                     CompleteSelf();
   312                     }   
   339                     }   
   313                 else
   340                 else
   314                     {
   341                     {
   315                     // Note that this will also signal plugin that
   342                     // Note that this will also signal plugin that
   356                             TRAP_IGNORE( iDaemonBehaviour->RequestPluginInstall( iSisFile ) );                                                                                  
   383                             TRAP_IGNORE( iDaemonBehaviour->RequestPluginInstall( iSisFile ) );                                                                                  
   357                             
   384                             
   358                             // Let's continue to give all packages to plug-in. 
   385                             // Let's continue to give all packages to plug-in. 
   359                             // Note that we do not have iStatus as this is not async. call 
   386                             // Note that we do not have iStatus as this is not async. call 
   360                             // so we can not use EDSisInstallerStateInstalling state.                             
   387                             // so we can not use EDSisInstallerStateInstalling state.                             
   361                             iState = EDSisInstallerStateIdle;                           
   388                             iState = EDSisInstallerStateIdle;                                                 
   362         #ifdef RD_MULTIPLE_DRIVE                
       
   363                             iInstallerState = iState;
   389                             iInstallerState = iState;
   364         #endif           
   390                 
   365                             // Plugin interface is not asyncronous. We need to 
   391                             // Plugin interface is not asyncronous. We need to 
   366                             // complete self to get all packages to plugin.                            
   392                             // complete self to get all packages to plugin.                            
   367                             CompleteSelf(); 
   393                             CompleteSelf(); 
   368                             }                            
   394                             }                            
   369                         else
   395                         else
   370                             {                                                
   396                             {                                                
   371                             FLOG_1( _L("Daemon: Kick off the install for %S"), &iSisFile );
   397                             FLOG_1( _L("Daemon: Kick off the install for %S"), &iSisFile );
   372                             iInstallLauncher->InstallL( iSisFile, iStatus );
   398                             iInstallLauncher->InstallL( iSisFile, iStatus );
   373                             iDialogs->ShowWaitingNoteL(); 
   399                             iDialogs->ShowWaitingNoteL(); 
   374                             iState = EDSisInstallerStateInstalling;
   400                             iState = EDSisInstallerStateInstalling;                       
   375         #ifdef RD_MULTIPLE_DRIVE                
   401                             iInstallerState = iState;                                                   
   376                             iInstallerState = iState;
       
   377         #endif                                            
       
   378                             SetActive();
   402                             SetActive();
   379                             }
   403                             }
   380                         }               
   404                         }               
   381                     else
   405                     else
   382                         {                  
   406                         {                  
   383                         FLOG_1( _L("Daemon: No need to install %S"), &iSisFile );                                
   407                         FLOG_1( _L("Daemon: No need to install %S"), &iSisFile );                                
   384                         iState = EDSisInstallerStateIdle;
   408                         iState = EDSisInstallerStateIdle;                
   385     #ifdef RD_MULTIPLE_DRIVE                
   409                         iInstallerState = iState;                   
   386                         iInstallerState = iState;
       
   387     #endif                    
       
   388                         // Clear current pkg UID                    
   410                         // Clear current pkg UID                    
   389                         iCurrentPackageId = TUid::Null();                                   
   411                         iCurrentPackageId = TUid::Null();                                   
   390                         
   412                         
   391                         CompleteSelf();                    
   413                         CompleteSelf();                    
   392                         }                        
   414                         }                        
   404             case EDSisInstallerStateInstallerBusy:
   426             case EDSisInstallerStateInstallerBusy:
   405                 // Try to install the file again
   427                 // Try to install the file again
   406                 FLOG( _L("Daemon: RunL: EDSisInstallerStateInstallerBusy") );  
   428                 FLOG( _L("Daemon: RunL: EDSisInstallerStateInstallerBusy") );  
   407                 FLOG_1( _L("Daemon: Kick off the install for %S"), &iSisFile );
   429                 FLOG_1( _L("Daemon: Kick off the install for %S"), &iSisFile );
   408                 iInstallLauncher->InstallL( iSisFile, iStatus );
   430                 iInstallLauncher->InstallL( iSisFile, iStatus );
   409                 iState = EDSisInstallerStateInstalling;
   431                 iState = EDSisInstallerStateInstalling;                   
   410     #ifdef RD_MULTIPLE_DRIVE                
   432                 iInstallerState = iState;                                   
   411                 iInstallerState = iState;
       
   412     #endif                
       
   413                 
       
   414                 SetActive(); 
   433                 SetActive(); 
   415                 break;                       
   434                 break;                       
   416                 
   435                 
   417                 // Active object in unknown state
   436                 // Active object in unknown state
   418             default:
   437             default:
   419                 User::Panic(KMCSisInstaller,KErrNotSupported);
   438                 User::Panic(KMCSisInstaller,KErrNotSupported);
   420                 break;
   439                 break;
   421             }
   440             }
   422         } // else for uninstaller
   441         } // else for uninstaller
   423     }
   442     FLOG( _L("Daemon: RunL END") ); 
   424 	
   443     }
       
   444 	
       
   445 // -----------------------------------------------------------------------
       
   446 // CSisInstaller::RunError
   425 // If RunL leaves then ignore errors
   447 // If RunL leaves then ignore errors
   426 
   448 // -----------------------------------------------------------------------
       
   449 //
   427 TInt CSisInstaller::RunError(TInt aError)
   450 TInt CSisInstaller::RunError(TInt aError)
   428     {
   451     {
   429     FLOG_1( _L("Daemon: Installer RunL error %d"), aError );                
   452     FLOG_1( _L("Daemon: Installer Run error %d"), aError );                
   430     TInt err( KErrNone );
   453     TInt err( KErrNone );
   431     InstallationCompleted( aError );                
   454     InstallationCompleted( aError );                
   432     return err;
   455     return err;
   433     }	
   456     }	
   434     
   457 
       
   458 // -----------------------------------------------------------------------
       
   459 // CSisInstaller::NotifyShuttingDown
       
   460 // -----------------------------------------------------------------------
       
   461 //    
   435 void CSisInstaller::NotifyShuttingDown()
   462 void CSisInstaller::NotifyShuttingDown()
   436     {
   463     {
   437     // System is closing down, we need to stop installations and save
   464     // System is closing down, we need to stop installations and save
   438     // the lists of previously installed apps and failed installations.
   465     // the lists of previously installed apps and failed installations.
   439     // Application server receives EApaSystemEventShutdown event that
   466     // Application server receives EApaSystemEventShutdown event that
   440     // closes it down.
   467     // closes it down.
   441     Cancel();
   468     Cancel();
   442     }    	
   469     }   
   443 
   470 
       
   471 // -----------------------------------------------------------------------
       
   472 // CSisInstaller::InstallationCompleted
       
   473 // -----------------------------------------------------------------------
       
   474 //
   444 void CSisInstaller::InstallationCompleted( TInt aResult )
   475 void CSisInstaller::InstallationCompleted( TInt aResult )
   445     {
   476     {
   446     FLOG_1( _L("Daemon: InstallationCompleted with result = %d"), aResult );  
   477     FLOG_1( _L("Daemon: InstallationCompleted with result = %d"), aResult );  
   447     iState = EDSisInstallerStateIdle;    
   478     iState = EDSisInstallerStateIdle;    
   448     iInstallErr = KErrNone;    
   479     iInstallErr = KErrNone;    
   450     iInstallLauncher = NULL;
   481     iInstallLauncher = NULL;
   451     // We need to update cache again in RunL if plug-in is loaded.
   482     // We need to update cache again in RunL if plug-in is loaded.
   452     // It may be that plug-in does install packages after cache is updated.
   483     // It may be that plug-in does install packages after cache is updated.
   453     iUpdateCache = ETrue;
   484     iUpdateCache = ETrue;
   454     
   485     
   455 #ifdef RD_MULTIPLE_DRIVE 
       
   456     // If all files are installed set status to completed.
   486     // If all files are installed set status to completed.
   457     if ( iFileIndex >= iFilesToInstall.Count() )
   487     if ( iFileIndex >= iFilesToInstall.Count() )
   458         {                
   488         {                
   459         iInstallerState = EDSisInstallerStateCompleted; 
   489         iInstallerState = EDSisInstallerStateCompleted; 
   460         }
   490         }
   461 #endif                          
   491                             
   462    
       
   463     TRAP_IGNORE( iDialogs->CancelWaitingNoteL() );
   492     TRAP_IGNORE( iDialogs->CancelWaitingNoteL() );
   464     
   493     
   465     if ( aResult != KErrNone && 
   494     if ( aResult != KErrNone && 
   466          iSisFile.Length() > 0 && 
   495          iSisFile.Length() > 0 && 
   467          IsMediaPresent( TChar( iSisFile[0] ) ) )
   496          IsMediaPresent( TChar( iSisFile[0] ) ) )
   473         else 
   502         else 
   474             {
   503             {
   475             TRAP_IGNORE( iDialogs->ShowErrorResultL() );
   504             TRAP_IGNORE( iDialogs->ShowErrorResultL() );
   476             }    
   505             }    
   477         }
   506         }
   478     
   507 
   479     FLOG( _L("Daemon: InstallationCompleted: Update installed cache") );
   508 //TODO: remove this update. This is done in start installing !!!!     
       
   509     //FLOG( _L("Daemon: InstallationCompleted: Update installed cache") );
   480     // Update cache so we do not start to install those packages 
   510     // Update cache so we do not start to install those packages 
   481     // which are installed by the user manyally. 
   511     // which are installed by the user manyally. 
   482     // NOTE! plugin will install stuff after this call.
   512     // NOTE! plugin will install stuff after this call.
   483     TRAP_IGNORE(iPreviouslyInstalledAppsCache->UpdateAllL());
   513     //TRAP_IGNORE(iPreviouslyInstalledAppsCache->UpdateAllL());
   484     
   514     
   485     TRAP_IGNORE(iPreviouslyInstalledAppsCache->FlushToDiskL(););    
   515     TRAP_IGNORE(iPreviouslyInstalledAppsCache->FlushToDiskL(););    
   486     TRAP_IGNORE(iInstallationFailedAppsCache->FlushToDiskL());   
   516     TRAP_IGNORE(iInstallationFailedAppsCache->FlushToDiskL());   
   487     
   517     
   488     // Notify plugin that daemon has complete installation.
   518     // Notify plugin that daemon has complete installation.
   497           FLOG( _L("Daemon: InstallationCompleted: Set EStateIdle") );
   527           FLOG( _L("Daemon: InstallationCompleted: Set EStateIdle") );
   498           iProgramStatus->SetProgramStatusToIdle();
   528           iProgramStatus->SetProgramStatusToIdle();
   499           }       
   529           }       
   500     }  
   530     }  
   501 
   531 
       
   532 // -----------------------------------------------------------------------
       
   533 // CSisInstaller::NeedsInstallingL
   502 // Indicates if this package is installed or not.
   534 // Indicates if this package is installed or not.
   503 	
   535 // -----------------------------------------------------------------------
       
   536 //	
   504 TBool CSisInstaller::NeedsInstallingL( const TDesC& aPackageName )
   537 TBool CSisInstaller::NeedsInstallingL( const TDesC& aPackageName )
   505     {
   538     {
   506     FLOG( _L("Daemon: NeedsInstallingL") ); 
   539     FLOG( _L("Daemon: CSisInstaller::NeedsInstallingL") ); 
   507     TBool result( ETrue );
   540     //TBool result( ETrue );
       
   541     TBool needsInstalling( ETrue );
   508     
   542     
   509     // Read the controller data from the package
   543     // Read the controller data from the package
   510     CFileSisDataProvider* fileProvider = CFileSisDataProvider::NewLC( iFs, aPackageName ); 
   544     CFileSisDataProvider* fileProvider = CFileSisDataProvider::NewLC( iFs, aPackageName ); 
   511     TInt64 pos( 0 );                            
   545     TInt64 pos( 0 );                            
   512     fileProvider->Seek( ESeekStart, pos );                            
   546     fileProvider->Seek( ESeekStart, pos );                            
   515 
   549 
   516     HBufC8* controller = content->ReadControllerL();                                          
   550     HBufC8* controller = content->ReadControllerL();                                          
   517     CleanupStack::PushL( controller );                            
   551     CleanupStack::PushL( controller );                            
   518 
   552 
   519     // Code to read UID
   553     // Code to read UID
   520 
       
   521 	CDesDataProvider* controllerProvider= CDesDataProvider::NewLC(*controller);
   554 	CDesDataProvider* controllerProvider= CDesDataProvider::NewLC(*controller);
   522 	CController* controllerObject = NULL;
   555 	CController* controllerObject = NULL;
   523 	controllerObject = CController::NewL(*controllerProvider);
   556 	controllerObject = CController::NewL(*controllerProvider);
   524 	CleanupStack::PushL(controllerObject);
   557 	CleanupStack::PushL(controllerObject);
   525 
   558 
   526 	TUid packageId = controllerObject->Info().Uid().Uid();
   559 	TUid packageId = controllerObject->Info().Uid().Uid();
   527 
   560 
   528 	CleanupStack::PopAndDestroy(controllerObject);
   561 	CleanupStack::PopAndDestroy( controllerObject );
   529 	CleanupStack::PopAndDestroy(controllerProvider);
   562 	CleanupStack::PopAndDestroy( controllerProvider );
   530 
   563 
   531 	FLOG_1( _L("Daemon: NeedsInstallingL: Is UID installed = 0x%x"), packageId.iUid );
   564 	// Check if sw is installed previously. 
   532 	result = !iPreviouslyInstalledAppsCache->HasBeenPreviouslyInstalled(packageId);
   565 	// Note if UID is found sw will not be installed even if user 
   533 	FLOG_1( _L("Daemon: NeedsInstallingL: Has been installed (cache) = %d"), !result ); 
   566 	// has uninstall it bacause cache is not updated from SCR.
   534 	
   567 	FLOG_1( _L("Daemon: Is UID installed = 0x%x"), packageId.iUid );
   535 	if (result)
   568 	needsInstalling = !iPreviouslyInstalledAppsCache->
   536 	    {
   569                             HasBeenPreviouslyInstalled(packageId);
       
   570 	FLOG_1( _L("Daemon: Has been installed (cache) = %d"), !needsInstalling );
       
   571 	
       
   572 // TODO: Onko rom stubien tarkistus tarpeen jos upgrade ei ole sallittu.
       
   573 // Ei taida kannattaa tarksitaan RU ei pitäisi mennä läpi.
       
   574 	FLOG( _L("Daemon: HUOM ROM STUBEJA EI TARKISTETA") ); 	
       
   575 	/*	
       
   576 	// Huom! edellinen koodi ollut väärin koska UID on jo cachessä !
       
   577 	// Tarkistus pitää tehdä vain jos UID löytyy cachestä.
       
   578 	if ( !needsInstalling )
       
   579         {
   537         RSisRegistrySession registry;
   580         RSisRegistrySession registry;
   538         User::LeaveIfError( registry.Connect() );  
   581         User::LeaveIfError( registry.Connect() );  
   539         CleanupClosePushL( registry );  
   582         CleanupClosePushL( registry );  
   540         result = !registry.IsInstalledL( packageId );      
   583         result = !registry.IsInstalledL( packageId );      
   541           
   584           
   546             {
   589             {
   547             RSisRegistryEntry entry;
   590             RSisRegistryEntry entry;
   548             User::LeaveIfError( entry.Open( registry, packageId ) );
   591             User::LeaveIfError( entry.Open( registry, packageId ) );
   549             CleanupClosePushL( entry ); 
   592             CleanupClosePushL( entry ); 
   550             
   593             
   551             result = entry.IsInRomL();
   594             needsInstalling = entry.IsInRomL();
   552             
   595             
   553             FLOG_1( _L("Daemon: NeedsInstallingL: Is in ROM = %d"), result );              
   596             FLOG_1( _L("Daemon: NeedsInstallingL: Is in ROM = %d"), needsInstalling );              
   554             CleanupStack::PopAndDestroy( &entry );           
   597             CleanupStack::PopAndDestroy( &entry );           
   555             }
   598             }
   556         CleanupStack::PopAndDestroy( &registry ); 
   599         CleanupStack::PopAndDestroy( &registry ); 
   557 		}
   600         }
   558 		
   601 	*/	
       
   602 	
   559     // Check that previous install attempt did not fail.		
   603     // Check that previous install attempt did not fail.		
   560 	if (result)
   604 	if ( needsInstalling )
   561 	    {
   605 	    {
   562 	    result = !iInstallationFailedAppsCache->HasPreviousInstallationFailed( packageId );
   606 	    needsInstalling = !iInstallationFailedAppsCache->
   563 	    FLOG_1( _L("Daemon: NeedsInstallingL: Has failed (cache) = %d"), !result ); 
   607 	            HasPreviousInstallationFailed( packageId );
       
   608 	    FLOG_1( _L("Daemon: Has failed (cache) = %d"), !needsInstalling ); 
   564 	    }
   609 	    }
   565 
   610 
   566     // Update pkg ID. ID is added to cache after installation.
   611     // Update pkg ID. ID is added to cache after installation.
   567     if (result)
   612     if ( needsInstalling )
   568         {        
   613         {        
   569         iCurrentPackageId = packageId;
   614         iCurrentPackageId = packageId;
   570         }
   615         }
   571     
   616     
       
   617     // fileProvider, content, controller
   572     CleanupStack::PopAndDestroy( 3 );
   618     CleanupStack::PopAndDestroy( 3 );
   573         
   619     
   574     return result;            
   620     FLOG_1( _L("Daemon: NeedsInstallingL = %d"), needsInstalling );    
       
   621     return needsInstalling;            
   575     }  
   622     }  
   576 
   623 
       
   624 // -----------------------------------------------------------------------
       
   625 // CSisInstaller::IsMediaPresent
       
   626 // -----------------------------------------------------------------------
       
   627 //
   577 TBool CSisInstaller::IsMediaPresent( TChar aDrive )
   628 TBool CSisInstaller::IsMediaPresent( TChar aDrive )
   578     {
   629     {
   579     TInt drive( 0 );
   630     TInt drive( 0 );
   580     TInt err = iFs.CharToDrive( aDrive, drive );
   631     TInt err = iFs.CharToDrive( aDrive, drive );
   581     if ( err == KErrNone )
   632     if ( err == KErrNone )
   593         FLOG( _L("Daemon: Drive no present") );
   644         FLOG( _L("Daemon: Drive no present") );
   594         return EFalse;        
   645         return EFalse;        
   595         }
   646         }
   596     }
   647     }
   597 
   648 
       
   649 // -----------------------------------------------------------------------
       
   650 // CSisInstaller::IsValidPackageL
       
   651 // -----------------------------------------------------------------------
       
   652 //
   598 TBool CSisInstaller::IsValidPackageL( const TDesC& aPackageName )
   653 TBool CSisInstaller::IsValidPackageL( const TDesC& aPackageName )
   599     {
   654     {
   600     TBool result( EFalse );
   655     TBool result( EFalse );
   601   
   656   
   602     RFile file;
   657     RFile file;
   609     if ( dataType.Des8() == SwiUI::KSisxMimeType )
   664     if ( dataType.Des8() == SwiUI::KSisxMimeType )
   610         {
   665         {
   611         result = ETrue;
   666         result = ETrue;
   612         }
   667         }
   613 
   668 
       
   669     FLOG_1( _L("Daemon: IsValidPackageL = %d"), result );  
   614     return result;    
   670     return result;    
   615     }
   671     }
   616     
   672     
   617 //EOF
   673 //EOF
   618 
   674