applicationmanagement/server/src/ApplicationManagementServer.cpp
changeset 18 7d11f9a6646f
parent 4 75a71fdb4c92
child 21 c707676bf59f
equal deleted inserted replaced
4:75a71fdb4c92 18:7d11f9a6646f
     1 /*
       
     2  * Copyright (c) 2000 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: Implementation of applicationmanagement components
       
    15  *
       
    16  */
       
    17 
       
    18 #define __INCLUDE_CAPABILITY_NAMES__
       
    19 
       
    20 #include <e32svr.h>
       
    21 #include <badesca.h>
       
    22 #include <e32cmn.h>
       
    23 #include <bautils.h> 
       
    24 #include <featmgr.h>
       
    25 #include <imcvcodc.h>
       
    26 #include <uikon.hrh>
       
    27 #include <e32property.h>
       
    28 #include "ApplicationManagementConst.h"
       
    29 #include "ampskeys.h"
       
    30 #include <SWInstDefs.h>
       
    31 #include "amprivateCRKeys.h"
       
    32 #include <PolicyEngineClient.h>
       
    33 #include <PolicyEngineXACML.h>
       
    34 #include <pathinfo.h>
       
    35 #include <driveinfo.h>
       
    36 
       
    37 #include "ApplicationManagementCommon.h"
       
    38 #include "ApplicationManagementClientServer.h"
       
    39 #include "ApplicationManagementServer.h"
       
    40 #include "AMDeploymentComponent.h"
       
    41 #include "amsmlhelper.h"
       
    42 #include "ApplicationManagementUtility.h"
       
    43 #include "ApplicationManagementUtilityFactory.h"
       
    44 
       
    45 #include "debug.h"
       
    46 
       
    47 #include "coemain.h"
       
    48 #include <aknnotewrappers.h>
       
    49 #include "SyncService.h"
       
    50 #include "AMPreInstallApp.h"
       
    51 #include <DevManInternalCRKeys.h>
       
    52 
       
    53 using namespace NApplicationManagement;
       
    54 
       
    55 #ifdef __AM_CONNECT_INSTALLER_ONSTARTUP_	
       
    56 
       
    57 #pragma message("AM Connecting installer at startup")
       
    58 #else
       
    59 #pragma message("AM Connecting installer when needed")
       
    60 #endif
       
    61 
       
    62 // Needed only for jad+jar installation  
       
    63 _LIT( KInstallDir, "c:\\temp\\" );
       
    64 _LIT8(KMIDletJarURL, "MIDlet-Jar-URL");
       
    65 
       
    66 //OMA SCOMO Specific
       
    67 _LIT8(KDownloadState, "./SCOMO/Download/");
       
    68 _LIT8(KDeliveredState, "./SCOMO/Inventory/Delivered/");
       
    69 _LIT8(KDeployedState, "./SCOMO/Inventory/Deployed/");
       
    70 
       
    71 // ------------------------------------------------------------------------------------------------
       
    72 // CShutDown::CShutdown()
       
    73 // ------------------------------------------------------------------------------------------------
       
    74 
       
    75 inline CShutdown::CShutdown() :
       
    76     CTimer(-1)
       
    77     {
       
    78     CActiveScheduler::Add(this);
       
    79     }
       
    80 
       
    81 // ------------------------------------------------------------------------------------------------
       
    82 // CShutDown::ConstructL()
       
    83 // ------------------------------------------------------------------------------------------------
       
    84 
       
    85 inline void CShutdown::ConstructL()
       
    86     {
       
    87     CTimer::ConstructL();
       
    88     }
       
    89 
       
    90 // ------------------------------------------------------------------------------------------------
       
    91 // CShutDown::Start()
       
    92 // ------------------------------------------------------------------------------------------------
       
    93 
       
    94 inline void CShutdown::Start()
       
    95     {
       
    96     RDEBUG( "ApplicationManagementServer: starting shutdown timeout" );
       
    97     After(KApplicationManagementShutdownDelay);
       
    98     }
       
    99 
       
   100 // ------------------------------------------------------------------------------------------------
       
   101 // CShutDown::RunL()
       
   102 // ------------------------------------------------------------------------------------------------
       
   103 
       
   104 void CShutdown::RunL()
       
   105     {
       
   106     RDEBUG( "ApplicationManagementServer timeout ... closing" );
       
   107     CActiveScheduler::Stop();
       
   108     }
       
   109 
       
   110 // ------------------------------------------------------------------------------------------------
       
   111 // CShutDown::Start()
       
   112 // ------------------------------------------------------------------------------------------------
       
   113 
       
   114 inline void CShutdown::Stop()
       
   115     {
       
   116     RDEBUG( "ApplicationManagementServer: Stop" );
       
   117     CActiveScheduler::Stop();
       
   118     }
       
   119 
       
   120 
       
   121 // ------------------------------------------------------------------------------------------------
       
   122 // CApplicationManagementServer::CreateServiceL()
       
   123 // ------------------------------------------------------------------------------------------------
       
   124 CApaAppServiceBase* CApplicationManagementServer::CreateServiceL(
       
   125         TUid aServiceType) const
       
   126     {
       
   127     RDEBUG( "ApplicationManagementServer CreateServiceL" );
       
   128     if (aServiceType.iUid == KAMServiceUid)
       
   129         {
       
   130         return ((CApaAppServiceBase*) (new (ELeave) CApplicationManagementSession));
       
   131         }
       
   132     else
       
   133         {
       
   134         return CAknAppServer::CreateServiceL(aServiceType);
       
   135         }
       
   136     }
       
   137 
       
   138 // ------------------------------------------------------------------------------------------------
       
   139 // CApplicationManagementServer::SendServerToBackground()
       
   140 // ------------------------------------------------------------------------------------------------
       
   141 
       
   142 void CApplicationManagementServer::SendServerToBackground()
       
   143     {
       
   144 
       
   145     RDEBUG( "ApplicationManagementServer SendServerToBackground - Start " );
       
   146     TApaTaskList taskList(CEikonEnv::Static()->WsSession() );
       
   147     TApaTask task = taskList.FindApp(TUid::Uid(KAppMgmtServerUid));
       
   148     
       
   149      TInt id = CEikonEnv::Static()->RootWin().Identifier();
       
   150 
       
   151     RDEBUG_2( "CApplicationManagementServer:::SendServerToBackground %d", id );
       
   152 	
       
   153     task.SetWgId(id);
       
   154 
       
   155     if (task.Exists())
       
   156         {
       
   157 	RDEBUG( "ApplicationManagementServer SendServerToBackground - Start 1" );
       
   158         task.SendToBackground();
       
   159         }
       
   160     RDEBUG( "ApplicationManagementServer SendServerToBackground - End " );
       
   161     TInt amServerEnabled = 0;
       
   162     RProperty::Set(KUidPSApplicationManagementKeys, KAMServerUIEnabled,
       
   163             amServerEnabled);
       
   164     RDEBUG( "ApplicationManagementServer SendServerToBackground - End 2 " );
       
   165 
       
   166     }
       
   167 
       
   168 // ------------------------------------------------------------------------------------------------
       
   169 // CApplicationManagementServer::BringServertoForeground()
       
   170 // ------------------------------------------------------------------------------------------------
       
   171 
       
   172 void CApplicationManagementServer::BringServertoForeground()
       
   173     {
       
   174 
       
   175     RDEBUG( "CApplicationManagementServer:::BringServertoForeground " );
       
   176     TApaTaskList taskList(CEikonEnv::Static()->WsSession() );
       
   177     TApaTask task = taskList.FindApp(TUid::Uid(KAppMgmtServerUid));
       
   178 
       
   179     TInt id = CEikonEnv::Static()->RootWin().Identifier();
       
   180 
       
   181     RDEBUG_2( "CApplicationManagementServer:::BringServertoForeground %d", id );
       
   182 	
       
   183     task.SetWgId(id);
       
   184     if (task.Exists())
       
   185         {
       
   186 	RDEBUG( "ApplicationManagementServer SendServerToBackground - BringServertoForeground " );
       
   187         task.BringToForeground();
       
   188         }
       
   189     }
       
   190 
       
   191 // ------------------------------------------------------------------------------------------------
       
   192 // CApplicationManagementServer::BringServertoForeground()
       
   193 // ------------------------------------------------------------------------------------------------
       
   194 
       
   195 void CApplicationManagementServer::BringDMUItoForeground()
       
   196     {
       
   197     RDEBUG( "ApplicationManagementServer DownloadComplete - DM UI Broughtto foreground Start " );
       
   198 
       
   199     TApaTaskList taskList(CEikonEnv::Static()->WsSession() );
       
   200     TApaTask task = taskList.FindApp(KPSUidNSmlDMSyncApp);
       
   201 
       
   202     const TInt id = task.WgId();
       
   203     task.SetWgId(id);
       
   204     RDEBUG_2( "CApplicationManagementServer:::BringDMUItoForeground %d", id );
       
   205     
       
   206     if (task.Exists())
       
   207         {
       
   208         RDEBUG( "ApplicationManagementServer DownloadComplete - DM UI Broughtto foreground " );
       
   209         task.BringToForeground();
       
   210         }
       
   211     }
       
   212 
       
   213 // ------------------------------------------------------------------------------------------------
       
   214 // CApplicationManagementServer::ComponentDownloadComplete()
       
   215 // ------------------------------------------------------------------------------------------------
       
   216 
       
   217 void CApplicationManagementServer::ComponentDownloadComplete(
       
   218         CDeploymentComponent *aComponent, TInt iapid, HBufC8 *aServerId)
       
   219     {
       
   220     TInt err = KErrNone;
       
   221     TRAP( err, DownloadCompleteL( aComponent, iapid, aServerId ));
       
   222     }
       
   223 
       
   224 // ------------------------------------------------------------------------------------------------
       
   225 // CApplicationManagementServer::DownloadCompleteL()
       
   226 // ------------------------------------------------------------------------------------------------
       
   227 
       
   228 void CApplicationManagementServer::DownloadCompleteL(
       
   229         CDeploymentComponent *aComponent, TInt iapid, HBufC8 *aServerId)
       
   230     {
       
   231     RDEBUG( "ApplicationManagementServer DownloadComplete - start" );
       
   232     __ASSERT_DEBUG( aComponent, User::Invariant() );
       
   233     iStorage->UpdateL( *aComponent);
       
   234     TInt errdownload = KErrNone;
       
   235     TInt errInstall = KErrNone;
       
   236     TInt status = KStatusSuccess;
       
   237     if ( !aComponent->DownloadFailed() )
       
   238         {
       
   239         CDeploymentComponent *old = DoDataUpdateCheckL( *aComponent);
       
   240         TDownloadTarget trgt = aComponent->DownloadTarget();
       
   241         switch (trgt)
       
   242             {
       
   243             case EDeliver:
       
   244                 {
       
   245                 break;
       
   246                 }
       
   247             case EInstall:
       
   248             case EInstallAndActivate:
       
   249                 {
       
   250                 TRAP(errInstall,DoTheInstallL( *aComponent));
       
   251                 if (trgt == EInstall && errInstall == KErrNone)
       
   252                     {
       
   253                     iStorage->DeactivateL( *aComponent);
       
   254                     }
       
   255                 /* to avoid duplicates in deployed tree if user delivered upgrade package
       
   256                  * by using "Install/InstallActivate" operation. if upgrade package is delivered 
       
   257                  * by Update/UpdateandActivate" , this been handled in next switch case
       
   258                  */
       
   259 
       
   260                 break;
       
   261                 }
       
   262 
       
   263             case EUpdate:
       
   264             case EUpdateAndActivate:
       
   265                 {
       
   266                 if (old)
       
   267                     {
       
   268                     FullUpdateL( *aComponent, *old);
       
   269                     if (trgt == EUpdate)
       
   270                         {
       
   271                         iStorage->DeactivateL( *aComponent);
       
   272                         }
       
   273                     }
       
   274                 break;
       
   275                 }
       
   276             default:
       
   277                 {
       
   278                 break;
       
   279                 }
       
   280             }
       
   281 
       
   282         }
       
   283     else
       
   284         {
       
   285         errdownload = aComponent->DownloadStatus();
       
   286         }
       
   287 
       
   288     RDEBUG( "ApplicationManagementServer DownloadComplete - Start Send to background" );
       
   289     //Download Completed/ Failed or installation success/ failure Send server to Background.
       
   290 
       
   291     SendServerToBackground();
       
   292 
       
   293     // Bring DM UI to foreground provided operation is in non silent mode.
       
   294     TInt operNonSilent = KErrNotFound;
       
   295 
       
   296     RProperty::Get(KUidPSApplicationManagementKeys, KAMOperationNonSilent,
       
   297             operNonSilent);
       
   298 
       
   299     if (operNonSilent==1 || operNonSilent==KErrNotFound)
       
   300         {
       
   301         RDEBUG( "ApplicationManagementServer DownloadComplete - DM UI Bring " );
       
   302         BringDMUItoForeground();
       
   303         }
       
   304 
       
   305     iOMASCOMOEnabled = IsOMASCOMOEnabledL();
       
   306 		
       
   307 
       
   308     if (iOMASCOMOEnabled)
       
   309         {
       
   310 
       
   311 
       
   312 				status = GetErrorStatus(errdownload,errInstall); 
       
   313 		      
       
   314         TInt ASyncSupported = -1;
       
   315 
       
   316         CRepository *repository = CRepository::NewLC( KUidPSApplicationManagementKeys );
       
   317         repository->Get(KAsyncEnabled, ASyncSupported);
       
   318         CleanupStack::PopAndDestroy();
       
   319         
       
   320         // For Sync Reporting
       
   321         if (!ASyncSupported)
       
   322             {
       
   323             
       
   324             // Update Central Repository with proper error code for Sync
       
   325             
       
   326            
       
   327             CRepository *repository= CRepository::NewLC ( KUidPSApplicationManagementKeys ) ;
       
   328             repository->Set(KAMSyncStatus, status);
       
   329             CleanupStack::PopAndDestroy();
       
   330                         
       
   331             RProperty counter;
       
   332             
       
   333             TInt r=counter.Attach(KUidPSApplicationManagementKeys,
       
   334                     KSyncNotifier, EOwnerThread);
       
   335             User::LeaveIfError(r);
       
   336 
       
   337             TInt err = counter.Set(KErrCancel);
       
   338             User::LeaveIfError(err);
       
   339             counter.Close();
       
   340 
       
   341             }
       
   342         else// Do AsyncReporting
       
   343             {
       
   344 
       
   345             // Get deployement component entries
       
   346             TInt internalid = aComponent->InternalId();
       
   347 
       
   348             TBuf8<256> targetURI;
       
   349 
       
   350             TDeploymentComponentState state = aComponent->State();
       
   351 
       
   352             if (state == EDCSDownload)
       
   353                 {
       
   354                 targetURI.Append(KDownloadState);
       
   355                 targetURI.Append(aComponent->UserId());
       
   356                 }
       
   357             else
       
   358                 if (state == EDCSDelivered)
       
   359                     {
       
   360                     targetURI.Append(KDeliveredState);
       
   361                     targetURI.Append(aComponent->UserId());
       
   362 
       
   363                     }
       
   364                 else
       
   365                     if (state == EDCSActive|| state == EDCSInactive)
       
   366                         {
       
   367                         targetURI.Append(KDeployedState);
       
   368                         targetURI.Append(aComponent->UserId());
       
   369                         }
       
   370 
       
   371             //Save Entry to database with status and target URI of deployment component
       
   372 
       
   373             TInt index;
       
   374             iAMServerDB->SaveToDatabaseL(index, internalid, status,
       
   375                     targetURI, iapid);
       
   376 
       
   377             EnableDMNetworkMonL(iapid, aServerId);
       
   378             }
       
   379 
       
   380         }
       
   381     if (iDownloadMngr->DownloadCount() == 0)
       
   382         {
       
   383         
       
   384         RDEBUG_2( "CApplicationManagementServer::ConstructL - ERROR leaving cannot connect installer: %d", iSessionCount );
       
   385         
       
   386         // Is session count is not modified whenever there is error then at the end of download complete decrement
       
   387         //  the session count.
       
   388         
       
   389         if(status != KStatusSuccess && iSessionCount != 0 )
       
   390             {
       
   391             iSessionCount--; 
       
   392             }
       
   393        
       
   394         if (iSessionCount == 0)
       
   395             {  
       
   396 		       iShutdown.Stop();
       
   397             }
       
   398         }
       
   399 
       
   400     RDEBUG( "ApplicationManagementServer DownloadComplete - end" );
       
   401     }
       
   402 
       
   403 // ------------------------------------------------------------------------------------------------
       
   404 // CApplicationManagementServer::IsOMASCOMOEnabledL()
       
   405 // ------------------------------------------------------------------------------------------------
       
   406 
       
   407 TBool CApplicationManagementServer::IsOMASCOMOEnabledL()
       
   408     {
       
   409     TInt adapterValue;
       
   410     
       
   411     CRepository *repository = CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys ) ;
       
   412     repository->Get(KAMAdapterValue, adapterValue);
       
   413     CleanupStack::PopAndDestroy();
       
   414     
       
   415     if(adapterValue ==0 || adapterValue == 1)
       
   416      return EFalse;
       
   417     else
       
   418      return ETrue;
       
   419     
       
   420     }
       
   421 
       
   422 // ------------------------------------------------------------------------------------------------
       
   423 // CApplicationManagementServer::GetErrorStatus()
       
   424 // ------------------------------------------------------------------------------------------------
       
   425 TInt CApplicationManagementServer::GetErrorStatus(TInt aErrorDownload, TInt aErrorInstall)
       
   426 {
       
   427 	       TInt status = KStatusSuccess;
       
   428 	       
       
   429 	       if (aErrorDownload!=KErrNone)
       
   430                 {
       
   431                 if (aErrorDownload == KStatusUserCancelled || aErrorDownload
       
   432                         == KStatusDowloadFailedOOM || aErrorDownload
       
   433                          == KStatusUnSupportedEnvironment || aErrorDownload 
       
   434                         ==KStatusAlternateDownldAuthFail || aErrorDownload == KStatusAltDowldUnavailable)
       
   435                     {
       
   436                     status = aErrorDownload;
       
   437                     }
       
   438                 else
       
   439                     status = KStatusDownloadFailed;
       
   440                 }
       
   441 
       
   442             else
       
   443                 if (aErrorInstall!=KErrNone)
       
   444                     {
       
   445                     if (aErrorInstall == SwiUI::KSWInstErrSecurityFailure)
       
   446                         status = KStatusPkgValidationFailed;
       
   447                     if (aErrorInstall == SwiUI::KSWInstErrInsufficientMemory)
       
   448                         status = KStatusInstallFailedOOM;
       
   449                     else
       
   450                         status = KStatusInstallFailed;
       
   451 
       
   452                     }
       
   453                     
       
   454            return status;
       
   455 
       
   456 }
       
   457 
       
   458    
       
   459 // ------------------------------------------------------------------------------------------------
       
   460 // CApplicationManagementServer::EnableDMNetworkMonL()
       
   461 // ------------------------------------------------------------------------------------------------
       
   462 void CApplicationManagementServer::EnableDMNetworkMonL(TInt iapid, HBufC8 *aServerId)
       
   463 {
       
   464 						TInt retryenabled = 1;
       
   465 						_LIT( KNetMon,"\\dmnetworkmon.exe" );
       
   466             
       
   467             // Enable DM Network Monitoring for retry of Generic alert in case of N/W loss
       
   468 
       
   469             CRepository *repository= CRepository::NewLC ( KCRUidDeviceManagementInternalKeys );
       
   470             repository->Set(KDevManEnableDMNetworkMon, retryenabled);
       
   471             repository->Set(KDevManServerIdKey, *aServerId);
       
   472             repository->Set(KDevManIapIdKey, iapid);
       
   473             CleanupStack::PopAndDestroy();
       
   474                
       
   475 						// create NetMon EXE
       
   476             RProcess rp;
       
   477             TInt err = rp.Create(KNetMon,KNullDesC);
       
   478             User::LeaveIfError(err);
       
   479             TRequestStatus stat;
       
   480             rp.Rendezvous(stat);
       
   481                             
       
   482             if (stat!=KRequestPending)
       
   483               rp.Kill(0);     // abort startup
       
   484             else
       
   485               rp.Resume();    // logon OK - start the server
       
   486             TInt r=(rp.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
   487                         rp.Close();
       
   488 
       
   489 	
       
   490 }
       
   491 
       
   492 // ------------------------------------------------------------------------------------------------
       
   493 // CApplicationManagementServer::CApplicationManagementServer
       
   494 // ------------------------------------------------------------------------------------------------
       
   495 
       
   496 inline CApplicationManagementServer::CApplicationManagementServer()
       
   497     {
       
   498     }
       
   499 
       
   500 // ------------------------------------------------------------------------------------------------
       
   501 // CApplicationManagementServer::AddSession()
       
   502 // ------------------------------------------------------------------------------------------------
       
   503 
       
   504 void CApplicationManagementServer::AddSession()
       
   505     {
       
   506     // A new session is being created
       
   507     RDEBUG( "ApplicationManagementServer: CApplicationManagementServer::AddSession" );
       
   508     ++iSessionCount;
       
   509 
       
   510     // Cancel the shutdown timer if it was running
       
   511     iShutdown.Cancel();
       
   512     }
       
   513 
       
   514 // ------------------------------------------------------------------------------------------------
       
   515 // CApplicationManagementServer::DropSession()
       
   516 // ------------------------------------------------------------------------------------------------
       
   517 
       
   518 void CApplicationManagementServer::DropSession()
       
   519     {
       
   520     // A session is being destroyed
       
   521     RDEBUG( "ApplicationManagementServer: CApplicationManagementServer::DropSession" );
       
   522 
       
   523     // Start the shutdown timer if it is the last session
       
   524     if ( --iSessionCount == 0)
       
   525         {
       
   526         if (iDownloadMngr->DownloadCount() > 0)
       
   527             {
       
   528             RDEBUG( "ApplicationManagementServer: CApplicationManagementServer::DropSession download in progress" );
       
   529             }
       
   530         else
       
   531             {
       
   532             iShutdown.Start();
       
   533             }
       
   534         }
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------------------------------------
       
   538 // CApplicationManagementServer::AddDownloadL( CDeploymentComponent *aComponent )
       
   539 // -----------------------------------------------------------------------------------------------------------
       
   540 
       
   541 void CApplicationManagementServer::AddDownloadL(
       
   542         CDeploymentComponent *aComponent)
       
   543     {
       
   544     __ASSERT_DEBUG( aComponent, User::Invariant() );
       
   545     iDownloadMngr->AddDownloadL(aComponent);
       
   546     }
       
   547 
       
   548 // ------------------------------------------------------------------------------------------------
       
   549 // CApplicationManagementServer::NewLC
       
   550 // ------------------------------------------------------------------------------------------------
       
   551 
       
   552 CApplicationManagementServer* CApplicationManagementServer::NewL()
       
   553     {
       
   554 
       
   555     CApplicationManagementServer* self=new(ELeave) CApplicationManagementServer;
       
   556 
       
   557     return self;
       
   558     }
       
   559 
       
   560 // ------------------------------------------------------------------------------------------------
       
   561 // CApplicationManagementServer::CreateServiceSecurityCheckL
       
   562 // ------------------------------------------------------------------------------------------------
       
   563 
       
   564 CPolicyServer::TCustomResult CApplicationManagementServer::CreateServiceSecurityCheckL(
       
   565         TUid aServiceType, const RMessage2& aMsg, TInt& aAction,
       
   566         TSecurityInfo& aMissing)
       
   567     {
       
   568     TInt32 trustRange = EAddTrust;
       
   569     TInt32 performRFS = EPerformRfs;
       
   570     TInt32 last = ELast;
       
   571 
       
   572     if ( (aServiceType.iUid >= trustRange)
       
   573             && (aServiceType.iUid < performRFS ))
       
   574         {
       
   575         if (aMsg.HasCapability(TCapability(ECapabilityTrustedUI) ) )
       
   576             {
       
   577             return CPolicyServer::EPass;
       
   578             }
       
   579         else
       
   580             {
       
   581             return CPolicyServer::EFail;
       
   582             }
       
   583         }
       
   584 
       
   585     else
       
   586         if ( (aServiceType.iUid >= performRFS) && (aServiceType.iUid < last))
       
   587 
       
   588             {
       
   589             if (aMsg.HasCapability(TCapability(ECapabilityDiskAdmin))
       
   590                     && (aMsg.SecureId().iId == 0x101f9a02 ))
       
   591                 {
       
   592                 return CPolicyServer::EPass;
       
   593                 }
       
   594             else
       
   595                 {
       
   596                 return CPolicyServer::EFail;
       
   597                 }
       
   598             }
       
   599 
       
   600         else
       
   601             if (aServiceType.iUid == last)
       
   602                 {
       
   603                 return CPolicyServer::EFail;
       
   604                 }
       
   605 
       
   606             else
       
   607                 {
       
   608                 return CAknAppServer::CreateServiceSecurityCheckL(
       
   609                         aServiceType, aMsg, aAction, aMissing);
       
   610                 }
       
   611 
       
   612     }
       
   613 
       
   614 // ------------------------------------------------------------------------------------------------
       
   615 // CApplicationManagementServer::~CApplicationManagementServer
       
   616 // ------------------------------------------------------------------------------------------------
       
   617 
       
   618 CApplicationManagementServer::~CApplicationManagementServer()
       
   619     {
       
   620     RDEBUG_3("CApplicationManagementServer::~CApplicationManagementServer 0x%X - 0x%X", reinterpret_cast<TUint>(this ),
       
   621             reinterpret_cast<TUint>(this)+sizeof( CApplicationManagementServer ) );
       
   622     FeatureManager::UnInitializeLib();
       
   623     iInstaller.Close();
       
   624     delete iStorage;
       
   625 
       
   626     delete iUtility;
       
   627     delete iAMServerDB;
       
   628 
       
   629     RProperty::Delete(KUidPSApplicationManagementKeys, KAMServerUIEnabled);
       
   630 
       
   631     RProperty::Delete(KUidPSApplicationManagementKeys, KAMOperationNonSilent);
       
   632 
       
   633     RProperty::Delete(KUidPSApplicationManagementKeys, KSyncNotifier);
       
   634 
       
   635     RProperty::Delete(KUidPSApplicationManagementKeys, KDMUINotClosed);
       
   636 
       
   637     
       
   638     iInstallFile.Close();
       
   639     iInstallRFs.Close();
       
   640 
       
   641     delete iDownloadMngr;
       
   642     }
       
   643 
       
   644 // ------------------------------------------------------------------------------------------------
       
   645 // CApplicationManagementServer::HandleAllClientsClosed
       
   646 // ------------------------------------------------------------------------------------------------
       
   647 void CApplicationManagementServer::HandleAllClientsClosed()
       
   648     {
       
   649     // Do Nothing
       
   650     RDEBUG( "CApplicationManagementServer::HandleAllClientsClosed" );
       
   651     }
       
   652 
       
   653 // ------------------------------------------------------------------------------------------------
       
   654 // CApplicationManagementServer::ConstructL
       
   655 // ------------------------------------------------------------------------------------------------
       
   656 
       
   657 void CApplicationManagementServer::ConstructL(const TDesC &aServerName)
       
   658     {
       
   659 
       
   660     // 2nd phase construction - ensure the timer and server objects are running
       
   661     RDEBUG( "CApplicationManagementServer::ConstructL - Start" );
       
   662 
       
   663     iOMASCOMOEnabled = ETrue;
       
   664 
       
   665     CAknAppServer::ConstructL(aServerName);
       
   666     TRAPD( errf, FeatureManager::InitializeLibL() )
       
   667     ;
       
   668     if (errf != KErrNone)
       
   669         {
       
   670         User::Leave(errf);
       
   671         }
       
   672 
       
   673     RDEBUG( "CApplicationManagementServer::ConstructL - start" );
       
   674 
       
   675     iStorage = CDeliveryComponentStorage::NewL();
       
   676 
       
   677     iUtility
       
   678             = ApplicationManagementUtilityFactory::CreateManagementUtilityL();
       
   679     iDownloadMngr = CAMDownloadManager::NewL( *this);
       
   680     iAMServerDB = CAMDownloaddb::NewL();
       
   681 
       
   682     // Define P&S Keys
       
   683     RProperty::Define(KUidPSApplicationManagementKeys, KAMServerUIEnabled,
       
   684             RProperty::EInt);
       
   685 
       
   686     RProperty::Define(KUidPSApplicationManagementKeys, KAMOperationNonSilent,
       
   687             RProperty::EInt);
       
   688 
       
   689     RProperty::Define(KUidPSApplicationManagementKeys, KSyncNotifier,
       
   690             RProperty::EInt);
       
   691 
       
   692     RProperty::Define(KUidPSApplicationManagementKeys, KDMUINotClosed,
       
   693             RProperty::EInt);
       
   694 
       
   695     RProperty syncproperty;
       
   696 
       
   697     //Ignore error status
       
   698     syncproperty.Attach(KUidPSApplicationManagementKeys, KSyncNotifier,
       
   699             EOwnerThread);
       
   700     syncproperty.Set(KErrNone);
       
   701     syncproperty.Close();
       
   702     
       
   703     SendServerToBackground();
       
   704 
       
   705 #ifdef __AM_CONNECT_INSTALLER_ONSTARTUP_	
       
   706     TInt err( iInstaller.Connect() );
       
   707     if ( err != KErrNone )
       
   708         {
       
   709         RDEBUG_2( "CApplicationManagementServer::ConstructL - ERROR leaving cannot connect installer: %d", err );
       
   710         User::LeaveIfError( err );
       
   711         }
       
   712 #endif	
       
   713     RDEBUG( "CApplicationManagementServer::ConstructL - end" );
       
   714     }
       
   715 
       
   716 // ------------------------------------------------------------------------------------------------
       
   717 // CApplicationManagementServer::StartShutDownTimer()
       
   718 // ------------------------------------------------------------------------------------------------
       
   719 
       
   720 void CApplicationManagementServer::StartShutDownTimerL()
       
   721     {
       
   722 
       
   723     RDEBUG( "CApplicationManagementServer::ConstructL - end" );
       
   724 
       
   725     iShutdown.ConstructL();
       
   726     // ensure that the server still exits even if the 1st client fails to connect
       
   727     iShutdown.Start();
       
   728 
       
   729     RDEBUG( "CApplicationManagementServer::ConstructL - end" );
       
   730     }
       
   731 
       
   732 // ------------------------------------------------------------------------------------------------
       
   733 // CApplicationManagementServer::CustomSecurityCheckL()
       
   734 // ------------------------------------------------------------------------------------------------
       
   735 
       
   736 CPolicyServer::TCustomResult CApplicationManagementServer::CustomSecurityCheckL(
       
   737         const RMessage2& /*aMsg*/, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
       
   738     {
       
   739     return EPass;
       
   740     }
       
   741 
       
   742 // ------------------------------------------------------------------------------------------------
       
   743 // CApplicationManagementServer::InstallCompleteL()
       
   744 // ------------------------------------------------------------------------------------------------
       
   745 
       
   746 void CApplicationManagementServer::InstallCompleteL(
       
   747         const CDeploymentComponent& aCompo, const TBool &aInstallSuccess)
       
   748     {
       
   749     RDEBUG_2("CApplicationManagementServer::InstallCompleteL start (%d)", aInstallSuccess);
       
   750     iInstallFile.Close();
       
   751 
       
   752     // if java jad + jar install, remove files from c:\temp directory
       
   753     if (CDeploymentComponent::IsJavaMimeL(aCompo.MetaData().MimeType() ) && CDeploymentComponent::IsJavaMimeL(aCompo.Data().MimeType() ) )
       
   754         {
       
   755         TFileName fn, fn2;
       
   756         GenerateTempFileNameL(iInstallRFs, aCompo, fn, fn2);
       
   757         RDEBUG_3("CApplicationManagementServer::InstallCompleteL delete files: (%S) (%S)", &fn, &fn2);
       
   758         User::LeaveIfError(iInstallRFs.Delete(fn) );
       
   759         User::LeaveIfError(iInstallRFs.Delete(fn2) );
       
   760         }
       
   761 
       
   762     if (aInstallSuccess)
       
   763         {
       
   764         // Remove temporary files from private directory 
       
   765         const_cast<CDeploymentComponent&>(aCompo).ResetDataL(iInstallRFs);
       
   766         }
       
   767 
       
   768     iInstallRFs.Close();
       
   769 
       
   770     iInstallInProgress = EFalse;
       
   771 #ifndef __AM_CONNECT_INSTALLER_ONSTARTUP_	
       
   772     iInstaller.Close() ;
       
   773 #endif
       
   774     RDEBUG("CApplicationManagementServer::InstallCompleteL end");
       
   775     }
       
   776 
       
   777 // ------------------------------------------------------------------------------------------------
       
   778 // CApplicationManagementServer::GenerateTempJarFileNameL()
       
   779 // ------------------------------------------------------------------------------------------------
       
   780 
       
   781 void CApplicationManagementServer::GenerateTempJarFileNameL(RFs &aFs,
       
   782         const TDesC& aMetaSource, TFileName &aFileName) const
       
   783     {
       
   784     if (aMetaSource != KNullDesC)
       
   785         {
       
   786         RFile file;
       
   787         User::LeaveIfError(file.Open(aFs, aMetaSource, EFileRead) );
       
   788         CleanupClosePushL(file);
       
   789         TFileName temp;
       
   790         temp = ReadJarFileNameL(file);
       
   791         GenerateTempFileNameL(aFs, temp, aFileName);
       
   792         CleanupStack::PopAndDestroy( &file);
       
   793         }
       
   794     }
       
   795 
       
   796 // ------------------------------------------------------------------------------------------------
       
   797 // CApplicationManagementServer::GenerateTempFileNameL()
       
   798 // ------------------------------------------------------------------------------------------------
       
   799 
       
   800 void CApplicationManagementServer::GenerateTempFileNameL(const RFs &aFs,
       
   801         const TDesC& aSource, TFileName &aFileName) const
       
   802     {
       
   803     if (aSource != KNullDesC)
       
   804         {
       
   805         aFileName.Copy(KInstallDir);
       
   806         TParse p;
       
   807         User::LeaveIfError(aFs.Parse(aSource, p) );
       
   808         aFileName.Append(p.NameAndExt() );
       
   809         }
       
   810     }
       
   811 
       
   812 // ------------------------------------------------------------------------------------------------
       
   813 // CApplicationManagementServer::GenerateTempFileNameL()
       
   814 // ------------------------------------------------------------------------------------------------
       
   815 
       
   816 void CApplicationManagementServer::GenerateTempFileNameL(RFs &aFs,
       
   817         const CDeploymentComponent& aCompo, TFileName& aSource,
       
   818         TFileName &aMetaSource, TFileName &aFileName,
       
   819         TFileName &aMetaFileName) const
       
   820     {
       
   821     if ( !BaflUtils::FolderExists(aFs, KInstallDir) )
       
   822         {
       
   823         aFs.MkDirAll(KInstallDir);
       
   824         }
       
   825 
       
   826     aMetaSource.Copy(aCompo.MetaData().DataFileName() );
       
   827     GenerateTempFileNameL(aFs, aMetaSource, aMetaFileName);
       
   828     aSource.Copy(aCompo.Data().DataFileName() );
       
   829     GenerateTempJarFileNameL(aFs, aMetaSource, aFileName);
       
   830     }
       
   831 
       
   832 // ------------------------------------------------------------------------------------------------
       
   833 // CApplicationManagementServer::GenerateTempFileNameL()
       
   834 // ------------------------------------------------------------------------------------------------	
       
   835 
       
   836 void CApplicationManagementServer::GenerateTempFileNameL(RFs &aFs,
       
   837         const CDeploymentComponent& aCompo, TFileName &aFileName,
       
   838         TFileName &aMetaFileName) const
       
   839     {
       
   840     TFileName ftemp, msource;
       
   841     GenerateTempFileNameL(aFs, aCompo, ftemp, msource, aFileName,
       
   842             aMetaFileName);
       
   843     }
       
   844 
       
   845 // ------------------------------------------------------------------------------------------------
       
   846 // CApplicationManagementServer::ReadJarFileNameL()
       
   847 // ------------------------------------------------------------------------------------------------
       
   848 
       
   849 TFileName CApplicationManagementServer::ReadJarFileNameL(RFile& aFile) const
       
   850     {
       
   851     TFileName jarFileName;
       
   852     HBufC8* lineBuffer = HBufC8::NewLC(KMaxFileName+72); // lets hope all lines fit to this
       
   853     TPtr8 linePtr(lineBuffer->Des() );
       
   854     TInt length(0);
       
   855     aFile.Size(length);
       
   856     HBufC8* data = HBufC8::NewLC(length);
       
   857     TPtr8 ptr(data->Des() );
       
   858     aFile.Read(ptr);
       
   859     RDesReadStream stream(*data);
       
   860     CleanupClosePushL(stream);
       
   861     TInt colonIndex = -1;
       
   862     TInt err(KErrNone);
       
   863     TInt found(KErrNotFound);
       
   864     const TInt KJadNameValueSeparator = 0x3A; //':' 
       
   865 
       
   866     for (;;)
       
   867         {
       
   868         TRAP( err, ReadLineL(stream, linePtr) );
       
   869         if (err == KErrNone)
       
   870             {
       
   871             RDEBUG8_2("Read line: (%S)", &linePtr);
       
   872             found = linePtr.Find(KMIDletJarURL);
       
   873             if (found != KErrNotFound && found == 0) // found
       
   874                 {
       
   875                 TPtrC8 filename(linePtr);
       
   876                 colonIndex = linePtr.Locate(KJadNameValueSeparator);
       
   877                 if (colonIndex != KErrNotFound)
       
   878                     {
       
   879                     filename.Set(linePtr.Mid(colonIndex+1)); // get jar filename, format is: MIDlet-Jar-URL: bomber.jar
       
   880                     jarFileName.Copy(filename);
       
   881                     jarFileName.Trim();
       
   882                     break;
       
   883                     }
       
   884                 }
       
   885             }
       
   886         else
       
   887             {
       
   888             User::Leave(err);
       
   889             }
       
   890         }
       
   891     CleanupStack::PopAndDestroy(3, lineBuffer); // stream, data
       
   892     return jarFileName;
       
   893     }
       
   894 
       
   895 // ------------------------------------------------------------------------------------------------
       
   896 // CApplicationManagementServer::ReadLineL()
       
   897 // ------------------------------------------------------------------------------------------------
       
   898 
       
   899 void CApplicationManagementServer::ReadLineL(RReadStream& aStream,
       
   900         TDes8& aLineBuffer) const
       
   901     {
       
   902     TBuf8<1> input;
       
   903     const TUint32 LF = 10;
       
   904     const TUint32 CR = 13;
       
   905     TBool endOfLine(EFalse);
       
   906     TInt errRead(KErrNone);
       
   907 
       
   908     // reset
       
   909     aLineBuffer.Zero();
       
   910 
       
   911     while ( !endOfLine)
       
   912         {
       
   913         TRAP(errRead, aStream.ReadL(input, 1));
       
   914 
       
   915         if (errRead == KErrEof)
       
   916             {
       
   917             // EOF
       
   918             User::Leave(KErrEof);
       
   919             }
       
   920         // check special characters	
       
   921         if (input[0] == LF)
       
   922             {
       
   923             // End of line
       
   924             endOfLine = ETrue;
       
   925             }
       
   926         else
       
   927             if (input[0] == CR)
       
   928                 {
       
   929                 // Only end of line if not followed by a LF
       
   930                 }
       
   931             else
       
   932                 {
       
   933                 // We put any other character in the buffer
       
   934                 if (aLineBuffer.Length() < aLineBuffer.MaxLength())
       
   935                     {
       
   936                     aLineBuffer.Append(input[0]);
       
   937                     }
       
   938                 }
       
   939         }
       
   940     }
       
   941 
       
   942 // ------------------------------------------------------------------------------------------------
       
   943 // CApplicationManagementServer::PrepareInstallL()
       
   944 // ------------------------------------------------------------------------------------------------	
       
   945 
       
   946 TBool CApplicationManagementServer::PrepareInstallL(
       
   947         const CDeploymentComponent &aComponent, TFileName &aFileName)
       
   948     {
       
   949     RDEBUG( "CApplicationManagementServer::PrepareInstallL" );
       
   950     TBool res(ETrue);
       
   951 
       
   952 #ifndef __AM_CONNECT_INSTALLER_ONSTARTUP_
       
   953     TInt err(iInstaller.Connect() );
       
   954     if (err != KErrNone)
       
   955         {
       
   956         RDEBUG_2( "CApplicationManagementServer::PrepareInstallL - ERROR leaving cannot connect installer: %d", err );
       
   957         User::LeaveIfError(err);
       
   958         }
       
   959     CleanupClosePushL(iInstaller);
       
   960 #endif
       
   961 
       
   962     RDEBUG( "CApplicationManagementServer::PrepareInstallL - connected to installer" );
       
   963     // Copy data file name (install file)
       
   964     if (aComponent.Data().DataFileName().Length() > 0)
       
   965         {
       
   966         aFileName.Copy(aComponent.Data().DataFileName() );
       
   967         }
       
   968     else
       
   969         {
       
   970         // data file has not been created for component!	
       
   971         User::Leave(KErrNotFound);
       
   972         }
       
   973     // Open RFs session
       
   974     User::LeaveIfError(iInstallRFs.Connect() );
       
   975     User::LeaveIfError(iInstallRFs.ShareProtected() );
       
   976 
       
   977     // set installoptions and correct mime type
       
   978     using namespace SwiUI;
       
   979     iInstallOptions = aComponent.InstallOpts().iOptions;
       
   980     TInstallReq req;
       
   981 	if (aComponent.Data().MimeType() == SwiUI::KSisMimeType) 
       
   982 	{
       
   983 		//convert if MIME type is application/vnd.symbian.install to x-epoc/x-sisx-app
       
   984 		//as installer doesn't support application/vnd.symbian.install MIME type from S60 3rd edition onwards.
       
   985 		req.iMIME = SwiUI::KSisxMimeType;
       
   986 	}
       
   987 	else 
       
   988 	{
       
   989 		req.iMIME = aComponent.Data().MimeType();
       
   990 	}
       
   991 
       
   992 	if (CDeploymentComponent::IsJavaMimeL(aComponent.MetaData().MimeType() ) ) {
       
   993 		// Check if both jad and jar files already exist in the phone	
       
   994 		if (CDeploymentComponent::IsJavaMimeL(aComponent.Data().MimeType() ) && aComponent.MetaData().MimeType() == SwiUI::KJadMIMEType) {
       
   995 			// Move both files to temporary location and use jad to install java application
       
   996 			CFileMan *fm = CFileMan::NewL(iInstallRFs);
       
   997 			CleanupStack::PushL(fm);
       
   998 			TFileName source, metasource, metatarget;
       
   999 			aFileName.Copy(KNullDesC8() ); // reset
       
  1000 			GenerateTempFileNameL(iInstallRFs, aComponent, source, metasource,
       
  1001 					aFileName, metatarget);
       
  1002 
       
  1003             RDEBUG_2( "CApplicationManagementServer::PrepareInstallL - temp jar file '%S'", &aFileName );
       
  1004             RDEBUG_2( "CApplicationManagementServer::PrepareInstallL - temp jad file '%S'", &metatarget );
       
  1005 
       
  1006             // Copy datafile (jar)
       
  1007             TInt copyer(fm->Copy(source, aFileName) );
       
  1008 
       
  1009             // Copy metadatafile (jad)
       
  1010             TInt copyer2(fm->Copy(metasource, metatarget) );
       
  1011 
       
  1012             CleanupStack::PopAndDestroy(fm);
       
  1013 
       
  1014             RDEBUG_3( "CApplicationManagementServer::PrepareInstallL - (%d)-(%d)", copyer, copyer2 );
       
  1015 
       
  1016             if (copyer == KErrNone && copyer2 == KErrNone)
       
  1017                 {
       
  1018                 res = ETrue;
       
  1019                 aFileName = metatarget;
       
  1020                 req.iMIME = aComponent.MetaData().MimeType();
       
  1021                 }
       
  1022             else
       
  1023                 {
       
  1024                 User::Leave(KErrWrite);
       
  1025                 }
       
  1026             }
       
  1027         else
       
  1028             if (aComponent.MetaData().MimeType() == SwiUI::KJadMIMEType)
       
  1029                 {
       
  1030                 aFileName.Copy(aComponent.MetaData().DataFileName() );
       
  1031                 req.iMIME = aComponent.MetaData().MimeType();
       
  1032                 RDEBUG_2( "CApplicationManagementServer::PrepareInstallL - Using Jad file to install java application: %S", &aFileName );
       
  1033                 }
       
  1034         }
       
  1035 
       
  1036     if (aComponent.GetIAP() > -1)
       
  1037         {
       
  1038         req.iIAP = aComponent.GetIAP();
       
  1039         RDEBUG_2( "CApplicationManagementServer::PrepareInstallL: setting iap to %d", req.iIAP );
       
  1040         }
       
  1041     else
       
  1042         {
       
  1043         TInt iap = KErrNotFound;
       
  1044         TRAPD( err, SmlHelper::GetDefaultIAPFromDMProfileL( iap ) )
       
  1045         ;
       
  1046         if (err == KErrNone)
       
  1047             {
       
  1048             req.iIAP = iap;
       
  1049             RDEBUG_2("	-> using DM profile default IAP: %d", iap);
       
  1050             }
       
  1051         else
       
  1052             {
       
  1053             RDEBUG_2("**** ERROR while fetching DM profile default iap: %d", err );
       
  1054             }
       
  1055         }
       
  1056 
       
  1057     iInstallReq = SwiUI::TInstallReqPckg(req);
       
  1058     RDEBUG8_2( "CApplicationManagementServer::PrepareInstallL: mime type is (%S)", &req.iMIME);
       
  1059     RDEBUG_2( "CApplicationManagementServer::PrepareInstallL - Using temp file '%S'", &aFileName );
       
  1060 
       
  1061     User::LeaveIfError(iInstallFile.Open(iInstallRFs, aFileName, EFileRead) );
       
  1062     TInt sz;
       
  1063     User::LeaveIfError(iInstallFile.Size(sz) );
       
  1064     if ( !(sz > 0))
       
  1065         {
       
  1066         res = EFalse;
       
  1067         RDEBUG( "CApplicationManagementServer::PrepareInstallL - ERROR size of source file is 0!" );
       
  1068         }
       
  1069 
       
  1070 #ifndef __AM_CONNECT_INSTALLER_ONSTARTUP_
       
  1071     CleanupStack::Pop( &iInstaller);
       
  1072 #endif
       
  1073 
       
  1074     RDEBUG( "CApplicationManagementServer::PrepareInstallL end" );
       
  1075     return res;
       
  1076     }
       
  1077 
       
  1078 // ------------------------------------------------------------------------------------------------
       
  1079 // CApplicationManagementServer::InstallL()
       
  1080 // ------------------------------------------------------------------------------------------------	
       
  1081 
       
  1082 void CApplicationManagementServer::InstallL(
       
  1083         const CDeploymentComponent &aComponent, TRequestStatus &aStatus)
       
  1084     {
       
  1085     RDEBUG( "CApplicationManagementServer::InstallL (async): begin" );
       
  1086 
       
  1087     if (iInstallInProgress == EFalse)
       
  1088         {
       
  1089         TFileName fn;
       
  1090         if (PrepareInstallL(aComponent, fn) )
       
  1091             {
       
  1092             RDEBUG_3( "CApplicationManagementServer::InstallL: Install '%S' sizeof opts: %d", &fn, sizeof (aComponent.InstallOpts()));
       
  1093 
       
  1094             // Silent or Non Silent Installation is choosen based on DM session started in silent or non silent
       
  1095 
       
  1096             TInt err = KErrNone;
       
  1097             TInt nonSilentOperation = KErrNotFound;
       
  1098             RProperty::Get(KUidPSApplicationManagementKeys,
       
  1099                     KAMOperationNonSilent, nonSilentOperation);
       
  1100 
       
  1101             if (!nonSilentOperation)
       
  1102                 {
       
  1103                 TRAP( err ,iInstaller.SilentInstall( aStatus, iInstallFile, iInstallReq, iInstallOptions ) );
       
  1104                 }
       
  1105             else
       
  1106                 {
       
  1107                 TRAP( err ,iInstaller.Install( aStatus, iInstallFile, iInstallReq ) );
       
  1108                 }
       
  1109 
       
  1110             RDEBUG_2( "CApplicationManagementServer::InstallL: status: %d", err);
       
  1111             User::LeaveIfError(err);
       
  1112             iInstallInProgress = ETrue;
       
  1113             }
       
  1114         else
       
  1115             {
       
  1116             RDEBUG( "CApplicationManagementServer::InstallL - PrepareInstallL failed, leaving" );
       
  1117             User::Leave(KErrArgument);
       
  1118             }
       
  1119         }
       
  1120     else
       
  1121         {
       
  1122         RDEBUG( "CApplicationManagementServer::InstallL (async): previous install still in progress...bailing out" );
       
  1123         TRequestStatus * status = &aStatus;
       
  1124         User::RequestComplete(status, KErrInUse);
       
  1125         }
       
  1126     RDEBUG( "CApplicationManagementServer::InstallL (async): end" );
       
  1127     }
       
  1128 
       
  1129 // ------------------------------------------------------------------------------------------------
       
  1130 // CApplicationManagementServer::PrepareInstallL()
       
  1131 // ------------------------------------------------------------------------------------------------	
       
  1132 
       
  1133 void CApplicationManagementServer::InstallL(
       
  1134         const CDeploymentComponent &aComponent)
       
  1135     {
       
  1136     RDEBUG( "CApplicationManagementServer::InstallL: begin" );
       
  1137 
       
  1138     if (iInstallInProgress == EFalse)
       
  1139         {
       
  1140         TFileName fn;
       
  1141         if (PrepareInstallL(aComponent, fn) )
       
  1142             {
       
  1143             iInstallInProgress = ETrue;
       
  1144             RDEBUG_2( "CApplicationManagementServer::InstallL: Install '%S' ", &fn);
       
  1145             SwiUI::TInstallOptionsPckg pkg(aComponent.InstallOpts().iOptions);
       
  1146             TRAPD( err ,iInstaller.SilentInstall( fn, pkg ) )
       
  1147             ;
       
  1148             User::LeaveIfError(err);
       
  1149             iInstallInProgress = EFalse;
       
  1150             }
       
  1151         else
       
  1152             {
       
  1153             RDEBUG( "CApplicationManagementServer::InstallL - PrepareInstallL failed, leaving" );
       
  1154             User::Leave(KErrArgument);
       
  1155             }
       
  1156         }
       
  1157     RDEBUG( "CApplicationManagementServer::InstallL: end" );
       
  1158     }
       
  1159 
       
  1160 // ------------------------------------------------------------------------------------------------
       
  1161 // CApplicationManagementServer::UninstallL()
       
  1162 // ------------------------------------------------------------------------------------------------	
       
  1163 
       
  1164 void CApplicationManagementServer::UninstallL(
       
  1165         const CDeploymentComponent &aComponent, TRequestStatus &aStatus)
       
  1166     {
       
  1167     RDEBUG( "CApplicationManagementServer::UninstallL: begin" );
       
  1168     if (iInstallInProgress == EFalse)
       
  1169         {
       
  1170         TInt err(iInstaller.Connect() );
       
  1171         User::LeaveIfError(err);
       
  1172         RDEBUG_2( "CApplicationManagementServer::UninstallL: UninstallL '0x%X' ", aComponent.Uid());
       
  1173         using namespace SwiUI;
       
  1174         iUninstallOptions = aComponent.UninstallOpts();
       
  1175 
       
  1176         TInt nonSilentOperation = KErrNotFound;
       
  1177 
       
  1178         RProperty::Get(KPSUidNSmlDMSyncApp, KSilentSession,
       
  1179                 nonSilentOperation);
       
  1180 
       
  1181 				iOMASCOMOEnabled = IsOMASCOMOEnabledL();
       
  1182 
       
  1183         if (!iOMASCOMOEnabled)
       
  1184             nonSilentOperation = 0;
       
  1185         if (!nonSilentOperation)
       
  1186             {
       
  1187             TRAP( err ,iInstaller.SilentUninstall( aStatus, aComponent.Uid(),
       
  1188                             iUninstallOptions, aComponent.MimeType() ) );
       
  1189             }
       
  1190         else
       
  1191             {
       
  1192             TRAP( err ,iInstaller.Uninstall( aStatus, aComponent.Uid(), aComponent.MimeType() ) );
       
  1193             CSyncService *syncService =
       
  1194                     CSyncService::NewL(NULL, KDevManServiceStart);
       
  1195             if (syncService)
       
  1196                 {
       
  1197                 syncService->EnableProgressNoteL(EFalse);
       
  1198                 }
       
  1199 
       
  1200             delete syncService;
       
  1201             }
       
  1202 
       
  1203         RDEBUG_2( "CApplicationManagementServer::UninstallL: UninstallL result '0x%X'", err );
       
  1204         User::LeaveIfError(err);
       
  1205         iInstallInProgress = ETrue;
       
  1206         }
       
  1207     else
       
  1208         {
       
  1209         RDEBUG( "CApplicationManagementServer::UninstallL: previous uninstall still in progress...bailing out" );
       
  1210         TRequestStatus * status = &aStatus;
       
  1211         User::RequestComplete(status, KErrInUse);
       
  1212         }
       
  1213 
       
  1214     RDEBUG( "CApplicationManagementServer::UninstallL: end" );
       
  1215     }
       
  1216 // ------------------------------------------------------------------------------------------------
       
  1217 // CApplicationManagementServer::PerformRFSL()
       
  1218 // ------------------------------------------------------------------------------------------------
       
  1219 
       
  1220 void CApplicationManagementServer::PerformRFSL()
       
  1221     {
       
  1222     RDEBUG( "CApplicationManagementServer::PerformRFSL: begin" );
       
  1223     const RComponentIdArray &arrt = iStorage->GetComponentIds();
       
  1224     TCertInfoPckg *corcert= NULL;
       
  1225     for (TInt i( 0); i < arrt.Count(); i++)
       
  1226         {
       
  1227         RDEBUG_3( "CApplicationManagementServer::PerformRFSL processing dc %d of %d", i, arrt.Count() );
       
  1228         CDeploymentComponent &c = iStorage->ComponentL(arrt[i]);
       
  1229 
       
  1230         const RCertArray &certs = iStorage->Certificates();
       
  1231         TInt index = c.Owner();
       
  1232         TCertInfoPckg *certp = NULL;
       
  1233         if (index >= 0)
       
  1234         {
       
  1235         	certp = certs[ c.Owner() ];
       
  1236         }
       
  1237         if ( !corcert && certp)
       
  1238             {
       
  1239             if (CheckCertL( (*certp)() ) )
       
  1240                 {
       
  1241                 corcert = certp;
       
  1242                 RDEBUG_2( "CApplicationManagementServer::PerformRFSL Found CORP Cert! Removing %d ", i );
       
  1243                 RemoveInternalL(c);
       
  1244                 }
       
  1245             else
       
  1246                 {
       
  1247                 RDEBUG_2( "CApplicationManagementServer::PerformRFSL skipping %d because not corp dc", i );
       
  1248                 }
       
  1249             }
       
  1250         else
       
  1251             {
       
  1252             if (corcert == certp)
       
  1253                 {
       
  1254                 RDEBUG_2( "CApplicationManagementServer::PerformRFSL Removing %d ", i );
       
  1255                 RemoveInternalL(c);
       
  1256                 }
       
  1257             else
       
  1258                 {
       
  1259                 RDEBUG_2( "CApplicationManagementServer::PerformRFSL skipping %d because not corp dc", i );
       
  1260                 }
       
  1261             }
       
  1262         }
       
  1263     RDEBUG( "CApplicationManagementServer::PerformRFSL: end" );
       
  1264     }
       
  1265 
       
  1266 // ------------------------------------------------------------------------------------------------
       
  1267 // CApplicationManagementServer::RemoveInternalL()
       
  1268 // ------------------------------------------------------------------------------------------------
       
  1269 
       
  1270 void CApplicationManagementServer::RemoveInternalL(
       
  1271         const CDeploymentComponent &aCompo, TBool aDoUninstall /* = ETrue */)
       
  1272     {
       
  1273     RDEBUG_2("CApplicationManagementServer: RemoveInternalL - Remove id: (%d)", aCompo.InternalId() );
       
  1274 
       
  1275     aCompo.SetStatusNode(EDelivered_RemoveProgress);
       
  1276     TInt err(KErrNone);
       
  1277     TDeploymentComponentState st(aCompo.State() );
       
  1278     if (st == EDCSDelivered || st == EDCSDownload)
       
  1279         {
       
  1280         TRAP(err,iStorage->RemoveL( aCompo.InternalId() ));
       
  1281         }
       
  1282     else
       
  1283         if (st == EDCSActive || st == EDCSInactive)
       
  1284             {
       
  1285             if (aDoUninstall)
       
  1286                 {
       
  1287                 if (aCompo.Uid() != TUid::Null() )
       
  1288                     {
       
  1289                     //TInt err= KErrNone;
       
  1290 
       
  1291                     TInt nonSilentOperation = KErrNotFound;
       
  1292 
       
  1293                     RProperty::Get(KPSUidNSmlDMSyncApp, KSilentSession,
       
  1294                             nonSilentOperation);
       
  1295 
       
  1296 										iOMASCOMOEnabled = IsOMASCOMOEnabledL();
       
  1297 
       
  1298                     if (!iOMASCOMOEnabled)
       
  1299                         nonSilentOperation = 0;
       
  1300 
       
  1301                     if (nonSilentOperation!=0)
       
  1302                         {
       
  1303 
       
  1304                         BringServertoForeground();
       
  1305 
       
  1306                         TInt amServerEnabled = 1;
       
  1307                         err = RProperty::Set(KUidPSApplicationManagementKeys,
       
  1308                                 KAMServerUIEnabled, amServerEnabled);
       
  1309                         User::LeaveIfError(err); // invalid
       
  1310 
       
  1311                         }
       
  1312 
       
  1313                     TRequestStatus s;
       
  1314                     TRAP(err,UninstallL( aCompo, s ));
       
  1315                     User::WaitForRequest(s);
       
  1316                     iInstallInProgress = EFalse;
       
  1317                     // Capturing Installer errors,if any
       
  1318                     err = s.Int();
       
  1319 
       
  1320                     TInt amServerEnabled = 0;
       
  1321                     RProperty::Set(KUidPSApplicationManagementKeys,
       
  1322                             KAMServerUIEnabled, amServerEnabled);
       
  1323                     //User::LeaveIfError(err); // invalid
       
  1324 
       
  1325                     SendServerToBackground();
       
  1326 
       
  1327                     // Bring DM UI to foreground
       
  1328                     if (nonSilentOperation!=0)
       
  1329                         {
       
  1330                         BringDMUItoForeground();
       
  1331                         }
       
  1332 
       
  1333                     if (s.Int() == KErrNone)
       
  1334                         {
       
  1335                         RDEBUG("CApplicationManagementServer::RemoveInternalL Uninstalled");
       
  1336                         }
       
  1337                     else
       
  1338                         if (s.Int() == KErrNotFound)
       
  1339                             {
       
  1340                             RDEBUG( "CApplicationManagementServer: RemoveInternalL WARNING component was not found by uninstaller" );
       
  1341                             }
       
  1342                         else
       
  1343                             {
       
  1344                             RDEBUG_2("CApplicationManagementServer: RemoveInternalL ERROR uninstall failed %d", s.Int() );
       
  1345                             
       
  1346                             }
       
  1347                     }
       
  1348                 else
       
  1349                     {
       
  1350                     RDEBUG( "CApplicationManagementServer: RemoveInternalL ERROR component is deployed but has null uid - it cannot be uninstalled!" );
       
  1351                     }
       
  1352                 }
       
  1353             else
       
  1354                 {
       
  1355                 RDEBUG_2("CApplicationManagementServer: RemoveInternalL - Skipped uninstall of %d", aCompo.InternalId() );
       
  1356                 }
       
  1357             /*
       
  1358              *   if (unstall is sucesss) then remove component from storage
       
  1359              *   
       
  1360              */
       
  1361             if (err == KErrNone)
       
  1362                 {
       
  1363                 iStorage->RemoveL(aCompo.InternalId() );
       
  1364                 }
       
  1365             }
       
  1366         else
       
  1367             {
       
  1368             RDEBUG_2("CApplicationManagementServer: RemoveInternalL ERROR called with illegal state component id %d", aCompo.State() );
       
  1369             User::Leave(KErrArgument);
       
  1370             }
       
  1371     /*  
       
  1372      * if error set state to remove failed
       
  1373      * Finally call userleaveiferror()
       
  1374      * */
       
  1375     if (err != KErrNone)
       
  1376         {
       
  1377         aCompo.SetStatusNode(EDelivered_RemoveFailed);
       
  1378         }
       
  1379     User::LeaveIfError(err);
       
  1380     }
       
  1381 
       
  1382 // ------------------------------------------------------------------------------------------------
       
  1383 // CApplicationManagementServer::CheckCertL()
       
  1384 // ------------------------------------------------------------------------------------------------
       
  1385 
       
  1386 TBool CApplicationManagementServer::CheckCertL(const TCertInfo &aInfo) const
       
  1387     {
       
  1388     TBool go(EFalse);
       
  1389 
       
  1390     if (FeatureManager::FeatureSupported( KFeatureIdSapPolicyManagement) )
       
  1391         {
       
  1392         //	#ifdef __SAP_POLICY_MANAGEMENT
       
  1393         RPolicyEngine peng;
       
  1394 
       
  1395         // The management session
       
  1396         //
       
  1397         TInt err(peng.Connect() );
       
  1398 
       
  1399         if (err == KErrNone)
       
  1400             {
       
  1401             CleanupClosePushL(peng);
       
  1402             RPolicyRequest rq;
       
  1403             err = rq.Open(peng) ;
       
  1404             if (err == KErrNone)
       
  1405                 {
       
  1406                 CleanupClosePushL(rq);
       
  1407 
       
  1408                 TRequestContext rc;
       
  1409 
       
  1410                 using namespace PolicyEngineXACML;
       
  1411                 using namespace NPolicyConstants;
       
  1412 
       
  1413                 rc.AddSubjectAttributeL(KTrustedSubject, aInfo);
       
  1414                 rc.AddResourceAttributeL(KResourceId, KApplicationManagement,
       
  1415                         KStringDataType);
       
  1416 
       
  1417                 TResponse resp;
       
  1418                 err = rq.MakeRequest(rc, resp);
       
  1419                 if (err == KErrNone)
       
  1420                     {
       
  1421                     if (resp.GetResponseValue() == EResponsePermit
       
  1422 #ifdef _DEBUG
       
  1423                             || resp.GetResponseValue()
       
  1424                                     == EResponseNotApplicable
       
  1425 #endif 
       
  1426                     )
       
  1427                         {
       
  1428                         go = ETrue;
       
  1429                         }
       
  1430                     else
       
  1431                         {
       
  1432                         RDEBUG_2( "CApplicationManagementSession::CheckCertL; Policy response denies access! %d", resp.GetResponseValue());
       
  1433                         }
       
  1434                     }
       
  1435                 else
       
  1436                     {
       
  1437                     RDEBUG_2( "CApplicationManagementSession::CheckCertL; ERROR making policy request! %d", err);
       
  1438                     }
       
  1439                 CleanupStack::PopAndDestroy( &rq) ;
       
  1440                 }
       
  1441             else
       
  1442                 {
       
  1443                 RDEBUG_2( "CApplicationManagementSession::CheckCertL; ERROR Failed to open policy engine session! %d", err);
       
  1444                 }
       
  1445             CleanupStack::PopAndDestroy( &peng) ;
       
  1446             }
       
  1447         else
       
  1448             {
       
  1449             RDEBUG_2( "CApplicationManagementSession::CheckCertL; ERROR Failed to connect policy engine! %d", err);
       
  1450             }
       
  1451         User::LeaveIfError(err);
       
  1452         }
       
  1453     else
       
  1454         {
       
  1455         RDEBUG( "CApplicationManagementSession::CheckCertL; No PolicyManagement by featmgr-> cert ok!" );
       
  1456         go = ETrue;
       
  1457         }
       
  1458     return go;
       
  1459     }
       
  1460 
       
  1461 // ------------------------------------------------------------------------------------------------
       
  1462 // CApplicationManagementServer::HasUidL()
       
  1463 // ------------------------------------------------------------------------------------------------	
       
  1464 
       
  1465 TBool CApplicationManagementServer::HasUidL(const TUid &aUid,
       
  1466         CDeploymentComponent *& aCompo, CDeploymentComponent *aIgnored /* = NULL */)
       
  1467     {
       
  1468     TBool found(EFalse);
       
  1469     const RComponentIdArray &arrt = iStorage->GetComponentIds();
       
  1470     TInt count(arrt.Count() );
       
  1471     for (TInt i( 0); i < count; i++)
       
  1472         {
       
  1473         CDeploymentComponent &compo = iStorage->ComponentL(arrt[i]);
       
  1474         if (compo.Uid() == aUid)
       
  1475             {
       
  1476             if ( &compo != aIgnored)
       
  1477                 {
       
  1478                 aCompo = &compo;
       
  1479                 found = ETrue;
       
  1480                 RDEBUG_3( "ApplicationManagementServer: UidExistsL 0x%X - Found NOT ignored %d", aUid.iUid, compo.InternalId() );
       
  1481                 }
       
  1482             else
       
  1483                 {
       
  1484                 RDEBUG( "ApplicationManagementServer: UidExistsL - Found ignored " );
       
  1485                 }
       
  1486             }
       
  1487         }
       
  1488     if ( !found)
       
  1489         {
       
  1490         found = FindInstalledSisUidL(aUid);
       
  1491         if ( !found)
       
  1492             {
       
  1493             found = FindInstalledJavaUidL(aUid);
       
  1494             }
       
  1495         }
       
  1496     return found;
       
  1497     }
       
  1498 
       
  1499 // ------------------------------------------------------------------------------------------------
       
  1500 // CApplicationManagementServer::FindInstalledSisUidL()
       
  1501 // ------------------------------------------------------------------------------------------------	
       
  1502 
       
  1503 TBool CApplicationManagementServer::FindInstalledSisUidL(const TUid &aUid) const
       
  1504     {
       
  1505     TBool found(EFalse);
       
  1506     Swi::RSisRegistrySession sisses;
       
  1507     TInt r(sisses.Connect() );
       
  1508     User::LeaveIfError(r) ;
       
  1509     CleanupClosePushL(sisses);
       
  1510 
       
  1511     RArray<TUid> uids;
       
  1512     sisses.InstalledUidsL(uids);
       
  1513     CleanupClosePushL(uids);
       
  1514 
       
  1515     TInt uidc(uids.Count() );
       
  1516     for (TInt j( 0); found == EFalse && j < uidc; j++)
       
  1517         {
       
  1518         if (uids[j] == aUid)
       
  1519             {
       
  1520             found = ETrue;
       
  1521             }
       
  1522         }
       
  1523     CleanupStack::PopAndDestroy( &uids);
       
  1524     CleanupStack::PopAndDestroy( &sisses);
       
  1525 
       
  1526     return found;
       
  1527     }
       
  1528 
       
  1529 // ------------------------------------------------------------------------------------------------
       
  1530 // CApplicationManagementServer::FindInstalledJavaUidL()
       
  1531 // ------------------------------------------------------------------------------------------------	
       
  1532 
       
  1533 TBool CApplicationManagementServer::FindInstalledJavaUidL(const TUid &aUid) const
       
  1534     {
       
  1535     TBool found(EFalse);
       
  1536     iUtility->RefreshJavaRegistryL();
       
  1537     found = iUtility->FindInstalledJavaUidL(aUid);
       
  1538     return found;
       
  1539     }
       
  1540 
       
  1541 // ------------------------------------------------------------------------------------------------
       
  1542 // CApplicationManagementServer::FindNewUid()
       
  1543 // ------------------------------------------------------------------------------------------------	
       
  1544 
       
  1545 TUid CApplicationManagementServer::FindNewUid(const RArray<TUid> &aUidsOrig,
       
  1546         const RArray<TUid> &aUidsNew) const
       
  1547     {
       
  1548     TUid ret(TUid::Null() );
       
  1549     TInt c1(aUidsOrig.Count() );
       
  1550     TInt c2(aUidsNew.Count() );
       
  1551     if (c2 >= c1)
       
  1552         {
       
  1553         for (TInt i(c2 - 1); i >= 0 && !ret.iUid; i--)
       
  1554             {
       
  1555             if (aUidsOrig.Find(aUidsNew[i]) == KErrNotFound)
       
  1556                 {
       
  1557                 ret = aUidsNew[i];
       
  1558                 }
       
  1559 
       
  1560             }
       
  1561         }
       
  1562     return ret;
       
  1563     }
       
  1564 
       
  1565 // ------------------------------------------------------------------------------------------------
       
  1566 // CApplicationManagementServer::JavaUidsL()
       
  1567 // ------------------------------------------------------------------------------------------------	
       
  1568 
       
  1569 void CApplicationManagementServer::JavaUidsL(RArray<TUid> &aUids) const
       
  1570     {
       
  1571     iUtility->RefreshJavaRegistryL();
       
  1572     iUtility->JavaUidsL(aUids);
       
  1573     }
       
  1574 
       
  1575 void CApplicationManagementServer::CheckforDuplicateMidletsL(
       
  1576         TMidletParameters& amidletParameters)
       
  1577     {
       
  1578     RDEBUG( "CApplicationManagementServer::CheckforDuplicateMidletsL: Start");
       
  1579     const RComponentIdArray &arrt = iStorage->GetComponentIds();
       
  1580     TInt cont(arrt.Count() );
       
  1581     for (TInt i( 0); i < cont; i++)
       
  1582         {
       
  1583         CDeploymentComponent &compo = iStorage->ComponentL(arrt[i]);
       
  1584         if (((compo.State() == EDCSActive) || (compo.State() == EDCSInactive ))
       
  1585                 && (compo.MidletName()== amidletParameters.iMidletName)
       
  1586                 && (compo.MidletVendor()== amidletParameters.iMidletVenorName))
       
  1587             {
       
  1588             //remove old one
       
  1589             iStorage->RemoveL(compo.InternalId() );
       
  1590             }
       
  1591         }
       
  1592 
       
  1593     RDEBUG( "CApplicationManagementServer::CheckforDuplicateMidletsL: End");
       
  1594     }
       
  1595 // ------------------------------------------------------------------------------------------------
       
  1596 // CApplicationManagementServer::JavaInstallL()
       
  1597 // ------------------------------------------------------------------------------------------------	
       
  1598 
       
  1599 void CApplicationManagementServer::JavaInstallL(CDeploymentComponent &aCompo)
       
  1600     {
       
  1601     RDEBUG( "CApplicationManagementServer::JavaInstallL: Start");
       
  1602 
       
  1603     TRequestStatus s;
       
  1604     TInt err(KErrNone);
       
  1605     // set state to install progress
       
  1606     aCompo.SetStatusNode(EDelivered_InstallProgress);
       
  1607     TRAP(err,InstallL( aCompo,s ));
       
  1608     if (err != KErrNone)
       
  1609         {
       
  1610         aCompo.SetStatusNode(EDelivered_InstalledFailedWithData);
       
  1611         User::Leave(err);
       
  1612         }
       
  1613     User::WaitForRequest(s);
       
  1614     SendServerToBackground();
       
  1615     if (s != KErrNone)
       
  1616         {
       
  1617         RDEBUG_2( "ApplicationManagementSession: JavaInstallL failed with code %d",
       
  1618                 s.Int() );
       
  1619         // set state to install failed with data
       
  1620         aCompo.SetStatusNode(EDelivered_InstalledFailedWithData);
       
  1621         User::Leave(s.Int() );
       
  1622         }
       
  1623     else
       
  1624         {
       
  1625         TMidletParameters midletParameters;
       
  1626         iUtility->RefreshJavaRegistryL();
       
  1627         //Ignore if any error comes
       
  1628         TRAPD(err,iUtility->GetInstalledMidletParametersL(midletParameters))
       
  1629         ;
       
  1630         TRAP(err,CheckforDuplicateMidletsL(midletParameters));
       
  1631 
       
  1632         if (err != KErrNone)
       
  1633             {
       
  1634             aCompo.SetStatusNode(EDelivered_InstalledFailedWithData);
       
  1635             User::Leave(err);
       
  1636             }
       
  1637         else
       
  1638             {
       
  1639             aCompo.SetStatusNode(EIdle);
       
  1640             }
       
  1641         aCompo.SetUid(midletParameters.iMidletUid);
       
  1642 
       
  1643         RDEBUG( "CApplicationManagementServer::JavaInstallL: Step1");
       
  1644         if (aCompo.ComponentVersion() == KNullDesC8)
       
  1645             {
       
  1646             aCompo.SetVersionL(midletParameters.bufVersion);
       
  1647 
       
  1648             }
       
  1649 
       
  1650         TBool status = EFalse;
       
  1651 
       
  1652         //Since "C" drive is not removable
       
  1653 
       
  1654         if (midletParameters.iDrive!=EDriveC)
       
  1655             {
       
  1656             status = IsInstalledAppRemovableL(midletParameters.iDrive);
       
  1657             }
       
  1658         if (status)
       
  1659             {
       
  1660             RDEBUG( "IsInstalledAppRemovableL(midletParameters.iDrive); True");
       
  1661             }
       
  1662         else
       
  1663             {
       
  1664             RDEBUG( "IsInstalledAppRemovableL(midletParameters.iDrive); False");
       
  1665             }
       
  1666 
       
  1667         //check for status drive
       
  1668         aCompo.SetAppRemovableStatus(status);
       
  1669         }
       
  1670 
       
  1671     RDEBUG( "CApplicationManagementServer::JavaInstallL: End");
       
  1672     }
       
  1673 
       
  1674 // ------------------------------------------------------------------------------------------------
       
  1675 // CApplicationManagementServer::SisInstallL()
       
  1676 // ------------------------------------------------------------------------------------------------	
       
  1677 
       
  1678 void CApplicationManagementServer::SisInstallL(
       
  1679         const CDeploymentComponent &aCompo)
       
  1680     {
       
  1681     TRequestStatus s;
       
  1682     // set state to install progress
       
  1683     aCompo.SetStatusNode(EDelivered_InstallProgress);
       
  1684     TInt err(KErrNone);
       
  1685     TRAP(err,InstallL( aCompo,s ));
       
  1686     if (err != KErrNone)
       
  1687         {
       
  1688         aCompo.SetStatusNode(EDelivered_InstalledFailedWithData);
       
  1689         User::Leave(err);
       
  1690         }
       
  1691     User::WaitForRequest(s);
       
  1692     if (s != KErrNone)
       
  1693         {
       
  1694         RDEBUG_2("ApplicationManagementSession: SisInstallL failed with code %d",
       
  1695                 s.Int() );
       
  1696         // set state to install failed with data
       
  1697         aCompo.SetStatusNode(EDelivered_InstalledFailedWithData);
       
  1698         User::Leave(s.Int() );
       
  1699         }
       
  1700     else
       
  1701         {
       
  1702         // set state to install sucessful
       
  1703         aCompo.SetStatusNode(EIdle);
       
  1704         RDEBUG("ApplicationManagementSession: SisInstallL successfull" );
       
  1705         }
       
  1706     RDEBUG( "CApplicationManagementServer::SisInstallL: End");
       
  1707     }
       
  1708 
       
  1709 // ------------------------------------------------------------------------------------------------
       
  1710 // CApplicationManagementServer::DoTheInstallL()
       
  1711 // ------------------------------------------------------------------------------------------------	
       
  1712 
       
  1713 void CApplicationManagementServer::DoTheInstallL(CDeploymentComponent &aCompo)
       
  1714     {
       
  1715     RDEBUG( "CApplicationManagementServer::DoTheInstallL: Start");
       
  1716     TInt error(KErrNone);
       
  1717     if (CDeploymentComponent::IsJavaMimeL(aCompo.Data().MimeType() )
       
  1718             || CDeploymentComponent::IsJavaMimeL(aCompo.MetaData().MimeType() ) )
       
  1719         {
       
  1720         TRAP( error, JavaInstallL( aCompo ) );
       
  1721         }
       
  1722     else
       
  1723         {
       
  1724         TRAP( error, SisInstallL( aCompo ) );
       
  1725         SetSisAppVersionAndDriveL(aCompo);
       
  1726         }
       
  1727     
       
  1728     SendServerToBackground();
       
  1729 
       
  1730     if (error == KErrNone)
       
  1731         {
       
  1732         InstallCompleteL(aCompo, ETrue);
       
  1733         CDeploymentComponent *old = DoDataUpdateCheckL(aCompo);
       
  1734         if (old)
       
  1735             {
       
  1736             if (aCompo.State() == EDCSDelivered)
       
  1737                 {
       
  1738                 if (old->State() == EDCSActive || old->State()== EDCSInactive)
       
  1739                     {
       
  1740                     RDEBUG("AMSession: DoTheInstallL ** deleting old node **" );
       
  1741                     iStorage->RemoveL(old->InternalId() );
       
  1742                     }
       
  1743                 }
       
  1744             }
       
  1745         iStorage->InstalledL(aCompo);
       
  1746         }
       
  1747     else
       
  1748         {
       
  1749         InstallCompleteL(aCompo, EFalse);
       
  1750         User::Leave(error);
       
  1751         }
       
  1752     RDEBUG( "CApplicationManagementServer::DoTheInstallL: End");
       
  1753     }
       
  1754 
       
  1755 // ------------------------------------------------------------------------------------------------
       
  1756 // CApplicationManagementServer::DoDataUpdateCheckL()
       
  1757 // ------------------------------------------------------------------------------------------------	
       
  1758 
       
  1759 CDeploymentComponent *CApplicationManagementServer::DoDataUpdateCheckL(
       
  1760         CDeploymentComponent &aCompo)
       
  1761     {
       
  1762     CDeploymentComponent *old= NULL;
       
  1763     if (aCompo.Uid() != TUid::Null() && HasUidL(aCompo.Uid(), old, &aCompo) )
       
  1764         {
       
  1765         // check for Uid component.. Legacy code removed.
       
  1766         }
       
  1767     return old;
       
  1768     }
       
  1769 
       
  1770 // ------------------------------------------------------------------------------------------------
       
  1771 // CApplicationManagementServer::SetDataL()
       
  1772 // ------------------------------------------------------------------------------------------------
       
  1773 
       
  1774 void CApplicationManagementServer::SetDataL(CDeploymentComponent &aCompo,
       
  1775         const TDesC8 &aData, const TDesC8 &aMime)
       
  1776     {
       
  1777     aCompo.SetDataL(aData, aMime);
       
  1778     DoDataUpdateCheckL(aCompo);
       
  1779     }
       
  1780 
       
  1781 // ------------------------------------------------------------------------------------------------
       
  1782 // CApplicationManagementServer::FullUpdateL()
       
  1783 // ------------------------------------------------------------------------------------------------
       
  1784 
       
  1785 void CApplicationManagementServer::FullUpdateL(const TUint32 sid,
       
  1786         const TUint32 tid)
       
  1787     {
       
  1788     CDeploymentComponent &scompo = iStorage->ComponentL(sid);
       
  1789     CDeploymentComponent &tcompo = iStorage->ComponentL(tid);
       
  1790     FullUpdateL(scompo, tcompo);
       
  1791     }
       
  1792 
       
  1793 // ------------------------------------------------------------------------------------------------
       
  1794 // CApplicationManagementServer::FullUpdateL()
       
  1795 // ------------------------------------------------------------------------------------------------
       
  1796 
       
  1797 void CApplicationManagementServer::FullUpdateL(CDeploymentComponent &scompo,
       
  1798         const CDeploymentComponent &tcompo)
       
  1799     {
       
  1800     if (scompo.State() == EDCSDelivered)
       
  1801         {
       
  1802         if (tcompo.State() == EDCSActive || tcompo.State() == EDCSInactive)
       
  1803             {
       
  1804             TRequestStatus s2;
       
  1805             InstallL(scompo, s2);
       
  1806             User::WaitForRequest(s2);
       
  1807             if (s2 != KErrNone)
       
  1808                 {
       
  1809                 RDEBUG_2( "ApplicationManagementSession: FullUpdateL failed with code %d", s2.Int() );
       
  1810                 User::Leave(s2.Int() );
       
  1811                 }
       
  1812             else
       
  1813                 {
       
  1814                 InstallCompleteL(scompo);
       
  1815                 // Before deleting old node ,copy node values which are not set in new node from old node
       
  1816                 if (scompo.ComponentId()== KNullDesC8)
       
  1817                 scompo.SetIdL(tcompo.ComponentId());
       
  1818                 
       
  1819                 if (scompo.ComponentName()== KNullDesC8)
       
  1820                 scompo.SetNameL(tcompo.ComponentName());
       
  1821                 
       
  1822                 if (scompo.ComponentVersion()== KNullDesC8)
       
  1823                 scompo.SetVersionL(tcompo.ComponentVersion());
       
  1824                 
       
  1825                 //Tag tcompo state for deletion. Cant delete now, since nsmldmtree woudnt be updated
       
  1826                 //Remove the const'ness since state needs to be updated.
       
  1827                 
       
  1828                 iStorage->SetDeploymentComponentState(const_cast <CDeploymentComponent &>(tcompo),EDCSDelete);
       
  1829 
       
  1830                 iStorage->InstalledL( scompo );
       
  1831                 RDEBUG( "ApplicationManagementSession: FullUpdateL ok" );
       
  1832                 }
       
  1833             }
       
  1834         else
       
  1835             {
       
  1836             RDEBUG_2( "ApplicationManagementSession: ERROR FullUpdateL called for illegal state component: %d!", scompo.State() );
       
  1837             User::Leave(KErrArgument);
       
  1838             }
       
  1839         }
       
  1840     else
       
  1841         {
       
  1842         RDEBUG( "ApplicationManagementSession: ERROR FullUpdateL called for illegal state message!" );
       
  1843         User::Leave(KErrArgument);
       
  1844         }
       
  1845     }
       
  1846 
       
  1847 // -------------------------------------------------------------------------------------------------------------------
       
  1848 // CApplicationManagementServer::IsDataFileB64EncodedL()
       
  1849 // -------------------------------------------------------------------------------------------------------------------
       
  1850 TBool CApplicationManagementServer::IsDataFileB64EncodedL(RFile &aFile,
       
  1851         TInt& aLength)
       
  1852     {
       
  1853     RDEBUG("CApplicationManagementServer::IsDataFileB64EncodedL()  : start");
       
  1854     TBool encoded = ETrue; // assume b64 encoded
       
  1855     TInt bufSize(KBase64BufSize);
       
  1856     TInt offset(0);
       
  1857     HBufC8 *dataBuf = HBufC8::NewLC(bufSize);
       
  1858     TPtr8 dataPtr = dataBuf->Des();
       
  1859     aFile.Size(aLength);
       
  1860     aFile.Seek(ESeekStart, offset);
       
  1861 
       
  1862     while (encoded)
       
  1863         {
       
  1864         aFile.Read(dataPtr);
       
  1865         if ( !dataPtr.Length() )
       
  1866             {
       
  1867             break;
       
  1868             }
       
  1869         offset = 0;
       
  1870         aFile.Seek(ESeekCurrent, offset);
       
  1871         RDEBUG_2("OFFSET: %d", offset);
       
  1872         encoded = CheckB64Encode(dataPtr);
       
  1873         }
       
  1874     RDEBUG_2("Encoded: %d", encoded);
       
  1875     CleanupStack::PopAndDestroy(dataBuf);
       
  1876     offset = 0;
       
  1877     aFile.Seek(ESeekStart, offset);
       
  1878 
       
  1879     RDEBUG("CApplicationManagementServer::IsDataFileB64EncodedL()  : end");
       
  1880     return encoded;
       
  1881     }
       
  1882 
       
  1883 // -------------------------------------------------------------------------------------------------------------------
       
  1884 // CApplicationManagementServer::CheckB64Encode( const TDesC8& aData )
       
  1885 // -------------------------------------------------------------------------------------------------------------------
       
  1886 TBool CApplicationManagementServer::CheckB64Encode(const TDesC8& aData)
       
  1887     {
       
  1888     TInt inputIndex = 0;
       
  1889     TInt inputLen = aData.Length();
       
  1890 
       
  1891     while (inputIndex < inputLen)
       
  1892         {
       
  1893         const TUint8& p = aData[ inputIndex ];
       
  1894 
       
  1895         if ((p >= 48 && p <= 57) || (p >= 65 && p <= 90) || (p >= 97 && p
       
  1896                 <= 122) || p == 43 || p == 47 || p == 61 || p == 10 || p
       
  1897                 == 13)
       
  1898             {
       
  1899             }
       
  1900         else
       
  1901             {
       
  1902             return EFalse;
       
  1903             }
       
  1904 
       
  1905         inputIndex++;
       
  1906 
       
  1907         }
       
  1908 
       
  1909     return ETrue;
       
  1910     }
       
  1911 
       
  1912 // ------------------------------------------------------------------------------------------------
       
  1913 // CApplicationManagementServer::GetAMServerDownloadDBL()
       
  1914 // ------------------------------------------------------------------------------------------------	
       
  1915 
       
  1916 void CApplicationManagementServer::GetAMServerDownloadDBL(TUint32 internalid,
       
  1917         TInt& finalresult, TDes8& aTargetURI)
       
  1918     {
       
  1919     RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step1" );
       
  1920 
       
  1921     TBuf<50> internalidbuf;
       
  1922 
       
  1923     RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step2" );
       
  1924     internalidbuf.Num(internalid);
       
  1925 
       
  1926     RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step3" );
       
  1927 
       
  1928     RPointerArray<CAMDbItem> aItemArray;
       
  1929 
       
  1930     RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step4" );
       
  1931 
       
  1932     iAMServerDB->GetEntryForLUIDL(aItemArray, internalidbuf);
       
  1933 
       
  1934     RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step5" );
       
  1935 
       
  1936     if (aItemArray.Count()!=0)
       
  1937         {
       
  1938         RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step6" );
       
  1939 
       
  1940         finalresult = aItemArray[0]->iResult;
       
  1941 
       
  1942         RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step7" );
       
  1943 
       
  1944         if (finalresult < KErrNone)
       
  1945             User::Leave(KErrGeneral);
       
  1946 
       
  1947         RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step8" );
       
  1948 
       
  1949         if (*aItemArray[0]->iTargetURI == KNullDesC8())
       
  1950             User::Leave(KErrGeneral);
       
  1951 
       
  1952         RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step9" );
       
  1953         aTargetURI.Copy(*aItemArray[0]->iTargetURI);
       
  1954 
       
  1955         }
       
  1956     RDEBUG( "CApplicationManagementServer::GetAMServerDownloadDBL(): Step10" );
       
  1957     aItemArray.ResetAndDestroy();
       
  1958 
       
  1959     }
       
  1960 
       
  1961 // ------------------------------------------------------------------------------------------------
       
  1962 // CApplicationManagementServer::DeleteGenericAlertForIDL()
       
  1963 // ------------------------------------------------------------------------------------------------	
       
  1964 
       
  1965 void CApplicationManagementServer::DeleteGenericAlertForIDL(TUint32 internalid)
       
  1966     {
       
  1967     iAMServerDB->DeleteFromDatabaseL(internalid);
       
  1968     }
       
  1969 
       
  1970 // -------------------------------------------------------------------------------------------------------------------
       
  1971 // CApplicationManagementServer::DecodeB64DataFileL( RFile& aDataFile, RFile& aDestinationFile )
       
  1972 // -------------------------------------------------------------------------------------------------------------------
       
  1973 void CApplicationManagementServer::DecodeB64DataFileL(RFile& aSourceFile,
       
  1974         RFile& aDestinationFile)
       
  1975     {
       
  1976     RDEBUG( "CApplicationManagementServer::DecodeB64DataFileL(): Start" );
       
  1977     // Create buffers
       
  1978     //TInt b64bufferSize = 131072;
       
  1979     TInt decodedBufferSize = ( (KBase64BufSize*3) / 4 + 16 );
       
  1980     HBufC8 *dataBuf = HBufC8::NewLC(KBase64BufSize);
       
  1981     TPtr8 dataPtr = dataBuf->Des();
       
  1982     HBufC8* targetBuf = HBufC8::NewLC(decodedBufferSize);
       
  1983     TPtr8 targetPtr(targetBuf->Des() );
       
  1984 
       
  1985     TInt offset(0);
       
  1986     TInt length(0);
       
  1987     TBool reading(ETrue);
       
  1988     aSourceFile.Size(length);
       
  1989     RDEBUG_2( "CApplicationManagementServer::DecodeB64DataFileL(): b64 file total size: (%d)", length );
       
  1990     aSourceFile.Seek(ESeekStart, offset);
       
  1991 
       
  1992     // Initialize decoder
       
  1993     TImCodecB64 B64Coder;
       
  1994     B64Coder.Initialise();
       
  1995 
       
  1996     while (reading)
       
  1997         {
       
  1998         aSourceFile.Read(dataPtr);
       
  1999         if ( !dataPtr.Length() )
       
  2000             {
       
  2001             // EOF
       
  2002             break;
       
  2003             }
       
  2004         offset = 0;
       
  2005         aSourceFile.Seek(ESeekCurrent, offset);
       
  2006         RDEBUG_2("OFFSET: %d", offset);
       
  2007 
       
  2008         // decode data
       
  2009         B64Coder.Decode(dataPtr, targetPtr);
       
  2010         // write decoded data to temporary file
       
  2011         aDestinationFile.Write(targetPtr);
       
  2012         }
       
  2013     CleanupStack::PopAndDestroy(targetBuf);
       
  2014     CleanupStack::PopAndDestroy(dataBuf);
       
  2015 
       
  2016     offset = 0;
       
  2017     aDestinationFile.Seek(ESeekStart, offset);
       
  2018     RDEBUG( "CApplicationManagementServer::DecodeB64DataFileL(): end" );
       
  2019     }
       
  2020 
       
  2021 // -------------------------------------------------------------------------------------------------------------------
       
  2022 // CApplicationManagementServer::DecodeB64DataLC( const TDesC8& aData )
       
  2023 // -------------------------------------------------------------------------------------------------------------------
       
  2024 HBufC8* CApplicationManagementServer::DecodeB64DataLC(const TDesC8 &aData)
       
  2025     {
       
  2026     RDEBUG( "CApplicationManagementServer::DecodeB64DataLC(): Start" );
       
  2027     TImCodecB64 B64Coder;
       
  2028     B64Coder.Initialise();
       
  2029     HBufC8 *target = HBufC8::NewLC( (aData.Length() * 3 ) / 4 + 16);
       
  2030     TPtr8 targetPtr(target->Des() );
       
  2031     B64Coder.Decode(aData, targetPtr);
       
  2032     RDEBUG( "CApplicationManagementServer::DecodeB64DataLC(): End" );
       
  2033     return target;
       
  2034     }
       
  2035 
       
  2036 // -------------------------------------------------------------------------------------------------------------------
       
  2037 //  CApplicationManagementServer::EncodeDataL( const TDesC8& aData, CBufBase &aTarget )
       
  2038 // -------------------------------------------------------------------------------------------------------------------
       
  2039 void CApplicationManagementServer::EncodeDataL(const TDesC8& aData,
       
  2040         CBufBase &aTarget)
       
  2041     {
       
  2042     TInt outLen(aData.Length() * 2);
       
  2043     aTarget.ExpandL(0, outLen);
       
  2044     TImCodecB64 B64Coder;
       
  2045     B64Coder.Initialise();
       
  2046     TPtr8 target(aTarget.Ptr(0) );
       
  2047     TInt decoded(B64Coder.Encode(aData, target) );
       
  2048     TInt s(target.Length() );
       
  2049     aTarget.ResizeL(s);
       
  2050     //	TInt s2( aTarget.Size());
       
  2051     aTarget.Compress();
       
  2052     //	TInt s3( aTarget.Size() );
       
  2053     if ( !decoded)
       
  2054         {
       
  2055         RDEBUG( "CApplicationManagementServer::EncodeDataL(): Encoding b64 failed?" );
       
  2056         }
       
  2057     }
       
  2058 
       
  2059 // -------------------------------------------------------------------------------------------------------------------
       
  2060 // CApplicationManagementSession::CApplicationManagementSession
       
  2061 // -------------------------------------------------------------------------------------------------------------------
       
  2062 inline CApplicationManagementSession::CApplicationManagementSession()
       
  2063     {
       
  2064     RDEBUG_2( "CApplicationManagementSession::CApplicationManagementSession 0x%x", this);
       
  2065     }
       
  2066 
       
  2067 // -------------------------------------------------------------------------------------------------------------------
       
  2068 // CApplicationManagementSession::CApplicationManagementSession
       
  2069 // -------------------------------------------------------------------------------------------------------------------
       
  2070 
       
  2071 inline CApplicationManagementSession::CApplicationManagementSession(
       
  2072         const TCertInfo &aInfo) :
       
  2073     iCertInfo(aInfo)
       
  2074     {
       
  2075     RDEBUG( "CApplicationManagementSession::CApplicationManagementSession (cert) " );
       
  2076     }
       
  2077 
       
  2078 // -------------------------------------------------------------------------------------------------------------------
       
  2079 // CApplicationManagementSession::Server()
       
  2080 // -------------------------------------------------------------------------------------------------------------------
       
  2081 
       
  2082 inline CApplicationManagementServer& CApplicationManagementSession::Server() const
       
  2083     {
       
  2084     return *static_cast<CApplicationManagementServer*>( const_cast<CServer2*>(CSession2::Server()));
       
  2085     }
       
  2086 
       
  2087 // -------------------------------------------------------------------------------------------------------------------
       
  2088 // CApplicationManagementSession::CreateL()
       
  2089 // -------------------------------------------------------------------------------------------------------------------
       
  2090 // 2nd phase construct for sessions - called by the CServer framework
       
  2091 
       
  2092 void CApplicationManagementSession::CreateL()
       
  2093     {
       
  2094     RDEBUG_2( "ApplicationManagementSession: CApplicationManagementSession::CreateL: 0x%x", this );
       
  2095 
       
  2096     Server().AddSession();
       
  2097     CAknAppServiceBase::CreateL();
       
  2098     }
       
  2099 
       
  2100 // -------------------------------------------------------------------------------------------------------------------
       
  2101 // CApplicationManagementSession::~CApplicationManagementSession()
       
  2102 // -------------------------------------------------------------------------------------------------------------------
       
  2103 
       
  2104 CApplicationManagementSession::~CApplicationManagementSession()
       
  2105     {
       
  2106     RDEBUG_3("CApplicationManagementSession::~CApplicationManagementSession 0x%X - 0x%X", reinterpret_cast<TUint>(this),
       
  2107             reinterpret_cast<TUint>(this)+sizeof( CApplicationManagementSession ) );
       
  2108     RDEBUG_2("CApplicationManagementSession::~CApplicationManagementSession iCertInfo offs 0x%X",
       
  2109             reinterpret_cast<TUint>(&this->iCertInfo) - reinterpret_cast<TUint>(this) );
       
  2110 
       
  2111     Server().DropSession();
       
  2112     }
       
  2113 
       
  2114 // -------------------------------------------------------------------------------------------------------------------
       
  2115 // CApplicationManagementSession::ServiceL()
       
  2116 // -------------------------------------------------------------------------------------------------------------------
       
  2117 
       
  2118 void CApplicationManagementSession::ServiceL(const RMessage2& aMessage)
       
  2119     {
       
  2120     if (aMessage.Function() == EPerformRfs)
       
  2121         {
       
  2122         TRAPD( err, Server().PerformRFSL() )
       
  2123         ;
       
  2124         aMessage.Complete(err);
       
  2125         }
       
  2126     else
       
  2127         {
       
  2128         TBool handled(EFalse);
       
  2129         TInt err(KErrNone);
       
  2130         TRAP( err, handled = PreDispatchMessageL( aMessage ) );
       
  2131         if ( !handled)
       
  2132             {
       
  2133             TRAP(err,DispatchMessageL(aMessage));
       
  2134             }
       
  2135 
       
  2136         // Some of the functions contains operations that already complete message
       
  2137         // doing Complete() twice will cause panic
       
  2138         if (aMessage.Handle() )
       
  2139             {
       
  2140             aMessage.Complete(err);
       
  2141             }
       
  2142         }
       
  2143     }
       
  2144 
       
  2145 // CApplicationManagementSession::PreDispatchMessageL()
       
  2146 // -------------------------------------------------------------------------------------------------------------------
       
  2147 
       
  2148 TBool CApplicationManagementSession::PreDispatchMessageL(
       
  2149         const RMessage2 &aMessage)
       
  2150     {
       
  2151     TBool ret(EFalse);
       
  2152     // These succeed regardless of certificate....
       
  2153     switch (aMessage.Function() )
       
  2154         {
       
  2155         case EGetStateChangingIdsCountOperation:
       
  2156             {
       
  2157             // gets count of items list of ids that are potentially changing state
       
  2158             StateChangeComponentIdsCountL(aMessage);
       
  2159             ret = ETrue;
       
  2160             break;
       
  2161             }
       
  2162         case EGetStateChangingIdsOperation:
       
  2163             {
       
  2164             // gets list of ids that are potentially changing state
       
  2165             StateChangeComponentIdsL(aMessage);
       
  2166             ret = ETrue;
       
  2167             break;
       
  2168             }
       
  2169         case ECompleteStateChangeOperation: // completes change of state
       
  2170             {
       
  2171             StateChangeCompleteL(aMessage);
       
  2172             ret = ETrue;
       
  2173             break;
       
  2174             }
       
  2175         default:
       
  2176             {
       
  2177             break;
       
  2178             }
       
  2179         }
       
  2180     return ret;
       
  2181     }
       
  2182 
       
  2183 // -------------------------------------------------------------------------------------------------------------------
       
  2184 // CApplicationManagementSession::DispatchMessageL()
       
  2185 // -------------------------------------------------------------------------------------------------------------------
       
  2186 
       
  2187 void CApplicationManagementSession::DispatchMessageL(const RMessage2& aMessage)
       
  2188     {
       
  2189     RDEBUG_2( "CApplicationManagementSession::DispatchMessageL; %d" ,
       
  2190             aMessage.Function() );
       
  2191 
       
  2192     TBool go(EFalse);
       
  2193     if (iTrustAdded)
       
  2194         {
       
  2195         go = Server().CheckCertL(iCertInfo);
       
  2196         }
       
  2197     else
       
  2198         {
       
  2199         go = ETrue;
       
  2200         }
       
  2201 
       
  2202     if (go)
       
  2203         {
       
  2204         switch (aMessage.Function() )
       
  2205             {
       
  2206             case EAddTrust:
       
  2207                 {
       
  2208                 RDEBUG_2( "CApplicationManagementSession::DispatchMessageL; EAddTrust this=0x%x", this );
       
  2209                 AddTrustL(aMessage);
       
  2210                 break;
       
  2211                 }
       
  2212             case EDeplCompCountOperation:
       
  2213                 {
       
  2214                 ComponentCountL(aMessage);
       
  2215                 return;
       
  2216                 }
       
  2217             case EDeplCompIdsOperation:
       
  2218                 {
       
  2219                 ComponentIdsL(aMessage);
       
  2220                 return;
       
  2221                 }
       
  2222             case EDeplCompDeliverCompleteOperation:
       
  2223                 {
       
  2224                 DeliverCompleteL(aMessage);
       
  2225                 break;
       
  2226                 }
       
  2227             case EDeplCompGetOperation:
       
  2228                 {
       
  2229                 GetComponentL(aMessage) ;
       
  2230                 break;
       
  2231                 }
       
  2232             case EInstallOperation:
       
  2233                 {
       
  2234                 InstallL(aMessage) ;
       
  2235                 break;
       
  2236                 }
       
  2237             case EDeplCompAttrUpdateOperation:
       
  2238                 {
       
  2239                 UpdateL(aMessage) ;
       
  2240                 break;
       
  2241                 }
       
  2242             case EDeplCompGetDataOperation:
       
  2243                 {
       
  2244                 GetDataL(aMessage) ;
       
  2245                 break;
       
  2246                 }
       
  2247             case EDeplCompGetDataLengthOperation:
       
  2248                 {
       
  2249                 GetDataLengthL(aMessage) ;
       
  2250                 break;
       
  2251                 }
       
  2252             case EDeplCompRemoveOperation:
       
  2253                 {
       
  2254                 RemoveL(aMessage) ;
       
  2255                 break;
       
  2256                 }
       
  2257             case EDeplCompDeliverStartOperation2:
       
  2258                 {
       
  2259                 Deliver2L(aMessage) ;
       
  2260                 break;
       
  2261                 }
       
  2262             case EDeplCompUpdateDataOperation:
       
  2263                 {
       
  2264                 UpdateDataL(aMessage) ;
       
  2265                 break;
       
  2266                 }
       
  2267             case EDeplCompUpdateStreamedDataOperation:
       
  2268                 {
       
  2269                 UpdateStreamedDataL(aMessage) ;
       
  2270                 break;
       
  2271                 }
       
  2272             case EDeplCompDownloadOperation:
       
  2273                 {
       
  2274                 DownloadL(aMessage) ;
       
  2275                 break;
       
  2276                 }
       
  2277             case EDeplCompUpdateOperation:
       
  2278                 {
       
  2279                 FullUpdateL(aMessage) ;
       
  2280                 break;
       
  2281                 }
       
  2282             case EDeplCompGetUserIdOperation:
       
  2283                 {
       
  2284                 GetUserIdL(aMessage);
       
  2285                 break;
       
  2286                 }
       
  2287             case EDeplCompStartDownloadOperation:
       
  2288                 {
       
  2289                 StartDownloadL(aMessage);
       
  2290                 break;
       
  2291                 }
       
  2292             case EDeplCompDeactivateOperation:
       
  2293                 {
       
  2294                 DeactivateL(aMessage);
       
  2295                 break;
       
  2296                 }
       
  2297             case EDeplCompActivateOperation:
       
  2298                 {
       
  2299                 ActivateL(aMessage);
       
  2300                 break;
       
  2301                 }
       
  2302             case EDeplCompGetTemporaryInstFile:
       
  2303                 {
       
  2304                 GetTemporaryInstFileL(aMessage);
       
  2305                 break;
       
  2306                 }
       
  2307 
       
  2308             case EDeplCompGetFinalResultForGA:
       
  2309                 {
       
  2310                 GetFinalResultForGAL(aMessage);
       
  2311                 break;
       
  2312 
       
  2313                 }
       
  2314             case EDeplCompGenericAlertSent:
       
  2315                 {
       
  2316                 GenericAlertSentForIdL(aMessage);
       
  2317                 break;
       
  2318                 }
       
  2319             case ECheckStatusNodes:
       
  2320                 {
       
  2321                 CheckStatusNodesValuesL();
       
  2322                 break;
       
  2323                 }
       
  2324 
       
  2325             default:
       
  2326                 {
       
  2327                 User::Leave(KErrNotSupported);
       
  2328                 break;
       
  2329                 }
       
  2330             }
       
  2331         }
       
  2332     else
       
  2333         {
       
  2334         RDEBUG_2( "CApplicationManagementSession::DispatchMessageL; Policy prevented action this=0x%x", this );
       
  2335         User::Leave(KErrAccessDenied);
       
  2336         }
       
  2337     }
       
  2338 
       
  2339 // -------------------------------------------------------------------------------------------------------------------
       
  2340 // CApplicationManagementSession::GenericAlertSentForIdL()
       
  2341 // -------------------------------------------------------------------------------------------------------------------
       
  2342 
       
  2343 void CApplicationManagementSession::GenericAlertSentForIdL(
       
  2344         const RMessage2& aMessage) const
       
  2345     {
       
  2346     TUint32 luid;
       
  2347     TPckg<TUint32> pk(luid);
       
  2348     TInt read(aMessage.Read(0, pk));
       
  2349 
       
  2350     Server().DeleteGenericAlertForIDL(luid);
       
  2351 
       
  2352     }
       
  2353 
       
  2354 // -------------------------------------------------------------------------------------------------------------------
       
  2355 // CApplicationManagementSession::GetFinalResultForGAL()
       
  2356 // -------------------------------------------------------------------------------------------------------------------
       
  2357 
       
  2358 void CApplicationManagementSession::GetFinalResultForGAL(
       
  2359         const RMessage2& aMessage)
       
  2360     {
       
  2361 
       
  2362     RDEBUG( "CApplicationManagementSession: GetFinalResultForGAL Step 1" );
       
  2363     TUint32 luid;
       
  2364     TPckg<TUint32> pk(luid);
       
  2365 
       
  2366     TInt finalresult = KErrNone;
       
  2367 
       
  2368     RDEBUG( "CApplicationManagementSession: GetFinalResultForGAL Step 2" );
       
  2369 
       
  2370     HBufC8 *targetURI = HBufC8::NewL(512);
       
  2371     TPtr8 ptr = targetURI->Des();
       
  2372 
       
  2373     RDEBUG( "CApplicationManagementSession: GetFinalResultForGAL Step 3" );
       
  2374 
       
  2375     TInt read(aMessage.Read(0, pk));
       
  2376 
       
  2377     RDEBUG( "CApplicationManagementSession: GetFinalResultForGAL Step 4" );
       
  2378 
       
  2379     Server().GetAMServerDownloadDBL(luid, finalresult, ptr);
       
  2380 
       
  2381     RDEBUG( "CApplicationManagementSession: GetFinalResultForGAL Step 5" );
       
  2382 
       
  2383     RDEBUG_2( "ApplicationManagementServer: GetFinalResultForGAL Count is %d", finalresult );
       
  2384     TPckg<TInt> p1(finalresult);
       
  2385     aMessage.WriteL(1, p1);
       
  2386 
       
  2387     RDEBUG( "CApplicationManagementSession: GetFinalResultForGAL Step 6" );
       
  2388     aMessage.WriteL(2, ptr);
       
  2389 
       
  2390     RDEBUG( "CApplicationManagementSession: GetFinalResultForGAL Step 7" );
       
  2391     if (targetURI)
       
  2392         delete targetURI;
       
  2393 
       
  2394     }
       
  2395 
       
  2396 // -------------------------------------------------------------------------------------------------------------------
       
  2397 // CApplicationManagementSession::ComponentCountL()
       
  2398 // -------------------------------------------------------------------------------------------------------------------
       
  2399 
       
  2400 void CApplicationManagementSession::ComponentCountL(const RMessage2& aMessage)
       
  2401     {
       
  2402     RDEBUG( "CApplicationManagementSession: ComponentCountL" );
       
  2403     TDeploymentComponentState st;
       
  2404     TPckg<TDeploymentComponentState> pk(st);
       
  2405 
       
  2406     TInt read(aMessage.Read( 1, pk) );
       
  2407     RDEBUG_3( "CApplicationManagementSession: ComponentCountL State is %d, read %d", st, read);
       
  2408 
       
  2409     const RComponentIdArray &arrt = Server().Storage()->GetComponentIds();
       
  2410     RComponentIdArray arr;
       
  2411     CleanupClosePushL(arr);
       
  2412     if ((st == EDCSActive)||(st == EDCSInactive))
       
  2413         {
       
  2414         ActiveComponentsL(arrt, arr,st);
       
  2415         }
       
  2416     else
       
  2417         {
       
  2418         TInt count(arrt.Count() );
       
  2419         for (TInt i( 0); i < count; i++)
       
  2420             {
       
  2421             CDeploymentComponent &compo = Server().Storage()->ComponentL(arrt[i]);
       
  2422             if (st == EDCSNone || compo.State() == st)
       
  2423                 {
       
  2424                 arr.Append(arrt[i]);
       
  2425                 }
       
  2426             }
       
  2427         }
       
  2428     TInt n(arr.Count() );
       
  2429     CleanupStack::PopAndDestroy( &arr);
       
  2430 
       
  2431     RDEBUG_2( "ApplicationManagementServer: ComponentCountL Count is %d", n );
       
  2432     TPckg<TInt> p(n);
       
  2433 
       
  2434     aMessage.WriteL(0, p);
       
  2435 
       
  2436     }
       
  2437 
       
  2438 // -------------------------------------------------------------------------------------------------------------------
       
  2439 // CApplicationManagementSession::ActiveComponentsL()
       
  2440 // -------------------------------------------------------------------------------------------------------------------
       
  2441 
       
  2442 void CApplicationManagementSession::ActiveComponentsL(
       
  2443         const RComponentIdArray &aArrt, RComponentIdArray &aArr,TDeploymentComponentState &aState) const
       
  2444     {
       
  2445     Swi::RSisRegistrySession sisses;
       
  2446     TInt r(sisses.Connect() );
       
  2447     User::LeaveIfError(r) ;
       
  2448     CleanupClosePushL(sisses);
       
  2449 
       
  2450     RArray<TUid> uids;
       
  2451     sisses.InstalledUidsL(uids);
       
  2452     CleanupClosePushL(uids);
       
  2453     TInt cont(aArrt.Count() );
       
  2454     TInt uidc(uids.Count() );
       
  2455     RArray<TUid> juids;
       
  2456     Server().JavaUidsL(juids);
       
  2457     CleanupClosePushL(juids);
       
  2458     TInt juidc(juids.Count() );
       
  2459     RComponentIdArray rem;
       
  2460     CleanupClosePushL(rem);
       
  2461     for (TInt i( 0); i < cont; i++)
       
  2462         {
       
  2463         CDeploymentComponent &compo = Server().Storage()->ComponentL(aArrt[i]);
       
  2464         TDeploymentComponentState state = compo.State();
       
  2465         if (state == aState)
       
  2466             {
       
  2467             TBool add(EFalse);
       
  2468             const TUid &uid(compo.Uid() );
       
  2469             for (TInt j( 0); add == EFalse && j < uidc; j++)
       
  2470                 {
       
  2471 
       
  2472                 if (uids[j] == uid)
       
  2473                     {
       
  2474                    
       
  2475                     RDEBUG( "CApplicationManagementSession::ActiveComponentsL Entered" );
       
  2476                     
       
  2477                     // Check if this registry entry is present
       
  2478                     Swi::RSisRegistrySession sisSession;
       
  2479     								User::LeaveIfError(sisSession.Connect());
       
  2480     								CleanupClosePushL(sisSession);
       
  2481 
       
  2482     								Swi::RSisRegistryEntry sisEntry;
       
  2483 
       
  2484                     //Opens the base package entry by specifying a UID. 
       
  2485                     User::LeaveIfError(sisEntry.Open(sisSession, compo.Uid()));
       
  2486                     CleanupClosePushL(sisEntry);   
       
  2487 
       
  2488 										add  = sisEntry.IsPresentL();	
       
  2489 										
       
  2490 			  if(add)
       
  2491                     {
       
  2492 				
       
  2493 				// If Present update the Version, name and other info to that deployement component. Since application would have got an update
       
  2494                         // by some other means
       
  2495 				
       
  2496                         TVersion version = sisEntry.VersionL();
       
  2497                         TBuf8<KVersionLength> pkgDes;
       
  2498                         pkgDes.AppendNum(version.iMajor);
       
  2499                         pkgDes.Append(KLiteralPeriod);
       
  2500                         pkgDes.AppendNum(version.iMinor);
       
  2501                         
       
  2502 				
       
  2503 				HBufC *packagename = sisEntry.PackageNameL();
       
  2504 				TBuf8<512> packagename8;
       
  2505 				packagename8.Copy(*packagename);
       
  2506 				delete packagename;
       
  2507 
       
  2508                         compo.SetNameL(packagename8);
       
  2509                         compo.SetVersionL(pkgDes);
       
  2510 				                        
       
  2511 
       
  2512                         Server().Storage()->UpdateL( compo );
       
  2513                         
       
  2514 
       
  2515 				
       
  2516 
       
  2517 				RDEBUG( "CApplicationManagementSession::ActiveComponentsL ETrue" );
       
  2518 
       
  2519 
       
  2520 			  }
       
  2521 			  else
       
  2522 			      RDEBUG( "CApplicationManagementSession::ActiveComponentsL EFalse" );
       
  2523 																	    
       
  2524 	
       
  2525                     CleanupStack::PopAndDestroy(2, &sisSession);
       
  2526                                    
       
  2527                     }
       
  2528                 }
       
  2529             if ( !add) // go throug java suites
       
  2530                 {
       
  2531                 for (TInt k( 0); add == EFalse && k < juidc; k++)
       
  2532                     {
       
  2533                     if (juids[k] == uid)
       
  2534                         {
       
  2535                         add = ETrue;
       
  2536                         }
       
  2537                     }
       
  2538                 }
       
  2539             if (add)
       
  2540                 {
       
  2541                 aArr.Append(aArrt[i]);
       
  2542                 }
       
  2543             else
       
  2544                 {
       
  2545                 RDEBUG8_3( "ApplicationManagementServer: ActiveComponentCountL skipping 0x%x, %S",
       
  2546                         compo.Uid() ,&compo.ComponentId() );
       
  2547                 rem.Append(aArrt[i]);
       
  2548                 }
       
  2549             }
       
  2550         }
       
  2551     TInt rc(rem.Count() );
       
  2552     for (TInt t( 0); t < rc; t++)
       
  2553         {
       
  2554         RDEBUG_2( "ApplicationManagementServer: ActiveComponentCountL removing non existing %d", rem[t] );
       
  2555         CDeploymentComponent &compo = Server().Storage()->ComponentL(rem[t]);
       
  2556         if(!compo.AppRemovable())
       
  2557         Server().RemoveInternalL(compo, EFalse);
       
  2558         }
       
  2559     CleanupStack::PopAndDestroy( &rem);
       
  2560     CleanupStack::PopAndDestroy( &juids);
       
  2561     CleanupStack::PopAndDestroy( &uids);
       
  2562     CleanupStack::PopAndDestroy( &sisses);
       
  2563     }
       
  2564 
       
  2565 // -------------------------------------------------------------------------------------------------------------------
       
  2566 // CApplicationManagementSession::ComponentIdsL()
       
  2567 // -------------------------------------------------------------------------------------------------------------------
       
  2568 
       
  2569 void CApplicationManagementSession::ComponentIdsL(const RMessage2& aMessage) const
       
  2570     {
       
  2571     RDEBUG( "CApplicationManagementSession: ComponentIdsL" );
       
  2572     TDeploymentComponentState st;
       
  2573     TPckg<TDeploymentComponentState> pk(st);
       
  2574 
       
  2575     TInt read(aMessage.Read( 1, pk) );
       
  2576     RDEBUG_3( "CApplicationManagementSession: ComponentIdsL State is %d, read %d", st, read);
       
  2577 
       
  2578     const RComponentIdArray &arrt = Server().Storage()->GetComponentIds();
       
  2579     TInt buflen( 0);
       
  2580     TUint32* buf= NULL;
       
  2581     if (st == EDCSNone)
       
  2582         {
       
  2583         buflen = arrt.Count() ;
       
  2584         buf = new ( ELeave ) TUint32[buflen];
       
  2585         CleanupArrayDeletePushL(buf);
       
  2586         for (TInt i( 0); i < buflen; i++)
       
  2587             {
       
  2588             RDEBUG_2("ApplicationManagementSession: ComponentIdsL Adding %d!!", arrt[i]);
       
  2589             buf[i] = arrt[i];
       
  2590             }
       
  2591         }
       
  2592     else
       
  2593         {
       
  2594         RComponentIdArray arr;
       
  2595         if (st == EDCSActive)
       
  2596             {
       
  2597             ActiveComponentsL(arrt, arr,st);
       
  2598             }
       
  2599         else
       
  2600             {
       
  2601             TInt artc(arrt.Count() );
       
  2602             for (TInt i( 0); i < artc; i++)
       
  2603                 {
       
  2604                 CDeploymentComponent &compo = Server().Storage()->ComponentL(arrt[i]);
       
  2605                 if (compo.State() == st)
       
  2606                     {
       
  2607                     arr.Append(arrt[i]);
       
  2608                     }
       
  2609                 }
       
  2610             }
       
  2611         buflen = arr.Count() ;
       
  2612         buf = new ( ELeave ) TUint32[buflen];
       
  2613         CleanupArrayDeletePushL(buf);
       
  2614 
       
  2615         TUint32 len(aMessage.GetDesMaxLength( 0) / 4);
       
  2616         if (buflen == len)
       
  2617             {
       
  2618             RDEBUG( "CApplicationManagementSession: ComponentIdsL Right count!!" );
       
  2619             }
       
  2620         else
       
  2621             {
       
  2622             RDEBUG_3( "CApplicationManagementSession: ComponentIdsL Wrong count (is %d, should be %d)!!", len, buflen);
       
  2623             if (len < buflen)
       
  2624                 {
       
  2625                 buflen = len;
       
  2626                 }
       
  2627             }
       
  2628         for (TInt i( 0); i < buflen; i++)
       
  2629             {
       
  2630             RDEBUG_2( "CApplicationManagementSession: ComponentIdsL Adding %d!!",
       
  2631                     arr[i] );
       
  2632             buf[i] = arr[i];
       
  2633             }
       
  2634         arr.Close();
       
  2635         }
       
  2636 
       
  2637     TPtrC8 p( ( TUint8* ) buf, buflen * sizeof(TUint32));
       
  2638     aMessage.WriteL( 0, p);
       
  2639 
       
  2640     CleanupStack::PopAndDestroy(buf);
       
  2641     }
       
  2642 
       
  2643 #ifdef _DEBUG
       
  2644 HBufC* Des8to16LC(const TDesC8 &aDes)
       
  2645     {
       
  2646     HBufC *b = HBufC::NewLC(aDes.Length() );
       
  2647     TPtr p(b->Des() );
       
  2648     p.Copy(aDes);
       
  2649     return b;
       
  2650     }
       
  2651 
       
  2652 HBufC* ToStringLC(TDeploymentComponent &aComp)
       
  2653     {
       
  2654     HBufC *b = HBufC::NewLC(aComp.iId.Length() + aComp.iName.Length()
       
  2655             + aComp.iVersion.Length() + 10 + 50);
       
  2656     TPtr p(b->Des() );
       
  2657     _LIT( KFormat, "Id: '%S', Name: '%S', Version: '%S', State: %d, OldState: %d");
       
  2658     p.Format(KFormat, &*Des8to16LC(aComp.iId), &*Des8to16LC(aComp.iName),
       
  2659             &*Des8to16LC(aComp.iVersion), aComp.iState, aComp.iOldState) ;
       
  2660     CleanupStack::PopAndDestroy( 3);
       
  2661     return b;
       
  2662     }
       
  2663 #endif
       
  2664 
       
  2665 // -------------------------------------------------------------------------------------------------------------------
       
  2666 // CApplicationManagementSession::Deliver2L()
       
  2667 // -------------------------------------------------------------------------------------------------------------------
       
  2668 
       
  2669 void CApplicationManagementSession::Deliver2L(const RMessage2& aMessage) const
       
  2670     {
       
  2671     RDEBUG( "ApplicationManagementSession: Deliver2L" );
       
  2672 
       
  2673     TDeploymentComponentIPC comp;
       
  2674     TPckg< TDeploymentComponentIPC> pcomp(comp);
       
  2675     TInt read2(aMessage.Read( 0, pcomp) );
       
  2676 
       
  2677     HBufC8 *data = HBufC8::NewLC(aMessage.GetDesLength( 1) );
       
  2678     TPtr8 pbuf(data->Des());
       
  2679     TInt read(aMessage.Read( 1, pbuf) );
       
  2680 
       
  2681     CDeploymentComponent *compo= NULL;
       
  2682     if (iTrustAdded)
       
  2683         {
       
  2684         compo = Server().Storage()->NewComponentL(EDCSDelivered, comp.iUserId, &iCertInfo);
       
  2685         }
       
  2686     else
       
  2687         {
       
  2688         compo = Server().Storage()->NewComponentL(EDCSDelivered, comp.iUserId);
       
  2689         }
       
  2690 
       
  2691     compo->Set(comp.iComponent);
       
  2692     compo->Data().SetDataL(pbuf, comp.iMimeType);
       
  2693     Server().Storage()->UpdateL( *compo);
       
  2694     compo->CopyStateTo(comp.iComponent);
       
  2695 
       
  2696 #ifdef _DEBUG
       
  2697     RDEBUG_2( "Deliver2L: TDeploymentComponent is '%S'",
       
  2698             ToStringLC( comp.iComponent ) );
       
  2699     CleanupStack::PopAndDestroy();
       
  2700 #endif
       
  2701 
       
  2702     TPckg< TDeploymentComponent> pcomp2(comp.iComponent);
       
  2703     aMessage.Write( 0, pcomp2);
       
  2704     CleanupStack::PopAndDestroy(data) ;
       
  2705     TInt n(compo->InternalId() );
       
  2706     TPckg<TUint32> p(n);
       
  2707     aMessage.WriteL( 2, p);
       
  2708     }
       
  2709 
       
  2710 // -------------------------------------------------------------------------------------------------------------------
       
  2711 // CApplicationManagementSession::DeliverCompleteL()
       
  2712 // -------------------------------------------------------------------------------------------------------------------
       
  2713 
       
  2714 void CApplicationManagementSession::DeliverCompleteL(const RMessage2& aMessage) const
       
  2715     {
       
  2716     RDEBUG( "ApplicationManagementSession: DeliverCompleteL" );
       
  2717     TUint32 id;
       
  2718     TPckg<TUint32> pid(id);
       
  2719 
       
  2720     TInt read(aMessage.Read( 0, pid) );
       
  2721     RDEBUG_2( "ApplicationManagementSession: DeliverCompleteL id is %d", id );
       
  2722 
       
  2723     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2724 
       
  2725     HBufC8 *opts = HBufC8::NewLC(aMessage.GetDesLength( 1) );
       
  2726     TPtr8 popts(opts->Des() );
       
  2727     TInt read1(aMessage.Read( 1, popts) );
       
  2728     compo.SetInstallOptsL( *opts);
       
  2729 
       
  2730     HBufC8 *meta = HBufC8::NewLC(aMessage.GetDesLength( 2) );
       
  2731     TPtr8 pmeta(meta->Des() );
       
  2732     TInt read2(aMessage.Read( 2, pmeta) );
       
  2733     compo.SetMetaDataL( *meta, KNullDesC8);
       
  2734 
       
  2735     CleanupStack::PopAndDestroy(meta) ;
       
  2736     CleanupStack::PopAndDestroy(opts) ;
       
  2737     Server().Storage()->UpdateL(compo);
       
  2738     }
       
  2739 
       
  2740 // -------------------------------------------------------------------------------------------------------------------
       
  2741 // CApplicationManagementSession::GetComponentL()
       
  2742 // -------------------------------------------------------------------------------------------------------------------
       
  2743 
       
  2744 void CApplicationManagementSession::GetComponentL(const RMessage2& aMessage) const
       
  2745     {
       
  2746     RDEBUG( "ApplicationManagementSession: GetComponentL" );
       
  2747     TUint32 id;
       
  2748     TPckg<TUint32> pid(id);
       
  2749     TInt read(aMessage.Read( 0, pid) );
       
  2750 
       
  2751     RDEBUG_2( "ApplicationManagementSession: GetComponentL id is %d", id );
       
  2752     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2753 
       
  2754     TDeploymentComponent comp;
       
  2755     compo.CopyStateTo(comp);
       
  2756 
       
  2757     TPckg< TDeploymentComponent> pcomp(comp);
       
  2758     aMessage.Write( 1, pcomp);
       
  2759     }
       
  2760 
       
  2761 // -------------------------------------------------------------------------------------------------------------------
       
  2762 // CApplicationManagementSession::StartDownloadL()
       
  2763 // -------------------------------------------------------------------------------------------------------------------
       
  2764 
       
  2765 void CApplicationManagementSession::StartDownloadL(const RMessage2& aMessage) const
       
  2766     {
       
  2767     RDEBUG( "ApplicationManagementSession: StartDownloadL" );
       
  2768     TUint32 id = 0;
       
  2769     TPckg<TUint32> pid(id);
       
  2770     TInt read(aMessage.Read( 0, pid) );
       
  2771 
       
  2772     TPckgBuf<TDownloadTarget> target;
       
  2773     read = aMessage.Read( 1, target) ;
       
  2774     RDEBUG_2( "ApplicationManagementSession: StartDownloadL id is %d", id );
       
  2775 
       
  2776     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2777     compo.SetDownloadTarget(target() );
       
  2778     Server().AddDownloadL( &compo);
       
  2779     }
       
  2780 
       
  2781 // -------------------------------------------------------------------------------------------------------------------
       
  2782 // CApplicationManagementSession::DeactivateL()
       
  2783 // -------------------------------------------------------------------------------------------------------------------
       
  2784 
       
  2785 void CApplicationManagementSession::DeactivateL(const RMessage2& aMessage) const
       
  2786     {
       
  2787     RDEBUG( "ApplicationManagementSession: DeactivateL" );
       
  2788     TUint32 id = 0;
       
  2789     TPckg<TUint32> pid(id);
       
  2790     TInt read(aMessage.Read( 0, pid) );
       
  2791 
       
  2792     RDEBUG_2( "ApplicationManagementSession: DeactivateL id is %d", id );
       
  2793     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2794     Server().Storage()->DeactivateL(compo);
       
  2795     }
       
  2796 
       
  2797 // -------------------------------------------------------------------------------------------------------------------
       
  2798 // CApplicationManagementSession::ActivateL()
       
  2799 // -------------------------------------------------------------------------------------------------------------------
       
  2800 
       
  2801 void CApplicationManagementSession::ActivateL(const RMessage2& aMessage) const
       
  2802     {
       
  2803     RDEBUG( "ApplicationManagementSession: ActivateL" );
       
  2804     TUint32 id;
       
  2805     TPckg<TUint32> pid(id);
       
  2806     TInt read(aMessage.Read( 0, pid) );
       
  2807 
       
  2808     RDEBUG_2( "ApplicationManagementSession: ActivateL id is %d", id );
       
  2809     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2810     Server().Storage()->ActivateL(compo);
       
  2811     }
       
  2812 
       
  2813 // -------------------------------------------------------------------------------------------------------------------
       
  2814 // CApplicationManagementSession::GetUserIdL()
       
  2815 // -------------------------------------------------------------------------------------------------------------------
       
  2816 
       
  2817 void CApplicationManagementSession::GetUserIdL(const RMessage2& aMessage) const
       
  2818     {
       
  2819     RDEBUG( "ApplicationManagementSession: GetUserIdL" );
       
  2820     TUint32 id = 0;
       
  2821     TPckg<TUint32> pid(id);
       
  2822     TInt read(aMessage.Read( 0, pid) );
       
  2823 
       
  2824     RDEBUG_2( "ApplicationManagementSession: GetUserIdL id is %d", id );
       
  2825     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2826 
       
  2827     aMessage.Write( 1, compo.UserId() );
       
  2828     }
       
  2829 
       
  2830 // -------------------------------------------------------------------------------------------------------------------
       
  2831 // CApplicationManagementSession::GetTemporaryInstFileL()
       
  2832 // -------------------------------------------------------------------------------------------------------------------
       
  2833 
       
  2834 void CApplicationManagementSession::GetTemporaryInstFileL(
       
  2835         const RMessage2& aMessage) const
       
  2836     {
       
  2837     // TIpcArgs( &id, &itemid, &filehandle )
       
  2838     RDEBUG( "ApplicationManagementSession: GetTemporaryInstFileL" );
       
  2839     TUint32 id;
       
  2840     TPckg<TUint32> pid(id);
       
  2841     TInt read(aMessage.Read( 0, pid) );
       
  2842 
       
  2843     TDeplCompAttrType item;
       
  2844     TPckg<TDeplCompAttrType> itemid(item);
       
  2845     read = aMessage.Read( 1, itemid);
       
  2846 
       
  2847     RDEBUG_2( "ApplicationManagementSession: GetTemporaryInstFileL id is %d", id );
       
  2848     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2849 
       
  2850     TFileName fileName;
       
  2851 
       
  2852     if (item == EDCData)
       
  2853         {
       
  2854         fileName.Copy(compo.Data().DataFileName() );
       
  2855         }
       
  2856     else
       
  2857         if (item == EDCMetaData)
       
  2858             {
       
  2859             fileName.Copy(compo.MetaData().DataFileName() );
       
  2860             }
       
  2861         else
       
  2862             {
       
  2863             RDEBUG_2( "ApplicationManagementSession: GetTemporaryInstFileL: Not supported type: (%d)", item);
       
  2864             User::Leave(KErrNotSupported);
       
  2865             }
       
  2866 
       
  2867     RDEBUG_2( "ApplicationManagementSession: GetTemporaryInstFileL: (%S)", &fileName);
       
  2868 
       
  2869     RFs fs;
       
  2870     User::LeaveIfError(fs.Connect() );
       
  2871     User::LeaveIfError(fs.ShareProtected() );
       
  2872     CleanupClosePushL(fs);
       
  2873     RFile file;
       
  2874     User::LeaveIfError(file.Open(fs, fileName, EFileWrite) );
       
  2875     CleanupClosePushL(file);
       
  2876 
       
  2877     // Takes care of completing with session (RFs), 
       
  2878     // SendReceieve returns session handle at client side
       
  2879     User::LeaveIfError(file.TransferToClient(aMessage, 2) );
       
  2880     CleanupStack::PopAndDestroy(2, &fs); // fs , file	
       
  2881     }
       
  2882 
       
  2883 // -------------------------------------------------------------------------------------------------------------------
       
  2884 // CApplicationManagementSession::PackageSizeL()
       
  2885 // -------------------------------------------------------------------------------------------------------------------
       
  2886 
       
  2887 TInt CApplicationManagementSession::PackageSizeL(
       
  2888         Swi::RSisRegistrySession& aSession, Swi::RSisRegistryEntry& aEntry)
       
  2889     {
       
  2890     RPointerArray<Swi::CSisRegistryPackage> listPackages;
       
  2891     TInt size(0);
       
  2892     TInt err(0);
       
  2893     CleanupClosePushL(listPackages);
       
  2894 
       
  2895     aEntry.AugmentationsL(listPackages);
       
  2896 
       
  2897     for (TInt index(0); index < listPackages.Count(); index++)
       
  2898         {
       
  2899         TRAP(err, AugmentationSizeL( aSession, *listPackages[index]))
       
  2900         if (err != KErrNone)
       
  2901             {
       
  2902             break;
       
  2903             }
       
  2904         }
       
  2905 
       
  2906     if (err != KErrNone)
       
  2907         {
       
  2908         size = 0;
       
  2909         }
       
  2910     else
       
  2911         {
       
  2912         TRAP(err, size += aEntry.SizeL() );
       
  2913         }
       
  2914 
       
  2915     listPackages.ResetAndDestroy();
       
  2916     CleanupStack::PopAndDestroy( &listPackages);
       
  2917 
       
  2918     if (err != KErrNone)
       
  2919         {
       
  2920         //We leave if there was an error, 
       
  2921         // but we have to clean up the listPackages before the leave.
       
  2922         User::Leave(err);
       
  2923         }
       
  2924 
       
  2925     return size;
       
  2926     }
       
  2927 
       
  2928 // ------------------------------------------------------------------------------------------------
       
  2929 // CAppMngrSisxInfo::AugmentationSizeL()
       
  2930 // Returns the Size of the package
       
  2931 // (other items were commented in a header).
       
  2932 // ------------------------------------------------------------------------------------------------
       
  2933 //  
       
  2934 TInt CApplicationManagementSession::AugmentationSizeL(
       
  2935         Swi::RSisRegistrySession& aSession,
       
  2936         const Swi::CSisRegistryPackage& aPackage)
       
  2937     {
       
  2938     TInt size(0);
       
  2939     Swi::RSisRegistryEntry regEntry;
       
  2940     CleanupClosePushL(regEntry);
       
  2941 
       
  2942     regEntry.OpenL(aSession, aPackage);
       
  2943     size += PackageSizeL(aSession, regEntry);
       
  2944 
       
  2945     CleanupStack::PopAndDestroy( &regEntry);
       
  2946 
       
  2947     return size;
       
  2948     }
       
  2949 
       
  2950 // -------------------------------------------------------------------------------------------------------------------
       
  2951 // CApplicationManagementSession::LookupSisRegistryL()
       
  2952 // -------------------------------------------------------------------------------------------------------------------
       
  2953 
       
  2954 void CApplicationManagementSession::LookupSisRegistryL()
       
  2955     {
       
  2956     Swi::RSisRegistrySession sisses;
       
  2957     TInt r(sisses.Connect() );
       
  2958     RPointerArray<Swi::CSisRegistryPackage> pkgs(12);
       
  2959     sisses.InstalledPackagesL(pkgs);
       
  2960 
       
  2961     TInt count(pkgs.Count() );
       
  2962     for (TInt i( 0); i < count; i++)
       
  2963         {
       
  2964         Swi::CSisRegistryPackage* p = pkgs[i];
       
  2965 
       
  2966         RDEBUG_5(" Found package: %d, '%S', uid: 0x%X, size: %d" ,
       
  2967                 i, &p->Name(), p->Uid().iUid, AugmentationSizeL( sisses, *p ) );
       
  2968         }
       
  2969 
       
  2970     sisses.Close();
       
  2971     pkgs.ResetAndDestroy();
       
  2972 
       
  2973     }
       
  2974 
       
  2975 // -------------------------------------------------------------------------------------------------------------------
       
  2976 // CApplicationManagementSession::InstallL()
       
  2977 // -------------------------------------------------------------------------------------------------------------------
       
  2978 
       
  2979 void CApplicationManagementSession::InstallL(const RMessage2& aMessage) const
       
  2980     {
       
  2981     RDEBUG( "ApplicationManagementSession: InstallL" );
       
  2982     TUint32 id;
       
  2983     TPckg<TUint32> pid(id);
       
  2984     TInt read(aMessage.Read( 0, pid) );
       
  2985 
       
  2986     TDeploymentComponentState targetst;
       
  2987     TPckg<TDeploymentComponentState> pk(targetst);
       
  2988 
       
  2989     read = aMessage.Read( 1, pk) ;
       
  2990 
       
  2991     RDEBUG_3( "ApplicationManagementSession: InstallL id is %d, targetstate %d",
       
  2992             id, targetst );
       
  2993 
       
  2994     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  2995     if (compo.State() == EDCSDelivered)
       
  2996         {
       
  2997         Server().DoTheInstallL(compo) ;
       
  2998         }
       
  2999     else
       
  3000         {
       
  3001         User::Leave(KErrArgument);
       
  3002         }
       
  3003     RDEBUG_2( "ApplicationManagementSession: InstallL success. New compo state (%d)", compo.State());
       
  3004     }
       
  3005 
       
  3006 // -------------------------------------------------------------------------------------------------------------------
       
  3007 // CApplicationManagementSession::UpdateDataL()
       
  3008 // -------------------------------------------------------------------------------------------------------------------
       
  3009 
       
  3010 void CApplicationManagementSession::UpdateDataL(const RMessage2& aMessage) const
       
  3011     {
       
  3012     RDEBUG( "ApplicationManagementSession: UpdateDataL" );
       
  3013 
       
  3014     TDeplCompDataIPC ipc;
       
  3015     TPckg<TDeplCompDataIPC> pipc(ipc);
       
  3016     TInt read(aMessage.Read( 0, pipc) );
       
  3017     RDEBUG_2( "ApplicationManagementSession: UpdateDataL id is %d", ipc.iInternalId );
       
  3018 
       
  3019     HBufC8 *buf = HBufC8::NewLC(aMessage.GetDesLength( 1) );
       
  3020     TPtr8 pbuf(buf->Des() );
       
  3021     TInt read2(aMessage.Read( 1, pbuf) );
       
  3022 
       
  3023     CDeploymentComponent &compo = Server().Storage()->ComponentL(ipc.iInternalId);
       
  3024 
       
  3025     if (Server().CheckB64Encode(pbuf) )
       
  3026         {
       
  3027         RDEBUG( "ApplicationManagementSession: UpdateDataL data is base64 encoded");
       
  3028         // b64 encoded data, decode it 
       
  3029         HBufC8* tmp;
       
  3030         tmp = Server().DecodeB64DataLC(pbuf);
       
  3031         pbuf.Copy( *tmp);
       
  3032         pbuf = buf->Des();
       
  3033         CleanupStack::PopAndDestroy(tmp);
       
  3034         }
       
  3035 
       
  3036     if (compo.State() == EDCSDelivered)
       
  3037         {
       
  3038         if (ipc.iAttrType == EDCData)
       
  3039             {
       
  3040             compo.SetDataL(pbuf, ipc.iDataMime);
       
  3041             }
       
  3042         else
       
  3043             if (ipc.iAttrType == EDCMetaData)
       
  3044                 {
       
  3045                 compo.SetMetaDataL(pbuf, ipc.iDataMime);
       
  3046                 }
       
  3047             else
       
  3048                 {
       
  3049                 RDEBUG_2( "ApplicationManagementSession::UpdateDataL -  ERROR UpdateDataL called for illegal item: %d!", ipc.iAttrType );
       
  3050                 User::Leave(KErrArgument);
       
  3051                 }
       
  3052 
       
  3053         Server().Storage()->UpdateL(compo);
       
  3054         }
       
  3055     else
       
  3056         {
       
  3057         RDEBUG( "ApplicationManagementSession::UpdateDataL -  ERROR UpdateDataL called for illegal state message!" );
       
  3058         User::Leave(KErrArgument);
       
  3059         }
       
  3060     CleanupStack::PopAndDestroy(buf);
       
  3061     }
       
  3062 
       
  3063 // -------------------------------------------------------------------------------------------------------------------
       
  3064 // CApplicationManagementSession::UpdateStreamedDataL()
       
  3065 // -------------------------------------------------------------------------------------------------------------------
       
  3066 
       
  3067 void CApplicationManagementSession::UpdateStreamedDataL(
       
  3068         const RMessage2& aMessage) const
       
  3069     {
       
  3070     RDEBUG( "ApplicationManagementSession: UpdateStreamedDataL() Start");
       
  3071     TDeplCompDataIPC ipc;
       
  3072     TPckg<TDeplCompDataIPC> pipc(ipc);
       
  3073     TInt read(aMessage.Read( 0, pipc) );
       
  3074     RDEBUG_2( "ApplicationManagementSession: UpdateStreamedDataL id is %d", ipc.iInternalId );
       
  3075 
       
  3076     CDeploymentComponent &compo = Server().Storage()->ComponentL(ipc.iInternalId);
       
  3077 
       
  3078     if (compo.State() == EDCSDelivered)
       
  3079         {
       
  3080         RFs fs;
       
  3081         User::LeaveIfError(fs.Connect() );
       
  3082         CleanupClosePushL(fs);
       
  3083         RFile file;
       
  3084         TFileName dataFileName;
       
  3085         TInt length(0);
       
  3086 
       
  3087         if (ipc.iAttrType == EDCData)
       
  3088             {
       
  3089             dataFileName.Copy(compo.Data().DataFileName() ) ;
       
  3090             }
       
  3091         else
       
  3092             if (ipc.iAttrType == EDCMetaData)
       
  3093                 {
       
  3094                 dataFileName.Copy(compo.MetaData().DataFileName() ) ;
       
  3095                 }
       
  3096             else
       
  3097                 {
       
  3098                 RDEBUG_2( "ApplicationManagementSession::UpdateStreamedDataL -  ERROR called for illegal item: %d!", ipc.iAttrType );
       
  3099                 User::Leave(KErrArgument);
       
  3100                 }
       
  3101 
       
  3102         RDEBUG_2( "ApplicationManagementSession::UpdateStreamedDataL(): using dataFile: (%S)", &dataFileName );
       
  3103 
       
  3104         // EFileWrite So we can delete the original decoded data file
       
  3105         User::LeaveIfError(file.Open(fs, dataFileName, EFileWrite) );
       
  3106         CleanupClosePushL(file) ;
       
  3107         if (Server().IsDataFileB64EncodedL(file, length) )
       
  3108             {
       
  3109             RDEBUG( "CApplicationManagementServer::UpdateStreamedDataL(): data is decoded" );
       
  3110 
       
  3111             TFileName tempFileName;
       
  3112             TBuf<30> privatePath;
       
  3113             fs.PrivatePath(privatePath);
       
  3114             RFile tempFile;
       
  3115             TInt err(KErrNone);
       
  3116             err = tempFile.Temp(fs, privatePath, tempFileName, EFileWrite);
       
  3117             if (err == KErrNone)
       
  3118                 {
       
  3119                 RDEBUG_2( "ApplicationManagementSession::UpdateStreamedDataL(): created tempFile: (%S)", &tempFileName );
       
  3120                 }
       
  3121             else
       
  3122                 {
       
  3123                 User::Leave(err);
       
  3124                 }
       
  3125             CleanupClosePushL(tempFile);
       
  3126 
       
  3127             TRAP( err, Server().DecodeB64DataFileL( file, tempFile ) );
       
  3128             if (err != KErrNone)
       
  3129                 {
       
  3130                 RDEBUG_2( "ApplicationManagementSession::UpdateStreamedDataL -  failed to decode datafile: %d", err );
       
  3131                 CleanupStack::PopAndDestroy( 2, &file);
       
  3132                 compo.ResetDataL(fs); // Remove both files if exists
       
  3133                 User::Leave(err);
       
  3134                 }
       
  3135             else
       
  3136                 {
       
  3137                 // close both files, delete decode file and rename temp file to correct one
       
  3138                 CleanupStack::PopAndDestroy( 2, &file);
       
  3139                 fs.Delete(dataFileName);
       
  3140                 err = fs.Rename(tempFileName, dataFileName);
       
  3141                 RDEBUG_2( "ApplicationManagementSession::UpdateStreamedDataL -  successfully decoded datafile: %d", err );
       
  3142                 }
       
  3143             CleanupStack::PopAndDestroy( &fs);
       
  3144             }
       
  3145         else
       
  3146             {
       
  3147             RDEBUG( "ApplicationManagementSession::UpdateStreamedDataL(): data is NOT decoded" );
       
  3148             CleanupStack::PopAndDestroy( 2, &fs);
       
  3149             }
       
  3150 
       
  3151         if (ipc.iAttrType == EDCData)
       
  3152             {
       
  3153             compo.SetDataL(ipc.iDataMime);
       
  3154             }
       
  3155         else
       
  3156             {
       
  3157             compo.SetMetaDataL(ipc.iDataMime);
       
  3158             }
       
  3159 
       
  3160         Server().Storage()->UpdateL(compo);
       
  3161         }
       
  3162     else
       
  3163         {
       
  3164         RDEBUG( "ApplicationManagementSession::UpdateStreamedDataL -  ERROR called for illegal state message!" );
       
  3165         User::Leave(KErrArgument);
       
  3166         }
       
  3167     RDEBUG( "ApplicationManagementSession: UpdateStreamedDataL() End");
       
  3168     }
       
  3169 
       
  3170 // -------------------------------------------------------------------------------------------------------------------
       
  3171 // CApplicationManagementSession::UpdateL()
       
  3172 // -------------------------------------------------------------------------------------------------------------------
       
  3173 
       
  3174 void CApplicationManagementSession::UpdateL(const RMessage2& aMessage) const
       
  3175     {
       
  3176     RDEBUG( "ApplicationManagementSession: UpdateL" );
       
  3177 
       
  3178     TUint32 id;
       
  3179     TPckg<TUint32> pid(id);
       
  3180     TInt read(aMessage.Read( 0, pid) );
       
  3181     RDEBUG_2("ApplicationManagementSession: UpdateL id is %d", id );
       
  3182 
       
  3183     TDeplCompAttrType item;
       
  3184     TPckg<TDeplCompAttrType> itemid(item);
       
  3185     TInt read1(aMessage.Read( 1, itemid) );
       
  3186     HBufC8 *buf = HBufC8::NewLC(aMessage.GetDesLength( 2) );
       
  3187     TPtr8 pbuf(buf->Des() );
       
  3188     TInt read2(aMessage.Read( 2, pbuf) );
       
  3189 
       
  3190     CDeploymentComponent &c = Server().Storage()->ComponentL(id);
       
  3191     TDeploymentComponentState st(c.State() );
       
  3192     if (st == EDCSDelivered || st == EDCSDownload)
       
  3193         {
       
  3194         switch (item)
       
  3195             {
       
  3196             case EDCId:
       
  3197                 {
       
  3198                 c.SetIdL(pbuf);
       
  3199                 break;
       
  3200                 }
       
  3201             case EDCName:
       
  3202                 {
       
  3203                 c.SetNameL(pbuf);
       
  3204                 break;
       
  3205                 }
       
  3206             case EDCVersion:
       
  3207                 {
       
  3208                 c.SetVersionL(pbuf);
       
  3209                 break;
       
  3210                 }
       
  3211             case EDCDescriptionRef:
       
  3212                 {
       
  3213                 c.SetDescriptionL(pbuf);
       
  3214                 break;
       
  3215                 }
       
  3216             case EDCInstallOptions:
       
  3217                 {
       
  3218                 c.SetInstallOptsL(pbuf);
       
  3219                 break;
       
  3220                 }
       
  3221             case EDCMetaData:
       
  3222                 {
       
  3223                 c.SetMetaDataL(pbuf, KNullDesC8);
       
  3224                 break;
       
  3225                 }
       
  3226             case EDCPkgID:
       
  3227                 {
       
  3228                 c.SetPkgIDL(pbuf);
       
  3229                 break;
       
  3230                 }
       
  3231             case EDCPkgType:
       
  3232                 {
       
  3233                 c.SetPkgTypeL(pbuf);
       
  3234                 break;
       
  3235                 }
       
  3236 
       
  3237             default:
       
  3238                 {
       
  3239                 if (st == EDCSDelivered)
       
  3240                     {
       
  3241                     switch (item)
       
  3242                         {
       
  3243                         case EDCData:
       
  3244                             {
       
  3245                             c.SetDataL(pbuf, KNullDesC8);
       
  3246                             if (c.State() == EDCSDownload)
       
  3247                                 {
       
  3248                                 //	Server().StartDownload( *compo );
       
  3249                                 }
       
  3250                             break;
       
  3251                             }
       
  3252                         default:
       
  3253                             {
       
  3254                             RDEBUG_2("ApplicationManagementSession: ERROR UpdateL called for illegal item type!!!! %d", item );
       
  3255                             User::Leave(KErrArgument);
       
  3256                             }
       
  3257                         }
       
  3258                     }
       
  3259                 else
       
  3260                     if (st == EDCSDownload)
       
  3261                         {
       
  3262                         switch (item)
       
  3263                             {
       
  3264                             case EDCId:
       
  3265                                 {
       
  3266                                 c.SetIdL(pbuf);
       
  3267                                 break;
       
  3268                                 }
       
  3269                             case EDCName:
       
  3270                                 {
       
  3271                                 c.SetNameL(pbuf);
       
  3272                                 break;
       
  3273                                 }
       
  3274                             case EDCVersion:
       
  3275                                 {
       
  3276                                 c.SetVersionL(pbuf);
       
  3277                                 break;
       
  3278                                 }
       
  3279                             case EDCDownloadURI:
       
  3280                                 {
       
  3281                                 c.SetDownloadURIL(pbuf);
       
  3282                                 break;
       
  3283                                 }
       
  3284                             case EDCConRef:
       
  3285                                 {
       
  3286                                 TPckgBuf<TInt> aInt;
       
  3287                                 aInt.Copy(pbuf);
       
  3288                                 c.SetIAPL(aInt() );
       
  3289                                 break;
       
  3290                                 }
       
  3291                             default:
       
  3292                                 {
       
  3293                                 RDEBUG_2( "ApplicationManagementSession: ERROR UpdateL called for illegal item type!!!! %d", item );
       
  3294                                 User::Leave(KErrArgument);
       
  3295                                 break;
       
  3296                                 }
       
  3297                             }
       
  3298                         }
       
  3299                 break;
       
  3300                 }
       
  3301             }
       
  3302         Server().Storage()->UpdateL(c);
       
  3303         }
       
  3304     else
       
  3305         if (st == EDCSActive ||st == EDCSInactive)
       
  3306             {
       
  3307             switch (item)
       
  3308                 {
       
  3309                 case EDCName:
       
  3310                     {
       
  3311                     c.SetNameL(pbuf);
       
  3312                     break;
       
  3313                     }
       
  3314                 case EDCVersion:
       
  3315                     {
       
  3316                     c.SetVersionL(pbuf);
       
  3317                     break;
       
  3318                     }
       
  3319                 case EDCDescriptionRef:
       
  3320                 {
       
  3321                 c.SetDescriptionL(pbuf);
       
  3322                 break;
       
  3323                 }
       
  3324                 default:
       
  3325                     {
       
  3326                     RDEBUG_2( "ApplicationManagementSession: ERROR UpdateL called for illegal item type!!!! %d", item );
       
  3327                     User::Leave(KErrArgument);
       
  3328                     break;
       
  3329                     }
       
  3330                 }
       
  3331             Server().Storage()->UpdateL(c);
       
  3332             }
       
  3333         else
       
  3334             {
       
  3335             RDEBUG( "ApplicationManagementSession: ERROR UpdateL called for illegal state message!" );
       
  3336             User::Leave(KErrArgument);
       
  3337             }
       
  3338     CleanupStack::PopAndDestroy(buf);
       
  3339     }
       
  3340 
       
  3341 // -------------------------------------------------------------------------------------------------------------------
       
  3342 // CApplicationManagementSession::GetDataLengthL()
       
  3343 // -------------------------------------------------------------------------------------------------------------------
       
  3344 
       
  3345 void CApplicationManagementSession::GetDataLengthL(const RMessage2& aMessage) const
       
  3346     {
       
  3347     RDEBUG( "ApplicationManagementSession: GetDataLengthL" );
       
  3348     TUint32 id;
       
  3349     TPckg<TUint32> pid(id);
       
  3350 
       
  3351     TInt read(aMessage.Read( 0, pid) );
       
  3352 
       
  3353     TInt length( 0);
       
  3354 
       
  3355     TDeplCompAttrType dt;
       
  3356     TPckg< TDeplCompAttrType> pdt(dt);
       
  3357     read = aMessage.Read( 1, pdt) ;
       
  3358     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  3359     if (compo.State() == EDCSDelivered)
       
  3360         {
       
  3361         if (dt == EDCInstallOptions)
       
  3362             {
       
  3363             if (compo.InstallOptsSet() )
       
  3364                 {
       
  3365                 length = sizeof(TAMInstallOptions);
       
  3366                 }
       
  3367             }
       
  3368         else
       
  3369             if (dt == EDCData)
       
  3370                 {
       
  3371                 length = compo.Data().DataLengthL();
       
  3372                 }
       
  3373             else
       
  3374                 if (dt == EDCDataMime)
       
  3375                     {
       
  3376                     length = compo.Data().MimeType().Length();
       
  3377                     }
       
  3378                 else
       
  3379                     if (dt == EDCMetaData)
       
  3380                         {
       
  3381                         length = compo.MetaData().DataLengthL();
       
  3382                         }
       
  3383                     else
       
  3384                         if (dt == EDCMetaDataMime)
       
  3385                             {
       
  3386                             length = compo.MetaData().MimeType().Length();
       
  3387                             }
       
  3388                         else
       
  3389                             {
       
  3390                             RDEBUG_2( "ApplicationManagementSession: GetDataLengthL ERROR called with illegal type %d", dt );
       
  3391                             User::Leave(KErrArgument);
       
  3392                             }
       
  3393         }
       
  3394     else
       
  3395         if (compo.State() == EDCSDownload)
       
  3396             {
       
  3397             if (dt == EDCDownloadURI)
       
  3398                 {
       
  3399                 length = compo.DownloadURI().Length();
       
  3400                 }
       
  3401             else
       
  3402                 if (dt == EDCInstallOptions)
       
  3403                     {
       
  3404                     if (compo.InstallOptsSet() )
       
  3405                         {
       
  3406                         length = sizeof(TAMInstallOptions);
       
  3407                         }
       
  3408                     }
       
  3409                 else
       
  3410                     {
       
  3411                     RDEBUG_2( "ApplicationManagementSession: GetDataLengthL ERROR Download / called with illegal state component id %d",
       
  3412                             compo.State() );
       
  3413                     User::Leave(KErrArgument);
       
  3414                     }
       
  3415             }
       
  3416         else
       
  3417             {
       
  3418             RDEBUG_2( "ApplicationManagementSession: GetDataLengthL ERROR called with illegal state component id %d",
       
  3419                     compo.State() );
       
  3420             User::Leave(KErrArgument);
       
  3421             }
       
  3422 
       
  3423     TPckg< TInt> pcomp(length);
       
  3424     aMessage.Write( 2, pcomp);
       
  3425     }
       
  3426 
       
  3427 // -------------------------------------------------------------------------------------------------------------------
       
  3428 // CApplicationManagementSession::GetDataL()
       
  3429 // -------------------------------------------------------------------------------------------------------------------
       
  3430 
       
  3431 void CApplicationManagementSession::GetDataL(const RMessage2& aMessage) const
       
  3432     {
       
  3433     RDEBUG( "ApplicationManagementSession: GetDataL" );
       
  3434     TUint32 id;
       
  3435     TPckg<TUint32> pid(id);
       
  3436 
       
  3437     TInt read(aMessage.Read( 0, pid) );
       
  3438 
       
  3439     TDeplCompAttrType dt;
       
  3440     TPckg< TDeplCompAttrType> pdt(dt);
       
  3441     read = aMessage.Read( 1, pdt) ;
       
  3442 
       
  3443     RDEBUG_3( "ApplicationManagementSession: GetDataL id is %d, and attribute %d", id, dt );
       
  3444     CDeploymentComponent &compo = Server().Storage()->ComponentL(id);
       
  3445     if (dt == EDCStatus)
       
  3446         {
       
  3447         TPckg<TInt> p(compo.Status() );
       
  3448         aMessage.Write( 2, p);
       
  3449         }
       
  3450     else
       
  3451         if (compo.State() == EDCSDelivered)
       
  3452             {
       
  3453             if (dt == EDCInstallOptions)
       
  3454                 {
       
  3455                 if (compo.InstallOptsSet() )
       
  3456                     {
       
  3457                     TAMInstallOptionsPckgBuf pckg(compo.InstallOpts() );
       
  3458                     aMessage.Write( 2, pckg);
       
  3459                     }
       
  3460                 else
       
  3461                     {
       
  3462                     aMessage.Write( 2, KNullDesC8);
       
  3463                     }
       
  3464                 }
       
  3465             else
       
  3466                 if (dt == EDCData)
       
  3467                     {
       
  3468                     aMessage.Write( 2, compo.Data().Data() );
       
  3469                     }
       
  3470                 else
       
  3471                     if (dt == EDCDataMime)
       
  3472                         {
       
  3473                         aMessage.Write( 2, compo.Data().MimeType() );
       
  3474                         }
       
  3475                     else
       
  3476                         if (dt == EDCMetaData)
       
  3477                             {
       
  3478                             aMessage.Write( 2, compo.MetaData().Data() );
       
  3479                             }
       
  3480                         else
       
  3481                             if (dt == EDCMetaDataMime)
       
  3482                                 {
       
  3483                                 aMessage.Write( 2, compo.MetaData().MimeType() );
       
  3484                                 }
       
  3485                             else
       
  3486                                 {
       
  3487                                 RDEBUG_2( "ApplicationManagementSession: GetDataL ERROR called with illegal type %d", dt );
       
  3488                                 User::Leave(KErrArgument);
       
  3489                                 }
       
  3490             }
       
  3491         else
       
  3492             if (compo.State() == EDCSDownload)
       
  3493                 {
       
  3494 
       
  3495                 if (dt == EDCDownloadURI)
       
  3496                     {
       
  3497                     aMessage.Write( 2, compo.DownloadURI() );
       
  3498                     }
       
  3499 
       
  3500                 else
       
  3501                     if (dt == EDCInstallOptions)
       
  3502                         {
       
  3503                         if (compo.InstallOptsSet() )
       
  3504                             {
       
  3505                             TAMInstallOptionsPckgBuf
       
  3506                                     pckg(compo.InstallOpts() );
       
  3507                             aMessage.Write( 2, pckg);
       
  3508                             }
       
  3509                         else
       
  3510                             {
       
  3511                             aMessage.Write( 2, KNullDesC8);
       
  3512                             }
       
  3513                         }
       
  3514                     else
       
  3515                         if (dt == EDCConRef)
       
  3516                             {
       
  3517                             TPckg<TInt> p(compo.GetIAP() );
       
  3518                             aMessage.Write( 2, p);
       
  3519                             }
       
  3520                         else
       
  3521                             {
       
  3522                             RDEBUG_2( "ApplicationManagementSession:GetDataL ERROR called with illegal type %d", dt );
       
  3523                             User::Leave(KErrArgument);
       
  3524                             }
       
  3525                 }
       
  3526             else
       
  3527                 {
       
  3528                 RDEBUG_2("ApplicationManagementSession: GetDataL ERROR called with illegal state component id %d", compo.State() );
       
  3529                 User::Leave(KErrArgument);
       
  3530                 }
       
  3531     }
       
  3532 
       
  3533 // -------------------------------------------------------------------------------------------------------------------
       
  3534 // CApplicationManagementSession::RemoveL()
       
  3535 // -------------------------------------------------------------------------------------------------------------------
       
  3536 
       
  3537 void CApplicationManagementSession::RemoveL(const RMessage2& aMessage) const
       
  3538     {
       
  3539     RDEBUG( "ApplicationManagementSession: RemoveL" );
       
  3540     TUint32 id;
       
  3541     TPckg<TUint32> pid(id);
       
  3542     TInt read(aMessage.Read( 0, pid) );
       
  3543     RDEBUG_2( "ApplicationManagementSession: RemoveL id is %d", id );
       
  3544     RemoveInternalL(id);
       
  3545     }
       
  3546 
       
  3547 // -------------------------------------------------------------------------------------------------------------------
       
  3548 // CApplicationManagementSession::RemoveInternalL()
       
  3549 // -------------------------------------------------------------------------------------------------------------------
       
  3550 
       
  3551 void CApplicationManagementSession::RemoveInternalL(const TUint32 &aId) const
       
  3552     {
       
  3553     CDeploymentComponent &compo = Server().Storage()->ComponentL(aId);
       
  3554 
       
  3555     Server().RemoveInternalL(compo);
       
  3556     }
       
  3557 
       
  3558 // -------------------------------------------------------------------------------------------------------------------
       
  3559 // CApplicationManagementSession::DownloadL()
       
  3560 // -------------------------------------------------------------------------------------------------------------------
       
  3561 
       
  3562 void CApplicationManagementSession::DownloadL(const RMessage2& aMessage) const
       
  3563     {
       
  3564     RDEBUG( "ApplicationManagementSession: DownloadL" );
       
  3565 
       
  3566     TDCUserId userId;
       
  3567     aMessage.ReadL( 1, userId);
       
  3568     CDeploymentComponent *compo= NULL;
       
  3569 
       
  3570     if (iTrustAdded)
       
  3571         {
       
  3572         compo = Server().Storage()->NewComponentL(EDCSDownload, userId, &iCertInfo);
       
  3573         }
       
  3574     else
       
  3575         {
       
  3576         compo = Server().Storage()->NewComponentL(EDCSDownload, userId);
       
  3577         }
       
  3578     TUint32 i(compo->InternalId() );
       
  3579     TPckg<TUint32> p(i);
       
  3580     aMessage.WriteL(0, p);
       
  3581     }
       
  3582 
       
  3583 // -------------------------------------------------------------------------------------------------------------------
       
  3584 // CApplicationManagementSession::FullUpdateL()
       
  3585 // -------------------------------------------------------------------------------------------------------------------
       
  3586 
       
  3587 void CApplicationManagementSession::FullUpdateL(const RMessage2& aMessage) const
       
  3588     {
       
  3589     RDEBUG( "ApplicationManagementSession: FullUpdateL" );
       
  3590 
       
  3591     TUint32 sid;
       
  3592 
       
  3593     TPckg<TUint32> psid(sid);
       
  3594     TInt read(aMessage.Read( 0, psid) );
       
  3595     TUint32 tid;
       
  3596     TPckg<TUint32> ptid(tid);
       
  3597     TInt read2(aMessage.Read( 1, ptid) );
       
  3598 
       
  3599     RDEBUG_3( "ApplicationManagementSession: FullUpdateL sid is %d, tid is %d", sid, tid );
       
  3600     CApplicationManagementServer &server = Server();
       
  3601     server.FullUpdateL(sid, tid);
       
  3602     }
       
  3603 
       
  3604 // -------------------------------------------------------------------------------------------------------------------
       
  3605 // CApplicationManagementSession::ServiceError()
       
  3606 // -------------------------------------------------------------------------------------------------------------------
       
  3607 
       
  3608 void CApplicationManagementSession::ServiceError(const RMessage2& aMessage,
       
  3609         TInt aError)
       
  3610     {
       
  3611     RDEBUG_2( "ApplicationManagementSession: CApplicationManagementSession::ServiceError %d", aError);
       
  3612     CSession2::ServiceError(aMessage, aError);
       
  3613     }
       
  3614 
       
  3615 // -------------------------------------------------------------------------------------------------------------------
       
  3616 // CApplicationManagementSession::AddTrustL()
       
  3617 // -------------------------------------------------------------------------------------------------------------------
       
  3618 
       
  3619 void CApplicationManagementSession::AddTrustL(const RMessage2 &aMessage)
       
  3620     {
       
  3621     TPckg<TCertInfo> pkg(iCertInfo);
       
  3622     aMessage.ReadL( 0, pkg);
       
  3623     iTrustAdded = ETrue;
       
  3624     }
       
  3625 
       
  3626 // -------------------------------------------------------------------------------------------------------------------
       
  3627 // CApplicationManagementSession::StateChangeComponentIdsL()
       
  3628 // -------------------------------------------------------------------------------------------------------------------
       
  3629 
       
  3630 void CApplicationManagementSession::StateChangeComponentIdsL(
       
  3631         const RMessage2& aMessage) const
       
  3632     {
       
  3633     RDEBUG( "CApplicationManagementSession: StateChangeComponentIdsL" );
       
  3634     RComponentIdArray arr;
       
  3635     Server().Storage()->GetStateChangeComponentIdsL(arr);
       
  3636     TInt buflen(arr.Count() );
       
  3637     TUint32* buf = new ( ELeave ) TUint32[buflen];
       
  3638     CleanupArrayDeletePushL(buf);
       
  3639     for (TInt i( 0); i < buflen; i++)
       
  3640         {
       
  3641         RDEBUG_2( "ApplicationManagementSession:ComponentIdsL Adding %d!!", arr[i]);
       
  3642         buf[i] = arr[i];
       
  3643         }
       
  3644     TPtrC8 p( ( TUint8* ) buf, buflen * sizeof(TUint32));
       
  3645     aMessage.WriteL( 0, p);
       
  3646     arr.Close();
       
  3647     CleanupStack::PopAndDestroy(buf);
       
  3648     RDEBUG( "CApplicationManagementSession: StateChangeComponentIdsL end" );
       
  3649 
       
  3650     }
       
  3651 
       
  3652 // -------------------------------------------------------------------------------------------------------------------
       
  3653 // CApplicationManagementSession::StateChangeComponentIdsCountL()
       
  3654 // -------------------------------------------------------------------------------------------------------------------
       
  3655 
       
  3656 void CApplicationManagementSession::StateChangeComponentIdsCountL(
       
  3657         const RMessage2& aMessage) const
       
  3658     {
       
  3659     RDEBUG( "CApplicationManagementSession: StateChangeComponentIdsCountL" );
       
  3660                 RPointerArray<TPreInstalledAppParams> preInstalledAppParams;
       
  3661                 CAMPreInstallApp* preInstallApp = CAMPreInstallApp::NewL();
       
  3662                 preInstallApp->GetPreInstalledAppsL(preInstalledAppParams);
       
  3663                 TInt count = 0;
       
  3664                 for (count = 0; count< preInstalledAppParams.Count(); count++)
       
  3665                     {
       
  3666                     RDEBUG8_2("CApplicationManagementSession::DownloadL: Installed App Name is: %S",&(preInstalledAppParams[count]->iPreInstalledAppame));
       
  3667                     RDEBUG8_2("CApplicationManagementSession::DownloadL: Installed App Vendor is: %S",&(preInstalledAppParams[count]->iPreInstalledAppVendorName));
       
  3668                     RDEBUG_2("CApplicationManagementSession::DownloadL: Installed App UID is : '0x%X'",preInstalledAppParams[count]->iPreInstalledAppUid);
       
  3669 
       
  3670                     TBool found = EFalse;
       
  3671                     const RComponentIdArray &arrt = Server().Storage()->GetComponentIds();
       
  3672                     TInt countval(arrt.Count() );
       
  3673                     for (TInt i( 0); i < countval; i++)
       
  3674                         {
       
  3675                         CDeploymentComponent &compo = Server().Storage()->ComponentL(arrt[i]);
       
  3676                         if (compo.Uid()== preInstalledAppParams[count]->iPreInstalledAppUid)
       
  3677                             {
       
  3678                             RDEBUG( "CApplicationManagementSession: ActiveComponentsL found= TRUE" );
       
  3679                             found = ETrue;
       
  3680                             }
       
  3681                         }
       
  3682                     if (!found)
       
  3683                         {
       
  3684                         RDEBUG( "CApplicationManagementSession: Adding Pre-installed app" );
       
  3685                         TDCUserId preInstalledAppName;
       
  3686                         preInstalledAppName.Copy(preInstalledAppParams[count]->iPreInstalledAppame);
       
  3687                         CDeploymentComponent *preInstallCompo= NULL;
       
  3688                         RDEBUG8_2("CApplicationManagementSession: Installed App Name is: %S",&preInstalledAppName);
       
  3689                         preInstallCompo = Server().Storage()->NewComponentL(EDCSActive, preInstalledAppName);
       
  3690                         preInstallCompo->SetUid(preInstalledAppParams[count]->iPreInstalledAppUid);
       
  3691                         preInstallCompo->SetNameL(preInstalledAppName);
       
  3692                         preInstallCompo->SetVersionL(preInstalledAppParams[count]->iVersion);
       
  3693                         preInstallCompo->SetMimeTypeL(preInstalledAppParams[count]->iMimeType);
       
  3694 				preInstallCompo->SetAppRemovableStatus(ETrue);
       
  3695 
       
  3696                         Server().Storage()->UpdateL( *preInstallCompo );
       
  3697                         Server().Storage()->CheckForDuplicateNodesInDeployedL(*preInstallCompo);
       
  3698                         }
       
  3699                     }
       
  3700                 delete preInstallApp;
       
  3701     RComponentIdArray arr;
       
  3702     Server().Storage()->GetStateChangeComponentIdsL(arr);
       
  3703     TPckgBuf<TInt> buflen(arr.Count() );
       
  3704     aMessage.WriteL( 0, buflen);
       
  3705     arr.Close();
       
  3706     RDEBUG( "CApplicationManagementSession: StateChangeComponentIdsCountL end" );
       
  3707     }
       
  3708 
       
  3709 // -------------------------------------------------------------------------------------------------------------------
       
  3710 // CApplicationManagementSession::StateChangeCompleteL()
       
  3711 // -------------------------------------------------------------------------------------------------------------------
       
  3712 
       
  3713 void CApplicationManagementSession::StateChangeCompleteL(
       
  3714         const RMessage2& aMessage) const
       
  3715     {
       
  3716     RDEBUG( "CApplicationManagementSession: StateChangeCompleteL" );
       
  3717     TUint32 tid;
       
  3718     TPckg<TUint32> ptid(tid);
       
  3719     TInt read2(aMessage.Read( 0, ptid) );
       
  3720     Server().Storage()->StateChangedL(tid);
       
  3721     }
       
  3722 void CApplicationManagementSession::CheckStatusNodesValuesL()
       
  3723     {
       
  3724     const RComponentIdArray &arrt = Server().Storage()->GetComponentIds();
       
  3725     TInt cont(arrt.Count() );
       
  3726     TBool isUpdateRequired = ETrue;
       
  3727     for (TInt i( 0); i < cont; i++)
       
  3728         {
       
  3729         CDeploymentComponent &compo = Server().Storage()->ComponentL(arrt[i]);
       
  3730         isUpdateRequired = EFalse;
       
  3731         if (compo.Status() == EDownload_DownloadProgress)
       
  3732             {
       
  3733             compo.SetStatusNode(EDownload_DownloadFailed);
       
  3734             isUpdateRequired = ETrue;
       
  3735             }
       
  3736         else
       
  3737             if (compo.Status() == EDelivered_InstallProgress)
       
  3738                 {
       
  3739                 compo.SetStatusNode(EDelivered_InstalledFailedWithData);
       
  3740                 isUpdateRequired = ETrue;
       
  3741                 }
       
  3742             else
       
  3743                 if (compo.Status() == EDelivered_RemoveProgress)
       
  3744                     {
       
  3745                     compo.SetStatusNode(EDelivered_RemoveFailed);
       
  3746                     isUpdateRequired = ETrue;
       
  3747                     }
       
  3748                 else
       
  3749                     if (compo.Status() == EDeployed_RemoveProgress)
       
  3750                         {
       
  3751                         compo.SetStatusNode(EDeployed_RemoveFailed);
       
  3752                         isUpdateRequired = ETrue;
       
  3753                         }
       
  3754                     else
       
  3755                         if (compo.Status() == EDeployed_ActivateProgress)
       
  3756                             {
       
  3757                             compo.SetStatusNode(EDeployed_ActivateFailed);
       
  3758                             isUpdateRequired = ETrue;
       
  3759                             }
       
  3760                         else
       
  3761                             if (compo.Status()
       
  3762                                     == EDeployed_DeactivateProgress)
       
  3763                                 {
       
  3764                                 compo.SetStatusNode(EDeployed_DeactivateFailed);
       
  3765                                 isUpdateRequired = ETrue;
       
  3766                                 }
       
  3767         if (isUpdateRequired)
       
  3768             Server().Storage()->UpdateL(compo);
       
  3769         }
       
  3770 
       
  3771     }
       
  3772 
       
  3773 void CApplicationManagementServer::SetSisAppVersionAndDriveL(
       
  3774         CDeploymentComponent &aCompo)
       
  3775     {
       
  3776     RDEBUG( "CApplicationManagementSession: SetSisAppVersionAndDriveL: Begin" );
       
  3777 
       
  3778         Swi::RSisRegistrySession sisSession;
       
  3779         User::LeaveIfError(sisSession.Connect());
       
  3780         CleanupClosePushL(sisSession);
       
  3781         
       
  3782         Swi::RSisRegistryEntry sisEntry;
       
  3783         
       
  3784         //Opens the base package entry by specifying a UID. 
       
  3785         User::LeaveIfError(sisEntry.Open(sisSession, aCompo.Uid()));
       
  3786         CleanupClosePushL(sisEntry);
       
  3787 
       
  3788     TUint drivesMask = sisEntry.InstalledDrivesL();
       
  3789     
       
  3790     TInt drive= EDriveA;
       
  3791     TDriveNumber installedDrive = EDriveC;
       
  3792     
       
  3793     if( drivesMask )
       
  3794     {
       
  3795     // Select the highest drive as location drive. That's the case when 
       
  3796     // all installation is not in same drive
       
  3797     
       
  3798     while( drivesMask >>= 1 )
       
  3799     {
       
  3800     drive++;
       
  3801     }
       
  3802     
       
  3803     RDEBUG_2( "drive -> SetSisAppVersionAndDriveL %d", drive);
       
  3804     
       
  3805     installedDrive = (TDriveNumber)drive;
       
  3806     }
       
  3807     
       
  3808 
       
  3809     TBool status = EFalse;
       
  3810 
       
  3811     //Since "C" drive is not removable
       
  3812 
       
  3813     if (installedDrive!=EDriveC)
       
  3814         {
       
  3815         status = IsInstalledAppRemovableL(installedDrive);
       
  3816         }
       
  3817     if (status)
       
  3818         {
       
  3819         RDEBUG( "IsInstalledAppRemovableL(SetSisAppVersionAndDriveL); True");
       
  3820         }
       
  3821     else
       
  3822         {
       
  3823         RDEBUG( "IsInstalledAppRemovableL(SetSisAppVersionAndDriveL); False");
       
  3824         }
       
  3825    
       
  3826     //check for status drive
       
  3827     aCompo.SetAppRemovableStatus(status);
       
  3828     
       
  3829     TVersion version = sisEntry.VersionL();
       
  3830 
       
  3831     if (aCompo.ComponentVersion() == KNullDesC8)
       
  3832         {
       
  3833         TBuf8<KVersionLength> pkgDes;
       
  3834         pkgDes.AppendNum(version.iMajor);
       
  3835         pkgDes.Append(KLiteralPeriod);
       
  3836         pkgDes.AppendNum(version.iMinor);
       
  3837         aCompo.SetVersionL(pkgDes);
       
  3838 
       
  3839         }
       
  3840     CleanupStack::PopAndDestroy(2, &sisSession);
       
  3841 
       
  3842     RDEBUG( "CApplicationManagementSession: SetSisAppVersionAndDriveL: End" );
       
  3843     }
       
  3844 
       
  3845 TBool CApplicationManagementServer::IsInstalledAppRemovableL(
       
  3846         TDriveNumber &iDrive)
       
  3847     {
       
  3848 
       
  3849     RDEBUG( "IsInstalledAppRemovableL: Step1" );
       
  3850     TBool removable=EFalse;
       
  3851     RFs rfs;
       
  3852     User::LeaveIfError(rfs.Connect() );
       
  3853     CleanupClosePushL(rfs);
       
  3854     TDriveList driveList;
       
  3855     TInt driveCount;
       
  3856 
       
  3857     //Get all removeable drive, both physically and logically
       
  3858     User::LeaveIfError(DriveInfo::GetUserVisibleDrives(rfs, driveList,
       
  3859             driveCount, KDriveAttRemovable));
       
  3860 
       
  3861     TInt max(driveList.Length());
       
  3862 
       
  3863     RDEBUG_2( "driveList.Length() %d", max);
       
  3864 
       
  3865     RDEBUG_2( "driveCount %d", driveCount);
       
  3866 
       
  3867     TBuf<26> buf;
       
  3868     buf.Copy(driveList);
       
  3869     RDEBUG_2( "Drive Info (%S)", &buf);
       
  3870 
       
  3871     for (TInt i=0; i<max; ++i)
       
  3872         {
       
  3873 
       
  3874         //RDEBUG( "IsInstalledAppRemovableL: Step2" );
       
  3875         if (driveList[i])
       
  3876             {
       
  3877             TUint status;
       
  3878             RDEBUG( "IsInstalledAppRemovableL: Step3" );
       
  3879             DriveInfo::GetDriveStatus(rfs, i, status);
       
  3880 
       
  3881             RDEBUG( "IsInstalledAppRemovableL: Step4" );
       
  3882             //To make sure the drive is physically removeable not logically removeable  
       
  3883             if (status & DriveInfo::EDriveRemovable)
       
  3884                 {
       
  3885                 RDEBUG( "IsInstalledAppRemovableL: Drive removable" );
       
  3886                 RDEBUG_2( "IsInstalledAppRemovableL: Drive removable Drive ID %d", i);
       
  3887                 if (i == iDrive)
       
  3888                     {
       
  3889                     RDEBUG( "IsInstalledAppRemovableL: Step5" );
       
  3890                     removable=ETrue;
       
  3891                     break;
       
  3892                     }
       
  3893                 }
       
  3894             }
       
  3895         }
       
  3896 
       
  3897     CleanupStack::PopAndDestroy( &rfs);
       
  3898 
       
  3899     return removable;
       
  3900 
       
  3901     }
       
  3902 //  End of File