appinstaller/AppinstUi/Server/Src/SWInstSession.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 CSWInstSession class 
       
    15 *                member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <ecom/ecom.h>
       
    22 #include <w32std.h>
       
    23 #include <apgtask.h>
       
    24 #include <s32mem.h> //RDesReadStream 
       
    25 
       
    26 #include "SWInstSession.h"
       
    27 #include "SWInstServer.h"
       
    28 #include "SWInstServerPanic.h"
       
    29 #include "SWInstInstallRequest.h"
       
    30 #include "SWInstUninstallRequest.h"
       
    31 #include "SWInstRequestStore.h"
       
    32 #include "SWInstPrivateUid.h"
       
    33 
       
    34 using namespace SwiUI;
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CSWInstSession::CSWInstSession
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CSWInstSession::CSWInstSession()
       
    45     {
       
    46     }
       
    47     
       
    48 // Destructor
       
    49 CSWInstSession::~CSWInstSession()
       
    50     {   
       
    51     if ( iCanceller )
       
    52         {
       
    53         iCanceller->Cancel();
       
    54         delete iCanceller;
       
    55         }    
       
    56          
       
    57     delete iRequestStore;    
       
    58     // Call final close for ecom    
       
    59     REComSession::FinalClose();  
       
    60       
       
    61     delete iHeapSourceUrl;   
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CSWInstSession::PrepareForExit
       
    66 // Prepare the session for exit.
       
    67 // (other items were commented in a header).
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CSWInstSession::PrepareForExit( MRequestCallback* aExitCallback )
       
    71     {
       
    72     iExitCallback = aExitCallback;
       
    73 
       
    74     // If we have any pending requests, cancel them all
       
    75     if ( iRequestStore )
       
    76         {
       
    77         iRequestStore->CancelAllRequests();
       
    78         }
       
    79 
       
    80     if ( iExitCallback )
       
    81         {
       
    82         iExitCallback->RequestCompleted( KErrNone ); 
       
    83         iExitCallback = NULL;        
       
    84         }    
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSWInstSession::ServiceL
       
    89 // Handles the received message.
       
    90 // (other items were commented in a header).
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 void CSWInstSession::ServiceL( const RMessage2& aMessage )
       
    94     {
       
    95     // Dispatch the message in trap harness.
       
    96     TRAPD( result, HandleRequestL( aMessage ) );
       
    97     
       
    98     if ( result == KErrBadDescriptor )
       
    99         {
       
   100         PanicClient( aMessage, ESWInstPanicBadDescriptor );
       
   101         }    
       
   102 
       
   103     // In case of leave, we need to complete the client request here
       
   104     else if ( result != KErrNone )
       
   105         {
       
   106         if ( iRequestStore )
       
   107             {
       
   108             CSWInstRequestObject* req = iRequestStore->GetRequest( aMessage.Function() );
       
   109             if ( req && req->IsActive() )
       
   110                 {
       
   111                 req->Cancel();                
       
   112                 }            
       
   113             else 
       
   114                 {
       
   115                 // No active request found, we must complete the message manually
       
   116                 aMessage.Complete( result );
       
   117                 }            
       
   118             } 
       
   119         else
       
   120             {
       
   121             aMessage.Complete( result );
       
   122             }        
       
   123         }
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CSWInstSession::ServiceError
       
   128 // Called back by the server framework if this sessions RunL function returns an
       
   129 // error.
       
   130 // (other items were commented in a header).
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CSWInstSession::ServiceError( const RMessage2& aMessage, TInt aError )
       
   134     {
       
   135     // A bad descriptor error implies a badly programmed client, so panic it;
       
   136     // otherwise use the default handling (report the error to the client)
       
   137     if ( aError == KErrBadDescriptor )
       
   138         {
       
   139         PanicClient( aMessage, ESWInstPanicBadDescriptor );
       
   140         }
       
   141     CAknAppServiceBase::ServiceError( aMessage, aError );    
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CSWInstSession::CreateL
       
   146 // Completes construction of this server-side client session object.
       
   147 // (other items were commented in a header).
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CSWInstSession::CreateL()
       
   151     {
       
   152     iRequestStore = CSWInstRequestStore::NewL();  
       
   153     CAknAppServiceBase::CreateL();   
       
   154     iAppInForeground = ETrue; 
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CSWInstSession::RequestCompleted
       
   159 // Called when request is completed.
       
   160 // (other items were commented in a header).
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CSWInstSession::RequestCompleted( TInt /*aResult*/ )
       
   164     {
       
   165     // Delete completed requests
       
   166     iRequestStore->Flush();
       
   167     TInt pendingRequests = iRequestStore->PendingRequestCount();
       
   168 
       
   169     // See if we need to notify this completion
       
   170     if( iExitCallback && !pendingRequests )
       
   171         {
       
   172         iExitCallback->RequestCompleted( KErrNone );
       
   173         iExitCallback = NULL;
       
   174         }    
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CSWInstSession::Server
       
   179 // Returns reference to the server.
       
   180 // (other items were commented in a header).
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 CSWInstServer& CSWInstSession::Server()
       
   184     {
       
   185     return *static_cast<CSWInstServer*>( const_cast<CServer2*>
       
   186                                          ( CSession2::Server() ) );
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CSWInstSession::HandleRequestL
       
   191 // Handles the request.
       
   192 // (other items were commented in a header).
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CSWInstSession::HandleRequestL( const RMessage2& aMessage )
       
   196     {       
       
   197     TServerRequest opCode( ( TServerRequest ) aMessage.Function() );  
       
   198     
       
   199     // Send application to background if installation is silent. This way
       
   200     // we do not block other apps if installation takes long time.   
       
   201     if ( opCode == ERequestSilentInstall && iAppInForeground || 
       
   202          opCode == ERequestSilentInstallParams && iAppInForeground ||
       
   203          opCode == ERequestSilentInstallHandle && iAppInForeground ||
       
   204          opCode == ERequestSilentInstallParamsHandle && iAppInForeground )
       
   205         {        
       
   206         SendAppToBackgroundL();                                
       
   207         }      
       
   208 
       
   209     // Handle requests for the session.
       
   210     switch ( opCode ) 
       
   211         {
       
   212         case ERequestCancelRequest:
       
   213             {
       
   214             // We need to cancel and destroy the corresponding request. 
       
   215             TInt functionToCancel( GetInt( aMessage, KRequestIpcSlot ) );            
       
   216             CSWInstRequestObject* requestObj = iRequestStore->GetRequest( functionToCancel );
       
   217             if ( requestObj && requestObj->IsActive() )
       
   218                 {
       
   219                 requestObj->Cancel( aMessage );
       
   220                 }
       
   221             else
       
   222                 {                
       
   223                 // If we are cancelling we may have a dialog waiting. We need to 
       
   224                 // use this special method to cancel dialog before exit.
       
   225                 // See error TSW ELBA-78SBTS
       
   226                 TRAP_IGNORE(
       
   227                     iCanceller = CommonUI::CCUICancelTimer::NewL( this );
       
   228                     iCanceller->StartCancelling();            
       
   229                     );
       
   230                                      
       
   231                 aMessage.Complete( KErrNotFound );
       
   232                 }           
       
   233 
       
   234             break;                
       
   235             }                    
       
   236 
       
   237         case ERequestInstall:
       
   238         case ERequestInstallParams:
       
   239         case ERequestSilentInstall:
       
   240         case ERequestSilentInstallParams:
       
   241             {          
       
   242             // Delete completed requests
       
   243             iRequestStore->Flush();
       
   244                 
       
   245             CSWInstInstallRequest* installRequestObj = CSWInstInstallRequest::NewL( aMessage );
       
   246             CleanupStack::PushL( installRequestObj );
       
   247             // If store is full, this leaves with KSWInstErrBusy
       
   248             iRequestStore->AddRequestL( installRequestObj );  // Ownership transfers to store
       
   249             CleanupStack::Pop( installRequestObj );
       
   250 
       
   251             TFileName fileName;            
       
   252             TInstallReq params;
       
   253 
       
   254             // Parse filename
       
   255             __ASSERT_ALWAYS( aMessage.GetDesLength( KFileNameIpcSlot ) > 0, 
       
   256                              User::Leave( KErrBadDescriptor ) );
       
   257 
       
   258             aMessage.ReadL( KFileNameIpcSlot, fileName );                
       
   259 
       
   260             if ( opCode == ERequestInstall )
       
   261                 {                
       
   262                 installRequestObj->Install( fileName, params );                
       
   263                 }            
       
   264 
       
   265             else if( opCode == ERequestSilentInstall )
       
   266                 {            
       
   267                 __ASSERT_ALWAYS( aMessage.GetDesLength( KOptionsIpcSlot ) > 0, 
       
   268                                  User::Leave( KErrBadDescriptor ) );
       
   269             
       
   270                 // Parse install options
       
   271                 TInstallOptions options;
       
   272                 TPckg<TInstallOptions> optionsPckg( options );            
       
   273                 aMessage.ReadL( KOptionsIpcSlot, optionsPckg );
       
   274 
       
   275                 installRequestObj->SilentInstall( fileName, params, options );
       
   276                 }
       
   277             
       
   278             else if ( opCode == ERequestInstallParams )
       
   279                 {                              
       
   280                 //TSW JROL-7B8K6H            
       
   281                 TPckg<TInstallReq> paramsPckg( params );        
       
   282                 TInt desLength = aMessage.GetDesLength( KParamsIpcSlot );                 				
       
   283                 __ASSERT_ALWAYS( desLength > 0, 
       
   284                         User::Leave( KErrBadDescriptor ) );                          
       
   285                     
       
   286                 // If length is more then sizeof TInstallReqPckg, input data 
       
   287                 // is stored to to heap. Read data to descriptor.                                  
       
   288                 if ( desLength > sizeof( TInstallReq ) )
       
   289                     {                       	          	
       
   290                     HBufC8* paramDescriptor = HBufC8::NewLC( desLength );
       
   291                     TPtr8 paramDesPtr = paramDescriptor->Des();						                	                                                                
       
   292                     aMessage.ReadL( KParamsIpcSlot, paramDesPtr );                  	
       
   293                     // Get install parameters and store URL to heap. 
       
   294                     GetReqParamsL( *paramDescriptor, params );					
       
   295                     CleanupStack::PopAndDestroy( paramDescriptor ); 		
       
   296                     }
       
   297                 else
       
   298                     {             	
       
   299                     aMessage.ReadL( KParamsIpcSlot, paramsPckg );	
       
   300                     }	
       
   301 
       
   302                 installRequestObj->Install( fileName, params );
       
   303                 }
       
   304             
       
   305             else if ( opCode == ERequestSilentInstallParams )
       
   306                 {                            
       
   307                 __ASSERT_ALWAYS( aMessage.GetDesLength( KParamsIpcSlot ) > 0 && 
       
   308                                  aMessage.GetDesLength( KOptionsIpcSlot ) > 0, 
       
   309                                  User::Leave( KErrBadDescriptor ) );
       
   310 
       
   311                 //TSW JROL-7B8K6H 
       
   312                 TPckg<TInstallReq> paramsPckg( params );        
       
   313                 TInt desLength = aMessage.GetDesLength( KParamsIpcSlot );                 
       
   314                      			                                          
       
   315                 // If length is more then sizeof TInstallReqPckg, input data 
       
   316                 // is stored to to heap. Read data to descriptor.                                  
       
   317                 if ( desLength > sizeof( TInstallReq ) )
       
   318                     {                       	          	
       
   319                     HBufC8* paramDescriptor = HBufC8::NewLC( desLength );
       
   320                     TPtr8 paramDesPtr = paramDescriptor->Des();						                	                                                                
       
   321                     aMessage.ReadL( KParamsIpcSlot, paramDesPtr );                  	
       
   322                     // Get install parameters and store URL to heap. 
       
   323                     GetReqParamsL( *paramDescriptor, params );					
       
   324                     CleanupStack::PopAndDestroy( paramDescriptor ); 		
       
   325                     } 
       
   326                 // Read params to pckg if lenght is more then 0.	               
       
   327                 else
       
   328                     {             	
       
   329                     aMessage.ReadL( KParamsIpcSlot, paramsPckg );	
       
   330                     }	
       
   331                
       
   332                 // Parse install options
       
   333                 TInstallOptions options;
       
   334                 TPckg<TInstallOptions> optionsPckg( options );            
       
   335                 aMessage.ReadL( KOptionsIpcSlot, optionsPckg );                                 
       
   336 
       
   337                 installRequestObj->SilentInstall( fileName, params, options );
       
   338                 }
       
   339 
       
   340             break;            
       
   341             }
       
   342 
       
   343         case ERequestInstallHandle:
       
   344         case ERequestInstallParamsHandle:
       
   345         case ERequestSilentInstallHandle:
       
   346         case ERequestSilentInstallParamsHandle:
       
   347             {
       
   348             // Delete completed requests
       
   349             iRequestStore->Flush();
       
   350                 
       
   351             CSWInstInstallRequest* installRequestObj = CSWInstInstallRequest::NewL( aMessage );
       
   352             CleanupStack::PushL( installRequestObj );
       
   353             // If store is full, this leaves with KSWInstErrBusy
       
   354             iRequestStore->AddRequestL( installRequestObj );  // Ownership transfers to store
       
   355             CleanupStack::Pop( installRequestObj );
       
   356 
       
   357             RFile file;            
       
   358             TInstallReq params;
       
   359 
       
   360             // Get the file handle
       
   361             User::LeaveIfError( file.AdoptFromClient( aMessage, KFileHandleIpcSlot, KFileSrvSessionIpcSlot ) );
       
   362             CleanupClosePushL( file );            
       
   363             
       
   364             if ( opCode == ERequestInstallHandle )
       
   365                 {                
       
   366                 installRequestObj->Install( file, params ); // Ownership of file transfers
       
   367                 CleanupStack::Pop(); // file
       
   368                 }            
       
   369 
       
   370             else if( opCode == ERequestSilentInstallHandle )
       
   371                 {            
       
   372                 __ASSERT_ALWAYS( aMessage.GetDesLength( KOptionsIpcSlot ) > 0, 
       
   373                                  User::Leave( KErrBadDescriptor ) );
       
   374             
       
   375                 // Parse install options
       
   376                 TInstallOptions options;
       
   377                 TPckg<TInstallOptions> optionsPckg( options );            
       
   378                 aMessage.ReadL( KOptionsIpcSlot, optionsPckg );
       
   379 
       
   380                 installRequestObj->SilentInstall( file, params, options ); // Ownership of file transfers
       
   381                 CleanupStack::Pop(); // file
       
   382                 }
       
   383             
       
   384             else if ( opCode == ERequestInstallParamsHandle )
       
   385                 {                        
       
   386                 TPckg<TInstallReq> paramsPckg( params );        
       
   387                 TInt desLength = aMessage.GetDesLength( KParamsIpcSlot );                 				              
       
   388                 __ASSERT_ALWAYS( desLength > 0, 
       
   389                         User::Leave( KErrBadDescriptor ) );                          
       
   390                     
       
   391                 // If length is more then sizeof TInstallReqPckg, input data 
       
   392                 // is stored to to heap. Read data to descriptor.                                           
       
   393                 if ( desLength > sizeof( TInstallReq ) )
       
   394                     {                       	          	
       
   395                     HBufC8* paramDescriptor = HBufC8::NewLC( desLength );
       
   396                     TPtr8 paramDesPtr = paramDescriptor->Des();						                	                                                                
       
   397                     aMessage.ReadL( KParamsIpcSlot, paramDesPtr );                  	
       
   398                     // Get install parameters and store URL to heap. 
       
   399                     GetReqParamsL( *paramDescriptor, params );					
       
   400                     CleanupStack::PopAndDestroy( paramDescriptor ); 		
       
   401                     }
       
   402                 else 
       
   403                     {             	
       
   404                     aMessage.ReadL( KParamsIpcSlot, paramsPckg );	
       
   405                     }	
       
   406 
       
   407                 installRequestObj->Install( file, params ); // Ownership of file transfers
       
   408                 CleanupStack::Pop(); // file                
       
   409                 }
       
   410             
       
   411             else if ( opCode == ERequestSilentInstallParamsHandle )
       
   412                 {                          
       
   413                 __ASSERT_ALWAYS( aMessage.GetDesLength( KParamsIpcSlot ) > 0 && 
       
   414                                  aMessage.GetDesLength( KOptionsIpcSlot ) > 0, 
       
   415                                  User::Leave( KErrBadDescriptor ) );
       
   416 
       
   417                 TPckg<TInstallReq> paramsPckg( params );        
       
   418                 TInt desLength = aMessage.GetDesLength( KParamsIpcSlot );                 
       
   419                      			                                          
       
   420                 // If length is more then sizeof TInstallReqPckg, input data 
       
   421                 // is stored to to heap. Read data to descriptor.                                  
       
   422                 if ( desLength > sizeof( TInstallReq ) )
       
   423                     {                       	          	
       
   424                     HBufC8* paramDescriptor = HBufC8::NewLC( desLength );
       
   425                     TPtr8 paramDesPtr = paramDescriptor->Des();						                	                                                                
       
   426                     aMessage.ReadL( KParamsIpcSlot, paramDesPtr );                  	
       
   427                     // Get install parameters and store URL to heap. 
       
   428                     GetReqParamsL( *paramDescriptor, params );					
       
   429                     CleanupStack::PopAndDestroy( paramDescriptor ); 		
       
   430                     }
       
   431                 else 
       
   432                     {             	
       
   433                     aMessage.ReadL( KParamsIpcSlot, paramsPckg );	
       
   434                     }	
       
   435                
       
   436                 // Parse install options
       
   437                 TInstallOptions options;
       
   438                 TPckg<TInstallOptions> optionsPckg( options );
       
   439                 aMessage.ReadL( KOptionsIpcSlot, optionsPckg );
       
   440 
       
   441                 installRequestObj->SilentInstall( file, params, options ); // Ownership of file transfers
       
   442                 CleanupStack::Pop(); // file
       
   443                 }
       
   444 
       
   445             break;            
       
   446             }
       
   447             
       
   448         case ERequestUninstall:
       
   449         case ERequestSilentUninstall:
       
   450             {
       
   451             // Delete completed requests
       
   452             iRequestStore->Flush();
       
   453 
       
   454             CSWInstUninstallRequest* uninstRequestObj = CSWInstUninstallRequest::NewL( aMessage );
       
   455             CleanupStack::PushL( uninstRequestObj );                
       
   456             // If store is full, this leaves with KSWInstErrBusy
       
   457             iRequestStore->AddRequestL( uninstRequestObj );  // Ownership transfers to store
       
   458             CleanupStack::Pop( uninstRequestObj );  
       
   459            
       
   460             TUid uid;
       
   461             HBufC8* mime = NULL;
       
   462         
       
   463             if ( opCode == ERequestUninstall )
       
   464                 {            
       
   465                  __ASSERT_ALWAYS( aMessage.GetDesLength( KMimeIpcSlot ) > 0, 
       
   466                              User::Leave( KErrBadDescriptor ) );
       
   467 
       
   468                 // Parse Uid            
       
   469                 uid.iUid = GetInt( aMessage, KUidIpcSlot );                
       
   470 
       
   471                 // Parse the mime
       
   472                 mime = HBufC8::NewLC( aMessage.GetDesLength( KMimeIpcSlot ) );
       
   473                 TPtr8 ptr( mime->Des() );            
       
   474                 aMessage.ReadL( KMimeIpcSlot, ptr );
       
   475             
       
   476                 uninstRequestObj->Uninstall( uid, *mime );
       
   477                 CleanupStack::PopAndDestroy( mime );            
       
   478                 }
       
   479             
       
   480             else if ( opCode == ERequestSilentUninstall )
       
   481                 {            
       
   482                 __ASSERT_ALWAYS( aMessage.GetDesLength( KOptionsIpcSlot ) > 0 && 
       
   483                                  aMessage.GetDesLength( KMimeIpcSlot ) > 0, 
       
   484                                  User::Leave( KErrBadDescriptor ) );
       
   485             
       
   486                 // Parse Uid                
       
   487                 uid.iUid = GetInt( aMessage, KUidIpcSlot );                
       
   488 
       
   489                 TUninstallOptions options;            
       
   490                 // Parse uninstall options
       
   491                 TPckg<TUninstallOptions> optionsPckg( options );
       
   492                 aMessage.ReadL( KOptionsIpcSlot, optionsPckg );
       
   493 
       
   494                 // Parse the mime
       
   495                 mime = HBufC8::NewLC( aMessage.GetDesLength( KMimeIpcSlot ) );
       
   496                 TPtr8 ptr( mime->Des() );            
       
   497                 aMessage.ReadL( KMimeIpcSlot, ptr );
       
   498 
       
   499                 uninstRequestObj->SilentUninstall( uid, *mime, options );
       
   500                 CleanupStack::PopAndDestroy( mime );
       
   501                 }
       
   502 
       
   503             break;        
       
   504             }            
       
   505 
       
   506         case ERequestCustomUninstall:
       
   507         case ERequestSilentCustomUninstall:
       
   508             {
       
   509             __ASSERT_ALWAYS( aMessage.GetDesLength( KCommonParamsIpcSlot ) > 0 &&
       
   510                              aMessage.GetDesLength( KMimeIpcSlot ) > 0,
       
   511                              User::Leave( KErrBadDescriptor ) );
       
   512 
       
   513              // Get the operation we need to perform
       
   514             TOperation operation = (TOperation) GetInt( aMessage, KOperationIpcSlot );
       
   515 
       
   516             // Get the params
       
   517             HBufC8* params = HBufC8::NewLC( aMessage.GetDesLength( KCommonParamsIpcSlot ) );
       
   518             TPtr8 paramPtr( params->Des() );            
       
   519             aMessage.ReadL( KCommonParamsIpcSlot, paramPtr );
       
   520 
       
   521             // Parse the mime
       
   522             HBufC8* mime = HBufC8::NewLC( aMessage.GetDesLength( KMimeIpcSlot ) );
       
   523             TPtr8 mimePtr( mime->Des() );            
       
   524             aMessage.ReadL( KMimeIpcSlot, mimePtr );
       
   525 
       
   526             // Delete completed requests
       
   527             iRequestStore->Flush();
       
   528             
       
   529             CSWInstUninstallRequest* uninstRequestObj = CSWInstUninstallRequest::NewL( aMessage );
       
   530             CleanupStack::PushL( uninstRequestObj );                
       
   531             // If store is full, this leaves with KSWInstErrBusy
       
   532             iRequestStore->AddRequestL( uninstRequestObj );  // Ownership transfers to store
       
   533             CleanupStack::Pop( uninstRequestObj );  
       
   534             
       
   535             if ( opCode == ERequestSilentCustomUninstall )
       
   536                 {
       
   537                 __ASSERT_ALWAYS( aMessage.GetDesLength( KOptionsIpcSlot ) > 0,
       
   538                                  User::Leave( KErrBadDescriptor ) );
       
   539 
       
   540                 TUninstallOptions options;            
       
   541                 // Parse uninstall options
       
   542                 TPckg<TUninstallOptions> optionsPckg( options );
       
   543                 aMessage.ReadL( KOptionsIpcSlot, optionsPckg );
       
   544 
       
   545                 uninstRequestObj->SilentCustomUninstall( operation, options, *params, *mime );
       
   546                 }
       
   547             else
       
   548                 {                
       
   549                 uninstRequestObj->CustomUninstall( operation, *params, *mime );
       
   550                 }            
       
   551 
       
   552             CleanupStack::PopAndDestroy( 2, params );            
       
   553             }
       
   554             
       
   555             break;          
       
   556 
       
   557         default:
       
   558             CAknAppServiceBase::ServiceL( aMessage );
       
   559             break;            
       
   560         }
       
   561        
       
   562     }    
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // CSWInstSession::SecurityCheckL
       
   566 // Virtual framework function that is called on receipt of a message from the 
       
   567 // client. This allows the service implementation to define a security policy 
       
   568 // for messages from the client. 
       
   569 // (other items were commented in a header).
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 CPolicyServer::TCustomResult CSWInstSession::SecurityCheckL( const RMessage2& aMsg, 
       
   573                                                              TInt& aAction, 
       
   574                                                              TSecurityInfo& aMissing )
       
   575     {
       
   576     switch ( aMsg.Function() )
       
   577         {
       
   578         case ERequestSilentInstall:
       
   579         case ERequestSilentInstallParams:
       
   580         case ERequestSilentUninstall:
       
   581         case ERequestSilentInstallHandle:
       
   582         case ERequestSilentInstallParamsHandle:
       
   583 
       
   584             if ( aMsg.HasCapability( TCapability( ECapabilityTrustedUI ) ) )
       
   585                 {
       
   586                 // AllFiles capability required to install untrusted SW silently.
       
   587                 if( aMsg.Function() != ERequestSilentUninstall )
       
   588                     {
       
   589                     TInstallOptions options;
       
   590                     TPckg<TInstallOptions> optionsPckg( options );
       
   591                     aMsg.ReadL( KOptionsIpcSlot, optionsPckg );
       
   592                     if( options.iUntrusted == EPolicyAllowed )
       
   593                         {
       
   594                         if( !aMsg.HasCapability( TCapability( ECapabilityAllFiles ) ) )
       
   595                             {
       
   596                             return CPolicyServer::EFail;
       
   597                             }
       
   598                         }
       
   599                     }
       
   600 
       
   601                 return CPolicyServer::EPass;
       
   602                 }
       
   603             else
       
   604                 {
       
   605                 return CPolicyServer::EFail;
       
   606                 }            
       
   607 
       
   608         case ERequestInstall:
       
   609         case ERequestInstallParams:
       
   610         case ERequestUninstall:
       
   611         case ERequestInstallHandle:
       
   612         case ERequestInstallParamsHandle:
       
   613         case ERequestCancelRequest:
       
   614             // No capabilities needed for these
       
   615             return CPolicyServer::EPass;            
       
   616 
       
   617         default:
       
   618             // Not recognized message, pass to CAknAppServiceBase
       
   619             return CAknAppServiceBase::SecurityCheckL( aMsg, aAction, aMissing );            
       
   620         }    
       
   621     }
       
   622 
       
   623 // -----------------------------------------------------------------------------
       
   624 // CSWInstSession::GetInt
       
   625 // Helper to retrieve an int parameter from message.
       
   626 // (other items were commented in a header).
       
   627 // -----------------------------------------------------------------------------
       
   628 //
       
   629 TInt CSWInstSession::GetInt( const RMessage2& aMessage, TInt aIpcSlot )
       
   630     {
       
   631     switch ( aIpcSlot )
       
   632         {
       
   633         case 0:
       
   634             return aMessage.Int0();
       
   635         case 1:
       
   636             return aMessage.Int1();
       
   637         case 2:
       
   638             return aMessage.Int2();
       
   639         case 3:
       
   640             return aMessage.Int3();              
       
   641         default:
       
   642             return 0;            
       
   643         }    
       
   644     }
       
   645 
       
   646 // -----------------------------------------------------------------------------
       
   647 // CSWInstSession::SendAppToBackgroundL
       
   648 // Sends application to background. This is used in silent install to prevent
       
   649 // blocking of other applications UI.
       
   650 // -----------------------------------------------------------------------------
       
   651 //
       
   652 void CSWInstSession::SendAppToBackgroundL()
       
   653     {    	                                                
       
   654     RWsSession ws;   
       
   655                                              
       
   656     if ( ws.Connect() == KErrNone )
       
   657         {
       
   658         CleanupClosePushL(ws);        
       
   659         TApaTaskList tasklist(ws);   
       
   660                  
       
   661         TApaTask task = tasklist.FindApp( TUid::Uid(KSWInstSvrUid) );
       
   662                         
       
   663         if ( task.Exists() )
       
   664             {                                       
       
   665             task.SendToBackground();              
       
   666             // Set to false, so we do not do this again.            
       
   667             iAppInForeground = EFalse;                                                      
       
   668             } 
       
   669                                                                
       
   670         CleanupStack::PopAndDestroy(); //ws       
       
   671         }                           
       
   672     }
       
   673 
       
   674 
       
   675 // -----------------------------------------------------------------------------
       
   676 // CSWInstSession::IsShowingDialog()
       
   677 // From MCUICancellable. Function returns always ETrue so StartCancelling() 
       
   678 // function will start cancelling the dialog.
       
   679 // -----------------------------------------------------------------------------
       
   680 //
       
   681 TBool CSWInstSession::IsShowingDialog()
       
   682     {
       
   683     return ETrue;
       
   684     }
       
   685 
       
   686 // -----------------------------------------------------------------------------
       
   687 // CSWInstSession::CancelEngine()
       
   688 // From MCUICancellable. 
       
   689 // -----------------------------------------------------------------------------
       
   690 //
       
   691 void CSWInstSession::CancelEngine()
       
   692     {    
       
   693     }
       
   694 
       
   695 // -----------------------------------------------------------------------------
       
   696 // CSWInstSession::ForceCancel()
       
   697 // From MCUICancellable. 
       
   698 // -----------------------------------------------------------------------------
       
   699 //          
       
   700 void CSWInstSession::ForceCancel()
       
   701     {        
       
   702     }
       
   703 
       
   704 // -----------------------------------------------------------------------------
       
   705 // CSWInstSession::StartedCancellingL()
       
   706 // From MCUICancellable. 
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 void CSWInstSession::StartedCancellingL()
       
   710     {    
       
   711     }
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // CSWInstSession::GetReqParamsL
       
   715 // Reads parameters from descriptor to TInstallReg and buffer.
       
   716 // -----------------------------------------------------------------------------
       
   717 //    
       
   718 void CSWInstSession::GetReqParamsL( TDesC8& aParamsDes, TInstallReq& aParams )	
       
   719     {   
       
   720     // Delete previous URL.
       
   721     delete iHeapSourceUrl;
       
   722     iHeapSourceUrl = NULL; 
       
   723 
       
   724     RDesReadStream paramStream( aParamsDes );
       
   725     CleanupClosePushL( paramStream );
       
   726 
       
   727     TPckg<TInstallReq> paramsPckg( aParams );
       
   728     // Read install parameters to pckg.
       
   729     paramStream.ReadL( paramsPckg );
       
   730     // Get length of url
       
   731     TInt urlLength = paramStream.ReadInt32L();
       
   732     
       
   733     
       
   734     // Check the url lenght. 
       
   735     // Note that given url length may be zero in some cases.
       
   736     if( urlLength )
       
   737         {         
       
   738         iHeapSourceUrl = HBufC::NewL( urlLength );	
       
   739         TPtr urlPtr = iHeapSourceUrl->Des();        
       
   740         // Get url to heap descriptor
       
   741         paramStream.ReadL( urlPtr, urlLength );        	
       
   742         // Set url's pointer.		
       
   743         TInstallReqHeapURL heapURL;                                           								                                                                                        
       
   744         heapURL.iSourcePtr = iHeapSourceUrl;            
       
   745 
       
   746         TInstallReqURLPckg heapPckg( heapURL );         	
       
   747         // Copy url pointer to TInstallReg params.     	         	            
       
   748         aParams.iSourceURL.Copy( heapPckg );            
       
   749         }
       
   750 
       
   751     CleanupStack::PopAndDestroy( &paramStream );              				
       
   752     }        
       
   753     
       
   754 //  End of File