appinstaller/AppinstUi/startuplistupdater/src/startuplistupdater.cpp
changeset 80 9dcba1ee99f7
parent 37 6e7b00453237
equal deleted inserted replaced
77:d1838696558c 80:9dcba1ee99f7
    35 _LIT( KAsterisk, "*" );
    35 _LIT( KAsterisk, "*" );
    36 
    36 
    37 const TInt KDriveSpecLength = 2;
    37 const TInt KDriveSpecLength = 2;
    38 const TInt KFirstStartupItemInfo = 1;
    38 const TInt KFirstStartupItemInfo = 1;
    39 
    39 
       
    40 #ifdef _DEBUG
       
    41 #define FLOG(x)         RDebug::Print(x);
       
    42 #define FLOG_1(x,y)     RDebug::Print(x, y);
       
    43 #define FLOG_2(x,y,z)   RDebug::Print(x, y, z);
       
    44 #define FLOG_3(x,y,z,v) RDebug::Print(x, y, z, v);
       
    45 #else
       
    46 #define FLOG(x)
       
    47 #define FLOG_1(x,y)
       
    48 #define FLOG_2(x,y,z)
       
    49 #define FLOG_3(x,y,z,v)
       
    50 #endif
       
    51 
       
    52 _LIT( KDevTraceDir, "c:\\data\\logs\\swinst\\" );
       
    53 _LIT( KDevTraceFile, "startuplistmgmt.log" );
       
    54 const TInt KDevTraceBuffer = 256;
       
    55 
    40 
    56 
    41 // ======== LOCAL FUNCTIONS ========
    57 // ======== LOCAL FUNCTIONS ========
    42 
    58 
    43 // ---------------------------------------------------------------------------
    59 // ---------------------------------------------------------------------------
    44 // FileNamesEqual()
    60 // FileNamesEqual()
    56 // CStartupListUpdater::NewL()
    72 // CStartupListUpdater::NewL()
    57 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    58 //
    74 //
    59 CStartupListUpdater* CStartupListUpdater::NewL()
    75 CStartupListUpdater* CStartupListUpdater::NewL()
    60     {
    76     {
       
    77     FLOG( _L("CStartupListUpdater::NewL") );
    61     CStartupListUpdater* self = new( ELeave ) CStartupListUpdater;
    78     CStartupListUpdater* self = new( ELeave ) CStartupListUpdater;
    62     CleanupStack::PushL( self );
    79     CleanupStack::PushL( self );
    63     self->ConstructL();
    80     self->ConstructL();
    64     CleanupStack::Pop( self );
    81     CleanupStack::Pop( self );
    65     return self;
    82     return self;
    69 // CStartupListUpdater::~CStartupListUpdater()
    86 // CStartupListUpdater::~CStartupListUpdater()
    70 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    71 //
    88 //
    72 CStartupListUpdater::~CStartupListUpdater()
    89 CStartupListUpdater::~CStartupListUpdater()
    73     {
    90     {
       
    91     FLOG( _L("CStartupListUpdater::~CStartupListUpdater") );
       
    92     iLogFile.Close();
       
    93     iFileBuf.Close();
       
    94     delete iLogBuf;
    74     delete iPrivateImportPath;
    95     delete iPrivateImportPath;
    75     iFs.Close();
    96     iFs.Close();
    76 
    97 
    77     FeatureManager::UnInitializeLib();
    98     FeatureManager::UnInitializeLib();
    78     }
    99     }
    81 // CStartupListUpdater::UpdateStartupListL()
   102 // CStartupListUpdater::UpdateStartupListL()
    82 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
    83 //
   104 //
    84 void CStartupListUpdater::UpdateStartupListL()
   105 void CStartupListUpdater::UpdateStartupListL()
    85     {
   106     {
    86     if ( FeatureManager::FeatureSupported( KFeatureIdExtendedStartup ) )
   107     FLOG( _L("CStartupListUpdater::UpdateStartupListL") );
       
   108     if( FeatureManager::FeatureSupported( KFeatureIdExtendedStartup ) )
    87         {
   109         {
    88         ProcessImportsAndUninstallsL();
   110         ProcessImportsAndUninstallsL();
    89         }
   111         }
    90     }
   112     }
    91 
   113 
   101 // CStartupListUpdater::ConstructL()
   123 // CStartupListUpdater::ConstructL()
   102 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   103 //
   125 //
   104 void CStartupListUpdater::ConstructL()
   126 void CStartupListUpdater::ConstructL()
   105     {
   127     {
       
   128     FLOG( _L("CStartupListUpdater::ConstructL, begin") );
   106     FeatureManager::InitializeLibL();
   129     FeatureManager::InitializeLibL();
   107     User::LeaveIfError( iFs.Connect() );
   130     User::LeaveIfError( iFs.Connect() );
   108 
   131 
   109     TInt err = iFs.MkDirAll( PrivateImportPathL() );
   132     TInt err = iFs.MkDirAll( PrivateImportPathL() );
   110     if( err != KErrNone && err != KErrAlreadyExists )
   133     if( err != KErrNone && err != KErrAlreadyExists )
   111         {
   134         {
       
   135         FLOG_1( _L("CStartupListUpdater::ConstructL, err %d"), err );
   112         User::Leave( err );
   136         User::Leave( err );
   113         }
   137         }
       
   138     FLOG( _L("CStartupListUpdater::ConstructL, end") );
   114     }
   139     }
   115 
   140 
   116 // ---------------------------------------------------------------------------
   141 // ---------------------------------------------------------------------------
   117 // CStartupListUpdater::PrivateImportPathL()
   142 // CStartupListUpdater::PrivateImportPathL()
   118 // ---------------------------------------------------------------------------
   143 // ---------------------------------------------------------------------------
   133 
   158 
   134         iPrivateImportPath = HBufC::NewL( KDriveSpecLength + privateImportPath.Length() );
   159         iPrivateImportPath = HBufC::NewL( KDriveSpecLength + privateImportPath.Length() );
   135         TPtr ptr( iPrivateImportPath->Des() );
   160         TPtr ptr( iPrivateImportPath->Des() );
   136         ptr.Format( KDriveAndPathFormat, static_cast< TUint >( driveLetter ), &privateImportPath );
   161         ptr.Format( KDriveAndPathFormat, static_cast< TUint >( driveLetter ), &privateImportPath );
   137         }
   162         }
       
   163     FLOG_1( _L("CStartupListUpdater::PrivateImportPathL %S"), iPrivateImportPath );
   138     return *iPrivateImportPath;
   164     return *iPrivateImportPath;
   139     }
   165     }
   140 
   166 
   141 // ---------------------------------------------------------------------------
   167 // ---------------------------------------------------------------------------
   142 // CStartupListUpdater::ProcessImportsAndUninstallsL()
   168 // CStartupListUpdater::ProcessImportsAndUninstallsL()
   143 // ---------------------------------------------------------------------------
   169 // ---------------------------------------------------------------------------
   144 //
   170 //
   145 void CStartupListUpdater::ProcessImportsAndUninstallsL()
   171 void CStartupListUpdater::ProcessImportsAndUninstallsL()
   146     {
   172     {
       
   173     FLOG( _L("CStartupListUpdater::ProcessImportsAndUninstallsL, begin") );
   147     RDscStore dscStore;
   174     RDscStore dscStore;
   148     OpenDscStoreLC( dscStore );
   175     OpenDscStoreLC( dscStore );
   149 
   176 
   150     ImportNewResourceFilesL( dscStore );
   177     TRAPD( err, ImportNewResourceFilesL( dscStore ) );
       
   178     if( err )
       
   179         {
       
   180         DevTrace( _L("Error: import failed, error code %d"), err );
       
   181         User::Leave( err );
       
   182         }
   151     DeregisterUninstalledAppsL( dscStore );
   183     DeregisterUninstalledAppsL( dscStore );
   152 
   184 
   153     CleanupStack::PopAndDestroy( &dscStore );
   185     CleanupStack::PopAndDestroy( &dscStore );
       
   186     FLOG( _L("CStartupListUpdater::ProcessImportsAndUninstallsL, end") );
   154     }
   187     }
   155 
   188 
   156 // ---------------------------------------------------------------------------
   189 // ---------------------------------------------------------------------------
   157 // CStartupListUpdater::OpenDscStoreLC()
   190 // CStartupListUpdater::OpenDscStoreLC()
   158 // ---------------------------------------------------------------------------
   191 // ---------------------------------------------------------------------------
   159 //
   192 //
   160 void CStartupListUpdater::OpenDscStoreLC( RDscStore& aDscStore )
   193 void CStartupListUpdater::OpenDscStoreLC( RDscStore& aDscStore )
   161     {
   194     {
       
   195     FLOG( _L("CStartupListUpdater::OpenDscStoreLC") );
   162     if( !aDscStore.IsOpened() )
   196     if( !aDscStore.IsOpened() )
   163         {
   197         {
   164         aDscStore.OpenL();
   198         aDscStore.OpenL();
   165         CleanupClosePushL( aDscStore );
   199         CleanupClosePushL( aDscStore );
   166         if( !aDscStore.DscExistsL() )
   200         if( !aDscStore.DscExistsL() )
   168             aDscStore.CreateDscL();
   202             aDscStore.CreateDscL();
   169             }
   203             }
   170         }
   204         }
   171     else
   205     else
   172         {
   206         {
       
   207         FLOG( _L("CStartupListUpdater::OpenDscStoreLC, KErrAlreadyExists") );
   173         User::Leave( KErrAlreadyExists );
   208         User::Leave( KErrAlreadyExists );
   174         }
   209         }
   175     }
   210     }
   176 
   211 
   177 // ---------------------------------------------------------------------------
   212 // ---------------------------------------------------------------------------
   178 // CStartupListUpdater::ImportNewResourceFilesL()
   213 // CStartupListUpdater::ImportNewResourceFilesL()
   179 // ---------------------------------------------------------------------------
   214 // ---------------------------------------------------------------------------
   180 //
   215 //
   181 void CStartupListUpdater::ImportNewResourceFilesL( RDscStore& aDscStore )
   216 void CStartupListUpdater::ImportNewResourceFilesL( RDscStore& aDscStore )
   182     {
   217     {
       
   218     FLOG( _L("CStartupListUpdater::ImportNewResourceFilesL, begin") );
   183     RPointerArray<HBufC> executableArray;
   219     RPointerArray<HBufC> executableArray;
   184     CleanupResetAndDestroyPushL( executableArray );
   220     CleanupResetAndDestroyPushL( executableArray );
   185     RPointerArray<HBufC> resourceFileArray;
   221     RPointerArray<HBufC> resourceFileArray;
   186     CleanupResetAndDestroyPushL( resourceFileArray );
   222     CleanupResetAndDestroyPushL( resourceFileArray );
   187 
   223 
   188     GetDataToBeImportedL( executableArray, resourceFileArray );
   224     GetDataToBeImportedL( executableArray, resourceFileArray );
   189     ImportExecutablesL( aDscStore, executableArray );
   225     ImportExecutablesL( aDscStore, executableArray );
   190     RemoveImportedResourceFiles( resourceFileArray );
   226     RemoveImportedResourceFiles( resourceFileArray );
   191 
   227 
   192     CleanupStack::PopAndDestroy( 2, &executableArray );
   228     CleanupStack::PopAndDestroy( 2, &executableArray );
       
   229     FLOG( _L("CStartupListUpdater::ImportNewResourceFilesL, end") );
   193     }
   230     }
   194 
   231 
   195 // ---------------------------------------------------------------------------
   232 // ---------------------------------------------------------------------------
   196 // CStartupListUpdater::DeregisterUninstalledAppsL()
   233 // CStartupListUpdater::DeregisterUninstalledAppsL()
   197 // ---------------------------------------------------------------------------
   234 // ---------------------------------------------------------------------------
   198 //
   235 //
   199 void CStartupListUpdater::DeregisterUninstalledAppsL( RDscStore& aDscStore )
   236 void CStartupListUpdater::DeregisterUninstalledAppsL( RDscStore& aDscStore )
   200     {
   237     {
       
   238     FLOG( _L("CStartupListUpdater::DeregisterUninstalledAppsL, begin") );
   201     RPointerArray<HBufC> startedAtBootArray;
   239     RPointerArray<HBufC> startedAtBootArray;
   202     CleanupResetAndDestroyPushL( startedAtBootArray );
   240     CleanupResetAndDestroyPushL( startedAtBootArray );
   203     RPointerArray<HBufC> installedArray;
   241     RPointerArray<HBufC> installedArray;
   204     CleanupResetAndDestroyPushL( installedArray );
   242     CleanupResetAndDestroyPushL( installedArray );
   205     RPointerArray<HBufC> startedNotInstalled;
   243     RPointerArray<HBufC> startedNotInstalled;
   209     GetInstalledAppsL( installedArray );
   247     GetInstalledAppsL( installedArray );
   210     StartedButNotInstalledAppsL( startedAtBootArray, installedArray, startedNotInstalled );
   248     StartedButNotInstalledAppsL( startedAtBootArray, installedArray, startedNotInstalled );
   211     RemoveFromStartupListL( aDscStore, startedNotInstalled );
   249     RemoveFromStartupListL( aDscStore, startedNotInstalled );
   212 
   250 
   213     CleanupStack::PopAndDestroy( 3, &startedAtBootArray );
   251     CleanupStack::PopAndDestroy( 3, &startedAtBootArray );
       
   252     FLOG( _L("CStartupListUpdater::DeregisterUninstalledAppsL, end") );
   214     }
   253     }
   215 
   254 
   216 // ---------------------------------------------------------------------------
   255 // ---------------------------------------------------------------------------
   217 // CStartupListUpdater::GetDataToBeImportedL()
   256 // CStartupListUpdater::GetDataToBeImportedL()
   218 // ---------------------------------------------------------------------------
   257 // ---------------------------------------------------------------------------
   219 //
   258 //
   220 void CStartupListUpdater::GetDataToBeImportedL(
   259 void CStartupListUpdater::GetDataToBeImportedL(
   221         RPointerArray<HBufC>& aExecutableArray,
   260         RPointerArray<HBufC>& aExecutableArray,
   222         RPointerArray<HBufC>& aResourceFileArray )
   261         RPointerArray<HBufC>& aResourceFileArray )
   223     {
   262     {
       
   263     FLOG( _L("CStartupListUpdater::GetDataToBeImportedL, begin") );
   224     TParse resourceFiles;
   264     TParse resourceFiles;
   225     User::LeaveIfError( resourceFiles.Set( KResourceFileSpec, &PrivateImportPathL(), NULL ) );
   265     User::LeaveIfError( resourceFiles.Set( KResourceFileSpec, &PrivateImportPathL(), NULL ) );
   226     const TPtrC importDir( resourceFiles.FullName() );
   266     const TPtrC importDir( resourceFiles.FullName() );
   227 
   267 
   228     CDir* dir;
   268     CDir* dir;
   240 
   280 
   241             AppendExecutablesFromResourceFileL( resourceFile, aExecutableArray );
   281             AppendExecutablesFromResourceFileL( resourceFile, aExecutableArray );
   242             }
   282             }
   243         }
   283         }
   244     CleanupStack::PopAndDestroy( dir );
   284     CleanupStack::PopAndDestroy( dir );
       
   285     FLOG( _L("CStartupListUpdater::GetDataToBeImportedL, end") );
   245     }
   286     }
   246 
   287 
   247 // ---------------------------------------------------------------------------
   288 // ---------------------------------------------------------------------------
   248 // CStartupListUpdater::ImportExecutablesL()
   289 // CStartupListUpdater::ImportExecutablesL()
   249 // ---------------------------------------------------------------------------
   290 // ---------------------------------------------------------------------------
   250 //
   291 //
   251 void CStartupListUpdater::ImportExecutablesL( RDscStore& aDscStore,
   292 void CStartupListUpdater::ImportExecutablesL( RDscStore& aDscStore,
   252         RPointerArray<HBufC>& aExecutableArray )
   293         RPointerArray<HBufC>& aExecutableArray )
   253     {
   294     {
       
   295     FLOG( _L("CStartupListUpdater::ImportExecutablesL, begin") );
   254     for( TInt index = 0; index < aExecutableArray.Count(); ++index )
   296     for( TInt index = 0; index < aExecutableArray.Count(); ++index )
   255         {
   297         {
   256         const TDesC& executableName = *( aExecutableArray[ index ] );
   298         const TDesC& executableName = *( aExecutableArray[ index ] );
       
   299         FLOG_1( _L("CStartupListUpdater::ImportExecutablesL, exe %S"), &executableName );
   257         CDscItem* item = CDscItem::NewLC( executableName, KNullDesC );
   300         CDscItem* item = CDscItem::NewLC( executableName, KNullDesC );
   258         if( !aDscStore.ItemExistsL( *item ) )
   301         if( !aDscStore.ItemExistsL( *item ) )
   259             {
   302             {
       
   303             FLOG( _L("CStartupListUpdater::ImportExecutablesL, add item to DscStore") );
   260             aDscStore.AddItemL( *item );
   304             aDscStore.AddItemL( *item );
       
   305             DevTrace( _L("Success: '%S' will be started at boot"), &executableName );
       
   306             }
       
   307         else
       
   308             {
       
   309             DevTrace( _L("Error: '%S' already in start list"), &executableName );
   261             }
   310             }
   262         CleanupStack::PopAndDestroy( item );
   311         CleanupStack::PopAndDestroy( item );
   263         }
   312         }
       
   313     FLOG( _L("CStartupListUpdater::ImportExecutablesL, end") );
   264     }
   314     }
   265 
   315 
   266 // ---------------------------------------------------------------------------
   316 // ---------------------------------------------------------------------------
   267 // CStartupListUpdater::RemoveImportedResourceFiles()
   317 // CStartupListUpdater::RemoveImportedResourceFiles()
   268 // ---------------------------------------------------------------------------
   318 // ---------------------------------------------------------------------------
   269 //
   319 //
   270 void CStartupListUpdater::RemoveImportedResourceFiles(
   320 void CStartupListUpdater::RemoveImportedResourceFiles(
   271         RPointerArray<HBufC>& aResourceFileArray )
   321         RPointerArray<HBufC>& aResourceFileArray )
   272     {
   322     {
       
   323     FLOG( _L("CStartupListUpdater::RemoveImportedResourceFiles, begin") );
   273     for( TInt index = 0; index < aResourceFileArray.Count(); ++index )
   324     for( TInt index = 0; index < aResourceFileArray.Count(); ++index )
   274         {
   325         {
   275         const TDesC& fileName = *( aResourceFileArray[ index ] );
   326         const TDesC& fileName = *( aResourceFileArray[ index ] );
       
   327         FLOG_1( _L("CStartupListUpdater::RemoveImportedResourceFiles, deleting %S"), &fileName );
   276         TInt err = iFs.Delete( fileName );
   328         TInt err = iFs.Delete( fileName );
   277         if( err )
   329         FLOG_1( _L("CStartupListUpdater::RemoveImportedResourceFiles, err %d"), err );
   278             {
   330         if( !err )
   279 #ifdef _DEBUG
   331             {
   280             RDebug::Print( _L("CStartupListUpdater: cannot delete %S, error %d"),
   332             DevTrace( _L("Resource file '%S' processed"), &fileName );
   281                     &fileName, err );
   333             }
   282 #endif
   334         }
   283             }
   335     FLOG( _L("CStartupListUpdater::RemoveImportedResourceFiles, end") );
   284         }
       
   285     }
   336     }
   286 
   337 
   287 // ---------------------------------------------------------------------------
   338 // ---------------------------------------------------------------------------
   288 // CStartupListUpdater::AppendExecutablesFromResourceFileL()
   339 // CStartupListUpdater::AppendExecutablesFromResourceFileL()
   289 // ---------------------------------------------------------------------------
   340 // ---------------------------------------------------------------------------
   290 //
   341 //
   291 void CStartupListUpdater::AppendExecutablesFromResourceFileL(
   342 void CStartupListUpdater::AppendExecutablesFromResourceFileL(
   292         const TDesC& aResourceFile,
   343         const TDesC& aResourceFile,
   293         RPointerArray<HBufC>& aExecutableArray )
   344         RPointerArray<HBufC>& aExecutableArray )
   294     {
   345     {
       
   346     FLOG( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, begin") );
       
   347     OpenDevTraceL();
       
   348     DevTrace( _L("Processing resource file: %S"), &aResourceFile );
       
   349 
   295     RResourceFile resource;
   350     RResourceFile resource;
   296     CleanupClosePushL( resource );
   351     CleanupClosePushL( resource );
   297     resource.OpenL( iFs, aResourceFile );
   352     resource.OpenL( iFs, aResourceFile );
       
   353     FLOG_1( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, %S"), &aResourceFile );
   298 
   354 
   299     for( TInt id = KFirstStartupItemInfo; resource.OwnsResourceId( id ); ++id )
   355     for( TInt id = KFirstStartupItemInfo; resource.OwnsResourceId( id ); ++id )
   300         {
   356         {
       
   357         FLOG_1( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, resource id %d"), id );
   301         HBufC8* buffer = resource.AllocReadLC( id );
   358         HBufC8* buffer = resource.AllocReadLC( id );
   302 
   359 
   303         TResourceReader reader;
   360         TResourceReader reader;
   304         reader.SetBuffer( buffer );
   361         reader.SetBuffer( buffer );
   305 
   362 
   306         // Read STARTUP_ITEM_INFO
   363         // Read STARTUP_ITEM_INFO
   307         TInt versionInfo = reader.ReadUint8();
   364         TInt versionInfo = reader.ReadUint8();
   308         TFileName executableName;
   365         TFileName executableName;
   309         executableName.Copy( reader.ReadTPtrC() );
   366         executableName.Copy( reader.ReadTPtrC() );
   310         TInt recoveryPolicy = reader.ReadUint16();
   367         TInt recoveryPolicy = reader.ReadUint16();
       
   368         FLOG_1( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, executableName %S"),
       
   369                 &executableName );
       
   370         FLOG_1( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, recoveryPolicy %d"),
       
   371                 recoveryPolicy );
   311 
   372 
   312         CleanupStack::PopAndDestroy( buffer );
   373         CleanupStack::PopAndDestroy( buffer );
   313 
   374 
   314         if( versionInfo == 0 && recoveryPolicy == EStartupItemExPolicyNone )
   375         if( versionInfo == 0 && recoveryPolicy == EStartupItemExPolicyNone )
   315             {
   376             {
   325                     {
   386                     {
   326                     CleanupStack::PushL( executableDir );
   387                     CleanupStack::PushL( executableDir );
   327                     executableName.Replace( 0, 1, fileFinder.File() );
   388                     executableName.Replace( 0, 1, fileFinder.File() );
   328                     CleanupStack::PopAndDestroy( executableDir );
   389                     CleanupStack::PopAndDestroy( executableDir );
   329                     }
   390                     }
       
   391 
       
   392                 FLOG_1( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, new name %S"),
       
   393                         &executableName );
   330                 }
   394                 }
   331 
   395 
       
   396             DevTrace( _L("Executable file: %S"), &executableName );
   332             if( IsValidExecutableForStartupL( aResourceFile, executableName ) )
   397             if( IsValidExecutableForStartupL( aResourceFile, executableName ) )
   333                 {
   398                 {
       
   399                 FLOG( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, adding to array") );
   334                 aExecutableArray.AppendL( executableName.AllocL() );
   400                 aExecutableArray.AppendL( executableName.AllocL() );
   335                 }
   401                 }
   336             }
   402             }
       
   403         else
       
   404             {
       
   405             if( versionInfo != 0 )
       
   406                 {
       
   407                 DevTrace( _L("Error: unsupported STARTUP_ITEM_INFO version: %d"), versionInfo );
       
   408                 }
       
   409             else
       
   410                 {
       
   411                 DevTrace( _L("Error: unsupported recovery policy: %d"), recoveryPolicy );
       
   412                 }
       
   413             }
   337         }
   414         }
   338 
   415 
   339     CleanupStack::PopAndDestroy( &resource );
   416     CleanupStack::PopAndDestroy( &resource );
       
   417     FLOG( _L("CStartupListUpdater::AppendExecutablesFromResourceFileL, end") );
   340     }
   418     }
   341 
   419 
   342 // ---------------------------------------------------------------------------
   420 // ---------------------------------------------------------------------------
   343 // CStartupListUpdater::IsValidExecutableForStartupL()
   421 // CStartupListUpdater::IsValidExecutableForStartupL()
   344 // ---------------------------------------------------------------------------
   422 // ---------------------------------------------------------------------------
   345 //
   423 //
   346 TBool CStartupListUpdater::IsValidExecutableForStartupL( const TDesC& aResourceFile,
   424 TBool CStartupListUpdater::IsValidExecutableForStartupL( const TDesC& aResourceFile,
   347         const TDesC& aExecutableName )
   425         const TDesC& aExecutableName )
   348     {
   426     {
       
   427     FLOG( _L("CStartupListUpdater::IsValidExecutableForStartupL, begin") );
       
   428     FLOG_1( _L("CStartupListUpdater::IsValidExecutableForStartupL, res %S"), &aResourceFile );
       
   429     FLOG_1( _L("CStartupListUpdater::IsValidExecutableForStartupL, exe %S"), &aExecutableName );
   349     TBool isValid = EFalse;
   430     TBool isValid = EFalse;
   350 
   431 
   351     TEntry entry;
   432     TEntry entry;
   352     if( iFs.Entry( aExecutableName, entry ) == KErrNone )   // needs AllFiles capability
   433     if( iFs.Entry( aExecutableName, entry ) == KErrNone )   // needs AllFiles capability
   353         {
   434         {
   354         isValid = ETrue;
   435         FLOG( _L("CStartupListUpdater::IsValidExecutableForStartupL, exe file exists") );
   355 
   436 
   356         // Extract package UID from the resource file name
       
   357         // - allow both "[1234ABCD]" and "1234ABCD" formats
       
   358         // - allow possible "0x" prefix too
       
   359         TUid packageUid = KNullUid;
   437         TUid packageUid = KNullUid;
   360         TParsePtrC parse( aResourceFile );
   438         ExtractPackageUidFromResourceFileL( aResourceFile, packageUid );
   361         TPtrC parseName = parse.Name();
   439 
   362         TInt fileNameLength = parseName.Length();
       
   363         if( !parse.IsNameWild() && fileNameLength > 0 )
       
   364             {
       
   365             TPtr fileName( const_cast<TUint16*>( parseName.Ptr() ),
       
   366                 fileNameLength, fileNameLength );
       
   367 
       
   368             if( fileName[ 0 ] == '[' && fileName[ fileNameLength - 1 ] == ']' )
       
   369                 {
       
   370                 const TInt KTwoCharsLength = 2;
       
   371                 fileNameLength -= KTwoCharsLength;
       
   372                 fileName = fileName.Mid( 1, fileNameLength );
       
   373                 }
       
   374 
       
   375             _LIT( KHexPrefix, "0x" );
       
   376             const TInt KHexPrefixLength = 2;
       
   377             if( fileName.Left( KHexPrefixLength ) == KHexPrefix )
       
   378                 {
       
   379                 fileNameLength -= KHexPrefixLength;
       
   380                 fileName = fileName.Mid( KHexPrefixLength, fileNameLength );
       
   381                 }
       
   382 
       
   383             TLex lex( fileName );
       
   384             TUint32 uidValue = 0;
       
   385             TInt lexError = lex.Val( uidValue, EHex );
       
   386             if( !lexError )
       
   387                 {
       
   388                 packageUid.iUid = uidValue;
       
   389                 }
       
   390             }
       
   391 
       
   392         // Get package info from RSisRegistry, and check that
       
   393         // - the package contains the resource file
       
   394         // - the package is properly signed
       
   395         if( packageUid != KNullUid )
   440         if( packageUid != KNullUid )
   396             {
   441             {
   397             Swi::RSisRegistrySession sisRegSession;
   442             Swi::RSisRegistrySession sisRegSession;
   398             User::LeaveIfError( sisRegSession.Connect() );
   443             User::LeaveIfError( sisRegSession.Connect() );
   399             CleanupClosePushL( sisRegSession );
   444             CleanupClosePushL( sisRegSession );
   400 
   445 
   401             Swi::RSisRegistryEntry package;
   446             isValid = IsResourceFileValidForPackageL( sisRegSession, aResourceFile, packageUid ) &&
       
   447                     IsExeFileIncludedInPackageL( sisRegSession, aExecutableName, packageUid );
       
   448 
       
   449             CleanupStack::PopAndDestroy( &sisRegSession );
       
   450             }
       
   451         else
       
   452             {
       
   453             DevTrace( _L("Error: invalid package UID - check resource file name") );
       
   454             }
       
   455         }
       
   456     else
       
   457         {
       
   458         DevTrace( _L("Error: executable file '%S' not found"), &aExecutableName );
       
   459         }
       
   460 
       
   461     FLOG_1( _L("CStartupListUpdater::IsValidExecutableForStartupL, return %d"), isValid );
       
   462     return isValid;
       
   463     }
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CStartupListUpdater::ExtractPackageUidFromResourceFileL()
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 void CStartupListUpdater::ExtractPackageUidFromResourceFileL( const TDesC& aResourceFile,
       
   470         TUid& aPackageUid )
       
   471     {
       
   472     FLOG( _L("CStartupListUpdater::ExtractPackageUidFromResourceFileL, begin") );
       
   473 
       
   474     // Extract package UID from the resource file name
       
   475     // - allow both "[1234ABCD]" and "1234ABCD" formats
       
   476     // - allow possible "0x" prefix too
       
   477     aPackageUid = KNullUid;
       
   478 
       
   479     TParse parse;
       
   480     parse.Set( aResourceFile, NULL, NULL );
       
   481     TPtrC parseName = parse.Name();
       
   482     TInt fileNameLength = parseName.Length();
       
   483     if( !parse.IsNameWild() && fileNameLength > 0 )
       
   484         {
       
   485         TPtr fileName( const_cast<TUint16*>( parseName.Ptr() ),
       
   486             fileNameLength, fileNameLength );
       
   487 
       
   488         if( fileName[ 0 ] == '[' && fileName[ fileNameLength - 1 ] == ']' )
       
   489             {
       
   490             const TInt KTwoCharsLength = 2;
       
   491             fileNameLength -= KTwoCharsLength;
       
   492             fileName = fileName.Mid( 1, fileNameLength );
       
   493             }
       
   494 
       
   495         _LIT( KHexPrefix, "0x" );
       
   496         const TInt KHexPrefixLength = 2;
       
   497         if( fileName.Left( KHexPrefixLength ) == KHexPrefix )
       
   498             {
       
   499             fileNameLength -= KHexPrefixLength;
       
   500             fileName = fileName.Mid( KHexPrefixLength, fileNameLength );
       
   501             }
       
   502 
       
   503         FLOG_1( _L("CStartupListUpdater::ExtractPackageUidFromResourceFileL, fileName %S"),
       
   504                 &fileName );
       
   505         TLex lex( fileName );
       
   506         TUint32 uidValue = 0;
       
   507         TInt lexError = lex.Val( uidValue, EHex );
       
   508         if( !lexError )
       
   509             {
       
   510             aPackageUid.iUid = uidValue;
       
   511             }
       
   512         }
       
   513 
       
   514     FLOG_1( _L("CStartupListUpdater::ExtractPackageUidFromResourceFileL, end, ret 0x%08x"),
       
   515             aPackageUid.iUid );
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 // CStartupListUpdater::IsResourceFileValidForPackageL()
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 TBool CStartupListUpdater::IsResourceFileValidForPackageL(
       
   523         Swi::RSisRegistrySession& aSisRegSession,
       
   524         const TDesC& aResourceFile,
       
   525         const TUid& aPackageUid )
       
   526     {
       
   527     FLOG( _L("CStartupListUpdater::IsResourceFileValidForPackageL, begin") );
       
   528     TBool isValidForPackage = EFalse;
       
   529 
       
   530     // Get package info from RSisRegistry, and check that
       
   531     // - the package contains the resource file, and
       
   532     // - the package is properly signed
       
   533 
       
   534     Swi::RSisRegistryEntry package;
       
   535     CleanupClosePushL( package );
       
   536     TInt openError = package.Open( aSisRegSession, aPackageUid );
       
   537     FLOG_1( _L("CStartupListUpdater::IsResourceFileValidForPackageL, openError %d"), openError );
       
   538     if( !openError )
       
   539         {
       
   540         Swi::TSisTrustStatus trustStatus = package.TrustStatusL();
       
   541         Swi::TValidationStatus validationStatus = trustStatus.ValidationStatus();
       
   542         FLOG_1( _L("CStartupListUpdater::IsResourceFileValidForPackageL, validationStatus %d"),
       
   543                 validationStatus );
       
   544         Swi::TRevocationStatus revocationStatus = trustStatus.RevocationStatus();
       
   545         FLOG_1( _L("CStartupListUpdater::IsResourceFileValidForPackageL, revocationStatus %d"),
       
   546                 revocationStatus );
       
   547         TBool isTrusted = (validationStatus == Swi::EPackageInRom ||
       
   548                 validationStatus == Swi::EValidatedToAnchor) &&
       
   549                 revocationStatus != Swi::EOcspRevoked;
       
   550         FLOG_1( _L("CStartupListUpdater::IsResourceFileValidForPackageL, isTrusted %d"),
       
   551                 isTrusted );
       
   552 
       
   553         if( isTrusted )
       
   554             {
       
   555             isValidForPackage = IsFileIncludedInPackageL( aResourceFile, package );
       
   556 
       
   557             if( !isValidForPackage )
       
   558                 {
       
   559                 DevTrace( _L("Error: package 0x%08x does not install resource file %S"),
       
   560                         aPackageUid.iUid, &aResourceFile );
       
   561                 }
       
   562             }
       
   563         else
       
   564             {
       
   565             DevTrace( _L("Error: package 0x%08x not trusted"), aPackageUid.iUid );
       
   566             }
       
   567         }
       
   568     else
       
   569         {
       
   570         DevTrace( _L("Error: package 0x%08x open failed, error %d - check resource file name"),
       
   571                 aPackageUid.iUid, openError );
       
   572         }
       
   573 
       
   574     CleanupStack::PopAndDestroy( &package );
       
   575 
       
   576     FLOG_1( _L("CStartupListUpdater::IsResourceFileValidForPackageL, ret %d"), isValidForPackage );
       
   577     return isValidForPackage;
       
   578     }
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // CStartupListUpdater::IsFileIncludedInPackageL()
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 TBool CStartupListUpdater::IsFileIncludedInPackageL( const TDesC& aFile,
       
   585         Swi::RSisRegistryEntry& aPackage )
       
   586     {
       
   587     FLOG_1( _L("CStartupListUpdater::IsFileIncludedInPackageL, begin, file %S"), &aFile );
       
   588     TBool isIncluded = EFalse;
       
   589 
       
   590     RPointerArray<HBufC> files;
       
   591     CleanupResetAndDestroyPushL( files );
       
   592     aPackage.FilesL( files );
       
   593     TInt fileCount = files.Count();
       
   594     FLOG_1( _L("CStartupListUpdater::IsFileIncludedInPackageL, pckg fileCount %d"), fileCount );
       
   595     for( TInt index = 0; index < fileCount && !isIncluded; ++index )
       
   596         {
       
   597         TPtrC pckgFile( *files[ index ] );
       
   598         FLOG_1( _L("CStartupListUpdater::IsFileIncludedInPackageL, pckgFile %S"), &pckgFile );
       
   599         isIncluded = ( aFile.CompareF( pckgFile ) == 0 );
       
   600         }
       
   601     CleanupStack::PopAndDestroy( &files );
       
   602 
       
   603     if( isIncluded )
       
   604         {
       
   605         DevTrace( _L("File '%S' installed by package 0x%08x" ), &aFile, aPackage.UidL().iUid );
       
   606         }
       
   607     else
       
   608         {
       
   609         DevTrace( _L("File '%S' not installed by package 0x%08x" ), &aFile, aPackage.UidL().iUid );
       
   610         }
       
   611     FLOG_1( _L("CStartupListUpdater::IsFileIncludedInPackageL, ret %d"), isIncluded );
       
   612     return isIncluded;
       
   613     }
       
   614 
       
   615 // ---------------------------------------------------------------------------
       
   616 // CStartupListUpdater::IsFileIncludedInEmbeddedPackagesL()
       
   617 // ---------------------------------------------------------------------------
       
   618 //
       
   619 TBool CStartupListUpdater::IsFileIncludedInEmbeddedPackagesL(
       
   620         Swi::RSisRegistrySession& aSisRegSession, const TDesC& aFile,
       
   621         Swi::RSisRegistryEntry& aPackage )
       
   622     {
       
   623     FLOG( _L("CStartupListUpdater::IsFileIncludedInEmbeddedPackagesL, begin") );
       
   624     TBool isIncluded = EFalse;
       
   625 
       
   626     RPointerArray<Swi::CSisRegistryPackage> embeddedPackages;
       
   627     CleanupResetAndDestroyPushL( embeddedPackages );
       
   628     aPackage.EmbeddedPackagesL( embeddedPackages );
       
   629 
       
   630     TInt embeddedPackagesCount = embeddedPackages.Count();
       
   631     FLOG_1( _L("CStartupListUpdater::IsFileIncludedInEmbeddedPackagesL, embeddedPackagesCount %d"),
       
   632             embeddedPackagesCount );
       
   633     for( TInt index = 0; index < embeddedPackagesCount && !isIncluded; ++index )
       
   634         {
       
   635         TUid uid = embeddedPackages[index]->Uid();
       
   636         FLOG_1( _L("CStartupListUpdater::IsFileIncludedInEmbeddedPackagesL, uid 0x%08x"),
       
   637                 uid.iUid );
       
   638 
       
   639         Swi::RSisRegistryEntry package;
       
   640         if( package.Open( aSisRegSession, uid ) == KErrNone )
       
   641             {
   402             CleanupClosePushL( package );
   642             CleanupClosePushL( package );
   403             TInt openError = package.Open( sisRegSession, packageUid );
   643             isIncluded = IsFileIncludedInPackageL( aFile, package );
   404             if( !openError )
   644             if( !isIncluded )
   405                 {
   645                 {
   406                 TBool hasResourceFile = EFalse;
   646                 // Check other embedded packages recursively if necessary
   407 
   647                 isIncluded = IsFileIncludedInEmbeddedPackagesL( aSisRegSession, aFile, package );
   408                 RPointerArray<HBufC> files;
       
   409                 CleanupResetAndDestroyPushL( files );
       
   410                 package.FilesL( files );
       
   411                 for( TInt index = 0; index < files.Count() && !hasResourceFile; ++index )
       
   412                     {
       
   413                     hasResourceFile = ( aResourceFile.CompareF( *files[ index ] ) == 0 );
       
   414                     }
       
   415 
       
   416                 if( hasResourceFile && package.TrustStatusL().IsTrusted() )
       
   417                     {
       
   418                     isValid = ETrue;
       
   419                     }
       
   420 
       
   421                 CleanupStack::PopAndDestroy( &files );
       
   422                 }
   648                 }
   423 
   649             CleanupStack::PopAndDestroy( &package );
   424             CleanupStack::PopAndDestroy( 2, &sisRegSession );  // package, sisRegSession
   650             }
   425             }
   651         }
   426         }
   652     CleanupStack::PopAndDestroy( &embeddedPackages );
   427 
   653 
   428     return isValid;
   654     FLOG_1( _L("CStartupListUpdater::IsFileIncludedInEmbeddedPackagesL, ret %d"), isIncluded );
       
   655     return isIncluded;
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 // CStartupListUpdater::IsExeFileIncludedInPackageL()
       
   660 // ---------------------------------------------------------------------------
       
   661 //
       
   662 TBool CStartupListUpdater::IsExeFileIncludedInPackageL(
       
   663         Swi::RSisRegistrySession& aSisRegSession,
       
   664         const TDesC& aExeFile, const TUid& aPackageUid )
       
   665     {
       
   666     FLOG_1( _L("CStartupListUpdater::IsExeFileIncludedInPackageL, begin, file %S"), &aExeFile );
       
   667     TBool isIncluded = EFalse;
       
   668 
       
   669     Swi::RSisRegistryEntry package;
       
   670     CleanupClosePushL( package );
       
   671     TInt openError = package.Open( aSisRegSession, aPackageUid );
       
   672     if( !openError )
       
   673         {
       
   674         isIncluded = IsFileIncludedInPackageL( aExeFile, package ) ||
       
   675                 IsFileIncludedInEmbeddedPackagesL( aSisRegSession, aExeFile, package );
       
   676         if( !isIncluded )
       
   677             {
       
   678             DevTrace( _L("Error: exe not installed by this package or it's subpackages") );
       
   679             }
       
   680         }
       
   681     CleanupStack::PopAndDestroy( &package );
       
   682 
       
   683     FLOG_1( _L("CStartupListUpdater::IsExeFileIncludedInPackageL, return %d"), isIncluded );
       
   684     return isIncluded;
   429     }
   685     }
   430 
   686 
   431 // ---------------------------------------------------------------------------
   687 // ---------------------------------------------------------------------------
   432 // CStartupListUpdater::GetInstalledAppsL()
   688 // CStartupListUpdater::GetInstalledAppsL()
   433 // ---------------------------------------------------------------------------
   689 // ---------------------------------------------------------------------------
   434 //
   690 //
   435 void CStartupListUpdater::GetInstalledAppsL(
   691 void CStartupListUpdater::GetInstalledAppsL(
   436         RPointerArray<HBufC>& aInstalledExecutableArray )
   692         RPointerArray<HBufC>& aInstalledExecutableArray )
   437     {
   693     {
       
   694     FLOG( _L("CStartupListUpdater::GetInstalledAppsL, begin") );
   438     Swi::RSisRegistrySession sisRegistrySession;
   695     Swi::RSisRegistrySession sisRegistrySession;
   439     User::LeaveIfError( sisRegistrySession.Connect() );
   696     User::LeaveIfError( sisRegistrySession.Connect() );
   440     CleanupClosePushL( sisRegistrySession );
   697     CleanupClosePushL( sisRegistrySession );
   441 
   698 
   442     RPointerArray<Swi::CSisRegistryPackage> removablePackages;
   699     RPointerArray<Swi::CSisRegistryPackage> removablePackages;
   443     CleanupResetAndDestroyPushL( removablePackages );
   700     CleanupResetAndDestroyPushL( removablePackages );
   444     sisRegistrySession.RemovablePackagesL( removablePackages );
   701     sisRegistrySession.RemovablePackagesL( removablePackages );
   445 
   702 
   446     for( TInt index = 0; index < removablePackages.Count(); ++index )
   703     TInt removablePackagesCount = removablePackages.Count();
   447         {
   704     FLOG_1( _L("CStartupListUpdater::GetInstalledAppsL, removablePackagesCount %d"),
       
   705             removablePackagesCount );
       
   706     for( TInt index = 0; index < removablePackagesCount; ++index )
       
   707         {
       
   708         FLOG_1( _L("CStartupListUpdater::GetInstalledAppsL, index %d"), index );
   448         Swi::RSisRegistryEntry entry;
   709         Swi::RSisRegistryEntry entry;
   449         CleanupClosePushL( entry );
   710         CleanupClosePushL( entry );
   450         entry.OpenL( sisRegistrySession, *( removablePackages[ index ] ) );
   711         entry.OpenL( sisRegistrySession, *( removablePackages[ index ] ) );
   451         if( entry.RemovableL() )
   712         if( entry.RemovableL() )
   452             {
   713             {
   454             }
   715             }
   455         CleanupStack::PopAndDestroy( &entry );
   716         CleanupStack::PopAndDestroy( &entry );
   456         }
   717         }
   457 
   718 
   458     CleanupStack::PopAndDestroy( 2, &sisRegistrySession );
   719     CleanupStack::PopAndDestroy( 2, &sisRegistrySession );
       
   720     FLOG( _L("CStartupListUpdater::GetInstalledAppsL, end") );
   459     }
   721     }
   460 
   722 
   461 // ---------------------------------------------------------------------------
   723 // ---------------------------------------------------------------------------
   462 // CStartupListUpdater::GetStartupListAppsL()
   724 // CStartupListUpdater::GetStartupListAppsL()
   463 // ---------------------------------------------------------------------------
   725 // ---------------------------------------------------------------------------
   464 //
   726 //
   465 void CStartupListUpdater::GetStartupListAppsL( RDscStore& aDscStore,
   727 void CStartupListUpdater::GetStartupListAppsL( RDscStore& aDscStore,
   466         RPointerArray<HBufC>& aStartedExecutableArray )
   728         RPointerArray<HBufC>& aStartedExecutableArray )
   467     {
   729     {
       
   730     FLOG( _L("CStartupListUpdater::GetStartupListAppsL, begin") );
   468     aDscStore.EnumOpenLC();
   731     aDscStore.EnumOpenLC();
   469 
   732 
   470     while( CDscItem* item = aDscStore.EnumReadNextL() )
   733     while( CDscItem* item = aDscStore.EnumReadNextL() )
   471         {
   734         {
   472         CleanupStack::PushL( item );
   735         CleanupStack::PushL( item );
   473         aStartedExecutableArray.AppendL( item->FileName().AllocL() );
   736         TPtrC fileName( item->FileName() );
       
   737         FLOG_1( _L("CStartupListUpdater::GetStartupListAppsL, fileName %S"), &fileName );
       
   738         aStartedExecutableArray.AppendL( fileName.AllocL() );
   474         CleanupStack::PopAndDestroy( item );
   739         CleanupStack::PopAndDestroy( item );
   475         }
   740         }
   476 
   741 
   477     CleanupStack::PopAndDestroy();  // runs EnumClose
   742     CleanupStack::PopAndDestroy();  // runs EnumClose
       
   743     FLOG( _L("CStartupListUpdater::GetStartupListAppsL, end") );
   478     }
   744     }
   479 
   745 
   480 // ---------------------------------------------------------------------------
   746 // ---------------------------------------------------------------------------
   481 // CStartupListUpdater::StartedButNotInstalledAppsL()
   747 // CStartupListUpdater::StartedButNotInstalledAppsL()
   482 // ---------------------------------------------------------------------------
   748 // ---------------------------------------------------------------------------
   484 void CStartupListUpdater::StartedButNotInstalledAppsL(
   750 void CStartupListUpdater::StartedButNotInstalledAppsL(
   485         RPointerArray<HBufC>& aStartedExecutableArray,                  // in
   751         RPointerArray<HBufC>& aStartedExecutableArray,                  // in
   486         RPointerArray<HBufC>& aInstalledExecutableArray,                // in
   752         RPointerArray<HBufC>& aInstalledExecutableArray,                // in
   487         RPointerArray<HBufC>& aStartedButNotInstalledExecutableArray )  // out
   753         RPointerArray<HBufC>& aStartedButNotInstalledExecutableArray )  // out
   488     {
   754     {
       
   755     FLOG( _L("CStartupListUpdater::StartedButNotInstalledAppsL, begin") );
   489     aStartedButNotInstalledExecutableArray.ResetAndDestroy();
   756     aStartedButNotInstalledExecutableArray.ResetAndDestroy();
   490 
   757 
   491     TIdentityRelation<HBufC> identityRelation( FileNamesEqual );
   758     TIdentityRelation<HBufC> identityRelation( FileNamesEqual );
   492     for( TInt index = 0; index < aStartedExecutableArray.Count(); ++index )
   759     for( TInt index = 0; index < aStartedExecutableArray.Count(); ++index )
   493         {
   760         {
   494         const HBufC* startedAppName = aStartedExecutableArray[ index ];
   761         const HBufC* startedAppName = aStartedExecutableArray[ index ];
       
   762         FLOG_1( _L("CStartupListUpdater::StartedButNotInstalledAppsL, startedAppName %S"),
       
   763                 startedAppName );
   495         if( aInstalledExecutableArray.Find( startedAppName, identityRelation ) == KErrNotFound )
   764         if( aInstalledExecutableArray.Find( startedAppName, identityRelation ) == KErrNotFound )
   496             {
   765             {
       
   766             FLOG( _L("CStartupListUpdater::StartedButNotInstalledAppsL, adding to array") );
   497             aStartedButNotInstalledExecutableArray.AppendL( startedAppName->AllocL() );
   767             aStartedButNotInstalledExecutableArray.AppendL( startedAppName->AllocL() );
   498             }
   768             }
   499         }
   769         }
       
   770     FLOG( _L("CStartupListUpdater::StartedButNotInstalledAppsL, end") );
   500     }
   771     }
   501 
   772 
   502 // ---------------------------------------------------------------------------
   773 // ---------------------------------------------------------------------------
   503 // CStartupListUpdater::RemoveFromStartupListL()
   774 // CStartupListUpdater::RemoveFromStartupListL()
   504 // ---------------------------------------------------------------------------
   775 // ---------------------------------------------------------------------------
   505 //
   776 //
   506 void CStartupListUpdater::RemoveFromStartupListL( RDscStore& aDscStore,
   777 void CStartupListUpdater::RemoveFromStartupListL( RDscStore& aDscStore,
   507         RPointerArray<HBufC>& aExecutableArray )
   778         RPointerArray<HBufC>& aExecutableArray )
   508     {
   779     {
       
   780     FLOG( _L("CStartupListUpdater::RemoveFromStartupListL, begin") );
   509     for( TInt index = 0; index < aExecutableArray.Count(); ++index )
   781     for( TInt index = 0; index < aExecutableArray.Count(); ++index )
   510         {
   782         {
   511         const TDesC& executableName = *( aExecutableArray[ index ] );
   783         const TDesC& executableName = *( aExecutableArray[ index ] );
       
   784         FLOG_1( _L("CStartupListUpdater::RemoveFromStartupListL, executableName %S"),
       
   785                 &executableName );
   512         CDscItem* item = CDscItem::NewLC( executableName, KNullDesC );
   786         CDscItem* item = CDscItem::NewLC( executableName, KNullDesC );
   513         if( aDscStore.ItemExistsL( *item ) )
   787         if( aDscStore.ItemExistsL( *item ) )
   514             {
   788             {
       
   789             FLOG( _L("CStartupListUpdater::RemoveFromStartupListL, removing from DscStore") );
   515             aDscStore.DeleteItemL( *item );
   790             aDscStore.DeleteItemL( *item );
   516             }
   791             }
   517         CleanupStack::PopAndDestroy( item );
   792         CleanupStack::PopAndDestroy( item );
   518         }
   793         }
       
   794     FLOG( _L("CStartupListUpdater::RemoveFromStartupListL, end") );
   519     }
   795     }
   520 
   796 
   521 // ---------------------------------------------------------------------------
   797 // ---------------------------------------------------------------------------
   522 // CStartupListUpdater::GetExecutablesFromEntryL()
   798 // CStartupListUpdater::GetExecutablesFromEntryL()
   523 // ---------------------------------------------------------------------------
   799 // ---------------------------------------------------------------------------
   524 //
   800 //
   525 void CStartupListUpdater::GetExecutablesFromEntryL( Swi::RSisRegistryEntry& aEntry,
   801 void CStartupListUpdater::GetExecutablesFromEntryL( Swi::RSisRegistryEntry& aEntry,
   526         RPointerArray<HBufC>& aExecutableArray )
   802         RPointerArray<HBufC>& aExecutableArray )
   527     {
   803     {
       
   804     FLOG( _L("CStartupListUpdater::GetExecutablesFromEntryL, begin") );
   528     RPointerArray<HBufC> filesList;
   805     RPointerArray<HBufC> filesList;
   529     CleanupResetAndDestroyPushL( filesList );
   806     CleanupResetAndDestroyPushL( filesList );
   530     aEntry.FilesL( filesList );
   807     aEntry.FilesL( filesList );
   531 
   808 
   532     for( TInt index = 0; index < filesList.Count(); ++index )
   809     for( TInt index = 0; index < filesList.Count(); ++index )
   533         {
   810         {
   534         TParse parse;
   811         TParse parse;
   535         TInt err = parse.SetNoWild( KNullDesC, filesList[ index ], NULL );
   812         TInt err = parse.SetNoWild( KNullDesC, filesList[ index ], NULL );
       
   813         FLOG_3( _L("CStartupListUpdater::GetExecutablesFromEntryL, index %d, parse %S, err %d"),
       
   814                 index, &(parse.FullName()), err );
   536         if( !err && ( parse.Ext().CompareF( KExecutableExtension ) == 0 ) )
   815         if( !err && ( parse.Ext().CompareF( KExecutableExtension ) == 0 ) )
   537             {
   816             {
       
   817             FLOG( _L("CStartupListUpdater::GetExecutablesFromEntryL, adding to array") );
   538             aExecutableArray.AppendL( parse.FullName().AllocL() );
   818             aExecutableArray.AppendL( parse.FullName().AllocL() );
   539             }
   819             }
       
   820         else
       
   821             {
       
   822             FLOG( _L("CStartupListUpdater::GetExecutablesFromEntryL, skipped") );
       
   823             }
   540         }
   824         }
   541 
   825 
   542     CleanupStack::PopAndDestroy( &filesList );
   826     CleanupStack::PopAndDestroy( &filesList );
   543     }
   827     FLOG( _L("CStartupListUpdater::GetExecutablesFromEntryL, end") );
   544 
   828     }
       
   829 
       
   830 // ---------------------------------------------------------------------------
       
   831 // CStartupListUpdater::OpenDevTraceL()
       
   832 // ---------------------------------------------------------------------------
       
   833 //
       
   834 void CStartupListUpdater::OpenDevTraceL()
       
   835     {
       
   836     if( !iLogBuf )
       
   837         {
       
   838         TEntry entry;
       
   839         if( iFs.Entry( KDevTraceDir, entry ) == KErrNone )
       
   840             {
       
   841             FLOG( _L("CStartupListUpdater::OpenDevTraceL, log dir exists") );
       
   842             TFileName fileName;
       
   843             fileName.Copy( KDevTraceDir );
       
   844             fileName.Append( KDevTraceFile );
       
   845             if( iLogFile.Replace( iFs, fileName, EFileWrite ) == KErrNone )
       
   846                 {
       
   847                 iLogBuf = HBufC::NewL( KDevTraceBuffer );
       
   848                 iFileBuf.CreateL( KDevTraceBuffer );
       
   849                 FLOG( _L("CStartupListUpdater::OpenDevTraceL, log file opened") );
       
   850                 }
       
   851             }
       
   852         }
       
   853     }
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // CStartupListUpdater::DevTrace()
       
   857 // ---------------------------------------------------------------------------
       
   858 //
       
   859 void CStartupListUpdater::DevTrace( TRefByValue<const TDesC> aFmt, ... )
       
   860     {
       
   861     if( iLogBuf )
       
   862         {
       
   863         VA_LIST list;
       
   864         VA_START( list, aFmt );
       
   865         TPtr line( iLogBuf->Des() );
       
   866         line.FormatList( aFmt, list );
       
   867         FLOG_1( _L("CStartupListUpdater::DevTrace: %S"), iLogBuf );
       
   868 
       
   869         const TChar KNewLine( '\n' );
       
   870         line.Append( KNewLine );
       
   871         iFileBuf.Copy( line );
       
   872         iLogFile.Write( iFileBuf );  // return value ignored
       
   873         }
       
   874     }
       
   875