appinstaller/AppMngr2/Sisx/src/appmngr2sisxappinfo.cpp
changeset 80 9dcba1ee99f7
parent 77 d1838696558c
equal deleted inserted replaced
77:d1838696558c 80:9dcba1ee99f7
     1 /*
       
     2 * Copyright (c) 2003-2008 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:   SisxAppInfo implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2sisxappinfo.h"        // CAppMngr2SisxAppInfo
       
    20 #include "appmngr2sisxruntime.h"        // KAppMngr2SisxUid
       
    21 #include "appmngr2sisxinfoiterator.h"   // CAppMngr2SisxInfoIterator
       
    22 #include "appmngr2sisx.hrh"             // SISX command IDs
       
    23 #include <eikmenup.h>                   // CEikMenuPaneItem
       
    24 #include <appmngr2runtimeobserver.h>    // RefreshInstalledApps
       
    25 #include <appmngr2driveutils.h>         // TAppMngr2DriveUtils
       
    26 #include <appmngr2drmutils.h>           // TAppMngr2DRMUtils
       
    27 #include <appmngr2cleanuputils.h>       // CleanupResetAndDestroyPushL
       
    28 #include <appmngr2debugutils.h>         // FLOG macros
       
    29 #include <x509cert.h>                   // CX509Certificate
       
    30 #include <swi/sisregistrypackage.h>     // CSisRegistryPackage
       
    31 
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CAppMngr2SisxAppInfo::NewL()
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CAppMngr2SisxAppInfo* CAppMngr2SisxAppInfo::NewL( CAppMngr2Runtime& aRuntime,
       
    40         Swi::RSisRegistryEntry& aEntry, RFs& aFsSession )
       
    41     {
       
    42     CAppMngr2SisxAppInfo* self = new (ELeave) CAppMngr2SisxAppInfo( aRuntime,
       
    43             aFsSession );
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL( aEntry );
       
    46     CleanupStack::Pop( self );
       
    47     return self;
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CAppMngr2SisxAppInfo::~CAppMngr2SisxAppInfo()
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CAppMngr2SisxAppInfo::~CAppMngr2SisxAppInfo()
       
    55     {
       
    56     CancelCommand();
       
    57     delete iProtectedFile;
       
    58     delete iSWInstLauncherCustomUninstallParams;
       
    59     delete iName;
       
    60     delete iDetails;
       
    61     delete iVendor;
       
    62     iCertificates.ResetAndDestroy();
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CAppMngr2SisxAppInfo::IconIndex()
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TInt CAppMngr2SisxAppInfo::IconIndex() const
       
    70     {
       
    71     if( iIsDRMProtected && iIsRightsObjectMissingOrExpired )
       
    72         {
       
    73         return EQgnPropDrmExpLarge;
       
    74         }
       
    75     return EQgnMenuAmSis;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CAppMngr2SisxAppInfo::Name()
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 const TDesC& CAppMngr2SisxAppInfo::Name() const
       
    83     {
       
    84     if( iName )
       
    85         {
       
    86         return *iName;
       
    87         }
       
    88     return KNullDesC;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CAppMngr2SisxAppInfo::Details()
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 const TDesC& CAppMngr2SisxAppInfo::Details() const
       
    96     {
       
    97     if( iDetails )
       
    98         {
       
    99         return *iDetails;
       
   100         }
       
   101     return KNullDesC;
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // CAppMngr2SisxAppInfo::SupportsGenericCommand()
       
   106 // ---------------------------------------------------------------------------
       
   107 //
       
   108 TBool CAppMngr2SisxAppInfo::SupportsGenericCommand( TInt /*aCmdId*/ )
       
   109     {
       
   110     return ETrue;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CAppMngr2SisxAppInfo::HandleCommandL()
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CAppMngr2SisxAppInfo::HandleCommandL( TInt aCommandId, TRequestStatus& aStatus )
       
   118     {
       
   119     FLOG( "CAppMngr2SisxAppInfo::HandleCommandL( %d )", aCommandId );
       
   120     iCommandId = aCommandId;
       
   121     switch( aCommandId )
       
   122         {
       
   123         case EAppMngr2CmdViewDetails:
       
   124             ShowDetailsL();
       
   125             break;
       
   126 
       
   127         case EAppMngr2CmdUninstall:
       
   128             HandleUninstallL( aStatus );
       
   129             return;     // async operation started
       
   130 
       
   131         default:
       
   132             break;
       
   133         }
       
   134 
       
   135     // sync operation done, complete aStatus
       
   136     TRequestStatus* statusPtr = &aStatus;
       
   137     User::RequestComplete( statusPtr, KErrNone );
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CAppMngr2SisxAppInfo::HandleCommandResultL()
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CAppMngr2SisxAppInfo::HandleCommandResultL( TInt aStatus )
       
   145     {
       
   146     FLOG( "CAppMngr2SisxAppInfo::HandleCommandResultL( %d ), cmd = %d", aStatus, iCommandId );
       
   147     if( iSWInstLauncher )
       
   148         {
       
   149         iSWInstLauncher->Close();
       
   150         delete iSWInstLauncher;
       
   151         iSWInstLauncher = NULL;
       
   152         delete iSWInstLauncherCustomUninstallParams;
       
   153         iSWInstLauncherCustomUninstallParams = NULL;
       
   154         }
       
   155     if( aStatus != SwiUI::KSWInstErrUserCancel && aStatus != KErrCancel )
       
   156         {
       
   157         User::LeaveIfError( aStatus );
       
   158         }
       
   159     if( iIsAugmentation && iCommandId == EAppMngr2CmdUninstall )
       
   160         {
       
   161         Runtime().Observer().RefreshInstalledApps();
       
   162         }
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CAppMngr2SisxAppInfo::CancelCommand()
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 void CAppMngr2SisxAppInfo::CancelCommand()
       
   170     {
       
   171     FLOG( "CAppMngr2SisxAppInfo::CancelCommand(), cmd = %d", iCommandId );
       
   172     if( iSWInstLauncher )
       
   173         {
       
   174         if( iIsAugmentation )
       
   175             {
       
   176             iSWInstLauncher->CancelAsyncRequest( SwiUI::ERequestCustomUninstall );
       
   177             }
       
   178         else
       
   179             {
       
   180             iSWInstLauncher->CancelAsyncRequest( SwiUI::ERequestUninstall );
       
   181             }
       
   182         iSWInstLauncher->Close();
       
   183         delete iSWInstLauncher;
       
   184         iSWInstLauncher = NULL;
       
   185         delete iSWInstLauncherCustomUninstallParams;
       
   186         iSWInstLauncherCustomUninstallParams = NULL;
       
   187         }
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CAppMngr2SisxAppInfo::Version()
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 TVersion CAppMngr2SisxAppInfo::Version() const
       
   195     {
       
   196     return iVersion;
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CAppMngr2SisxAppInfo::Vendor()
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 const TDesC& CAppMngr2SisxAppInfo::Vendor() const
       
   204     {
       
   205     if( iVendor )
       
   206         {
       
   207         return *iVendor;
       
   208         }
       
   209     return KNullDesC;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CAppMngr2SisxAppInfo::IsTrusted()
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TBool CAppMngr2SisxAppInfo::IsTrusted() const
       
   217     {
       
   218     return iIsTrusted;
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CAppMngr2SisxAppInfo::CAppMngr2SisxAppInfo()
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 CAppMngr2SisxAppInfo::CAppMngr2SisxAppInfo( CAppMngr2Runtime& aRuntime,
       
   226         RFs& aFsSession ) : CAppMngr2AppInfo( aRuntime, aFsSession )
       
   227     {
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CAppMngr2SisxAppInfo::ConstructL()
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CAppMngr2SisxAppInfo::ConstructL( Swi::RSisRegistryEntry& aEntry )
       
   235     {
       
   236     FLOG( "CAppMngr2SisxAppInfo::ConstructL()" );
       
   237     CAppMngr2AppInfo::ConstructL();     // base construct
       
   238     
       
   239     iAppUid = aEntry.UidL();
       
   240     FLOG( "CAppMngr2SisxAppInfo::ConstructL, iAppUid = 0x%08x", iAppUid.iUid );
       
   241     iName = aEntry.PackageNameL();
       
   242     FLOG( "CAppMngr2SisxAppInfo::ConstructL, iName = %S", iName );
       
   243     iDetails = SizeStringWithUnitsL( aEntry.SizeL() );
       
   244     FLOG( "CAppMngr2SisxAppInfo::ConstructL, iDetails = %S", iDetails );
       
   245 
       
   246     TUint drivesMask = aEntry.InstalledDrivesL();
       
   247     if( drivesMask )
       
   248         {
       
   249         // Select the highest drive as location drive
       
   250         TInt drive = EDriveA;
       
   251         while( drivesMask >>= 1 )
       
   252             {
       
   253             drive++;
       
   254             }
       
   255         iLocationDrive = drive;
       
   256         }
       
   257     else
       
   258         {
       
   259         // No installed files, select C: as location drive
       
   260         iLocationDrive = EDriveC;
       
   261         }
       
   262     iLocation = TAppMngr2DriveUtils::LocationFromDriveL( iLocationDrive, iFs );
       
   263 
       
   264     iVersion = aEntry.VersionL();
       
   265     iVendor = aEntry.LocalizedVendorNameL();
       
   266     
       
   267     iIsAugmentation = aEntry.IsAugmentationL();
       
   268     if( iIsAugmentation )
       
   269         {
       
   270         Swi::CSisRegistryPackage* pkg = aEntry.PackageL();
       
   271         iAugmentationIndex = pkg->Index();
       
   272         delete pkg;
       
   273         }
       
   274 
       
   275     Swi::TSisPackageTrust trustLevel = aEntry.TrustL();  
       
   276     if( trustLevel >= Swi::ESisPackageCertificateChainValidatedToTrustAnchor )
       
   277         {
       
   278         iIsTrusted = ETrue;
       
   279         }
       
   280 
       
   281     // If installed SIS package is DRM protected, find the protected file and
       
   282     // save it's full name in iProtectedFile member variable for later use.
       
   283     // Full name of the protected file is needed in ShowDetailsL() function
       
   284     // to show the licence information.
       
   285     RPointerArray<HBufC> files;
       
   286     TRAPD( err, aEntry.FilesL( files ) );
       
   287     if( err == KErrNone )
       
   288         {
       
   289         CleanupResetAndDestroyPushL( files );
       
   290         for( TInt fileIndex = 0; fileIndex < files.Count() && !iIsDRMProtected; fileIndex++ )
       
   291             {
       
   292             HBufC* fileName = files[ fileIndex ];
       
   293             iIsDRMProtected = TAppMngr2DRMUtils::IsDRMProtected( *fileName );
       
   294             if( iIsDRMProtected )
       
   295                 {
       
   296                 FLOG( "CAppMngr2SisxAppInfo::ConstructL, protected file %S", fileName );
       
   297                 iProtectedFile = fileName;  // takes ownership
       
   298                 files.Remove( fileIndex );
       
   299                 iIsRightsObjectMissingOrExpired = 
       
   300                     TAppMngr2DRMUtils::IsDRMRightsObjectExpiredOrMissingL( *fileName ); 
       
   301                 }
       
   302             }
       
   303         CleanupStack::PopAndDestroy( &files );
       
   304         }
       
   305 
       
   306     FLOG( "CAppMngr2SisxAppInfo::ConstructL, loc=%d, aug=%d, trust=%d, drm=%d, RO=%d",
       
   307             iLocation, iIsAugmentation, iIsTrusted, iIsDRMProtected,
       
   308             iIsRightsObjectMissingOrExpired );
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CAppMngr2SisxAppInfo::ShowDetailsL()
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CAppMngr2SisxAppInfo::ShowDetailsL()
       
   316     {
       
   317     FLOG( "CAppMngr2SisxAppInfo::ShowDetailsL()" );
       
   318     TRAP_IGNORE( ReadCertificatesL() );
       
   319     
       
   320     CAppMngr2SisxInfoIterator* iterator = CAppMngr2SisxInfoIterator::NewL( *this,
       
   321             EAppMngr2StatusInstalled );
       
   322     CleanupStack::PushL( iterator );
       
   323     
       
   324     SwiUI::CommonUI::CCUIDetailsDialog* details = SwiUI::CommonUI::CCUIDetailsDialog::NewL();
       
   325     FLOG( "CAppMngr2SisxAppInfo::ShowDetailsL, isDRM %d, noRightsObj %d, CertCount %d",
       
   326             iIsDRMProtected, iIsRightsObjectMissingOrExpired, iCertificates.Count() );
       
   327     
       
   328     if( iIsDRMProtected && !iIsRightsObjectMissingOrExpired )
       
   329         {
       
   330         RFile fileHandle;
       
   331         TInt err = fileHandle.Open( iFs, *iProtectedFile, EFileShareReadersOnly | EFileRead );
       
   332         CleanupClosePushL( fileHandle );
       
   333         
       
   334         if( iCertificates.Count() )
       
   335             {
       
   336             details->ExecuteLD( *iterator, iCertificates, fileHandle );
       
   337             }
       
   338         else
       
   339             {
       
   340             details->ExecuteLD( *iterator, fileHandle );
       
   341             }
       
   342 
       
   343         CleanupStack::PopAndDestroy( &fileHandle );
       
   344         }
       
   345     else
       
   346         {
       
   347         if( iCertificates.Count() )
       
   348             {
       
   349             details->ExecuteLD( *iterator, iCertificates );
       
   350             }
       
   351         else
       
   352             {
       
   353             details->ExecuteLD( *iterator );
       
   354             }
       
   355         }
       
   356     
       
   357     CleanupStack::PopAndDestroy( iterator );
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // CAppMngr2SisxAppInfo::ReadCertificatesL()
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CAppMngr2SisxAppInfo::ReadCertificatesL()
       
   365     {
       
   366     if( !iCertsRead )
       
   367         {
       
   368         FLOG_PERF_STATIC_BEGIN( SisxAppInfo_ReadCerts );
       
   369         
       
   370         Swi::RSisRegistrySession regSession;
       
   371         CleanupClosePushL( regSession );
       
   372         User::LeaveIfError( regSession.Connect() );
       
   373 
       
   374         Swi::RSisRegistryEntry entry;
       
   375         CleanupClosePushL( entry );
       
   376         TInt err = entry.Open( regSession, iAppUid );
       
   377         if( err != KErrNotFound )
       
   378             {
       
   379             User::LeaveIfError( err );
       
   380             }
       
   381         RPointerArray<HBufC8> certificateChain;
       
   382         CleanupResetAndDestroyPushL( certificateChain );
       
   383         if( err == KErrNone )
       
   384             {
       
   385             entry.CertificateChainsL( certificateChain );
       
   386             }
       
   387 
       
   388         TInt certCount = certificateChain.Count();
       
   389         for( TInt index = 0; index < certCount; index++ )
       
   390             {
       
   391             CX509Certificate* cert = CX509Certificate::NewL( *certificateChain[ index ] );
       
   392             CleanupStack::PushL( cert );
       
   393             SwiUI::CommonUI::CCUICertificateInfo* certInfo =
       
   394                 SwiUI::CommonUI::CCUICertificateInfo::NewL( *cert );
       
   395             CleanupStack::PopAndDestroy( cert );
       
   396             iCertificates.AppendL( certInfo );
       
   397             }
       
   398 
       
   399         CleanupStack::PopAndDestroy( &certificateChain );
       
   400         CleanupStack::PopAndDestroy( &entry );
       
   401         CleanupStack::PopAndDestroy( &regSession );
       
   402         iCertsRead = ETrue;
       
   403         
       
   404         FLOG_PERF_STATIC_END( SisxAppInfo_ReadCerts )
       
   405         }
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CAppMngr2SisxAppInfo::HandleUninstallL()
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 void CAppMngr2SisxAppInfo::HandleUninstallL( TRequestStatus& aStatus )
       
   413     {
       
   414     FLOG( "CAppMngr2SisxAppInfo::HandleUninstallL()" );
       
   415     if( !iSWInstLauncher )
       
   416         {
       
   417         SwiUI::RSWInstLauncher* swInstLauncher = new (ELeave) SwiUI::RSWInstLauncher;
       
   418         CleanupStack::PushL( swInstLauncher );
       
   419         User::LeaveIfError( swInstLauncher->Connect() );
       
   420         CleanupStack::Pop( swInstLauncher );
       
   421         iSWInstLauncher = swInstLauncher;
       
   422         }
       
   423     else
       
   424         {
       
   425         User::Leave( KErrInUse );
       
   426         }
       
   427     
       
   428     if( iIsAugmentation )
       
   429         {
       
   430         FLOG( "CAppMngr2SisxAppInfo::HandleUninstallL, is augmentation" );
       
   431         SwiUI::TOpUninstallIndexParam params;
       
   432         params.iUid = iAppUid;
       
   433         params.iIndex = iAugmentationIndex;
       
   434         
       
   435         SwiUI::TOpUninstallIndexParamPckg pckg( params );
       
   436         if( iSWInstLauncherCustomUninstallParams )
       
   437             {
       
   438             delete iSWInstLauncherCustomUninstallParams;
       
   439             iSWInstLauncherCustomUninstallParams = NULL;
       
   440             }
       
   441         TInt length = pckg.Length();
       
   442         iSWInstLauncherCustomUninstallParams = HBufC8::NewL( length );
       
   443         *iSWInstLauncherCustomUninstallParams = pckg;
       
   444 
       
   445         FLOG( "CAppMngr2SisxAppInfo::HandleUninstallL, calling CustomUninstall" );
       
   446         iSWInstLauncher->CustomUninstall( aStatus, SwiUI::EOperationUninstallIndex,
       
   447                 *iSWInstLauncherCustomUninstallParams, SwiUI::KSisxMimeType() );
       
   448         }
       
   449     else
       
   450         {
       
   451         FLOG( "CAppMngr2SisxAppInfo::HandleUninstallL, calling Uninstall" );
       
   452         iSWInstLauncher->Uninstall( aStatus, iAppUid, SwiUI::KSisxMimeType() );
       
   453         }
       
   454     }
       
   455