connectivitymodules/SeCon/services/pcd/src/sconinstaller.cpp
branchRCL_3
changeset 20 4a793f564d72
parent 0 d0791faffa3f
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CSConAppInstaller implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <pathinfo.h>
       
    22 #include <swi/sisregistryentry.h>
       
    23 #include <swi/sisregistrypackage.h>
       
    24 #include <swi/sisregistrysession.h>
       
    25 #include <SWInstDefs.h>
       
    26 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    27 #include <javaregistry.h>
       
    28 
       
    29 using namespace Java;
       
    30 
       
    31 #include "debug.h"
       
    32 #include "sconinstaller.h"
       
    33 #include "sconpcdconsts.h"
       
    34 #include "sconpcdutility.h"
       
    35 
       
    36 _LIT8( KWidgetMimeType, "application/x-nokia-widget");
       
    37 
       
    38 const TInt KSConSeConUidValue = 0x101f99f6;
       
    39 const TUid KSConSeConUid = {KSConSeConUidValue};
       
    40 
       
    41 // ============================= MEMBER FUNCTIONS ===============================
       
    42 
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CSConAppInstaller::CSConAppInstaller( CSConInstallerQueue* aQueue )
       
    46 // Constructor
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CSConAppInstaller::CSConAppInstaller( CSConInstallerQueue* aQueue, RFs& aFs ) :
       
    50     CActive( EPriorityStandard ), iQueue( aQueue ), iFs( aFs )
       
    51     {
       
    52     TRACE_FUNC;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CSConAppInstaller::~CSConAppInstaller()
       
    57 // Destructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSConAppInstaller::~CSConAppInstaller()
       
    61     {
       
    62     TRACE_FUNC;
       
    63     iSWInst.Close();
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSConAppInstaller::StartInstaller( TInt& aTaskId )
       
    68 // Starts the installer task
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 void CSConAppInstaller::StartInstaller( TInt& aTaskId )
       
    72     {
       
    73     TRACE_FUNC_ENTRY;
       
    74     CSConTask* task = NULL;
       
    75     TRequestStatus* status = NULL;
       
    76     TInt err( KErrNone );
       
    77     
       
    78     TInt ret = iQueue->GetTask( aTaskId, task );
       
    79     
       
    80     if( aTaskId > 0 && ret != KErrNotFound )
       
    81         {
       
    82         if ( iInstallerState != EIdle || IsActive() )
       
    83             {
       
    84             LOGGER_WRITE("WARNING! SConAppInstaller was not on idle state!");
       
    85             iQueue->CompleteTask( aTaskId, KErrInUse );
       
    86             TRACE_FUNC_EXIT;
       
    87             return;
       
    88             }
       
    89         
       
    90         
       
    91         iCurrentTask = aTaskId;
       
    92         iQueue->SetTaskProgress( aTaskId, KSConCodeProcessingStarted );
       
    93         
       
    94         switch( task->GetServiceId() )
       
    95             {
       
    96             case EInstall :
       
    97                 iQueue->ChangeQueueProcessStatus();
       
    98                 err = iSWInst.Connect();
       
    99                 
       
   100                 if( err == KErrNone )
       
   101                     {
       
   102                     if ( task->iInstallParams->iMode == ESilentInstall )
       
   103                     	{
       
   104                     	LOGGER_WRITE( "Begin silent installation.. " );
       
   105                     	iOptions.iUntrusted = SwiUI::EPolicyNotAllowed;
       
   106                         iOptions.iOCSP = SwiUI::EPolicyNotAllowed;
       
   107                         iOptionsPckg = iOptions;
       
   108                         iInstallerState = ESilentInstalling;
       
   109                     	iSWInst.SilentInstall( iStatus, task->iInstallParams->iPath, iOptionsPckg );
       
   110                     	}
       
   111                     else
       
   112                     	{
       
   113                     	LOGGER_WRITE( "Begin to install.. " );
       
   114                     	iInstallerState = EInstalling;
       
   115                         iSWInst.Install( iStatus, task->iInstallParams->iPath );
       
   116                     	}
       
   117                     }
       
   118                 
       
   119                 break;
       
   120             case EUninstall :
       
   121                 iQueue->ChangeQueueProcessStatus();
       
   122                 err = iSWInst.Connect();
       
   123                 
       
   124                 if( err == KErrNone )
       
   125                     {
       
   126                     LOGGER_WRITE( "Begin to uninstall.. " );
       
   127                     
       
   128                     TRAP( err, ProcessUninstallL( *task->iUninstallParams ) );
       
   129                     if( err != KErrNone )
       
   130                         {
       
   131                         LOGGER_WRITE_1( "StartInstaller ProcessUninstallL err: %d", err );
       
   132                         status = &iStatus;
       
   133                         User::RequestComplete( status, err );
       
   134                         }
       
   135                     }
       
   136                 
       
   137                 break;
       
   138             case EListInstalledApps :
       
   139                 iQueue->ChangeQueueProcessStatus();
       
   140                 iInstallerState = EListingInstalledApps;
       
   141                 TRAP( err, ProcessListInstalledAppsL() );
       
   142                 status = &iStatus;
       
   143                 User::RequestComplete( status, err );
       
   144                 break;
       
   145             default :
       
   146                 break;
       
   147             }
       
   148 
       
   149         SetActive();
       
   150         }
       
   151     TRACE_FUNC_EXIT;
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CSConAppInstaller::StopInstaller( TInt& aTaskId )
       
   156 // Stops the installer task
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 void CSConAppInstaller::StopInstaller( TInt& aTaskId )
       
   160     {
       
   161     TRACE_FUNC_ENTRY;
       
   162     //If the task is the current task, cancel it first
       
   163     if( iCurrentTask == aTaskId )
       
   164         {
       
   165         Cancel();
       
   166         iSWInst.Close();
       
   167         }
       
   168     TRACE_FUNC_EXIT;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // TBool CSConAppInstaller::InstallerActive()
       
   173 // returns installer activity status
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 TBool CSConAppInstaller::InstallerActive() const
       
   177     {
       
   178     if ( iInstallerState == EIdle )
       
   179         {
       
   180         return EFalse;
       
   181         }
       
   182     else
       
   183         {
       
   184         return ETrue;
       
   185         }
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CSConAppInstaller::DoCancel()
       
   190 // Implementation of CActive::DoCancel()
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CSConAppInstaller::DoCancel()
       
   194     {
       
   195     TRACE_FUNC_ENTRY;
       
   196     
       
   197     switch (iInstallerState)
       
   198         {
       
   199         case EInstalling:
       
   200             LOGGER_WRITE("Cancel normal install");
       
   201             iSWInst.CancelAsyncRequest( SwiUI::ERequestInstall );
       
   202             break;
       
   203         case ESilentInstalling:
       
   204             LOGGER_WRITE("Cancel silent install");
       
   205             iSWInst.CancelAsyncRequest( SwiUI::ERequestSilentInstall );
       
   206             break;
       
   207         case EUninstalling:
       
   208             LOGGER_WRITE("Cancel normal uninstall");
       
   209             iSWInst.CancelAsyncRequest( SwiUI::ERequestUninstall );
       
   210             break;
       
   211         case ESilentUninstalling:
       
   212             LOGGER_WRITE("Cancel silent uninstall");
       
   213             iSWInst.CancelAsyncRequest( SwiUI::ERequestSilentUninstall );
       
   214             break;
       
   215         case ECustomUninstalling: 
       
   216             LOGGER_WRITE("Cancel custom uninstall");
       
   217             iSWInst.CancelAsyncRequest( SwiUI::ERequestCustomUninstall );
       
   218             break;
       
   219         case ESilentCustomUnistalling:
       
   220             LOGGER_WRITE("Cancel silent custom uninstall");
       
   221             iSWInst.CancelAsyncRequest( SwiUI::ERequestSilentCustomUninstall );
       
   222             break;
       
   223         default:
       
   224             LOGGER_WRITE("WARNING! Unknown state");
       
   225             break;
       
   226         }
       
   227     iInstallerState = EIdle;
       
   228     
       
   229     // find and complete current task
       
   230     CSConTask* task = NULL;
       
   231     TInt ret = iQueue->GetTask( iCurrentTask, task );
       
   232 
       
   233     if ( iCurrentTask > 0 && ret != KErrNotFound )
       
   234         {
       
   235 
       
   236         switch( task->GetServiceId() )
       
   237             {
       
   238             case EInstall :
       
   239                 iQueue->CompleteTask( iCurrentTask, KErrCancel );
       
   240                 break;
       
   241             case EUninstall :
       
   242                 iQueue->CompleteTask( iCurrentTask, KErrCancel );
       
   243                 break;
       
   244             default :
       
   245                 break;
       
   246             }
       
   247         }
       
   248     TRACE_FUNC_EXIT;
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CSConAppInstaller::RunL()
       
   253 // Implementation of CActive::RunL()
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CSConAppInstaller::RunL()
       
   257     {
       
   258     TRACE_FUNC_ENTRY;
       
   259     iInstallerState = EIdle;
       
   260     iSWInst.Close();
       
   261     iQueue->ChangeQueueProcessStatus();
       
   262     TInt err( iStatus.Int() );
       
   263     LOGGER_WRITE_1( "CSConAppInstaller::RunL() iStatus.Int() : returned %d", err );
       
   264     
       
   265     CSConTask* task = NULL;
       
   266     TInt taskErr = iQueue->GetTask( iCurrentTask, task );
       
   267     
       
   268     LOGGER_WRITE_1( "CSConAppInstaller::RunL() GetTask %d", taskErr );
       
   269         
       
   270     if( taskErr == KErrNone )
       
   271         {
       
   272         if( task->GetServiceId() == EInstall && err == KErrNone )
       
   273             {
       
   274             LOGGER_WRITE( "CSConAppInstaller::RunL() : before DeleteFile" );
       
   275             //delete sis after succesfull install
       
   276             DeleteFile( task->iInstallParams->iPath );
       
   277             }
       
   278         }
       
   279     
       
   280     iQueue->CompleteTask( iCurrentTask, err );
       
   281     TRACE_FUNC_EXIT;
       
   282     }
       
   283 
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CSConAppInstaller::ProcessUninstallL( const CSConUninstall& aUninstallParams )
       
   287 // Execures UnInstall task
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 void CSConAppInstaller::ProcessUninstallL( const CSConUninstall& aUninstallParams )
       
   291     {
       
   292     TRACE_FUNC_ENTRY;
       
   293     LOGGER_WRITE_1( "aUid: 0x%08x", aUninstallParams.iUid.iUid );
       
   294     LOGGER_WRITE_1( "aName: %S", &aUninstallParams.iName );
       
   295     LOGGER_WRITE_1( "aVendor: %S", &aUninstallParams.iVendor );
       
   296     LOGGER_WRITE_1( "aType: %d", aUninstallParams.iType );
       
   297     LOGGER_WRITE_1( "aMode: %d", aUninstallParams.iMode );
       
   298     switch ( aUninstallParams.iType )
       
   299 	    {
       
   300 	    case ESisApplication:
       
   301 	    case ESisAugmentation:
       
   302 	    	UninstallSisL( aUninstallParams );
       
   303 	    	break;
       
   304 	    case EJavaApplication:
       
   305 	    	UninstallJavaL( aUninstallParams.iUid,
       
   306     			aUninstallParams.iMode);
       
   307 	    	break;
       
   308 	    case EWidgetApplication:
       
   309 	    	UninstallWidget( aUninstallParams.iUid,
       
   310 	    		aUninstallParams.iMode );
       
   311 	    	break;
       
   312 	    default:
       
   313 	    	User::Leave( KErrNotSupported );
       
   314 	    }
       
   315     
       
   316     TRACE_FUNC_EXIT;
       
   317     }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CSConAppInstaller::UninstallSisL( const CSConUninstall& aUninstallParams )
       
   321 // Uninstall sis package or augmentation
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CSConAppInstaller::UninstallSisL( const CSConUninstall& aUninstallParams )
       
   325 	{
       
   326 	TRACE_FUNC_ENTRY;
       
   327 
       
   328 	if ( aUninstallParams.iUid == KSConSeConUid )
       
   329 	    {
       
   330 	    LOGGER_WRITE("Cannot uninstall itself, leave");
       
   331 	    // cannot uninstall itself
       
   332 	    User::Leave( SwiUI::KSWInstErrFileInUse );
       
   333 	    }
       
   334 	
       
   335 	Swi::RSisRegistrySession sisRegistry;
       
   336     User::LeaveIfError( sisRegistry.Connect() );
       
   337     CleanupClosePushL( sisRegistry );
       
   338     //Check if uid belongs to SIS package
       
   339     if( !sisRegistry.IsInstalledL( aUninstallParams.iUid ) )
       
   340         {
       
   341         CleanupStack::PopAndDestroy( &sisRegistry );
       
   342         User::Leave( KErrNotFound );
       
   343         }
       
   344     
       
   345     Swi::RSisRegistryEntry entry;
       
   346     CleanupClosePushL(entry);
       
   347     User::LeaveIfError( entry.Open( sisRegistry, aUninstallParams.iUid ) );
       
   348     if ( aUninstallParams.iType == ESisAugmentation )
       
   349         {
       
   350         // augmentation pkg
       
   351         LOGGER_WRITE( "CSConAppInstaller::ProcessUninstallL ESisAugmentation" );
       
   352         
       
   353         TBool augmentationFound(EFalse);
       
   354         // Get possible augmentations
       
   355         RPointerArray<Swi::CSisRegistryPackage> augPackages;
       
   356         CleanupResetAndDestroyPushL( augPackages );
       
   357         entry.AugmentationsL( augPackages );
       
   358         for ( TInt j( 0 ); j < augPackages.Count() && !augmentationFound; j++ )
       
   359             {
       
   360             Swi::RSisRegistryEntry augmentationEntry;
       
   361             CleanupClosePushL( augmentationEntry );
       
   362             augmentationEntry.OpenL( sisRegistry, *augPackages[j] );
       
   363             
       
   364             HBufC* augPackageName = augmentationEntry.PackageNameL();
       
   365             CleanupStack::PushL( augPackageName );
       
   366             HBufC* augUniqueVendorName = augmentationEntry.UniqueVendorNameL();
       
   367             CleanupStack::PushL( augUniqueVendorName );
       
   368             
       
   369             if ( !augmentationEntry.IsInRomL() 
       
   370                 && augmentationEntry.IsPresentL()
       
   371                 && aUninstallParams.iName.Compare( *augPackageName ) == 0
       
   372                 && aUninstallParams.iVendor.Compare( *augUniqueVendorName ) == 0 )
       
   373                 {
       
   374                 // Correct augmentation found, uninstall it.
       
   375                 augmentationFound = ETrue;
       
   376                 TInt augmentationIndex = augPackages[j]->Index();
       
   377                 LOGGER_WRITE_1( "CSConAppInstaller::ProcessUninstallL augmentationIndex %d", augmentationIndex );
       
   378         
       
   379                 SwiUI::TOpUninstallIndexParam params;
       
   380                 params.iUid = aUninstallParams.iUid;
       
   381                 params.iIndex = augmentationIndex;
       
   382                 SwiUI::TOpUninstallIndexParamPckg pckg( params );
       
   383                 SwiUI::TOperation operation( SwiUI::EOperationUninstallIndex );
       
   384                 if( aUninstallParams.iMode == ESilentInstall )
       
   385                     {
       
   386                     LOGGER_WRITE( "CSConAppInstaller::ProcessUninstallL : silent aug-sis-uninstall" );
       
   387                     SwiUI::TUninstallOptionsPckg options;
       
   388                     iInstallerState = ESilentCustomUnistalling;
       
   389                     iSWInst.SilentCustomUninstall( iStatus, operation, options, pckg, KSISMIMEType );
       
   390                     }
       
   391                 else
       
   392                     {
       
   393                     LOGGER_WRITE( "CSConAppInstaller::ProcessUninstallL : unsilent aug-sis-uninstall" )
       
   394                     iInstallerState = ECustomUninstalling;
       
   395                     iSWInst.CustomUninstall( iStatus, operation, pckg, KSISMIMEType );
       
   396                     }
       
   397                 }
       
   398             CleanupStack::PopAndDestroy( augUniqueVendorName );
       
   399             CleanupStack::PopAndDestroy( augPackageName );
       
   400             CleanupStack::PopAndDestroy( &augmentationEntry );
       
   401             }  
       
   402         CleanupStack::PopAndDestroy( &augPackages );
       
   403         
       
   404         if ( !augmentationFound )
       
   405             {
       
   406             LOGGER_WRITE( "CSConAppInstaller::ProcessUninstallL augmentation not found -> Leave" );
       
   407             User::Leave( KErrNotFound );
       
   408             }
       
   409         }
       
   410     else
       
   411         {
       
   412         // Only uninstall if not in rom and is present
       
   413         if ( !entry.IsInRomL() && entry.IsPresentL() )
       
   414             { 
       
   415             if ( aUninstallParams.iMode == ESilentInstall )
       
   416                 {
       
   417                 LOGGER_WRITE( "CSConAppInstaller::ProcessUninstallL : silent sis-uninstall" );
       
   418                 SwiUI::TUninstallOptionsPckg options;
       
   419                 iInstallerState = ESilentUninstalling;
       
   420                 iSWInst.SilentUninstall( iStatus, aUninstallParams.iUid, options, KSISMIMEType );
       
   421                 }
       
   422             else
       
   423                 {
       
   424                 LOGGER_WRITE( "CSConAppInstaller::ProcessUninstallL : unsilent sis-uninstall" )
       
   425                 iInstallerState = EUninstalling;
       
   426                 iSWInst.Uninstall( iStatus, aUninstallParams.iUid, KSISMIMEType );
       
   427                 }
       
   428             }
       
   429         else
       
   430             {
       
   431             LOGGER_WRITE( "CSConAppInstaller::ProcessUninstallL sis not present -> Leave" );
       
   432             User::Leave( KErrNotFound );
       
   433             }
       
   434         }
       
   435     
       
   436     CleanupStack::PopAndDestroy( &entry );
       
   437 	CleanupStack::PopAndDestroy( &sisRegistry );
       
   438 	TRACE_FUNC_EXIT;
       
   439 	}
       
   440 
       
   441 // -----------------------------------------------------------------------------
       
   442 // CSConAppInstaller::UninstallJavaL( const TUid& aUid, const TSConInstallMode aMode )
       
   443 // Uninstall java package
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void CSConAppInstaller::UninstallJavaL( const TUid& aUid, const TSConInstallMode aMode )
       
   447 	{
       
   448 	TRACE_FUNC_ENTRY;
       
   449 	CJavaRegistry* javaRegistry = CJavaRegistry::NewLC( );
       
   450 	TBool entryExist = javaRegistry->RegistryEntryExistsL( aUid );
       
   451 	CleanupStack::PopAndDestroy( javaRegistry ); 
       
   452 	
       
   453     if( entryExist )
       
   454         {
       
   455         if( aMode == ESilentInstall )
       
   456             {
       
   457             LOGGER_WRITE( "CSConAppInstaller::UninstallJavaL : silent midlet-uninstall" )
       
   458             SwiUI::TUninstallOptionsPckg options;
       
   459             iInstallerState = ESilentUninstalling;
       
   460             iSWInst.SilentUninstall( iStatus, aUid, options, KMidletMIMEType );
       
   461             }
       
   462         else
       
   463             {
       
   464             LOGGER_WRITE( "CSConAppInstaller::UninstallJavaL : unsilent midlet-uninstall" )
       
   465             iInstallerState = EUninstalling;
       
   466             iSWInst.Uninstall( iStatus, aUid, KMidletMIMEType );
       
   467             }
       
   468         }
       
   469     else
       
   470         {
       
   471         LOGGER_WRITE( "CSConAppInstaller::UninstallJavaL java entry does not exist -> Leave" )
       
   472         User::Leave( KErrNotFound );
       
   473         }
       
   474     TRACE_FUNC_EXIT;
       
   475 	}
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CSConAppInstaller::UninstallWidget( const TUid& aUid, const TSConInstallMode aMode )
       
   479 // Uninstall widget
       
   480 // -----------------------------------------------------------------------------
       
   481 //
       
   482 void CSConAppInstaller::UninstallWidget( const TUid& aUid, const TSConInstallMode aMode )
       
   483 	{
       
   484 	TRACE_FUNC_ENTRY;
       
   485 	if( aMode == ESilentInstall )
       
   486         {
       
   487         LOGGER_WRITE( "CSConAppInstaller::UninstallWidget : silent uninstall" )
       
   488         SwiUI::TUninstallOptionsPckg options;
       
   489         iInstallerState = ESilentUninstalling;
       
   490         iSWInst.SilentUninstall( iStatus, aUid, options, KWidgetMimeType );
       
   491         }
       
   492     else
       
   493         {
       
   494         LOGGER_WRITE( "CSConAppInstaller::UninstallWidget : unsilent uninstall" )
       
   495         iInstallerState = EUninstalling;
       
   496         iSWInst.Uninstall( iStatus, aUid, KWidgetMimeType );
       
   497         }
       
   498 	TRACE_FUNC_EXIT;
       
   499 	}
       
   500 
       
   501     
       
   502 //--------------------------------------------------------------------------------
       
   503 //void CSConAppInstaller::ProcessListInstalledAppsL()
       
   504 //--------------------------------------------------------------------------------
       
   505 //
       
   506 void CSConAppInstaller::ProcessListInstalledAppsL()
       
   507     {
       
   508     TRACE_FUNC_ENTRY;
       
   509     
       
   510     CSConTask* task = NULL;
       
   511     User::LeaveIfError( iQueue->GetTask( iCurrentTask, task ) );
       
   512     
       
   513     SConPcdUtility::ProcessListInstalledAppsL( task );
       
   514     
       
   515     TRACE_FUNC_EXIT;
       
   516     }
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CSConAppInstaller::DeleteFile( const TDesC& aPath )
       
   520 // Deletes a file 
       
   521 // -----------------------------------------------------------------------------
       
   522 //  
       
   523 void CSConAppInstaller::DeleteFile( const TDesC& aPath )    
       
   524     {
       
   525     TRACE_FUNC;
       
   526     iFs.Delete( aPath );
       
   527     }
       
   528 // End of file