appinstaller/AppinstUi/Daemon/Src/daemonbehaviour.cpp
changeset 1 c42dffbd5b4f
parent 0 ba25891c3a9e
child 25 7333d7932ef7
equal deleted inserted replaced
0:ba25891c3a9e 1:c42dffbd5b4f
    22 #include "SWInstDebug.h"
    22 #include "SWInstDebug.h"
    23 #include "sisregistryentry.h"
    23 #include "sisregistryentry.h"
    24 
    24 
    25 
    25 
    26 namespace Swi
    26 namespace Swi
    27 	{
    27     {
    28 	// For uninstaller
    28     // For uninstaller
    29 	CDaemonBehaviour* CDaemonBehaviour::NewL( CProgramStatus& aMainStatus )
    29     CDaemonBehaviour* CDaemonBehaviour::NewL( CProgramStatus& aMainStatus )
    30 		{
    30         {
    31 		CDaemonBehaviour* self = NewLC( aMainStatus );
    31         CDaemonBehaviour* self = NewLC( aMainStatus );
    32 		CleanupStack::Pop(self);
    32         CleanupStack::Pop(self);
    33 		return self;
    33         return self;
    34 		}
    34         }
    35 	
    35   
    36 	CDaemonBehaviour* CDaemonBehaviour::NewLC( CProgramStatus& aMainStatus )
    36     CDaemonBehaviour* CDaemonBehaviour::NewLC( CProgramStatus& aMainStatus )
    37 		{
    37         {
    38 		CDaemonBehaviour* self = new (ELeave) CDaemonBehaviour;
    38         CDaemonBehaviour* self = new (ELeave) CDaemonBehaviour;
    39 		CleanupStack::PushL(self);
    39         CleanupStack::PushL(self);
    40 		self->ConstructL( aMainStatus );
    40         self->ConstructL( aMainStatus );
    41 		return self;	
    41         return self;  
    42 		}
    42         }
    43 		
    43     
    44 	void CDaemonBehaviour::ConstructL( CProgramStatus& aMainStatus )
    44     void CDaemonBehaviour::ConstructL( CProgramStatus& aMainStatus )
    45 		{
    45         {
    46 		User::LeaveIfError(iFs.Connect());
    46         User::LeaveIfError(iFs.Connect());
    47 		User::LeaveIfError(iFs.ShareProtected());
    47         User::LeaveIfError(iFs.ShareProtected());
    48 
    48         
    49 		// For uninstaller
    49         // For uninstaller
    50 		iSisInstaller = CSisInstaller::NewL( this, aMainStatus );
    50         iSisInstaller = CSisInstaller::NewL( this, aMainStatus );
    51 		// Create plugin
    51         // Create plugin
    52 		TRAP_IGNORE( iSwiDaemonPlugin = CSwiDaemonPlugin::NewL() );		
    52         TRAP_IGNORE( iSwiDaemonPlugin = CSwiDaemonPlugin::NewL() );   
    53 		}
    53         }
    54 	
    54   
    55 	CDaemonBehaviour::~CDaemonBehaviour()
    55     CDaemonBehaviour::~CDaemonBehaviour()
    56 		{
    56         {
    57 	    if ( iSwiDaemonPlugin )
    57         if ( iSwiDaemonPlugin )
    58 	        {
    58             {
    59 	        delete iSwiDaemonPlugin;
    59             delete iSwiDaemonPlugin;
    60 	        REComSession::FinalClose();
    60             REComSession::FinalClose();
    61 	        }		
    61             }   
    62 		delete iSisInstaller;
    62         delete iSisInstaller;
    63 		iSisInstaller = NULL;
    63         iSisInstaller = NULL;
    64 		iFs.Close();	
    64         iFs.Close();  
    65 
    65                 
    66 		
    66 #ifdef RD_MULTIPLE_DRIVE    
    67 #ifdef RD_MULTIPLE_DRIVE 		
    67         iDriveArray.Close();
    68 		iDriveArray.Close();
    68 #endif        
    69 #endif				
    69         }
    70 		}
    70     
    71 		
    71     // from MDaemonBehaviour
    72 	// from MDaemonBehaviour
    72     TBool CDaemonBehaviour::StartupL()
    73 	TBool CDaemonBehaviour::StartupL()
    73         {
    74 		{
    74         // Return state of Startup
    75 		// Return state of Startup
    75         return ETrue;
    76 		return ETrue;
    76         }
    77 		}
       
    78 
    77 
    79     void CDaemonBehaviour::MediaChangeL(TInt aDrive, TChangeType aChangeType)
    78     void CDaemonBehaviour::MediaChangeL(TInt aDrive, TChangeType aChangeType)
    80 		{
    79         {
    81         FLOG_1( _L("Daemon: Media change %d"), aDrive );
    80         FLOG_1( _L("Daemon: Media change %d"), aDrive );
    82         RSisRegistryWritableSession registrySession;
    81         RSisRegistryWritableSession registrySession;
    83         
    82         
    84         User::LeaveIfError(registrySession.Connect());
    83         User::LeaveIfError(registrySession.Connect());
    85         CleanupClosePushL(registrySession);
    84         CleanupClosePushL(registrySession);
    86         
    85         
    87         if (aChangeType==EMediaInserted)
    86         if (aChangeType==EMediaInserted)
    88             {
    87             {
    89             FLOG( _L("Daemon: Media inserted") );                        
    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);
       
    98                                                 
    90             // Scan directory on the card and run pre-installed through SWIS
    99             // Scan directory on the card and run pre-installed through SWIS
    91             ProcessPreinstalledFilesL(aDrive);
   100             FLOG( _L("Daemon: Media change: Process preinstalled files") );
    92             
   101             ProcessPreinstalledFilesL(aDrive);            
    93             // notify IAR
   102         
    94             registrySession.AddDriveL(aDrive);
       
    95 			
       
    96 #ifdef RD_MULTIPLE_DRIVE   
   103 #ifdef RD_MULTIPLE_DRIVE   
    97             // Add inserted media drive to drive array.                     
   104             // Add inserted media drive to drive array.                     
    98             if ( iDriveArray.Find(aDrive) == KErrNotFound )
   105             if ( iDriveArray.Find(aDrive) == KErrNotFound )
    99                 {                
   106                 {                
   100                 iDriveArray.AppendL(aDrive); 
   107                 iDriveArray.AppendL(aDrive); 
   101                 }      
   108                 }      
   102 #endif			
   109 #endif      
   103             }
   110             }
   104         else if (aChangeType==EMediaRemoved)
   111         else if (aChangeType==EMediaRemoved)
   105             {
   112             {
   106             FLOG( _L("Daemon: Media removed") ); 
   113             FLOG( _L("Daemon: Media removed") ); 
   107             
   114         
   108 #ifdef RD_MULTIPLE_DRIVE     
   115 #ifdef RD_MULTIPLE_DRIVE     
   109             // Get Installer state.                   
   116             // Get Installer state.                   
   110             TBool installerRunning = iSisInstaller->IsInstalling();                        
   117             TBool installerRunning = iSisInstaller->IsInstalling();                        
   111 #endif 
   118 #endif 
   112             
   119         
   113 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK                                           
   120 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK                                           
   114             // notify IAR
   121             // notify IAR
       
   122             // Note SWI Daemon need to notify sis registry from
       
   123             // media change.            
   115             registrySession.RemoveDriveL(aDrive);
   124             registrySession.RemoveDriveL(aDrive);
   116 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   125 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   117             
   126         
   118             // Cancel all requests for install
   127             // Cancel all requests for install
   119             iSisInstaller->Cancel();
   128             iSisInstaller->Cancel();
   120             
   129         
   121 #ifdef RD_MULTIPLE_DRIVE
   130 #ifdef RD_MULTIPLE_DRIVE
   122 // Notify plugin
   131             // Notify plugin
   123         if(iSwiDaemonPlugin)
   132             if(iSwiDaemonPlugin)
   124             {
   133                 {
   125             TInt index = iDriveArray.Find(aDrive);
   134                 TInt index = iDriveArray.Find(aDrive);
   126             iSwiDaemonPlugin->MediaRemoved(index);
   135                 iSwiDaemonPlugin->MediaRemoved(index);
   127             }
   136                 }
   128 #else
   137 #else
   129 // Notify plugin
   138             // Notify plugin
   130         if(iSwiDaemonPlugin)
   139             if(iSwiDaemonPlugin)
   131             {
   140                 {
   132             iSwiDaemonPlugin->MediaRemoved(aDrive);
   141                 iSwiDaemonPlugin->MediaRemoved(aDrive);
   133             }
   142                 }
   134 #endif //RD_MULTIPLE_DRIVE            
   143 #endif //RD_MULTIPLE_DRIVE            
   135 
   144         
   136 #ifdef RD_MULTIPLE_DRIVE
   145 #ifdef RD_MULTIPLE_DRIVE
   137             // Get index of removed drive from array
   146             // Get index of removed drive from array
   138             TInt index = iDriveArray.Find(aDrive);
   147             TInt index = iDriveArray.Find(aDrive);
   139             
   148         
   140             if ( index > KErrNotFound )
   149             if ( index > KErrNotFound )
   141                 {
   150                 {
   142                 iDriveArray.Remove(index); 
   151                 iDriveArray.Remove(index); 
   143                 iDriveArray.Compress();   
   152                 iDriveArray.Compress();   
   144                 }
   153                 }
   145             
   154         
   146             // Continue installing from other drives if needed.
   155             // Continue installing from other drives if needed.
   147             if ( installerRunning )
   156             if ( installerRunning )
   148                 {			    			    	                
   157                 {                                     
   149                 // Get count of inserted drives.
   158                 // Get count of inserted drives.
   150                 TInt count = iDriveArray.Count();
   159                 TInt count = iDriveArray.Count();
   151                                 
   160                         
   152                 if ( count )            
   161                 if ( count )            
   153                     {                             
   162                     {                             
   154                     for(index = 0; index < count; index++ )
   163                     for(index = 0; index < count; index++ )
   155                         {                                        
   164                         {                                        
   156                         ProcessPreinstalledFilesL(iDriveArray[index]);
   165                         ProcessPreinstalledFilesL(iDriveArray[index]);
   157                         iSisInstaller->StartInstallingL();                
   166                         iSisInstaller->StartInstallingL();                
   158                         }
   167                         }
   159                     }                
   168                     }                
   160                 }           
   169                 }           
   161 #endif						
   170 #endif            
   162 			}
   171             }
   163 		CleanupStack::PopAndDestroy(&registrySession);
   172         
   164 		}
   173         CleanupStack::PopAndDestroy(&registrySession);
   165 	
   174         }
       
   175       
   166     void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive)
   176     void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive)
   167 		{
   177         {
   168 		_LIT(KDaemonPrivatePath,":\\private\\10202dce\\");
   178         _LIT(KDaemonPrivatePath,":\\private\\10202dce\\");
   169 		
   179         
   170 #ifndef RD_MULTIPLE_DRIVE
   180 #ifndef RD_MULTIPLE_DRIVE
   171 		iSisInstaller->Cancel();
   181         iSisInstaller->Cancel();
   172 #endif			
   182 #endif      
   173 		// For uninstaller
   183         // For uninstaller
   174         // Set on installing mode.
   184         // Set on installing mode.
   175         iGeneralProcessStatus = EStateInstalling; 
   185         iGeneralProcessStatus = EStateInstalling; 
   176         FLOG_1( _L("[CDaemonBehaviour] iGeneralProcessStatus = %d"), 
   186         FLOG_1( _L("[CDaemonBehaviour] iGeneralProcessStatus = %d"), 
   177                 iGeneralProcessStatus );
   187         iGeneralProcessStatus );
   178 		
   188         
   179 		ProcessPreinstalledFilesL(aDrive, KDaemonPrivatePath);
   189         ProcessPreinstalledFilesL(aDrive, KDaemonPrivatePath);
   180         iStartNotified = EFalse;
   190         iStartNotified = EFalse;
   181         iDrive = aDrive;		
   191         iDrive = aDrive;    
   182 		iSisInstaller->StartInstallingL();
   192         iSisInstaller->StartInstallingL();
   183 		}
   193         }
   184 		
   194     
   185 	void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive, const TDesC& aDirectory)
   195     void CDaemonBehaviour::ProcessPreinstalledFilesL(TInt aDrive, const TDesC& aDirectory)
   186         {
   196         {
   187         FLOG( _L("Daemon: ProcessPreInstalledFilesL") );
   197         FLOG( _L("Daemon: ProcessPreInstalledFilesL") );
   188         TPath preInstalledPath;
   198         TPath preInstalledPath;
   189         TChar drive;
   199         TChar drive;
   190         RFs::DriveToChar(aDrive, drive);
   200         RFs::DriveToChar(aDrive, drive);
   191         preInstalledPath.Append(drive);
   201         preInstalledPath.Append(drive);
   192         preInstalledPath.Append(aDirectory);
   202         preInstalledPath.Append(aDirectory);
   193         
   203         
   194         FLOG_1( _L("Daemon: ProcessPreInstalledFilesL Getting dir %S"), &preInstalledPath );
   204         FLOG_1( _L("Daemon: ProcessPreInstalledFilesL Getting dir %S"), &preInstalledPath );
   195         CDir* dir = NULL;
   205         CDir* dir = NULL;
   196         TInt err = iFs.GetDir(preInstalledPath, KEntryAttNormal, ESortNone, dir);	
   206         TInt err = iFs.GetDir(preInstalledPath, KEntryAttNormal, ESortNone, dir); 
   197         if (err != KErrNone && err != KErrPathNotFound)
   207         if (err != KErrNone && err != KErrPathNotFound)
   198             {
   208             {
   199             FLOG_1( _L("Daemon: ProcessPreInstalledFilesL GetDir with error %d"), err );
   209             FLOG_1( _L("Daemon: ProcessPreInstalledFilesL GetDir with error %d"), err );
   200             User::Leave(err);
   210             User::Leave(err);
   201             }
   211             }
   215                 }
   225                 }
   216             CleanupStack::PopAndDestroy(dir);
   226             CleanupStack::PopAndDestroy(dir);
   217             }
   227             }
   218         }
   228         }
   219 
   229 
   220 	// For uninstaller
   230     // For uninstaller
   221     TInt& CDaemonBehaviour::GetProcessStatus()
   231     TInt& CDaemonBehaviour::GetProcessStatus()
   222         {
   232         {
   223         return iGeneralProcessStatus;
   233         return iGeneralProcessStatus;
   224         }
   234         }
   225 
   235 
   226     // For uninstaller
   236     // For uninstaller
   227     void CDaemonBehaviour::SetProcessStatus( TInt aStatus )
   237     void CDaemonBehaviour::SetProcessStatus( TInt aStatus )
   228         {
   238         {
   229         iGeneralProcessStatus = aStatus;
   239         iGeneralProcessStatus = aStatus;
   230         }   	
   240         }     
   231 	
   241   
   232     // For plugin support
   242     // For plugin support
   233     void CDaemonBehaviour::DoNotifyMediaProcessingComplete()
   243     void CDaemonBehaviour::DoNotifyMediaProcessingComplete()
   234         {
   244         {
   235         if ( iSwiDaemonPlugin && iStartNotified )
   245         if ( iSwiDaemonPlugin && iStartNotified )
   236             {
   246             {
   251     // For plugin support
   261     // For plugin support
   252     void CDaemonBehaviour::NotifyPlugin()
   262     void CDaemonBehaviour::NotifyPlugin()
   253         {
   263         {
   254         FLOG( _L("Daemon: NotifyPlugin"));
   264         FLOG( _L("Daemon: NotifyPlugin"));
   255         if ( !iStartNotified )
   265         if ( !iStartNotified )
   256              {
   266             {
   257              FLOG_1( _L("Daemon: MediaProcessingStart for drive = %d"), iDrive );
   267             FLOG_1( _L("Daemon: MediaProcessingStart for drive = %d"), iDrive );
   258              iSwiDaemonPlugin->MediaProcessingStart( iDrive );
   268             iSwiDaemonPlugin->MediaProcessingStart( iDrive );
   259              iStartNotified = ETrue;
   269             iStartNotified = ETrue;
   260              }    
   270             }    
   261         }
   271         }
   262     
   272     
   263     // For plugin support
   273     // For plugin support
   264     void CDaemonBehaviour::RequestPluginInstall( TDesC& aSisFile )
   274     void CDaemonBehaviour::RequestPluginInstall( TDesC& aSisFile )
   265         {
   275         {
   280         
   290         
   281         // close file, original SWI Daemon do not leave file open.
   291         // close file, original SWI Daemon do not leave file open.
   282         CleanupStack::PopAndDestroy( &file ); 
   292         CleanupStack::PopAndDestroy( &file ); 
   283         }
   293         }
   284                                         
   294                                         
   285 	} // namespace Swi
   295     } // namespace Swi
   286 //EOF
   296 //EOF