contentstorage/casrv/causifscanner/src/causifscanner.cpp
branchRCL_3
changeset 113 0efa10d348c0
equal deleted inserted replaced
111:053c6c7c14f3 113:0efa10d348c0
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: causifscanner.cpp
       
    15  *
       
    16  */
       
    17 
       
    18 #include <e32property.h>
       
    19 #include <f32file.h>
       
    20 #include <badesca.h>
       
    21 
       
    22 #include "causifscanner.h"
       
    23 #include "cainnerentry.h"
       
    24 #include "cainnerquery.h"
       
    25 #include "cadef.h"
       
    26 #include "castorageproxy.h"
       
    27 #include "caarraycleanup.inl"
       
    28 
       
    29 using namespace Usif;
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CCaUsifScanner* CCaUsifScanner::NewL( TPluginParams* aPluginParams )
       
    36     {
       
    37     CCaUsifScanner* self = new ( ELeave ) CCaUsifScanner(
       
    38             *aPluginParams->storageProxy, *aPluginParams->softwareRegistry );
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CCaUsifScanner::CCaUsifScanner( CCaStorageProxy& aStorageProxy,
       
    50     RSoftwareComponentRegistry& aSoftwareRegistry ) :
       
    51         iStorageProxy( aStorageProxy ), iSoftwareRegistry(aSoftwareRegistry)
       
    52     {
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CCaUsifScanner::ConstructL()
       
    60     {
       
    61     iSystemInstallNotifier = CCaInstallNotifier::NewL( *this,
       
    62             CCaInstallNotifier::ESisInstallNotification );
       
    63 
       
    64     iUsifUninstallNotifier = CCaInstallNotifier::NewL( *this,
       
    65             CCaInstallNotifier::EUsifUninstallNotification );
       
    66 
       
    67     iJavaInstallNotifier = CCaInstallNotifier::NewL( *this,
       
    68                 CCaInstallNotifier::EJavaInstallNotification );
       
    69 
       
    70     User::LeaveIfError( iFs.Connect() );
       
    71     iMmcWatcher = CCaMmcWatcher::NewL( iFs, this );
       
    72 
       
    73     UpdateUsifListL();
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CCaUsifScanner::~CCaUsifScanner()
       
    81     {
       
    82     delete iMmcWatcher;
       
    83     iFs.Close();
       
    84     delete iJavaInstallNotifier;
       
    85     delete iUsifUninstallNotifier;
       
    86     delete iSystemInstallNotifier;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 /*void CCaUsifScanner::InstallL( const TDesC& aFileName )
       
    94  {
       
    95  RSoftwareInstall sif;
       
    96  CleanupClosePushL( sif );
       
    97  User::LeaveIfError( sif.Connect());
       
    98 
       
    99  // Install the component
       
   100  TRequestStatus status;
       
   101  sif.Install( aFileName, status, EFalse );
       
   102  User::WaitForRequest( status );
       
   103  User::LeaveIfError(status.Int());
       
   104 
       
   105  // Disconnect from the SIF server
       
   106  CleanupStack::PopAndDestroy( &sif );
       
   107  }*/
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CCaUsifScanner::HandleInstallNotifyL( TInt /*aUid*/)
       
   114     {
       
   115     UpdateUsifListL();
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 #ifdef COVERAGE_MEASUREMENT
       
   123 #pragma CTC SKIP
       
   124 #endif //COVERAGE_MEASUREMENT
       
   125 void CCaUsifScanner::MmcChangeL()
       
   126     {
       
   127     UpdateUsifListL();
       
   128     }
       
   129 #ifdef COVERAGE_MEASUREMENT
       
   130 #pragma CTC ENDSKIP
       
   131 #endif //COVERAGE_MEASUREMENT
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CCaUsifScanner::UpdateUsifListL()
       
   137     {
       
   138     AddPackageL();
       
   139     UpdatePackagesL();
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CCaUsifScanner::CreateCaEntryFromEntryL(
       
   147         const CComponentEntry* aEntry, CCaInnerEntry* aCaEntry )
       
   148     {
       
   149     aCaEntry->SetRole( EItemEntryRole );
       
   150     aCaEntry->SetEntryTypeNameL( KCaTypePackage );
       
   151     if( !aEntry->SoftwareType().Compare( KSoftwareTypeNative ) )
       
   152         {
       
   153         aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueNative );
       
   154         }
       
   155     else if( !aEntry->SoftwareType().Compare( KSoftwareTypeJava ) )
       
   156         {
       
   157         aCaEntry->AddAttributeL( KCaAttrAppType, KCaAttrAppTypeValueJava );
       
   158         }
       
   159     if( aEntry->Name().Compare( KNullDesC ) )
       
   160         {
       
   161         aCaEntry->SetTextL( aEntry->Name() );
       
   162         }
       
   163     if( !aEntry->IsHidden() )
       
   164         {
       
   165         aCaEntry->SetFlags( EVisible );
       
   166         }
       
   167     if( aEntry->IsRemovable() )
       
   168         {
       
   169         aCaEntry->SetFlags( aCaEntry->GetFlags() | ERemovable );
       
   170         }
       
   171     // entries obtained with usif should have component id.
       
   172     //it's needed for uninstalling
       
   173     RBuf compIdDesc;
       
   174     CleanupClosePushL( compIdDesc );
       
   175     compIdDesc.CreateL( KCaMaxAttrValueLen );
       
   176     compIdDesc.Num( aEntry->ComponentId() );
       
   177     aCaEntry->AddAttributeL( KCaAttrComponentId, compIdDesc );
       
   178     CleanupStack::PopAndDestroy( &compIdDesc );
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CCaUsifScanner::AddPackageL()
       
   186     {
       
   187     RPointerArray<CCaInnerEntry> entries;
       
   188     CleanupResetAndDestroyPushL( entries );
       
   189     GetCaPackageEntriesL( entries );
       
   190 
       
   191     RPointerArray<CComponentEntry> resultUsifArray;
       
   192     CleanupResetAndDestroyPushL( resultUsifArray );
       
   193     GetUsifPackageEntriesL( resultUsifArray );
       
   194 
       
   195     for( TInt i(0); i < resultUsifArray.Count(); i++ )
       
   196         {
       
   197         TInt entryIndex = PackageExists( entries, resultUsifArray[i]);
       
   198         // entry is not present in CaStorage
       
   199         if( entryIndex == KErrNotFound )
       
   200             {
       
   201             CCaInnerEntry *caEntry = CCaInnerEntry::NewLC();
       
   202             CreateCaEntryFromEntryL( resultUsifArray[i], caEntry );
       
   203             // in case we rebuild our db mark as missing
       
   204             if( !(iSoftwareRegistry.IsComponentPresentL( 
       
   205                     resultUsifArray[i]->ComponentId())) )
       
   206                 {
       
   207                 caEntry->SetFlags( caEntry->GetFlags() | EMissing );
       
   208                 }
       
   209             iStorageProxy.AddL( caEntry );
       
   210             CleanupStack::PopAndDestroy( caEntry );
       
   211             } 
       
   212         // found in the CaStorage, mark is as missing
       
   213         else if( !(iSoftwareRegistry.IsComponentPresentL( 
       
   214                 resultUsifArray[i]->ComponentId() ))  ) 
       
   215             {
       
   216             if( !( entries[entryIndex]->GetFlags() & EMissing ) )
       
   217                 {
       
   218                 entries[entryIndex]->SetFlags( 
       
   219                         ( entries[entryIndex]->GetFlags() | EMissing ) );
       
   220                 iStorageProxy.AddL( 
       
   221                         entries[entryIndex], EFalse, EItemDisappeared );
       
   222                 }
       
   223             }
       
   224         // found in the storage remove missing flag as this is Present in scr
       
   225         else if (entries[entryIndex]->GetFlags() & EMissing)
       
   226             {
       
   227             entries[entryIndex]->SetFlags( 
       
   228                     entries[entryIndex]->GetFlags() & ~EMissing );
       
   229             iStorageProxy.AddL( entries[entryIndex]);            
       
   230             }
       
   231         }
       
   232 
       
   233     CleanupStack::PopAndDestroy( &resultUsifArray );
       
   234     CleanupStack::PopAndDestroy( &entries );
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CCaUsifScanner::UpdatePackagesL()
       
   242     {
       
   243     RPointerArray<CCaInnerEntry> resultCaArray;
       
   244     CleanupResetAndDestroyPushL( resultCaArray );
       
   245     GetCaPackageEntriesL( resultCaArray );
       
   246 
       
   247     RPointerArray<CComponentEntry> resultUsifArray;
       
   248     CleanupResetAndDestroyPushL( resultUsifArray );
       
   249     GetUsifPackageEntriesL( resultUsifArray );
       
   250 
       
   251     FindDeletedEntriesL( resultCaArray, resultUsifArray );
       
   252     RemoveEntriesFromDbL( resultCaArray );
       
   253 
       
   254     CleanupStack::PopAndDestroy( &resultUsifArray );
       
   255     CleanupStack::PopAndDestroy( &resultCaArray );
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CCaUsifScanner::GetCaPackageEntriesL(
       
   263         RPointerArray<CCaInnerEntry>& aArray )
       
   264     {
       
   265     CCaInnerQuery* allAppQuery = CCaInnerQuery::NewLC();
       
   266     CDesC16ArrayFlat* appType =
       
   267             new ( ELeave ) CDesC16ArrayFlat( KGranularityOne );
       
   268     CleanupStack::PushL( appType );
       
   269     appType->AppendL( KCaTypePackage );
       
   270     allAppQuery->SetEntryTypeNames( appType );
       
   271     CleanupStack::Pop( appType );
       
   272     iStorageProxy.GetEntriesL( allAppQuery, aArray );
       
   273     CleanupStack::PopAndDestroy( allAppQuery );
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CCaUsifScanner::GetUsifPackageEntriesL(
       
   281         RPointerArray<CComponentEntry>& aArray )
       
   282     {
       
   283     CComponentFilter *filter = CComponentFilter::NewL();
       
   284     CleanupStack::PushL( filter );
       
   285     filter->SetRemovable( ETrue );
       
   286     filter->SetHidden( EFalse );
       
   287 
       
   288     // Create an SCR view
       
   289     RSoftwareComponentRegistryView scrView;
       
   290     CleanupClosePushL( scrView );
       
   291     scrView.OpenViewL( iSoftwareRegistry, filter );
       
   292 
       
   293     // Iterate over the matching components
       
   294     //The ownership is transferred to the calling client.
       
   295     while( CComponentEntry* entry = scrView.NextComponentL() )
       
   296         {
       
   297         CleanupStack::PushL( entry );
       
   298         aArray.AppendL( entry );
       
   299         CleanupStack::Pop( entry );
       
   300         }
       
   301     CleanupStack::PopAndDestroy( &scrView );
       
   302     CleanupStack::PopAndDestroy( filter );
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 TInt CCaUsifScanner::PackageExists( RPointerArray<CCaInnerEntry>& aArray,
       
   310         const CComponentEntry* aEntry )
       
   311     {
       
   312     TInt retVal( KErrNotFound );
       
   313     for( TInt i( 0 ); i < aArray.Count(); i++ )
       
   314         {
       
   315         TBuf<KMaxUnits> compIdDes;
       
   316         if( aArray[i]->FindAttribute( KCaAttrComponentId, compIdDes ) )
       
   317             {
       
   318             TLex lex( compIdDes );
       
   319             TUint uint( 0 );
       
   320             if( lex.Val( uint ) == KErrNone && aEntry->ComponentId() == uint )
       
   321                 {
       
   322                 retVal = i;
       
   323                 }
       
   324             }
       
   325         }
       
   326     return retVal;
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 void CCaUsifScanner::FindDeletedEntriesL(
       
   334         RPointerArray<CCaInnerEntry>& aCaArray, const RPointerArray<
       
   335                 CComponentEntry>& aUsifArray )
       
   336     {
       
   337     for( TInt i( aCaArray.Count() - 1 ); i >= 0; i-- )
       
   338         {
       
   339         TBuf<KMaxUnits> compIdDes;
       
   340         if( aCaArray[i]->FindAttribute( KCaAttrComponentId, compIdDes ) )
       
   341             {
       
   342             TLex lex( compIdDes );
       
   343             TUint uint( 0 );
       
   344             User::LeaveIfError( lex.Val( uint ) );
       
   345             //for each usif entry check if entry has to be removed
       
   346             for( TInt k( 0 ); k < aUsifArray.Count(); k++ )
       
   347                 {
       
   348                 if( aUsifArray[k]->ComponentId() == uint)
       
   349                     {
       
   350                     delete aCaArray[i];
       
   351                     aCaArray.Remove( i );
       
   352                     break;
       
   353                     }
       
   354                 }
       
   355             }
       
   356         }
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 //
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 void CCaUsifScanner::RemoveEntriesFromDbL(
       
   364         RPointerArray<CCaInnerEntry>& aCaArray )
       
   365     {
       
   366     RArray<TInt> entriesId;
       
   367     CleanupClosePushL( entriesId );
       
   368     for( TInt i( 0 ); i < aCaArray.Count(); i++ )
       
   369         {
       
   370         entriesId.Append( aCaArray[i]->GetId() );
       
   371         }
       
   372     iStorageProxy.RemoveL( entriesId );
       
   373     CleanupStack::PopAndDestroy( &entriesId );
       
   374     }