appinstaller/AppinstUi/Daemon/Src/daemonbehaviour.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
    13 *
    13 *
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <usif/scr/scr.h>
       
    19 #include <usif/scr/scrcommon.h>
       
    20 #include <usif/scr/screntries.h>
       
    21 #include <apgcli.h>    // RApaSession
       
    22 #include <apgupdate.h> // TApaAppUpdateInfo
       
    23 
       
    24 #include "daemonbehaviour.h"
    18 #include "daemonbehaviour.h"
    25 #include "swispubsubdefs.h"
    19 #include "swispubsubdefs.h"
    26 #include "recsisx.h"
    20 #include "recsisx.h"
    27 #include "sisregistrywritablesession.h"
    21 #include "sisregistrywritablesession.h"
    28 #include "SWInstDebug.h"
    22 #include "SWInstDebug.h"
    29 #include "sisregistryentry.h"
    23 #include "sisregistryentry.h"
    30 
    24 
    31 using namespace Swi;
    25 
    32 
    26 namespace Swi
    33 // -----------------------------------------------------------------------
       
    34 // CDaemonBehaviour::NewL
       
    35 // -----------------------------------------------------------------------
       
    36 //    
       
    37 CDaemonBehaviour* CDaemonBehaviour::NewL( CProgramStatus& aMainStatus )
       
    38     {
    27     {
    39     CDaemonBehaviour* self = NewLC( aMainStatus );
       
    40     CleanupStack::Pop(self);
       
    41     return self;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------
       
    45 // CDaemonBehaviour::NewLC
       
    46 // -----------------------------------------------------------------------
       
    47 //
       
    48 CDaemonBehaviour* CDaemonBehaviour::NewLC( CProgramStatus& aMainStatus )
       
    49     {
       
    50     CDaemonBehaviour* self = new (ELeave) CDaemonBehaviour;
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL( aMainStatus );
       
    53     return self;  
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------
       
    57 // CDaemonBehaviour::ConstructL
       
    58 // -----------------------------------------------------------------------
       
    59 //        
       
    60 void CDaemonBehaviour::ConstructL( CProgramStatus& aMainStatus )
       
    61     {
       
    62     User::LeaveIfError(iFs.Connect());
       
    63     User::LeaveIfError(iFs.ShareProtected());
       
    64     
       
    65     // For uninstaller
    28     // For uninstaller
    66     iSisInstaller = CSisInstaller::NewL( this, aMainStatus );
    29     CDaemonBehaviour* CDaemonBehaviour::NewL( CProgramStatus& aMainStatus )
    67     // Create plugin
    30         {
    68     TRAP_IGNORE( iSwiDaemonPlugin = CSwiDaemonPlugin::NewL() );   
    31         CDaemonBehaviour* self = NewLC( aMainStatus );
    69     }
    32         CleanupStack::Pop(self);
    70 
    33         return self;
    71 // -----------------------------------------------------------------------
    34         }
    72 // CDaemonBehaviour::~CDaemonBehaviour
    35   
    73 // -----------------------------------------------------------------------
    36     CDaemonBehaviour* CDaemonBehaviour::NewLC( CProgramStatus& aMainStatus )
    74 //      
    37         {
    75 CDaemonBehaviour::~CDaemonBehaviour()
    38         CDaemonBehaviour* self = new (ELeave) CDaemonBehaviour;
    76     {
    39         CleanupStack::PushL(self);
    77     if ( iSwiDaemonPlugin )
    40         self->ConstructL( aMainStatus );
    78         {
    41         return self;  
    79         delete iSwiDaemonPlugin;
    42         }
    80         REComSession::FinalClose();
    43     
    81         }   
    44     void CDaemonBehaviour::ConstructL( CProgramStatus& aMainStatus )
    82     delete iSisInstaller;
    45         {
    83     iSisInstaller = NULL;
    46         User::LeaveIfError(iFs.Connect());
    84     iFs.Close();                
    47         User::LeaveIfError(iFs.ShareProtected());
    85     iDriveArray.Close();        
    48         
    86     }
    49         // For uninstaller
    87 
    50         iSisInstaller = CSisInstaller::NewL( this, aMainStatus );
    88 // -----------------------------------------------------------------------
    51         // Create plugin
    89 // CDaemonBehaviour::StartupL
    52         TRAP_IGNORE( iSwiDaemonPlugin = CSwiDaemonPlugin::NewL() );   
    90 // -----------------------------------------------------------------------
    53         }
    91 //         
    54   
    92 TBool CDaemonBehaviour::StartupL()
    55     CDaemonBehaviour::~CDaemonBehaviour()
    93     {
    56         {
    94     // Return state of Startup
    57         if ( iSwiDaemonPlugin )
    95     return ETrue;
    58             {
    96     }
    59             delete iSwiDaemonPlugin;
    97 
    60             REComSession::FinalClose();
    98 // -----------------------------------------------------------------------
    61             }   
    99 // CDaemonBehaviour::MediaChangeL
    62         delete iSisInstaller;
   100 // -----------------------------------------------------------------------
    63         iSisInstaller = NULL;
   101 //     
    64         iFs.Close();  
   102 void CDaemonBehaviour::MediaChangeL(TInt aDrive, TChangeType aChangeType)
    65                 
   103     {
    66 #ifdef RD_MULTIPLE_DRIVE    
   104     FLOG_1( _L("Daemon: MediaChangeL: Media change %d"), aDrive );
    67         iDriveArray.Close();
   105     RSisRegistryWritableSession registrySession;
    68 #endif        
   106     
    69         }
   107     User::LeaveIfError( registrySession.Connect() );
    70     
   108     CleanupClosePushL( registrySession );
    71     // from MDaemonBehaviour
   109     
    72     TBool CDaemonBehaviour::StartupL()
   110     
    73         {
   111     if ( aChangeType==EMediaInserted )
    74         // Return state of Startup
   112         {
    75         return ETrue;
   113         FLOG( _L("Daemon: MediaChangeL: Media inserted") ); 
    76         }
   114         TInt err = KErrNone;
    77 
   115         // Notify SCR and AppArc for media change.
    78     void CDaemonBehaviour::MediaChangeL(TInt aDrive, TChangeType aChangeType)
   116         TRAP( err, UpdateComponentStatusL( aChangeType, aDrive ) );
    79         {
   117         FLOG_1( _L("Daemon: UpdateComponentStatusL err = %d"), err );
    80         FLOG_1( _L("Daemon: Media change %d"), aDrive );
   118 
    81         RSisRegistryWritableSession registrySession;
   119         // We need call sis registry since this call will
    82         
   120         // activate sis registry to clean uninstalled components
    83         User::LeaveIfError(registrySession.Connect());
   121         // from inserted media.
    84         CleanupClosePushL(registrySession);
   122         registrySession.AddDriveL( aDrive );
    85         
       
    86         if (aChangeType==EMediaInserted)
       
    87             {
       
    88             FLOG( _L("Daemon: Media inserted") );  
       
    89             FLOG( _L("Daemon: Media change: Update sis registry") );            
       
    90             // notify IAR
       
    91             // Error ou1cimx1#212652
       
    92             // Note SWI Daemon needs to notify sis registry from
       
    93             // media change. Otherwice registry is not updated
       
    94             // and e.g. IsPresentL function will give false results.
       
    95             // Note also that this function should be called before
       
    96             // ProcessPreinstalledFilesL in SWI Daemon.            
       
    97             registrySession.AddDriveL(aDrive);
   123                                                 
    98                                                 
   124         // Scan directory on the card and run pre-installed through SWIS
    99             // Scan directory on the card and run pre-installed through SWIS
   125         FLOG( _L("Daemon: MediaChangeL: Process preinstalled files") );
   100             FLOG( _L("Daemon: Media change: Process preinstalled files") );
   126         ProcessPreinstalledFilesL( aDrive );  
   101             ProcessPreinstalledFilesL(aDrive);            
   127         FLOG_1( _L("Daemon: MediaChangeL: StartInstalling drive: %d"), aDrive );
   102         
       
   103 #ifdef RD_MULTIPLE_DRIVE   
       
   104             // Add inserted media drive to drive array.                     
       
   105             if ( iDriveArray.Find(aDrive) == KErrNotFound )
       
   106                 {                
       
   107                 iDriveArray.AppendL(aDrive); 
       
   108                 }      
       
   109 #endif      
       
   110             }
       
   111         else if (aChangeType==EMediaRemoved)
       
   112             {
       
   113             FLOG( _L("Daemon: Media removed") ); 
       
   114         
       
   115 #ifdef RD_MULTIPLE_DRIVE     
       
   116             // Get Installer state.                   
       
   117             TBool installerRunning = iSisInstaller->IsInstalling();                        
       
   118 #endif 
       
   119         
       
   120 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK                                           
       
   121             // notify IAR
       
   122             // Note SWI Daemon need to notify sis registry from
       
   123             // media change.            
       
   124             registrySession.RemoveDriveL(aDrive);
       
   125 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   126         
       
   127             // Cancel all requests for install
       
   128             iSisInstaller->Cancel();
       
   129         
       
   130 #ifdef RD_MULTIPLE_DRIVE
       
   131             // Notify plugin
       
   132             if(iSwiDaemonPlugin)
       
   133                 {
       
   134                 TInt index = iDriveArray.Find(aDrive);
       
   135                 iSwiDaemonPlugin->MediaRemoved(index);
       
   136                 }
       
   137 #else
       
   138             // Notify plugin
       
   139             if(iSwiDaemonPlugin)
       
   140                 {
       
   141                 iSwiDaemonPlugin->MediaRemoved(aDrive);
       
   142                 }
       
   143 #endif //RD_MULTIPLE_DRIVE            
       
   144         
       
   145 #ifdef RD_MULTIPLE_DRIVE
       
   146             // Get index of removed drive from array
       
   147             TInt index = iDriveArray.Find(aDrive);
       
   148         
       
   149             if ( index > KErrNotFound )
       
   150                 {
       
   151                 iDriveArray.Remove(index); 
       
   152                 iDriveArray.Compress();   
       
   153                 }
       
   154         
       
   155             // Continue installing from other drives if needed.
       
   156             if ( installerRunning )
       
   157                 {                                     
       
   158                 // Get count of inserted drives.
       
   159                 TInt count = iDriveArray.Count();
       
   160                         
       
   161                 if ( count )            
       
   162                     {                             
       
   163                     for(index = 0; index < count; index++ )
       
   164                         {                                        
       
   165                         ProcessPreinstalledFilesL(iDriveArray[index]);
       
   166                         iSisInstaller->StartInstallingL();                
       
   167                         }
       
   168                     }                
       
   169                 }           
       
   170 #endif            
       
   171             }
       
   172         
       
   173         CleanupStack::PopAndDestroy(&registrySession);
       
   174         }
       
   175       
       
   176     void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive)
       
   177         {
       
   178         _LIT(KDaemonPrivatePath,":\\private\\10202dce\\");
       
   179         
       
   180 #ifndef RD_MULTIPLE_DRIVE
       
   181         iSisInstaller->Cancel();
       
   182 #endif      
       
   183         // For uninstaller
       
   184         // Set on installing mode.
       
   185         iGeneralProcessStatus = EStateInstalling; 
       
   186         FLOG_1( _L("[CDaemonBehaviour] iGeneralProcessStatus = %d"), 
       
   187         iGeneralProcessStatus );
       
   188         
       
   189         ProcessPreinstalledFilesL(aDrive, KDaemonPrivatePath);
       
   190         iStartNotified = EFalse;
       
   191         iDrive = aDrive;    
   128         iSisInstaller->StartInstallingL();
   192         iSisInstaller->StartInstallingL();
   129                       
   193         }
   130         // Add inserted media drive to drive array.                     
   194     
   131         if ( iDriveArray.Find(aDrive) == KErrNotFound )
   195     void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive, const TDesC& aDirectory)
   132             {                
   196         {
   133             iDriveArray.AppendL(aDrive); 
   197         FLOG( _L("Daemon: ProcessPreInstalledFilesL") );
   134             }           
   198         TPath preInstalledPath;
   135         }
   199         TChar drive;
   136     else if (aChangeType==EMediaRemoved)
   200         RFs::DriveToChar(aDrive, drive);
   137         {
   201         preInstalledPath.Append(drive);
   138         FLOG( _L("Daemon: MediaChangeL: Media removed") );       
   202         preInstalledPath.Append(aDirectory);
   139         TInt err = KErrNone;           
   203         
   140         // Notify SCR and AppArc for media change.
   204         FLOG_1( _L("Daemon: ProcessPreInstalledFilesL Getting dir %S"), &preInstalledPath );
   141         TRAP( err, UpdateComponentStatusL( aChangeType, aDrive ) );
   205         CDir* dir = NULL;
   142         FLOG_1( _L("Daemon: UpdateComponentStatusL err = %d"), err );
   206         TInt err = iFs.GetDir(preInstalledPath, KEntryAttNormal, ESortNone, dir); 
   143  
   207         if (err != KErrNone && err != KErrPathNotFound)
   144         // Get Installer state.                   
   208             {
   145         TBool installerRunning = iSisInstaller->IsInstalling();
   209             FLOG_1( _L("Daemon: ProcessPreInstalledFilesL GetDir with error %d"), err );
   146         FLOG_1( _L("Daemon: MediaChangeL: IsInstalling = %d"), installerRunning );
   210             User::Leave(err);
   147         
   211             }
   148         FLOG( _L("Daemon: MediaChangeL: Cancel install process") );
   212         if(dir)
   149         // Cancel all requests for install
   213             {
   150         iSisInstaller->Cancel();                       
   214             // dir will only exist if GetDir succeeded
   151     
   215             CleanupStack::PushL(dir);
   152         // Notify plugin
   216             for(TInt i = 0; i < dir->Count(); i++)
   153         if( iSwiDaemonPlugin )
   217                 {
   154             {
   218                 const TEntry &entry = (*dir)[i];
   155             TInt index = iDriveArray.Find(aDrive);
   219                 if(!entry.IsDir())
   156             iSwiDaemonPlugin->MediaRemoved(index);
   220                     {
   157             }
   221                     TFileName fileName(preInstalledPath);
   158     
   222                     fileName.Append(entry.iName);
   159         // Get index of removed drive from array
   223                     iSisInstaller->AddFileToInstallL(fileName);
   160         TInt index = iDriveArray.Find(aDrive);
   224                     }
   161     
   225                 }
   162         if ( index > KErrNotFound )
   226             CleanupStack::PopAndDestroy(dir);
   163             {
   227             }
   164             iDriveArray.Remove(index); 
   228         }
   165             iDriveArray.Compress();   
   229 
   166             }
   230     // For uninstaller
       
   231     TInt& CDaemonBehaviour::GetProcessStatus()
       
   232         {
       
   233         return iGeneralProcessStatus;
       
   234         }
       
   235 
       
   236     // For uninstaller
       
   237     void CDaemonBehaviour::SetProcessStatus( TInt aStatus )
       
   238         {
       
   239         iGeneralProcessStatus = aStatus;
       
   240         }     
       
   241   
       
   242     // For plugin support
       
   243     void CDaemonBehaviour::DoNotifyMediaProcessingComplete()
       
   244         {
       
   245         if ( iSwiDaemonPlugin && iStartNotified )
       
   246             {
       
   247             iSwiDaemonPlugin->MediaProcessingComplete();
       
   248             }
       
   249         }
       
   250     
       
   251     // For plugin support
       
   252     TBool CDaemonBehaviour::IsPlugin()
       
   253         {        
       
   254         if ( iSwiDaemonPlugin )
       
   255             {
       
   256             return ETrue;
       
   257             }        
       
   258         return EFalse;
       
   259         }
       
   260     
       
   261     // For plugin support
       
   262     void CDaemonBehaviour::NotifyPlugin()
       
   263         {
       
   264         FLOG( _L("Daemon: NotifyPlugin"));
       
   265         if ( !iStartNotified )
       
   266             {
       
   267             FLOG_1( _L("Daemon: MediaProcessingStart for drive = %d"), iDrive );
       
   268             iSwiDaemonPlugin->MediaProcessingStart( iDrive );
       
   269             iStartNotified = ETrue;
       
   270             }    
       
   271         }
       
   272     
       
   273     // For plugin support
       
   274     void CDaemonBehaviour::RequestPluginInstall( TDesC& aSisFile )
       
   275         {
       
   276         // Note We will open file in here but that is only because
       
   277         // plug-in interface has been designed this way. Original
       
   278         // Symbian SWI daemon did use RApaLsSession for installing
       
   279         // and thus RFile was open already. 
       
   280         // Since current SWI Daemon does use SWI API it doesn't 
       
   281         // open files and thus we need to open the file in here.        
       
   282         FLOG( _L("Daemon: RequestPluginInstall "));
   167                 
   283                 
   168         // Continue installing from other drives if needed.
   284         RFile file;
   169         if ( installerRunning )
   285         User::LeaveIfError( file.Open( 
   170             {
   286                 iFs, aSisFile, EFileRead | EFileShareReadersOnly ) );
   171             FLOG( _L("Daemon: MediaChangeL: Continue installing other drives") );
   287         CleanupClosePushL( file );
   172             // Get count of inserted drives.
   288         
   173             TInt count = iDriveArray.Count();
   289         iSwiDaemonPlugin->RequestInstall( file );
   174             FLOG_1( _L("Daemon: Drive count = %d"), count );        
   290         
   175             if ( count )            
   291         // close file, original SWI Daemon do not leave file open.
   176                 {
   292         CleanupStack::PopAndDestroy( &file ); 
   177                 // Find packages for other drives.
   293         }
   178                 for(index = 0; index < count; index++ )
   294                                         
   179                     {                   
   295     } // namespace Swi
   180                     ProcessPreinstalledFilesL(iDriveArray[index]);                                        
       
   181                     }
       
   182                 // Start installing.
       
   183                 FLOG( _L("Daemon: MediaChangeL: StartInstallingL") );
       
   184                 iSisInstaller->StartInstallingL();
       
   185                 }                
       
   186             }                      
       
   187         }
       
   188     
       
   189     CleanupStack::PopAndDestroy(&registrySession);
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------
       
   193 // CDaemonBehaviour::ProcessPreinstalledFilesL
       
   194 // -----------------------------------------------------------------------
       
   195 //          
       
   196 void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive)
       
   197     {
       
   198     FLOG_1( _L("Daemon: ProcessPreinstalledFilesL: Drive index: %d"), 
       
   199             aDrive );
       
   200      _LIT( KDaemonPrivatePath,":\\private\\10202dce\\" );
       
   201     
       
   202     // For uninstaller
       
   203     // Set on installing mode.
       
   204     iGeneralProcessStatus = EStateInstalling; 
       
   205     FLOG_1( _L("[CDaemonBehaviour] iGeneralProcessStatus = %d"), 
       
   206     iGeneralProcessStatus );
       
   207     
       
   208     ProcessPreinstalledFilesL(aDrive, KDaemonPrivatePath);
       
   209     iStartNotified = EFalse;
       
   210     iDrive = aDrive;    
       
   211     FLOG( _L("Daemon: ProcessPreInstalledFilesL END") );
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------
       
   215 // CDaemonBehaviour::ProcessPreinstalledFilesL
       
   216 // -----------------------------------------------------------------------
       
   217 //        
       
   218 void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive, const TDesC& aDirectory)
       
   219     {    
       
   220     TPath preInstalledPath;
       
   221     TChar drive;
       
   222     RFs::DriveToChar(aDrive, drive);
       
   223     preInstalledPath.Append(drive);
       
   224     preInstalledPath.Append(aDirectory);
       
   225     
       
   226     FLOG_1( _L("Daemon: ProcessPreInstalledFilesL Getting dir %S"), &preInstalledPath );
       
   227     CDir* dir = NULL;
       
   228     TInt err = iFs.GetDir( preInstalledPath, KEntryAttNormal, ESortNone, dir ); 
       
   229     if ( err != KErrNone && err != KErrPathNotFound )
       
   230         {
       
   231         FLOG_1( _L("Daemon: ProcessPreInstalledFilesL GetDir with error %d"), err );
       
   232         User::Leave(err);
       
   233         }
       
   234     if(dir)
       
   235         {
       
   236         // dir will only exist if GetDir succeeded
       
   237         CleanupStack::PushL(dir);
       
   238         for(TInt i = 0; i < dir->Count(); i++)
       
   239             {
       
   240             const TEntry &entry = (*dir)[i];
       
   241             if(!entry.IsDir())
       
   242                 {
       
   243                 TFileName fileName(preInstalledPath);
       
   244                 fileName.Append(entry.iName);                
       
   245                 // Add files to sis installer.
       
   246                 iSisInstaller->AddFileToInstallL(fileName);
       
   247                 }
       
   248             }
       
   249         CleanupStack::PopAndDestroy(dir);
       
   250         }
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------
       
   254 // CDaemonBehaviour::GetProcessStatus
       
   255 // -----------------------------------------------------------------------
       
   256 //     
       
   257 TInt& CDaemonBehaviour::GetProcessStatus()
       
   258     {
       
   259     return iGeneralProcessStatus;
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------
       
   263 // CDaemonBehaviour::SetProcessStatus
       
   264 // -----------------------------------------------------------------------
       
   265 //     
       
   266 void CDaemonBehaviour::SetProcessStatus( TInt aStatus )
       
   267     {
       
   268     iGeneralProcessStatus = aStatus;
       
   269     }     
       
   270 
       
   271 // -----------------------------------------------------------------------
       
   272 // CDaemonBehaviour::DoNotifyMediaProcessingComplete
       
   273 // -----------------------------------------------------------------------
       
   274 //      
       
   275 void CDaemonBehaviour::DoNotifyMediaProcessingComplete()
       
   276     {
       
   277     if ( iSwiDaemonPlugin && iStartNotified )
       
   278         {
       
   279         iSwiDaemonPlugin->MediaProcessingComplete();
       
   280         }
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------
       
   284 // CDaemonBehaviour::IsPlugin
       
   285 // -----------------------------------------------------------------------
       
   286 //         
       
   287 // For plugin support
       
   288 TBool CDaemonBehaviour::IsPlugin()
       
   289     {        
       
   290     if ( iSwiDaemonPlugin )
       
   291         {
       
   292         return ETrue;
       
   293         }        
       
   294     return EFalse;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------
       
   298 // CDaemonBehaviour::NotifyPlugin
       
   299 // -----------------------------------------------------------------------
       
   300 //        
       
   301 // For plugin support
       
   302 void CDaemonBehaviour::NotifyPlugin()
       
   303     {
       
   304     FLOG( _L("Daemon: NotifyPlugin"));
       
   305     if ( !iStartNotified )
       
   306         {
       
   307         FLOG_1( _L("Daemon: MediaProcessingStart for drive = %d"), iDrive );
       
   308         iSwiDaemonPlugin->MediaProcessingStart( iDrive );
       
   309         iStartNotified = ETrue;
       
   310         }    
       
   311     }
       
   312 
       
   313 // -----------------------------------------------------------------------
       
   314 // CDaemonBehaviour::RequestPluginInstall
       
   315 // -----------------------------------------------------------------------
       
   316 //         
       
   317 void CDaemonBehaviour::RequestPluginInstall( TDesC& aSisFile )
       
   318     {
       
   319     // Note We will open file in here but that is only because
       
   320     // plug-in interface has been designed this way. Original
       
   321     // Symbian SWI daemon did use RApaLsSession for installing
       
   322     // and thus RFile was open already. 
       
   323     // Since current SWI Daemon does use SWI API it doesn't 
       
   324     // open files and thus we need to open the file in here.        
       
   325     FLOG( _L("Daemon: RequestPluginInstall "));
       
   326             
       
   327     RFile file;
       
   328     User::LeaveIfError( file.Open( 
       
   329             iFs, aSisFile, EFileRead | EFileShareReadersOnly ) );
       
   330     CleanupClosePushL( file );
       
   331     
       
   332     iSwiDaemonPlugin->RequestInstall( file );
       
   333     
       
   334     // close file, original SWI Daemon do not leave file open.
       
   335     CleanupStack::PopAndDestroy( &file ); 
       
   336     }
       
   337  
       
   338 // -----------------------------------------------------------------------
       
   339 // CDaemonBehaviour::UpdateComponentStatusL
       
   340 // -----------------------------------------------------------------------
       
   341 //         
       
   342 void CDaemonBehaviour::UpdateComponentStatusL( TChangeType aChangeType, 
       
   343                                                TInt aDrive )
       
   344     {
       
   345     FLOG( _L("Daemon: UpdateComponentStatus") ); 
       
   346             
       
   347     Usif::RSoftwareComponentRegistry scrServer;       
       
   348     User::LeaveIfError( scrServer.Connect() );
       
   349     CleanupClosePushL( scrServer );
       
   350             
       
   351     // Filter all other component types except sisx.
       
   352     Usif::CComponentFilter* filter = Usif::CComponentFilter::NewLC();        
       
   353     filter->SetSoftwareTypeL( Usif::KSoftwareTypeNative );
       
   354         
       
   355     RArray<Usif::TComponentId> componentIdList;
       
   356     CleanupClosePushL( componentIdList );
       
   357     
       
   358     // Get list of all native (sisx) installed packages. 
       
   359     scrServer.GetComponentIdsL( componentIdList, filter  );
       
   360     FLOG_1( _L("Daemon: componentIdList count: %d"),componentIdList.Count() ); 
       
   361    
       
   362     if ( componentIdList.Count() )
       
   363         {
       
   364         RArray<TApaAppUpdateInfo> appInfoArray;         
       
   365         CleanupClosePushL( appInfoArray );
       
   366         FLOG_1( _L("Daemon: target drive: %d"), aDrive );
       
   367                               
       
   368 #ifdef _DEBUG
       
   369         TChar targetDrive;
       
   370         iFs.DriveToChar( aDrive, targetDrive );
       
   371         HBufC* tarceBuf = HBufC::NewL( 16 );
       
   372         TPtr bufPtr = tarceBuf->Des();
       
   373         bufPtr.Append( targetDrive );
       
   374         FLOG_1( _L("Daemon: target drive: %S"), &bufPtr ); 
       
   375         delete tarceBuf;
       
   376 #endif         
       
   377     
       
   378         FLOG( _L("Daemon: Check all SCR native components") ); 
       
   379         // Check all components in SCR. If media is removed/inserted
       
   380         // change status flag in SCR and in AppArc.
       
   381         for ( TInt index=0; index < componentIdList.Count(); index++ )
       
   382             {  
       
   383             Usif::TComponentId componentId( componentIdList[index] );
       
   384             FLOG_1( _L("Daemon: componentId: %d"), componentId ); 
       
   385         
       
   386             // Check that package is not in ROM. If package is in rom
       
   387             // it can not be removed/not present.
       
   388             TBool inRom = scrServer.IsComponentOnReadOnlyDriveL( componentId );
       
   389             FLOG_1( _L("Daemon: IsComponentOnReadOnlyDriveL: %d"), inRom ); 
       
   390             
       
   391             if ( !inRom )
       
   392                 {              
       
   393                 UpdateStatusL( scrServer, 
       
   394                                componentId, 
       
   395                                aChangeType,
       
   396                                aDrive,
       
   397                                appInfoArray );
       
   398                 }                            
       
   399             } // for loop
       
   400         
       
   401         FLOG_1( _L("Daemon: appInfoArray.Count = %d"), appInfoArray.Count() );         
       
   402         // Check do we have updated some application info.
       
   403         if ( appInfoArray.Count() )
       
   404             {             
       
   405             // Update AppArc list after we have all application 
       
   406             // uids/status in array. 
       
   407             FLOG( _L("Daemon: Update AppArc") );
       
   408             RApaLsSession appArcSession;
       
   409             TInt err = appArcSession.Connect();
       
   410             FLOG_1( _L("Daemon: appArcSession.Connect err = %d"), err ); 
       
   411             if ( !err )
       
   412                 {
       
   413                 CleanupClosePushL( appArcSession );            
       
   414                 FLOG( _L("Daemon: UpdateAppListL") ); 
       
   415                 appArcSession.UpdateAppListL( appInfoArray );            
       
   416                 CleanupStack::PopAndDestroy(); // appArcSession                 
       
   417                 }
       
   418             }
       
   419         CleanupStack::PopAndDestroy( &appInfoArray );
       
   420         } // if componentList.Count()
       
   421              
       
   422     CleanupStack::PopAndDestroy( &componentIdList ); //componentIDList.Close();
       
   423     CleanupStack::PopAndDestroy( filter ); 
       
   424     CleanupStack::PopAndDestroy( &scrServer );  
       
   425     FLOG( _L("Daemon: UpdateComponentStatus END") ); 
       
   426     } 
       
   427 
       
   428 // -----------------------------------------------------------------------
       
   429 // CDaemonBehaviour::UpdateStatusL
       
   430 // -----------------------------------------------------------------------
       
   431 //    
       
   432 void CDaemonBehaviour::UpdateStatusL( 
       
   433     Usif::RSoftwareComponentRegistry& aScrServer,
       
   434     Usif::TComponentId aComponentId,
       
   435     TChangeType aChangeType,
       
   436     TInt aTargetDrive,
       
   437     RArray<TApaAppUpdateInfo>& aAppInfoArray )     
       
   438     {
       
   439     FLOG( _L("Daemon: CDaemonBehaviour::UpdateStatusL start") ); 
       
   440     
       
   441     Usif::CComponentEntry* entry = Usif::CComponentEntry::NewL();
       
   442     CleanupStack::PushL( entry );
       
   443         
       
   444     TInt err = KErrNone;
       
   445     TRAP( err, aScrServer.GetComponentL( aComponentId, 
       
   446                                          *entry, 
       
   447                                          Usif::KUnspecifiedLocale ) );    
       
   448     FLOG_1( _L("Daemon: GetComponentL TRAP err = %d"), err );
       
   449     
       
   450     // If we get error let's not stop the loop.
       
   451     if ( !err )
       
   452         { 
       
   453         TBool isInTargetDrive = EFalse;
       
   454         // Get all component drives.
       
   455         TDriveList driveList;                
       
   456         driveList = entry->InstalledDrives();           
       
   457 
       
   458         FLOG( _L("Daemon: Check all drives for this component") ); 
       
   459         // Go through all drives which have files for this component.
       
   460         for ( TInt i = 0; i < KMaxDrives; i++ )
       
   461             {                
       
   462             if ( driveList[i] != 0 )
       
   463                 {                                           
       
   464                 FLOG_1( _L("Daemon: Found drive: %d"), i ); 
       
   465                 
       
   466                 if ( aTargetDrive == i )
       
   467                     {
       
   468                     // Ok we have files in this target drive.
       
   469                     isInTargetDrive = ETrue;
       
   470                     FLOG( _L("Daemon: Component has files in target drive") ); 
       
   471                     }
       
   472                 }
       
   473             } // for
       
   474                             
       
   475         // Check if component or part of it is in the media.
       
   476         if ( isInTargetDrive )
       
   477             {
       
   478             // We need to update applications status to AppArc when
       
   479             // there is some media change. AppArc needs application
       
   480             // UID (not package UID) so we need to get all app. UIDs
       
   481             // from the package and set them to present or not present.
       
   482             
       
   483             FLOG( _L("Daemon: Create application status for AppArc") );
       
   484             FLOG( _L("Daemon: Get applications UIDs from SCR") );
       
   485             RArray<TUid> appUidArray;
       
   486             CleanupClosePushL( appUidArray );
       
   487              
       
   488             TRAP( err, aScrServer.GetAppUidsForComponentL( aComponentId, appUidArray ) );
       
   489             FLOG_1( _L("Daemon: GetAppUidsForComponentL TRAP err = %d"), err );                        
       
   490             FLOG_1( _L("Daemon: UID array count = %d"), appUidArray.Count() );
       
   491             
       
   492             for (TInt index = 0; index < appUidArray.Count(); index++)
       
   493                 {
       
   494                 FLOG_1( _L("Daemon: Add app UID = 0x%x"), 
       
   495                  appUidArray[index].iUid );                
       
   496                 
       
   497                 TApaAppUpdateInfo appInfo;
       
   498                 appInfo.iAppUid = appUidArray[index]; 
       
   499                 
       
   500                 if ( aChangeType == EMediaInserted  )
       
   501                     {
       
   502                     appInfo.iAction = TApaAppUpdateInfo::EAppPresent;
       
   503                     FLOG( _L("Daemon: Set app = EAppPresent") );
       
   504                     }
       
   505                 else
       
   506                     {
       
   507                     appInfo.iAction = TApaAppUpdateInfo::EAppNotPresent;
       
   508                     FLOG( _L("Daemon: Set app = EAppNotPresent") );
       
   509                     }
       
   510                 
       
   511                 aAppInfoArray.Append( appInfo );   
       
   512                 }                           
       
   513             CleanupStack::PopAndDestroy(&appUidArray);
       
   514 // Set do not work, it will leave.
       
   515 /*            
       
   516             FLOG( _L("Daemon: Set component status to SCR") );
       
   517             // Update component flag to SCR. 
       
   518             if ( aChangeType == EMediaInserted )
       
   519                 {  
       
   520                 FLOG( _L("Daemon: Set component present = TRUE") );                                  
       
   521                 TRAP( err, aScrServer.SetIsComponentPresentL( aComponentId, ETrue ) );                                                                            
       
   522                 }
       
   523             else if ( aChangeType==EMediaRemoved )
       
   524                 {
       
   525                 FLOG( _L("Daemon: Set component present = FALSE") );                              
       
   526                 TRAP( err, aScrServer.SetIsComponentPresentL( aComponentId, EFalse ) );                                                                               
       
   527                 }            
       
   528             FLOG_1( _L("Daemon: SetIsComponentPresentL TRAP err = %d"), err );
       
   529 */                                                          
       
   530             }   // if isInTargetDrive        
       
   531         }   // if err
       
   532     
       
   533     CleanupStack::PopAndDestroy( entry );
       
   534     entry = NULL;
       
   535     
       
   536     FLOG( _L("Daemon: CDaemonBehaviour::UpdateStatusL end") ); 
       
   537     }
       
   538 
       
   539 //EOF
   296 //EOF