connectivitymodules/SeCon/services/pcd/src/sconpcdutility.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
parent 18 453dfc402455
child 20 4a793f564d72
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
     1 /*
       
     2 * Copyright (c) 2006-2010 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:  SConPcdUtility implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  CLASS HEADER
       
    20 #include <swi/sisregistryentry.h>
       
    21 #include <swi/sisregistrysession.h>
       
    22 #include <swi/sisregistrypackage.h>
       
    23 #include <stringresourcereader.h>
       
    24 #include <widgetregistryclient.h>
       
    25 #include <javaregistryincludes.h>
       
    26 #include <appversion.h>
       
    27 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    28 #include <sconftp.rsg>              // Resource to be read header 
       
    29 
       
    30 using namespace Java;
       
    31 
       
    32 #include "debug.h"
       
    33 #include "sconpcdutility.h"
       
    34 #include "sconconmltask.h"
       
    35 
       
    36 // localized "unknown vendor".
       
    37 _LIT( KSConResourceName, "z:\\Resource\\sconftp.rsc" );
       
    38 
       
    39 
       
    40 
       
    41 //  METHODS
       
    42 //----------------------------------------------------------------------------
       
    43 // void SConPcdUtility::ProcessListInstalledAppsL( CSConTask*& aTask )
       
    44 //----------------------------------------------------------------------------
       
    45 //
       
    46 void SConPcdUtility::ProcessListInstalledAppsL( CSConTask*& aTask )
       
    47     {
       
    48     TRACE_FUNC_ENTRY;
       
    49     
       
    50     LOGGER_WRITE_1("iAllApps: %d",(TInt)aTask->iListAppsParams->iAllApps);
       
    51     LOGGER_WRITE8_1("driveList: %S", &aTask->iListAppsParams->iDriveList);
       
    52     
       
    53     AppendInstalledSisL( *aTask->iListAppsParams );
       
    54     AppendInstalledJavaL( *aTask->iListAppsParams );
       
    55     AppendInstalledWidgetsL( *aTask->iListAppsParams );
       
    56     
       
    57     TRACE_FUNC_EXIT;
       
    58     }
       
    59 
       
    60 //----------------------------------------------------------------------------
       
    61 // void SConPcdUtility::AppendInstalledSisL( RPointerArray<CSConInstApp> &aApps )
       
    62 // Appends installed sis packages and augmentations to aApps array.
       
    63 //----------------------------------------------------------------------------
       
    64 //
       
    65 void SConPcdUtility::AppendInstalledSisL( CSConListInstApps& aListInstApps )
       
    66     {
       
    67     TRACE_FUNC_ENTRY;
       
    68     // Get installed applications from sis registry
       
    69     Swi::RSisRegistrySession sisRegistry;
       
    70     CleanupClosePushL( sisRegistry );
       
    71     User::LeaveIfError( sisRegistry.Connect() );
       
    72     
       
    73     RArray<TUid> uids;
       
    74     CleanupClosePushL(uids);
       
    75     sisRegistry.InstalledUidsL( uids );
       
    76     
       
    77     
       
    78     //Read package information
       
    79     for( TInt i = 0; i < uids.Count(); i++ )
       
    80         {
       
    81         Swi::RSisRegistryEntry entry;
       
    82         CleanupClosePushL(entry);
       
    83         User::LeaveIfError( entry.Open( sisRegistry, uids[i] ) );
       
    84         
       
    85         TBool showIt( EFalse );
       
    86         if ( aListInstApps.iAllApps )
       
    87             {
       
    88             // show all apps -param defined, exlude stubs on ROM
       
    89             if ( !entry.IsInRomL() )
       
    90                 {
       
    91                 showIt = ETrue;
       
    92                 }
       
    93             }
       
    94         else
       
    95             {
       
    96             // show if installed one of the specified drives
       
    97             // don't exlude stubs on ROM
       
    98             showIt = IsInstalledToSelectedDrive( aListInstApps.iDriveList,
       
    99                                                  entry.InstalledDrivesL() );
       
   100             }
       
   101         
       
   102         // Only show if not in rom
       
   103         if ( showIt && entry.IsPresentL() )
       
   104             {    
       
   105             // Add the created object to the list
       
   106             LOGGER_WRITE_1( "SConPcdUtility::ProcessListInstalledAppsL : add pkg, index %d", i );
       
   107             CSConInstApp* app = new (ELeave) CSConInstApp();
       
   108             CleanupStack::PushL( app );
       
   109             
       
   110             HBufC* temp = entry.PackageNameL();
       
   111             TPtrC tempPtr = temp->Des();
       
   112             LOGGER_WRITE_1("PackageNameL: %S", &tempPtr);
       
   113             CleanupStack::PushL( temp );
       
   114             if ( temp->Length() > app->iName.MaxLength() )
       
   115             	{
       
   116             	User::Leave( KErrTooBig );
       
   117             	}
       
   118             app->iName.Copy( *temp );
       
   119             CleanupStack::PopAndDestroy( temp );
       
   120             temp = NULL;
       
   121             
       
   122             temp = entry.UniqueVendorNameL();
       
   123             CleanupStack::PushL( temp );
       
   124             if ( temp->Length() > app->iVendor.MaxLength() )
       
   125             	{
       
   126             	User::Leave( KErrTooBig );
       
   127             	}
       
   128             app->iVendor.Copy( *temp );
       
   129             CleanupStack::PopAndDestroy( temp );
       
   130             temp = NULL;
       
   131             
       
   132             app->iVersion.Copy( entry.VersionL().Name() );
       
   133             app->iType = ESisApplication;
       
   134             app->iSize = entry.SizeL();
       
   135             app->iUid = entry.UidL();
       
   136             
       
   137             User::LeaveIfError( aListInstApps.iApps.Append( app ) );
       
   138             CleanupStack::Pop( app );
       
   139             }
       
   140         
       
   141         // Get possible augmentations
       
   142         RPointerArray<Swi::CSisRegistryPackage> augPackages;
       
   143         CleanupResetAndDestroyPushL( augPackages );
       
   144         entry.AugmentationsL( augPackages );
       
   145         for ( TInt j( 0 ); j < augPackages.Count(); j++ )
       
   146             {
       
   147             Swi::RSisRegistryEntry augmentationEntry;
       
   148             CleanupClosePushL( augmentationEntry );
       
   149             augmentationEntry.OpenL( sisRegistry, *augPackages[j] );
       
   150             
       
   151             TBool showIt( EFalse );
       
   152             if ( aListInstApps.iAllApps )
       
   153                 {
       
   154                 // show all apps -param defined, exlude stubs on ROM
       
   155                 if ( !augmentationEntry.IsInRomL() )
       
   156                     {
       
   157                     showIt = ETrue;
       
   158                     }
       
   159                 }
       
   160             else
       
   161                 {
       
   162                 // show if installed one of the specified drives
       
   163                 // don't exlude stubs on ROM
       
   164                 showIt = IsInstalledToSelectedDrive( aListInstApps.iDriveList,
       
   165                                         augmentationEntry.InstalledDrivesL() );
       
   166                 }
       
   167             
       
   168             // Only show if not in rom
       
   169             if ( showIt && augmentationEntry.IsPresentL() )
       
   170                 {
       
   171                 CSConInstApp* augApp = new (ELeave) CSConInstApp();
       
   172                 CleanupStack::PushL( augApp );
       
   173                 augApp->iName.Copy( augPackages[j]->Name() );
       
   174                 
       
   175                 HBufC* temp = entry.PackageNameL();
       
   176                 CleanupStack::PushL( temp );
       
   177                 if ( temp->Length() > augApp->iParentName.MaxLength() )
       
   178                 	{
       
   179                 	User::Leave( KErrTooBig );
       
   180                 	}
       
   181                 augApp->iParentName.Copy( *temp );
       
   182                 CleanupStack::PopAndDestroy( temp );
       
   183                 temp = NULL;
       
   184                 
       
   185                 augApp->iVendor.Copy( augPackages[j]->Vendor() );
       
   186                 augApp->iVersion.Copy( augmentationEntry.VersionL().Name() );
       
   187                 augApp->iType = ESisAugmentation;
       
   188                 augApp->iSize = augmentationEntry.SizeL();
       
   189                 augApp->iUid = augmentationEntry.UidL();
       
   190                 
       
   191                 LOGGER_WRITE_1( "SConPcdUtility::ProcessListInstalledAppsL : add augmentation, index: %d", j );
       
   192                 LOGGER_WRITE_1( "SConPcdUtility::ProcessListInstalledAppsL : add augmentation, basepkg: %d", i );
       
   193                 TInt augindex = augPackages[j]->Index();
       
   194                 LOGGER_WRITE_1( "SConPcdUtility::ProcessListInstalledAppsL : augindex: %d",augindex );
       
   195                 User::LeaveIfError( aListInstApps.iApps.Append( augApp ) );
       
   196                 CleanupStack::Pop( augApp );   
       
   197                 }
       
   198             CleanupStack::PopAndDestroy( &augmentationEntry );
       
   199             }  
       
   200         CleanupStack::PopAndDestroy( &augPackages ); 
       
   201         CleanupStack::PopAndDestroy( &entry );
       
   202         }
       
   203     
       
   204     CleanupStack::PopAndDestroy(&uids);
       
   205     CleanupStack::PopAndDestroy(&sisRegistry);
       
   206     TRACE_FUNC_EXIT;
       
   207     }
       
   208 
       
   209 //----------------------------------------------------------------------------
       
   210 // void SConPcdUtility::AppendInstalledJavaL( RPointerArray<CSConInstApp> &aApps )
       
   211 // Appends installed java packages to aApps array.
       
   212 //----------------------------------------------------------------------------
       
   213 //
       
   214 void SConPcdUtility::AppendInstalledJavaL( CSConListInstApps& aListInstApps )
       
   215     {
       
   216     TRACE_FUNC_ENTRY;
       
   217     CJavaRegistry* javaRegistry = CJavaRegistry::NewLC( );
       
   218     RArray<TUid> packageUids;
       
   219     CleanupClosePushL( packageUids );
       
   220     javaRegistry->GetRegistryEntryUidsL( packageUids );
       
   221     LOGGER_WRITE_1("packageUids.Count(): %d", packageUids.Count());
       
   222     for (TInt i=0; i<packageUids.Count(); i++ )
       
   223         {
       
   224         LOGGER_WRITE_1("RegistryEntryL: %d",i);
       
   225         LOGGER_WRITE_1("handle entry uid: 0x%08X",packageUids[i].iUid);
       
   226         CJavaRegistryEntry* entry = javaRegistry->RegistryEntryL( packageUids[i] );
       
   227         if ( entry )
       
   228             {
       
   229             CleanupStack::PushL( entry );
       
   230             if ( entry->Type() >= EGeneralPackage && entry->Type() < EGeneralApplication )
       
   231                 {
       
   232                 // entry was correct type
       
   233                 CJavaRegistryPackageEntry* packageEntry = ( CJavaRegistryPackageEntry* ) entry;
       
   234                 
       
   235                 // check do we need to filter it out
       
   236                 TBool showIt( EFalse );
       
   237                 if ( aListInstApps.iAllApps )
       
   238                     {
       
   239                     showIt = ETrue;
       
   240                     }
       
   241                 else
       
   242                     {
       
   243                     TDriveNumber drive = packageEntry->Drive();
       
   244                     if ( aListInstApps.iDriveList.Length() > drive
       
   245                             && aListInstApps.iDriveList[ drive ] )
       
   246                         {
       
   247                         showIt = ETrue;
       
   248                         }
       
   249                     }
       
   250                 
       
   251                 if ( showIt )
       
   252                     {
       
   253                     CSConInstApp* app = new (ELeave) CSConInstApp();
       
   254                     CleanupStack::PushL( app );
       
   255                     // Get Uid, name, type, vendor
       
   256                     app->iUid =  packageEntry->Uid();
       
   257                     app->iName.Copy ( packageEntry->Name() );
       
   258                     LOGGER_WRITE_1( "Name: %S", &app->iName );
       
   259                     app->iType = EJavaApplication;
       
   260                     
       
   261                     // Get version
       
   262                     TAppVersion midletVersion( packageEntry->Version() );
       
   263                     TVersion verType(midletVersion.iMajor, midletVersion.iMinor, midletVersion.iBuild);    
       
   264                     app->iVersion.Copy( verType.Name() );
       
   265                     
       
   266                     // Get vendor
       
   267                     if ( entry->NumberOfCertificateChains() > 0 && packageEntry->Vendor().Length() > 0 )
       
   268                         {
       
   269                         app->iVendor.Copy( packageEntry->Vendor() );
       
   270                         }
       
   271                     else
       
   272                         {
       
   273                         // untrusted applications do not have certificates.
       
   274                         // if the application has a certificate, it is installed either as 
       
   275                         // trusted or not installed at all.
       
   276                         
       
   277                         // unknown vendor
       
   278                         TFileName myFileName( KSConResourceName );
       
   279                         CStringResourceReader* resReader = CStringResourceReader::NewL( myFileName );
       
   280                         TPtrC bufUnknownSuplier;
       
   281                         bufUnknownSuplier.Set( resReader->ReadResourceString( R_SECON_UNKNOWN_SUPPLIER ) );
       
   282                         
       
   283                         app->iVendor.Copy( bufUnknownSuplier );
       
   284                         
       
   285                         delete resReader;
       
   286                         }
       
   287                     
       
   288                     // Get size
       
   289                     app->iSize = packageEntry->UsedUserDiskSpace();
       
   290                     
       
   291                     User::LeaveIfError( aListInstApps.iApps.Append( app ) );
       
   292                     CleanupStack::Pop( app );
       
   293                     }
       
   294                 }
       
   295             CleanupStack::PopAndDestroy( entry );
       
   296             }
       
   297         }
       
   298     
       
   299     CleanupStack::PopAndDestroy( &packageUids );
       
   300     CleanupStack::PopAndDestroy( javaRegistry );
       
   301     TRACE_FUNC_EXIT;
       
   302     }
       
   303 
       
   304 //----------------------------------------------------------------------------
       
   305 // void SConPcdUtility::AppendInstalledWidgetsL( RPointerArray<CSConInstApp> &aApps )
       
   306 // Appends installed widgets to aApps array.
       
   307 //----------------------------------------------------------------------------
       
   308 //
       
   309 void SConPcdUtility::AppendInstalledWidgetsL( CSConListInstApps& aListInstApps )
       
   310     {
       
   311     TRACE_FUNC_ENTRY;
       
   312     RWidgetRegistryClientSession widgetSession;
       
   313     CleanupClosePushL( widgetSession );
       
   314     User::LeaveIfError( widgetSession.Connect() );
       
   315     
       
   316     // Get the list of installed widgets
       
   317     RWidgetInfoArray widgetInfoArr;
       
   318     CleanupClosePushL( widgetInfoArr );
       
   319     widgetSession.InstalledWidgetsL( widgetInfoArr );
       
   320     TFileName bundleId;
       
   321     for ( TInt i = 0; i < widgetInfoArr.Count(); i++ )
       
   322         {
       
   323         CWidgetInfo *item = widgetInfoArr[i];
       
   324         CleanupStack::PushL( item );
       
   325         
       
   326         
       
   327         TBool showIt( EFalse );
       
   328         if ( aListInstApps.iAllApps )
       
   329             {
       
   330             // show all apps -param defined
       
   331             showIt = ETrue;
       
   332             }
       
   333         else
       
   334             {
       
   335             TDriveUnit locationDrive = item->iDriveName->Des();
       
   336             // show if installed one of the specified drives
       
   337             if (  aListInstApps.iDriveList.Length() > locationDrive
       
   338                     && aListInstApps.iDriveList[locationDrive] )
       
   339                 {
       
   340                 showIt = ETrue;
       
   341                 }
       
   342             }
       
   343         
       
   344         if ( showIt )
       
   345             {
       
   346             
       
   347             CSConInstApp* app = new (ELeave) CSConInstApp();
       
   348             CleanupStack::PushL( app );
       
   349             app->iName.Copy( *(item->iBundleName) );
       
   350             app->iType = EWidgetApplication;
       
   351             app->iSize = item->iFileSize;
       
   352             app->iUid = item->iUid;
       
   353             
       
   354             CWidgetPropertyValue* propValue = widgetSession.GetWidgetPropertyValueL(
       
   355                     item->iUid, EBundleVersion );
       
   356             if ( propValue && propValue->iType == EWidgetPropTypeString )
       
   357                 {
       
   358                 app->iVersion.Copy( *(propValue->iValue.s) );
       
   359                 }
       
   360             delete propValue;
       
   361             propValue = NULL;
       
   362             bundleId.Zero();
       
   363             widgetSession.GetWidgetBundleId( item->iUid, bundleId );
       
   364             app->iWidgetBundleId = bundleId.AllocL();
       
   365             
       
   366             User::LeaveIfError( aListInstApps.iApps.Append( app ) );
       
   367             CleanupStack::Pop( app ); // ownership transferred, do not delete
       
   368             }
       
   369         CleanupStack::PopAndDestroy( item );
       
   370         }
       
   371     User::LeaveIfError( widgetSession.Disconnect() );
       
   372     
       
   373     CleanupStack::PopAndDestroy( &widgetInfoArr );
       
   374     CleanupStack::PopAndDestroy( &widgetSession );
       
   375     TRACE_FUNC_EXIT;
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------
       
   379 // SConPcdUtility::IsInstalledToSelectedDrive
       
   380 // Solve highest drive from aInstalledDrives and check
       
   381 // if that drive is selected
       
   382 // ---------------------------------------------------------
       
   383 //
       
   384 TBool SConPcdUtility::IsInstalledToSelectedDrive( const TDriveList& aSelectedDriveList, TUint aInstalledDrives )
       
   385     {
       
   386     TInt locationDrive;
       
   387     if( aInstalledDrives )
       
   388          {
       
   389          // Select the highest drive as location drive
       
   390          TInt drive = EDriveA;
       
   391          while( aInstalledDrives >>= 1 )
       
   392              {
       
   393              drive++;
       
   394              }
       
   395          locationDrive = drive;
       
   396          }
       
   397      else
       
   398          {
       
   399          // No installed files, select C: as location drive
       
   400          locationDrive = EDriveC;
       
   401          }
       
   402     
       
   403     if ( aSelectedDriveList.Length() > locationDrive && aSelectedDriveList[locationDrive] )
       
   404         {
       
   405         LOGGER_WRITE("SConPcdUtility::IsInstalledToSelectedDrive : return ETrue");
       
   406         return ETrue;
       
   407         }
       
   408     else
       
   409         {
       
   410         LOGGER_WRITE("SConPcdUtility::IsInstalledToSelectedDrive : return EFalse");
       
   411         return EFalse;
       
   412         }
       
   413     }
       
   414 //  END OF FILE