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