appinstaller/AppinstUi/sisxsifplugin/src/sisxsifpluginactiveimpl.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 /*
       
     2 * Copyright (c) 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: Native SISX SIF (Software Install Framework) plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "sisxsifpluginactiveimpl.h"        // CSisxSifPluginActiveImpl
       
    19 #include "sisxsifpluginuihandlerbase.h"     // CSisxSifPluginUiHandlerBase
       
    20 #include "sisxsifpluginuihandler.h"         // CSisxSifPluginUiHandler
       
    21 #include "sisxsifpluginuihandlersilent.h"   // CSisxSifPluginUiHandlerSilent
       
    22 #include "sisxsifplugininstallparams.h"     // CSisxSifPluginInstallParams
       
    23 #include "sisxsifpluginerrorhandler.h"      // CSisxSifPluginErrorHandler
       
    24 #include "sisxsifcleanuputils.h"            // CleanupResetAndDestroyPushL
       
    25 #include "sisxsifpluginerrors.h"            // Error codes
       
    26 #include "sisxsifplugin.pan"                // Panic codes
       
    27 #include <usif/sif/sifcommon.h>             // Usif::CComponentInfo
       
    28 #include <usif/scr/scr.h>                   // RSoftwareComponentRegistry
       
    29 #include <swi/asynclauncher.h>              // Swi::CAsyncLauncher
       
    30 #include <swi/sisregistrysession.h>         // RSisRegistrySession
       
    31 #include "sisregistrywritablesession.h"     // RSisRegistryWritableSession
       
    32 #include <e32property.h>                    // RProperty
       
    33 #include <centralrepository.h>              // CRepository
       
    34 #include <sacls.h>                          // KUidSwiLatestInstallation
       
    35 #include <SWInstallerInternalCRKeys.h>      // KCRUidSWInstallerSettings
       
    36 #include <featmgr.h>                        // FeatureManager
       
    37 #include <syslangutil.h>                    // GetInstalledLanguages
       
    38 
       
    39 // TODO: replace with proper logging
       
    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 using namespace Usif;
       
    53 
       
    54 _LIT( KCompUid, "CompUid" );
       
    55 _LIT( KStartupListUpdaterExecutable, "z:\\sys\\bin\\startuplistupdater.exe" );
       
    56 _LIT( KStartupListUpdaterName, "StartupListUpdater" );
       
    57 
       
    58 
       
    59 // ======== MEMBER FUNCTIONS ========
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CSisxSifPluginActiveImpl::NewL()
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CSisxSifPluginActiveImpl* CSisxSifPluginActiveImpl::NewL()
       
    66     {
       
    67     FLOG( _L("Constructing CSisxSifPluginActiveImpl") );
       
    68     CSisxSifPluginActiveImpl *self = new( ELeave ) CSisxSifPluginActiveImpl;
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CSisxSifPluginActiveImpl::~CSisxSifPluginActiveImpl()
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CSisxSifPluginActiveImpl::~CSisxSifPluginActiveImpl()
       
    80     {
       
    81     FLOG( _L("Destructing CSisxSifPluginActiveImpl") );
       
    82     Cancel();
       
    83     delete iAsyncLauncher;
       
    84     delete iUiHandler;
       
    85     delete iInstallPrefs;
       
    86     iDeviceSupportedLanguages.Reset();
       
    87     iInputParams = NULL;    // not owned
       
    88     iOutputParams = NULL;   // not owned
       
    89     delete iInstallParams;
       
    90     delete iComponentInfo;
       
    91     delete iFileName;
       
    92     delete iErrorHandler;
       
    93     FeatureManager::UnInitializeLib();
       
    94     iFs.Close();
       
    95     }
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CSisxSifPluginActiveImpl::DoCancel()
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CSisxSifPluginActiveImpl::DoCancel()
       
   102     {
       
   103     FLOG( _L("CSisxSifPluginActiveImpl::DoCancel") );
       
   104 
       
   105     if( iClientStatus )
       
   106         {
       
   107         if( iAsyncLauncher )
       
   108             {
       
   109             iAsyncLauncher->CancelOperation();
       
   110             delete iAsyncLauncher;
       
   111             iAsyncLauncher = NULL;
       
   112             }
       
   113 
       
   114         CompleteClientRequest( KErrCancel );
       
   115         }
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CSisxSifPluginActiveImpl::RunL()
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CSisxSifPluginActiveImpl::RunL()
       
   123     {
       
   124     FLOG_3( _L("CSisxSifPluginActiveImpl::RunL(), operation %d, phase %d, result %d"),
       
   125             iOperation, iPhase, iStatus.Int() );
       
   126 
       
   127     User::LeaveIfError( iStatus.Int() );
       
   128     switch( iOperation )
       
   129         {
       
   130         case EGetComponentInfo:
       
   131             __ASSERT_DEBUG( iPhase == ERunningOperation, Panic( ESisxSifInternalError ) );
       
   132             CompleteClientRequest( KErrNone );
       
   133             break;
       
   134 
       
   135         case EInstall:
       
   136             switch( iPhase )
       
   137                 {
       
   138                 case EPreprocessing:
       
   139                     if( IsSilentMode() )
       
   140                         {
       
   141                         StartSilentInstallingL();
       
   142                         }
       
   143                     else
       
   144                         {
       
   145                         StartInstallingL();
       
   146                         }
       
   147                     break;
       
   148 
       
   149                 case ERunningOperation:
       
   150                     FinalizeInstallationL();
       
   151                     CompleteClientRequest( KErrNone );
       
   152                     break;
       
   153 
       
   154 				// TODO: KSifInParam_InstallInactive
       
   155 
       
   156                 default:
       
   157                     Panic( ESisxSifInternalError );
       
   158                     break;
       
   159                 }
       
   160             break;
       
   161 
       
   162         case EUninstall:
       
   163             __ASSERT_DEBUG( iPhase == ERunningOperation, Panic( ESisxSifInternalError ) );
       
   164             UpdateStartupListL();
       
   165             iUiHandler->PublishCompletionL();
       
   166             CompleteClientRequest( KErrNone );
       
   167             break;
       
   168 
       
   169         case EActivate:
       
   170         case EDeactivate:
       
   171             __ASSERT_DEBUG( iPhase == ERunningOperation, Panic( ESisxSifInternalError ) );
       
   172             CompleteClientRequest( KErrNone );
       
   173             break;
       
   174 
       
   175         default:
       
   176             Panic( ESisxSifInternalError );
       
   177             break;
       
   178         }
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CSisxSifPluginActiveImpl::RunError()
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 TInt CSisxSifPluginActiveImpl::RunError( TInt aError )
       
   186     {
       
   187     FLOG_1( _L("CSisxSifPluginActiveImpl::RunError(), aError %d"), aError );
       
   188 
       
   189     TRAP_IGNORE( DoHandleErrorL( aError ) );
       
   190     CompleteClientRequest( aError );
       
   191     return KErrNone;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CSisxSifPluginActiveImpl::GetComponentInfo()
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CSisxSifPluginActiveImpl::GetComponentInfo(
       
   199         const TDesC& aFileName,
       
   200         const TSecurityContext& /*aSecurityContext*/,
       
   201         CComponentInfo& aComponentInfo,
       
   202         TRequestStatus& aStatus )
       
   203     {
       
   204     FLOG_1( _L("CSisxSifPluginActiveImpl::GetComponentInfo: %S"), &aFileName );
       
   205 
       
   206     if( IsActive() )
       
   207         {
       
   208         FLOG( _L("CSisxSifPluginActiveImpl::GetComponentInfo, KErrInUse") );
       
   209         CompleteClientRequest( KErrInUse );
       
   210         return;
       
   211         }
       
   212 
       
   213     TRAPD( error, SetFileL( aFileName ) );
       
   214     if( error )
       
   215         {
       
   216         FLOG_1( _L("CSisxSifPluginActiveImpl::GetComponentInfo, set file error %d"), error );
       
   217         CompleteClientRequest( error );
       
   218         return;
       
   219         }
       
   220 
       
   221     TRAP( error, DoGetComponentInfoL( aComponentInfo, aStatus ) );
       
   222 	if( error )
       
   223 		{
       
   224 		FLOG_1( _L("CSisxSifPluginActiveImpl::GetComponentInfo ERROR %d"), error );
       
   225 		CompleteClientRequest( error );
       
   226 		}
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CSisxSifPluginActiveImpl::GetComponentInfo()
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CSisxSifPluginActiveImpl::GetComponentInfo(
       
   234         RFile& aFileHandle,
       
   235         const TSecurityContext& /*aSecurityContext*/,
       
   236         CComponentInfo& aComponentInfo,
       
   237         TRequestStatus& aStatus )
       
   238     {
       
   239     FLOG( _L("CSisxSifPluginActiveImpl::GetComponentInfo(RFile)") );
       
   240 
       
   241     if( IsActive() )
       
   242         {
       
   243         FLOG( _L("CSisxSifPluginActiveImpl::GetComponentInfo, KErrInUse") );
       
   244         CompleteClientRequest( KErrInUse );
       
   245         return;
       
   246         }
       
   247 
       
   248     SetFile( aFileHandle );
       
   249 
       
   250 	TRAPD( error, DoGetComponentInfoL( aComponentInfo, aStatus ) );
       
   251 	if( error )
       
   252 		{
       
   253 		FLOG_1( _L("CSisxSifPluginActiveImpl::GetComponentInfo ERROR %d"), error );
       
   254 		CompleteClientRequest( error );
       
   255 		}
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // CSisxSifPluginActiveImpl::Install()
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CSisxSifPluginActiveImpl::Install(
       
   263         const TDesC& aFileName,
       
   264         const TSecurityContext& aSecurityContext,
       
   265         const COpaqueNamedParams& aInputParams,
       
   266         COpaqueNamedParams& aOutputParams,
       
   267         TRequestStatus& aStatus )
       
   268     {
       
   269     FLOG_1( _L("CSisxSifPluginActiveImpl::Install: %S"), &aFileName );
       
   270 
       
   271     if( IsActive() )
       
   272         {
       
   273 		FLOG( _L("CSisxSifPluginActiveImpl::Install, KErrInUse") );
       
   274 		CompleteClientRequest( KErrInUse );
       
   275 		return;
       
   276 		}
       
   277 
       
   278     iHasAllFilesCapability = aSecurityContext.HasCapability( ECapabilityAllFiles );
       
   279 
       
   280 	TRAPD( error, SetFileL( aFileName ) );
       
   281 	if( error )
       
   282 		{
       
   283 		FLOG_1( _L("CSisxSifPluginActiveImpl::Install, set file error %d"), error );
       
   284 		CompleteClientRequest( error );
       
   285 		return;
       
   286 		}
       
   287 
       
   288 	TRAP( error, DoInstallL( aSecurityContext, aInputParams, aOutputParams, aStatus ) );
       
   289 	if( error )
       
   290 		{
       
   291 		FLOG_1( _L("CSisxSifPluginActiveImpl::Install, DoInstallL error %d"), error );
       
   292 		CompleteClientRequest( error );
       
   293 		}
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // CSisxSifPluginActiveImpl::Install()
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 void CSisxSifPluginActiveImpl::Install(
       
   301         RFile& aFileHandle,
       
   302         const TSecurityContext& aSecurityContext,
       
   303         const COpaqueNamedParams& aInputParams,
       
   304         COpaqueNamedParams& aOutputParams,
       
   305         TRequestStatus& aStatus )
       
   306     {
       
   307     FLOG( _L("CSisxSifPluginActiveImpl::Install(RFile)") );
       
   308 
       
   309     if( IsActive() )
       
   310         {
       
   311 		FLOG( _L("CSisxSifPluginActiveImpl::Install KErrInUse") );
       
   312 		CompleteClientRequest( KErrInUse );
       
   313 		return;
       
   314 		}
       
   315 
       
   316     iHasAllFilesCapability = aSecurityContext.HasCapability( ECapabilityAllFiles );
       
   317 
       
   318     SetFile( aFileHandle );
       
   319 
       
   320     TRAPD( error, DoInstallL( aSecurityContext, aInputParams, aOutputParams, aStatus ) );
       
   321     if( error )
       
   322         {
       
   323         FLOG_1( _L("CSisxSifPluginActiveImpl::Install, DoInstallL error %d"), error );
       
   324         CompleteClientRequest( error );
       
   325         }
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // CSisxSifPluginActiveImpl::Uninstall()
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CSisxSifPluginActiveImpl::Uninstall(
       
   333         TComponentId aComponentId,
       
   334         const TSecurityContext& aSecurityContext,
       
   335         const COpaqueNamedParams& aInputParams,
       
   336         COpaqueNamedParams& aOutputParams,
       
   337         TRequestStatus& aStatus )
       
   338     {
       
   339     FLOG_1( _L("CSisxSifPluginActiveImpl::Uninstall, aComponentId %d"), aComponentId );
       
   340 
       
   341     if( IsActive() )
       
   342         {
       
   343         FLOG( _L("CSisxSifPluginActiveImpl::Uninstall KErrInUse") );
       
   344         CompleteClientRequest( KErrInUse );
       
   345         return;
       
   346         }
       
   347 
       
   348     iHasAllFilesCapability = aSecurityContext.HasCapability( ECapabilityAllFiles );
       
   349 
       
   350     // Uninstall is always silent. TrustedUI capability is required.
       
   351 	if( !aSecurityContext.HasCapability( ECapabilityTrustedUI ) )
       
   352 		{
       
   353 		FLOG( _L( "CSisxSifPluginActiveImpl::Uninstall, missing ECapabilityTrustedUI") );
       
   354 		iErrorHandler->SetExtendedErrorCode( ESifUiTrustedUICapabilityRequired );
       
   355 		CompleteClientRequest( KErrPermissionDenied );
       
   356 		return;
       
   357 		}
       
   358 
       
   359 	TRAPD( error, DoUninstallL( aComponentId, aInputParams, aOutputParams, aStatus ) );
       
   360 	if( error )
       
   361 		{
       
   362 		FLOG_1( _L("CSisxSifPluginActiveImpl::Uninstall, DoUninstallL ERROR %d"), error );
       
   363 		CompleteClientRequest( error );
       
   364 		}
       
   365     }
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // CSisxSifPluginActiveImpl::Activate()
       
   369 // ---------------------------------------------------------------------------
       
   370 //
       
   371 void CSisxSifPluginActiveImpl::Activate(
       
   372         TComponentId aComponentId,
       
   373         const TSecurityContext& aSecurityContext,
       
   374         TRequestStatus& aStatus )
       
   375     {
       
   376     FLOG_1( _L("CSisxSifPluginActiveImpl::Activate, aComponentId %d"), aComponentId );
       
   377 
       
   378     if( IsActive() )
       
   379         {
       
   380         FLOG( _L("CSisxSifPluginActiveImpl::Activate KErrInUse") );
       
   381         CompleteClientRequest( KErrInUse );
       
   382         return;
       
   383         }
       
   384 
       
   385     iHasAllFilesCapability = aSecurityContext.HasCapability( ECapabilityAllFiles );
       
   386 
       
   387     TRAPD( error, DoActivateL( aComponentId, aStatus ) );
       
   388     if( error )
       
   389         {
       
   390         FLOG_1( _L("CSisxSifPluginActiveImpl::Activate, DoActivateL ERROR %d"), error );
       
   391         CompleteClientRequest( error );
       
   392         }
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------------------------
       
   396 // CSisxSifPluginActiveImpl::Deactivate()
       
   397 // ---------------------------------------------------------------------------
       
   398 //
       
   399 void CSisxSifPluginActiveImpl::Deactivate(
       
   400         TComponentId aComponentId,
       
   401         const TSecurityContext& aSecurityContext,
       
   402         TRequestStatus& aStatus )
       
   403     {
       
   404     FLOG_1( _L("CSisxSifPluginActiveImpl::Deactivate, aComponentId %d"), aComponentId );
       
   405 
       
   406     if( IsActive() )
       
   407         {
       
   408         FLOG( _L("CSisxSifPluginActiveImpl::Deactivate KErrInUse") );
       
   409         CompleteClientRequest( KErrInUse );
       
   410         return;
       
   411         }
       
   412 
       
   413     iHasAllFilesCapability = aSecurityContext.HasCapability( ECapabilityAllFiles );
       
   414 
       
   415     TRAPD( error, DoDeactivateL( aComponentId, aStatus ) );
       
   416     if( error )
       
   417         {
       
   418         FLOG_1( _L("CSisxSifPluginActiveImpl::Deactivate, DoDeactivateL ERROR %d"), error );
       
   419         CompleteClientRequest( error );
       
   420         }
       
   421     }
       
   422 
       
   423 // ---------------------------------------------------------------------------
       
   424 // CSisxSifPluginActiveImpl::CSisxSifPluginActiveImpl()
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 CSisxSifPluginActiveImpl::CSisxSifPluginActiveImpl() : CActive( CActive::EPriorityStandard )
       
   428     {
       
   429     CActiveScheduler::Add( this );
       
   430     }
       
   431 
       
   432 // ---------------------------------------------------------------------------
       
   433 // CSisxSifPluginActiveImpl::ConstructL()
       
   434 // ---------------------------------------------------------------------------
       
   435 //
       
   436 void CSisxSifPluginActiveImpl::ConstructL()
       
   437     {
       
   438     User::LeaveIfError( iFs.Connect() );
       
   439     FeatureManager::InitializeLibL();
       
   440 
       
   441     iAsyncLauncher = Swi::CAsyncLauncher::NewL();
       
   442     iInstallPrefs = Swi::CInstallPrefs::NewL();
       
   443     iComponentInfo = CComponentInfo::NewL();
       
   444     iErrorHandler = CSisxSifPluginErrorHandler::NewL();
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // CSisxSifPluginActiveImpl::CommonRequestPreambleL()
       
   449 // ---------------------------------------------------------------------------
       
   450 //
       
   451 void CSisxSifPluginActiveImpl::CommonRequestPreambleL( TRequestStatus& aStatus )
       
   452     {
       
   453     aStatus = KRequestPending;
       
   454     iClientStatus = &aStatus;
       
   455 
       
   456     if( iInstallParams )
       
   457         {
       
   458         delete iInstallParams;
       
   459         iInstallParams = NULL;
       
   460         }
       
   461     CreateUiHandlerL();
       
   462 
       
   463     iInputParams = NULL;
       
   464     iOutputParams = NULL;
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // CSisxSifPluginActiveImpl::CommonRequestPreambleL()
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 void CSisxSifPluginActiveImpl::CommonRequestPreambleL(
       
   472         const COpaqueNamedParams& aInputParams,
       
   473         COpaqueNamedParams& aOutputParams,
       
   474         TRequestStatus& aStatus )
       
   475     {
       
   476     aStatus = KRequestPending;
       
   477     iClientStatus = &aStatus;
       
   478 
       
   479     if( iInstallParams )
       
   480         {
       
   481         delete iInstallParams;
       
   482         iInstallParams = NULL;
       
   483         }
       
   484     iInstallParams = CSisxSifPluginInstallParams::NewL( aInputParams );
       
   485     CreateUiHandlerL();
       
   486 
       
   487     iInputParams = &aInputParams;
       
   488     iOutputParams = &aOutputParams;
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CSisxSifPluginActiveImpl::CompleteSelf()
       
   493 // ---------------------------------------------------------------------------
       
   494 //
       
   495 void CSisxSifPluginActiveImpl::CompleteSelf( TInt aResult )
       
   496     {
       
   497     iStatus = KRequestPending;
       
   498     TRequestStatus* status = &iStatus;
       
   499     User::RequestComplete( status, aResult );
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // CSisxSifPluginActiveImpl::CreateUiHandlerL()
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 void CSisxSifPluginActiveImpl::CreateUiHandlerL()
       
   507     {
       
   508     if( iUiHandler )
       
   509     	{
       
   510 		delete iUiHandler;
       
   511 		iUiHandler = NULL;
       
   512     	}
       
   513 	if( IsSilentMode() )
       
   514 		{
       
   515 		iUiHandler = CSisxSifPluginUiHandlerSilent::NewL( iFs, *iErrorHandler );
       
   516 		}
       
   517 	else
       
   518 		{
       
   519 		iUiHandler = CSisxSifPluginUiHandler::NewL( iFs, *iErrorHandler );
       
   520 		}
       
   521 	if( iInstallParams )
       
   522 		{
       
   523 		iUiHandler->SetInstallParamsL( *iInstallParams );
       
   524 		}
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // CSisxSifPluginActiveImpl::IsSilentMode()
       
   529 // ---------------------------------------------------------------------------
       
   530 //
       
   531 TBool CSisxSifPluginActiveImpl::IsSilentMode()
       
   532 	{
       
   533 	return( iInstallParams && iInstallParams->IsSilentMode() );
       
   534 	}
       
   535 
       
   536 // ---------------------------------------------------------------------------
       
   537 // CSisxSifPluginActiveImpl::CompleteClientRequest()
       
   538 // ---------------------------------------------------------------------------
       
   539 //
       
   540 void CSisxSifPluginActiveImpl::CompleteClientRequest( TInt aResult )
       
   541     {
       
   542     if( iClientStatus )
       
   543         {
       
   544         User::RequestComplete( iClientStatus, aResult );
       
   545         iClientStatus = NULL;
       
   546         }
       
   547     __ASSERT_DEBUG( !IsActive(), Panic( ESisxSifInternalError ) );
       
   548     iOperation = ENoOperation;
       
   549     iPhase = ENotActive;
       
   550     }
       
   551 
       
   552 // ---------------------------------------------------------------------------
       
   553 // CSisxSifPluginActiveImpl::DoGetComponentInfoL()
       
   554 // ---------------------------------------------------------------------------
       
   555 //
       
   556 void CSisxSifPluginActiveImpl::DoGetComponentInfoL( CComponentInfo& aComponentInfo,
       
   557 		TRequestStatus& aStatus )
       
   558 	{
       
   559 	CommonRequestPreambleL( aStatus );
       
   560 
       
   561 	if( iFileName )
       
   562 		{
       
   563 		iAsyncLauncher->GetComponentInfoL( *iUiHandler, *iFileName, *iInstallPrefs,
       
   564 				aComponentInfo, iStatus );
       
   565 		}
       
   566 	else if( iFileHandle )
       
   567 		{
       
   568 		iAsyncLauncher->GetComponentInfoL( *iUiHandler, *iFileHandle, *iInstallPrefs,
       
   569 				aComponentInfo, iStatus );
       
   570 		}
       
   571 	else
       
   572 		{
       
   573 		User::Leave( KErrGeneral );
       
   574 		}
       
   575 
       
   576     iOperation = EGetComponentInfo;
       
   577     iPhase = ERunningOperation;
       
   578     SetActive();
       
   579 	}
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // CSisxSifPluginActiveImpl::DoInstallL()
       
   583 // ---------------------------------------------------------------------------
       
   584 //
       
   585 void CSisxSifPluginActiveImpl::DoInstallL( const TSecurityContext& aSecurityContext,
       
   586 		const COpaqueNamedParams& aInputParams, COpaqueNamedParams& aOutputParams,
       
   587 		TRequestStatus& aStatus )
       
   588 	{
       
   589     CommonRequestPreambleL( aInputParams, aOutputParams, aStatus );
       
   590     FLOG_1( _L("CSisxSifPluginActiveImpl::DoInstall, IsSilentMode=%d"), IsSilentMode() );
       
   591 
       
   592     if( IsSilentMode() )
       
   593         {
       
   594         if( !aSecurityContext.HasCapability( ECapabilityTrustedUI ) )
       
   595             {
       
   596             FLOG( _L("CSisxSifPluginActiveImpl::Install, missing ECapabilityTrustedUI") );
       
   597             iErrorHandler->SetExtendedErrorCode( ESifUiTrustedUICapabilityRequired );
       
   598             CompleteClientRequest( KErrPermissionDenied );
       
   599             return;
       
   600             }
       
   601         }
       
   602 
       
   603     if( iFileName )
       
   604         {
       
   605         iUiHandler->DisplayPreparingInstallL( *iFileName );
       
   606         iAsyncLauncher->GetComponentInfoL( *iUiHandler, *iFileName, *iInstallPrefs,
       
   607                 *iComponentInfo, iStatus );
       
   608         }
       
   609     else if( iFileHandle )
       
   610         {
       
   611         TFileName fileName;
       
   612         iFileHandle->Name( fileName );
       
   613         iUiHandler->DisplayPreparingInstallL( fileName );
       
   614         iAsyncLauncher->GetComponentInfoL( *iUiHandler, *iFileHandle, *iInstallPrefs,
       
   615                 *iComponentInfo, iStatus );
       
   616         }
       
   617     else
       
   618         {
       
   619         User::Leave( KErrGeneral );
       
   620         }
       
   621 
       
   622     iOperation = EInstall;
       
   623     iPhase = EPreprocessing;
       
   624     SetActive();
       
   625 	}
       
   626 
       
   627 // ---------------------------------------------------------------------------
       
   628 // CSisxSifPluginActiveImpl::DoUninstallL()
       
   629 // ---------------------------------------------------------------------------
       
   630 //
       
   631 void CSisxSifPluginActiveImpl::DoUninstallL( TComponentId aComponentId,
       
   632 		const COpaqueNamedParams& aInputParams, COpaqueNamedParams& aOutputParams,
       
   633 		TRequestStatus& aStatus )
       
   634     {
       
   635     CommonRequestPreambleL( aInputParams, aOutputParams, aStatus );
       
   636 
       
   637     TUid uid;
       
   638     CComponentEntry *entry = CComponentEntry::NewLC();
       
   639     GetComponentAndUidL( aComponentId, *entry, uid );
       
   640     iUiHandler->PublishStartL( *entry );
       
   641     CleanupStack::PopAndDestroy( entry );
       
   642 
       
   643     iAsyncLauncher->UninstallL( *iUiHandler, uid, iStatus );
       
   644 
       
   645     iOperation = EUninstall;
       
   646     iPhase = ERunningOperation;
       
   647     SetActive();
       
   648     }
       
   649 
       
   650 // ---------------------------------------------------------------------------
       
   651 // CSisxSifPluginActiveImpl::DoActivateL()
       
   652 // ---------------------------------------------------------------------------
       
   653 //
       
   654 void CSisxSifPluginActiveImpl::DoActivateL( TComponentId aComponentId,
       
   655         TRequestStatus& aStatus )
       
   656     {
       
   657     CommonRequestPreambleL( aStatus );
       
   658 
       
   659     Swi::RSisRegistryWritableSession sisRegSession;
       
   660     User::LeaveIfError( sisRegSession.Connect() );
       
   661     CleanupClosePushL( sisRegSession );
       
   662     sisRegSession.ActivateComponentL( aComponentId );
       
   663     CleanupStack::PopAndDestroy( &sisRegSession );
       
   664 
       
   665     CompleteSelf( KErrNone );
       
   666 
       
   667     iOperation = EActivate;
       
   668     iPhase = ERunningOperation;
       
   669     SetActive();
       
   670     }
       
   671 
       
   672 // ---------------------------------------------------------------------------
       
   673 // CSisxSifPluginActiveImpl::DoDeactivateL()
       
   674 // ---------------------------------------------------------------------------
       
   675 //
       
   676 void CSisxSifPluginActiveImpl::DoDeactivateL( TComponentId aComponentId,
       
   677         TRequestStatus& aStatus )
       
   678     {
       
   679     CommonRequestPreambleL( aStatus );
       
   680 
       
   681     Swi::RSisRegistryWritableSession sisRegSession;
       
   682     User::LeaveIfError( sisRegSession.Connect() );
       
   683     CleanupClosePushL( sisRegSession );
       
   684     sisRegSession.DeactivateComponentL( aComponentId );
       
   685     CleanupStack::PopAndDestroy( &sisRegSession );
       
   686 
       
   687     CompleteSelf( KErrNone );
       
   688 
       
   689     iOperation = EDeactivate;
       
   690     iPhase = ERunningOperation;
       
   691     SetActive();
       
   692     }
       
   693 
       
   694 // ---------------------------------------------------------------------------
       
   695 // CSisxSifPluginActiveImpl::DoHandleErrorL()
       
   696 // ---------------------------------------------------------------------------
       
   697 //
       
   698 void CSisxSifPluginActiveImpl::DoHandleErrorL( TInt aError )
       
   699     {
       
   700     FLOG_1( _L("CSisxSifPluginActiveImpl::DoHandleErrorL(), aError=%d"), aError );
       
   701 
       
   702     iErrorHandler->SetErrorCode( aError );
       
   703     if( iOutputParams )
       
   704         {
       
   705         iErrorHandler->FillOutputParamsL( *iOutputParams );
       
   706         }
       
   707     iUiHandler->PublishCompletionL();
       
   708 
       
   709     if( aError != KErrNone && aError != KErrCancel )
       
   710         {
       
   711         iUiHandler->DisplayFailedL( *iErrorHandler );
       
   712         }
       
   713     }
       
   714 
       
   715 // ---------------------------------------------------------------------------
       
   716 // CSisxSifPluginActiveImpl::SetFileL()
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 void CSisxSifPluginActiveImpl::SetFileL( const TDesC& aFileName )
       
   720     {
       
   721     if( iFileName )
       
   722         {
       
   723         delete iFileName;
       
   724         iFileName = NULL;
       
   725         }
       
   726     iFileName = aFileName.AllocL();
       
   727     iFileHandle = NULL;
       
   728     }
       
   729 
       
   730 // ---------------------------------------------------------------------------
       
   731 // CSisxSifPluginActiveImpl::SetFile()
       
   732 // ---------------------------------------------------------------------------
       
   733 //
       
   734 void CSisxSifPluginActiveImpl::SetFile( RFile& aFileHandle )
       
   735     {
       
   736     if( iFileName )
       
   737         {
       
   738         delete iFileName;
       
   739         iFileName = NULL;
       
   740         }
       
   741     iFileHandle = &aFileHandle;
       
   742     }
       
   743 
       
   744 // ---------------------------------------------------------------------------
       
   745 // CSisxSifPluginActiveImpl::GetLastInstalledComponentIdL()
       
   746 // ---------------------------------------------------------------------------
       
   747 //
       
   748 TComponentId CSisxSifPluginActiveImpl::GetLastInstalledComponentIdL()
       
   749     {
       
   750     __ASSERT_DEBUG( iOperation == EInstall, Panic( ESisxSifInternalError ) );
       
   751 
       
   752     // Find the id of the last installed component and return it
       
   753     TInt uid;
       
   754     User::LeaveIfError( RProperty::Get( KUidSystemCategory, KUidSwiLatestInstallation, uid ) );
       
   755 
       
   756     Swi::RSisRegistrySession sisRegistrySession;
       
   757     User::LeaveIfError( sisRegistrySession.Connect() );
       
   758     CleanupClosePushL( sisRegistrySession );
       
   759 
       
   760     TUid tuid( TUid::Uid( uid ) );
       
   761     TComponentId componentId = sisRegistrySession.GetComponentIdForUidL( tuid );
       
   762     CleanupStack::PopAndDestroy( &sisRegistrySession );
       
   763 
       
   764     return componentId;
       
   765     }
       
   766 
       
   767 // ---------------------------------------------------------------------------
       
   768 // CSisxSifPluginActiveImpl::GetComponentAndUidL()
       
   769 // ---------------------------------------------------------------------------
       
   770 //
       
   771 void CSisxSifPluginActiveImpl::GetComponentAndUidL( TComponentId aComponentId,
       
   772         CComponentEntry& aEntry, TUid& aUid ) const
       
   773     {
       
   774     FLOG_1( _L("CSisxSifPluginActiveImpl::GetComponentAndUidL, component %d"), aComponentId );
       
   775 
       
   776     RSoftwareComponentRegistry scrSession;
       
   777     User::LeaveIfError( scrSession.Connect() );
       
   778     CleanupClosePushL( scrSession );
       
   779 
       
   780     if( scrSession.GetComponentL( aComponentId, aEntry ) )
       
   781         {
       
   782         FLOG( _L("CSisxSifPluginActiveImpl::GetComponentAndUidL, entry found") );
       
   783 
       
   784         CPropertyEntry* propertyEntry = scrSession.GetComponentPropertyL( aComponentId, KCompUid );
       
   785         CleanupStack::PushL( propertyEntry );
       
   786 
       
   787         CIntPropertyEntry* intPropertyEntry = dynamic_cast< CIntPropertyEntry* >( propertyEntry );
       
   788         if( !intPropertyEntry )
       
   789             {
       
   790             FLOG( _L("CSisxSifPluginActiveImpl::GetComponentUidL, UID property not found") );
       
   791             User::Leave( KErrNotFound );
       
   792             }
       
   793         aUid = TUid::Uid( intPropertyEntry->IntValue() );
       
   794 
       
   795         CleanupStack::PopAndDestroy( propertyEntry );
       
   796         }
       
   797     else
       
   798         {
       
   799         FLOG( _L("CSisxSifPluginActiveImpl::GetComponentAndUidL, entry not found") );
       
   800         User::Leave( KErrNotFound );
       
   801         }
       
   802 
       
   803     CleanupStack::PopAndDestroy( &scrSession );
       
   804     }
       
   805 
       
   806 // ---------------------------------------------------------------------------
       
   807 // CSisxSifPluginActiveImpl::RequiresUserCapabilityL()
       
   808 // ---------------------------------------------------------------------------
       
   809 //
       
   810 TBool CSisxSifPluginActiveImpl::RequiresUserCapabilityL(
       
   811         const CComponentInfo::CNode& aRootNode )
       
   812     {
       
   813     // Silent install is not allowed when the package requires additional capabilities
       
   814     // than what it is signed for (package may request for some capability that is not
       
   815     // granted by the certificate used to sign it).
       
   816     const TCapabilitySet& componentUserCaps( aRootNode.UserGrantableCaps() );
       
   817     for( TInt cap = 0; cap < ECapability_Limit; cap++ )
       
   818         {
       
   819         if( componentUserCaps.HasCapability( TCapability( cap ) ) )
       
   820             {
       
   821             FLOG_1( _L("CSisxSifPluginActiveImpl::RequiresUserCapabilityL - %d"), cap );
       
   822             return ETrue;
       
   823             }
       
   824         }
       
   825     return EFalse;
       
   826     }
       
   827 
       
   828 // ---------------------------------------------------------------------------
       
   829 // CSisxSifPluginActiveImpl::SetInstallPrefsRevocationServerUriL()
       
   830 // ---------------------------------------------------------------------------
       
   831 //
       
   832 void CSisxSifPluginActiveImpl::SetInstallPrefsRevocationServerUriL( const TDesC& aUri )
       
   833     {
       
   834     if( aUri.Length() )
       
   835         {
       
   836         HBufC8* uriBuf = HBufC8::NewLC( aUri.Length() );
       
   837         TPtr8 uri( uriBuf->Des() );
       
   838         uri.Copy( aUri );
       
   839         iInstallPrefs->SetRevocationServerUriL( uri );
       
   840         CleanupStack::PopAndDestroy( uriBuf );
       
   841         }
       
   842     else
       
   843         {
       
   844         iInstallPrefs->SetRevocationServerUriL( KNullDesC8 );
       
   845         }
       
   846     }
       
   847 
       
   848 // ---------------------------------------------------------------------------
       
   849 // CSisxSifPluginActiveImpl::UpdateInstallPrefsForPerformingOcspL()
       
   850 // ---------------------------------------------------------------------------
       
   851 //
       
   852 void CSisxSifPluginActiveImpl::UpdateInstallPrefsForPerformingOcspL()
       
   853     {
       
   854     if( IsSilentMode() )
       
   855         {
       
   856         TBool performOcsp( iInstallParams->PerformOCSP() != ENotAllowed );
       
   857         iInstallPrefs->SetPerformRevocationCheck( performOcsp );
       
   858 
       
   859         if( performOcsp )
       
   860             {
       
   861             SetInstallPrefsRevocationServerUriL( iInstallParams->OCSPUrl() );
       
   862             }
       
   863         }
       
   864     else
       
   865         {
       
   866         CRepository* cenRep = CRepository::NewLC( KCRUidSWInstallerSettings );
       
   867 
       
   868         TInt ocspProcedure = ESWInstallerOcspProcedureOff;
       
   869         (void)cenRep->Get( KSWInstallerOcspProcedure, ocspProcedure );
       
   870         TBool performOcsp( ocspProcedure != ESWInstallerOcspProcedureOff );
       
   871         iInstallPrefs->SetPerformRevocationCheck( performOcsp );
       
   872 
       
   873         if( performOcsp )
       
   874             {
       
   875             HBufC* ocspUrlBuf = HBufC::NewLC(
       
   876                     NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   877             TPtr ocspUrl( ocspUrlBuf->Des() );
       
   878             (void)cenRep->Get( KSWInstallerOcspDefaultURL, ocspUrl );
       
   879             SetInstallPrefsRevocationServerUriL( ocspUrl );
       
   880             CleanupStack::PopAndDestroy( ocspUrlBuf );
       
   881             }
       
   882 
       
   883         CleanupStack::PopAndDestroy( cenRep );
       
   884         }
       
   885     }
       
   886 
       
   887 // ---------------------------------------------------------------------------
       
   888 // CSisxSifPluginActiveImpl::StartInstallingL()
       
   889 // ---------------------------------------------------------------------------
       
   890 //
       
   891 void CSisxSifPluginActiveImpl::StartInstallingL()
       
   892     {
       
   893 	const CComponentInfo::CNode& rootNode( iComponentInfo->RootNodeL() );
       
   894 	TBool driveSelection = rootNode.DriveSeletionRequired();
       
   895 	iUiHandler->SetDriveSelectionRequired( driveSelection );
       
   896 	TInt maxInstalledSize = rootNode.MaxInstalledSize();
       
   897 	iUiHandler->SetMaxInstalledSize( maxInstalledSize );
       
   898 
       
   899 	iUiHandler->PublishStartL( rootNode );
       
   900 
       
   901 	UpdateInstallPrefsForPerformingOcspL();
       
   902 	FillDeviceSupportedLanguagesL();
       
   903 
       
   904     if( iFileHandle )
       
   905         {
       
   906         iAsyncLauncher->InstallL( *iUiHandler, *iFileHandle, *iInstallPrefs,
       
   907                 iDeviceSupportedLanguages, iStatus );
       
   908         }
       
   909     else if( iFileName )
       
   910         {
       
   911         iAsyncLauncher->InstallL( *iUiHandler, *iFileName, *iInstallPrefs,
       
   912                 iDeviceSupportedLanguages, iStatus );
       
   913         }
       
   914     else
       
   915         {
       
   916         Panic( ESisxSifInternalError );
       
   917         }
       
   918 
       
   919     iPhase = ERunningOperation;
       
   920     SetActive();
       
   921     }
       
   922 
       
   923 // ---------------------------------------------------------------------------
       
   924 // CSisxSifPluginActiveImpl::StartSilentInstallingL()
       
   925 // ---------------------------------------------------------------------------
       
   926 //
       
   927 void CSisxSifPluginActiveImpl::StartSilentInstallingL()
       
   928     {
       
   929     // TODO: fix this, removed temporarily to allow installations
       
   930 #ifdef _NOT_DEFINED_
       
   931     const CComponentInfo::CNode& rootNode( iComponentInfo->RootNodeL() );
       
   932     TBool isAuthenticated = ( rootNode.Authenticity() == EAuthenticated );
       
   933 
       
   934     // AllowUntrusted option is needed to install untrusted packages.
       
   935     if( !isAuthenticated && ( iInstallParams->AllowUntrusted() != EAllowed ) )
       
   936         {
       
   937         FLOG( _L("Attempt to install unsigned package silently without AllowUntrusted option") );
       
   938         iErrorHandler->SetExtendedErrorCode( ENeedsAllowUntrustedParameter );
       
   939         CompleteClientRequest( KErrPermissionDenied );
       
   940         }
       
   941     // GrantCapabilities option is needed to install packages that require user capabilities
       
   942     else if( RequiresUserCapabilityL( rootNode ) &&
       
   943             ( iInstallParams->GrantCapabilities() != EAllowed  ) )
       
   944         {
       
   945         FLOG( _L("Attempt to grant user capabilities silently without GrantCapabilities option") );
       
   946         iErrorHandler->SetExtendedErrorCode( ENeedsGrantCapabilitiesParameter );
       
   947         CompleteClientRequest( KErrPermissionDenied );
       
   948         }
       
   949     // AllFiles capability is needed to install untrusted packages that contains exe/dll binaries
       
   950     else if( !isAuthenticated && rootNode.HasExecutable() && !iHasAllFilesCapability )
       
   951         {
       
   952         FLOG( _L("Attempt to install untrusted binaries silently without AllFiles capability") );
       
   953         iErrorHandler->SetExtendedErrorCode( EAllFilesCapabilityRequired );
       
   954         CompleteClientRequest( KErrPermissionDenied );
       
   955         }
       
   956     else
       
   957 #endif
       
   958         {
       
   959         StartInstallingL();
       
   960         }
       
   961     }
       
   962 
       
   963 // ---------------------------------------------------------------------------
       
   964 // CSisxSifPluginActiveImpl::FinalizeInstallationL()
       
   965 // ---------------------------------------------------------------------------
       
   966 //
       
   967 void CSisxSifPluginActiveImpl::FinalizeInstallationL()
       
   968     {
       
   969     UpdateStartupListL();
       
   970 
       
   971     if( iOutputParams )
       
   972         {
       
   973         TComponentId componentId = GetLastInstalledComponentIdL();
       
   974         iOutputParams->AddIntL( KSifOutParam_ComponentId, componentId );
       
   975         }
       
   976 
       
   977     iUiHandler->PublishCompletionL();
       
   978 	iUiHandler->DisplayCompleteL();
       
   979     }
       
   980 
       
   981 // ---------------------------------------------------------------------------
       
   982 // CSisxSifPluginActiveImpl::UpdateStartupListL()
       
   983 // ---------------------------------------------------------------------------
       
   984 //
       
   985 void CSisxSifPluginActiveImpl::UpdateStartupListL()
       
   986     {
       
   987     if( FeatureManager::FeatureSupported( KFeatureIdExtendedStartup ) )
       
   988         {
       
   989         TFullName name( KStartupListUpdaterName );
       
   990         name.Append( '*' );
       
   991         TFindProcess findProcess( name );
       
   992         if( findProcess.Next( name ) == KErrNone )
       
   993             {
       
   994             // already running, no need to do anything
       
   995             return;
       
   996             }
       
   997 
       
   998         RProcess process;
       
   999         CleanupClosePushL( process );
       
  1000 
       
  1001         TInt result = process.Create( KStartupListUpdaterExecutable, KNullDesC );
       
  1002         if( result == KErrNone )
       
  1003             {
       
  1004             TRequestStatus rendezvousStatus;
       
  1005             process.Rendezvous( rendezvousStatus );
       
  1006 
       
  1007             // start process and wait until it is started
       
  1008             process.Resume();
       
  1009             User::WaitForRequest( rendezvousStatus );
       
  1010 
       
  1011             // ignore possible errors
       
  1012             result = rendezvousStatus.Int();
       
  1013             }
       
  1014 
       
  1015         CleanupStack::PopAndDestroy( &process );
       
  1016         }
       
  1017     }
       
  1018 
       
  1019 // ---------------------------------------------------------------------------
       
  1020 // CSisxSifPluginActiveImpl::FillDeviceSupportedLanguagesL()
       
  1021 // ---------------------------------------------------------------------------
       
  1022 //
       
  1023 void CSisxSifPluginActiveImpl::FillDeviceSupportedLanguagesL()
       
  1024     {
       
  1025     FLOG( _L("CSisxSifPluginActiveImpl::FillDeviceSupportedLanguagesL, begin") );
       
  1026 
       
  1027     CArrayFixFlat<TInt>* installedLanguages = NULL;
       
  1028     TInt err = SysLangUtil::GetInstalledLanguages( installedLanguages, &iFs );
       
  1029     CleanupStack::PushL( installedLanguages );
       
  1030     User::LeaveIfError( err );
       
  1031     if( installedLanguages )
       
  1032         {
       
  1033         iDeviceSupportedLanguages.Reset();
       
  1034         for( TInt index = 0; index < installedLanguages->Count(); index++ )
       
  1035             {
       
  1036             TInt language = (*installedLanguages)[ index ];
       
  1037             FLOG_1( _L("CSisxSifPluginActiveImpl::FillDeviceSupportedLanguagesL: %d"), language );
       
  1038             iDeviceSupportedLanguages.AppendL( language );
       
  1039             }
       
  1040         }
       
  1041     CleanupStack::PopAndDestroy( installedLanguages );
       
  1042 
       
  1043     FLOG( _L("CSisxSifPluginActiveImpl::FillDeviceSupportedLanguagesL, end") );
       
  1044     }
       
  1045