appinstaller/AppinstUi/Plugin/SisxUI/Src/SisxUIOperationWatcher.cpp
changeset 80 9dcba1ee99f7
parent 77 d1838696558c
equal deleted inserted replaced
77:d1838696558c 80:9dcba1ee99f7
     1 /*
       
     2 * Copyright (c) 2002-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:   This module contains the implementation of CSisxUIOperationWatcher 
       
    15 *                class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <swi/asynclauncher.h>
       
    23 #include <swi/sisregistrysession.h>
       
    24 #include <swi/sisregistryentry.h>
       
    25 #include <swi/sisregistrypackage.h>
       
    26 #include <centralrepository.h>
       
    27 #include <SWInstallerInternalCRKeys.h>
       
    28 #include <pathinfo.h>
       
    29 #include <zipfilemember.h>
       
    30 #include <DRMLicenseManager.h>
       
    31 #include <SisxUIData.rsg>
       
    32 #include <SWInstTaskManager.h>
       
    33 #include <SWInstTask.h>
       
    34 #include <SWInstDefs.h>
       
    35 #include <featmgr.h>
       
    36 #include <SWInstFileTaskParam.h>
       
    37 #include <e32property.h>
       
    38 #include <SWInstallerInternalPSKeys.h>
       
    39 #include <Oma2Agent.h>              // KOmaDrm2AgentName
       
    40 #include <syslangutil.h>
       
    41 #include <caf/manager.h>            // ContentAccess::CManager
       
    42 #include <caf/agent.h>              // ContentAccess::TAgent
       
    43 
       
    44 #include <DcfEntry.h> // JPAA-7GEB7P 
       
    45 #include <DcfRep.h> // JPAA-7GEB7P
       
    46 
       
    47 #include "SisxUIOperationWatcher.h"
       
    48 #include "SisxUIHandler.h"
       
    49 #include "SisxUIResult.h"
       
    50 #include "SisxUIAppInfo.h"
       
    51 #include "SisxUIStartupFile.h"
       
    52 #include "SWInstDebug.h"
       
    53 #include "SisxUISilentHandler.h"
       
    54 #include "SisxUICleanupUtils.h" // JPAA-7GEB7P
       
    55 
       
    56 _LIT( KTempDir, "piptemp\\" );
       
    57 _LIT( KPipFileMatch, "*" );
       
    58 const TUint KSisxFileUidPosition = 8;
       
    59 const TUint KDot = 0x2E; // Dot
       
    60 _LIT(KSisString, "sis");
       
    61 _LIT( KSkinExtension, "*.skn" ); // JPAA-7GEB7P
       
    62 
       
    63 using namespace SwiUI;
       
    64 using namespace ContentAccess;
       
    65 
       
    66 // ============================ MEMBER FUNCTIONS ===============================
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CSisxUIOperationWatcher::CSisxUIOperationWatcher
       
    70 // C++ default constructor can NOT contain any code, that
       
    71 // might leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CSisxUIOperationWatcher::CSisxUIOperationWatcher() 
       
    75     : CActive( CActive::EPriorityStandard ),
       
    76       iIsSilent( EFalse ),
       
    77       iDoSilentOcsp( EFalse )
       
    78     {
       
    79     CActiveScheduler::Add( this );    
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CSisxUIOperationWatcher::ConstructL
       
    84 // Symbian 2nd phase constructor can leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CSisxUIOperationWatcher::ConstructL()
       
    88     {
       
    89     iTaskManager = CTaskManager::NewL();
       
    90     User::LeaveIfError( iRfs.Connect() );    
       
    91     iRfs.ShareProtected();
       
    92     FeatureManager::InitializeLibL(); 
       
    93     iLauncher = Swi::CAsyncLauncher::NewL();
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CSisxUIOperationWatcher::NewL
       
    98 // Two-phased constructor.
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 CSisxUIOperationWatcher* CSisxUIOperationWatcher::NewL()
       
   102     {
       
   103     CSisxUIOperationWatcher* self = new( ELeave ) CSisxUIOperationWatcher();
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL();
       
   106     CleanupStack::Pop( self );
       
   107     return self;    
       
   108     }
       
   109     
       
   110 // Destructor
       
   111 CSisxUIOperationWatcher::~CSisxUIOperationWatcher()
       
   112     {
       
   113     iDeletionOngoing = ETrue;
       
   114     if ( iCanceller )
       
   115         {
       
   116         iCanceller->Cancel();
       
   117         delete iCanceller;
       
   118         }    
       
   119 
       
   120     delete iLauncher;
       
   121     iLauncher = NULL;
       
   122     CActive::Cancel();
       
   123 
       
   124     iSupportedLanguages.Close();
       
   125     delete iUIHandler;
       
   126     delete iTaskManager;
       
   127     delete iMIME;    
       
   128 
       
   129     NotifyEndUninstall();
       
   130 
       
   131     iInstalledFiles.ResetAndDestroy();
       
   132     iAugmentations.ResetAndDestroy();    
       
   133 
       
   134     iTempFile.Close();
       
   135     iRfs.Close();    
       
   136 
       
   137     FeatureManager::UnInitializeLib();
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CSisxUIOperationWatcher::InstallL
       
   142 // Handle install request.
       
   143 // (other items were commented in a header).
       
   144 // -----------------------------------------------------------------------------
       
   145 //    
       
   146 void CSisxUIOperationWatcher::InstallL( RFile& aFile, 
       
   147                                         const TDesC8& aMIME, 
       
   148                                         TBool aIsDRM, 
       
   149                                         TRequestStatus& aRequestStatus )
       
   150     {
       
   151     // Set client request to pending state
       
   152     iRequestStatus = &aRequestStatus;    
       
   153     *iRequestStatus = KRequestPending; 
       
   154 
       
   155     iSourceFile = aFile;
       
   156     iMIME = aMIME.AllocL();    
       
   157 
       
   158     // Create the ui
       
   159     iUIHandler = CSisxUIHandler::NewL( CSisxUIHandler::EModeInstall, this );   
       
   160     if ( aIsDRM )
       
   161         {
       
   162         // We need to pass the handle to ui handler, so that it can shown
       
   163         // details of drm
       
   164         iUIHandler->SetFileForDrm( aFile );        
       
   165         }    
       
   166 
       
   167     iPreparing = ETrue;    
       
   168     // Kick off the RunL
       
   169     TRequestStatus* stat = &iStatus;
       
   170     User::RequestComplete( stat, KErrNone );
       
   171     SetActive();  
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CSisxUIOperationWatcher::SilentInstallL
       
   176 // Handle silentinstall request.
       
   177 // (other items were commented in a header).
       
   178 // -----------------------------------------------------------------------------
       
   179 //    
       
   180 void CSisxUIOperationWatcher::SilentInstallL( RFile& aFile, 
       
   181                                               const TDesC8& aMIME, 
       
   182                                               TBool aIsDRM,
       
   183                                               TInstallOptions& aOptions, 
       
   184                                               TRequestStatus& aRequestStatus )
       
   185     {
       
   186     // Set client request to pending state
       
   187     iRequestStatus = &aRequestStatus;    
       
   188     *iRequestStatus = KRequestPending;
       
   189 
       
   190     iIsSilent = ETrue;      
       
   191     iSourceFile = aFile;
       
   192     iMIME = aMIME.AllocL();    
       
   193     if ( aOptions.iOCSP == EPolicyAllowed )
       
   194         {
       
   195         iDoSilentOcsp = ETrue;        
       
   196         }    
       
   197 
       
   198     // Create the ui
       
   199     iUIHandler = CSisxUISilentHandler::NewL( aOptions, this );   
       
   200     if ( aIsDRM )
       
   201         {
       
   202         // We need to pass the handle to ui handler, so that it can shown
       
   203         // details of drm
       
   204         iUIHandler->SetFileForDrm( aFile );        
       
   205         }    
       
   206 
       
   207     iPreparing = ETrue;    
       
   208     // Kick off the RunL
       
   209     TRequestStatus* stat = &iStatus;
       
   210     User::RequestComplete( stat, KErrNone );
       
   211     SetActive();  
       
   212     }        
       
   213       
       
   214 // -----------------------------------------------------------------------------
       
   215 // CSisxUIOperationWatcher::UninstallL
       
   216 // Handle uninstall request.
       
   217 // (other items were commented in a header).
       
   218 // -----------------------------------------------------------------------------
       
   219 //      
       
   220 void CSisxUIOperationWatcher::UninstallL( const TUid& aUid, TRequestStatus& aRequestStatus ) 
       
   221     {
       
   222     // Set client request to pending state
       
   223     iRequestStatus = &aRequestStatus;    
       
   224     *iRequestStatus = KRequestPending; 
       
   225 
       
   226     iUninstalledUid = aUid;    
       
   227 
       
   228     TRAP_IGNORE( NotifyStartUninstallL(aUid ) );
       
   229     iUIHandler = CSisxUIHandler::NewL( CSisxUIHandler::EModeUninstall, this );
       
   230     
       
   231     iLauncher->UninstallL( *iUIHandler, aUid, iStatus );
       
   232     SetActive();    
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CSisxUIOperationWatcher::UninstallL
       
   237 // Handle uninstall request.
       
   238 // (other items were commented in a header).
       
   239 // -----------------------------------------------------------------------------
       
   240 //      
       
   241 void CSisxUIOperationWatcher::SilentUninstallL( const TUid& aUid, 
       
   242                                                 TUninstallOptions& aOptions, 
       
   243                                                 TRequestStatus& aRequestStatus ) 
       
   244     {
       
   245     // Set client request to pending state
       
   246     iRequestStatus = &aRequestStatus;    
       
   247     *iRequestStatus = KRequestPending; 
       
   248 
       
   249     iIsSilent = ETrue;    
       
   250     iUninstalledUid = aUid;    
       
   251 
       
   252     iUIHandler = CSisxUISilentHandler::NewL( aOptions, this );
       
   253 
       
   254     TRAP_IGNORE( NotifyStartUninstallL(aUid ) );
       
   255     iLauncher->UninstallL( *iUIHandler, aUid, iStatus );
       
   256     SetActive();    
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CSisxUIOperationWatcher::UninstallAugmentationL
       
   261 // Uninstalls only a specific augmentation (sispatch)
       
   262 // (other items were commented in a header).
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CSisxUIOperationWatcher::UninstallAugmentationL( const TUid& aUid, 
       
   266                                                       TInt aIndex, 
       
   267                                                       TRequestStatus& aRequestStatus )
       
   268     {
       
   269     // Set client request to pending state
       
   270     iRequestStatus = &aRequestStatus;    
       
   271     *iRequestStatus = KRequestPending; 
       
   272 
       
   273     iUninstalledUid = aUid;    
       
   274 
       
   275     TRAP_IGNORE( NotifyStartUninstallL(aUid ) );
       
   276     iUIHandler = CSisxUIHandler::NewL( CSisxUIHandler::EModeUninstall, this );
       
   277    
       
   278     DoUninstallAugmentationL( aUid, aIndex );    
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CSisxUIOperationWatcher::SilentUninstallAugmentationL
       
   283 // Uninstalls only a specific augmentation (sispatch)
       
   284 // (other items were commented in a header).
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CSisxUIOperationWatcher::SilentUninstallAugmentationL( const TUid& aUid, 
       
   288                                                             TUninstallOptions& aOptions,
       
   289                                                             TInt aIndex, 
       
   290                                                             TRequestStatus& aRequestStatus )
       
   291     {
       
   292     // Set client request to pending state
       
   293     iRequestStatus = &aRequestStatus;    
       
   294     *iRequestStatus = KRequestPending; 
       
   295 
       
   296     iIsSilent = ETrue;    
       
   297     iUninstalledUid = aUid;    
       
   298 
       
   299     TRAP_IGNORE( NotifyStartUninstallL(aUid ) );
       
   300     iUIHandler = CSisxUISilentHandler::NewL( aOptions, this );
       
   301    
       
   302     DoUninstallAugmentationL( aUid, aIndex );    
       
   303     }
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CSisxUIOperationWatcher::FinalCompleteL
       
   307 // Informs the UI, about final completion.
       
   308 // (other items were commented in a header).
       
   309 // -----------------------------------------------------------------------------
       
   310 // 
       
   311 void CSisxUIOperationWatcher::FinalCompleteL()
       
   312     {
       
   313     iTempFile.Close();
       
   314     
       
   315     if ( iUIHandler )
       
   316         {
       
   317         iUIHandler->ShowFinalNoteL();        
       
   318         }    
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CSisxUIOperationWatcher::Cancel
       
   323 // Override of CActive::Cancel
       
   324 // (other items were commented in a header).
       
   325 // -----------------------------------------------------------------------------
       
   326 //    
       
   327 void CSisxUIOperationWatcher::Cancel()
       
   328     {
       
   329     if ( !iCancelOngoing )
       
   330         {        
       
   331         iUIHandler->ProcessResult( KSWInstErrUserCancel );
       
   332     
       
   333         if ( iPreparing )
       
   334             {
       
   335             CActive::Cancel();            
       
   336             iUIHandler->DoNotShowFinalNote();            
       
   337             // Just complete the client request
       
   338             CompleteRequest( KSWInstErrUserCancel ); 
       
   339             }        
       
   340         else
       
   341             {            
       
   342             // If we are installing/uninstalling we may have a dialog waiting
       
   343             // for user input. We need to use this special method to cancel
       
   344             // the operation.
       
   345             TRAPD( err,
       
   346                    iCanceller = CommonUI::CCUICancelTimer::NewL( this );
       
   347                    iCanceller->StartCancelling();            
       
   348                 );
       
   349             if ( err != KErrNone )
       
   350                 {
       
   351                 // Complete the original request from client
       
   352                 CompleteRequest( KSWInstErrUserCancel );           
       
   353                 }            
       
   354             }        
       
   355 
       
   356         iCancelOngoing = ETrue;        
       
   357         }    
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CSisxUIOperationWatcher::RunL
       
   362 // Called by framework when request is finished.
       
   363 // (other items were commented in a header).
       
   364 // -----------------------------------------------------------------------------
       
   365 //    
       
   366 void CSisxUIOperationWatcher::RunL()
       
   367     {
       
   368     FLOG_1( _L("SisxUI: RunL() status: %d"), iStatus.Int() );
       
   369 
       
   370     // If we got here, we don't need the canceller anymore
       
   371     if ( iCanceller )
       
   372         {
       
   373         iCanceller->Cancel();
       
   374         delete iCanceller;
       
   375         iCanceller = NULL;        
       
   376         }    
       
   377 
       
   378     if ( iPreparing )
       
   379         {
       
   380         // Do all the necessary preparations
       
   381         PrepareInstallL();
       
   382         return;        
       
   383         }
       
   384 
       
   385     // Let the UI know about the result
       
   386     iUIHandler->ProcessResult( iStatus.Int() );    
       
   387 
       
   388     if ( iUIHandler->GetResult().iResult == EUiResultOk )
       
   389         {
       
   390         // Install case    
       
   391         if ( iUIHandler->InstallMode() == CSisxUIHandler::EModeInstall )
       
   392             {
       
   393             TRAP_IGNORE( CompleteInstallationL() );            
       
   394             }
       
   395         // Uninstall case
       
   396         else 
       
   397             {
       
   398             TRAP_IGNORE( CompleteUninstallationL() );
       
   399             }       
       
   400         }
       
   401 
       
   402     CompleteRequest( iUIHandler->GetResult().CommonResult() );          
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // CSisxUIOperationWatcher::DoCancelL
       
   407 // Called by framework when request is cancelled.
       
   408 // (other items were commented in a header).
       
   409 // -----------------------------------------------------------------------------
       
   410 // 
       
   411 void CSisxUIOperationWatcher::DoCancel()
       
   412     {        
       
   413     // This function is usually not used because of overridden Cancel().
       
   414     // Usually CActive::Cancel() followed by CompleteRequest() is used to
       
   415     // cancel active CSisxUIOperationWatcher. However, when active operation
       
   416     // watcher is deleted, this function must complete the client request
       
   417     // (to avoid deadlock when client calls CActive::Cancel() later).
       
   418     if( iDeletionOngoing && iRequestStatus )
       
   419         {
       
   420         CompleteRequest( KErrCancel );
       
   421         }
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CSisxUIOperationWatcher::DoCancelL
       
   426 // Handles a leave occurring in the request completion event handler RunL().
       
   427 // (other items were commented in a header).
       
   428 // -----------------------------------------------------------------------------
       
   429 // 
       
   430 TInt CSisxUIOperationWatcher::RunError( TInt aError )
       
   431     {
       
   432     // Report the error to the UI
       
   433     iUIHandler->ProcessResult( aError );    
       
   434     // Complete client request
       
   435     CompleteRequest( aError );
       
   436     return KErrNone;    
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CSisxUIOperationWatcher::UserCancelL
       
   441 // Called when user has cancelled the operation.
       
   442 // (other items were commented in a header).
       
   443 // -----------------------------------------------------------------------------
       
   444 // 
       
   445 void CSisxUIOperationWatcher::UserCancelL( TBool aCancelImmediately )
       
   446     {
       
   447     iIsUserCancel = ETrue;
       
   448     if ( !aCancelImmediately )
       
   449         {        
       
   450         Cancel();
       
   451         }
       
   452     else
       
   453         {
       
   454         CancelEngine();
       
   455         }    
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CSisxUIOperationWatcher::IsShowingDialog
       
   460 // Indicates if a modal dialog is currently shown.
       
   461 // (other items were commented in a header).
       
   462 // -----------------------------------------------------------------------------
       
   463 // 
       
   464 TBool CSisxUIOperationWatcher::IsShowingDialog()
       
   465     {
       
   466     return iUIHandler->IsShowingDialog();    
       
   467     }
       
   468     
       
   469 // -----------------------------------------------------------------------------
       
   470 // CSisxUIOperationWatcher::CancelEngine
       
   471 // Cancels the installation engine.
       
   472 // (other items were commented in a header).
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 void CSisxUIOperationWatcher::CancelEngine()
       
   476     {
       
   477     if ( iLauncher )
       
   478         {
       
   479         iLauncher->CancelOperation();   
       
   480         }              
       
   481     }
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // CSisxUIOperationWatcher::ForceCancel
       
   485 // Called when nothing else has worked.
       
   486 // (other items were commented in a header).
       
   487 // -----------------------------------------------------------------------------
       
   488 //
       
   489 void CSisxUIOperationWatcher::ForceCancel()
       
   490     {
       
   491     // We need to make a dirty cancel
       
   492     // Kill the async launcher
       
   493     delete iLauncher;
       
   494     iLauncher = NULL;
       
   495     
       
   496     // We can cancel the AO, launcher has completed the request
       
   497     CActive::Cancel();
       
   498     
       
   499     // Complete the client request
       
   500     CompleteRequest( KSWInstErrUserCancel );
       
   501     }
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CSisxUIOperationWatcher::StartedCancellingL
       
   505 // Called to indicate that the cancelling progress has been started.
       
   506 // (other items were commented in a header).
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 void CSisxUIOperationWatcher::StartedCancellingL()
       
   510     {
       
   511     // Show the dialog only if this is user initiated cancel.
       
   512     if ( iIsUserCancel )
       
   513         {        
       
   514         iUIHandler->ShowCancellingL();    
       
   515         }    
       
   516     }
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CSisxUIOperationWatcher::DoCancelL
       
   520 // Completes the pending request.
       
   521 // (other items were commented in a header).
       
   522 // -----------------------------------------------------------------------------
       
   523 // 
       
   524 void CSisxUIOperationWatcher::CompleteRequest( TInt aResult )
       
   525     {
       
   526     iTempFile.Close();
       
   527     
       
   528     if ( iRequestStatus )
       
   529         {        
       
   530         FLOG_1( _L("SisxUI: Completing with: %d"), aResult );
       
   531         User::RequestComplete( iRequestStatus, aResult );
       
   532         iRequestStatus = NULL;
       
   533         }   
       
   534     }
       
   535 
       
   536 // -----------------------------------------------------------------------------
       
   537 // CSisxUIOperationWatcher::AddStartupItemsL
       
   538 // Add files to startup list.
       
   539 // (other items were commented in a header).
       
   540 // -----------------------------------------------------------------------------
       
   541 // 
       
   542 void CSisxUIOperationWatcher::AddStartupItemsL( RArray<TStartupTaskParam>& aParams )
       
   543     {
       
   544     if ( FeatureManager::FeatureSupported( KFeatureIdExtendedStartup ) )
       
   545         {        
       
   546         if ( aParams.Count() > 0 )
       
   547             {        
       
   548             CTask* task = CTask::NewL( KSTartupTaskAddImplUid, ETrue );
       
   549             CleanupStack::PushL( task );        
       
   550             for ( TInt index = 0; index < aParams.Count(); index++ )
       
   551                 {
       
   552                 TStartupTaskParamPckg pckg( aParams[index] );        
       
   553                 task->SetParameterL( pckg, index );        
       
   554                 }
       
   555     
       
   556             iTaskManager->AddTaskL( task );
       
   557             CleanupStack::Pop( task );
       
   558             }
       
   559         }    
       
   560     }
       
   561  
       
   562 // -----------------------------------------------------------------------------
       
   563 // CSisxUIOperationWatcher::RemoveStartupItemsL
       
   564 // Remove files from the startup list.
       
   565 // (other items were commented in a header).
       
   566 // -----------------------------------------------------------------------------
       
   567 // 
       
   568 void CSisxUIOperationWatcher::RemoveStartupItemsL( RArray<TStartupTaskParam>& aParams )
       
   569     {
       
   570     if ( FeatureManager::FeatureSupported( KFeatureIdExtendedStartup ) )
       
   571         {        
       
   572         if ( aParams.Count() > 0 )
       
   573             {        
       
   574             CTask* task = CTask::NewL( KSTartupTaskRemoveImplUid, ETrue );
       
   575             CleanupStack::PushL( task );        
       
   576             for ( TInt index = 0; index < aParams.Count(); index++ )
       
   577                 {
       
   578                 TStartupTaskParamPckg pckg( aParams[index] );        
       
   579                 task->SetParameterL( pckg, index );        
       
   580                 }
       
   581     
       
   582             iTaskManager->AddTaskL( task );
       
   583             CleanupStack::Pop( task );
       
   584             }    
       
   585         }
       
   586     }
       
   587 
       
   588 // -----------------------------------------------------------------------------
       
   589 // CSisxUIOperationWatcher::RemoveStartupFileL
       
   590 // Checks if the given uid has installed a startup file. If it finds one
       
   591 // it removes it and creates a task to remove the items as well.
       
   592 // (other items were commented in a header).
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 void CSisxUIOperationWatcher::RemoveStartupFileL( TUid aUid )
       
   596     {
       
   597     if ( FeatureManager::FeatureSupported( KFeatureIdExtendedStartup ) )
       
   598         {        
       
   599         // Handle startup list
       
   600         CSisxUIStartupFile* startupFile = CSisxUIStartupFile::NewL( aUid );
       
   601         CleanupStack::PushL( startupFile );
       
   602         if ( !startupFile->NewFileExists() )
       
   603             {
       
   604             FLOG( _L("SisxUI: Removal of import file") );
       
   605         
       
   606             // First see if we have a control file for this package
       
   607             if ( startupFile->PrivateFileExists() )
       
   608                 {            
       
   609                 RArray<TStartupTaskParam> params;     
       
   610                 startupFile->RemovePrivateFile( params );
       
   611                 CleanupClosePushL( params );                        
       
   612                 RemoveStartupItemsL( params ); 
       
   613                 CleanupStack::PopAndDestroy(); // params
       
   614                 iInstalledFiles.ResetAndDestroy();
       
   615 
       
   616                 // Put the flag on that we did modify the startup list
       
   617                 iStartupModified = ETrue;        
       
   618                 }
       
   619             }
       
   620         
       
   621         CleanupStack::PopAndDestroy( startupFile );        
       
   622         }      
       
   623     }
       
   624 
       
   625 // -----------------------------------------------------------------------------
       
   626 // CSisxUIOperationWatcher::HandleLogL
       
   627 // Handles the log entry addition.
       
   628 // (other items were commented in a header).
       
   629 // -----------------------------------------------------------------------------
       
   630 // 
       
   631 void CSisxUIOperationWatcher::HandleLogL( const CSisxUIAppInfo& aAppInfo, 
       
   632                                           const TLogTaskAction& aAction, 
       
   633                                           TBool aIsStartup )
       
   634     {
       
   635     // Create a log task object, non-persistent
       
   636     CTask* task = CTask::NewL( KLogTaskImplUid, EFalse );
       
   637     CleanupStack::PushL( task );
       
   638     
       
   639     // Construct log task parameters
       
   640     TLogTaskParam params;
       
   641 
       
   642     // Make sure that we don't copy over limits
       
   643     params.iName.Copy( aAppInfo.Name().Left( KMaxLogNameLength ) );
       
   644     params.iVendor.Copy( aAppInfo.Vendor().Left( KMaxLogNameLength ) );
       
   645 
       
   646     params.iVersion = aAppInfo.Version();
       
   647     params.iUid = aAppInfo.Uid();
       
   648     // The time must be in universal time
       
   649     TTime time;
       
   650     time.UniversalTime();    
       
   651     params.iTime = time;
       
   652     params.iAction = aAction;
       
   653     params.iIsStartup = aIsStartup;    
       
   654     
       
   655     TLogTaskParamPckg pckg( params );
       
   656     task->SetParameterL( pckg, 0 );
       
   657 
       
   658     // Add the log task to the task list
       
   659     iTaskManager->AddTaskL( task );
       
   660 
       
   661     CleanupStack::Pop( task );
       
   662     }
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CSisxUIOperationWatcher::HandlePipFileL
       
   666 // Helper to handle the case of pip file.
       
   667 // (other items were commented in a header).
       
   668 // -----------------------------------------------------------------------------
       
   669 // 
       
   670 void CSisxUIOperationWatcher::HandlePipFileL( RFile& aPipFileHandle, RFile& aSisFileHandle )
       
   671     {
       
   672     FLOG( _L("SisxUI: Handle pip file") );
       
   673 
       
   674     // PIP package, we need to use license manager to extract the sis file
       
   675     // First construct the temp path
       
   676     iRfs.PrivatePath( iTempDir );
       
   677     iTempDir.Insert( 0, TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive() );
       
   678     iTempDir.Append( KTempDir );
       
   679     iRfs.MkDir( iTempDir );    
       
   680   
       
   681     // Add task to delete the extracted sis file
       
   682     HBufC* pipFileMatch = HBufC::NewLC( KMaxFileName );
       
   683     pipFileMatch->Des().Copy( iTempDir );
       
   684     pipFileMatch->Des().Append( KPipFileMatch );
       
   685 
       
   686     // Create a delete file task
       
   687     CTask* task = CTask::NewL( KFileTaskDeleteImplUid, ETrue );
       
   688     CleanupStack::PushL( task );
       
   689     
       
   690     // Construct file task parameters
       
   691     TFileTaskDeleteParam params;
       
   692     params.iFile = *pipFileMatch;
       
   693     TFileTaskDeleteParamPckg pckg( params );
       
   694     task->SetParameterL( pckg, 0 );
       
   695     
       
   696     // Add the task to the task list
       
   697     iTaskManager->AddTaskL( task );
       
   698     CleanupStack::Pop( task );    
       
   699     iTaskManager->CommitL();
       
   700     
       
   701     CleanupStack::PopAndDestroy( pipFileMatch );    
       
   702     
       
   703     // Use license manager to extract files from the pip package
       
   704     CDRMLicenseManager* licenseMgr = CDRMLicenseManager::NewL();
       
   705     CleanupStack::PushL( licenseMgr );               
       
   706     User::LeaveIfError( licenseMgr->ExtractSISFileL( aPipFileHandle, iTempDir ) );
       
   707     
       
   708     // Get the sis file name and open temporary handle to it.
       
   709     // HLEI-7EGFRE
       
   710     CZipFileMember* sisMember( licenseMgr->GetSISMemberL() );
       
   711     CleanupStack::PushL( sisMember );
       
   712     iTempDir.Append( *sisMember->Name() );
       
   713     CleanupStack::PopAndDestroy( sisMember );
       
   714     sisMember = NULL;
       
   715     
       
   716     User::LeaveIfError( aSisFileHandle.Open( iRfs, iTempDir, EFileShareAny ) );        
       
   717     iIsPipFile = ETrue;
       
   718     
       
   719     CleanupStack::PopAndDestroy( licenseMgr );    
       
   720     }
       
   721 
       
   722 // -----------------------------------------------------------------------------
       
   723 // CSisxUIOperationWatcher::PrepareOCSPL
       
   724 // Helper to read ocsp values from central repository and prepare the ui.
       
   725 // (other items were commented in a header).
       
   726 // -----------------------------------------------------------------------------
       
   727 // 
       
   728 void CSisxUIOperationWatcher::PrepareOCSPL( CSisxUIHandler* aUIHandler, 
       
   729                                             Swi::CInstallPrefs* aPrefs )
       
   730     {
       
   731     TSWInstallerOcspProcedure ocspProc( ESWInstallerOcspProcedureOff );
       
   732     
       
   733     if ( !iIsSilent || iDoSilentOcsp )
       
   734         {        
       
   735         CRepository* repository = CRepository::NewL( KCRUidSWInstallerSettings );
       
   736         CleanupStack::PushL( repository );
       
   737     
       
   738         if ( !iIsSilent )
       
   739             {            
       
   740             // In case of normal installation we check the ocsp value from central rep
       
   741             TInt value( 0 );
       
   742             repository->Get( KSWInstallerOcspProcedure, value );
       
   743             ocspProc = TSWInstallerOcspProcedure( value );    
       
   744             }
       
   745         else
       
   746             {
       
   747             // In case of silent install, the client sets the value
       
   748             ocspProc = ESWInstallerOcspProcedureOn;            
       
   749             }
       
   750     
       
   751         // Get default OCSP URL
       
   752         HBufC* ocspURL = HBufC::NewLC( NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   753         TPtr ptr( ocspURL->Des() );
       
   754         repository->Get( KSWInstallerOcspDefaultURL, ptr );
       
   755 
       
   756         // Convert to 8 byte
       
   757         HBufC8* ocspURL8 = HBufC8::NewLC( ocspURL->Length() );
       
   758         ocspURL8->Des().Copy( *ocspURL );
       
   759         
       
   760         aPrefs->SetRevocationServerUriL( *ocspURL8 );
       
   761         CleanupStack::PopAndDestroy( 3, repository );        
       
   762         }
       
   763     
       
   764     if ( ocspProc == ESWInstallerOcspProcedureOn ||
       
   765          ocspProc == ESWInstallerOcspProcedureMust )
       
   766         {
       
   767         if ( ocspProc == ESWInstallerOcspProcedureOn )
       
   768             {
       
   769             aUIHandler->SetOcspProcedure( ESisxUIOcspProcOn );
       
   770             }
       
   771         else
       
   772             {
       
   773             aUIHandler->SetOcspProcedure( ESisxUIOcspProcMust );
       
   774             }        
       
   775         
       
   776         aPrefs->SetPerformRevocationCheck( ETrue );        
       
   777         }
       
   778     else
       
   779         {
       
   780         aUIHandler->SetOcspProcedure( ESisxUIOcspProcOff );
       
   781         aPrefs->SetPerformRevocationCheck( EFalse );
       
   782         }   
       
   783     }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CSisxUIOperationWatcher::GetInstalledPackagesL
       
   787 // Helper to get the packages that were installed in this session.
       
   788 // (other items were commented in a header).
       
   789 // -----------------------------------------------------------------------------
       
   790 // 
       
   791 void CSisxUIOperationWatcher::GetInstalledPackagesL( RPointerArray<CSisxUIAppInfo>& aPackages )
       
   792     {
       
   793     ContentAccess::CContent* content = NULL;
       
   794     if ( iIsPipFile )
       
   795         {
       
   796         // The source file is a pip file, we need to use the extracted sis file instead.
       
   797         content = ContentAccess::CContent::NewLC( iTempFile );
       
   798         }  
       
   799     else
       
   800         {
       
   801         content = ContentAccess::CContent::NewLC( iSourceFile );
       
   802         }
       
   803     
       
   804     ContentAccess::CData* data = content->OpenContentLC( ContentAccess::EExecute );
       
   805 
       
   806     // Read the uid from the package
       
   807     TInt32 uid( 0 );    
       
   808     TPckg<TInt32> uidpkg( uid );
       
   809     TInt pos( KSisxFileUidPosition );
       
   810     data->Seek( ESeekStart, pos );    
       
   811     data->Read( uidpkg, sizeof( TInt32 ) );
       
   812 
       
   813     CleanupStack::PopAndDestroy( 2, content );    
       
   814 
       
   815     iUIHandler->ProcessedPackages( aPackages );            
       
   816 
       
   817     // Currently we can only get the parent package
       
   818     for ( TInt index = 0; index < 1 && index < aPackages.Count(); index++ )
       
   819         {
       
   820         aPackages[index]->SetUid( TUid::Uid( uid ) );                
       
   821         }
       
   822     }
       
   823 
       
   824 // -----------------------------------------------------------------------------
       
   825 // CSisxUIOperationWatcher::HandleStartupAdditionL
       
   826 // Helper to handle startup list addition.
       
   827 // (other items were commented in a header).
       
   828 // -----------------------------------------------------------------------------
       
   829 // 
       
   830 void CSisxUIOperationWatcher::HandleStartupAdditionL( const CSisxUIAppInfo& aAppInfo )
       
   831     {
       
   832     FLOG( _L("SisxUI: Handle startup") );
       
   833 
       
   834     if ( FeatureManager::FeatureSupported( KFeatureIdExtendedStartup ) )
       
   835         {        
       
   836         CSisxUIStartupFile* startupFile = CSisxUIStartupFile::NewL( aAppInfo.Uid() );
       
   837         CleanupStack::PushL( startupFile );
       
   838 
       
   839         // First check if there is a control file in import dir
       
   840         if ( startupFile->NewFileExists() )
       
   841             {
       
   842             FLOG( _L("SisxUI: Processing control file") );
       
   843 
       
   844             // Get all files installed by this package
       
   845             Swi::RSisRegistrySession regSession;
       
   846             CleanupClosePushL( regSession );
       
   847             User::LeaveIfError( regSession.Connect() );
       
   848 
       
   849             Swi::RSisRegistryEntry regEntry;
       
   850             CleanupClosePushL( regEntry );
       
   851             User::LeaveIfError( regEntry.Open( regSession, aAppInfo.Uid() ) );
       
   852 
       
   853             regEntry.FilesL( iInstalledFiles ); 
       
   854 
       
   855             CleanupStack::PopAndDestroy( 2 ); // regEntry, regSession
       
   856                          
       
   857             RArray<TStartupTaskParam> params;
       
   858 
       
   859             // See if there are some old items, if so remove them
       
   860             if ( startupFile->PrivateFileExists() )
       
   861                 {
       
   862                 startupFile->RemovePrivateFile( params );
       
   863                 CleanupClosePushL( params );                        
       
   864                 RemoveStartupItemsL( params ); 
       
   865                 CleanupStack::Pop(); // params                        
       
   866                 params.Reset();                               
       
   867                 }                        
       
   868 
       
   869             startupFile->ProcessNewFile( params, iInstalledFiles );
       
   870                         
       
   871             CleanupClosePushL( params );                        
       
   872             AddStartupItemsL( params ); 
       
   873             CleanupStack::PopAndDestroy(); // params
       
   874             iInstalledFiles.ResetAndDestroy();  
       
   875             }
       
   876 
       
   877         iTaskManager->CommitL();
       
   878 
       
   879         CleanupStack::PopAndDestroy( startupFile );   
       
   880         }
       
   881     }
       
   882 
       
   883 // -----------------------------------------------------------------------------
       
   884 // CSisxUIOperationWatcher::PrepareInstallL
       
   885 // Prepares the installation.
       
   886 // (other items were commented in a header).
       
   887 // -----------------------------------------------------------------------------
       
   888 // 
       
   889 void CSisxUIOperationWatcher::PrepareInstallL()
       
   890     {    
       
   891     Swi::CInstallPrefs* prefs = Swi::CInstallPrefs::NewL();
       
   892     CleanupStack::PushL( prefs );    
       
   893 
       
   894     // Prepare for possible OCSP
       
   895     PrepareOCSPL( iUIHandler, prefs );
       
   896 
       
   897     // Check if we allow untrusted SW to be installed
       
   898     CRepository* repository = CRepository::NewL( KCRUidSWInstallerSettings );
       
   899     CleanupStack::PushL( repository );    
       
   900     TInt value( 1 );
       
   901     repository->Get( KSWInstallerAllowUntrusted, value );
       
   902     if ( !value )
       
   903         {
       
   904         iUIHandler->SetAllowUntrusted( EFalse );        
       
   905         }
       
   906     else
       
   907         {
       
   908         iUIHandler->SetAllowUntrusted( ETrue );
       
   909         }    
       
   910     CleanupStack::PopAndDestroy( repository );    
       
   911 
       
   912     // Get supported language ids in a RArray for Swi::CAsyncLauncher::InstallL()
       
   913     iSupportedLanguages.Reset();
       
   914     CArrayFixFlat<TInt>* installedLanguages = NULL;
       
   915     TInt err = SysLangUtil::GetInstalledLanguages( installedLanguages, &iRfs );
       
   916     CleanupStack::PushL( installedLanguages );
       
   917     User::LeaveIfError( err );
       
   918     if( installedLanguages )
       
   919         {
       
   920         for( TInt lang = 0; lang < installedLanguages->Count(); lang++ )
       
   921             {
       
   922             iSupportedLanguages.AppendL( (*installedLanguages)[ lang ] );
       
   923             }
       
   924         }
       
   925     CleanupStack::PopAndDestroy( installedLanguages );
       
   926 
       
   927     if ( *iMIME == KPipMimeType )
       
   928         {
       
   929         // Handle the pip file
       
   930         HandlePipFileL( iSourceFile, iTempFile );
       
   931         
       
   932         // Start installation
       
   933         iLauncher->InstallL( *iUIHandler, iTempFile, *prefs, iSupportedLanguages, iStatus );
       
   934         }   
       
   935     else
       
   936         {
       
   937         // Start installation
       
   938         iLauncher->InstallL( *iUIHandler, iSourceFile, *prefs, iSupportedLanguages, iStatus );
       
   939         }    
       
   940 
       
   941     CleanupStack::PopAndDestroy( prefs );
       
   942     
       
   943     // Preparing done
       
   944     iPreparing = EFalse;
       
   945     SetActive();       
       
   946     }
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // CSisxUIOperationWatcher::CompleteInstallationL
       
   950 // Completes the installation
       
   951 // (other items were commented in a header).
       
   952 // -----------------------------------------------------------------------------
       
   953 //
       
   954 void CSisxUIOperationWatcher::CompleteInstallationL()
       
   955     {
       
   956     FLOG( _L("SisxUI: CompleteInstallationL ->") );
       
   957     // If this was a pip file, process it
       
   958     if ( iIsPipFile )
       
   959         {    
       
   960         FLOG( _L("SisxUI: PIP file") );
       
   961                     
       
   962         CDRMLicenseManager* licenseMgr = CDRMLicenseManager::NewL();
       
   963         CleanupStack::PushL( licenseMgr );     
       
   964         TInt err = licenseMgr->ProcessL( iSourceFile, KNullDesC() );
       
   965         if ( err != KErrNone )
       
   966             {
       
   967             // Reset the OK result so that we can show the error.
       
   968             iUIHandler->ResetResult();
       
   969             User::Leave( KSWInstErrFileCorrupted );
       
   970             }
       
   971                 
       
   972         CleanupStack::PopAndDestroy( licenseMgr );                
       
   973         
       
   974 // RVIN-6JUGWH
       
   975         HBufC* fileName = HBufC::NewLC( 100 );
       
   976         TPtr fileNamePtr( fileName->Des() );   
       
   977     	TInt err2 = iSourceFile.Name( fileNamePtr );
       
   978         
       
   979         FLOG_1( _L("Original file name: %S"), &fileNamePtr );
       
   980         
       
   981         TInt i = 0;
       
   982         for ( ; i < fileNamePtr.Length(); i++ )
       
   983             {
       
   984             if ( fileNamePtr[i] == KDot )
       
   985                 {
       
   986                 break;
       
   987                 }                    
       
   988             } 
       
   989             
       
   990         HBufC* tmpFile = HBufC::NewLC( i + 4 );
       
   991         TPtr tmpFilePtr( tmpFile->Des() );   
       
   992         tmpFilePtr = fileNamePtr.Left( i + 1 );
       
   993         tmpFilePtr.Append( KSisString );               
       
   994 
       
   995         FLOG_1( _L( "Changed file name: %S" ), &tmpFilePtr );
       
   996 
       
   997         // Create data supplier      
       
   998         CContent* content = CContent::NewLC( iSourceFile );
       
   999 
       
  1000         HBufC* contentID = HBufC::NewLC( KMaxCafContentName  );
       
  1001         TPtr contPtr(NULL, NULL);
       
  1002 
       
  1003         // create attribute set
       
  1004         ContentAccess::RStringAttributeSet stringAttSet;
       
  1005         //RStringAttributeSet stringAttSet;
       
  1006         CleanupClosePushL( stringAttSet );
       
  1007 
       
  1008         stringAttSet.AddL( EContentID );
       
  1009 
       
  1010         content->GetStringAttributeSet( stringAttSet );
       
  1011 
       
  1012         // pass on values of string attributes
       
  1013         contPtr.Set( contentID->Des() );
       
  1014 
       
  1015         err = stringAttSet.GetValue( EContentID, contPtr );
       
  1016         
       
  1017         if ( err != KErrNone )
       
  1018             {  
       
  1019             FLOG_1( _L("SisxUI: ContentID error = %d"), err );          
       
  1020             // Reset the OK result so that we can show the error.
       
  1021             iUIHandler->ResetResult();
       
  1022             User::Leave( KSWInstErrGeneralError );
       
  1023             }
       
  1024 
       
  1025         HBufC8* contentID8 = HBufC8::NewLC( contentID->Length() );
       
  1026         TPtr8 cont8Ptr = contentID8->Des();
       
  1027         
       
  1028         // Copy 8bit data from contentID buffer.
       
  1029         // Note that AgentSpecificCommand function take's only 8bit data.
       
  1030         cont8Ptr.Copy( contPtr );
       
  1031 
       
  1032         HBufC8* buffer = HBufC8::NewMaxLC( sizeof( TInt ) + 
       
  1033                                            contentID8->Size() + 
       
  1034                                            tmpFilePtr.Size() );                                           
       
  1035         TUint8* bptr = const_cast<TUint8*>( buffer->Ptr() );
       
  1036 
       
  1037         TUint length = tmpFilePtr.Length();
       
  1038         TPtr8 temp( NULL, 0, 0 );
       
  1039         TPtr8 buf( buffer->Des() );
       
  1040         Mem::Copy(bptr, &length, sizeof(TInt));
       
  1041         Mem::Copy(bptr+sizeof( TInt ), tmpFilePtr.Ptr(), length * 2 );
       
  1042         Mem::Copy(bptr+sizeof( TInt )+( length * 2 ), contentID8->Ptr(), contentID8->Size());    
       
  1043 
       
  1044         ContentAccess::CManager* manager = NULL;
       
  1045         ContentAccess::TAgent agent;
       
  1046 
       
  1047         // Find the caf agent and create manager
       
  1048         manager = GetCafDataL( agent );
       
  1049 
       
  1050     	// ignore any error, we couldn't do anything about it anyway
       
  1051         length = manager->AgentSpecificCommand( agent, ContentAccess::ESetContentName, 
       
  1052                                                 buf, temp);
       
  1053 
       
  1054         FLOG( _L("SisxUI: PopAndDestroy") );
       
  1055         // buffer, tmpfile, fileName, content, contentID, stringAttSet, contentID8 
       
  1056         CleanupStack::PopAndDestroy( 7 ); 
       
  1057         delete manager;
       
  1058 // RVIN-6JUGWH                       
       
  1059         }            
       
  1060 
       
  1061     FLOG( _L("SisxUI: GetInstalledPackagesL") );
       
  1062 
       
  1063     // Here we get only the first package in case of embedded packages
       
  1064     // as currently there is no means to get the sub packages 
       
  1065     RPointerArray<CSisxUIAppInfo> packages;  
       
  1066     GetInstalledPackagesL( packages );            
       
  1067     CleanupClosePushL( packages );            
       
  1068 
       
  1069     // Create log entry for every installed package and handle possible 
       
  1070     // startup list addition.
       
  1071     for ( TInt index = 0; index < packages.Count(); index++ )
       
  1072         {               
       
  1073         // Handle startup list
       
  1074         // Currently, if embedded sis, only the first package can contain
       
  1075         // startup items
       
  1076         if ( !index && packages[index]->IsTrusted() )
       
  1077             {
       
  1078             HandleStartupAdditionL( *packages[index] ); 
       
  1079        
       
  1080             // Handle log
       
  1081             HandleLogL( *packages[index], ELogTaskActionInstall, ETrue );
       
  1082             }
       
  1083         else
       
  1084             {
       
  1085             // Handle log
       
  1086             HandleLogL( *packages[index], ELogTaskActionInstall, EFalse );
       
  1087             }                
       
  1088         }            
       
  1089      
       
  1090 // JPAA-7GEB7P
       
  1091     // Register PIP file content to DRM DCF server.
       
  1092     if ( iIsPipFile )     
       
  1093         {               
       
  1094         TInt siscount = packages.Count();
       
  1095         FLOG_1( _L("SisxUI: packages.Count() = %d"), siscount ); 
       
  1096     
       
  1097         if ( siscount )
       
  1098             {    
       
  1099             TUid pkgUid( packages[0]->Uid() );
       
  1100             FLOG_1( _L("SisxUI: package UID: 0x%x"), pkgUid.iUid );              
       
  1101             RegisterContentToDCF( pkgUid );
       
  1102             }
       
  1103         }
       
  1104 // JPAA-7GEB7P        
       
  1105         
       
  1106     FLOG( _L("SisxUI: PopAndDestroy") );
       
  1107     CleanupStack::PopAndDestroy(); // packages
       
  1108     
       
  1109     FLOG( _L("SisxUI: CompleteInstallationL <-") );
       
  1110             
       
  1111     // Make sure that all other control files are removed.
       
  1112     }
       
  1113 
       
  1114 // -----------------------------------------------------------------------------
       
  1115 // CSisxUIOperationWatcher::CompleteUninstallationL
       
  1116 // Completes the uninstallation
       
  1117 // (other items were commented in a header).
       
  1118 // -----------------------------------------------------------------------------
       
  1119 //
       
  1120 void CSisxUIOperationWatcher::CompleteUninstallationL()
       
  1121     {
       
  1122     NotifyEndUninstall();
       
  1123     
       
  1124     RemoveStartupFileL( iUninstalledUid );
       
  1125     iTaskManager->CommitL();   
       
  1126 
       
  1127     RPointerArray<CSisxUIAppInfo> packages;            
       
  1128     iUIHandler->ProcessedPackages( packages );
       
  1129     CleanupClosePushL( packages );
       
  1130         
       
  1131     if ( packages.Count() > 0 )
       
  1132         {            
       
  1133         packages[0]->SetUid( iUninstalledUid );           
       
  1134         
       
  1135         HandleLogL( *packages[0], ELogTaskActionUninstall, iStartupModified );
       
  1136         }        
       
  1137     CleanupStack::PopAndDestroy(); // packages 
       
  1138     }
       
  1139 
       
  1140 // -----------------------------------------------------------------------------
       
  1141 // CSisxUIOperationWatcher::DoUninstallAugmentationL
       
  1142 // Performs the uninstallation of augmentation.
       
  1143 // (other items were commented in a header).
       
  1144 // -----------------------------------------------------------------------------
       
  1145 //
       
  1146 void CSisxUIOperationWatcher::DoUninstallAugmentationL( TUid aUid, TInt aIndex )
       
  1147     {
       
  1148     // Find the augmentation
       
  1149     Swi::RSisRegistrySession regSession;
       
  1150     CleanupClosePushL( regSession );
       
  1151     User::LeaveIfError( regSession.Connect() );
       
  1152     
       
  1153     Swi::RSisRegistryEntry regEntry;
       
  1154     CleanupClosePushL( regEntry );
       
  1155     User::LeaveIfError( regEntry.Open( regSession, aUid ) );
       
  1156     
       
  1157     regEntry.AugmentationsL( iAugmentations );
       
  1158     
       
  1159     for ( TInt i( 0 ); i < iAugmentations.Count(); i++ )
       
  1160         {
       
  1161         if ( iAugmentations[i]->Index() == aIndex )
       
  1162             {
       
  1163             iIsAugmentation = ETrue;            
       
  1164             // We found the correct package, now uninstall it
       
  1165             iLauncher->UninstallL( *iUIHandler, *iAugmentations[i], iStatus );            
       
  1166             SetActive();
       
  1167             break;            
       
  1168             }        
       
  1169         if ( i == iAugmentations.Count() + 1 )
       
  1170             {
       
  1171             // We have gone through the whole list and couldn't find the package
       
  1172             User::Leave( KErrNotFound );            
       
  1173             }        
       
  1174         }  
       
  1175        
       
  1176     iAugmentations.ResetAndDestroy();    
       
  1177     CleanupStack::PopAndDestroy( 2, &regSession );   
       
  1178     }
       
  1179 
       
  1180 // -----------------------------------------------------------------------------
       
  1181 // CSisxUIOperationWatcher::NotifyStartUninstallL
       
  1182 // Notifies that uninstallation is about to start.
       
  1183 // (other items were commented in a header).
       
  1184 // -----------------------------------------------------------------------------
       
  1185 //
       
  1186 void CSisxUIOperationWatcher::NotifyStartUninstallL( TUid aUid )
       
  1187     {
       
  1188     _LIT_SECURITY_POLICY_PASS( KPropReadPolicy );
       
  1189     _LIT_SECURITY_POLICY_C1( KPropWritePolicy, ECapabilityWriteDeviceData );
       
  1190 
       
  1191     // Try to define the property if this is the first time
       
  1192     TInt err = RProperty::Define( KPSUidSWInstallerUiNotification, 
       
  1193                                   KSWInstallerUninstallation, 
       
  1194                                   RProperty::EInt,
       
  1195                                   KPropReadPolicy,
       
  1196                                   KPropWritePolicy );	
       
  1197     if ( err != KErrNone && err != KErrAlreadyExists )
       
  1198         {		
       
  1199         User::Leave( err );		
       
  1200         }
       
  1201     
       
  1202     // Set the package uid as the value
       
  1203     err = RProperty::Set( KPSUidSWInstallerUiNotification, 
       
  1204                           KSWInstallerUninstallation, 
       
  1205                           aUid.iUid );
       
  1206     User::LeaveIfError( err );
       
  1207     }
       
  1208 
       
  1209 // -----------------------------------------------------------------------------
       
  1210 // CSisxUIOperationWatcher::NotifyEndUninstall
       
  1211 // Notifies that uninstallation has been completed.
       
  1212 // (other items were commented in a header).
       
  1213 // -----------------------------------------------------------------------------
       
  1214 //
       
  1215 void CSisxUIOperationWatcher::NotifyEndUninstall()
       
  1216     {
       
  1217     RProperty::Set( KPSUidSWInstallerUiNotification, 
       
  1218                     KSWInstallerUninstallation, 
       
  1219                     0 );
       
  1220     }
       
  1221 
       
  1222 // -----------------------------------------------------------------------------
       
  1223 // CSisxUIOperationWatcher::GetCafDataL
       
  1224 // Handles searching correct DRM agent and manager.
       
  1225 // (other items were commented in a header).
       
  1226 // -----------------------------------------------------------------------------
       
  1227 // 
       
  1228 ContentAccess::CManager* CSisxUIOperationWatcher::GetCafDataL( ContentAccess::TAgent& aAgent )
       
  1229     {
       
  1230     RArray<TAgent> agents;
       
  1231 
       
  1232     CleanupClosePushL( agents );
       
  1233     CManager* manager = CManager::NewLC();
       
  1234 
       
  1235     manager->ListAgentsL( agents );
       
  1236     
       
  1237     for ( TInt i = 0; i < agents.Count(); i++ )
       
  1238         {
       
  1239         if (agents[i].Name().Compare(KOmaDrm2AgentName) == 0)
       
  1240             {
       
  1241             aAgent = agents[i];
       
  1242             break;
       
  1243             }
       
  1244         }
       
  1245     CleanupStack::Pop( manager );
       
  1246     CleanupStack::PopAndDestroy( &agents );
       
  1247     return manager;    
       
  1248     }
       
  1249 
       
  1250 // -----------------------------------------------------------------------------
       
  1251 // CSisxUIOperationWatcher::RegisterContentToDCF
       
  1252 // This function does register PIP packages content to DCF server.
       
  1253 // -----------------------------------------------------------------------------
       
  1254 // 
       
  1255 void CSisxUIOperationWatcher::RegisterContentToDCF( TUid aUid )
       
  1256     {
       
  1257     // Note that currently we do register only skin (*.skn) 
       
  1258     // files since there is not way to SisxUI plugin to know 
       
  1259     // which files should be registerd to DCF. It is not reasonable
       
  1260     // to push all files to DCF and hope that some is correct one.
       
  1261     
       
  1262     FLOG( _L("SisxUI: RegisterContentToDCF") ); 
       
  1263     Swi::RSisRegistrySession sisRegSession;                                        
       
  1264     User::LeaveIfError( sisRegSession.Connect() );                
       
  1265     CleanupClosePushL( sisRegSession );
       
  1266                 
       
  1267     // Get current package UID and open the entry.
       
  1268     Swi::RSisRegistryEntry entry;                                
       
  1269     // Open entry
       
  1270     TInt error = entry.Open( sisRegSession, aUid );
       
  1271     FLOG_1( _L("SisxUI: SisEntry open error: %d"), error );  
       
  1272      
       
  1273     if ( error == KErrNone )
       
  1274         {                       
       
  1275         CleanupClosePushL( entry );   
       
  1276         // Get all files to array for DCF update.
       
  1277         RPointerArray<HBufC> fileArray; 
       
  1278         CleanupResetAndDestroyPushL( fileArray );
       
  1279         TInt index = 0;     
       
  1280         // It seems that some PIP pkg do not have files in 
       
  1281         // main pacakge, but let's make sure that we do not
       
  1282         // miss any files.
       
  1283         FLOG( _L("SisxUI: Get files from main pkg") );  
       
  1284         RPointerArray<HBufC> sisFileArray;                
       
  1285         entry.FilesL( sisFileArray );                    
       
  1286         CleanupResetAndDestroyPushL( sisFileArray );
       
  1287         
       
  1288         // Add main package's file paths to file array.
       
  1289         SearchFilesForDCFL( sisFileArray, fileArray );
       
  1290               
       
  1291         // Let's see if there is augmentations to this main pkg.                  
       
  1292         RPointerArray<Swi::CSisRegistryPackage> augPackages;                      
       
  1293         entry.AugmentationsL( augPackages );                                        
       
  1294         CleanupResetAndDestroyPushL( augPackages );
       
  1295         
       
  1296         TInt augCount = augPackages.Count();
       
  1297         FLOG_1( _L("SisxUI: augmentations count = %d"), augCount );
       
  1298         
       
  1299         if ( augCount )
       
  1300             { 
       
  1301             // There may be several augmentaion pkgs and we need 
       
  1302             // check them all.      
       
  1303             for ( TInt augInd = 0; augInd < augCount; augInd++ )
       
  1304                 {
       
  1305                 FLOG_1( _L("SisxUI: augm. index = %d"), augInd );                                           
       
  1306                 Swi::RSisRegistryEntry augEntry;  
       
  1307                 
       
  1308                 error = augEntry.OpenL( 
       
  1309                       sisRegSession, 
       
  1310                       *augPackages[augInd] );
       
  1311                 FLOG_1( _L("SisxUI: Open augm. error = %d"), error );  
       
  1312                                                                                             
       
  1313                 if ( !error )
       
  1314                     {
       
  1315                     CleanupClosePushL( augEntry );
       
  1316                     
       
  1317                     RPointerArray<HBufC> augFileArray;                
       
  1318                     augEntry.FilesL( augFileArray );                         
       
  1319                     CleanupResetAndDestroyPushL( augFileArray );
       
  1320                     
       
  1321                     // Add file paths to file array.
       
  1322                     SearchFilesForDCFL( augFileArray, fileArray );
       
  1323         
       
  1324                     // augEntry, augFileArray                         
       
  1325                     CleanupStack::PopAndDestroy( 2, &augEntry );                                             
       
  1326                     }
       
  1327                 }//for   
       
  1328             }
       
  1329         // sisFileArray, augPackages
       
  1330         CleanupStack::PopAndDestroy( 2, &sisFileArray );  
       
  1331         
       
  1332         // Ok let's start to register files to DCF server.
       
  1333         TInt fileCount = fileArray.Count();  
       
  1334         
       
  1335         if ( fileCount )
       
  1336             {                                       
       
  1337             FLOG( _L("SisxUI: Create DCF entry") );
       
  1338             CDcfEntry* dcfEntry = CDcfEntry::NewL();    
       
  1339             CleanupStack::PushL( dcfEntry );
       
  1340             
       
  1341             CDcfRep* dcfRep = CDcfRep::NewL();
       
  1342             CleanupStack::PushL( dcfRep );    
       
  1343             
       
  1344             for (index = 0; index < fileCount; index++ )
       
  1345                 {   
       
  1346                 TPtr fileBufPtr = fileArray[index]->Des();
       
  1347                 FLOG_1( _L("SisxUI: DCF SetLocationL with file: %S"), &fileBufPtr );
       
  1348                 
       
  1349                 TRAP( error, dcfEntry->SetLocationL( fileBufPtr, 0 ) );                   
       
  1350                 FLOG_1( _L("SisxUI: SetLocationL err = %d"), error );                
       
  1351                 // Note UpdateL function needs to be TRAPed. It
       
  1352                 // does leave if file type is not supported.
       
  1353                 TRAP( error, dcfRep->UpdateL( dcfEntry ) );                            
       
  1354                 FLOG_1( _L("SisxUI: UpdateL err = %d"), error );                                                                      
       
  1355                 }                                               
       
  1356             // dcfRep, dcfEntry 
       
  1357             CleanupStack::PopAndDestroy( 2 );  
       
  1358             }
       
  1359         // fileArray
       
  1360         CleanupStack::PopAndDestroy( 1, &fileArray ); 
       
  1361         // sisRegSession,  sisRegEntry                                                                                           
       
  1362         CleanupStack::PopAndDestroy( 2, &sisRegSession );     
       
  1363         }                                                      
       
  1364     }
       
  1365 
       
  1366 
       
  1367 // -----------------------------------------------------------------------------
       
  1368 // CSisxUIOperationWatcher::SearchFilesForDCFL
       
  1369 // This function finds files for DCF server.
       
  1370 // -----------------------------------------------------------------------------
       
  1371 // 
       
  1372 void CSisxUIOperationWatcher::SearchFilesForDCFL( 
       
  1373     RPointerArray<HBufC>& aSourceArray,
       
  1374     RPointerArray<HBufC>& aTargetArray )
       
  1375     {
       
  1376     FLOG( _L("SisxUI: SearchFilesForDCFL") );   
       
  1377     // Currently we do register only skin files.       
       
  1378     // Note for now there is no way to get list from file types
       
  1379     // which DCF server will accecpt. PIP package contais
       
  1380     // some txt file which specifies files to be registred,
       
  1381     // but SisxUI do not have acceess to that file since DRM
       
  1382     // has extracts the pip content.
       
  1383           
       
  1384     TInt fileCount = aSourceArray.Count();                                                 
       
  1385     FLOG_1( _L("SisxUI: package file count = %d"), fileCount );   
       
  1386             
       
  1387     if ( fileCount )
       
  1388         {        
       
  1389         for ( TInt index = 0; index < fileCount; index++ )
       
  1390             {
       
  1391             HBufC* tempPath = aSourceArray[index];
       
  1392             // Search extension 
       
  1393             FLOG( _L("SisxUI: Search extension") ); 
       
  1394             if ( tempPath->Match( KSkinExtension ) != KErrNotFound )
       
  1395                 {
       
  1396                 // Ok correct file extension found. Alloc memory
       
  1397                 // because source may be deleted.
       
  1398                 HBufC* filePath = tempPath->AllocL();
       
  1399                 aTargetArray.Append( filePath );
       
  1400 #ifdef _DEBUG
       
  1401                 TPtr tempPtr = filePath->Des();                                                           
       
  1402                 FLOG_1( _L("SisxUI: Add file to array: %S"), &tempPtr );
       
  1403 #endif                                
       
  1404                 } 
       
  1405             }
       
  1406         }    
       
  1407     }
       
  1408 
       
  1409 //  End of File