installationservices/swi/source/sislauncher/server/sislauncherserver.cpp
branchRCL_3
changeset 65 7333d7932ef7
parent 0 ba25891c3a9e
child 66 8b7f4e561641
equal deleted inserted replaced
62:5cc91383ab1e 65:7333d7932ef7
     1 /*
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    32 
    32 
    33 #include "threadmonitor.h"
    33 #include "threadmonitor.h"
    34 #include "queueprocessor.h"
    34 #include "queueprocessor.h"
    35 
    35 
    36 #ifndef SWI_TEXTSHELL_ROM
    36 #ifndef SWI_TEXTSHELL_ROM
    37 	#include <apmstd.h>
    37     #include <apmstd.h>
    38 	#include <apgcli.h>
    38     #include <apgcli.h>
    39 	#include <apgwgnam.h>
    39     #include <apgwgnam.h>
    40 	#include <apgtask.h>
    40     #include <apgtask.h>
    41 #endif
    41 #endif
    42 
    42 
    43 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    43 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    44 const TUint KInstallServerUid = 0x101F7295;
    44 const TUint KInstallServerUid = 0x101F7295;
    45 const TUint KSisRegistryServerUid = 0x10202DCA;
    45 const TUint KSisRegistryServerUid = 0x10202DCA;
    46 #endif
    46 #endif
    47 
    47 
    48 using namespace Swi;
    48 using namespace Swi;
    49 
    49 
    50 CServer2* CSisLauncherServer::NewLC()
    50 CServer2* CSisLauncherServer::NewLC()
    51 	{
    51     {
    52 	CSisLauncherServer* self=new(ELeave) CSisLauncherServer;
    52     CSisLauncherServer* self=new(ELeave) CSisLauncherServer;
    53 	CleanupStack::PushL(self);
    53     CleanupStack::PushL(self);
    54 	self->ConstructL();
    54     self->ConstructL();
    55 	return self;
    55     return self;
    56 	}
    56     }
    57 
    57 
    58 CSisLauncherServer::~CSisLauncherServer()
    58 CSisLauncherServer::~CSisLauncherServer()
    59 	{
    59     {
    60 #ifndef SWI_TEXTSHELL_ROM
    60 #ifndef SWI_TEXTSHELL_ROM
    61 	if (iBootMode != KTextShell)
    61     if (iBootMode != KTextShell)
    62 		{
    62         {
    63 		iWsSession.Close();	
    63         iWsSession.Close(); 
    64 		}
    64         }
    65 #endif
    65 #endif
    66 	delete iShutdown;
    66     delete iShutdown;
    67 	delete iQueueProcessor;
    67     delete iQueueProcessor;
    68 	CSecurityPolicy::ReleaseResource();
    68     CSecurityPolicy::ReleaseResource();
    69 	}
    69     }
    70 
    70 
    71 void CSisLauncherServer::ConstructL()
    71 void CSisLauncherServer::ConstructL()
    72 	{
    72     {
    73 	StartL(KSisLauncherServerName);
    73     StartL(KSisLauncherServerName);
    74 	iShutdown = new (ELeave) CSisLauncherServerShutdown;
    74     iShutdown = new (ELeave) CSisLauncherServerShutdown;
    75 	iShutdown->ConstructL();
    75     iShutdown->ConstructL();
    76 	TInt connectErr = KErrNotFound;
    76     TInt connectErr = KErrNotFound;
    77 #ifndef SWI_TEXTSHELL_ROM
    77 #ifndef SWI_TEXTSHELL_ROM
    78 	// Connect to Window Session
    78     // Connect to Window Session
    79 	connectErr = iWsSession.Connect();
    79     connectErr = iWsSession.Connect();
    80 	if (connectErr != KErrNotFound)
    80     if (connectErr != KErrNotFound)
    81 		{
    81         {
    82 		User::LeaveIfError(connectErr);
    82         User::LeaveIfError(connectErr);
    83 		}
    83         }
    84 #endif
    84 #endif
    85 	if (connectErr == KErrNotFound)
    85     if (connectErr == KErrNotFound)
    86 		{
    86         {
    87 		// emulator tests running in textshell or in textshell ROM (#def SWI_TEXTSHELL_ROM)
    87         // emulator tests running in textshell or in textshell ROM (#def SWI_TEXTSHELL_ROM)
    88 		iBootMode = KTextShell;
    88         iBootMode = KTextShell;
    89 		}
    89         }
    90 	iQueueProcessor = CQueueProcessor::NewL(*this);
    90     iQueueProcessor = CQueueProcessor::NewL(*this);
    91 	}
    91     }
    92 
    92 
    93 CSession2* CSisLauncherServer::NewSessionL(const TVersion&,const RMessage2&) const
    93 CSession2* CSisLauncherServer::NewSessionL(const TVersion&,const RMessage2&) const
    94 	{
    94     {
    95 	return new(ELeave) CSisLauncherSession();
    95     return new(ELeave) CSisLauncherSession();
    96 	}
    96     }
    97 
    97 
    98 void CSisLauncherServer::AddSession()
    98 void CSisLauncherServer::AddSession()
    99 	{
    99     {
   100 	++iSessionCount;
   100     ++iSessionCount;
   101 	
   101     
   102 	DEBUG_PRINTF2(_L8("Sis Launcher Server - Adding Session (%d sessions total.)"), iSessionCount);
   102     DEBUG_PRINTF2(_L8("Sis Launcher Server - Adding Session (%d sessions total.)"), iSessionCount);
   103 	
   103     
   104 	CancelShutdown();	
   104     CancelShutdown();   
   105 	}
   105     }
   106 
   106 
   107 void CSisLauncherServer::DropSession()
   107 void CSisLauncherServer::DropSession()
   108 	{
   108     {
   109 	--iSessionCount;
   109     --iSessionCount;
   110 	
   110     
   111 	DEBUG_PRINTF2(_L8("Sis Launcher Server - Dropping Session (%d sessions total.)"), iSessionCount);
   111     DEBUG_PRINTF2(_L8("Sis Launcher Server - Dropping Session (%d sessions total.)"), iSessionCount);
   112 	
   112     
   113 	if (0==iSessionCount && iShutdown)
   113     if (0==iSessionCount && iShutdown)
   114 		{
   114         {
   115 		DEBUG_PRINTF(_L8("Sis Launcher Server - Starting shutdown timer."));
   115         DEBUG_PRINTF(_L8("Sis Launcher Server - Starting shutdown timer."));
   116 		// ignored if a long timer is active
   116         // ignored if a long timer is active
   117 		iShutdown->StartShort(EFalse);
   117         iShutdown->StartShort(EFalse);
   118 		} 
   118         } 
   119 	}
   119     }
   120 /**
   120 /**
   121  * Cancels an existing shutdown timer before renabling with the long timeout. This is used to catch
   121  * Cancels an existing shutdown timer before renabling with the long timeout. This is used to catch
   122  * the case where we need to allow ECOM to work before killing the server. ECOM should finish scanning 
   122  * the case where we need to allow ECOM to work before killing the server. ECOM should finish scanning 
   123  * files within a couple of seconds of SWI finishing but just in case we allow ECOM a little longer.
   123  * files within a couple of seconds of SWI finishing but just in case we allow ECOM a little longer.
   124  * The other reason we have the timer is to handle the case where SWI mistakenly identified a plugin 
   124  * The other reason we have the timer is to handle the case where SWI mistakenly identified a plugin 
   125  * resource file, we don't want to hang around forever waiting for an event that never comes.
   125  * resource file, we don't want to hang around forever waiting for an event that never comes.
   126  * */
   126  * */
   127 void CSisLauncherServer::LongServerShutdown()
   127 void CSisLauncherServer::LongServerShutdown()
   128 	{
   128     {
   129 	DEBUG_PRINTF(_L8("Sis Launcher Server - Switching to long shutdown timer"));
   129     DEBUG_PRINTF(_L8("Sis Launcher Server - Switching to long shutdown timer"));
   130 	if (iShutdown)
   130     if (iShutdown)
   131 		{
   131         {
   132 		iShutdown->StartLong();
   132         iShutdown->StartLong();
   133 		}
   133         }
   134 	}
   134     }
   135 
   135 
   136 void CSisLauncherServer::CancelShutdown()
   136 void CSisLauncherServer::CancelShutdown()
   137 	{
   137     {
   138 	DEBUG_PRINTF(_L8("Sis Launcher Server - Cancelling shutdown timer"));
   138     DEBUG_PRINTF(_L8("Sis Launcher Server - Cancelling shutdown timer"));
   139 		
   139         
   140 	if (iShutdown)
   140     if (iShutdown)
   141 		{
   141         {
   142 		iShutdown->Cancel();
   142         iShutdown->Cancel();
   143 		}	
   143         }   
   144 	}
   144     }
   145 
   145 
   146 void CSisLauncherServer::ShortServerShutdown()
   146 void CSisLauncherServer::ShortServerShutdown()
   147 	{
   147     {
   148 	DEBUG_PRINTF(_L8("Sis Launcher Server - Re-enabling short shutdown timer"));
   148     DEBUG_PRINTF(_L8("Sis Launcher Server - Re-enabling short shutdown timer"));
   149 	if (0==iSessionCount && iShutdown)
   149     if (0==iSessionCount && iShutdown)
   150 		{
   150         {
   151 		DEBUG_PRINTF(_L8("Sis Launcher Server - Starting shutdown timer"));
   151         DEBUG_PRINTF(_L8("Sis Launcher Server - Starting shutdown timer"));
   152 		iShutdown->StartShort(ETrue);
   152         iShutdown->StartShort(ETrue);
   153 		} 
   153         } 
   154 	}
   154     }
   155 
   155 
   156 	// All functions require TCB capability
       
   157 const TInt CSisLauncherServer::iRanges[iRangeCount] = 
   156 const TInt CSisLauncherServer::iRanges[iRangeCount] = 
   158 	{
   157     {
   159 	0, // All connect attempts
   158     0, // All connect attempts
   160 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   159 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   161 	// Range of utility services for Post manufacture management of Layered Execution Environemnts
   160     EParseSwTypeRegFile,                                // accessible by Installserver 
   162 	EParseSwTypeRegFile,
   161     EUnregisterSifLauncherMimeTypes,                    // accessible by SisRegistryServer
   163 	EUnregisterSifLauncherMimeTypes,
   162     ENotifyApparcForApps,                               // accessible by Installserver and SisRegistry
   164 #endif
   163     EAsyncParseResourceFileSize,                        // accessible by all clients
   165 	ESeparatorEndAll,
   164 #endif
   166 	};
   165     ESeparatorEndAll,
       
   166     };
   167 
   167 
   168 const TUint8 CSisLauncherServer::iElementsIndex[iRangeCount] = 
   168 const TUint8 CSisLauncherServer::iElementsIndex[iRangeCount] = 
   169 	{
   169     {
   170 	0, // Used by Client which is only swis and TCB is needed.
   170     0, // Used by Client which is only swis and TCB is needed.
   171 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   171 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   172 	1, // Utility services used by InstallServer
   172     1, // Utility services used by InstallServer
   173 	2, // Utility services used by SisRegistryServer
   173     2, // Utility services used by SisRegistryServer
   174 #endif
   174     CPolicyServer::ECustomCheck,
   175 	CPolicyServer::ENotSupported,
   175     CPolicyServer::EAlwaysPass,
   176 	};
   176 #endif  
       
   177     CPolicyServer::ENotSupported,
       
   178     };
   177 
   179 
   178 const CPolicyServer::TPolicyElement CSisLauncherServer::iPolicyElements[] = 
   180 const CPolicyServer::TPolicyElement CSisLauncherServer::iPolicyElements[] = 
   179 	{
   181     {
   180 	{_INIT_SECURITY_POLICY_C1(ECapabilityTCB), CPolicyServer::EFailClient},
   182     {_INIT_SECURITY_POLICY_C1(ECapabilityTCB), CPolicyServer::EFailClient},
   181 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   183 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   182 	{_INIT_SECURITY_POLICY_S0(KInstallServerUid), CPolicyServer::EFailClient},
   184     {_INIT_SECURITY_POLICY_S0(KInstallServerUid), CPolicyServer::EFailClient},
   183 	{_INIT_SECURITY_POLICY_S0(KSisRegistryServerUid), CPolicyServer::EFailClient},
   185     {_INIT_SECURITY_POLICY_S0(KSisRegistryServerUid), CPolicyServer::EFailClient},  
   184 #endif
   186 #endif
   185 	};
   187     };
   186 
   188 
   187 const CPolicyServer::TPolicy CSisLauncherServer::iPolicy =
   189 const CPolicyServer::TPolicy CSisLauncherServer::iPolicy =
   188 	{
   190     {
   189 	0,					//specifies all connect attempts need TCB
   191     0,                  //specifies all connect attempts need TCB
   190 	iRangeCount,
   192     iRangeCount,
   191 	iRanges,
   193     iRanges,
   192 	iElementsIndex,
   194     iElementsIndex,
   193 	iPolicyElements,
   195     iPolicyElements,
   194 	};
   196     };
   195 	
   197     
   196 	
   198     
   197 // shutdown timer
   199 // shutdown timer
   198 
   200 
   199 CSisLauncherServerShutdown::~CSisLauncherServerShutdown()
   201 CSisLauncherServerShutdown::~CSisLauncherServerShutdown()
   200 	{
   202     {
   201 	Cancel();
   203     Cancel();
   202 	}
   204     }
   203 
   205 
   204 void CSisLauncherServerShutdown::RunL()
   206 void CSisLauncherServerShutdown::RunL()
   205 	{
   207     {
   206 	CActiveScheduler::Stop();
   208     CActiveScheduler::Stop();
   207 	}
   209     }
   208 	
   210     
   209 void CSisLauncherServerShutdown::StartShort(TBool aCancelLongTimer)
   211 void CSisLauncherServerShutdown::StartShort(TBool aCancelLongTimer)
   210 	{
   212     {
   211 	if (iLongTimerActive & !aCancelLongTimer)
   213     if (iLongTimerActive & !aCancelLongTimer)
   212 		{
   214         {
   213 		return;
   215         return;
   214 		}
   216         }
   215 	else
   217     else
   216 		{
   218         {
   217 		Cancel();
   219         Cancel();
   218 		iLongTimerActive=EFalse;
   220         iLongTimerActive=EFalse;
   219 		After(KSisLauncherShutdownDelay);
   221         After(KSisLauncherShutdownDelay);
   220 		}
   222         }
   221 	}
   223     }
   222 
   224 
   223 inline void CSisLauncherServerShutdown::StartLong()
   225 inline void CSisLauncherServerShutdown::StartLong()
   224 	{
   226     {
   225 	Cancel();
   227     Cancel();
   226 	iLongTimerActive=ETrue;
   228     iLongTimerActive=ETrue;
   227 	After(KSisLauncherLongShutdownDelay);
   229     After(KSisLauncherLongShutdownDelay);
   228 	}
   230     }
   229 
   231 
   230 
   232 
   231 void CSisLauncherServer::RunExecutableL(const TDesC& aFileName, TBool aWait)
   233 void CSisLauncherServer::RunExecutableL(const TDesC& aFileName, TBool aWait)
   232 	{
   234     {
   233 	DEBUG_CODE_SECTION(
   235     DEBUG_CODE_SECTION(
   234 		if (aWait)
   236         if (aWait)
   235 			{
   237             {
   236 			DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to run executable by filename ('%S'), waiting for termination."),
   238             DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to run executable by filename ('%S'), waiting for termination."),
   237 				&aFileName);
   239                 &aFileName);
   238 			}
   240             }
   239 		else
   241         else
   240 			{
   242             {
   241 			DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to run executable by filename ('%S'), not waiting for termination."),
   243             DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to run executable by filename ('%S'), not waiting for termination."),
   242 				&aFileName);
   244                 &aFileName);
   243 			}
   245             }
   244 	); // DEBUG_CODE_SECTION
   246     ); // DEBUG_CODE_SECTION
   245 	
   247     
   246 	RProcess process;
   248     RProcess process;
   247 	_LIT(KNullArgs, "");
   249     _LIT(KNullArgs, "");
   248 	User::LeaveIfError(process.Create(aFileName, KNullArgs));
   250     User::LeaveIfError(process.Create(aFileName, KNullArgs));
   249 	CleanupClosePushL(process);
   251     CleanupClosePushL(process);
   250 	
   252     
   251 	// Get the thread id of the main thread in the process
   253     // Get the thread id of the main thread in the process
   252 	// From CApaExeRecognizer::RunL	
   254     // From CApaExeRecognizer::RunL 
   253 	TFullName fullName(process.Name());
   255     TFullName fullName(process.Name());
   254 	_LIT(KCCMain,"::Main");
   256     _LIT(KCCMain,"::Main");
   255 	fullName.Append(KCCMain);
   257     fullName.Append(KCCMain);
   256 	TFindThread fT(fullName);
   258     TFindThread fT(fullName);
   257 	User::LeaveIfError(fT.Next(fullName));
   259     User::LeaveIfError(fT.Next(fullName));
   258 	RThread thread;
   260     RThread thread;
   259 	User::LeaveIfError(thread.Open(fT));
   261     User::LeaveIfError(thread.Open(fT));
   260 	TThreadId threadId = thread.Id();
   262     TThreadId threadId = thread.Id();
   261 	thread.Close();
   263     thread.Close();
   262 	process.Resume();
   264     process.Resume();
   263 	
   265     
   264 	CleanupStack::PopAndDestroy(&process);
   266     CleanupStack::PopAndDestroy(&process);
   265 	if (aWait)
   267     if (aWait)
   266 		HandleShutdownL(threadId, ETrue);
   268         HandleShutdownL(threadId, ETrue);
   267 	}
   269     }
   268 
       
   269 
       
   270 
   270 
   271 void CSisLauncherServer::ForceShutdownL(TUid aUid)
   271 void CSisLauncherServer::ForceShutdownL(TUid aUid)
   272 	{
   272     {
   273 	TBool needToScanFullList;
   273     TBool needToScanFullList;
   274 	TFullName fullName;
   274     TFullName fullName;
   275 	do
   275     do
   276 		{
   276         {
   277 		needToScanFullList = EFalse;
   277         needToScanFullList = EFalse;
   278 		TFindProcess findProcess;
   278         TFindProcess findProcess;
   279 
   279 
   280 		while(findProcess.Next(fullName) == KErrNone)
   280         while(findProcess.Next(fullName) == KErrNone)
   281 			{
   281             {
   282 			RProcess process;
   282             RProcess process;
   283 			User::LeaveIfError(process.Open(findProcess));
   283             User::LeaveIfError(process.Open(findProcess));
   284 			TUid sid(process.SecureId());
   284             TUid sid(process.SecureId());
   285 			if (sid == aUid && process.ExitType() == EExitPending)
   285             if (sid == aUid && process.ExitType() == EExitPending)
   286 				{
   286                 {
   287 				process.Kill(KErrNone);
   287                 process.Kill(KErrNone);
   288 				needToScanFullList = ETrue;
   288                 needToScanFullList = ETrue;
   289 				}
   289                 }
   290 			process.Close();
   290             process.Close();
   291 			}
   291             }
   292 		} while (needToScanFullList);
   292         } while (needToScanFullList);
   293 	}
   293     }
   294 
   294 
   295 
   295 
   296 void CSisLauncherServer::HandleShutdownL(TThreadId aThread, TBool aKillOnTimeout)
   296 void CSisLauncherServer::HandleShutdownL(TThreadId aThread, TBool aKillOnTimeout)
   297 	{
   297     {
   298 	RWsSession* wsSession = NULL;
   298     RWsSession* wsSession = NULL;
   299 	if (iBootMode == KTextShell) 
   299     if (iBootMode == KTextShell) 
   300 		{
   300         {
   301 		// emulator tests running in textshell or in textshell ROM (#def SWI_TEXTSHELL_ROM)
   301         // emulator tests running in textshell or in textshell ROM (#def SWI_TEXTSHELL_ROM)
   302 		DEBUG_PRINTF(_L8("Sis Launcher Server - textshell - skipping shutdown of user applications"));	
   302         DEBUG_PRINTF(_L8("Sis Launcher Server - textshell - skipping shutdown of user applications"));  
   303 		}
   303         }
   304 	else
   304     else
   305 		{
   305         {
   306 		#ifndef SWI_TEXTSHELL_ROM
   306         #ifndef SWI_TEXTSHELL_ROM
   307 			DEBUG_CODE_SECTION(
   307             DEBUG_CODE_SECTION(
   308 				if (aKillOnTimeout)
   308                 if (aKillOnTimeout)
   309 					{
   309                     {
   310 					DEBUG_PRINTF(_L8("Sis Launcher Server - Awaiting thread shutdown, will forcibly kill process on timeout."));
   310                     DEBUG_PRINTF(_L8("Sis Launcher Server - Awaiting thread shutdown, will forcibly kill process on timeout."));
   311 					}
   311                     }
   312 				else
   312                 else
   313 					{
   313                     {
   314 					DEBUG_PRINTF(_L8("Sis Launcher Server - Awaiting thread shutdown, will not forcibly kill process on timeout."));
   314                     DEBUG_PRINTF(_L8("Sis Launcher Server - Awaiting thread shutdown, will not forcibly kill process on timeout."));
   315 					}
   315                     }
   316 				);
   316                 );
   317 			wsSession = &iWsSession;	
   317             wsSession = &iWsSession;    
   318 		#endif
   318         #endif
   319 		}
   319         }
   320 	// Read timeout value from software install security
   320     // Read timeout value from software install security
   321 	// policy.
   321     // policy.
   322 	CSecurityPolicy* secPolicy = CSecurityPolicy::GetSecurityPolicyL();
   322     CSecurityPolicy* secPolicy = CSecurityPolicy::GetSecurityPolicyL();
   323 	TInt runWaitTimeout = secPolicy->RunWaitTimeout();
   323     TInt runWaitTimeout = secPolicy->RunWaitTimeout();
   324 	TInt shutdownTimeout = secPolicy->ApplicationShutdownTimeout();
   324     TInt shutdownTimeout = secPolicy->ApplicationShutdownTimeout();
   325 	// Wait until the thread finishes or a timeout occurs
   325     // Wait until the thread finishes or a timeout occurs
   326 	CThreadMonitor* threadMonitor = CThreadMonitor::NewLC(aThread, wsSession);
   326     CThreadMonitor* threadMonitor = CThreadMonitor::NewLC(aThread, wsSession);
   327 	threadMonitor->SyncShutdownL(runWaitTimeout, aKillOnTimeout, shutdownTimeout);
   327     threadMonitor->SyncShutdownL(runWaitTimeout, aKillOnTimeout, shutdownTimeout);
   328 	CleanupStack::PopAndDestroy(threadMonitor);
   328     CleanupStack::PopAndDestroy(threadMonitor);
   329 	}
   329     }
   330 
   330 
       
   331 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   332 CPolicyServer::TCustomResult CSisLauncherServer::CustomSecurityCheckL(const RMessage2& aMsg, 
       
   333     TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
       
   334     {
       
   335     TUint32 secureId = aMsg.SecureId().iId;
       
   336     if (secureId == KInstallServerUid || secureId == KSisRegistryServerUid)
       
   337         {
       
   338         return CPolicyServer::EPass;
       
   339         }
       
   340     else
       
   341         {
       
   342         //client accessing the function is neither Install Server nor Sis Registry
       
   343         return CPolicyServer::EFail;
       
   344         }
       
   345     }
       
   346 #endif
   331 
   347 
   332 #ifndef SWI_TEXTSHELL_ROM
   348 #ifndef SWI_TEXTSHELL_ROM
   333 void CSisLauncherServer::StartDocumentL(RFile& aFile, TBool aWait)
   349 void CSisLauncherServer::StartDocumentL(RFile& aFile, TBool aWait)
   334 	{
   350     {
   335 	DEBUG_CODE_SECTION(
   351     DEBUG_CODE_SECTION(
   336 	if (aWait)
   352     if (aWait)
   337 		{
   353         {
   338 		DEBUG_PRINTF(_L8("Sis Launcher Server - Attempting to start document by filehandle, waiting for termination."));
   354         DEBUG_PRINTF(_L8("Sis Launcher Server - Attempting to start document by filehandle, waiting for termination."));
   339 		}
   355         }
   340 	else
   356     else
   341 		{
   357         {
   342 		DEBUG_PRINTF(_L8("Sis Launcher Server - Attempting to start document by filehandle, not waiting for termination."));
   358         DEBUG_PRINTF(_L8("Sis Launcher Server - Attempting to start document by filehandle, not waiting for termination."));
   343 		}
   359         }
   344 	);
   360     );
   345 
   361 
   346 	RApaLsSession apaSession;
   362     RApaLsSession apaSession;
   347 	User::LeaveIfError(apaSession.Connect());
   363     User::LeaveIfError(apaSession.Connect());
   348 	CleanupClosePushL(apaSession);
   364     CleanupClosePushL(apaSession);
   349 
   365 
   350 	TThreadId threadId;	
   366     TThreadId threadId; 
   351 	User::LeaveIfError(apaSession.StartDocument(aFile, threadId));
   367     User::LeaveIfError(apaSession.StartDocument(aFile, threadId));
   352 
   368 
   353 	CleanupStack::PopAndDestroy(&apaSession);
   369     CleanupStack::PopAndDestroy(&apaSession);
   354 	if (aWait)
   370     if (aWait)
   355 		HandleShutdownL(threadId);
   371         HandleShutdownL(threadId);
   356 	}
   372     }
   357 
   373 
   358 void CSisLauncherServer::StartByMimeL(RFile& aFile, TDesC8& aMimeType, TBool aWait)
   374 void CSisLauncherServer::StartByMimeL(RFile& aFile, TDesC8& aMimeType, TBool aWait)
   359 	{
   375     {
   360 	DEBUG_CODE_SECTION(
   376     DEBUG_CODE_SECTION(
   361 	if (aWait)
   377     if (aWait)
   362 		{
   378         {
   363 		DEBUG_PRINTF2(_L8("Sis Launcher Server - Attempting to start document by mimetype '%S' (filehandle supplied), waiting for termination."),
   379         DEBUG_PRINTF2(_L8("Sis Launcher Server - Attempting to start document by mimetype '%S' (filehandle supplied), waiting for termination."),
   364 			&aMimeType);
   380             &aMimeType);
   365 		}
   381         }
   366 	else
   382     else
   367 		{
   383         {
   368 		DEBUG_PRINTF2(_L8("Sis Launcher Server - Attempting to start document by mimetype '%S' (filehandle supplied), not waiting for termination."),
   384         DEBUG_PRINTF2(_L8("Sis Launcher Server - Attempting to start document by mimetype '%S' (filehandle supplied), not waiting for termination."),
   369 			&aMimeType);
   385             &aMimeType);
   370 		}
   386         }
   371 	);
   387     );
   372 
   388 
   373 	RApaLsSession apaSession;
   389     RApaLsSession apaSession;
   374 	User::LeaveIfError(apaSession.Connect());
   390     User::LeaveIfError(apaSession.Connect());
   375 	CleanupClosePushL(apaSession);
   391     CleanupClosePushL(apaSession);
   376 
   392 
   377 	TThreadId threadId;
   393     TThreadId threadId;
   378 	TDataType dataType = TDataType(aMimeType);	
   394     TDataType dataType = TDataType(aMimeType);  
   379 	User::LeaveIfError(apaSession.StartDocument(aFile, dataType, threadId));
   395     User::LeaveIfError(apaSession.StartDocument(aFile, dataType, threadId));
   380 
   396 
   381 	CleanupStack::PopAndDestroy(&apaSession);
   397     CleanupStack::PopAndDestroy(&apaSession);
   382 	if (aWait)
   398     if (aWait)
   383 		HandleShutdownL(threadId);
   399         HandleShutdownL(threadId);
   384 	}
   400     }
   385 	
   401     
   386 void CSisLauncherServer::StartDocumentL(const TDesC& aFileName, TBool aWait)
   402 void CSisLauncherServer::StartDocumentL(const TDesC& aFileName, TBool aWait)
   387 	{
   403     {
   388 	DEBUG_CODE_SECTION(
   404     DEBUG_CODE_SECTION(
   389 	if (aWait)
   405     if (aWait)
   390 		{
   406         {
   391 		DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', waiting for termination."),
   407         DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', waiting for termination."),
   392 			&aFileName);
   408             &aFileName);
   393 		}
   409         }
   394 	else
   410     else
   395 		{
   411         {
   396 		DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', not waiting for termination."),
   412         DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', not waiting for termination."),
   397 			&aFileName);
   413             &aFileName);
   398 		}
   414         }
   399 	);
   415     );
   400 
   416 
   401 	RApaLsSession apaSession;
   417     RApaLsSession apaSession;
   402 	User::LeaveIfError(apaSession.Connect());
   418     User::LeaveIfError(apaSession.Connect());
   403 	CleanupClosePushL(apaSession);
   419     CleanupClosePushL(apaSession);
   404 
   420 
   405 	TThreadId threadId;
   421     TThreadId threadId;
   406 	User::LeaveIfError(apaSession.StartDocument(aFileName, threadId));
   422     User::LeaveIfError(apaSession.StartDocument(aFileName, threadId));
   407 
   423 
   408 	CleanupStack::PopAndDestroy(&apaSession);
   424     CleanupStack::PopAndDestroy(&apaSession);
   409 	if (aWait)
   425     if (aWait)
   410 		HandleShutdownL(threadId);
   426         HandleShutdownL(threadId);
   411 	}
   427     }
   412 
   428 
   413 void CSisLauncherServer::StartByMimeL(const TDesC& aFileName, TDesC8& aMimeType, TBool aWait)
   429 void CSisLauncherServer::StartByMimeL(const TDesC& aFileName, TDesC8& aMimeType, TBool aWait)
   414 	{
   430     {
   415 	DEBUG_CODE_SECTION(
   431     DEBUG_CODE_SECTION(
   416 	if (aWait)
   432     if (aWait)
   417 		{
   433         {
   418 		DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', waiting for termination."),
   434         DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', waiting for termination."),
   419 			&aFileName);
   435             &aFileName);
   420 		}
   436         }
   421 	else
   437     else
   422 		{
   438         {
   423 		DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', not waiting for termination."),
   439         DEBUG_PRINTF2(_L("Sis Launcher Server - Attempting to start document by filename '%S', not waiting for termination."),
   424 			&aFileName);
   440             &aFileName);
   425 		}
   441         }
   426 	);
   442     );
   427 	DEBUG_PRINTF2(_L8("Sis Launcher Server - Supplied MIME type is '%S'."), &aMimeType);	
   443     DEBUG_PRINTF2(_L8("Sis Launcher Server - Supplied MIME type is '%S'."), &aMimeType);    
   428 
   444 
   429 	RApaLsSession apaSession;
   445     RApaLsSession apaSession;
   430 	User::LeaveIfError(apaSession.Connect());
   446     User::LeaveIfError(apaSession.Connect());
   431 	CleanupClosePushL(apaSession);
   447     CleanupClosePushL(apaSession);
   432 
   448 
   433 	TThreadId threadId;
   449     TThreadId threadId;
   434 	TDataType dataType = TDataType(aMimeType);
   450     TDataType dataType = TDataType(aMimeType);
   435 	User::LeaveIfError(apaSession.StartDocument(aFileName, dataType, threadId));
   451     User::LeaveIfError(apaSession.StartDocument(aFileName, dataType, threadId));
   436 
   452 
   437 	CleanupStack::PopAndDestroy(&apaSession);
   453     CleanupStack::PopAndDestroy(&apaSession);
   438 	if (aWait)
   454     if (aWait)
   439 		HandleShutdownL(threadId);
   455         HandleShutdownL(threadId);
   440 	}
   456     }
   441 
   457 
   442 void CSisLauncherServer::ShutdownL(TUid aUid, TInt aTimeout)
   458 void CSisLauncherServer::ShutdownL(TUid aUid, TInt aTimeout)
   443 	{
   459     {
   444 	// This method shuts down running exes matching the SID provided in aUid.
   460     // This method shuts down running exes matching the SID provided in aUid.
   445 	// It first attempts a graceful shutdown, killing processes if a graceful
   461     // It first attempts a graceful shutdown, killing processes if a graceful
   446 	// shutdown is not supported or fails to work within aTimeout microseconds.
   462     // shutdown is not supported or fails to work within aTimeout microseconds.
   447 
   463 
   448 	DEBUG_PRINTF2(_L8("Sis Launcher Server - Attempting to kill process with SID: 0x%08x."),
   464     DEBUG_PRINTF2(_L8("Sis Launcher Server - Attempting to kill process with SID: 0x%08x."),
   449 		aUid.iUid);
   465         aUid.iUid);
   450 
   466 
   451 	TInt wgId=0;
   467     TInt wgId=0;
   452 
   468 
   453 	CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(iWsSession);
   469     CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(iWsSession);
   454 	CleanupStack::PushL(wgName);
   470     CleanupStack::PushL(wgName);
   455 	CApaWindowGroupName::FindByAppUid(aUid, iWsSession, wgId);
   471     CApaWindowGroupName::FindByAppUid(aUid, iWsSession, wgId);
   456 	
   472     
   457 	while (wgId != KErrNotFound)
   473     while (wgId != KErrNotFound)
   458 		{	
   474         {   
   459 		wgName->ConstructFromWgIdL(wgId);
   475         wgName->ConstructFromWgIdL(wgId);
   460 		if(wgName->RespondsToShutdownEvent())
   476         if(wgName->RespondsToShutdownEvent())
   461 			{
   477             {
   462 			TApaTask task(iWsSession);
   478             TApaTask task(iWsSession);
   463 			task.SetWgId(wgId);
   479             task.SetWgId(wgId);
   464 
   480 
   465 			RThread thread;
   481             RThread thread;
   466 			User::LeaveIfError(thread.Open(task.ThreadId()));
   482             User::LeaveIfError(thread.Open(task.ThreadId()));
   467 			CleanupClosePushL(thread);
   483             CleanupClosePushL(thread);
   468 			
   484             
   469 			RProcess process;
   485             RProcess process;
   470 			User::LeaveIfError(thread.Process(process));
   486             User::LeaveIfError(thread.Process(process));
   471 			CleanupClosePushL(process);
   487             CleanupClosePushL(process);
   472 
   488 
   473 			TRequestStatus processStatus;
   489             TRequestStatus processStatus;
   474 			process.Logon(processStatus);
   490             process.Logon(processStatus);
   475 			
   491             
   476 			task.SendSystemEvent(EApaSystemEventShutdown);
   492             task.SendSystemEvent(EApaSystemEventShutdown);
   477 
   493 
   478 			RTimer timer;
   494             RTimer timer;
   479 			CleanupClosePushL(timer);
   495             CleanupClosePushL(timer);
   480 			TRequestStatus timerStatus;
   496             TRequestStatus timerStatus;
   481 			timer.CreateLocal();
   497             timer.CreateLocal();
   482 			timer.After(timerStatus, aTimeout);
   498             timer.After(timerStatus, aTimeout);
   483 
   499 
   484 			User::WaitForRequest(processStatus,timerStatus);
   500             User::WaitForRequest(processStatus,timerStatus);
   485 
   501 
   486 			if (processStatus==KRequestPending)
   502             if (processStatus==KRequestPending)
   487 				{
   503                 {
   488 				// Failed to terminate gracefully, so kill the task.
   504                 // Failed to terminate gracefully, so kill the task.
   489 				DEBUG_PRINTF(_L8("Sis Launcher Server - Process did not die before timeout. Forcibly killing it."));
   505                 DEBUG_PRINTF(_L8("Sis Launcher Server - Process did not die before timeout. Forcibly killing it."));
   490 				process.Kill(KErrNone);
   506                 process.Kill(KErrNone);
   491 				}
   507                 }
   492 			else if (timerStatus==KRequestPending)
   508             else if (timerStatus==KRequestPending)
   493 				{
   509                 {
   494 				// Rendezvous completed so cancel timer
   510                 // Rendezvous completed so cancel timer
   495 				timer.Cancel();
   511                 timer.Cancel();
   496 				}
   512                 }
   497 			// Handle second request
   513             // Handle second request
   498 			User::WaitForRequest(processStatus,timerStatus);
   514             User::WaitForRequest(processStatus,timerStatus);
   499 			CleanupStack::PopAndDestroy(3, &thread);
   515             CleanupStack::PopAndDestroy(3, &thread);
   500 			}
   516             }
   501 
   517 
   502 		// See if there's another instance of this App running.
   518         // See if there's another instance of this App running.
   503 		CApaWindowGroupName::FindByAppUid(aUid, iWsSession, wgId);
   519         CApaWindowGroupName::FindByAppUid(aUid, iWsSession, wgId);
   504 		}
   520         }
   505 	CleanupStack::PopAndDestroy(wgName);
   521     CleanupStack::PopAndDestroy(wgName);
   506 	}
   522     }
   507 
   523 
   508 void CSisLauncherServer::ShutdownL()
   524 void CSisLauncherServer::ShutdownL()
   509 	{
   525     {
   510 	TInt wgId=0;
   526     TInt wgId=0;
   511     
   527     
   512 	CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(iWsSession);
   528     CApaWindowGroupName* wgName = CApaWindowGroupName::NewL(iWsSession);
   513 	CleanupStack::PushL(wgName);
   529     CleanupStack::PushL(wgName);
   514 	TBuf<1> matchAny;
   530     TBuf<1> matchAny;
   515 	matchAny.Append(KMatchAny);
   531     matchAny.Append(KMatchAny);
   516 	CApaWindowGroupName::FindByCaption(matchAny, iWsSession, wgId);
   532     CApaWindowGroupName::FindByCaption(matchAny, iWsSession, wgId);
   517 	while (wgId != KErrNotFound)
   533     while (wgId != KErrNotFound)
   518 		{
   534         {
   519 		wgName->ConstructFromWgIdL(wgId);
   535         wgName->ConstructFromWgIdL(wgId);
   520 		//DEF057706 - shut down hidden apps during uninstallation if
   536         //DEF057706 - shut down hidden apps during uninstallation if
   521 		// SH flag is specified
   537         // SH flag is specified
   522 		if (!wgName->IsSystem() /* && !wgName->Hidden() */)
   538         if (!wgName->IsSystem() /* && !wgName->Hidden() */)
   523 			{
   539             {
   524 			// leave if we cannot shutdown the app because its busy
   540             // leave if we cannot shutdown the app because its busy
   525 			if(!wgName->IsBusy())
   541             if(!wgName->IsBusy())
   526 				{
   542                 {
   527 				TApaTask task(iWsSession);
   543                 TApaTask task(iWsSession);
   528 				task.SetWgId(wgId);
   544                 task.SetWgId(wgId);
   529 				// show shutdown dialog for this app?
   545                 // show shutdown dialog for this app?
   530 				task.SendSystemEvent(EApaSystemEventShutdown);
   546                 task.SendSystemEvent(EApaSystemEventShutdown);
   531 				}
   547                 }
   532 			else
   548             else
   533 				{
   549                 {
   534 				// could not shutdown an app
   550                 // could not shutdown an app
   535 				User::Leave(KErrInUse);
   551                 User::Leave(KErrInUse);
   536 				}
   552                 }
   537 			}
   553             }
   538 	
   554     
   539 		// get next app to shutdown
   555         // get next app to shutdown
   540 		CApaWindowGroupName::FindByCaption(matchAny, iWsSession, wgId);
   556         CApaWindowGroupName::FindByCaption(matchAny, iWsSession, wgId);
   541 		}
   557         }
   542 	CleanupStack::PopAndDestroy(wgName);
   558     CleanupStack::PopAndDestroy(wgName);
   543 	}
   559     }
   544 
   560 
   545 void CSisLauncherServer::NotifyNewAppsL(const RPointerArray<TDesC>& aFiles)
   561 void CSisLauncherServer::NotifyNewAppsL(const RPointerArray<TDesC>& aFiles)
   546 	{
   562     {
   547 	RApaLsSession apaSession;
   563     RApaLsSession apaSession;
   548 	User::LeaveIfError(apaSession.Connect());
   564     User::LeaveIfError(apaSession.Connect());
   549 	CleanupClosePushL(apaSession);
   565     CleanupClosePushL(apaSession);
   550 
   566 
   551 	// UI frameworks advise ignoring the return code
   567     // UI frameworks advise ignoring the return code
   552 	apaSession.ForceRegistration(aFiles);
   568     apaSession.ForceRegistration(aFiles);
   553 
   569 
   554 	CleanupStack::PopAndDestroy();
   570     CleanupStack::PopAndDestroy();
   555 	}
   571     }
   556 #endif
   572 
   557 
   573 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   558 	
   574 void CSisLauncherServer::NotifyNewAppsL(const RPointerArray<Usif::CApplicationRegistrationData>& aApplicationRegistrationData)
       
   575     {
       
   576     RApaLsSession apaSession;
       
   577     User::LeaveIfError(apaSession.Connect());
       
   578     CleanupClosePushL(apaSession);
       
   579 
       
   580     // UI frameworks advise ignoring the return code
       
   581     // Proceeding even if force registration fails so that installation is not aborted
       
   582     apaSession.ForceRegistration(aApplicationRegistrationData);
       
   583     CleanupStack::PopAndDestroy();
       
   584     }
       
   585 
       
   586 #endif
       
   587 #endif
       
   588 
       
   589