localisation/apparchitecture/apserv/APSSES.CPP
branchSymbian3
changeset 57 b8d18c84f71c
parent 6 c108117318cb
equal deleted inserted replaced
56:aa99f2208aad 57:b8d18c84f71c
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // AppArc server session
    14 // AppArc server session
    15 // 
    15 // 
       
    16 // apsses.cpp
    16 //
    17 //
    17 
    18 
    18 #include <e32svr.h>
    19 #include <e32svr.h>
    19 #include <apacmdln.h>
    20 #include <apacmdln.h>
       
    21 
    20 #include <apaflrec.h>
    22 #include <apaflrec.h>
    21 #include <apsserv.h>
    23 #include "apsserv.h"
    22 #include "APSSES.H"
    24 #include "APSSES.H"
    23 #ifdef _DEBUG
    25 #ifdef _DEBUG
    24 #include "APSSTD.H"
    26 #include "APSSTD.H"
    25 #endif //_DEBUG
    27 #endif //_DEBUG
    26 #include "APSCLSV.H"
    28 #include "APSCLSV.H"
    34 #include <s32mem.h>
    36 #include <s32mem.h>
    35 #include <s32strm.h>
    37 #include <s32strm.h>
    36 #include <s32file.h>
    38 #include <s32file.h>
    37 #include "../apgrfx/apprivate.h"
    39 #include "../apgrfx/apprivate.h"
    38 #include "apgnotif.h"
    40 #include "apgnotif.h"
    39 #include "../apfile/aprfndr.h"
    41 #include "../aplist/aplappregfinder.h"
    40 #include "ApLaunchChecker.h"
    42 #include "ApLaunchChecker.h"
    41 #include "apsnnapps.h"
    43 #include "apsnnapps.h"
       
    44 #include "../aplist/aplapplistitem.h"
    42 
    45 
    43 #include "apsecutils.h"
    46 #include "apsecutils.h"
    44 
    47 
    45 const TInt KApaAppListServMaxBuffer=256;
    48 const TInt KApaAppListServMaxBuffer=256;
    46 #include "APSRECCACHE.h"
    49 #include "APSRECCACHE.h"
    47 const TInt KApaAppInfoArrayGranularity=4;
    50 const TInt KApaAppInfoArrayGranularity = 4;
    48 const TInt KApaAppInfoDesMaxLength=sizeof(TApaAppInfo);
    51 const TInt KApaAppInfoDesMaxLength = sizeof(TApaAppInfo);
    49 
    52 
    50 #if defined(__PROFILE)
    53 #if defined(__PROFILE)
    51 _LIT(KProfileAppForDocumentL, "AppForDocumentL - %d.%06d seconds");
    54 _LIT(KProfileAppForDocumentL, "AppForDocumentL - %d.%06d seconds");
    52 _LIT(KProfileAppForDocumentPassedByFileHandleL, "AppForDocumentPassedByFileHandleL - %d.%06d seconds");
    55 _LIT(KProfileAppForDocumentPassedByFileHandleL, "AppForDocumentPassedByFileHandleL - %d.%06d seconds");
    53 #endif
    56 #endif
    61 	virtual TInt ArrayItemCount() const=0;
    64 	virtual TInt ArrayItemCount() const=0;
    62 	virtual TInt ArrayItemSize() const=0;
    65 	virtual TInt ArrayItemSize() const=0;
    63 	virtual void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const=0;
    66 	virtual void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const=0;
    64 	};
    67 	};
    65 
    68 
    66 class TSizeArrayItemWriter : public MArrayItemWriter
    69 NONSHARABLE_CLASS(TSizeArrayItemWriter) : public MArrayItemWriter
    67 	{
    70 	{
    68 public:
    71 public:
    69 	inline TSizeArrayItemWriter(const CArrayFix<TSize>& aArray) : iArray(aArray) {}
    72 	inline TSizeArrayItemWriter(const CArrayFix<TSize>& aArray) : iArray(aArray) {}
    70 	
    73 public: // from MArrayItemWriter
    71 	// from MArrayItemWriter
       
    72 	TInt ArrayItemCount() const;
    74 	TInt ArrayItemCount() const;
    73 	TInt ArrayItemSize() const;
    75 	TInt ArrayItemSize() const;
    74 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
    76 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
    75 private:
    77 private:
    76 	const CArrayFix<TSize>& iArray;
    78 	const CArrayFix<TSize>& iArray;
    77 	};
    79 	};
    78 
    80 
    79 class TViewDataArrayItemWriter : public MArrayItemWriter
    81 NONSHARABLE_CLASS(TViewDataArrayItemWriter) : public MArrayItemWriter
    80 	{
    82 	{
    81 public:
    83 public:
    82 	inline TViewDataArrayItemWriter(const CArrayPtr<CApaAppViewData>& aArray) : iArray(aArray) {}
    84 	inline TViewDataArrayItemWriter(const CArrayPtr<CApaAppViewData>& aArray) : iArray(aArray) {}
    83 	
    85 public:	// from MArrayItemWriter
    84 	// from MArrayItemWriter
       
    85 	TInt ArrayItemCount() const;
    86 	TInt ArrayItemCount() const;
    86 	TInt ArrayItemSize() const;
    87 	TInt ArrayItemSize() const;
    87 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
    88 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
    88 private:
    89 private:
    89 	const CArrayPtr<CApaAppViewData>& iArray;
    90 	const CArrayPtr<CApaAppViewData>& iArray;
    90 	};
    91 	};
    91 
    92 
    92 class TDesCArrayItemWriter : public MArrayItemWriter
    93 NONSHARABLE_CLASS(TDesCArrayItemWriter) : public MArrayItemWriter
    93 	{
    94 	{
    94 public:
    95 public:
    95 	inline TDesCArrayItemWriter(const CDesCArray& aArray) : iArray(aArray) {}
    96 	inline TDesCArrayItemWriter(const CDesCArray& aArray) : iArray(aArray) {}
    96 	
    97 public:	// from MArrayItemWriter
    97 	// from MArrayItemWriter
       
    98 	TInt ArrayItemCount() const;
    98 	TInt ArrayItemCount() const;
    99 	TInt ArrayItemSize() const;
    99 	TInt ArrayItemSize() const;
   100 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
   100 	void WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const;
   101 private:
   101 private:
   102 	const CDesCArray& iArray;
   102 	const CDesCArray& iArray;
   103 	};
   103 	};
   104 
   104 
   105 
   105 NONSHARABLE_CLASS(CApaAppListServSession::CApaAppInfo) : public CBase
   106 class CApaAppListServSession::CApaAppInfo
       
   107 	{
   106 	{
   108 public:
   107 public:
   109 	CApaAppInfo();
   108 	CApaAppInfo();
   110 	~CApaAppInfo();
   109 	~CApaAppInfo();
   111 	void SetUid(const TUid aUid);
   110 	void SetUid(const TUid aUid);
   133 	{ return *iFullName; }
   132 	{ return *iFullName; }
   134 
   133 
   135 inline TUid CApaAppListServSession::CApaAppInfo::Uid() const
   134 inline TUid CApaAppListServSession::CApaAppInfo::Uid() const
   136 	{ return iUid; }
   135 	{ return iUid; }
   137 
   136 
       
   137 //
   138 // CApaAppListServSession
   138 // CApaAppListServSession
   139 
   139 //
   140 CApaAppListServSession* CApaAppListServSession::NewL(CApaAppListServer& aServer, RFs& aFs)
   140 
   141 	{
   141 CApaAppListServSession* CApaAppListServSession::NewL(RFs& aFs, CApaAppArcServer& aAppArcSrv, CApaAppList& aAppList)
   142 	CApaAppListServSession* self=new(ELeave) CApaAppListServSession(aServer, aFs);
   142 	{
       
   143 	CApaAppListServSession* self = new (ELeave) CApaAppListServSession(aFs, aAppArcSrv, aAppList);
   143 	CleanupStack::PushL(self);
   144 	CleanupStack::PushL(self);
   144 	self->ConstructL();
   145 	self->ConstructL();
   145 	CleanupStack::Pop(); // self
   146 	CleanupStack::Pop(self);
   146 	return self;
   147 	return self;
   147 	}
   148 	}
   148 
   149 
   149 CApaAppListServSession::CApaAppListServSession(CApaAppListServer& aServer, RFs& aFs)
   150 CApaAppListServSession::CApaAppListServSession(RFs& aFs, CApaAppArcServer& aAppArcSrv, CApaAppList& aAppList)
   150 	: CSession2(),
   151  : iFs(aFs), iAppArcSrv(aAppArcSrv), iAppList(aAppList), iApaAppInfoArray(KApaAppInfoArrayGranularity)
   151 	iServ(aServer),
   152 	{
   152 	iFs(aFs),
   153 
   153 	iMaxBufSize(KApaAppListServMaxBuffer),
   154 	}
   154 	iApaAppInfoArray(KApaAppInfoArrayGranularity),
       
   155 	iOpaqueData_pendingDispatchToClient(NULL)
       
   156 	{}
       
   157 
   155 
   158 void CApaAppListServSession::ConstructL()
   156 void CApaAppListServSession::ConstructL()
   159 	{
   157 	{
   160 	iFileRecognitionUtility = new (ELeave) CFileRecognitionUtility(iServ, iMaxBufSize, iFs);
   158 	iNonNativeApplicationsManager = CApsNonNativeApplicationsManager::NewL(iAppArcSrv,iFs);
   161 	iNonNativeApplicationsManager = CApsNonNativeApplicationsManager::NewL(iServ,iFs);
   159 	}
   162 	}
   160 	
   163 
   161 
   164 CApaAppListServSession::~CApaAppListServSession()
   162 CApaAppListServSession::~CApaAppListServSession()
   165 	{
   163 	{
   166 	delete iNonNativeApplicationsManager;
   164 	delete iNonNativeApplicationsManager;
   167 	delete iBuffer;
       
   168 	iApaAppInfoArray.ResetAndDestroy();
   165 	iApaAppInfoArray.ResetAndDestroy();
   169 	iApaAppInfoArray.Close();
   166 	iApaAppInfoArray.Close();
   170 	delete iFileRecognitionUtility;
   167 	}
   171 	delete iRecognitionResult;
   168 
   172 	delete iOpaqueData_pendingDispatchToClient;
   169 CApaAppList& CApaAppListServSession::AppList()
   173 	}
   170 	{
   174 
   171 	return iAppList;
   175 void CApaAppListServSession::ServiceL(const RMessage2& aMessage)
   172 	}
   176 	{
   173 
   177 	TBool completeMessage=ETrue;
   174 	
   178 	switch (aMessage.Function())
   175 void CApaAppListServSession::DoServiceL(const RMessage2& aMessage)
       
   176 	{
       
   177 	TBool completeMessage = ETrue;
       
   178 	const TInt opcode = aMessage.Function();
       
   179 	switch (opcode)
   179 		{
   180 		{
   180 	case ESetNotify:
   181 	case ESetNotify:
   181 		SetNotify(aMessage);
   182 		SetNotify(aMessage);
   182 		completeMessage=EFalse;
   183 		completeMessage=EFalse;
   183 		break;
   184 		break;
   217 		GetAppCapabilityL(aMessage);
   218 		GetAppCapabilityL(aMessage);
   218 		break;
   219 		break;
   219 	case EAppListServGetDefaultScreenNumber:
   220 	case EAppListServGetDefaultScreenNumber:
   220 		GetDefaultScreenNumberL(aMessage);
   221 		GetDefaultScreenNumberL(aMessage);
   221 		break;
   222 		break;
   222 	case EAppListServStartAppWithoutReturningThreadId:
       
   223 		StartAppL(aMessage,EFalse);
       
   224 		break;
       
   225 	case EAppListServStartAppReturningThreadId:
       
   226 		StartAppL(aMessage,ETrue);
       
   227 		break;
       
   228 	case EAppListServRecognizeData:
       
   229 		RecognizeDataL(aMessage);
       
   230 		break;
       
   231 	case EAppListServRecognizeDataPassedByFileHandle:
       
   232 		RecognizeDataPassedByFileHandleL(aMessage);
       
   233 		break;
       
   234 	case EAppListServRecognizeSpecificData:
       
   235 		RecognizeSpecificDataL(aMessage);
       
   236 		break;
       
   237 	case EAppListServRecognizeSpecificDataPassedByFileHandle:
       
   238 		RecognizeSpecificDataPassedByFileHandleL(aMessage);
       
   239 		break;
       
   240 	case EAppListServAppForDataType:
       
   241 		AppForDataTypeL(aMessage);
       
   242 		break;
       
   243 	case EAppListServStartDocument:
       
   244 		StartDocumentL(aMessage,EStart);
       
   245 		break;
       
   246 	case EAppListServStartDocumentByDataType:
       
   247 		StartDocumentL(aMessage,EStartByDataType);
       
   248 		break;
       
   249 	case EAppListServStartDocumentByUid:
       
   250 		StartDocumentL(aMessage,EStartByUid);
       
   251 		break;
       
   252 	case EAppListServCreateDocumentByUid:
       
   253 		StartDocumentL(aMessage,ECreateByUid);
       
   254 		break;
       
   255 	case EAppListServGetExecutableNameGivenDocument:
       
   256 		GetExecutableNameGivenDocumentL(aMessage);
       
   257 		break;
       
   258 	case EAppListServGetExecutableNameGivenDocumentPassedByFileHandle:
       
   259 		GetExecutableNameGivenDocumentPassedByFileHandleL(aMessage);
       
   260 		break;
       
   261 	case EAppListServGetExecutableNameGivenDataType:
       
   262 		GetExecutableNameGivenDataTypeL(aMessage);
       
   263 		break;
       
   264 	case EAppListServGetExecutableNameGivenAppUid:
       
   265 		GetExecutableNameGivenAppUidL(aMessage);
       
   266 		break;
       
   267 	case EAppListServGetOpaqueData:
       
   268 		GetOpaqueDataL(aMessage);
       
   269 		break;
       
   270 	case EAppListServGetNativeExecutableNameIfNonNative:
       
   271 		GetNativeExecutableNameIfNonNativeL(aMessage);
       
   272 		break;
       
   273 	case EAppListServAppIconByUid:
   223 	case EAppListServAppIconByUid:
   274 		IconForAppL(aMessage);
   224 		IconForAppL(aMessage);
   275 		break;
       
   276 	case EAppListServAppForDocument:
       
   277 		AppForDocumentL(aMessage, NULL);
       
   278 		break;
       
   279 	case EAppListServAppForDocumentPassedByFileHandle:
       
   280 		AppForDocumentPassedByFileHandleL(aMessage, NULL);
       
   281 		break;
       
   282 	case EAppListServGetConfidence:
       
   283 		GetConfidenceL(aMessage);
       
   284 		break;
       
   285 	case EAppListServSetConfidence:
       
   286 		SetConfidence(aMessage);
       
   287 		break;
       
   288 	case EAppListServGetBufSize:
       
   289 		GetBufSize(aMessage);
       
   290 		break;
       
   291 	case EAppListServSetBufSize:
       
   292 		SetBufSize(aMessage);
       
   293 		break;
       
   294 	case EAppListServGetDataTypesPhase1:
       
   295 		GetDataTypesCountL(aMessage);
       
   296 		break;
       
   297 	case EAppListServGetDataTypesPhase2:
       
   298 		GetDataTypesL(aMessage);
       
   299 		break;
   225 		break;
   300 	case ECancelNotify:
   226 	case ECancelNotify:
   301 		CancelNotify();
   227 		CancelNotify();
   302 		break;
   228 		break;
   303 	case EAppListServAppIconByUidAndSize:
   229 	case EAppListServAppIconByUidAndSize:
   330 	case EAppListServAppIconFileName:
   256 	case EAppListServAppIconFileName:
   331 		IconFileNameL(aMessage);
   257 		IconFileNameL(aMessage);
   332 		break;
   258 		break;
   333 	case EAppListServAppViewIconFileName:
   259 	case EAppListServAppViewIconFileName:
   334 		ViewIconFileNameL(aMessage);
   260 		ViewIconFileNameL(aMessage);
       
   261 		break;	
       
   262 	case EAppListServPrepareNonNativeApplicationsUpdates:
       
   263 		iNonNativeApplicationsManager->PrepareNonNativeApplicationsUpdatesL();
       
   264 		break;
       
   265 	case EAppListServRegisterNonNativeApplication:
       
   266 		iNonNativeApplicationsManager->RegisterNonNativeApplicationL(aMessage);
       
   267 		break;
       
   268 	case EAppListServDeregisterNonNativeApplication:
       
   269 		iNonNativeApplicationsManager->DeregisterNonNativeApplicationL(aMessage);
       
   270 		break;
       
   271 	case EAppListServCommitNonNativeApplications:
       
   272 		iNonNativeApplicationsManager->CommitNonNativeApplicationsUpdatesL(aMessage);
       
   273 		completeMessage=EFalse;
       
   274 		break;
       
   275 	case EAppListServRollbackNonNativeApplications:
       
   276 		iNonNativeApplicationsManager->RollbackNonNativeApplicationsUpdates();
       
   277 		break;
       
   278 	case EAppListServGetAppType:
       
   279 		GetAppTypeL(aMessage);
       
   280 		break;
       
   281 	case EAppListServForceRegistration:
       
   282 		ForceRegistrationL(aMessage);
       
   283 		completeMessage=EFalse;
       
   284 		break;
       
   285 	case EMatchesSecurityPolicy:
       
   286 		MatchesSecurityPolicyL(aMessage);
       
   287 		break;
       
   288 	case EAppListServSetAppShortCaption:
       
   289 		SetAppShortCaptionL(aMessage);
       
   290 		break;
       
   291 	case EDebugClearAppInfoArray:
       
   292 	#ifdef _DEBUG
       
   293 		iApaAppInfoArray.ResetAndDestroy();
       
   294 		iApaAppInfoArray.Compress();
       
   295 	#endif
       
   296 		break;
       
   297 	case EDebugAddFailingNonNativeApplicationsUpdate:
       
   298 	#ifdef _DEBUG
       
   299 		iNonNativeApplicationsManager->ForceFailInNonNativeApplicationsUpdatesL();
       
   300 	#endif
       
   301 		break;
       
   302 	case EDebugAddPanicingNonNativeApplicationsUpdate:
       
   303 	#ifdef _DEBUG
       
   304 		iNonNativeApplicationsManager->ForcePanicInNonNativeApplicationsUpdatesL();
       
   305 	#endif
       
   306 		break;
       
   307 	case EDebugAddRollbackPanicingNonNativeApplicationsUpdate:
       
   308 	#ifdef _DEBUG
       
   309 		iNonNativeApplicationsManager->ForcePanicInNonNativeApplicationsRollbackL();
       
   310 	#endif
       
   311 		break;
       
   312 	default:
       
   313 		aMessage.Panic(KApaPanicCli,EClientBadRequest);
       
   314 		break;
       
   315 		}
       
   316 		
       
   317 	if (completeMessage && !aMessage.IsNull())
       
   318 		aMessage.Complete(KErrNone);
       
   319 	}
       
   320 
       
   321 
       
   322 // CApaAppArcServSession
       
   323 
       
   324 CApaAppArcServSession* CApaAppArcServSession::NewL(CApaAppArcServer& aServer, RFs& aFs)
       
   325 	{
       
   326 	CApaAppArcServSession* self=new(ELeave) CApaAppArcServSession(aServer, aFs);
       
   327 	CleanupStack::PushL(self);
       
   328 	self->ConstructL();
       
   329 	CleanupStack::Pop(); // self
       
   330 	return self;
       
   331 	}
       
   332 
       
   333 CApaAppArcServSession::CApaAppArcServSession(CApaAppArcServer& aServer, RFs& aFs)
       
   334 	: CSession2(),
       
   335 	iServ(aServer),
       
   336 	iFs(aFs),
       
   337 	iMaxBufSize(KApaAppListServMaxBuffer),
       
   338 	iOpaqueData_pendingDispatchToClient(NULL)
       
   339 	{}
       
   340 
       
   341 void CApaAppArcServSession::ConstructL()
       
   342 	{
       
   343 	iAppListSession = CApaAppListServSession::NewL(iFs, iServ, iServ.AppList());
       
   344 	iFileRecognitionUtility = new (ELeave) CFileRecognitionUtility(iServ, iMaxBufSize, iFs);
       
   345 	}
       
   346 
       
   347 CApaAppArcServSession::~CApaAppArcServSession()
       
   348 	{
       
   349 	delete iAppListSession;
       
   350 	delete iBuffer;
       
   351 	delete iFileRecognitionUtility;
       
   352 	delete iRecognitionResult;
       
   353 	delete iOpaqueData_pendingDispatchToClient;
       
   354 	}
       
   355 
       
   356 void CApaAppArcServSession::ServiceL(const RMessage2& aMessage)
       
   357 	{
       
   358 	TBool completeMessage = ETrue;
       
   359 	switch (aMessage.Function())
       
   360 		{
       
   361 	case EAppListServStartAppWithoutReturningThreadId:
       
   362 		ASSERT(0);	// panic debug only
       
   363 		User::Leave(KErrNotSupported);
       
   364 		break;
       
   365 	case EAppListServStartAppReturningThreadId:
       
   366 		ASSERT(0);	// panic debug only
       
   367 		User::Leave(KErrNotSupported);
       
   368 		break;
       
   369 	case EAppListServRecognizeData:
       
   370 		RecognizeDataL(aMessage);
       
   371 		break;
       
   372 	case EAppListServRecognizeDataPassedByFileHandle:
       
   373 		RecognizeDataPassedByFileHandleL(aMessage);
       
   374 		break;
       
   375 	case EAppListServRecognizeSpecificData:
       
   376 		RecognizeSpecificDataL(aMessage);
       
   377 		break;
       
   378 	case EAppListServRecognizeSpecificDataPassedByFileHandle:
       
   379 		RecognizeSpecificDataPassedByFileHandleL(aMessage);
       
   380 		break;
       
   381 	case EAppListServAppForDataType:
       
   382 		AppForDataTypeL(aMessage);
       
   383 		break;
       
   384 	case EAppListServStartDocument:
       
   385 		ASSERT(0);	// panic debug only
       
   386 		User::Leave(KErrNotSupported);
       
   387 		break;
       
   388 	case EAppListServStartDocumentByDataType:
       
   389 		ASSERT(0);	// panic debug only
       
   390 		User::Leave(KErrNotSupported);
       
   391 		break;
       
   392 	case EAppListServStartDocumentByUid:
       
   393 		ASSERT(0);	// panic debug only
       
   394 		User::Leave(KErrNotSupported);
       
   395 		break;
       
   396 	case EAppListServCreateDocumentByUid:
       
   397 		ASSERT(0);	// panic debug only
       
   398 		User::Leave(KErrNotSupported);
       
   399 		break;
       
   400 	case EAppListServGetExecutableNameGivenDocument:
       
   401 		GetExecutableNameGivenDocumentL(aMessage);
       
   402 		break;
       
   403 	case EAppListServGetExecutableNameGivenDocumentPassedByFileHandle:
       
   404 		GetExecutableNameGivenDocumentPassedByFileHandleL(aMessage);
       
   405 		break;
       
   406 	case EAppListServGetExecutableNameGivenDataType:
       
   407 		GetExecutableNameGivenDataTypeL(aMessage);
       
   408 		break;
       
   409 	case EAppListServGetExecutableNameGivenAppUid:
       
   410 		GetExecutableNameGivenAppUidL(aMessage);
       
   411 		break;
       
   412 	case EAppListServGetOpaqueData:
       
   413 		GetOpaqueDataL(aMessage);
       
   414 		break;
       
   415 	case EAppListServGetNativeExecutableNameIfNonNative:
       
   416 		GetNativeExecutableNameIfNonNativeL(aMessage);
       
   417 		break;
       
   418 	case EAppListServAppForDocument:
       
   419 		AppForDocumentL(aMessage, NULL);
       
   420 		break;
       
   421 	case EAppListServAppForDocumentPassedByFileHandle:
       
   422 		AppForDocumentPassedByFileHandleL(aMessage, NULL);
       
   423 		break;
       
   424 	case EAppListServGetConfidence:
       
   425 		GetConfidenceL(aMessage);
       
   426 		break;
       
   427 	case EAppListServSetConfidence:
       
   428 		SetConfidence(aMessage);
       
   429 		break;
       
   430 	case EAppListServGetBufSize:
       
   431 		GetBufSize(aMessage);
       
   432 		break;
       
   433 	case EAppListServSetBufSize:
       
   434 		SetBufSize(aMessage);
       
   435 		break;
       
   436 	case EAppListServGetDataTypesPhase1:
       
   437 		GetDataTypesCountL(aMessage);
       
   438 		break;
       
   439 	case EAppListServGetDataTypesPhase2:
       
   440 		GetDataTypesL(aMessage);
   335 		break;
   441 		break;
   336 	case EAppListInsertDataMapping:
   442 	case EAppListInsertDataMapping:
   337 	case EAppListInsertDataMappingIfHigher:
   443 	case EAppListInsertDataMappingIfHigher:
   338 		InsertDataMappingL(aMessage);
   444 		InsertDataMappingL(aMessage);
   339 		break;
   445 		break;
   369 		RegisterNonNativeApplicationTypeL(aMessage);
   475 		RegisterNonNativeApplicationTypeL(aMessage);
   370 		break;
   476 		break;
   371 	case EAppListServDeregisterNonNativeApplicationType:
   477 	case EAppListServDeregisterNonNativeApplicationType:
   372 		DeregisterNonNativeApplicationTypeL(aMessage);
   478 		DeregisterNonNativeApplicationTypeL(aMessage);
   373 		break;
   479 		break;
   374 	case EAppListServPrepareNonNativeApplicationsUpdates:
       
   375 		iNonNativeApplicationsManager->PrepareNonNativeApplicationsUpdatesL();
       
   376 		break;
       
   377 	case EAppListServRegisterNonNativeApplication:
       
   378 		iNonNativeApplicationsManager->RegisterNonNativeApplicationL(aMessage);
       
   379 		break;
       
   380 	case EAppListServDeregisterNonNativeApplication:
       
   381 		iNonNativeApplicationsManager->DeregisterNonNativeApplicationL(aMessage);
       
   382 		break;
       
   383 	case EAppListServCommitNonNativeApplications:
       
   384 		iNonNativeApplicationsManager->CommitNonNativeApplicationsUpdatesL(aMessage);
       
   385 		completeMessage=EFalse;
       
   386 		break;
       
   387 	case EAppListServRollbackNonNativeApplications:
       
   388 		iNonNativeApplicationsManager->RollbackNonNativeApplicationsUpdates();
       
   389 		break;
       
   390 	case EAppListServGetAppType:
       
   391 		GetAppTypeL(aMessage);
       
   392 		break;
       
   393 	case EAppListServForceRegistration:
       
   394 		ForceRegistrationL(aMessage);
       
   395 		completeMessage=EFalse;
       
   396 		break;
       
   397 	case EAppListServPreferredBufSize:
   480 	case EAppListServPreferredBufSize:
   398 		aMessage.Complete(PreferredBufSize());
   481 		aMessage.Complete(PreferredBufSize());
   399 		break;
   482 		break;
   400 	case EAppListServRecognizeFiles:
   483 	case EAppListServRecognizeFiles:
   401 		RecognizeFilesL(aMessage);
   484 		RecognizeFilesL(aMessage);
   409 		break;
   492 		break;
   410 	case ECancelRecognizeFiles:
   493 	case ECancelRecognizeFiles:
   411 		CancelRecognizeFiles();
   494 		CancelRecognizeFiles();
   412 		break;
   495 		break;
   413 	case EAppListServRuleBasedLaunching:
   496 	case EAppListServRuleBasedLaunching:
   414 		RuleBasedLaunchingL(aMessage);
   497 		AquirePermissionToLaunchAppL(aMessage);
   415 		break;
       
   416 	case EMatchesSecurityPolicy:
       
   417 		MatchesSecurityPolicyL(aMessage);
       
   418 		break;
       
   419 	case EAppListServSetAppShortCaption:
       
   420 		SetAppShortCaptionL(aMessage);
       
   421 		break;
   498 		break;
   422 	case ENotifyOnDataMappingChange:
   499 	case ENotifyOnDataMappingChange:
   423 		NotifyOnDataMappingChange(aMessage);
   500 		NotifyOnDataMappingChange(aMessage);
   424 		completeMessage=EFalse;
   501 		completeMessage=EFalse;
   425 		break;
   502 		break;
   437 	#endif
   514 	#endif
   438 		break;
   515 		break;
   439 	case EDebugHeapFailNext:
   516 	case EDebugHeapFailNext:
   440 	#ifdef _DEBUG
   517 	#ifdef _DEBUG
   441 		__UHEAP_FAILNEXT(aMessage.Int0());
   518 		__UHEAP_FAILNEXT(aMessage.Int0());
   442 	#endif
       
   443 		break;
       
   444 	case EDebugClearAppInfoArray:
       
   445 	#ifdef _DEBUG
       
   446 		iApaAppInfoArray.ResetAndDestroy();
       
   447 		iApaAppInfoArray.Compress();
       
   448 	#endif
   519 	#endif
   449 		break;
   520 		break;
   450 	case EDebugFlushRecognitionCache:
   521 	case EDebugFlushRecognitionCache:
   451 	#ifdef _DEBUG
   522 	#ifdef _DEBUG
   452 		iServ.FlushRecognitionCache();
   523 		iServ.FlushRecognitionCache();
   461 	#ifdef _DEBUG
   532 	#ifdef _DEBUG
   462 		iServ.PerformOutstandingRecognizerUnloading();
   533 		iServ.PerformOutstandingRecognizerUnloading();
   463 		REComSession::FinalClose();
   534 		REComSession::FinalClose();
   464 	#endif
   535 	#endif
   465 		break;
   536 		break;
   466 	case EDebugAddFailingNonNativeApplicationsUpdate:
       
   467 	#ifdef _DEBUG
       
   468 		iNonNativeApplicationsManager->ForceFailInNonNativeApplicationsUpdatesL();
       
   469 	#endif
       
   470 		break;
       
   471 	case EDebugAddPanicingNonNativeApplicationsUpdate:
       
   472 	#ifdef _DEBUG
       
   473 		iNonNativeApplicationsManager->ForcePanicInNonNativeApplicationsUpdatesL();
       
   474 	#endif
       
   475 		break;
       
   476 	case EDebugAddRollbackPanicingNonNativeApplicationsUpdate:
       
   477 	#ifdef _DEBUG
       
   478 		iNonNativeApplicationsManager->ForcePanicInNonNativeApplicationsRollbackL();
       
   479 	#endif
       
   480 		break;
       
   481 	default:
   537 	default:
   482 		aMessage.Panic(KApaPanicCli,EClientBadRequest);
   538 		iAppListSession->DoServiceL(aMessage);
   483 		break;
   539 		return;
   484 		}
   540 		}
   485 		
   541 		
   486 	if (completeMessage && !aMessage.IsNull())
   542 	if (completeMessage && !aMessage.IsNull())
   487 		{
       
   488 		aMessage.Complete(KErrNone);
   543 		aMessage.Complete(KErrNone);
   489 		}
   544 	}
   490 	}
   545 
   491 void CApaAppListServSession::NotifyOnDataMappingChange(const RMessage2& aMessage)
   546 
       
   547 void CApaAppArcServSession::NotifyOnDataMappingChange(const RMessage2& aMessage)
   492 	{ 
   548 	{ 
   493 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
   549 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
   494 			{
   550 		aMessage.Panic(KApaPanicCli,ENotifyOnDataMappingChangeRequestOutstanding);
   495 			aMessage.Panic(KApaPanicCli,ENotifyOnDataMappingChangeRequestOutstanding);
       
   496 			}
       
   497 	else
   551 	else
   498 			{
   552 		iMessage_NotifyOnDataMappingChange=aMessage;
   499 			iMessage_NotifyOnDataMappingChange=aMessage;
   553 	}
   500 			}
   554 
   501 	}
   555 void CApaAppArcServSession::CancelNotifyOnDataMappingChange()
   502 void CApaAppListServSession::CancelNotifyOnDataMappingChange()
       
   503 	{
   556 	{
   504 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
   557 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
   505 			{
   558 		iMessage_NotifyOnDataMappingChange.Complete(KErrCancel);
   506 			iMessage_NotifyOnDataMappingChange.Complete(KErrCancel);
       
   507 			}
       
   508 	} //lint !e1762 Suppress member function could be made const
   559 	} //lint !e1762 Suppress member function could be made const
   509 
   560 
   510 
   561 
   511 TInt CApaAppListServSession::PreferredBufSize() const
   562 TInt CApaAppArcServSession::PreferredBufSize() const
   512 	{
   563 	{
   513 	TInt preferredBufferSize = 0;
   564 	TInt preferredBufferSize = 0;
   514 	TRAPD(err, preferredBufferSize = iServ.DataRecognizerPreferredBufSizeL());
   565 	TRAPD(err, preferredBufferSize = iServ.DataRecognizerPreferredBufSizeL());
   515 	return (err==KErrNone) ? Min(iMaxBufSize, preferredBufferSize) : iMaxBufSize;
   566 	return (err==KErrNone) ? Min(iMaxBufSize, preferredBufferSize) : iMaxBufSize;
   516 	}
   567 	}
   517 
   568 
   518 void CApaAppListServSession::RegisterNonNativeApplicationTypeL(const RMessage2& aMessage)
   569 void CApaAppArcServSession::RegisterNonNativeApplicationTypeL(const RMessage2& aMessage)
   519 	{
   570 	{
   520 	const TUid applicationType(TUid::Uid(aMessage.Int0()));
   571 	const TUid applicationType(TUid::Uid(aMessage.Int0()));
   521 	HBufC* const nativeExecutable=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
   572 	HBufC* const nativeExecutable=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
   522 	{TPtr nativeExecutable_asWritable(nativeExecutable->Des());
   573 	{TPtr nativeExecutable_asWritable(nativeExecutable->Des());
   523 	aMessage.ReadL(1, nativeExecutable_asWritable);}
   574 	aMessage.ReadL(1, nativeExecutable_asWritable);}
   524 	iServ.RegisterNonNativeApplicationTypeL(applicationType, *nativeExecutable);
   575 	iServ.RegisterNonNativeApplicationTypeL(applicationType, *nativeExecutable);
   525 	CleanupStack::PopAndDestroy(nativeExecutable);
   576 	CleanupStack::PopAndDestroy(nativeExecutable);
   526 	}
   577 	}
   527 
   578 
   528 void CApaAppListServSession::DeregisterNonNativeApplicationTypeL(const RMessage2& aMessage)
   579 void CApaAppArcServSession::DeregisterNonNativeApplicationTypeL(const RMessage2& aMessage)
   529 	{
   580 	{
   530 	const TUid applicationType(TUid::Uid(aMessage.Int0()));
   581 	const TUid applicationType(TUid::Uid(aMessage.Int0()));
   531 	iServ.DeregisterNonNativeApplicationTypeL(applicationType);
   582 	iServ.DeregisterNonNativeApplicationTypeL(applicationType);
   532 	}
   583 	}
   533 
   584 
   534 void CApaAppListServSession::GetAppTypeL(const RMessage2& aMessage)
   585 void CApaAppListServSession::GetAppTypeL(const RMessage2& aMessage)
   535 	{
   586 	{
   536 	TInt uid = aMessage.Int0();
   587 	TInt uid = aMessage.Int0();
   537 	CApaAppData* appData = iServ.AppList().AppDataByUid(TUid::Uid(uid));
   588 	CApaAppData* appData = iAppList.AppDataByUid(TUid::Uid(uid));
   538 	if (!appData)
   589 	if (!appData)
   539 		{
       
   540 		aMessage.Complete(KErrNotFound);
   590 		aMessage.Complete(KErrNotFound);
   541 		return;
   591 	else
   542 		}
   592 		{
   543 	TPckgBuf<TUid> typeUid(appData->NonNativeApplicationType());
   593 		TPckgBuf<TUid> typeUid(appData->NonNativeApplicationType());
   544 	aMessage.WriteL(1,typeUid);
   594 		aMessage.WriteL(1,typeUid);
   545 	aMessage.Complete(KErrNone);
   595 		aMessage.Complete(KErrNone);
       
   596 		}
   546 	}
   597 	}
   547 	
   598 	
   548 void CApaAppListServSession::ForceRegistrationL(const RMessage2& aMessage)
   599 void CApaAppListServSession::ForceRegistrationL(const RMessage2& aMessage)
   549 	{
   600 	{
   550 	TInt bufferSize = aMessage.GetDesLength(0);
   601 	TInt bufferSize = aMessage.GetDesLength(0);
   560 		{
   611 		{
   561 		TUint length = readStream.ReadUint32L();
   612 		TUint length = readStream.ReadUint32L();
   562 		HBufC* regFile = HBufC::NewLC(length);
   613 		HBufC* regFile = HBufC::NewLC(length);
   563   		TPtr ptr(regFile->Des());
   614   		TPtr ptr(regFile->Des());
   564   		readStream.ReadL(ptr, length);
   615   		readStream.ReadL(ptr, length);
   565 		iServ.AppList().AddForcedRegistrationL(regFile);
   616 		iAppList.AddForcedRegistrationL(*regFile);
   566 		CleanupStack::Pop(regFile);
   617 		CleanupStack::PopAndDestroy(regFile);
   567 		}
   618 		}
       
   619 	
   568 	CleanupStack::PopAndDestroy(&readStream);
   620 	CleanupStack::PopAndDestroy(&readStream);
   569 	
       
   570 	CleanupStack::PopAndDestroy(buffer);
   621 	CleanupStack::PopAndDestroy(buffer);
   571 	
   622 	
   572 	// Trigger a rescan, when rescan completes it will complete iNotifyOnScanCompleteMsg
   623 	// Trigger a rescan, when rescan completes it will complete iNotifyOnScanCompleteMsg
   573 	iNotifyOnScanCompleteMsg=aMessage;
   624 	iNotifyOnScanCompleteMsg=aMessage;
   574 	iServ.UpdateApps();
   625 	iAppArcSrv.UpdateAppsByForceRegistration();
   575 	}
   626 	}
   576 	
   627 	
   577 void CApaAppListServSession::AppForDocumentPassedByFileHandleL(const RMessage2& aMessage, const TUid* aServiceUid)
   628 void CApaAppArcServSession::AppForDocumentPassedByFileHandleL(const RMessage2& aMessage, const TUid* aServiceUid)
   578 	{
   629 	{
   579 #if defined(__PROFILE)
   630 #if defined(__PROFILE)
   580 	TProfile profile;
   631 	TProfile profile;
   581 	RDebug::ProfileReset(5,1);
   632 	RDebug::ProfileReset(5,1);
   582 	RDebug::ProfileStart(5);
   633 	RDebug::ProfileStart(5);
   595 	RDebug::Print(KProfileAppForDocumentPassedByFileHandleL,profile.iTime/1000000,profile.iTime%1000000);
   646 	RDebug::Print(KProfileAppForDocumentPassedByFileHandleL,profile.iTime/1000000,profile.iTime%1000000);
   596 	RDebug::ProfileStart(5);
   647 	RDebug::ProfileStart(5);
   597 #endif
   648 #endif
   598 	}
   649 	}
   599 
   650 
   600 void CApaAppListServSession::AppForDocumentL(const RMessage2& aMessage, const TUid* aServiceUid)
   651 /**
       
   652 Call the recognizer framework to find the MIME-type of the data buffer,
       
   653 then find and return the UID of the "best" application to handle that data.
       
   654 */
       
   655 void CApaAppArcServSession::AppForDocumentL(const RMessage2& aMessage, const TUid* aServiceUid)
   601 	{
   656 	{
   602 #if defined(__PROFILE)
   657 #if defined(__PROFILE)
   603 	TProfile profile;
   658 	TProfile profile;
   604 	RDebug::ProfileReset(5,1);
   659 	RDebug::ProfileReset(5,1);
   605 	RDebug::ProfileStart(5);
   660 	RDebug::ProfileStart(5);
   606 #endif
   661 #endif
   607 	HBufC* const fileName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
   662 
   608 	{TPtr fileName_asWritable(fileName->Des());
   663 	// Get the document file name from the IPC message
   609 	aMessage.ReadL(2,fileName_asWritable);}
   664 	HBufC* const docFileName = HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
   610 	HBufC8* const buffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(3)));
   665 	{TPtr docFileName_asWritable(docFileName->Des());
       
   666 	aMessage.ReadL(2, docFileName_asWritable);}
       
   667 	
       
   668 	// Get the data read from the document that will be used for recognition from the IPC message
       
   669 	HBufC8* const buffer = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(3)));
   611 	{TPtr8 buffer_asWritable(buffer->Des());
   670 	{TPtr8 buffer_asWritable(buffer->Des());
   612 	aMessage.ReadL(3,buffer_asWritable);}
   671 	aMessage.ReadL(3,buffer_asWritable);}
       
   672 	
       
   673 	// Call the recognizer framework to get the MIME-type
   613 	SReturnData_AppForDocument returnData;
   674 	SReturnData_AppForDocument returnData;
   614 	returnData.iDataType=iServ.RecognizeDataL(*fileName, *buffer).iDataType;
   675 	returnData.iDataType = iServ.RecognizeDataL(*docFileName, *buffer).iDataType;
   615 	returnData.iUid=(returnData.iDataType!=TDataType())? AppForDataTypeL(returnData.iDataType, aServiceUid): TUid::Null();
   676 	// If a MIME-type was found, get the UID of the "best" app registered for that type
       
   677 	returnData.iUid = (returnData.iDataType!=TDataType() ? AppForDataTypeL(returnData.iDataType, aServiceUid) : TUid::Null());
       
   678 	
   616 #if defined(__PROFILE)
   679 #if defined(__PROFILE)
   617 	RDebug::ProfileEnd(5);
   680 	RDebug::ProfileEnd(5);
   618 	RDebug::ProfileResult(&profile,5,1);
   681 	RDebug::ProfileResult(&profile,5,1);
   619 	RDebug::Print(KProfileAppForDocumentL,profile.iTime/1000000,profile.iTime%1000000);
   682 	RDebug::Print(KProfileAppForDocumentL,profile.iTime/1000000,profile.iTime%1000000);
   620 	RDebug::ProfileStart(5);
   683 	RDebug::ProfileStart(5);
   621 #endif
   684 #endif
   622 	CleanupStack::PopAndDestroy(2, fileName);
   685 	
       
   686 	// Send back the answer
       
   687 	CleanupStack::PopAndDestroy(2, docFileName);
   623 	aMessage.WriteL(0,TPckgC<SReturnData_AppForDocument>(returnData));
   688 	aMessage.WriteL(0,TPckgC<SReturnData_AppForDocument>(returnData));
   624 	}
   689 	}
   625 
   690 
   626 void CApaAppListServSession::GetConfidenceL(const RMessage2& aMessage)
   691 void CApaAppArcServSession::GetConfidenceL(const RMessage2& aMessage)
   627 // void GetAcceptedConfidence(TInt& aConfidence);
   692 // void GetAcceptedConfidence(TInt& aConfidence);
   628 	{
   693 	{
   629 	aMessage.WriteL(0,TPckgBuf<TInt>(iServ.DataRecognizer()->AcceptedConfidence()));
   694 	aMessage.WriteL(0,TPckgBuf<TInt>(iServ.MimeTypeRecognizer()->AcceptedConfidence()));
   630 	}
   695 	}
   631 
   696 
   632 void CApaAppListServSession::SetConfidence(const RMessage2& aMessage)
   697 void CApaAppArcServSession::SetConfidence(const RMessage2& aMessage)
   633 // SetAcceptedConfidence(TInt aConfidence);
   698 // SetAcceptedConfidence(TInt aConfidence);
   634 	{
   699 	{
   635 	__ASSERT_DEBUG(iServ.DataRecognizer(), Panic(EPanicNullPointer));
   700 	__ASSERT_DEBUG(iServ.MimeTypeRecognizer(), Panic(EPanicNullPointer));
   636 	iServ.DataRecognizer()->SetAcceptedConfidence(aMessage.Int0());
   701 	iServ.MimeTypeRecognizer()->SetAcceptedConfidence(aMessage.Int0());
   637 	}
   702 	}
   638 
   703 
   639 void CApaAppListServSession::GetBufSize(const RMessage2& aMessage)
   704 void CApaAppArcServSession::GetBufSize(const RMessage2& aMessage)
   640 // GetMaxDataBufSize(TInt& aBufSize);
   705 // GetMaxDataBufSize(TInt& aBufSize);
   641 	{
   706 	{
   642 	aMessage.Complete(iMaxBufSize);
   707 	aMessage.Complete(iMaxBufSize);
   643 	}
   708 	}
   644 
   709 
   645 void CApaAppListServSession::SetBufSize(const RMessage2& aMessage)
   710 void CApaAppArcServSession::SetBufSize(const RMessage2& aMessage)
   646 // SetMaxDataBufSize(TInt aBufSize);
   711 // SetMaxDataBufSize(TInt aBufSize);
   647 	{
   712 	{
   648 	iMaxBufSize=aMessage.Int0();
   713 	iMaxBufSize=aMessage.Int0();
   649 	}
   714 	}
   650 
   715 
   651 void CApaAppListServSession::GetDataTypesCountL(const RMessage2& aMessage)
   716 void CApaAppArcServSession::GetDataTypesCountL(const RMessage2& aMessage)
   652 	{
   717 	{
   653 	delete iBuffer;
   718 	delete iBuffer;
   654 	iBuffer=NULL;
   719 	iBuffer = NULL;
   655 	CDataTypeArray* const dataTypes=new(ELeave) CDataTypeArray(5);
   720 	CDataTypeArray* const dataTypes = new(ELeave) CDataTypeArray(5);
   656 	CleanupStack::PushL(dataTypes);
   721 	CleanupStack::PushL(dataTypes);
   657 	iServ.DataTypeL(*dataTypes);
   722 	iServ.DataTypeL(*dataTypes);
       
   723 	
   658 	TInt completionCode=0; // not KErrNone, as completion code of zero tells the client that zero data types were found
   724 	TInt completionCode=0; // not KErrNone, as completion code of zero tells the client that zero data types were found
   659 	if (dataTypes->Count()>0)
   725 	if (dataTypes->Count()>0)
   660 		{
   726 		{
   661 		CBufBase* const buffer=CBufFlat::NewL(sizeof(TDataType)); 
   727 		CBufBase* const buffer = CBufFlat::NewL(sizeof(TDataType)); 
   662 		CleanupStack::PushL(buffer); 
   728 		CleanupStack::PushL(buffer); 
   663 		RBufWriteStream writeStream(*buffer); 
   729 		RBufWriteStream writeStream(*buffer); 
   664 		writeStream<<*dataTypes; 
   730 		writeStream << *dataTypes; 
   665 		CleanupStack::Pop(buffer); 
   731 		CleanupStack::Pop(buffer); 
   666 		iBuffer=buffer;
   732 		iBuffer = buffer;
   667 		completionCode=iBuffer->Ptr(0).Size(); // number of bytes in buffer (not number of data types)
   733 		completionCode = iBuffer->Ptr(0).Size(); // number of bytes in buffer (not number of data types)
   668 		}
   734 		}
       
   735 	
   669 	CleanupStack::PopAndDestroy(dataTypes);
   736 	CleanupStack::PopAndDestroy(dataTypes);
   670 	aMessage.Complete(completionCode);
   737 	aMessage.Complete(completionCode);
   671 	}
   738 	}
   672 
   739 
   673 void CApaAppListServSession::GetDataTypesL(const RMessage2& aMessage)
   740 void CApaAppArcServSession::GetDataTypesL(const RMessage2& aMessage)
   674 // GetSupportedDataTypes(CDataTypeArray& aDataTypes);
   741 // GetSupportedDataTypes(CDataTypeArray& aDataTypes);
   675 	{
   742 	{
   676 	if(iBuffer==NULL)
   743 	if(!iBuffer)
   677 		{
       
   678 		aMessage.Panic(KApaPanicCli,ENoSupportedDataTypes);
   744 		aMessage.Panic(KApaPanicCli,ENoSupportedDataTypes);
   679 		}
       
   680 	else
   745 	else
   681 		{
   746 		{
   682 		aMessage.WriteL(0,iBuffer->Ptr(0));
   747 		aMessage.WriteL(0,iBuffer->Ptr(0));
   683 		delete iBuffer;
   748 		delete iBuffer;
   684 		iBuffer=NULL;
   749 		iBuffer=NULL;
   686 	}
   751 	}
   687 
   752 
   688 CApaAppData& CApaAppListServSession::FindAppInListL(TUid aUid)
   753 CApaAppData& CApaAppListServSession::FindAppInListL(TUid aUid)
   689 	{
   754 	{
   690 	TApaAppEntry dummy;
   755 	TApaAppEntry dummy;
   691 	CApaAppData* app=NULL;
   756 	CApaAppData* app = NULL;
   692 	if (!FindAppInList(app, dummy, aUid))
   757 	if (!FindAppInList(app, dummy, aUid))
   693 		{
       
   694 		User::Leave(KErrNotFound);
   758 		User::Leave(KErrNotFound);
   695 		}
   759 
   696 	return *app;
   760 	return *app;
   697 	}
   761 	}
   698 
   762 
   699 void CApaAppListServSession::SendArrayL(const MArrayItemWriter& aArrayItemWriter,const RMessage2& aMessage) const
   763 void CApaAppListServSession::SendArrayL(const MArrayItemWriter& aArrayItemWriter,const RMessage2& aMessage) const
   700 	{
   764 	{
   701 	const TInt sizeOfBuffer=aMessage.Int1();
   765 	const TInt sizeOfBuffer=aMessage.Int1();
   702 	const TInt arrayItemCount=aArrayItemWriter.ArrayItemCount();
   766 	const TInt arrayItemCount=aArrayItemWriter.ArrayItemCount();
   703 	const TInt sizeRequired=sizeof(TInt)+(arrayItemCount*aArrayItemWriter.ArrayItemSize());
   767 	const TInt sizeRequired=sizeof(TInt)+(arrayItemCount*aArrayItemWriter.ArrayItemSize());
   704 	__ASSERT_DEBUG(sizeRequired>0,User::Invariant());
   768 	ASSERT(sizeRequired > 0);
   705 	if (sizeRequired>sizeOfBuffer)
   769 	if (sizeRequired>sizeOfBuffer)
   706 		{
       
   707 		User::Leave(sizeRequired); // causes aMessage to complete with sizeRequired
   770 		User::Leave(sizeRequired); // causes aMessage to complete with sizeRequired
   708 		}
   771 
   709 	CBufFlat* const buf=CBufFlat::NewL(sizeRequired);
   772 	CBufFlat* const buf=CBufFlat::NewL(sizeRequired);
   710 	CleanupStack::PushL(buf);
   773 	CleanupStack::PushL(buf);
   711 	buf->ExpandL(0,sizeRequired);
   774 	buf->ExpandL(0,sizeRequired);
   712 	RBufWriteStream writeStream;
   775 	RBufWriteStream writeStream;
   713 	writeStream.Open(*buf);
   776 	writeStream.Open(*buf);
   714 	writeStream.WriteUint32L(arrayItemCount);
   777 	writeStream.WriteUint32L(arrayItemCount);
   715 	for (TInt i=0; i<arrayItemCount; ++i)
   778 	for (TInt i=0; i<arrayItemCount; ++i)
   716 		{
       
   717 		aArrayItemWriter.WriteArrayItemL(writeStream,i);
   779 		aArrayItemWriter.WriteArrayItemL(writeStream,i);
   718 		}
   780 
   719 	writeStream.CommitL();
   781 	writeStream.CommitL();
   720 	aMessage.WriteL(2,buf->Ptr(0));
   782 	aMessage.WriteL(2,buf->Ptr(0));
   721 	CleanupStack::PopAndDestroy(buf);
   783 	CleanupStack::PopAndDestroy(buf);
   722 	}
   784 	}
   723 
   785 
   724 void CApaAppListServSession::AppIconSizesL(const RMessage2& aMessage)
   786 void CApaAppListServSession::AppIconSizesL(const RMessage2& aMessage)
   725 	{
   787 	{
   726 	const TUid uid=TUid::Uid(aMessage.Int0());
   788 	const TUid uid=TUid::Uid(aMessage.Int0());
   727 	CApaAppData& app = FindAppInListL(uid);
   789 	const CApaAppData& app = FindAppInListL(uid);
   728 	if (app.NonMbmIconFile())
   790 	if (app.NonMbmIconFile())
   729 		{
       
   730 		User::Leave(KErrNotSupported);
   791 		User::Leave(KErrNotSupported);
   731 		}
       
   732 		
   792 		
   733 	CArrayFixFlat<TSize>* array = app.IconSizesL();
   793 	CArrayFixFlat<TSize>* array = app.IconSizesL();
   734 	CleanupStack::PushL(array);
   794 	CleanupStack::PushL(array);
   735 	TSizeArrayItemWriter arrayItemWriter(*array);		
   795 	TSizeArrayItemWriter arrayItemWriter(*array);		
   736 	SendArrayL(arrayItemWriter, aMessage);
   796 	SendArrayL(arrayItemWriter, aMessage);
   738 	}
   798 	}
   739 
   799 
   740 void CApaAppListServSession::AppViewsL(const RMessage2& aMessage)
   800 void CApaAppListServSession::AppViewsL(const RMessage2& aMessage)
   741 	{
   801 	{
   742 	const TUid uid=TUid::Uid(aMessage.Int0());
   802 	const TUid uid=TUid::Uid(aMessage.Int0());
   743 	CApaAppData& app = FindAppInListL(uid);
   803 	const CApaAppData& app = FindAppInListL(uid);
   744 	TViewDataArrayItemWriter arrayItemWriter(*app.Views());
   804 	TViewDataArrayItemWriter arrayItemWriter(*app.Views());
   745 	SendArrayL(arrayItemWriter,aMessage);
   805 	SendArrayL(arrayItemWriter,aMessage);
   746 	}
   806 	}
   747 
   807 
   748 void CApaAppListServSession::AppFileOwnershipInfoL(const RMessage2& aMessage)
   808 void CApaAppListServSession::AppFileOwnershipInfoL(const RMessage2& aMessage)
   749 	{
   809 	{
   750 	const TUid uid=TUid::Uid(aMessage.Int0());
   810 	const TUid uid=TUid::Uid(aMessage.Int0());
   751 	CApaAppData& app = FindAppInListL(uid);
   811 	const CApaAppData& app = FindAppInListL(uid);
   752 	TDesCArrayItemWriter arrayItemWriter(*app.OwnedFiles());
   812 	TDesCArrayItemWriter arrayItemWriter(*app.OwnedFiles());
   753 	SendArrayL(arrayItemWriter,aMessage);
   813 	SendArrayL(arrayItemWriter,aMessage);
   754 	}
   814 	}
   755 
   815 
   756 void CApaAppListServSession::NumberOfOwnDefinedIconsL(const RMessage2& aMessage)
   816 void CApaAppListServSession::NumberOfOwnDefinedIconsL(const RMessage2& aMessage)
       
   817 	{
       
   818 	const TUid uid = TUid::Uid(aMessage.Int0());
       
   819 	const CApaAppData& app = FindAppInListL(uid);
       
   820 	if (app.NonMbmIconFile())
       
   821 		User::Leave(KErrNotSupported);
       
   822 
       
   823 	TInt count, defaultIconsUsed;
       
   824 	app.GetIconInfo(count, defaultIconsUsed);
       
   825 	if (defaultIconsUsed)
       
   826 		count=0;
       
   827 
       
   828 	TPckgC<TInt> pckg(count); 
       
   829 	aMessage.Write(1,pckg);
       
   830 	}
       
   831 	
       
   832 void CApaAppListServSession::ApplicationLanguageL(const RMessage2& aMessage)
       
   833 	{
       
   834 	const TUid appUid = TUid::Uid(aMessage.Int0());
       
   835 	const CApaAppData& appData = FindAppInListL(appUid);
       
   836 
       
   837 	const TLanguage appLanguage = appData.ApplicationLanguage();
       
   838 	TPckgC<TLanguage> pckg(appLanguage); 
       
   839 	aMessage.Write(1,pckg);
       
   840 	}
       
   841 	
       
   842 
       
   843 void CApaAppListServSession::IconForViewBySizeL(const RMessage2& aMessage)
       
   844 	// Passes back handles to the icon and mask bitmaps for bitmap sharing 
       
   845 	{
       
   846 	TApaAppViewIconSizeData appViewIconSizeData;
       
   847 	{TPckg<TApaAppViewIconSizeData> appViewIconSizeData_asDescriptor(appViewIconSizeData);
       
   848 	aMessage.ReadL(0,appViewIconSizeData_asDescriptor);}
       
   849 	const CApaAppData& app = FindAppInListL(appViewIconSizeData.iAppUid);
       
   850 	
       
   851 	ASSERT(app.Views());
       
   852 	const CArrayPtr<CApaAppViewData>& viewDataArray = *app.Views();
       
   853 	CApaMaskedBitmap* icon = NULL;
       
   854 	const TInt count = viewDataArray.Count();
       
   855 	for (TInt ii=0; ii<count; ii++)
       
   856 		{
       
   857 		const CApaAppViewData& appViewData = *viewDataArray[ii];
       
   858 		if (appViewData.Uid() == appViewIconSizeData.iViewUid)
       
   859 			{
       
   860 			if (appViewData.NonMbmIconFile())
       
   861 				User::Leave(KErrNotSupported);
       
   862 
       
   863 			icon=appViewData.Icon(appViewIconSizeData.iSize);
       
   864 			break;
       
   865 			}
       
   866 		}
       
   867 		
       
   868 	if (!icon)
       
   869 		User::Leave(KErrNotFound);
       
   870 
       
   871 	SReturnData_ViewIconByUidAndSize returnData;
       
   872 	returnData.iIcon = icon->Handle();
       
   873 	returnData.iIconMask = icon->Mask()->Handle();
       
   874 	aMessage.WriteL(1,TPckgC<SReturnData_ViewIconByUidAndSize>(returnData));
       
   875 	}
       
   876 
       
   877 void CApaAppListServSession::IconForAppBySizeL(const RMessage2& aMessage)
       
   878 	{
       
   879 	const TUid uid=TUid::Uid(aMessage.Int0());
       
   880 	const TSize size(aMessage.Int1(),aMessage.Int2());
       
   881 	const CApaAppData& app=FindAppInListL(uid);
       
   882 
       
   883 	if (app.NonMbmIconFile())
       
   884 		User::Leave(KErrNotSupported);
       
   885 
       
   886 	CApaMaskedBitmap* const icon=app.Icon(size);
       
   887 	if (!icon)
       
   888 		User::Leave(KErrNotFound);
       
   889 
       
   890 	SReturnData_AppIconByUidAndSize returnData;
       
   891 	returnData.iIcon=icon->Handle();
       
   892 	returnData.iIconMask=icon->Mask()->Handle();
       
   893 	aMessage.WriteL(3,TPckgC<SReturnData_AppIconByUidAndSize>(returnData));
       
   894 	}
       
   895 
       
   896 void CApaAppListServSession::IconFileHandleForAppL(const RMessage2& aMessage)
   757 	{
   897 	{
   758 	const TUid uid=TUid::Uid(aMessage.Int0());
   898 	const TUid uid=TUid::Uid(aMessage.Int0());
   759 	TApaAppEntry entry;
   899 	TApaAppEntry entry;
   760 	CApaAppData* app=NULL;
   900 	CApaAppData* app=NULL;
   761 	if (!FindAppInList(app,entry,uid))
   901 	if (!FindAppInList(app,entry,uid))
   762 		{
       
   763 		User::Leave(KErrNotFound);
   902 		User::Leave(KErrNotFound);
   764 		}
   903 
   765 	if (app->NonMbmIconFile())
       
   766 		{
       
   767 		User::Leave(KErrNotSupported);
       
   768 		}
       
   769 	TInt count, defaultIconsUsed;
       
   770 	app->GetIconInfo(count, defaultIconsUsed);
       
   771 	if (defaultIconsUsed)
       
   772 		{
       
   773 		count=0;
       
   774 		}
       
   775 	TPckgC<TInt> pckg(count); 
       
   776 	aMessage.Write(1,pckg);
       
   777 	}
       
   778 	
       
   779 void CApaAppListServSession::ApplicationLanguageL(const RMessage2& aMessage)
       
   780 	{
       
   781 	const TUid appUid = TUid::Uid(aMessage.Int0());
       
   782 	TApaAppEntry appEntry;
       
   783 	CApaAppData* appData = NULL;
       
   784 	if (!FindAppInList(appData, appEntry, appUid))
       
   785 		{
       
   786 		User::Leave(KErrNotFound);
       
   787 		}
       
   788 	const TLanguage appLanguage = appData->ApplicationLanguage();
       
   789 	TPckgC<TLanguage> pckg(appLanguage); 
       
   790 	aMessage.Write(1,pckg);
       
   791 	}
       
   792 	
       
   793 
       
   794 void CApaAppListServSession::IconForViewBySizeL(const RMessage2& aMessage)
       
   795 	// Passes back handles to the icon and mask bitmaps for bitmap sharing 
       
   796 	{
       
   797 	TApaAppViewIconSizeData appViewIconSizeData;
       
   798 	{TPckg<TApaAppViewIconSizeData> appViewIconSizeData_asDescriptor(appViewIconSizeData);
       
   799 	aMessage.ReadL(0,appViewIconSizeData_asDescriptor);}
       
   800 	TApaAppEntry entry;
       
   801 	CApaAppData* app=NULL;
       
   802 	if (!FindAppInList(app,entry,appViewIconSizeData.iAppUid))
       
   803 		{
       
   804 		User::Leave(KErrNotFound);
       
   805 		}
       
   806 	ASSERT(app->Views());
       
   807 	const CArrayPtr<CApaAppViewData>& viewDataArray=*app->Views();
       
   808 	CApaMaskedBitmap* icon=NULL;
       
   809 	const TInt count=viewDataArray.Count();
       
   810 	for (TInt ii=0; ii<count; ii++)
       
   811 		{
       
   812 		const CApaAppViewData& appViewData=*viewDataArray[ii];
       
   813 		if (appViewData.Uid()==appViewIconSizeData.iViewUid)
       
   814 			{
       
   815 			if (appViewData.NonMbmIconFile())
       
   816 				{
       
   817 				User::Leave(KErrNotSupported);
       
   818 				}
       
   819 			icon=appViewData.Icon(appViewIconSizeData.iSize);
       
   820 			break;
       
   821 			}
       
   822 		}
       
   823 	if (icon==NULL)
       
   824 		{
       
   825 		User::Leave(KErrNotFound);
       
   826 		}
       
   827 	SReturnData_ViewIconByUidAndSize returnData;
       
   828 	returnData.iIcon=icon->Handle();
       
   829 	returnData.iIconMask=icon->Mask()->Handle();
       
   830 	aMessage.WriteL(1,TPckgC<SReturnData_ViewIconByUidAndSize>(returnData));
       
   831 	}
       
   832 
       
   833 void CApaAppListServSession::IconForAppBySizeL(const RMessage2& aMessage)
       
   834 	{
       
   835 	const TUid uid=TUid::Uid(aMessage.Int0());
       
   836 	const TSize size(aMessage.Int1(),aMessage.Int2());
       
   837 	TApaAppEntry entry;
       
   838 	CApaAppData* app=NULL;
       
   839 	if (!FindAppInList(app,entry,uid))
       
   840 		{
       
   841 		User::Leave(KErrNotFound);
       
   842 		}
       
   843 	if (app->NonMbmIconFile())
       
   844 		{
       
   845 		User::Leave(KErrNotSupported);
       
   846 		}
       
   847 	CApaMaskedBitmap* const icon=app->Icon(size);
       
   848 	if (icon==NULL)
       
   849 		{
       
   850 		User::Leave(KErrNotFound);
       
   851 		}
       
   852 	SReturnData_AppIconByUidAndSize returnData;
       
   853 	returnData.iIcon=icon->Handle();
       
   854 	returnData.iIconMask=icon->Mask()->Handle();
       
   855 	aMessage.WriteL(3,TPckgC<SReturnData_AppIconByUidAndSize>(returnData));
       
   856 
       
   857 	}
       
   858 
       
   859 void CApaAppListServSession::IconFileHandleForAppL(const RMessage2& aMessage)
       
   860 	{
       
   861 	const TUid uid=TUid::Uid(aMessage.Int0());
       
   862 	TApaAppEntry entry;
       
   863 	CApaAppData* app=NULL;
       
   864 	if (!FindAppInList(app,entry,uid))
       
   865 		{
       
   866 		User::Leave(KErrNotFound);
       
   867 		}
       
   868 	TPtrC iconFileName = app->IconFileName();
   904 	TPtrC iconFileName = app->IconFileName();
   869 	if (iconFileName.Length()==0)
   905 	if (iconFileName.Length()==0)
   870 		{
       
   871 		User::Leave(KErrNotFound);
   906 		User::Leave(KErrNotFound);
   872 		}
   907 
   873 	RFs fs;
   908 	RFs fs;
   874 	User::LeaveIfError(fs.Connect());
   909 	User::LeaveIfError(fs.Connect());
   875 	CleanupClosePushL(fs);
   910 	CleanupClosePushL(fs);
   876 	User::LeaveIfError(fs.ShareProtected());
   911 	User::LeaveIfError(fs.ShareProtected());
       
   912 
   877 	RFile file;
   913 	RFile file;
   878 	CleanupClosePushL(file);
   914 	CleanupClosePushL(file);
   879 	User::LeaveIfError(file.Open(fs, iconFileName, EFileShareReadersOnly));
   915 	User::LeaveIfError(file.Open(fs, iconFileName, EFileShareReadersOnly));
   880 	User::LeaveIfError(file.TransferToClient(aMessage, 1));
   916 	User::LeaveIfError(file.TransferToClient(aMessage, 1));
   881 	CleanupStack::PopAndDestroy(2, &fs); //file and fs
   917 	CleanupStack::PopAndDestroy(2, &fs); //file and fs
   884 void CApaAppListServSession::IconForAppL(const RMessage2& aMessage)
   920 void CApaAppListServSession::IconForAppL(const RMessage2& aMessage)
   885 // from GetAppIcon(TUid aAppUid, TInt aSideInPixels, CApaMaskedBitmap& aAppBitmap);
   921 // from GetAppIcon(TUid aAppUid, TInt aSideInPixels, CApaMaskedBitmap& aAppBitmap);
   886 // BUT!  It's interface is uid, side, icon handle, mask handle for bitmap sharing 
   922 // BUT!  It's interface is uid, side, icon handle, mask handle for bitmap sharing 
   887 // and avoiding IPC overhead
   923 // and avoiding IPC overhead
   888 	{
   924 	{
   889 	const TUid uid=TUid::Uid(aMessage.Int0());
   925 	const TUid uid = TUid::Uid(aMessage.Int0());
   890 	const TInt side=aMessage.Int1();
   926 	const CApaAppData& app = FindAppInListL(uid);
   891 	TApaAppEntry entry;
   927 
   892 	CApaAppData* app=NULL;
   928 	if (app.NonMbmIconFile())
   893 	if (!FindAppInList(app,entry,uid))
   929 		User::Leave(KErrNotSupported);
   894 		{
   930 	
       
   931 	const TInt side = aMessage.Int1();
       
   932 	CApaMaskedBitmap* const icon = app.Icon(side);
       
   933 	if (!icon)
   895 		User::Leave(KErrNotFound);
   934 		User::Leave(KErrNotFound);
   896 		}
   935 
   897 	if (app->NonMbmIconFile())
       
   898 		{
       
   899 		User::Leave(KErrNotSupported);
       
   900 		}
       
   901 	CApaMaskedBitmap* const icon=app->Icon(side);
       
   902 	if (icon==NULL)
       
   903 		{
       
   904 		User::Leave(KErrNotFound);
       
   905 		}
       
   906 	SReturnData_AppIconByUid returnData;
   936 	SReturnData_AppIconByUid returnData;
   907 	returnData.iIcon=icon->Handle();
   937 	returnData.iIcon = icon->Handle();
   908 	returnData.iIconMask=icon->Mask()->Handle();
   938 	returnData.iIconMask = icon->Mask()->Handle();
   909 	aMessage.WriteL(2,TPckgC<SReturnData_AppIconByUid>(returnData));
   939 	aMessage.WriteL(2,TPckgC<SReturnData_AppIconByUid>(returnData));
   910 	}
   940 	}
   911 
   941 
   912 void CApaAppListServSession::AppForDataTypeL(const RMessage2& aMessage)
   942 void CApaAppArcServSession::AppForDataTypeL(const RMessage2& aMessage)
   913 // from AppForDataType(const TDataType& aDataType, TUid& aAppUid);
   943 // from AppForDataType(const TDataType& aDataType, TUid& aAppUid);
   914 	{
   944 	{
   915 	if (sizeof(TDataType) != aMessage.GetDesLengthL(0))
   945 	if (sizeof(TDataType) != aMessage.GetDesLengthL(0))
   916 		{
   946 		{
   917 		//Leave with KErrArgument if client passes other than TDataType
   947 		//Leave with KErrArgument if client passes other than TDataType
   923 	TPckgBuf<TUid> uid_asDescriptor(AppForDataTypeL(dataType, NULL));
   953 	TPckgBuf<TUid> uid_asDescriptor(AppForDataTypeL(dataType, NULL));
   924 	aMessage.WriteL(1,uid_asDescriptor);
   954 	aMessage.WriteL(1,uid_asDescriptor);
   925 	aMessage.Complete(KErrNone);
   955 	aMessage.Complete(KErrNone);
   926 	}
   956 	}
   927 
   957 
   928 void CApaAppListServSession::AppForDataTypeAndServiceL(const RMessage2& aMessage)
   958 void CApaAppArcServSession::AppForDataTypeAndServiceL(const RMessage2& aMessage)
   929 	{
   959 	{
   930 	TDataType dataType;
   960 	TDataType dataType;
   931 	{TPckg<TDataType> dataType_asDescriptor(dataType);
   961 	{TPckg<TDataType> dataType_asDescriptor(dataType);
   932 	aMessage.ReadL(0,dataType_asDescriptor);}
   962 	aMessage.ReadL(0,dataType_asDescriptor);}
   933 	const TUid serviceUid=TUid::Uid(aMessage.Int1());
   963 	const TUid serviceUid=TUid::Uid(aMessage.Int1());
   934 	TPckgBuf<TUid> uid(AppForDataTypeL(dataType, &serviceUid));
   964 	TPckgBuf<TUid> uid(AppForDataTypeL(dataType, &serviceUid));
   935 	aMessage.WriteL(2,uid);
   965 	aMessage.WriteL(2,uid);
   936 	aMessage.Complete(KErrNone);
   966 	aMessage.Complete(KErrNone);
   937 	}
   967 	}
   938 
   968 
   939 TUid CApaAppListServSession::AppForDataTypeL(const TDataType& aDataType, const TUid* aServiceUid)
   969 TUid CApaAppArcServSession::AppForDataTypeL(const TDataType& aDataType, const TUid* aServiceUid)
   940 	{
   970 	{
   941 	// It is possible to register apps as datatype handlers with system priority,
   971 	// It is possible to register apps as datatype handlers with system priority,
   942 	// which means that they are not overridable by user mappings.
   972 	// which means that they are not overridable by user mappings.
   943 	// So search the list of apps for a datahandler and get the associated
   973 	// So search the list of apps for a datahandler and get the associated
   944 	// priority
   974 	// priority
   945 	TUid uid;
   975 	 
   946 	TInt priority;
   976 	TInt priority = KDataTypePriorityNormal;
   947 	uid=AppList().PreferredDataHandlerL(aDataType, aServiceUid, priority);
   977 	TUid uid = iAppListSession->AppList().PreferredDataHandlerL(aDataType, aServiceUid, priority);
   948 	if (priority == KDataTypePrioritySystem)
   978 	if (priority == KDataTypePrioritySystem)
   949 		{
   979 		return uid;	// We have found a handler with system priority
   950 		// We have found a handler with system priority
       
   951 		return uid;
       
   952 		}
       
   953 		
   980 		
   954 	// No handler with system priority so see if there is a user mapping
   981 	// No handler with system priority so see if there is a user mapping
   955 	TUid userUid = KNullUid;
   982 	TUid userUid = KNullUid;
   956 	if (aServiceUid)
   983 	if (aServiceUid)
   957 		{
   984 		iServ.GetAppForMimeType(aDataType,*aServiceUid,userUid);
   958 		iServ.GetAppByDataType(aDataType,*aServiceUid,userUid);
       
   959 		}
       
   960 	else
   985 	else
   961 		{
   986 		iServ.GetAppForMimeType(aDataType,userUid);
   962 		iServ.GetAppByDataType(aDataType,userUid);
   987 
   963 		}
       
   964 	TApaAppEntry entry;
   988 	TApaAppEntry entry;
   965 	CApaAppData* app=NULL;
   989 	const CApaAppData* app = NULL;
   966 	if ((userUid.iUid!=0) && FindAppInList(app,entry,userUid))
   990 	if (userUid.iUid && iAppListSession->FindAppInList(app,entry,userUid))
   967 		{
   991 		return userUid;	// The user mapping is valid
   968 		// The user mapping is valid
       
   969 		return userUid;
       
   970 		}
       
   971 		
   992 		
   972 	// A user mapping was not found or is invalid so try to use
   993 	// A user mapping was not found or is invalid so try to use
   973 	// the uid returned by PreferredDataHandlerL.
   994 	// the uid returned by PreferredDataHandlerL.
   974 	if (uid.iUid==0 && aDataType.IsNative())
   995 	if (!uid.iUid && aDataType.IsNative())
   975 		{
   996 		uid = aDataType.Uid();
   976 		uid=aDataType.Uid();
   997 
   977 		}
       
   978 	return uid;
   998 	return uid;
   979 	}
   999 	}
   980 
  1000 
   981 void CApaAppListServSession::InsertDataMappingL(const RMessage2& aMessage)
  1001 void CApaAppArcServSession::InsertDataMappingL(const RMessage2& aMessage)
   982 	{
  1002 	{
   983 	TPckgBuf<TDataType> dataType;
  1003 	TPckgBuf<TDataType> dataType;
   984 	aMessage.ReadL(0, dataType);
  1004 	aMessage.ReadL(0, dataType);
   985 	TDataTypePriority priority = aMessage.Int1();
  1005 	TDataTypePriority priority = aMessage.Int1();
   986 	const TUid appUid = { aMessage.Int2() };
  1006 	const TUid appUid = { aMessage.Int2() };
   987 
  1007 
   988 	if(priority>KDataTypeUnTrustedPriorityThreshold || priority == KDataTypePrioritySystem ) 
  1008 	if(priority>KDataTypeUnTrustedPriorityThreshold || priority == KDataTypePrioritySystem ) 
   989 	   {   
  1009 	   {   
   990 	   CApaAppData* appData = AppList().AppDataByUid(appUid);
  1010 	   CApaAppData* appData = iAppListSession->AppList().AppDataByUid(appUid);
   991 	   if( appData )	
  1011 	   if( appData )	
   992 		  {
  1012 		  {
   993           TBool hasWriteDeviceDataCap( EFalse );
  1013           TBool hasWriteDeviceDataCap( EFalse );
   994           TBool isSidTrusted( EFalse );
  1014           TBool isSidTrusted( EFalse );
   995           
  1015           
  1005                   priority = KDataTypePriorityNormal;
  1025                   priority = KDataTypePriorityNormal;
  1006                   }
  1026                   }
  1007               }
  1027               }
  1008           else
  1028           else
  1009               {
  1029               {
  1010               TPtrC registrationFilePath = appData->RegistrationFileName ( );
  1030               TPtrC registrationFilePath = appData->RegistrationFileName();
  1011               TInt match = registrationFilePath.MatchF (
  1031               TInt match = registrationFilePath.MatchF (
  1012                                           KLitPathForUntrustedRegistrationResourceFiles );
  1032                                           KLitPathForUntrustedRegistrationResourceFiles );
  1013               //Check if registration file is in path for untrusted apps 
  1033               //Check if registration file is in path for untrusted apps 
  1014               //and its SID is untrusted
  1034               //and its SID is untrusted
  1015               if (match != KErrNotFound && !isSidTrusted )
  1035               if (match != KErrNotFound && !isSidTrusted )
  1025               //if the application is not present in the applist 
  1045               //if the application is not present in the applist 
  1026               //then the priority will be reduced to Threshold
  1046               //then the priority will be reduced to Threshold
  1027               priority = KDataTypeUnTrustedPriorityThreshold;
  1047               priority = KDataTypeUnTrustedPriorityThreshold;
  1028 		  }
  1048 		  }
  1029 	   }
  1049 	   }
       
  1050 
  1030 	const TUid serviceUid = { aMessage.Int3() };
  1051 	const TUid serviceUid = { aMessage.Int3() };
  1031 	if(aMessage.Function() == EAppListInsertDataMappingIfHigher)
  1052 	if(aMessage.Function() == EAppListInsertDataMappingIfHigher)
  1032 		{
  1053 		{
  1033 		const TBool response = iServ.InsertAndStoreIfHigherL(dataType(), priority, appUid);
  1054 		const TBool response = iServ.InsertAndStoreIfHigherL(dataType(), priority, appUid);
  1034 		aMessage.WriteL(3, TPckgC<TBool>(response));
  1055 		aMessage.WriteL(3, TPckgC<TBool>(response));
  1035 
       
  1036 		}
  1056 		}
  1037 	else
  1057 	else
  1038 		{
       
  1039 		iServ.InsertAndStoreDataMappingL(dataType(), priority, appUid, serviceUid);
  1058 		iServ.InsertAndStoreDataMappingL(dataType(), priority, appUid, serviceUid);
  1040 		}
  1059 	}
  1041 	}
  1060 
  1042 
  1061 void CApaAppArcServSession::DeleteDataMappingL(const RMessage2& aMessage)
  1043 void CApaAppListServSession::DeleteDataMappingL(const RMessage2& aMessage)
       
  1044 	{
  1062 	{
  1045 	TPckgBuf<TDataType> dataType;
  1063 	TPckgBuf<TDataType> dataType;
  1046 	aMessage.ReadL(0, dataType);
  1064 	aMessage.ReadL(0, dataType);
  1047 	const TUid serviceUid = { aMessage.Int1() };
  1065 	const TUid serviceUid = { aMessage.Int1() };
  1048 	TUid uid;
  1066 	TUid uid;
  1049 	iServ.GetAppByDataType(dataType(),serviceUid,uid);
  1067 	iServ.GetAppForMimeType(dataType(),serviceUid,uid);
  1050 	if (uid != KNullUid)
  1068 	if (uid != KNullUid)
  1051 		{
  1069 		{
  1052 		// TypeStore doesn't support deletion of an inexistent mapping
  1070 		// TypeStore doesn't support deletion of an inexistent mapping
  1053 		iServ.DeleteAndStoreDataMappingL(dataType(), serviceUid);
  1071 		iServ.DeleteAndStoreDataMappingL(dataType(), serviceUid);
  1054 		aMessage.Complete(KErrNone);
  1072 		aMessage.Complete(KErrNone);
  1055 		}
  1073 		}
  1056 	else
  1074 	else
  1057 		{
       
  1058 		aMessage.Complete(KErrNotFound);
  1075 		aMessage.Complete(KErrNotFound);
  1059 		}
  1076 	}
  1060 	}
  1077 	
  1061 	
  1078 void CApaAppArcServSession::GetAppByDataTypeL(const RMessage2& aMessage) const
  1062 void CApaAppListServSession::GetAppByDataTypeL(const RMessage2& aMessage) const
       
  1063 	{
  1079 	{
  1064 	TPckgBuf<TDataType> dataType;
  1080 	TPckgBuf<TDataType> dataType;
  1065 	aMessage.ReadL(0,dataType);
  1081 	aMessage.ReadL(0,dataType);
  1066 	const TUid serviceUid = { aMessage.Int1() };
  1082 	const TUid serviceUid = { aMessage.Int1() };
  1067 	TUid uid;
  1083 	TUid uid;
  1068 	iServ.GetAppByDataType(dataType(),serviceUid,uid);
  1084 	iServ.GetAppForMimeType(dataType(),serviceUid,uid);
  1069 	TPckgC<TUid> uidpckg(uid);
  1085 	TPckgC<TUid> uidpckg(uid);
  1070 	aMessage.WriteL(2,uidpckg);
  1086 	aMessage.WriteL(2,uidpckg);
  1071 	aMessage.Complete(KErrNone);
  1087 	aMessage.Complete(KErrNone);
  1072 	}
  1088 	}
  1073 
  1089 
  1074 void CApaAppListServSession::StartDocumentL(const RMessage2& aMessage,TAppListDocumentStart aStartType)
  1090 void CApaAppArcServSession::GetExecutableNameGivenDocumentL(const RMessage2& aMessage)
  1075 // from StartDocument(const TDesC& aFileName, TThreadId& aId, TLaunchType aLaunchType);
       
  1076 // from StartDocument(const TDesC& aFileName, const TDataType& aDataType, TThreadId& aId, TLaunchType aLaunchType);
       
  1077 // from StartDocument(const TDesC& aFileName, TUid aAppUid, TThreadId& aId, TLaunchType aLaunchType);
       
  1078 // from CreateDocument(const TDesC& aFileName, TUid aAppUid, TThreadId& aId, TLaunchType aLaunchType);
       
  1079 // This method needs to open the file, mime type it then launch it.
       
  1080 	{
       
  1081 	HBufC* const fileName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
       
  1082 	{TPtr fileName_asWritable(fileName->Des());
       
  1083 	aMessage.ReadL(1,fileName_asWritable);}
       
  1084 
       
  1085 	TUid uid;
       
  1086 	if ((aStartType==EStartByUid) || (aStartType==ECreateByUid))
       
  1087 		{
       
  1088 		uid.iUid=aMessage.Int2();
       
  1089 		}
       
  1090 	else
       
  1091 		{
       
  1092 		TDataType* const dataType=new(ELeave) TDataType();
       
  1093 		CleanupStack::PushL(dataType);
       
  1094 		if (aStartType==EStart)
       
  1095 			{
       
  1096 			HBufC8* const buffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
       
  1097 			{TPtr8 buffer_asWritable(buffer->Des());
       
  1098 			aMessage.ReadL(2,buffer_asWritable);}
       
  1099 			*dataType=iServ.RecognizeDataL(*fileName, *buffer).iDataType;
       
  1100 			CleanupStack::PopAndDestroy(buffer);
       
  1101 			}
       
  1102 		else
       
  1103 			{
       
  1104 			__ASSERT_DEBUG(aStartType==EStartByDataType,User::Invariant());
       
  1105 			TPckg<TDataType> dataType_asDescriptor(*dataType);
       
  1106 			aMessage.ReadL(2,dataType_asDescriptor);
       
  1107 			}
       
  1108 		uid=AppForDataTypeL(*dataType, NULL);
       
  1109 		CleanupStack::PopAndDestroy(dataType);
       
  1110 		}
       
  1111 	const TThreadId threadId=StartDocumentL(*fileName,uid,(aStartType==ECreateByUid)? EApaCommandCreate: EApaCommandOpen);
       
  1112 	CleanupStack::PopAndDestroy(fileName);
       
  1113 	aMessage.WriteL(0, TPckgC<TThreadId>(threadId));
       
  1114 	}
       
  1115 
       
  1116 TThreadId CApaAppListServSession::StartDocumentL(const TDesC& aFileName, TUid aUid, TApaCommand aCommand)
       
  1117 // Launch the document of aFileName with the app with Uid aUid
       
  1118 	{
       
  1119 	CApaAppData* app=NULL;
       
  1120 	CApaFileRecognizerType* type=NULL;
       
  1121 	TApaAppEntry entry;
       
  1122 	const TBool findApp=FindAppInList(app,entry,aUid);
       
  1123 	if (findApp)
       
  1124 	    {
       
  1125 	    if (app->RegistrationFileUsed())
       
  1126 			{
       
  1127 			TApaAppCapabilityBuf buf;
       
  1128 			app->Capability(buf);
       
  1129 	 		if (((buf().iEmbeddability == TApaAppCapability::EEmbeddableOnly) || (buf().iEmbeddability == TApaAppCapability::EEmbeddableUiNotStandAlone)) && !(buf().iAttributes & TApaAppCapability::EBuiltAsDll))
       
  1130 	              {
       
  1131 				   User::Leave(KErrNotSupported);		
       
  1132                   }
       
  1133 	 		}
       
  1134 	    }
       
  1135 
       
  1136 	if (!findApp || aUid.iUid==0)
       
  1137 		{
       
  1138 		// if we can't bind the type from the Mime type stuff then use the old scheme
       
  1139 		TRAP_IGNORE(type=FileRecognizer()->RecognizeFileL(aFileName));
       
  1140 		}
       
  1141 	else
       
  1142 		{
       
  1143 		if (findApp)
       
  1144 			{
       
  1145 			TRAP_IGNORE(type=FileRecognizer()->RecognizeFileL(entry.iFullName));
       
  1146 			}
       
  1147 		}
       
  1148 	if (!type)
       
  1149 		{
       
  1150 		User::Leave(KErrNotFound);
       
  1151 		}
       
  1152 	if (aFileName.Length()==0)
       
  1153 		{
       
  1154 		return type->RunL(EApaCommandRun,NULL,NULL);
       
  1155 		}
       
  1156 	return type->RunL(aCommand,&aFileName,NULL);
       
  1157 	}
       
  1158 
       
  1159 void CApaAppListServSession::GetExecutableNameGivenDocumentL(const RMessage2& aMessage)
       
  1160 	{
  1091 	{
  1161 	HBufC* const name=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
  1092 	HBufC* const name=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
  1162 	{TPtr name_asWritable(name->Des());
  1093 	{TPtr name_asWritable(name->Des());
  1163 	aMessage.ReadL(2, name_asWritable);}
  1094 	aMessage.ReadL(2, name_asWritable);}
  1164 	HBufC8* const buffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(3)));
  1095 	HBufC8* const buffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(3)));
  1169 
  1100 
  1170 	const TUid appUid(AppForDataTypeL(dataType, NULL));
  1101 	const TUid appUid(AppForDataTypeL(dataType, NULL));
  1171 	GetExecutableNameL(aMessage, appUid);
  1102 	GetExecutableNameL(aMessage, appUid);
  1172 	}
  1103 	}
  1173 
  1104 
  1174 void CApaAppListServSession::GetExecutableNameGivenDocumentPassedByFileHandleL(const RMessage2& aMessage)
  1105 void CApaAppArcServSession::GetExecutableNameGivenDocumentPassedByFileHandleL(const RMessage2& aMessage)
  1175 	{
  1106 	{
  1176 	RFile file;
  1107 	RFile file;
  1177 	CleanupClosePushL(file);
  1108 	CleanupClosePushL(file);
  1178 	User::LeaveIfError(file.AdoptFromClient(aMessage, 2, 3));
  1109 	User::LeaveIfError(file.AdoptFromClient(aMessage, 2, 3));
  1179 	const TDataType dataType(iServ.RecognizeDataL(file, PreferredBufSize()).iDataType);
  1110 	const TDataType dataType(iServ.RecognizeDataL(file, PreferredBufSize()).iDataType);
  1181 
  1112 
  1182 	const TUid appUid(AppForDataTypeL(dataType, NULL));
  1113 	const TUid appUid(AppForDataTypeL(dataType, NULL));
  1183 	GetExecutableNameL(aMessage, appUid);
  1114 	GetExecutableNameL(aMessage, appUid);
  1184 	}
  1115 	}
  1185 
  1116 
  1186 void CApaAppListServSession::GetExecutableNameGivenDataTypeL(const RMessage2& aMessage)
  1117 void CApaAppArcServSession::GetExecutableNameGivenDataTypeL(const RMessage2& aMessage)
  1187 	{
  1118 	{
  1188 	if (sizeof(TDataType) != aMessage.GetDesLengthL(2))
  1119 	if (sizeof(TDataType) != aMessage.GetDesLengthL(2))
  1189 		{
  1120 		{
  1190 		//Leave with KErrArgument if client passes other than TDataType
  1121 		//Leave with KErrArgument if client passes other than TDataType
  1191 		User::Leave(KErrArgument);
  1122 		User::Leave(KErrArgument);
  1195 	aMessage.ReadL(2, dataType_asDescriptor);}
  1126 	aMessage.ReadL(2, dataType_asDescriptor);}
  1196 	const TUid appUid(AppForDataTypeL(dataType, NULL));
  1127 	const TUid appUid(AppForDataTypeL(dataType, NULL));
  1197 	GetExecutableNameL(aMessage, appUid);
  1128 	GetExecutableNameL(aMessage, appUid);
  1198 	}
  1129 	}
  1199 
  1130 
  1200 void CApaAppListServSession::GetExecutableNameGivenAppUidL(const RMessage2& aMessage)
  1131 void CApaAppArcServSession::GetExecutableNameGivenAppUidL(const RMessage2& aMessage)
  1201 	{
  1132 	{
  1202 	const TUid appUid(TUid::Uid(aMessage.Int2()));
  1133 	const TUid appUid(TUid::Uid(aMessage.Int2()));
  1203 	GetExecutableNameL(aMessage, appUid);
  1134 	GetExecutableNameL(aMessage, appUid);
  1204 	}
  1135 	}
  1205 
  1136 
  1206 void CApaAppListServSession::GetExecutableNameL(const RMessage2& aMessage, TUid aAppUid)
  1137 void CApaAppArcServSession::GetExecutableNameL(const RMessage2& aMessage, TUid aAppUid)
  1207 	{
  1138 	{
  1208 	CApaAppData* appData=NULL;
  1139 	const CApaAppData* appData=NULL;
  1209 	TApaAppEntry entry;
  1140 	TApaAppEntry entry;
  1210 	if (!FindAppInList(appData, entry, aAppUid))
  1141 	if (!iAppListSession->FindAppInList(appData, entry, aAppUid))
  1211 		{
  1142 		User::Leave(iAppListSession->AppList().IsFirstScanComplete() ? KErrNotFound : RApaLsSession::EAppListInvalid);
  1212 		User::Leave(AppList().IsFirstScanComplete() ?
  1143 
  1213 					KErrNotFound : RApaLsSession::EAppListInvalid);
       
  1214 		}
       
  1215 	const TDesC& executableName(entry.iFullName);
  1144 	const TDesC& executableName(entry.iFullName);
  1216 	if (executableName.Length() == 0)
  1145 	if (!executableName.Length())
  1217 		{
       
  1218 		User::Leave(KErrNotFound);
  1146 		User::Leave(KErrNotFound);
  1219 		}
  1147 
  1220 	aMessage.WriteL(1, executableName); // the "logical" executable name - for non-native applications this is the name of the MIDlet, Python script, etc
  1148 	aMessage.WriteL(1, executableName); // the "logical" executable name - for non-native applications this is the name of the MIDlet, Python script, etc
  1221 	WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(aMessage, 0, *appData);
  1149 	WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(aMessage, 0, *appData);
  1222 	}
  1150 	}
  1223 
  1151 
  1224 void CApaAppListServSession::GetNativeExecutableNameIfNonNativeL(const RMessage2& aMessage)
  1152 void CApaAppArcServSession::GetNativeExecutableNameIfNonNativeL(const RMessage2& aMessage)
  1225 	{
  1153 	{
  1226 	RBuf logicalExecutableName;
  1154 	RBuf logicalExecutableName;
  1227 	logicalExecutableName.CreateL(User::LeaveIfError(aMessage.GetDesLength(1)));
  1155 	logicalExecutableName.CreateL(User::LeaveIfError(aMessage.GetDesLength(1)));
  1228 	CleanupClosePushL(logicalExecutableName);
  1156 	CleanupClosePushL(logicalExecutableName);
  1229 	aMessage.ReadL(1, logicalExecutableName);
  1157 	aMessage.ReadL(1, logicalExecutableName);
  1230 	CApaAppData* const appData=AppList().AppDataByFileName(logicalExecutableName);
  1158 	CApaAppData* const appData=iAppListSession->AppList().AppDataByFileName(logicalExecutableName);
  1231 	if (appData!=NULL)
  1159 	if (appData!=NULL)
  1232 		{
       
  1233 		WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(aMessage, 0, *appData);
  1160 		WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(aMessage, 0, *appData);
  1234 		}
  1161 
  1235 	CleanupStack::PopAndDestroy(&logicalExecutableName);
  1162 	CleanupStack::PopAndDestroy(&logicalExecutableName);
  1236 	}
  1163 	}
  1237 
  1164 
  1238 void CApaAppListServSession::WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(const RMessage2& aMessage, TInt aMessageSlotForNativeExecutable, const CApaAppData& aAppData)
  1165 void CApaAppArcServSession::WriteNativeExecutableIfNonNativeAndPrepareForClientRetrievalOfOpaqueDataL(const RMessage2& aMessage, TInt aMessageSlotForNativeExecutable, const CApaAppData& aAppData)
  1239 	{
  1166 	{
  1240 	HBufC8* opaqueData=NULL;
  1167 	HBufC8* opaqueData=NULL;
  1241 	const TPtrC8 opaqueData_asTPtrC8(aAppData.OpaqueData());
  1168 	const TPtrC8 opaqueData_asTPtrC8(aAppData.OpaqueData());
  1242 	const TInt lengthOfOpaqueData(opaqueData_asTPtrC8.Length());
  1169 	const TInt lengthOfOpaqueData(opaqueData_asTPtrC8.Length());
  1243 	if (lengthOfOpaqueData>0)
  1170 	if (lengthOfOpaqueData>0)
  1244 		{
       
  1245 		opaqueData=opaqueData_asTPtrC8.AllocLC();
  1171 		opaqueData=opaqueData_asTPtrC8.AllocLC();
  1246 		}
  1172 
  1247 	const TUid nonNativeApplicationType(aAppData.NonNativeApplicationType());
  1173 	const TUid nonNativeApplicationType(aAppData.NonNativeApplicationType());
  1248 	if (nonNativeApplicationType!=TUid::Null())
  1174 	if (nonNativeApplicationType!=TUid::Null())
  1249 		{
       
  1250 		aMessage.WriteL(aMessageSlotForNativeExecutable, iServ.NativeExecutableL(nonNativeApplicationType));
  1175 		aMessage.WriteL(aMessageSlotForNativeExecutable, iServ.NativeExecutableL(nonNativeApplicationType));
  1251 		}
  1176 
  1252 	delete iOpaqueData_pendingDispatchToClient; // only done when the potentially leaving stuff has all succeeded
  1177 	delete iOpaqueData_pendingDispatchToClient; // only done when the potentially leaving stuff has all succeeded
  1253 	iOpaqueData_pendingDispatchToClient=opaqueData; // want to do this, even if opaqueData is NULL
  1178 	iOpaqueData_pendingDispatchToClient=opaqueData; // want to do this, even if opaqueData is NULL
  1254 	if (opaqueData!=NULL)
  1179 	if (opaqueData)
  1255 		{
  1180 		{
  1256 		CleanupStack::Pop(opaqueData);
  1181 		CleanupStack::Pop(opaqueData);
  1257 		aMessage.Complete(lengthOfOpaqueData);
  1182 		aMessage.Complete(lengthOfOpaqueData);
  1258 		}
  1183 		}
  1259 	}
  1184 	}
  1260 
  1185 
  1261 void CApaAppListServSession::GetOpaqueDataL(const RMessage2& aMessage)
  1186 void CApaAppArcServSession::GetOpaqueDataL(const RMessage2& aMessage)
  1262 	{
  1187 	{
  1263 	if (iOpaqueData_pendingDispatchToClient==NULL)
  1188 	if (iOpaqueData_pendingDispatchToClient==NULL)
  1264 		{
       
  1265 		User::Leave(KErrGeneral); // the protocol was broken: EAppListServGetOpaqueData can only be called immediately after one of the EAppListServGetExecutableNameGivenXxx or EAppListServGetNativeExecutableNameGivenXxx opcodes - see the client-side implementation of this protocol in RApaLsSession::GetOpaqueData (and the places that call it)
  1189 		User::Leave(KErrGeneral); // the protocol was broken: EAppListServGetOpaqueData can only be called immediately after one of the EAppListServGetExecutableNameGivenXxx or EAppListServGetNativeExecutableNameGivenXxx opcodes - see the client-side implementation of this protocol in RApaLsSession::GetOpaqueData (and the places that call it)
  1266 		}
  1190 
  1267 	aMessage.WriteL(0, *iOpaqueData_pendingDispatchToClient);
  1191 	aMessage.WriteL(0, *iOpaqueData_pendingDispatchToClient);
  1268 	delete iOpaqueData_pendingDispatchToClient;
  1192 	delete iOpaqueData_pendingDispatchToClient;
  1269 	iOpaqueData_pendingDispatchToClient=NULL;
  1193 	iOpaqueData_pendingDispatchToClient=NULL;
  1270 	}
  1194 	}
  1271 
  1195 
  1272 void CApaAppListServSession::GetAppInfoL(TUid aUid, TApaAppInfo& aInfo)
  1196 void CApaAppListServSession::GetAppInfoL(TUid aUid, TApaAppInfo& aInfo)
  1273 	{
  1197 	{
  1274 	CApaAppData* app=NULL;
  1198 	const CApaAppData* app = NULL;
  1275 	TApaAppEntry entry;
  1199 	TApaAppEntry entry;
  1276 	if (!FindAppInList(app,entry,aUid))
  1200 	if (!FindAppInList(app, entry, aUid))
  1277 		{
       
  1278 		User::Leave(KErrNotFound);
  1201 		User::Leave(KErrNotFound);
  1279 		}
  1202 
  1280 	aInfo.iUid = entry.iUidType[2];
  1203 	aInfo.iUid = entry.iUidType[2];
  1281 	aInfo.iFullName = entry.iFullName;
  1204 	aInfo.iFullName = entry.iFullName;
  1282 	aInfo.iCaption = app->Caption();
  1205 	aInfo.iCaption = app->Caption();
  1283 	aInfo.iShortCaption = app->ShortCaption();
  1206 	aInfo.iShortCaption = app->ShortCaption();
  1284 	}
  1207 	}
  1285 	
  1208 	
  1286 void CApaAppListServSession::DoRecognizeUnpackLC(HBufC*& aName, HBufC8*& aBuffer, const RMessage2& aMessage)
  1209 TPtrC8 CApaAppArcServSession::DoRecognizeUnpackLC(HBufC*& aName, RChunk& aLocalChunk, const RMessage2& aMessage)
  1287 	{
  1210 	{
  1288 	__ASSERT_DEBUG(aName==NULL,User::Invariant());
  1211     ASSERT(aName==NULL);
  1289 	__ASSERT_DEBUG(aBuffer==NULL,User::Invariant());
  1212     
  1290 	aName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
  1213     aName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(1)));
  1291 	TPtr name(aName->Des());
  1214     TPtr name(aName->Des());
  1292 	aMessage.ReadL(1, name);
  1215     aMessage.ReadL(1, name);
  1293 	aBuffer=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
  1216     
  1294 	TPtr8 buffer(aBuffer->Des());
  1217     HBufC8* buffer=NULL;
  1295 	aMessage.ReadL(2, buffer);
  1218     TInt error=KErrNone;
  1296 	}
  1219     TInt bufferSize= aMessage.GetDesLength(2);
  1297 
  1220     User::LeaveIfError(bufferSize);
  1298 void CApaAppListServSession::RecognizeDataL(const RMessage2& aMessage)
  1221     //Allocate memory in apparc's process heap.
       
  1222     TRAP(error, buffer=HBufC8::NewL(bufferSize));
       
  1223 
       
  1224     if(error==KErrNone)
       
  1225         {
       
  1226         CleanupStack::PushL(buffer);
       
  1227         TPtr8 bufPtr(buffer->Des());
       
  1228         aMessage.ReadL(2, bufPtr);   
       
  1229         return bufPtr;
       
  1230         }
       
  1231     else if(error==KErrNoMemory)
       
  1232         {
       
  1233         //If memory is not available in apparc's process heap, then allocate in kernel heap
       
  1234         User::LeaveIfError(aLocalChunk.CreateLocal(bufferSize,bufferSize));
       
  1235         CleanupClosePushL(aLocalChunk);
       
  1236         TPtr8 bufPtr(aLocalChunk.Base(), bufferSize);
       
  1237         aMessage.ReadL(2, bufPtr); 
       
  1238         return bufPtr;        
       
  1239         }
       
  1240     else
       
  1241         {
       
  1242         User::Leave(error);
       
  1243         }
       
  1244     
       
  1245     TPtrC8 bufPtr(NULL,0); //Never executed. To make compiler happy
       
  1246     return bufPtr;
       
  1247 	}
       
  1248 
       
  1249 void CApaAppArcServSession::RecognizeDataL(const RMessage2& aMessage)
  1299 // Recognize the data type of an object
  1250 // Recognize the data type of an object
  1300 	{
  1251 	{
  1301 	HBufC* name=NULL;
  1252 	HBufC* name=NULL;
  1302 	HBufC8* buffer=NULL;
  1253     RChunk localChunk;
  1303 	DoRecognizeUnpackLC(name,buffer,aMessage);
  1254     
  1304 
  1255 	TPtrC8 bufPtr=DoRecognizeUnpackLC(name, localChunk, aMessage);
  1305 	const TDataRecognitionResult result = iServ.RecognizeDataL(*name, *buffer);
  1256 
  1306 
  1257 	const TDataRecognitionResult result = iServ.RecognizeDataL(*name, bufPtr);
  1307 	CleanupStack::PopAndDestroy(2); // name & buffer
  1258 
       
  1259 	CleanupStack::PopAndDestroy(2); // name & buffer or localChunk
  1308 	aMessage.WriteL(0,TPckgC<TDataRecognitionResult>(result));
  1260 	aMessage.WriteL(0,TPckgC<TDataRecognitionResult>(result));
  1309 	}
  1261 	}
  1310 
  1262 
  1311 
  1263 
  1312 void CApaAppListServSession::RecognizeFilesL(const RMessage2& aMessage)
  1264 void CApaAppArcServSession::RecognizeFilesL(const RMessage2& aMessage)
  1313 	{
  1265 	{
  1314 	// if there is an outstanding async. request, we even don't allow 
  1266 	// if there is an outstanding async. request, we even don't allow 
  1315 	// a synchronous request at the same time (due to the two required
  1267 	// a synchronous request at the same time (due to the two required
  1316 	// server messages)
  1268 	// server messages)
  1317 	if (iAsyncRecognitionActive)
  1269 	if (iAsyncRecognitionActive)
  1318 		{
       
  1319 		User::Leave(KErrInUse);
  1270 		User::Leave(KErrInUse);
  1320 		}
       
  1321 
  1271 
  1322 	_LIT8(KAllDataTypes,"*");
  1272 	_LIT8(KAllDataTypes,"*");
  1323 
  1273 
  1324 	// retrieve pathname
  1274 	// retrieve pathname
  1325 	HBufC* const path=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
  1275 	HBufC* const path=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
  1349 	ASSERT(iFileRecognitionUtility);
  1299 	ASSERT(iFileRecognitionUtility);
  1350 	iFileRecognitionUtility->RecognizeSynchronouslyL(*iRecognitionResult);
  1300 	iFileRecognitionUtility->RecognizeSynchronouslyL(*iRecognitionResult);
  1351 	aMessage.WriteL(1,TPckgBuf<TUint>(iRecognitionResult->RequiredBufferSize()));
  1301 	aMessage.WriteL(1,TPckgBuf<TUint>(iRecognitionResult->RequiredBufferSize()));
  1352 	}
  1302 	}
  1353 
  1303 
  1354 void CApaAppListServSession::TransferRecognitionResultL(const RMessage2& aMessage)
  1304 void CApaAppArcServSession::TransferRecognitionResultL(const RMessage2& aMessage)
  1355 	{
  1305 	{
  1356 	if(iRecognitionResult == NULL)
  1306 	if(iRecognitionResult == NULL)
  1357 		User::Leave(KErrNotReady);
  1307 		User::Leave(KErrNotReady);
  1358 
  1308 
  1359 	iAsyncRecognitionActive = EFalse;
  1309 	iAsyncRecognitionActive = EFalse;
  1377 	iRecognitionResult = NULL;
  1327 	iRecognitionResult = NULL;
  1378 
  1328 
  1379 	CleanupStack::PopAndDestroy(buf);
  1329 	CleanupStack::PopAndDestroy(buf);
  1380 	}
  1330 	}
  1381 
  1331 
  1382 void CApaAppListServSession::RecognizeFilesAsyncL(const RMessage2& aMessage)
  1332 void CApaAppArcServSession::RecognizeFilesAsyncL(const RMessage2& aMessage)
  1383 	{
  1333 	{
  1384 	if (iAsyncRecognitionActive)
  1334 	if (iAsyncRecognitionActive)
  1385 		{
       
  1386 		User::Leave(KErrInUse);
  1335 		User::Leave(KErrInUse);
  1387 		}
       
  1388 	else
  1336 	else
  1389 		{
  1337 		{
  1390 		_LIT8(KAllDataTypes,"*");
  1338 		_LIT8(KAllDataTypes,"*");
  1391 
  1339 
  1392 		HBufC* path=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
  1340 		HBufC* path = HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
  1393 		TPtr pathPtr(path->Des());
  1341 		TPtr pathPtr(path->Des());
  1394 		aMessage.ReadL(0,pathPtr);
  1342 		aMessage.ReadL(0,pathPtr);
  1395 
  1343 
  1396 		// retrieve data type filter
  1344 		// retrieve data type filter
  1397 		HBufC8* dataType = 0;
  1345 		HBufC8* dataType = HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
  1398 		dataType=HBufC8::NewLC(User::LeaveIfError(aMessage.GetDesLength(2)));
       
  1399 		TPtr8 dataTypePtr(dataType->Des());
  1346 		TPtr8 dataTypePtr(dataType->Des());
  1400 		aMessage.ReadL(2,dataTypePtr);
  1347 		aMessage.ReadL(2,dataTypePtr);
  1401 
  1348 
  1402 		delete iRecognitionResult;
  1349 		delete iRecognitionResult;
  1403 		iRecognitionResult = NULL;
  1350 		iRecognitionResult = NULL;
  1424 given full name. It loops through all plug-ins until gets value different from 
  1371 given full name. It loops through all plug-ins until gets value different from 
  1425 CAppLaunchChecker::EAppLaunchIndifferent. 
  1372 CAppLaunchChecker::EAppLaunchIndifferent. 
  1426 The application will be launched if the return code is not equal to
  1373 The application will be launched if the return code is not equal to
  1427 CAppLaunchChecker::EAppLaunchDecline 
  1374 CAppLaunchChecker::EAppLaunchDecline 
  1428 */
  1375 */
  1429 void CApaAppListServSession::RuleBasedLaunchingL(const RMessage2& aMessage)
  1376 void CApaAppArcServSession::AquirePermissionToLaunchAppL(const RMessage2& aMessage) const
  1430 	{
  1377 	{
  1431 	CApaScanningRuleBasedPlugIns* theRuleBasedPlugIns = iServ.RuleBasedPlugIns();
  1378 	const CApaScanningRuleBasedPlugIns* theRuleBasedPlugIns = iServ.RuleBasedPlugIns();
  1432 	if(!theRuleBasedPlugIns)
  1379 	const TInt theNumImp = (theRuleBasedPlugIns ? theRuleBasedPlugIns->ImplementationCount() : 0);
  1433 		{
  1380 	if(!theNumImp || !iServ.WsSession().Handle())
  1434 		//we proceed with launching even if rule based plug-ins framework was not initialized
  1381 		{
       
  1382 		// Proceed with launch if rule based plug-in framework was not initialized
  1435 		aMessage.Complete(ETrue);
  1383 		aMessage.Complete(ETrue);
  1436 		return;
  1384 		return;
  1437 		}
  1385 		}
  1438 
  1386 
  1439 	HBufC* theFullFileName=HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
  1387 	// Get the name of the app to start from the IPC message object
       
  1388 	HBufC* theFullFileName = HBufC::NewLC(User::LeaveIfError(aMessage.GetDesLength(0)));
  1440 	TPtr theFullFileNamePtr(theFullFileName->Des());
  1389 	TPtr theFullFileNamePtr(theFullFileName->Des());
  1441 	aMessage.ReadL(0, theFullFileNamePtr);
  1390 	aMessage.ReadL(0, theFullFileNamePtr);
  1442 	TUid theUid = AppUidFromFullFileNameL(theFullFileNamePtr);
  1391 	
       
  1392 	// Ge the application's UID from its name
       
  1393 	const TUid theUid = iAppListSession->AppUidFromFullFileNameL(theFullFileNamePtr);
  1443 	CleanupStack::PopAndDestroy(theFullFileName); 
  1394 	CleanupStack::PopAndDestroy(theFullFileName); 
  1444 
  1395 
       
  1396 	// Iterate through all plug-ins and look for one that's not indifferent
  1445 	CAppLaunchChecker::TAppLaunchCode theLaunchCode = CAppLaunchChecker::EAppLaunchIndifferent;	
  1397 	CAppLaunchChecker::TAppLaunchCode theLaunchCode = CAppLaunchChecker::EAppLaunchIndifferent;	
  1446 	TInt theNumImp = theRuleBasedPlugIns->ImplementationCount();
       
  1447 
       
  1448 	TApaTaskList theTaskList(iServ.WsSession());
  1398 	TApaTaskList theTaskList(iServ.WsSession());
  1449 	for(TInt ii = 0; ii < theNumImp; ii++)
  1399 	for(TInt ii = 0; ii < theNumImp; ii++)
  1450 		{
  1400 		{
  1451 		CAppLaunchChecker* theLauncherChecker = (*theRuleBasedPlugIns)[ii];
  1401 		CAppLaunchChecker* const theLauncherChecker = (*theRuleBasedPlugIns)[ii];
  1452 		TRAP_IGNORE((theLaunchCode = theLauncherChecker->OkayToLaunchL(theUid, theTaskList)));
  1402 		TRAP_IGNORE(theLaunchCode = theLauncherChecker->OkayToLaunchL(theUid, theTaskList));
  1453 		if(theLaunchCode > CAppLaunchChecker::EAppLaunchIndifferent)
  1403 		if(theLaunchCode != CAppLaunchChecker::EAppLaunchIndifferent)
  1454 			break;
  1404 			break;
  1455 		}
  1405 		}
  1456 	//writing the result
  1406 		
  1457 	TBool okayToLaunch = theLaunchCode != CAppLaunchChecker::EAppLaunchDecline;
  1407 	// Return the result
       
  1408 	const TBool okayToLaunch = (theLaunchCode != CAppLaunchChecker::EAppLaunchDecline);
  1458 	aMessage.Complete(okayToLaunch);
  1409 	aMessage.Complete(okayToLaunch);
  1459 	}
  1410 	}
  1460 
  1411 
  1461 /** 
  1412 /** 
  1462 @param aFullFileName This filename is parsed and the path is replaced with "\\sys\\bin\\". 
  1413 @param aFullFileName This filename is parsed and the path is replaced with "\\sys\\bin\\". 
  1463 		And uses ".exe" if no other is provided in the filename passed.  If drive name is 
  1414 		It uses ".exe" if no other is provided in the filename passed.  If drive name is 
  1464 		present in the filename then it scans through the \\sys\\bin of that particular drive,
  1415 		present in the filename then it scans through the \\sys\\bin of that particular drive,
  1465 		otherwise it scans through the \\sys\\bin folders in all the avaliable drives.
  1416 		otherwise it scans through the \\sys\\bin folders in all the avaliable drives.
  1466 @return Returns the Application Uid for the aFullFileName application.
  1417 @return Returns the Application Uid for the aFullFileName application.
  1467 */
  1418 */
  1468 TUid CApaAppListServSession::AppUidFromFullFileNameL(const TDesC& aFullFileName) const
  1419 TUid CApaAppListServSession::AppUidFromFullFileNameL(const TDesC& aFullFileName) const
  1469 	{
  1420 	{
       
  1421 	
       
  1422 	// If the appliation still wasn't found, use AppArc's appliation list
       
  1423 	// Since we cannot get the Uid of NonNative apps by passing filename to RFs::Entry
       
  1424 	CApaAppData* appData = iAppList.AppDataByFileName(aFullFileName);
       
  1425 	if (appData)
       
  1426 		{
       
  1427 		TApaAppEntry appEntry = appData->AppEntry();
       
  1428 		return appEntry.iUidType[2];
       
  1429 		}
       
  1430 	
       
  1431 	
       
  1432 //mm: Why does this code not use AppArc's application list only?	
       
  1433 //mm: The order in which different methods to locate the app is used seems inefficient.
  1470 	_LIT(KSysBin, "\\sys\\bin\\");
  1434 	_LIT(KSysBin, "\\sys\\bin\\");
  1471 	_LIT(KFileExtension, ".EXE");
  1435 	_LIT(KFileExtension, ".EXE");
  1472 	
  1436 	
  1473 	RLoader loader;
  1437 	RLoader loader;
  1474 	User::LeaveIfError(loader.Connect());
  1438 	User::LeaveIfError(loader.Connect());
  1475 	CleanupClosePushL(loader);
  1439 	CleanupClosePushL(loader);
  1476 	TPckgBuf<RLibrary::TInfo> dllInfo;
  1440 	TPckgBuf<RLibrary::TInfo> dllInfo;
  1477 	TInt error = KErrNotFound;
       
  1478 
  1441 
  1479 	TParse parse;
  1442 	TParse parse;
  1480 	parse.Set(aFullFileName,NULL,NULL);
  1443 	parse.Set(aFullFileName,NULL,NULL);
       
  1444 
       
  1445 	// If the drive letter has been specified, look on that drive only...
       
  1446 	TInt error = KErrNotFound;
  1481 	if (parse.DrivePresent())
  1447 	if (parse.DrivePresent())
  1482 		{
  1448 		{
  1483 		const TPtrC appDrive = parse.Drive();
  1449 		const TPtrC appDrive = parse.Drive();
  1484 		TBuf<KMaxFileName>fileName(appDrive);
  1450 		TBuf<KMaxFileName>fileName(appDrive);
  1485 		fileName.Append(KSysBin);
  1451 		fileName.Append(KSysBin);
  1486 		User::LeaveIfError(parse.SetNoWild(fileName, &aFullFileName, &KFileExtension));
  1452 		User::LeaveIfError(parse.SetNoWild(fileName, &aFullFileName, &KFileExtension));
  1487 		error = loader.GetInfo(parse.FullName(), dllInfo);
  1453 		error = loader.GetInfo(parse.FullName(), dllInfo);
  1488 		}
  1454 		}
  1489 	else
  1455 	else	// ...otherwise scan all drives.
  1490 		{
  1456 		{
  1491 		// scan all drives
       
  1492 		User::LeaveIfError(parse.SetNoWild(KSysBin, &aFullFileName, &KFileExtension)); 
  1457 		User::LeaveIfError(parse.SetNoWild(KSysBin, &aFullFileName, &KFileExtension)); 
  1493 		TFileName tempFileName(parse.FullName());
  1458 		TFileName tempFileName(parse.FullName());
  1494 		TDriveList driveList;
  1459 		TDriveList driveList;
  1495 		User::LeaveIfError(iFs.DriveList(driveList));
  1460 		User::LeaveIfError(iFs.DriveList(driveList));
  1496 		for (TInt driveNumber = EDriveY; driveNumber != KFinishedScanning; driveNumber = NextDriveToScan(driveNumber))
  1461 		for (TInt driveNumber = EDriveY; driveNumber != KFinishedScanning; driveNumber = NextDriveToScan(driveNumber))
  1498 			if (driveList[driveNumber]!=0)
  1463 			if (driveList[driveNumber]!=0)
  1499 				{
  1464 				{
  1500 				User::LeaveIfError(parse.SetNoWild(TDriveUnit(driveNumber).Name(), &tempFileName, NULL));
  1465 				User::LeaveIfError(parse.SetNoWild(TDriveUnit(driveNumber).Name(), &tempFileName, NULL));
  1501 				error = loader.GetInfo(parse.FullName(), dllInfo);
  1466 				error = loader.GetInfo(parse.FullName(), dllInfo);
  1502 				if (error == KErrNone)
  1467 				if (error == KErrNone)
  1503 					{
       
  1504 					break;
  1468 					break;
  1505 					}
       
  1506 				}
  1469 				}
  1507 			}
  1470 			}
  1508 		}
  1471 		}
       
  1472 
  1509 	CleanupStack::PopAndDestroy(&loader);
  1473 	CleanupStack::PopAndDestroy(&loader);
  1510 	if (error == KErrNone)
  1474 	// Return the UID if found and no errors occured
  1511 		{
  1475 	if(!error)
  1512 		return dllInfo().iUids[2];
  1476 		return dllInfo().iUids[2];
  1513 		}
  1477 	
  1514 
  1478 	// If the application wasn't found
  1515 	//we can't use RFs::Entry if path refers to a system directory i.e. \\sys\\bin
  1479 	// Try looking for the application using normal F32. This won't work in protected directories
       
  1480 
       
  1481 	// Since we can't use RFs::Entry if the path refers the protected system directory (i.e. \sys\bin)...
  1516 	User::LeaveIfError(parse.SetNoWild(aFullFileName, NULL, NULL));
  1482 	User::LeaveIfError(parse.SetNoWild(aFullFileName, NULL, NULL));
  1517 	if(parse.Path().FindF(KSysBin) == 0)
  1483 	if(parse.Path().FindF(KSysBin) == 0)
  1518 		{
  1484 		User::Leave(KErrNotFound);	// ... then return not-found.
  1519 		User::Leave(KErrNotFound);
  1485 
  1520 		}
  1486 //mm: Surely we should still be allowed to use AppArc below?
  1521 	
  1487 
  1522 	//the following valid for non-native applications
  1488 	// The following is valid for non-native applications only
  1523 	TEntry entry;
  1489 	TEntry entry;
  1524 	error = iFs.Entry(aFullFileName, entry);
  1490 	error = iFs.Entry(aFullFileName, entry);
  1525 	if (error != KErrNone)
  1491 	if(!error)
  1526 		{
  1492 		return entry.iType[2];
  1527 		// Since we cannot get the Uid of NonNative apps by passing filename to RFs::Entry
  1493 
  1528 		CApaAppData* appData = AppList().AppDataByFileName(aFullFileName);
  1494 	User::Leave(KErrNotFound);
  1529 		if (appData)
  1495 	return TUid::Null();	// Won't be called
  1530 			{
  1496 	}
  1531 			TApaAppEntry appEntry = appData->AppEntry();
  1497 
  1532 			return appEntry.iUidType[2];
  1498 /**
  1533 			}
  1499 Applies the scanning order Y: through A: then Z: last.
  1534 		User::Leave(KErrNotFound);
  1500 */
  1535 		}
       
  1536 			
       
  1537 	return entry.iType[2];
       
  1538 	}
       
  1539 
       
  1540 TInt CApaAppListServSession::NextDriveToScan(TInt aCurrentDrive)
  1501 TInt CApaAppListServSession::NextDriveToScan(TInt aCurrentDrive)
  1541 // applies the scanning order y:->a: then z:
       
  1542 	{
  1502 	{
  1543 	if (aCurrentDrive == EDriveZ)
  1503 	if (aCurrentDrive == EDriveZ)
  1544 		{
       
  1545 		return KFinishedScanning;
  1504 		return KFinishedScanning;
  1546 		}
       
  1547 	else if (aCurrentDrive == 0)
  1505 	else if (aCurrentDrive == 0)
  1548 		{
  1506 		return EDriveZ; 	// finally scan the last one
  1549 		return EDriveZ; // finally scan the last one
       
  1550 		}
       
  1551 	else if (aCurrentDrive > 0 && aCurrentDrive < KMaxDrives)
  1507 	else if (aCurrentDrive > 0 && aCurrentDrive < KMaxDrives)
  1552 		{
       
  1553 		return aCurrentDrive - 1;
  1508 		return aCurrentDrive - 1;
  1554 		}
       
  1555 	else
  1509 	else
  1556 		{
       
  1557 		return KErrGeneral; // never gets here, but it wont compile otherwise
  1510 		return KErrGeneral; // never gets here, but it wont compile otherwise
  1558 		}
  1511 	}
  1559 	}
  1512 
  1560 
  1513 void CApaAppArcServSession::CancelRecognizeFiles()
  1561 void CApaAppListServSession::CancelRecognizeFiles()
       
  1562 	{
  1514 	{
  1563 	if (iAsyncRecognitionActive)
  1515 	if (iAsyncRecognitionActive)
  1564 		{
  1516 		{
  1565 		ASSERT(iFileRecognitionUtility);
  1517 		ASSERT(iFileRecognitionUtility);
  1566 		iFileRecognitionUtility->CancelRecognitionRequest();
  1518 		iFileRecognitionUtility->CancelRecognitionRequest();
  1567 		iAsyncRecognitionActive = EFalse;
  1519 		iAsyncRecognitionActive = EFalse;
  1568 		}
  1520 		}
  1569 	}
  1521 	}
  1570 
  1522 
  1571 void CApaAppListServSession::RecognizeDataPassedByFileHandleL(const RMessage2& aMessage)
  1523 void CApaAppArcServSession::RecognizeDataPassedByFileHandleL(const RMessage2& aMessage)
  1572 // Recognize the data type of an object
  1524 // Recognize the data type of an object
  1573 	{
  1525 	{
  1574 	RFile file;
  1526 	RFile file;
  1575 	CleanupClosePushL(file);
  1527 	CleanupClosePushL(file);
  1576 	User::LeaveIfError(file.AdoptFromClient(aMessage, 1, 2));
  1528 	User::LeaveIfError(file.AdoptFromClient(aMessage, 1, 2));
  1577 	const TDataRecognitionResult result(iServ.RecognizeDataL(file, PreferredBufSize()));
  1529 	const TDataRecognitionResult result(iServ.RecognizeDataL(file, PreferredBufSize()));
  1578 	CleanupStack::PopAndDestroy(&file);
  1530 	CleanupStack::PopAndDestroy(&file);
  1579 	aMessage.WriteL(0, TPckgC<TDataRecognitionResult>(result));
  1531 	aMessage.WriteL(0, TPckgC<TDataRecognitionResult>(result));
  1580 	}
  1532 	}
  1581 	
  1533 	
  1582 void CApaAppListServSession::RecognizeSpecificDataL(const RMessage2& aMessage)
  1534 void CApaAppArcServSession::RecognizeSpecificDataL(const RMessage2& aMessage)
  1583 // Determine whether an object is of a specific data type
  1535 // Determine whether an object is of a specific data type
  1584 	{
  1536 	{
  1585 	HBufC* name=NULL;
  1537 	HBufC* name=NULL;
  1586 	HBufC8* buffer=NULL;
  1538 	RChunk localChunk;
  1587 	DoRecognizeUnpackLC(name,buffer,aMessage);
  1539 	
       
  1540 	TPtrC8 bufPtr=DoRecognizeUnpackLC(name, localChunk, aMessage);
  1588 	TDataType dataType;
  1541 	TDataType dataType;
  1589 	{TPckg<TDataType> dataType_asDescriptor(dataType);
  1542 	{TPckg<TDataType> dataType_asDescriptor(dataType);
  1590 	aMessage.ReadL(0, dataType_asDescriptor);}
  1543 	aMessage.ReadL(0, dataType_asDescriptor);}
  1591 	aMessage.Complete(iServ.RecognizeDataL(*name,*buffer,dataType));
  1544 	aMessage.Complete(iServ.RecognizeDataL(*name,bufPtr,dataType));
  1592 	CleanupStack::PopAndDestroy(2); // name & buffer
  1545 	CleanupStack::PopAndDestroy(2); // name & buffer or localChunk
  1593 	}
  1546 	}
  1594 
  1547 
  1595 void CApaAppListServSession::RecognizeSpecificDataPassedByFileHandleL(const RMessage2& aMessage)
  1548 void CApaAppArcServSession::RecognizeSpecificDataPassedByFileHandleL(const RMessage2& aMessage)
  1596 	{
  1549 	{
  1597 	RFile file;
  1550 	RFile file;
  1598 	CleanupClosePushL(file);
  1551 	CleanupClosePushL(file);
  1599 	User::LeaveIfError(file.AdoptFromClient(aMessage, 1, 2));
  1552 	User::LeaveIfError(file.AdoptFromClient(aMessage, 1, 2));
  1600 	TDataType dataType;
  1553 	TDataType dataType;
  1614 		TApaEmbeddabilityFilter filter;
  1567 		TApaEmbeddabilityFilter filter;
  1615 		{TPckg<TApaEmbeddabilityFilter> filter_asDescriptor(filter);
  1568 		{TPckg<TApaEmbeddabilityFilter> filter_asDescriptor(filter);
  1616 		aMessage.ReadL(1,filter_asDescriptor);}
  1569 		aMessage.ReadL(1,filter_asDescriptor);}
  1617 		iEmbeddabilityFilter = filter;
  1570 		iEmbeddabilityFilter = filter;
  1618 		}
  1571 		}
       
  1572 
  1619 	if (aType == EListCapabilityAttrFilteredApps)
  1573 	if (aType == EListCapabilityAttrFilteredApps)
  1620 		{
  1574 		{
  1621 		iCapabilityAttrFilterMask = aMessage.Int1();
  1575 		iCapabilityAttrFilterMask = aMessage.Int1();
  1622 		iCapabilityAttrFilterValue = aMessage.Int2();
  1576 		iCapabilityAttrFilterValue = aMessage.Int2();
  1623 		}
  1577 		}
       
  1578 
  1624 	if (aType == EListServerApps)
  1579 	if (aType == EListServerApps)
  1625 		{
       
  1626 		iServiceUid = TUid::Uid(aMessage.Int1());
  1580 		iServiceUid = TUid::Uid(aMessage.Int1());
  1627 		}
  1581 
  1628 	iApaAppInfoArray.ResetAndDestroy();
  1582 	iApaAppInfoArray.ResetAndDestroy();
  1629 	iFlags|=EAppListPopulationPending;
  1583 	iFlags|=EAppListPopulationPending;
  1630 	}
  1584 	}
  1631 
  1585 
  1632 void CApaAppListServSession::EmbedCount(const RMessage2& aMessage) const
  1586 void CApaAppListServSession::EmbedCount(const RMessage2& aMessage) const
  1633 // writes back the number of embedded apps in the list
  1587 // writes back the number of embedded apps in the list
  1634 	{
  1588 	{
  1635 	TInt count=0;
  1589 	TInt count=0;
  1636 	const CApaAppList& list=AppList();
  1590 	const CApaAppList& list = iAppList;
  1637 	CApaAppData* app = list.FirstApp();
  1591 	CApaAppData* app = list.FirstApp();
  1638 	TApaEmbeddabilityFilter filter;
  1592 	TApaEmbeddabilityFilter filter;
  1639 	filter.AddEmbeddability(TApaAppCapability::EEmbeddable);
  1593 	filter.AddEmbeddability(TApaAppCapability::EEmbeddable);
  1640 	filter.AddEmbeddability(TApaAppCapability::EEmbeddableOnly);
  1594 	filter.AddEmbeddability(TApaAppCapability::EEmbeddableOnly);
  1641 	while (app)
  1595 	while (app)
  1642 		{
  1596 		{
  1643 		if (!AppIsControlPanelItem(*app) && AppMatchesEmbeddabilityFilter(*app, filter))
  1597 		if (!AppIsControlPanelItem(*app) && AppMatchesEmbeddabilityFilter(*app, filter))
  1644 			{
       
  1645 			count++;
  1598 			count++;
  1646 			}
  1599 
  1647 		app = list.NextApp(app);
  1600 		app = list.NextApp(app);
  1648 		}
  1601 		}
       
  1602 
  1649 	aMessage.Complete(count);
  1603 	aMessage.Complete(count);
  1650 	}
  1604 	}
  1651 
  1605 
  1652 void CApaAppListServSession::AppCount(const RMessage2& aMessage) const
  1606 void CApaAppListServSession::AppCount(const RMessage2& aMessage) const
  1653 // writes back the number of apps in the list
  1607 // writes back the number of apps in the list
  1654 	{
  1608 	{
  1655 	TInt count=0;
  1609 	TInt count = 0;
  1656 	const CApaAppList& list=AppList();
  1610 	const CApaAppList& list = iAppList;
  1657 	CApaAppData* app = list.FirstApp();
  1611 	CApaAppData* app = list.FirstApp();
  1658 	while (app)
  1612 	while (app)
  1659 		{
  1613 		{
  1660 		if (!AppIsControlPanelItem(*app))
  1614 		if (!AppIsControlPanelItem(*app))
  1661 			{
       
  1662 			count++;
  1615 			count++;
  1663 			}
  1616 
  1664 		app = list.NextApp(app);
  1617 		app = list.NextApp(app);
  1665 		}
  1618 		}
       
  1619 
  1666 	aMessage.Complete(count);
  1620 	aMessage.Complete(count);
  1667 	}
  1621 	}
  1668 
  1622 
  1669 void CApaAppListServSession::GetNextAppL(const RMessage2& aMessage)
  1623 void CApaAppListServSession::GetNextAppL(const RMessage2& aMessage)
  1670 	{
  1624 	{
  1671 	if (iFlags&EAppListPopulationPending)
  1625 	if (iFlags&EAppListPopulationPending)
  1672 		{
  1626 		{
  1673 		const CApaAppList& list=AppList();
  1627 		const CApaAppList& list=iAppList;
  1674 		if (!(list.IsFirstScanComplete()))
  1628 		if (!(list.IsFirstScanComplete()))
  1675 			{
       
  1676 			User::Leave(KErrCorrupt);
  1629 			User::Leave(KErrCorrupt);
  1677 			}
  1630 		
  1678 
       
  1679 		iApaAppInfoArray.ResetAndDestroy();
  1631 		iApaAppInfoArray.ResetAndDestroy();
  1680 		for (CApaAppData* appData = list.FirstApp(iAppListScreenMode); appData != NULL; appData = list.NextApp(appData, iAppListScreenMode))
  1632 		for (CApaAppData* appData = list.FirstApp(iAppListScreenMode); appData != NULL; appData = list.NextApp(appData, iAppListScreenMode))
  1681 			{
  1633 			{
  1682 			if (iAppListType==EListFilteredEmbeddedApps && (AppIsControlPanelItem(*appData) || !AppMatchesEmbeddabilityFilter(*appData, iEmbeddabilityFilter)))
  1634 			if (iAppListType==EListFilteredEmbeddedApps && (AppIsControlPanelItem(*appData) || !AppMatchesEmbeddabilityFilter(*appData, iEmbeddabilityFilter)))
  1683 				{
       
  1684 				continue;
  1635 				continue;
  1685 				}
  1636 
  1686 			if (iAppListType==EListCapabilityAttrFilteredApps && !AppMatchesCapabilityAttrFilter(*appData))
  1637 			if (iAppListType==EListCapabilityAttrFilteredApps && !AppMatchesCapabilityAttrFilter(*appData))
  1687 				{
       
  1688 				continue;
  1638 				continue;
  1689 				}
  1639 
  1690 			if (iAppListType==EListServerApps && !appData->ImplementsService(iServiceUid))
  1640 			if (iAppListType==EListServerApps && !appData->ImplementsService(iServiceUid))
  1691 				{
       
  1692 				continue;
  1641 				continue;
  1693 				}
  1642 
  1694 			CApaAppInfo* apaAppInfo= new (ELeave)CApaAppInfo();
  1643 			CApaAppInfo* apaAppInfo= new (ELeave)CApaAppInfo();
  1695 			CleanupStack::PushL(apaAppInfo);
  1644 			CleanupStack::PushL(apaAppInfo);
  1696 			apaAppInfo->SetCaptionL(appData->Caption());
  1645 			apaAppInfo->SetCaptionL(appData->Caption());
  1697 			apaAppInfo->SetShortCaptionL(appData->ShortCaption());
  1646 			apaAppInfo->SetShortCaptionL(appData->ShortCaption());
  1698 			apaAppInfo->SetFullNameL(appData->AppEntry().iFullName);
  1647 			apaAppInfo->SetFullNameL(appData->AppEntry().iFullName);
  1699 			apaAppInfo->SetUid(appData->AppEntry().iUidType[2]);
  1648 			apaAppInfo->SetUid(appData->AppEntry().iUidType[2]);
  1700 			User::LeaveIfError(iApaAppInfoArray.Append(apaAppInfo));
  1649 			User::LeaveIfError(iApaAppInfoArray.Append(apaAppInfo));
  1701 			CleanupStack::Pop(apaAppInfo);
  1650 			CleanupStack::Pop(apaAppInfo);
  1702 			}
  1651 			}
  1703 		iFlags&=~EAppListPopulationPending;
  1652 		
  1704 		}
  1653 		iFlags &= ~EAppListPopulationPending;
  1705 
  1654 		}
  1706 	if (iApaAppInfoArray.Count()==0)
  1655 
  1707 		{
  1656 	if (!iApaAppInfoArray.Count())
  1708 		User::Leave(KErrNotFound);
  1657 		User::Leave(KErrNotFound);
  1709 		}
  1658 
  1710 	TApaAppInfo* info=new(ELeave)TApaAppInfo; 
  1659 	TApaAppInfo* info=new(ELeave)TApaAppInfo; 
  1711 	CleanupStack::PushL(info);
  1660 	CleanupStack::PushL(info);
  1712 	CApaAppInfo* apaAppInfo = iApaAppInfoArray[0];
  1661 	CApaAppInfo* apaAppInfo = iApaAppInfoArray[0];
  1713 	info->iUid = apaAppInfo->Uid();
  1662 	info->iUid = apaAppInfo->Uid();
  1714 	info->iFullName = apaAppInfo->FullName();
  1663 	info->iFullName = apaAppInfo->FullName();
  1715 	info->iCaption = apaAppInfo->Caption();
  1664 	info->iCaption = apaAppInfo->Caption();
  1716 	// Get the length of the target descriptor
  1665 	// Get the length of the target descriptor
  1717 	TInt targetLen=aMessage.GetDesMaxLength(1);
  1666 	TInt targetLen=aMessage.GetDesMaxLength(1);
  1718 	if (targetLen==KApaAppInfoDesMaxLength)
  1667 	if (targetLen==KApaAppInfoDesMaxLength)
  1719 		{
       
  1720 		info->iShortCaption = apaAppInfo->ShortCaption();
  1668 		info->iShortCaption = apaAppInfo->ShortCaption();
  1721 		}
  1669 
  1722 	//
       
  1723 	iApaAppInfoArray.Remove(0);
  1670 	iApaAppInfoArray.Remove(0);
  1724 	delete apaAppInfo;
  1671 	delete apaAppInfo;
  1725 	TPckgC<TApaAppInfo> infoPk(*info);
  1672 	TPckgC<TApaAppInfo> infoPk(*info);
  1726 	if (targetLen<KApaAppInfoDesMaxLength)
  1673 	if (targetLen<KApaAppInfoDesMaxLength)
  1727 		{
       
  1728 		infoPk.Set(infoPk.Left(_FOFF(TApaAppInfo,iShortCaption))); // reduce the length of infoPk to the 7.0 size of TApaAppInfo
  1674 		infoPk.Set(infoPk.Left(_FOFF(TApaAppInfo,iShortCaption))); // reduce the length of infoPk to the 7.0 size of TApaAppInfo
  1729 		}
  1675 
  1730 	aMessage.WriteL(1,infoPk);
  1676 	aMessage.WriteL(1,infoPk);
  1731 	CleanupStack::PopAndDestroy(info);
  1677 	CleanupStack::PopAndDestroy(info);
  1732 	}
  1678 	}
  1733 
  1679 
  1734 TBool CApaAppListServSession::AppMatchesEmbeddabilityFilter(const CApaAppData& aAppData, const TApaEmbeddabilityFilter& aEmbeddabilityFilter) const
  1680 TBool CApaAppListServSession::AppMatchesEmbeddabilityFilter(const CApaAppData& aAppData, const TApaEmbeddabilityFilter& aEmbeddabilityFilter) const
  1735 // returns True if aAppData's embeddability matches the filter set by InitListL
  1681 // returns True if aAppData's embeddability matches the filter set by InitListL
  1736 	{
  1682 	{
  1737 	TApaAppCapabilityBuf capabilityBuf;
  1683 	TApaAppCapabilityBuf capabilityBuf;
  1738 	aAppData.Capability(capabilityBuf);
  1684 	aAppData.Capability(capabilityBuf);
  1739 	if (aEmbeddabilityFilter.MatchesEmbeddability(capabilityBuf().iEmbeddability))
  1685 
  1740 		{
  1686 	return (aEmbeddabilityFilter.MatchesEmbeddability(capabilityBuf().iEmbeddability));
  1741 		return ETrue;
       
  1742 		}
       
  1743 	return EFalse;
       
  1744 	}
  1687 	}
  1745 
  1688 
  1746 TBool CApaAppListServSession::AppMatchesCapabilityAttrFilter(const CApaAppData& aAppData) const
  1689 TBool CApaAppListServSession::AppMatchesCapabilityAttrFilter(const CApaAppData& aAppData) const
  1747 // returns True if aAppData's capability attributes match the filter set by InitListL
  1690 // returns True if aAppData's capability attributes match the filter set by InitListL
  1748 	{
  1691 	{
  1749 	TApaAppCapabilityBuf capabilityBuf;
  1692 	TApaAppCapabilityBuf capabilityBuf;
  1750 	aAppData.Capability(capabilityBuf);
  1693 	aAppData.Capability(capabilityBuf);
  1751 	if ((capabilityBuf().iAttributes & iCapabilityAttrFilterMask) == (iCapabilityAttrFilterValue & iCapabilityAttrFilterMask))
  1694 	return ((capabilityBuf().iAttributes & iCapabilityAttrFilterMask) == (iCapabilityAttrFilterValue & iCapabilityAttrFilterMask));
  1752 		{
       
  1753 		return ETrue;
       
  1754 		}
       
  1755 	return EFalse;
       
  1756 	}
  1695 	}
  1757 
  1696 
  1758 TBool CApaAppListServSession::AppIsControlPanelItem(const CApaAppData& aAppData)
  1697 TBool CApaAppListServSession::AppIsControlPanelItem(const CApaAppData& aAppData)
  1759 // returns True if aAppData represents a control panel app
  1698 // returns True if aAppData represents a control panel app
  1760 	{
  1699 	{
  1761 	TApaAppCapabilityBuf capabilityBuf;
  1700 	TApaAppCapabilityBuf capabilityBuf;
  1762 	aAppData.Capability(capabilityBuf);
  1701 	aAppData.Capability(capabilityBuf);
  1763 	if (capabilityBuf().iAttributes & TApaAppCapability::EControlPanelItem)
  1702 	return (capabilityBuf().iAttributes & TApaAppCapability::EControlPanelItem);
  1764 		{
  1703 	}
  1765 		return ETrue;
  1704 
  1766 		}
  1705 /**
  1767 	return EFalse;
  1706 locate app in list, return EFalse if it isn't present
  1768 	}
  1707 search is regardless of screen mode.
  1769 
  1708 @internalComponent
  1770 TBool CApaAppListServSession::FindAppInList(CApaAppData*& aApp,TApaAppEntry& aEntry,TUid aAppUid)
  1709 */
  1771 // locate app in list, return EFalse if it isn't present
  1710 TBool CApaAppListServSession::FindAppInList(CApaAppData*& aApp, TApaAppEntry& aEntry, TUid aAppUid)
  1772 // search is regardless of screen mode.
  1711 	{
  1773 	{
  1712 	// Look for the app with aAppUid in the app list we keep
  1774 	const CApaAppList& list=AppList();
  1713 	const CApaAppList& list = iAppList;
  1775 	aApp = list.AppDataByUid(aAppUid);
  1714 	aApp = list.AppDataByUid(aAppUid);
  1776 	TBool found=EFalse;
       
  1777 	if (aApp)
  1715 	if (aApp)
  1778 		{
       
  1779 		found = ETrue;
       
  1780 		aEntry = aApp->AppEntry();
  1716 		aEntry = aApp->AppEntry();
  1781 		}
  1717 	
  1782 	
  1718 	// If the app list is currently in flux, try to nail down the app by looking for it specifically
  1783 	TBool appPendingOnLangChange = found && list.IsLanguageChangePending() && aApp->IsPending();	
  1719 	const TBool appPendingOnLangChange = (aApp && list.IsLanguageChangePending() && aApp->IsPending());	
  1784 		
  1720 	if ((!aApp || appPendingOnLangChange) && !list.IsIdleUpdateComplete())
  1785 	if ((!found || appPendingOnLangChange) && !list.IsIdleUpdateComplete())
  1721 		{
  1786 		{
  1722 		// 1. App wasn't found, but an app scan is currently in progress,
  1787 		// 1. app wasn't found, but an app scan is currently in progress,
       
  1788 		// so try to find and add the specific app we're looking for to the list
  1723 		// so try to find and add the specific app we're looking for to the list
  1789 		
  1724 		
  1790 		// 2. On language change event, current app scan could not yet update the found app, 
  1725 		// 2. On language change event, current app scan could not yet update the found app, 
  1791 		// so try to update the specific app we're looking for, in the list.
  1726 		// so try to update the specific app we're looking for, in the list.
  1792 		CApaAppData* app = NULL;
  1727 		if(aAppUid != KNullUid)
  1793 		if(aAppUid!=KNullUid)
       
  1794 			{
  1728 			{
  1795 			TRAPD(ret, app = FindSpecificAppL(aAppUid));
  1729 			CApaAppData* app = NULL;
  1796 			if (ret == KErrNone && app)
  1730 			TRAPD(err, app = FindSpecificAppL(aAppUid));
       
  1731 			if (!err && app)
  1797 				{
  1732 				{
  1798 				// app has been found and added to the app list
  1733 				// app has been found and added to the app list
  1799 				aApp = app;
  1734 				aApp = app;
  1800 				aEntry = aApp->AppEntry();
  1735 				aEntry = aApp->AppEntry();
  1801 				found = ETrue;
       
  1802 				}
  1736 				}
  1803  			}
  1737  			}
  1804  		}
  1738  		}
  1805 	return found;
  1739 
       
  1740 	return (aApp != NULL);
  1806 	}
  1741 	}
  1807 
  1742 
  1808 CApaAppData* CApaAppListServSession::FindSpecificAppL(TUid aAppUid)
  1743 CApaAppData* CApaAppListServSession::FindSpecificAppL(TUid aAppUid)
  1809 	{
  1744 	{
  1810 	//Scans the drives and folder lists for the specific app
  1745 	//Scans the drives and folder lists for the specific app
  1811 	CApaAppRegFinder* regFinder = CApaAppRegFinder::NewLC(iFs);
  1746 	CApaAppRegFinder* regFinder = CApaAppRegFinder::NewLC(iFs);
  1812 	CApaAppData* app = iServ.AppList().FindAndAddSpecificAppL(regFinder, aAppUid);
  1747 	CApaAppData* app = iAppList.FindAndAddSpecificAppL(regFinder, aAppUid);
  1813 	CleanupStack::PopAndDestroy(regFinder);
  1748 	CleanupStack::PopAndDestroy(regFinder);
  1814 	return app;
  1749 	return app;
  1815 	}
  1750 	}
  1816 
  1751 
  1817 void CApaAppListServSession::GetAppInfoL(const RMessage2& aMessage)
  1752 void CApaAppListServSession::GetAppInfoL(const RMessage2& aMessage)
  1818 	{
  1753 	{
  1819 	// get UID of required app
  1754 	// get UID of required app
  1820 	const TUid uid=TUid::Uid(aMessage.Int0());
  1755 	const TUid uid = TUid::Uid(aMessage.Int0());
  1821 	TApaAppInfo* info=new(ELeave) TApaAppInfo; // on heap to avoid running out of stack
  1756 	TApaAppInfo* info = new(ELeave) TApaAppInfo; // on heap to avoid running out of stack
  1822 	CleanupStack::PushL(info);
  1757 	CleanupStack::PushL(info);
  1823 	GetAppInfoL(uid, *info);
  1758 	GetAppInfoL(uid, *info);
  1824 	TPckgC<TApaAppInfo> infoPk(*info);	
  1759 	TPckgC<TApaAppInfo> infoPk(*info);	
  1825 	aMessage.WriteL(1,infoPk);
  1760 	aMessage.WriteL(1, infoPk);
  1826 	CleanupStack::PopAndDestroy(info);
  1761 	CleanupStack::PopAndDestroy(info);
  1827 	}
  1762 	}
  1828 
  1763 
  1829 void CApaAppListServSession::GetAppCapabilityL(const RMessage2& aMessage)
  1764 void CApaAppListServSession::GetAppCapabilityL(const RMessage2& aMessage)
  1830 	{	  								  
  1765 	{	  								  
  1831 	const TUid uid=TUid::Uid(aMessage.Int1());
  1766 	const TUid uid = TUid::Uid(aMessage.Int1());
  1832 	CApaAppData* app=NULL;
  1767 	const CApaAppData& app = FindAppInListL(uid);
  1833 	TApaAppEntry entry;
  1768 
  1834 	if (!FindAppInList(app,entry,uid))
  1769 	TInt targetLen = aMessage.GetDesMaxLength(0);
  1835 		{
  1770 	HBufC8* buf = HBufC8::NewLC(User::LeaveIfError(targetLen));
  1836 		User::Leave(KErrNotFound);
  1771 	TPtr8 ptr = buf->Des();
  1837 		}
  1772 	app.Capability(ptr);
  1838 	TInt targetLen=aMessage.GetDesMaxLength(0);
       
  1839 	HBufC8* buf=HBufC8::NewLC(User::LeaveIfError(targetLen));
       
  1840 	TPtr8 ptr=buf->Des();
       
  1841 	app->Capability(ptr);
       
  1842 	ptr.SetLength(targetLen);
  1773 	ptr.SetLength(targetLen);
  1843 	aMessage.WriteL(0,*buf);
  1774 	aMessage.WriteL(0, *buf);
  1844 	CleanupStack::PopAndDestroy(buf); 
  1775 	CleanupStack::PopAndDestroy(buf); 
  1845 	}
  1776 	}
  1846 
  1777 
  1847 void CApaAppListServSession::GetDefaultScreenNumberL(const RMessage2& aMessage)
  1778 void CApaAppListServSession::GetDefaultScreenNumberL(const RMessage2& aMessage)
  1848 	{
  1779 	{
  1849 	const TUid uid=TUid::Uid(aMessage.Int0());
  1780 	const TUid uid=TUid::Uid(aMessage.Int0());
  1850 	CApaAppData* app=NULL;
  1781 	const CApaAppData& app = FindAppInListL(uid);
  1851 	TApaAppEntry entry;
  1782 
  1852 	if (!FindAppInList(app,entry,uid))
  1783 	aMessage.Complete(app.DefaultScreenNumber());
  1853 		{
  1784 	}
  1854 		User::Leave(KErrNotFound);
  1785 
  1855 		}
       
  1856 	aMessage.Complete(app->DefaultScreenNumber());
       
  1857 	}
       
  1858 
       
  1859 void CApaAppListServSession::StartAppL(const RMessage2& aMessage, TBool aReturnThreadId)
       
  1860 	{
       
  1861 	CApaCommandLine* commandLine=CApaCommandLine::NewLC();
       
  1862 	commandLine->ConstructCmdLineFromMessageL(aMessage);
       
  1863 
       
  1864 	CApaFileRecognizerType* type=NULL;
       
  1865 	TRAP_IGNORE(type=FileRecognizer()->RecognizeFileL(commandLine->ExecutableName()));
       
  1866 	if (type==NULL)
       
  1867 		{
       
  1868 		User::Leave(KErrNotFound);
       
  1869 		}
       
  1870 	CleanupStack::PushL(TCleanupItem(&NullifyAppCommandLinePointer,&iServ));
       
  1871 	iServ.SetAppCmdLine(commandLine);
       
  1872 	TPtrC fileName=commandLine->DocumentName();
       
  1873 	TPtrC8 tailEnd=commandLine->TailEnd();
       
  1874 	const TThreadId threadId(type->RunL(commandLine->Command(),(fileName.Length()?&fileName:NULL),(tailEnd.Length()?&tailEnd:NULL))); // pass in NULL for components that are not present
       
  1875 	CleanupStack::PopAndDestroy(&iServ); // calls iServ.SetAppCmdLine(NULL);
       
  1876 	CleanupStack::PopAndDestroy(commandLine);
       
  1877 
       
  1878 	if (aReturnThreadId)
       
  1879 		{
       
  1880 		aMessage.WriteL(CApaCommandLine::EIpcFirstFreeSlot,TPckgC<TThreadId>(threadId));
       
  1881 		}
       
  1882 	}
       
  1883 
  1786 
  1884 void CApaAppListServSession::SetNotify(const RMessage2& aMessage)
  1787 void CApaAppListServSession::SetNotify(const RMessage2& aMessage)
  1885 	{
  1788 	{
  1886 	if (!iNotifyMessage.IsNull())
  1789 	if (!iNotifyMessage.IsNull())
  1887 		{
       
  1888 		aMessage.Panic(KApaPanicCli,ENotifierAlreadyPresent);
  1790 		aMessage.Panic(KApaPanicCli,ENotifierAlreadyPresent);
  1889 		}
       
  1890 	else
  1791 	else
  1891 		{
  1792 		{
  1892 		const TBool completeImmediatelyIfNoScanImpendingOrInProgress=aMessage.Int0();
  1793 		const TBool completeImmediatelyIfNoScanImpendingOrInProgress=aMessage.Int0();
  1893 		if ((!completeImmediatelyIfNoScanImpendingOrInProgress) ||
  1794 		if ((!completeImmediatelyIfNoScanImpendingOrInProgress) ||
  1894 			iServ.AppFsMonitor().AnyNotificationImpending() ||
  1795 			iAppArcSrv.AppFsMonitor().AnyNotificationImpending() ||
  1895 			AppList().AppScanInProgress())
  1796 			iAppList.AppScanInProgress())
  1896 			{
       
  1897 			iNotifyMessage=aMessage;
  1797 			iNotifyMessage=aMessage;
  1898 			}
       
  1899 		else
  1798 		else
  1900 			{
       
  1901 			aMessage.Complete(KErrNone);
  1799 			aMessage.Complete(KErrNone);
  1902 			}
  1800 		}
  1903 		}
  1801 	}
       
  1802 
       
  1803 void CApaAppArcServSession::NotifyClients(TInt aReason)
       
  1804 	{
       
  1805 	iAppListSession->NotifyClients(aReason);
  1904 	}
  1806 	}
  1905 
  1807 
  1906 void CApaAppListServSession::CancelNotify()
  1808 void CApaAppListServSession::CancelNotify()
  1907 	{
  1809 	{
  1908 	NotifyClients(KErrCancel);
  1810 	NotifyClients(KErrCancel);
  1909 	}
  1811 	}
  1910 
  1812 
  1911 void CApaAppListServSession::NotifyClients(TInt aReason)
  1813 void CApaAppListServSession::NotifyClients(TInt aReason)
  1912 	{
  1814 	{
  1913 	if (!iNotifyMessage.IsNull())
  1815 	if (!iNotifyMessage.IsNull())
  1914 		{
       
  1915 		iNotifyMessage.Complete(aReason);
  1816 		iNotifyMessage.Complete(aReason);
  1916 		}
  1817 	
  1917 	//Notify client for scan complete.
  1818 	//Notify client for scan complete.
  1918 	NotifyScanComplete();
  1819 	NotifyScanComplete();
  1919 	}
  1820 	}
  1920 
  1821 
  1921 void CApaAppListServSession::AppInfoProvidedByRegistrationFileL(const RMessage2& aMessage)
  1822 void CApaAppListServSession::AppInfoProvidedByRegistrationFileL(const RMessage2& aMessage)
  1922 	{
  1823 	{
  1923 	// get UID of required app
  1824 	// get UID of required app
  1924 	const TUid uid=TUid::Uid(aMessage.Int0());
  1825 	const TUid uid = TUid::Uid(aMessage.Int0());
  1925 
  1826 
  1926 	// locate app in list
  1827 	// locate app in list
  1927 	CApaAppData* app=NULL;
  1828 	const CApaAppData& app = FindAppInListL(uid);
  1928 	TApaAppEntry entry;
  1829 	
  1929 	if (!FindAppInList(app,entry,uid))
  1830 	const TBool registrationFileUsed = app.RegistrationFileUsed();
  1930 		{
       
  1931 		User::Leave(KErrNotFound);
       
  1932 		}
       
  1933 
       
  1934 	const TBool registrationFileUsed = app->RegistrationFileUsed();
       
  1935 	TPckgC<TBool> pckg(registrationFileUsed);
  1831 	TPckgC<TBool> pckg(registrationFileUsed);
  1936 	aMessage.WriteL(1, pckg);
  1832 	aMessage.WriteL(1, pckg);
  1937 	}
  1833 	}
  1938 
  1834 
  1939 void CApaAppListServSession::IconFileNameL(const RMessage2& aMessage)
  1835 void CApaAppListServSession::IconFileNameL(const RMessage2& aMessage)
  1940 	{
  1836 	{
  1941 	// get UID of required app
  1837 	// get UID of required app
  1942 	const TUid uid=TUid::Uid(aMessage.Int0());
  1838 	const TUid uid=TUid::Uid(aMessage.Int0());
  1943 
  1839 
  1944 	// locate app in list
  1840 	// locate app in list
  1945 	CApaAppData* app=NULL;
  1841 	const CApaAppData& app = FindAppInListL(uid);
  1946 	TApaAppEntry entry;
  1842 
  1947 	if (!FindAppInList(app,entry,uid))
  1843 	if (!app.RegistrationFileUsed())
  1948 		{
       
  1949 		User::Leave(KErrNotFound);
       
  1950 		}
       
  1951 
       
  1952 	if (!app->RegistrationFileUsed())
       
  1953 		{
       
  1954 		User::Leave(KErrNotSupported);
  1844 		User::Leave(KErrNotSupported);
  1955 		}
       
  1956 	else
  1845 	else
  1957 		{
  1846 		{
  1958 		TPtrC iconFileName(app->IconFileName());
  1847 		TPtrC iconFileName(app.IconFileName());
  1959 		if (iconFileName.Length() == 0)
  1848 		if (iconFileName.Length() == 0)
  1960 			{
       
  1961 			User::Leave(KErrNotFound);
  1849 			User::Leave(KErrNotFound);
  1962 			}
       
  1963 		else
  1850 		else
  1964 			{
  1851 			{
  1965 			TFileName fileName = iconFileName;
  1852 			TFileName fileName = iconFileName;
  1966 			TPckgC<TFileName> pckg(fileName);
  1853 			TPckgC<TFileName> pckg(fileName);
  1967 			aMessage.WriteL(1, pckg);
  1854 			aMessage.WriteL(1, pckg);
  1977 	const TUid viewUid=TUid::Uid(aMessage.Int1());
  1864 	const TUid viewUid=TUid::Uid(aMessage.Int1());
  1978 
  1865 
  1979 	TPtrC viewIconFileName;
  1866 	TPtrC viewIconFileName;
  1980 
  1867 
  1981 	// locate app in list
  1868 	// locate app in list
  1982 	CApaAppData* app=NULL;
  1869 	const CApaAppData& app = FindAppInListL(uid);
  1983 	TApaAppEntry entry;
  1870 
  1984 	if (!FindAppInList(app,entry,uid))
  1871 	if (!app.RegistrationFileUsed())
  1985 		{
       
  1986 		User::Leave(KErrNotFound);
       
  1987 		}
       
  1988 
       
  1989 	if (!app->RegistrationFileUsed())
       
  1990 		{
       
  1991 		User::Leave(KErrNotSupported);
  1872 		User::Leave(KErrNotSupported);
  1992 		}
       
  1993 	else
  1873 	else
  1994 		{
  1874 		{
  1995 		const CArrayPtr<CApaAppViewData>& viewDataArray=*app->Views();
  1875 		const CArrayPtr<CApaAppViewData>& viewDataArray = *app.Views();
  1996 		const TInt count=viewDataArray.Count();
  1876 		const TInt count = viewDataArray.Count();
  1997 		for (TInt ii=0; ii<count; ii++)
  1877 		for (TInt ii=0; ii<count; ii++)
  1998 			{
  1878 			{
  1999 			const CApaAppViewData& appViewData=*viewDataArray[ii];
  1879 			const CApaAppViewData& appViewData = *viewDataArray[ii];
  2000 			if (appViewData.Uid()==viewUid)
  1880 			if (appViewData.Uid() == viewUid)
  2001 				{
  1881 				{
  2002 				viewIconFileName.Set(appViewData.IconFileName());
  1882 				viewIconFileName.Set(appViewData.IconFileName());
  2003 				break;
  1883 				break;
  2004 				}
  1884 				}
  2005 			}
  1885 			}
       
  1886 
  2006 		if (viewIconFileName.Length() == 0)
  1887 		if (viewIconFileName.Length() == 0)
  2007 			{
       
  2008 			User::Leave(KErrNotFound);
  1888 			User::Leave(KErrNotFound);
  2009 			}
       
  2010 		else
  1889 		else
  2011 			{
  1890 			{
  2012 			TFileName fileName = viewIconFileName;
  1891 			TFileName fileName = viewIconFileName;
  2013 			TPckgC<TFileName> pckg(fileName);
  1892 			TPckgC<TFileName> pckg(fileName);
  2014 			aMessage.WriteL(2, pckg);
  1893 			aMessage.WriteL(2, pckg);
  2015 			}
  1894 			}
  2016 		}
  1895 		}
  2017 	}
  1896 	}
  2018 
  1897 
  2019 void CApaAppListServSession::GetAppServicesL(const RMessage2& aMessage)
  1898 void CApaAppArcServSession::GetAppServicesL(const RMessage2& aMessage)
  2020 	{
  1899 	{
  2021 	const TInt initialBufSize = aMessage.Int2();
  1900 	const TInt initialBufSize = aMessage.Int2();
  2022 	if (initialBufSize)
  1901 	if (initialBufSize)
  2023 		{
  1902 		{
  2024 		delete iBuffer;
  1903 		delete iBuffer;
  2025 		iBuffer = NULL;
  1904 		iBuffer = NULL;
  2026 		iBuffer = GetServiceBufferL(aMessage);
  1905 		iBuffer = GetServiceBufferL(aMessage);
  2027 		if (iBuffer->Size() > initialBufSize)
  1906 		if (iBuffer->Size() > initialBufSize)
  2028 			{
  1907 			User::Leave(iBuffer->Ptr(0).Size());	// default buffer provided by client is too small, ask client to provide buffer of correct size
  2029 			// default buffer provided by client is too small, ask client to provide buffer of correct size
       
  2030 			User::Leave(iBuffer->Ptr(0).Size());
       
  2031 			}
       
  2032 		}
  1908 		}
  2033 	__ASSERT_ALWAYS(iBuffer, aMessage.Panic(KApaPanicCli,EClientBadRequest));
  1909 	__ASSERT_ALWAYS(iBuffer, aMessage.Panic(KApaPanicCli,EClientBadRequest));
  2034 	aMessage.WriteL(3, iBuffer->Ptr(0));
  1910 	aMessage.WriteL(3, iBuffer->Ptr(0));
  2035 	delete iBuffer;
  1911 	delete iBuffer;
  2036 	iBuffer = NULL;
  1912 	iBuffer = NULL;
  2037 	}
  1913 	}
  2038 
  1914 
  2039 CBufBase* CApaAppListServSession::GetServiceBufferL(const RMessage2& aMessage) const
  1915 CBufBase* CApaAppArcServSession::GetServiceBufferL(const RMessage2& aMessage) const
  2040 	{
  1916 	{
  2041 	CBufBase* buffer = NULL;
  1917 	CBufBase* buffer = NULL;
  2042 	const TUid uid = TUid::Uid(aMessage.Int0());
  1918 	const TUid uid = TUid::Uid(aMessage.Int0());
  2043 	switch (aMessage.Function())
  1919 	switch (aMessage.Function())
  2044 		{
  1920 		{
  2045 	case EAppListServGetAppServices:
  1921 	case EAppListServGetAppServices:
  2046 		buffer = AppList().ServiceArrayBufferL(uid);
  1922 		buffer = iAppListSession->AppList().ServiceArrayBufferL(uid);
  2047 		break;
  1923 		break;
  2048 	case EAppListServGetServiceImplementations:
  1924 	case EAppListServGetServiceImplementations:
  2049 		buffer = AppList().ServiceImplArrayBufferL(uid);
  1925 		buffer = iAppListSession->AppList().ServiceImplArrayBufferL(uid);
  2050 		break;
  1926 		break;
  2051 	case EAppListServGetServiceImplementationsDataType:
  1927 	case EAppListServGetServiceImplementationsDataType:
  2052 		{
  1928 		{
  2053 		TDataType dataType;
  1929 		TDataType dataType;
  2054 		TPckg<TDataType> dataType_asDescriptor(dataType);
  1930 		TPckg<TDataType> dataType_asDescriptor(dataType);
  2055 		aMessage.ReadL(1,dataType_asDescriptor);
  1931 		aMessage.ReadL(1,dataType_asDescriptor);
  2056 		buffer = AppList().ServiceImplArrayBufferL(uid, dataType);
  1932 		buffer = iAppListSession->AppList().ServiceImplArrayBufferL(uid, dataType);
  2057 		}
  1933 		}
  2058 		break;
  1934 		break;
  2059 	case EAppListServGetAppServiceUids:
  1935 	case EAppListServGetAppServiceUids:
  2060 		buffer = AppList().ServiceUidBufferL(uid);
  1936 		buffer = iAppListSession->AppList().ServiceUidBufferL(uid);
  2061 		break;
  1937 		break;
  2062 	case EAppListServGetAppServiceOpaqueData:
  1938 	case EAppListServGetAppServiceOpaqueData:
  2063 		buffer = AppList().ServiceOpaqueDataBufferL(uid, TUid::Uid(aMessage.Int1()));
  1939 		buffer = iAppListSession->AppList().ServiceOpaqueDataBufferL(uid, TUid::Uid(aMessage.Int1()));
  2064 		break;
  1940 		break;
  2065 	default:
  1941 	default:
  2066 		aMessage.Panic(KApaPanicCli,EClientBadRequest);
  1942 		aMessage.Panic(KApaPanicCli,EClientBadRequest);
  2067 		User::Leave(KErrNotSupported);
  1943 		User::Leave(KErrNotSupported);
  2068 		break;
  1944 		break;
  2069 		}
  1945 		}
       
  1946 
  2070 	return buffer;
  1947 	return buffer;
  2071 	}
       
  2072 
       
  2073 void CApaAppListServSession::NullifyAppCommandLinePointer(TAny* aServer)
       
  2074 	{
       
  2075 	static_cast<CApaAppListServer*>(aServer)->SetAppCmdLine(NULL);
       
  2076 	}
  1948 	}
  2077 
  1949 
  2078 CApaAppListServSession::CApaAppInfo::CApaAppInfo()
  1950 CApaAppListServSession::CApaAppInfo::CApaAppInfo()
  2079 	:iUid(KNullUid), iCaption(NULL), iShortCaption(NULL), iFullName(NULL)
  1951 	:iUid(KNullUid), iCaption(NULL), iShortCaption(NULL), iFullName(NULL)
  2080 	{
  1952 	{
  2114 	}
  1986 	}
  2115 
  1987 
  2116 void CApaAppListServSession::RegisterListPopulationCompleteObserver(const RMessage2& aMessage)
  1988 void CApaAppListServSession::RegisterListPopulationCompleteObserver(const RMessage2& aMessage)
  2117 	{
  1989 	{
  2118 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
  1990 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
  2119 		{
       
  2120 		aMessage.Panic(KApaPanicCli,EObserverAlreadyPresent);
  1991 		aMessage.Panic(KApaPanicCli,EObserverAlreadyPresent);
  2121 		}
       
  2122 	else
  1992 	else
  2123 		{
  1993 		{
  2124 		if(AppList().IsFirstScanComplete())
  1994 		if(iAppList.IsFirstScanComplete())
  2125 			{
       
  2126 			aMessage.Complete(KErrNone);
  1995 			aMessage.Complete(KErrNone);
  2127 			}
       
  2128 		else
  1996 		else
  2129 			{
       
  2130 			iCompletionOfListPopulationObserverMsg=aMessage;
  1997 			iCompletionOfListPopulationObserverMsg=aMessage;
  2131 			}
  1998 		}
  2132 		}
  1999 	}
       
  2000 
       
  2001 void CApaAppArcServSession::NotifyClientForCompletionOfListPopulation()
       
  2002 	{
       
  2003 	iAppListSession->NotifyClientForCompletionOfListPopulation();
  2133 	}
  2004 	}
  2134 
  2005 
  2135 void CApaAppListServSession::NotifyClientForCompletionOfListPopulation()
  2006 void CApaAppListServSession::NotifyClientForCompletionOfListPopulation()
  2136 	{
  2007 	{
  2137 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
  2008 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
  2138 		{
       
  2139 		iCompletionOfListPopulationObserverMsg.Complete(KErrNone);
  2009 		iCompletionOfListPopulationObserverMsg.Complete(KErrNone);
  2140 		}
       
  2141 	} //lint !e1762 Suppress member function could be made const
  2010 	} //lint !e1762 Suppress member function could be made const
  2142 
  2011 
  2143 
  2012 
  2144 void CApaAppListServSession::CancelListPopulationCompleteObserver()
  2013 void CApaAppListServSession::CancelListPopulationCompleteObserver()
  2145 	{
  2014 	{
  2146 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
  2015 	if (!iCompletionOfListPopulationObserverMsg.IsNull())
  2147 		{
       
  2148 		iCompletionOfListPopulationObserverMsg.Complete(KErrCancel);
  2016 		iCompletionOfListPopulationObserverMsg.Complete(KErrCancel);
  2149 		}
       
  2150 	} //lint !e1762 Suppress member function could be made const
  2017 	} //lint !e1762 Suppress member function could be made const
  2151 	
  2018 	
  2152 void CApaAppListServSession::NotifyClientOfDataMappingChange()
  2019 void CApaAppArcServSession::NotifyClientOfDataMappingChange()
  2153 	{
  2020 	{
  2154 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
  2021 	if (!iMessage_NotifyOnDataMappingChange.IsNull())
  2155 		{
       
  2156 		iMessage_NotifyOnDataMappingChange.Complete(KErrNone);
  2022 		iMessage_NotifyOnDataMappingChange.Complete(KErrNone);
  2157 		}
       
  2158 	} //lint !e1762 Suppress member function could be made const
  2023 	} //lint !e1762 Suppress member function could be made const
  2159 
  2024 
  2160 void CApaAppListServSession::MatchesSecurityPolicyL(const RMessage2& aMessage)
  2025 void CApaAppListServSession::MatchesSecurityPolicyL(const RMessage2& aMessage)
  2161 	{
  2026 	{
  2162 	const TUid appUid=TUid::Uid(aMessage.Int0());
  2027 	const TUid appUid=TUid::Uid(aMessage.Int0());
  2177 			aMessage.ReadL(1,securityPolicy);
  2042 			aMessage.ReadL(1,securityPolicy);
  2178 			aMessage.Complete(securityPolicy().CheckPolicy(process));
  2043 			aMessage.Complete(securityPolicy().CheckPolicy(process));
  2179 			process.Close();
  2044 			process.Close();
  2180 			}
  2045 			}
  2181 		else
  2046 		else
  2182 			{
       
  2183 			aMessage.Complete(result);
  2047 			aMessage.Complete(result);
  2184 			}
       
  2185 		}
  2048 		}
  2186 	else
  2049 	else
  2187 		{
       
  2188 		aMessage.Complete(KErrNotFound);
  2050 		aMessage.Complete(KErrNotFound);
  2189 		}
  2051 
  2190 	CleanupStack::PopAndDestroy(appInfo);
  2052 	CleanupStack::PopAndDestroy(appInfo);
  2191 	}
  2053 	}
  2192 	
  2054 	
  2193 void CApaAppListServSession::SetAppShortCaptionL(const RMessage2& aMessage)
  2055 void CApaAppListServSession::SetAppShortCaptionL(const RMessage2& aMessage)
  2194 	{
  2056 	{
  2195 	const TUid uid=TUid::Uid(aMessage.Int0());
  2057 	const TUid uid=TUid::Uid(aMessage.Int0());
  2196 	CApaAppData* app=NULL;
  2058 	CApaAppData* app=NULL;
  2197 	TApaAppEntry entry;
  2059 	TApaAppEntry entry;
  2198 	if (!FindAppInList(app,entry,uid))
  2060 	if (!FindAppInList(app,entry,uid))
  2199 		{
       
  2200 		User::Leave(KErrNotFound);
  2061 		User::Leave(KErrNotFound);
  2201 		}
  2062 
  2202 
  2063 	const TInt length = aMessage.GetDesLength(1);
  2203 	TInt length=aMessage.GetDesLength(1);
       
  2204 	if(length < 0)
  2064 	if(length < 0)
  2205 		{
       
  2206 		User::Leave(length);
  2065 		User::Leave(length);
  2207 		}
  2066 
  2208 
  2067 	HBufC* const shortCaption = HBufC::NewLC(length);
  2209 	HBufC* const shortCaption=HBufC::NewLC(length);
       
  2210 	TPtr captionPtr(shortCaption->Des());
  2068 	TPtr captionPtr(shortCaption->Des());
  2211 	aMessage.ReadL(1, captionPtr);
  2069 	aMessage.ReadL(1, captionPtr);
  2212 
  2070 
  2213 	TLanguage appLanguage=TLanguage(aMessage.Int2());
  2071 	TLanguage appLanguage = TLanguage(aMessage.Int2());
  2214 	CCustomAppInfoData* customAppInfo=CCustomAppInfoData::NewL(uid, appLanguage, *shortCaption);
  2072 	iAppList.AddCustomAppInfoInListL(uid, appLanguage, *shortCaption);
  2215 	CleanupStack::PushL(customAppInfo);
       
  2216 	iServ.AddCustomAppInfoInListL(customAppInfo);
       
  2217 	CleanupStack::Pop(customAppInfo);
       
  2218 	if(app->ApplicationLanguage() == appLanguage)
  2073 	if(app->ApplicationLanguage() == appLanguage)
  2219 		{
       
  2220 		app->SetShortCaptionL(*shortCaption);
  2074 		app->SetShortCaptionL(*shortCaption);
  2221 		}
       
  2222 	else if(appLanguage==ELangNone)
  2075 	else if(appLanguage==ELangNone)
  2223 		{
  2076 		iAppList.UpdateAppListByShortCaptionL(); 
  2224 		iServ.UpdateAppListByShortCaptionL(); 
  2077 
  2225 		}
       
  2226 	CleanupStack::PopAndDestroy(shortCaption);
  2078 	CleanupStack::PopAndDestroy(shortCaption);
       
  2079 	}
       
  2080 
       
  2081 
       
  2082 void CApaAppArcServSession::NotifyScanComplete()
       
  2083 	{
       
  2084 	iAppListSession->NotifyScanComplete();
  2227 	}
  2085 	}
  2228 
  2086 
  2229 void CApaAppListServSession::NotifyScanComplete()
  2087 void CApaAppListServSession::NotifyScanComplete()
  2230 	{
  2088 	{
  2231 	//See if the session is intrested in scan complete notification.
  2089 	//See if the session is intrested in scan complete notification.
  2287 
  2145 
  2288 void TDesCArrayItemWriter::WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const
  2146 void TDesCArrayItemWriter::WriteArrayItemL(RWriteStream& aWriteStream,TInt aIndex) const
  2289 	{
  2147 	{
  2290 	aWriteStream << iArray[aIndex];
  2148 	aWriteStream << iArray[aIndex];
  2291 	}
  2149 	}
       
  2150